KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > interop > rmi > iiop > SimpleObjectOutputStream


1 /**
2  *
3  * Copyright 2004-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.geronimo.interop.rmi.iiop;
19
20 import java.io.IOException JavaDoc;
21
22 import org.apache.geronimo.interop.util.ArrayUtil;
23 import org.apache.geronimo.interop.util.JavaObject;
24
25 public class SimpleObjectOutputStream extends ObjectOutputStream
26 {
27     public static ObjectOutputStream getInstance()
28     {
29         ObjectOutputStream oos = null;
30         try {
31             oos = new SimpleObjectOutputStream();
32         } catch (IOException JavaDoc e) {
33             e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
34
}
35         return oos;
36     }
37
38     public static ObjectOutputStream getInstance(CdrOutputStream cdrOutput)
39     {
40         ObjectOutputStream output = getInstance();
41         output.init(cdrOutput);
42         return output;
43     }
44
45     public static ObjectOutputStream getPooledInstance()
46     {
47         ObjectOutputStream output = null;
48         if (output == null)
49         {
50             output = getInstance();
51         }
52         return output;
53     }
54
55     // -----------------------------------------------------------------------
56
// private data
57
// -----------------------------------------------------------------------
58

59     // -----------------------------------------------------------------------
60
// public methods
61
// -----------------------------------------------------------------------
62

63     public SimpleObjectOutputStream() throws IOException JavaDoc
64     {
65         super();
66     }
67
68     public void $reset()
69     {
70         _cdrOutput.reset();
71     }
72
73     public void recycle()
74     {
75         $reset();
76     }
77
78     public void writeException(ValueType type, Exception JavaDoc value)
79     {
80         String JavaDoc repositoryID = "IDL:" + type._class.getName().replace('.', '/') + ":1.0";
81         _cdrOutput.write_string(repositoryID);
82         writeObject(type, value);
83         _hasException = true;
84     }
85
86     public void writeObject(ValueType type, Object JavaDoc value)
87     {
88         ObjectHelper h = type.helper;
89         if (h != null)
90         {
91             h.write(this, value);
92             return;
93         }
94         byte[] bytes = JavaObject.toByteArray(value);
95         if (bytes == null) bytes = ArrayUtil.EMPTY_BYTE_ARRAY;
96         _cdrOutput.write_octet_sequence(bytes);
97     }
98
99     // -----------------------------------------------------------------------
100
// protected methods
101
// -----------------------------------------------------------------------
102

103     protected void init(CdrOutputStream cdrOutput)
104     {
105         super.init(cdrOutput);
106     }
107 }
108
Popular Tags