1 7 8 package com.sun.corba.se.impl.ior; 9 10 import java.io.IOException ; 11 12 import org.omg.CORBA.MARSHAL ; 13 import org.omg.CORBA.OctetSeqHolder ; 14 import org.omg.CORBA_2_3.portable.InputStream ; 15 16 import com.sun.corba.se.spi.ior.ObjectId ; 17 import com.sun.corba.se.spi.ior.ObjectKey ; 18 import com.sun.corba.se.spi.ior.ObjectKeyFactory ; 19 import com.sun.corba.se.spi.ior.ObjectKeyTemplate ; 20 21 import com.sun.corba.se.spi.orb.ORB ; 22 import com.sun.corba.se.spi.logging.CORBALogDomains ; 23 24 import com.sun.corba.se.impl.orbutil.ORBConstants ; 25 26 import com.sun.corba.se.impl.ior.JIDLObjectKeyTemplate ; 27 import com.sun.corba.se.impl.ior.POAObjectKeyTemplate ; 28 import com.sun.corba.se.impl.ior.WireObjectKeyTemplate ; 29 import com.sun.corba.se.impl.ior.ObjectIdImpl ; 30 import com.sun.corba.se.impl.ior.ObjectKeyImpl ; 31 import com.sun.corba.se.impl.logging.IORSystemException ; 32 33 import com.sun.corba.se.impl.encoding.EncapsInputStream ; 34 35 39 interface Handler { 40 ObjectKeyTemplate handle( int magic, int scid, 41 InputStream is, OctetSeqHolder osh ) ; 42 } 43 44 48 public class ObjectKeyFactoryImpl implements ObjectKeyFactory 49 { 50 public static final int MAGIC_BASE = 0xAFABCAFE ; 51 52 public static final int JAVAMAGIC_OLD = MAGIC_BASE ; 55 56 public static final int JAVAMAGIC_NEW = MAGIC_BASE + 1 ; 58 59 public static final int JAVAMAGIC_NEWER = MAGIC_BASE + 2 ; 63 64 public static final int MAX_MAGIC = JAVAMAGIC_NEWER ; 65 66 public static final byte JDK1_3_1_01_PATCH_LEVEL = 1; 70 71 private final ORB orb ; 72 private IORSystemException wrapper ; 73 74 public ObjectKeyFactoryImpl( ORB orb ) 75 { 76 this.orb = orb ; 77 wrapper = IORSystemException.get( orb, 78 CORBALogDomains.OA_IOR ) ; 79 } 80 81 107 110 private Handler fullKey = new Handler() { 111 public ObjectKeyTemplate handle( int magic, int scid, 112 InputStream is, OctetSeqHolder osh ) { 113 ObjectKeyTemplate oktemp = null ; 114 115 if ((scid >= ORBConstants.FIRST_POA_SCID) && 116 (scid <= ORBConstants.MAX_POA_SCID)) { 117 if (magic >= JAVAMAGIC_NEWER) 118 oktemp = new POAObjectKeyTemplate( orb, magic, scid, is, osh ) ; 119 else 120 oktemp = new OldPOAObjectKeyTemplate( orb, magic, scid, is, osh ) ; 121 } else if ((scid >= 0) && (scid < ORBConstants.FIRST_POA_SCID)) { 122 if (magic >= JAVAMAGIC_NEWER) 123 oktemp = new JIDLObjectKeyTemplate( orb, magic, scid, is, osh ) ; 124 else 125 oktemp = new OldJIDLObjectKeyTemplate( orb, magic, scid, is, osh ); 126 } 127 128 return oktemp ; 129 } 130 } ; 131 132 134 private Handler oktempOnly = new Handler() { 135 public ObjectKeyTemplate handle( int magic, int scid, 136 InputStream is, OctetSeqHolder osh ) { 137 ObjectKeyTemplate oktemp = null ; 138 139 if ((scid >= ORBConstants.FIRST_POA_SCID) && 140 (scid <= ORBConstants.MAX_POA_SCID)) { 141 if (magic >= JAVAMAGIC_NEWER) 142 oktemp = new POAObjectKeyTemplate( orb, magic, scid, is ) ; 143 else 144 oktemp = new OldPOAObjectKeyTemplate( orb, magic, scid, is ) ; 145 } else if ((scid >= 0) && (scid < ORBConstants.FIRST_POA_SCID)) { 146 if (magic >= JAVAMAGIC_NEWER) 147 oktemp = new JIDLObjectKeyTemplate( orb, magic, scid, is ) ; 148 else 149 oktemp = new OldJIDLObjectKeyTemplate( orb, magic, scid, is ) ; 150 } 151 152 return oktemp ; 153 } 154 } ; 155 156 159 private boolean validMagic( int magic ) 160 { 161 return (magic >= MAGIC_BASE) && (magic <= MAX_MAGIC) ; 162 } 163 164 167 private ObjectKeyTemplate create( InputStream is, Handler handler, 168 OctetSeqHolder osh ) 169 { 170 ObjectKeyTemplate oktemp = null ; 171 172 try { 173 is.mark(0) ; 174 int magic = is.read_long() ; 175 176 if (validMagic( magic )) { 177 int scid = is.read_long() ; 178 oktemp = handler.handle( magic, scid, is, osh ) ; 179 } 180 } catch (MARSHAL mexc) { 181 } 184 185 if (oktemp == null) 186 try { 190 is.reset() ; 191 } catch (IOException exc) { 192 } 195 196 return oktemp ; 197 } 198 199 public ObjectKey create( byte[] key ) 200 { 201 OctetSeqHolder osh = new OctetSeqHolder () ; 202 EncapsInputStream is = new EncapsInputStream( orb, key, key.length ) ; 203 204 ObjectKeyTemplate oktemp = create( is, fullKey, osh ) ; 205 if (oktemp == null) 206 oktemp = new WireObjectKeyTemplate( is, osh ) ; 207 208 ObjectId oid = new ObjectIdImpl( osh.value ) ; 209 return new ObjectKeyImpl( oktemp, oid ) ; 210 } 211 212 public ObjectKeyTemplate createTemplate( InputStream is ) 213 { 214 ObjectKeyTemplate oktemp = create( is, oktempOnly, null ) ; 215 if (oktemp == null) 216 oktemp = new WireObjectKeyTemplate( orb ) ; 217 218 return oktemp ; 219 } 220 } 221 | Popular Tags |