KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > marshal > serializable > SerializableMarshaller


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.remoting.marshal.serializable;
8
9 import java.io.IOException JavaDoc;
10 import java.io.ObjectOutputStream JavaDoc;
11 import java.io.OutputStream JavaDoc;
12 import org.jboss.remoting.marshal.Marshaller;
13
14 /**
15  * Simple marshaller that simply serializes java objects
16  * using standard output stream.
17  *
18  * @author <a HREF="mailto:tom@jboss.org">Tom Elrod</a>
19  */

20 public class SerializableMarshaller implements Marshaller
21 {
22    static final long serialVersionUID = -5553685435323600244L;
23
24    public final static String JavaDoc DATATYPE = "serializable";
25
26    /**
27     * Take the data object and write to the output. Has ben customized
28     * for working with ObjectOutputStreams since requires extra messaging.
29     *
30     * @param dataObject Object to be writen to output
31     * @param output The data output to write the object
32     * data to.
33     */

34    public void write(Object JavaDoc dataObject, OutputStream JavaDoc output) throws IOException JavaDoc
35    {
36       ObjectOutputStream JavaDoc oos = null;
37       if(output instanceof ObjectOutputStream JavaDoc)
38       {
39          oos = (ObjectOutputStream JavaDoc) output;
40       }
41       else
42       {
43          oos = new ObjectOutputStream JavaDoc(output);
44       }
45       oos.writeObject(dataObject);
46
47       oos.reset();
48       // to make sure stream gets reset
49
// Stupid ObjectInputStream holds object graph
50
// can only be set by the client/server sending a TC_RESET
51
oos.writeObject(Boolean.TRUE);
52       oos.flush();
53       oos.reset();
54
55    }
56
57    public Marshaller cloneMarshaller()
58          throws CloneNotSupportedException JavaDoc
59    {
60       return new SerializableMarshaller();
61    }
62 }
Popular Tags