01: // AdminWriter.java
02: // $Id: AdminWriter.java,v 1.11 2003/02/28 10:34:01 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1997.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.jigsaw.admin;
07:
08: import java.io.IOException;
09: import java.io.OutputStream;
10: import java.io.OutputStreamWriter;
11: import java.io.Writer;
12: import org.w3c.tools.resources.Resource;
13: import org.w3c.tools.resources.serialization.ResourceDescription;
14: import org.w3c.tools.resources.serialization.SerializationException;
15: import org.w3c.tools.resources.serialization.Serializer;
16:
17: class AdminWriter implements AdminProtocol {
18:
19: /**
20: * Our serializer.
21: */
22: protected Serializer serializer = null;
23:
24: /**
25: * Write the given resource to the given output stream.
26: * @param out The object output stream to write to.
27: * @param resource The resource to write
28: * @exception IOException If something went wrong.
29: */
30:
31: protected void writeResource(Resource resource, OutputStream out)
32: throws IOException, AdminProtocolException {
33: try {
34: Resource resources[] = { resource };
35: Writer writer = new OutputStreamWriter(out, "UTF-8");
36: serializer.writeResourceDescriptions(resources, writer);
37: } catch (SerializationException ex) {
38: throw new AdminProtocolException(
39: "Unable to serialize resource :" + ex.getMessage());
40: }
41: }
42:
43: /**
44: * Write the given resource to the given output stream.
45: * @param out The object output stream to write to.
46: * @param description The resource description to write
47: * @exception IOException If something went wrong.
48: */
49:
50: protected void writeResourceDescription(
51: ResourceDescription description, OutputStream out)
52: throws IOException, AdminProtocolException {
53: try {
54: ResourceDescription descrs[] = { description };
55: Writer writer = new OutputStreamWriter(out, "UTF-8");
56: serializer.writeResourceDescriptions(descrs, writer);
57: } catch (SerializationException ex) {
58: throw new AdminProtocolException(
59: "Unable to serialize resource :" + ex.getMessage());
60: }
61: }
62:
63: AdminWriter() {
64: this .serializer = new org.w3c.tools.resources.serialization.xml.XMLSerializer();
65: }
66:
67: }
|