1 7 8 package com.sun.corba.se.impl.encoding; 9 10 import java.io.IOException ; 11 import java.nio.ByteBuffer ; 12 13 import org.omg.CORBA.Any ; 14 import org.omg.CORBA.Principal ; 15 import org.omg.CORBA.TypeCode ; 16 import org.omg.CORBA.portable.InputStream ; 17 18 import com.sun.corba.se.pept.encoding.OutputObject; 19 import com.sun.corba.se.pept.protocol.MessageMediator; 20 21 import com.sun.corba.se.spi.encoding.CorbaOutputObject ; 22 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 23 import com.sun.corba.se.spi.orb.ORB; 24 import com.sun.corba.se.spi.protocol.CorbaMessageMediator; 25 import com.sun.corba.se.pept.transport.ByteBufferPool; 26 import com.sun.corba.se.spi.transport.CorbaConnection; 27 import com.sun.corba.se.spi.logging.CORBALogDomains; 28 29 import com.sun.corba.se.spi.servicecontext.ServiceContexts; 30 import com.sun.corba.se.impl.encoding.BufferManagerFactory; 31 import com.sun.corba.se.impl.encoding.ByteBufferWithInfo; 32 import com.sun.corba.se.impl.encoding.CDROutputStream; 33 import com.sun.corba.se.impl.encoding.CDROutputStream_1_0; 34 import com.sun.corba.se.impl.encoding.CodeSetConversion; 35 import com.sun.corba.se.impl.encoding.CodeSetComponentInfo; 36 import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry; 37 import com.sun.corba.se.impl.orbutil.ORBUtility; 38 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message; 39 import com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase; 40 import com.sun.corba.se.impl.logging.ORBUtilSystemException; 41 import com.sun.corba.se.impl.logging.OMGSystemException; 42 43 46 public class CDROutputObject extends CorbaOutputObject 47 { 48 private Message header; 49 private ORB orb; 50 private ORBUtilSystemException wrapper; 51 private OMGSystemException omgWrapper; 52 53 private CorbaConnection connection; 55 56 private CDROutputObject( 57 ORB orb, GIOPVersion giopVersion, Message header, 58 BufferManagerWrite manager, byte streamFormatVersion, 59 CorbaMessageMediator mediator) 60 { 61 super(orb, giopVersion, header.getEncodingVersion(), 62 false, manager, streamFormatVersion, 63 ((mediator != null && mediator.getConnection() != null) ? 64 ((CorbaConnection)mediator.getConnection()). 65 shouldUseDirectByteBuffers() : false)); 66 67 this.header = header; 68 this.orb = orb; 69 this.wrapper = ORBUtilSystemException.get( orb, CORBALogDomains.RPC_ENCODING ) ; 70 this.omgWrapper = OMGSystemException.get( orb, CORBALogDomains.RPC_ENCODING ) ; 71 72 getBufferManager().setOutputObject(this); 73 this.corbaMessageMediator = mediator; 74 } 75 76 public CDROutputObject(ORB orb, 77 MessageMediator messageMediator, 78 Message header, 79 byte streamFormatVersion) 80 { 81 this( 82 orb, 83 ((CorbaMessageMediator)messageMediator).getGIOPVersion(), 84 header, 85 BufferManagerFactory.newBufferManagerWrite( 86 ((CorbaMessageMediator)messageMediator).getGIOPVersion(), 87 header.getEncodingVersion(), 88 orb), 89 streamFormatVersion, 90 (CorbaMessageMediator)messageMediator); 91 } 92 93 public CDROutputObject(ORB orb, 97 MessageMediator messageMediator, 98 Message header, 99 byte streamFormatVersion, 100 int strategy) 101 { 102 this( 103 orb, 104 ((CorbaMessageMediator)messageMediator).getGIOPVersion(), 105 header, 106 BufferManagerFactory. 107 newBufferManagerWrite(strategy, 108 header.getEncodingVersion(), 109 orb), 110 streamFormatVersion, 111 (CorbaMessageMediator)messageMediator); 112 } 113 114 public CDROutputObject(ORB orb, CorbaMessageMediator mediator, 118 GIOPVersion giopVersion, 119 CorbaConnection connection, Message header, 120 byte streamFormatVersion) 121 { 122 this( 123 orb, 124 giopVersion, 125 header, 126 BufferManagerFactory. 127 newBufferManagerWrite(giopVersion, 128 header.getEncodingVersion(), 129 orb), 130 streamFormatVersion, 131 mediator); 132 this.connection = connection ; 133 } 134 135 public Message getMessageHeader() { 140 return header; 141 } 142 143 public final void finishSendingMessage() { 144 getBufferManager().sendMessage(); 145 } 146 147 153 public void writeTo(CorbaConnection connection) 154 throws java.io.IOException 155 { 156 157 161 ByteBufferWithInfo bbwi = getByteBufferWithInfo(); 162 163 getMessageHeader().setSize(bbwi.byteBuffer, bbwi.getSize()); 164 165 if (orb() != null) { 166 if (((ORB)orb()).transportDebugFlag) { 167 dprint(".writeTo: " + connection); 168 } 169 if (((ORB)orb()).giopDebugFlag) { 170 CDROutputStream_1_0.printBuffer(bbwi); 171 } 172 } 173 bbwi.byteBuffer.position(0).limit(bbwi.getSize()); 174 connection.write(bbwi.byteBuffer); 175 } 176 177 178 public org.omg.CORBA.portable.InputStream create_input_stream() 179 { 180 return null; 182 } 185 186 public CorbaConnection getConnection() 187 { 188 if (connection != null) { 190 return connection; 191 } 192 return (CorbaConnection) corbaMessageMediator.getConnection(); 193 } 194 195 public final ByteBufferWithInfo getByteBufferWithInfo() { 200 return super.getByteBufferWithInfo(); 201 } 202 203 public final void setByteBufferWithInfo(ByteBufferWithInfo bbwi) { 205 super.setByteBufferWithInfo(bbwi); 206 } 207 208 217 protected CodeSetConversion.CTBConverter createCharCTBConverter() { 218 CodeSetComponentInfo.CodeSetContext codesets = getCodeSets(); 219 220 if (codesets == null) 224 return super.createCharCTBConverter(); 225 226 OSFCodeSetRegistry.Entry charSet 227 = OSFCodeSetRegistry.lookupEntry(codesets.getCharCodeSet()); 228 229 if (charSet == null) 230 throw wrapper.unknownCodeset( charSet ) ; 231 232 return CodeSetConversion.impl().getCTBConverter(charSet, 233 isLittleEndian(), 234 false); 235 } 236 237 protected CodeSetConversion.CTBConverter createWCharCTBConverter() { 238 239 CodeSetComponentInfo.CodeSetContext codesets = getCodeSets(); 240 241 if (codesets == null) { 245 if (getConnection().isServer()) 246 throw omgWrapper.noClientWcharCodesetCtx() ; 247 else 248 throw omgWrapper.noServerWcharCodesetCmp() ; 249 } 250 251 OSFCodeSetRegistry.Entry wcharSet 252 = OSFCodeSetRegistry.lookupEntry(codesets.getWCharCodeSet()); 253 254 if (wcharSet == null) 255 throw wrapper.unknownCodeset( wcharSet ) ; 256 257 boolean useByteOrderMarkers 258 = ((ORB)orb()).getORBData().useByteOrderMarkers(); 259 260 if (wcharSet == OSFCodeSetRegistry.UTF_16) { 268 if (getGIOPVersion().equals(GIOPVersion.V1_2)) { 269 return CodeSetConversion.impl().getCTBConverter(wcharSet, 270 false, 271 useByteOrderMarkers); 272 } 273 274 if (getGIOPVersion().equals(GIOPVersion.V1_1)) { 275 return CodeSetConversion.impl().getCTBConverter(wcharSet, 276 isLittleEndian(), 277 false); 278 } 279 } 280 281 return CodeSetConversion.impl().getCTBConverter(wcharSet, 283 isLittleEndian(), 284 useByteOrderMarkers); 285 } 286 287 private CodeSetComponentInfo.CodeSetContext getCodeSets() { 293 if (getConnection() == null) 294 return CodeSetComponentInfo.LOCAL_CODE_SETS; 295 else 296 return getConnection().getCodeSetContext(); 297 } 298 299 protected void dprint(String msg) 300 { 301 ORBUtility.dprint("CDROutputObject", msg); 302 } 303 } 304 305 | Popular Tags |