~ubuntu-branches/ubuntu/raring/libjboss-remoting-java/raring

« back to all changes in this revision

Viewing changes to src/main/org/jboss/remoting/marshal/serializable/SerializableMarshaller.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
6
*
 
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.
 
11
*
 
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.
 
16
*
 
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.
 
21
*/
 
22
 
 
23
package org.jboss.remoting.marshal.serializable;
 
24
 
 
25
import java.io.BufferedOutputStream;
 
26
import java.io.IOException;
 
27
import java.io.ObjectOutputStream;
 
28
import java.io.OutputStream;
 
29
import java.util.Map;
 
30
 
 
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;
 
37
 
 
38
/**
 
39
 * Simple marshaller that simply serializes java objects
 
40
 * using standard output stream.
 
41
 *
 
42
 * @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
 
43
 */
 
44
public class SerializableMarshaller implements PreferredStreamMarshaller, VersionedMarshaller
 
45
{
 
46
   static final long serialVersionUID = -5553685435323600244L;
 
47
 
 
48
   public final static String DATATYPE = "serializable";
 
49
 
 
50
   String serializationType;
 
51
 
 
52
 
 
53
   public void setSerializationType(String serializationType)
 
54
   {
 
55
      this.serializationType = serializationType;
 
56
   }
 
57
 
 
58
   public String getSerializationType()
 
59
   {
 
60
      if(serializationType == null)
 
61
      {
 
62
         return "java";
 
63
      }
 
64
      else
 
65
      {
 
66
         return serializationType;
 
67
      }
 
68
   }
 
69
   
 
70
   public OutputStream getMarshallingStream(OutputStream outputStream) throws IOException
 
71
   {
 
72
      return getMarshallingStream(outputStream, null);
 
73
   }
 
74
   
 
75
   /**
 
76
    * SerializableMarshaller prefers to write to an ObjectOutputStream wrapped around a
 
77
    * BufferedOutputStream.
 
78
    */
 
79
   public OutputStream getMarshallingStream(OutputStream outputStream, Map config) throws IOException
 
80
   {
 
81
      if(outputStream instanceof ObjectOutputStream)
 
82
      {
 
83
         return outputStream;
 
84
      }
 
85
      else
 
86
      {
 
87
         BufferedOutputStream bos = new BufferedOutputStream(outputStream);
 
88
         SerializationManager manager = SerializationStreamFactory.getManagerInstance(getSerializationType());
 
89
         ObjectOutputStream oos = manager.createOutput(bos);
 
90
         oos.flush();
 
91
         return oos;
 
92
      }
 
93
   }
 
94
 
 
95
   /**
 
96
    * Take the data object and write to the output.  Has ben customized
 
97
    * for working with ObjectOutputStreams since requires extra messaging.
 
98
    *
 
99
    * @param dataObject Object to be writen to output
 
100
    * @param output     The data output to write the object
 
101
    *                   data to.
 
102
    */
 
103
   public void write(Object dataObject, OutputStream output) throws IOException
 
104
   {
 
105
      int version = Version.getDefaultVersion();
 
106
      write(dataObject, output, version);
 
107
   }
 
108
 
 
109
   /**
 
110
    * Take the data object and write to the output.  Has ben customized
 
111
    * for working with ObjectOutputStreams since requires extra messaging.
 
112
    *
 
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
 
116
    */
 
117
   public void write(Object dataObject, OutputStream output, int version) throws IOException
 
118
   {
 
119
      ObjectOutputStream oos = (ObjectOutputStream) getMarshallingStream(output, null);
 
120
      SerializationStreamFactory.getManagerInstance(getSerializationType()).sendObject(oos, dataObject, version);
 
121
   }
 
122
   
 
123
   public Marshaller cloneMarshaller()
 
124
         throws CloneNotSupportedException
 
125
   {
 
126
      return new SerializableMarshaller();
 
127
   }
 
128
}
 
 
b'\\ No newline at end of file'