KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > encoding > CDROutputStream


1 /*
2  * @(#)CDROutputStream.java 1.28 04/06/21
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package com.sun.corba.se.impl.encoding;
8
9 import java.io.IOException JavaDoc;
10 import java.io.Serializable JavaDoc;
11 import java.math.BigDecimal JavaDoc;
12 import java.nio.ByteBuffer JavaDoc;
13
14 import org.omg.CORBA.TypeCode JavaDoc;
15 import org.omg.CORBA.Principal JavaDoc;
16 import org.omg.CORBA.Any JavaDoc;
17
18 import com.sun.corba.se.pept.protocol.MessageMediator;
19
20 import com.sun.corba.se.spi.orb.ORB;
21 import com.sun.corba.se.spi.logging.CORBALogDomains;
22 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
23 import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
24
25 import com.sun.corba.se.impl.encoding.CodeSetConversion;
26 import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;
27 import com.sun.corba.se.impl.orbutil.ORBConstants;
28 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
29 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
30
31 /**
32  * This is delegates to the real implementation.
33  */

34 public abstract class CDROutputStream
35     extends org.omg.CORBA_2_3.portable.OutputStream JavaDoc
36     implements com.sun.corba.se.impl.encoding.MarshalOutputStream,
37                org.omg.CORBA.DataOutputStream JavaDoc, org.omg.CORBA.portable.ValueOutputStream JavaDoc
38 {
39     private CDROutputStreamBase impl;
40     protected ORB orb ;
41     protected ORBUtilSystemException wrapper ;
42     protected CorbaMessageMediator corbaMessageMediator;
43
44
45     // We can move this out somewhere later. For now, it serves its purpose
46
// to create a concrete CDR delegate based on the GIOP version.
47
private static class OutputStreamFactory {
48         
49         public static CDROutputStreamBase newOutputStream(
50             ORB orb, GIOPVersion version, byte encodingVersion) {
51             switch(version.intValue()) {
52                 case GIOPVersion.VERSION_1_0:
53                     return new CDROutputStream_1_0();
54                 case GIOPVersion.VERSION_1_1:
55                     return new CDROutputStream_1_1();
56         case GIOPVersion.VERSION_1_2:
57         if (encodingVersion != Message.CDR_ENC_VERSION) {
58             return
59             new IDLJavaSerializationOutputStream(encodingVersion);
60         }
61         return new CDROutputStream_1_2();
62         default:
63             ORBUtilSystemException wrapper = ORBUtilSystemException.get( orb,
64             CORBALogDomains.RPC_ENCODING ) ;
65                     // REVISIT - what is appropriate? INTERNAL exceptions
66
// are really hard to track later.
67
throw wrapper.unsupportedGiopVersion( version ) ;
68             }
69         }
70     }
71
72     // REVISIT - These two constructors should be re-factored to better hide
73
// the fact that someone extending this class 'can' construct a CDROutputStream
74
// that does not use pooled ByteBuffers. Right now, only EncapsOutputStream
75
// does _not_ use pooled ByteBuffers, see EncapsOutputStream.
76

77     // NOTE: When a stream is constructed for non-channel-backed sockets
78
// it notifies the constructor not to use pooled (i.e, direct)
79
// ByteBuffers.
80

81     public CDROutputStream(ORB orb,
82                            GIOPVersion version,
83                byte encodingVersion,
84                boolean littleEndian,
85                BufferManagerWrite bufferManager,
86                            byte streamFormatVersion,
87                            boolean usePooledByteBuffers)
88     {
89         impl = OutputStreamFactory.newOutputStream(orb, version,
90                            encodingVersion);
91         impl.init(orb, littleEndian, bufferManager,
92           streamFormatVersion, usePooledByteBuffers);
93
94         impl.setParent(this);
95     this.orb = orb ;
96     this.wrapper = ORBUtilSystemException.get( orb,
97         CORBALogDomains.RPC_ENCODING ) ;
98     }
99
100     public CDROutputStream(ORB orb,
101                            GIOPVersion version,
102                byte encodingVersion,
103                boolean littleEndian,
104                BufferManagerWrite bufferManager,
105                            byte streamFormatVersion)
106     {
107         this(orb, version, encodingVersion, littleEndian,
108          bufferManager, streamFormatVersion, true);
109     }
110
111     // org.omg.CORBA.portable.OutputStream
112

113     // Provided by IIOPOutputStream and EncapsOutputStream
114
public abstract org.omg.CORBA.portable.InputStream JavaDoc create_input_stream();
115
116     public final void write_boolean(boolean value) {
117         impl.write_boolean(value);
118     }
119     public final void write_char(char value) {
120         impl.write_char(value);
121     }
122     public final void write_wchar(char value) {
123         impl.write_wchar(value);
124     }
125     public final void write_octet(byte value) {
126         impl.write_octet(value);
127     }
128     public final void write_short(short value) {
129         impl.write_short(value);
130     }
131     public final void write_ushort(short value) {
132         impl.write_ushort(value);
133     }
134     public final void write_long(int value) {
135         impl.write_long(value);
136     }
137     public final void write_ulong(int value) {
138         impl.write_ulong(value);
139     }
140     public final void write_longlong(long value) {
141         impl.write_longlong(value);
142     }
143     public final void write_ulonglong(long value) {
144         impl.write_ulonglong(value);
145     }
146     public final void write_float(float value) {
147         impl.write_float(value);
148     }
149     public final void write_double(double value) {
150         impl.write_double(value);
151     }
152     public final void write_string(String JavaDoc value) {
153         impl.write_string(value);
154     }
155     public final void write_wstring(String JavaDoc value) {
156         impl.write_wstring(value);
157     }
158
159     public final void write_boolean_array(boolean[] value, int offset, int length) {
160         impl.write_boolean_array(value, offset, length);
161     }
162     public final void write_char_array(char[] value, int offset, int length) {
163         impl.write_char_array(value, offset, length);
164     }
165     public final void write_wchar_array(char[] value, int offset, int length) {
166         impl.write_wchar_array(value, offset, length);
167     }
168     public final void write_octet_array(byte[] value, int offset, int length) {
169         impl.write_octet_array(value, offset, length);
170     }
171     public final void write_short_array(short[] value, int offset, int length) {
172         impl.write_short_array(value, offset, length);
173     }
174     public final void write_ushort_array(short[] value, int offset, int length){
175         impl.write_ushort_array(value, offset, length);
176     }
177     public final void write_long_array(int[] value, int offset, int length) {
178         impl.write_long_array(value, offset, length);
179     }
180     public final void write_ulong_array(int[] value, int offset, int length) {
181         impl.write_ulong_array(value, offset, length);
182     }
183     public final void write_longlong_array(long[] value, int offset, int length) {
184         impl.write_longlong_array(value, offset, length);
185     }
186     public final void write_ulonglong_array(long[] value, int offset,int length) {
187         impl.write_ulonglong_array(value, offset, length);
188     }
189     public final void write_float_array(float[] value, int offset, int length) {
190         impl.write_float_array(value, offset, length);
191     }
192     public final void write_double_array(double[] value, int offset, int length) {
193         impl.write_double_array(value, offset, length);
194     }
195     public final void write_Object(org.omg.CORBA.Object JavaDoc value) {
196         impl.write_Object(value);
197     }
198     public final void write_TypeCode(TypeCode JavaDoc value) {
199         impl.write_TypeCode(value);
200     }
201     public final void write_any(Any JavaDoc value) {
202         impl.write_any(value);
203     }
204
205     public final void write_Principal(Principal JavaDoc value) {
206         impl.write_Principal(value);
207     }
208
209     public final void write(int b) throws java.io.IOException JavaDoc {
210         impl.write(b);
211     }
212     
213     public final void write_fixed(java.math.BigDecimal JavaDoc value) {
214         impl.write_fixed(value);
215     }
216
217     public final void write_Context(org.omg.CORBA.Context JavaDoc ctx,
218                   org.omg.CORBA.ContextList JavaDoc contexts) {
219         impl.write_Context(ctx, contexts);
220     }
221
222     public final org.omg.CORBA.ORB JavaDoc orb() {
223         return impl.orb();
224     }
225
226     // org.omg.CORBA_2_3.portable.OutputStream
227
public final void write_value(java.io.Serializable JavaDoc value) {
228         impl.write_value(value);
229     }
230
231     public final void write_value(java.io.Serializable JavaDoc value, java.lang.Class JavaDoc clz) {
232         impl.write_value(value, clz);
233     }
234
235     public final void write_value(java.io.Serializable JavaDoc value, String JavaDoc repository_id) {
236         impl.write_value(value, repository_id);
237     }
238
239     public final void write_value(java.io.Serializable JavaDoc value,
240                             org.omg.CORBA.portable.BoxedValueHelper JavaDoc factory) {
241         impl.write_value(value, factory);
242     }
243
244     public final void write_abstract_interface(java.lang.Object JavaDoc obj) {
245         impl.write_abstract_interface(obj);
246     }
247
248     // java.io.OutputStream
249
public final void write(byte b[]) throws IOException JavaDoc {
250         impl.write(b);
251     }
252
253     public final void write(byte b[], int off, int len) throws IOException JavaDoc {
254         impl.write(b, off, len);
255     }
256
257     public final void flush() throws IOException JavaDoc {
258         impl.flush();
259     }
260
261     public final void close() throws IOException JavaDoc {
262         impl.close();
263     }
264
265     // com.sun.corba.se.impl.encoding.MarshalOutputStream
266
public final void start_block() {
267         impl.start_block();
268     }
269
270     public final void end_block() {
271         impl.end_block();
272     }
273
274     public final void putEndian() {
275         impl.putEndian();
276     }
277
278     public void writeTo(java.io.OutputStream JavaDoc s)
279     throws IOException JavaDoc
280     {
281         impl.writeTo(s);
282     }
283
284     public final byte[] toByteArray() {
285         return impl.toByteArray();
286     }
287
288     // org.omg.CORBA.DataOutputStream
289
public final void write_Abstract (java.lang.Object JavaDoc value) {
290         impl.write_Abstract(value);
291     }
292
293     public final void write_Value (java.io.Serializable JavaDoc value) {
294         impl.write_Value(value);
295     }
296
297     public final void write_any_array(org.omg.CORBA.Any JavaDoc[] seq, int offset, int length) {
298         impl.write_any_array(seq, offset, length);
299     }
300
301     public void setMessageMediator(MessageMediator messageMediator)
302     {
303         this.corbaMessageMediator = (CorbaMessageMediator) messageMediator;
304     }
305
306     public MessageMediator getMessageMediator()
307     {
308         return corbaMessageMediator;
309     }
310
311     // org.omg.CORBA.portable.ValueBase
312
public final String JavaDoc[] _truncatable_ids() {
313         return impl._truncatable_ids();
314     }
315
316     // Other
317
protected final int getSize() {
318         return impl.getSize();
319     }
320
321     protected final int getIndex() {
322         return impl.getIndex();
323     }
324
325     protected int getRealIndex(int index) {
326         // Used in indirections. Overridden by TypeCodeOutputStream.
327
return index;
328     }
329
330     protected final void setIndex(int value) {
331         impl.setIndex(value);
332     }
333
334     protected final ByteBuffer JavaDoc getByteBuffer() {
335         return impl.getByteBuffer();
336     }
337
338     protected final void setByteBuffer(ByteBuffer JavaDoc byteBuffer) {
339         impl.setByteBuffer(byteBuffer);
340     }
341
342     public final boolean isLittleEndian() {
343         return impl.isLittleEndian();
344     }
345
346     // XREVISIT - return to final if possible
347
// REVISIT - was protected - need access from msgtypes test.
348
public ByteBufferWithInfo getByteBufferWithInfo() {
349         return impl.getByteBufferWithInfo();
350     }
351
352     protected void setByteBufferWithInfo(ByteBufferWithInfo bbwi) {
353         impl.setByteBufferWithInfo(bbwi);
354     }
355
356     // REVISIT: was protected - but need to access from xgiop.
357
public final BufferManagerWrite getBufferManager() {
358         return impl.getBufferManager();
359     }
360
361     public final void write_fixed(java.math.BigDecimal JavaDoc bigDecimal, short digits, short scale) {
362         impl.write_fixed(bigDecimal, digits, scale);
363     }
364
365     public final void writeOctetSequenceTo(org.omg.CORBA.portable.OutputStream JavaDoc s) {
366         impl.writeOctetSequenceTo(s);
367     }
368
369     public final GIOPVersion getGIOPVersion() {
370         return impl.getGIOPVersion();
371     }
372
373     public final void writeIndirection(int tag, int posIndirectedTo) {
374         impl.writeIndirection(tag, posIndirectedTo);
375     }
376
377     // Use Latin-1 for GIOP 1.0 or when code set negotiation was not
378
// performed.
379
protected CodeSetConversion.CTBConverter createCharCTBConverter() {
380         return CodeSetConversion.impl().getCTBConverter(OSFCodeSetRegistry.ISO_8859_1);
381     }
382
383     // Subclasses must decide what to do here. It's inconvenient to
384
// make the class and this method abstract because of dup().
385
protected abstract CodeSetConversion.CTBConverter createWCharCTBConverter();
386
387     protected final void freeInternalCaches() {
388         impl.freeInternalCaches();
389     }
390
391     void printBuffer() {
392         impl.printBuffer();
393     }
394
395     public void alignOnBoundary(int octetBoundary) {
396         impl.alignOnBoundary(octetBoundary);
397     }
398
399     // Needed by request and reply messages for GIOP versions >= 1.2 only.
400
public void setHeaderPadding(boolean headerPadding) {
401         impl.setHeaderPadding(headerPadding);
402     }
403
404     // ValueOutputStream -----------------------------
405

406     public void start_value(String JavaDoc rep_id) {
407         impl.start_value(rep_id);
408     }
409
410     public void end_value() {
411         impl.end_value();
412     }
413 }
414
Popular Tags