KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)CDRInputObject.java 1.38 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
8 package com.sun.corba.se.impl.encoding;
9
10 import java.nio.ByteBuffer JavaDoc;
11
12 import com.sun.org.omg.SendingContext.CodeBase;
13
14 import com.sun.corba.se.pept.encoding.InputObject;
15
16 import com.sun.corba.se.spi.logging.CORBALogDomains;
17
18 import com.sun.corba.se.spi.orb.ORB;
19
20 import com.sun.corba.se.spi.transport.CorbaConnection;
21
22 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
23
24 import com.sun.corba.se.impl.encoding.BufferManagerFactory;
25 import com.sun.corba.se.impl.encoding.CodeSetComponentInfo;
26 import com.sun.corba.se.impl.encoding.CodeSetConversion;
27 import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;
28 import com.sun.corba.se.impl.encoding.CDRInputStream;
29
30 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
31
32 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
33 import com.sun.corba.se.impl.logging.OMGSystemException;
34
35 import com.sun.corba.se.impl.orbutil.ORBUtility;
36
37 /**
38  * @author Harold Carr
39  */

40 public class CDRInputObject extends CDRInputStream
41     implements
42     InputObject
43 {
44     private CorbaConnection corbaConnection;
45     private Message header;
46     private boolean unmarshaledHeader;
47     private ORB orb ;
48     private ORBUtilSystemException wrapper ;
49     private OMGSystemException omgWrapper ;
50
51     public CDRInputObject(ORB orb,
52               CorbaConnection corbaConnection,
53               ByteBuffer JavaDoc byteBuffer,
54               Message header)
55     {
56         super(orb, byteBuffer, header.getSize(), header.isLittleEndian(),
57               header.getGIOPVersion(), header.getEncodingVersion(),
58               BufferManagerFactory.newBufferManagerRead(
59                       header.getGIOPVersion(),
60                       header.getEncodingVersion(),
61                       orb));
62
63     this.corbaConnection = corbaConnection;
64     this.orb = orb ;
65     this.wrapper = ORBUtilSystemException.get( orb,
66         CORBALogDomains.RPC_ENCODING ) ;
67     this.omgWrapper = OMGSystemException.get( orb,
68         CORBALogDomains.RPC_ENCODING ) ;
69
70     if (orb.transportDebugFlag) {
71         dprint(".CDRInputObject constructor:");
72     }
73
74         getBufferManager().init(header);
75
76         this.header = header;
77
78         unmarshaledHeader = false;
79
80         setIndex(Message.GIOPMessageHeaderLength);
81
82         setBufferLength(header.getSize());
83     }
84
85     // REVISIT - think about this some more.
86
// This connection normally is accessed from the message mediator.
87
// However, giop input needs to get code set info from the connetion
88
// *before* the message mediator is available.
89
public final CorbaConnection getConnection()
90     {
91         return corbaConnection;
92     }
93
94     // XREVISIT - Should the header be kept in the stream or the
95
// message mediator? Or should we not have a header and
96
// have the information stored in the message mediator
97
// directly?
98
public Message getMessageHeader()
99     {
100         return header;
101     }
102
103     /**
104      * Unmarshal the extended GIOP header
105      * NOTE: May be fragmented, so should not be called by the ReaderThread.
106      * See CorbaResponseWaitingRoomImpl.waitForResponse. It is done
107      * there in the client thread.
108      */

109     public void unmarshalHeader()
110     {
111         // Unmarshal the extended GIOP message from the buffer.
112

113         if (!unmarshaledHeader) {
114         try {
115         if (((ORB)orb()).transportDebugFlag) {
116             dprint(".unmarshalHeader->: " + getMessageHeader());
117         }
118         getMessageHeader().read(this);
119         unmarshaledHeader= true;
120         } catch (RuntimeException JavaDoc e) {
121         if (((ORB)orb()).transportDebugFlag) {
122             dprint(".unmarshalHeader: !!ERROR!!: "
123                + getMessageHeader()
124                + ": " + e);
125         }
126         throw e;
127         } finally {
128         if (((ORB)orb()).transportDebugFlag) {
129             dprint(".unmarshalHeader<-: " + getMessageHeader());
130         }
131         }
132         }
133     }
134
135     public final boolean unmarshaledHeader()
136     {
137         return unmarshaledHeader;
138     }
139
140     /**
141      * Override the default CDR factory behavior to get the
142      * negotiated code sets from the connection.
143      *
144      * These are only called once per message, the first time needed.
145      *
146      * In the local case, there is no Connection, so use the
147      * local code sets.
148      */

149     protected CodeSetConversion.BTCConverter createCharBTCConverter() {
150         CodeSetComponentInfo.CodeSetContext codesets = getCodeSets();
151
152         // If the connection doesn't have its negotiated
153
// code sets by now, fall back on the defaults defined
154
// in CDRInputStream.
155
if (codesets == null)
156             return super.createCharBTCConverter();
157         
158         OSFCodeSetRegistry.Entry charSet
159             = OSFCodeSetRegistry.lookupEntry(codesets.getCharCodeSet());
160
161         if (charSet == null)
162         throw wrapper.unknownCodeset( charSet ) ;
163
164         return CodeSetConversion.impl().getBTCConverter(charSet, isLittleEndian());
165     }
166
167     protected CodeSetConversion.BTCConverter createWCharBTCConverter() {
168
169         CodeSetComponentInfo.CodeSetContext codesets = getCodeSets();
170
171         // If the connection doesn't have its negotiated
172
// code sets by now, we have to throw an exception.
173
// See CORBA formal 00-11-03 13.9.2.6.
174
if (codesets == null) {
175             if (getConnection().isServer())
176         throw omgWrapper.noClientWcharCodesetCtx() ;
177             else
178         throw omgWrapper.noServerWcharCodesetCmp() ;
179         }
180
181         OSFCodeSetRegistry.Entry wcharSet
182             = OSFCodeSetRegistry.lookupEntry(codesets.getWCharCodeSet());
183
184         if (wcharSet == null)
185         throw wrapper.unknownCodeset( wcharSet ) ;
186
187         // For GIOP 1.2 and UTF-16, use big endian if there is no byte
188
// order marker. (See issue 3405b)
189
//
190
// For GIOP 1.1 and UTF-16, use the byte order the stream if
191
// there isn't (and there shouldn't be) a byte order marker.
192
//
193
// GIOP 1.0 doesn't have wchars. If we're talking to a legacy ORB,
194
// we do what our old ORBs did.
195
if (wcharSet == OSFCodeSetRegistry.UTF_16) {
196             if (getGIOPVersion().equals(GIOPVersion.V1_2))
197                 return CodeSetConversion.impl().getBTCConverter(wcharSet, false);
198         }
199
200         return CodeSetConversion.impl().getBTCConverter(wcharSet, isLittleEndian());
201     }
202
203     // If we're local and don't have a Connection, use the
204
// local code sets, otherwise get them from the connection.
205
// If the connection doesn't have negotiated code sets
206
// yet, then we use ISO8859-1 for char/string and wchar/wstring
207
// are illegal.
208
private CodeSetComponentInfo.CodeSetContext getCodeSets() {
209         if (getConnection() == null)
210             return CodeSetComponentInfo.LOCAL_CODE_SETS;
211         else
212             return getConnection().getCodeSetContext();
213     }
214
215     public final CodeBase getCodeBase() {
216         if (getConnection() == null)
217             return null;
218         else
219             return getConnection().getCodeBase();
220     }
221
222     // -----------------------------------------------------------
223
// Below this point are commented out methods with features
224
// from the old stream. We must find ways to address
225
// these issues in the future.
226
// -----------------------------------------------------------
227

228     // XREVISIT
229
// private XIIOPInputStream(XIIOPInputStream stream) {
230
// super(stream);
231

232 // this.conn = stream.conn;
233
// this.msg = stream.msg;
234
// this.unmarshaledHeader = stream.unmarshaledHeader;
235
// }
236

237     public CDRInputStream dup() {
238         // XREVISIT
239
return null;
240         // return new XIIOPInputStream(this);
241
}
242
243     protected void dprint(String JavaDoc msg)
244     {
245     ORBUtility.dprint("CDRInputObject", msg);
246     }
247 }
248
249 // End of file.
250
Popular Tags