2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23
package org.jboss.remoting.marshal.serializable;
25
import java.io.BufferedOutputStream;
26
import java.io.IOException;
27
import java.io.ObjectOutputStream;
28
import java.io.OutputStream;
31
import org.jboss.remoting.Version;
32
import org.jboss.remoting.marshal.Marshaller;
33
import org.jboss.remoting.marshal.PreferredStreamMarshaller;
34
import org.jboss.remoting.marshal.VersionedMarshaller;
35
import org.jboss.remoting.serialization.SerializationManager;
36
import org.jboss.remoting.serialization.SerializationStreamFactory;
39
* Simple marshaller that simply serializes java objects
40
* using standard output stream.
42
* @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
44
public class SerializableMarshaller implements PreferredStreamMarshaller, VersionedMarshaller
46
static final long serialVersionUID = -5553685435323600244L;
48
public final static String DATATYPE = "serializable";
50
String serializationType;
53
public void setSerializationType(String serializationType)
55
this.serializationType = serializationType;
58
public String getSerializationType()
60
if(serializationType == null)
66
return serializationType;
70
public OutputStream getMarshallingStream(OutputStream outputStream) throws IOException
72
return getMarshallingStream(outputStream, null);
76
* SerializableMarshaller prefers to write to an ObjectOutputStream wrapped around a
77
* BufferedOutputStream.
79
public OutputStream getMarshallingStream(OutputStream outputStream, Map config) throws IOException
81
if(outputStream instanceof ObjectOutputStream)
87
BufferedOutputStream bos = new BufferedOutputStream(outputStream);
88
SerializationManager manager = SerializationStreamFactory.getManagerInstance(getSerializationType());
89
ObjectOutputStream oos = manager.createOutput(bos);
96
* Take the data object and write to the output. Has ben customized
97
* for working with ObjectOutputStreams since requires extra messaging.
99
* @param dataObject Object to be writen to output
100
* @param output The data output to write the object
103
public void write(Object dataObject, OutputStream output) throws IOException
105
int version = Version.getDefaultVersion();
106
write(dataObject, output, version);
110
* Take the data object and write to the output. Has ben customized
111
* for working with ObjectOutputStreams since requires extra messaging.
113
* @param dataObject Object to be writen to output
114
* @param output The data output to write the object data to.
115
* @param version Wire format version
117
public void write(Object dataObject, OutputStream output, int version) throws IOException
119
ObjectOutputStream oos = (ObjectOutputStream) getMarshallingStream(output, null);
120
SerializationStreamFactory.getManagerInstance(getSerializationType()).sendObject(oos, dataObject, version);
123
public Marshaller cloneMarshaller()
124
throws CloneNotSupportedException
126
return new SerializableMarshaller();
b'\\ No newline at end of file'