1 7 8 package com.sun.corba.se.impl.encoding; 9 10 import com.sun.corba.se.impl.encoding.BufferManagerRead; 11 import com.sun.corba.se.impl.encoding.BufferManagerReadGrow; 12 import com.sun.corba.se.impl.encoding.BufferManagerReadStream; 13 import com.sun.corba.se.impl.encoding.BufferManagerWrite; 14 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message; 15 import com.sun.corba.se.impl.logging.ORBUtilSystemException; 16 import com.sun.corba.se.spi.logging.CORBALogDomains; 17 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 18 import com.sun.corba.se.spi.orb.ORB; 19 20 import org.omg.CORBA.INTERNAL ; 21 22 26 27 public class BufferManagerFactory 28 { 29 public static final int GROW = 0; 30 public static final int COLLECT = 1; 31 public static final int STREAM = 2; 32 33 public static BufferManagerRead newBufferManagerRead( 37 GIOPVersion version, byte encodingVersion, ORB orb) { 38 39 43 if (encodingVersion != Message.CDR_ENC_VERSION) { 44 return new BufferManagerReadGrow(orb); 45 } 46 47 switch (version.intValue()) 48 { 49 case GIOPVersion.VERSION_1_0: 50 return new BufferManagerReadGrow(orb); 51 case GIOPVersion.VERSION_1_1: 52 case GIOPVersion.VERSION_1_2: 53 return new BufferManagerReadStream(orb); 56 default: 57 throw new INTERNAL ("Unknown GIOP version: " 59 + version); 60 } 61 } 62 63 public static BufferManagerRead newBufferManagerRead( 64 int strategy, byte encodingVersion, ORB orb) { 65 66 if (encodingVersion != Message.CDR_ENC_VERSION) { 67 if (strategy != BufferManagerFactory.GROW) { 68 ORBUtilSystemException wrapper = 69 ORBUtilSystemException.get((ORB)orb, 70 CORBALogDomains.RPC_ENCODING); 71 throw wrapper.invalidBuffMgrStrategy("newBufferManagerRead"); 72 } 73 return new BufferManagerReadGrow(orb); 74 } 75 switch (strategy) { 76 case BufferManagerFactory.GROW: 77 return new BufferManagerReadGrow(orb); 78 case BufferManagerFactory.COLLECT: 79 throw new INTERNAL ("Collect strategy invalid for reading"); 80 case BufferManagerFactory.STREAM: 81 return new BufferManagerReadStream(orb); 82 default: 83 throw new INTERNAL ("Unknown buffer manager read strategy: " 84 + strategy); 85 } 86 } 87 88 public static BufferManagerWrite newBufferManagerWrite( 89 int strategy, byte encodingVersion, ORB orb) { 90 if (encodingVersion != Message.CDR_ENC_VERSION) { 91 if (strategy != BufferManagerFactory.GROW) { 92 ORBUtilSystemException wrapper = 93 ORBUtilSystemException.get((ORB)orb, 94 CORBALogDomains.RPC_ENCODING); 95 throw wrapper.invalidBuffMgrStrategy("newBufferManagerWrite"); 96 } 97 return new BufferManagerWriteGrow(orb); 98 } 99 switch (strategy) { 100 case BufferManagerFactory.GROW: 101 return new BufferManagerWriteGrow(orb); 102 case BufferManagerFactory.COLLECT: 103 return new BufferManagerWriteCollect(orb); 104 case BufferManagerFactory.STREAM: 105 return new BufferManagerWriteStream(orb); 106 default: 107 throw new INTERNAL ("Unknown buffer manager write strategy: " 108 + strategy); 109 } 110 } 111 112 public static BufferManagerWrite newBufferManagerWrite( 113 GIOPVersion version, byte encodingVersion, ORB orb) { 114 if (encodingVersion != Message.CDR_ENC_VERSION) { 115 return new BufferManagerWriteGrow(orb); 116 } 117 return BufferManagerFactory.newBufferManagerWrite( 118 orb.getORBData().getGIOPBuffMgrStrategy(version), 119 encodingVersion, orb); 120 } 121 122 public static BufferManagerRead defaultBufferManagerRead(ORB orb) { 123 return new BufferManagerReadGrow(orb); 124 } 125 } 126 | Popular Tags |