Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / jigsaw / admin / AdminWriter.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/jigsaw/admin/AdminWriter.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/jigsaw/admin/AdminWriter.java
new file mode 100644 (file)
index 0000000..52f90c0
--- /dev/null
@@ -0,0 +1,70 @@
+// AdminWriter.java \r
+// $Id: AdminWriter.java,v 1.1 2010/06/15 12:24:27 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1997.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.jigsaw.admin;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.io.OutputStreamWriter;\r
+import java.io.Writer;\r
+import org.w3c.tools.resources.Resource;\r
+import org.w3c.tools.resources.serialization.ResourceDescription;\r
+import org.w3c.tools.resources.serialization.SerializationException;\r
+import org.w3c.tools.resources.serialization.Serializer;\r
+\r
+class AdminWriter implements AdminProtocol {\r
+\r
+    /**\r
+     * Our serializer.\r
+     */\r
+    protected Serializer serializer = null;\r
+\r
+    /**\r
+     * Write the given resource to the given output stream.\r
+     * @param out The object output stream to write to.\r
+     * @param resource The resource to write\r
+     * @exception IOException If something went wrong.\r
+     */\r
+\r
+    protected void writeResource(Resource resource, OutputStream out) \r
+       throws IOException, AdminProtocolException\r
+    {\r
+       try {\r
+           Resource resources[] = { resource };\r
+           Writer writer = new OutputStreamWriter( out, "UTF-8" );\r
+           serializer.writeResourceDescriptions(resources, writer);\r
+       } catch (SerializationException ex) {\r
+           throw new AdminProtocolException("Unable to serialize resource :"+\r
+                                            ex.getMessage());\r
+       }\r
+    }\r
+\r
+    /**\r
+     * Write the given resource to the given output stream.\r
+     * @param out The object output stream to write to.\r
+     * @param description The resource description to write\r
+     * @exception IOException If something went wrong.\r
+     */\r
+\r
+    protected void  writeResourceDescription(ResourceDescription description,\r
+                                            OutputStream out) \r
+       throws IOException, AdminProtocolException\r
+    {\r
+       try {\r
+           ResourceDescription descrs[] = { description };\r
+           Writer writer = new OutputStreamWriter( out, "UTF-8");\r
+           serializer.writeResourceDescriptions(descrs, writer);\r
+       } catch (SerializationException ex) {\r
+           throw new AdminProtocolException("Unable to serialize resource :"+\r
+                                            ex.getMessage());\r
+       }\r
+    }\r
+\r
+    AdminWriter() {\r
+       this.serializer = \r
+           new org.w3c.tools.resources.serialization.xml.XMLSerializer();\r
+    }\r
+\r
+}\r