1 7 8 package com.sun.corba.se.impl.ior; 9 10 import java.util.Iterator ; 11 12 import org.omg.CORBA_2_3.portable.InputStream ; 13 import org.omg.CORBA_2_3.portable.OutputStream ; 14 15 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ; 16 17 import com.sun.corba.se.spi.ior.ObjectId ; 18 import com.sun.corba.se.spi.ior.ObjectAdapterId ; 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.orb.ORBVersion ; 23 24 import com.sun.corba.se.spi.logging.CORBALogDomains ; 25 26 27 import com.sun.corba.se.impl.encoding.EncapsOutputStream ; 28 29 import com.sun.corba.se.impl.logging.IORSystemException ; 30 31 32 35 public abstract class ObjectKeyTemplateBase implements ObjectKeyTemplate 36 { 37 public static final String JIDL_ORB_ID = "" ; 39 private static final String [] JIDL_OAID_STRINGS = { "TransientObjectAdapter" } ; 40 public static final ObjectAdapterId JIDL_OAID = new ObjectAdapterIdArray( JIDL_OAID_STRINGS ) ; 41 42 private ORB orb ; 43 protected IORSystemException wrapper ; 44 private ORBVersion version ; 45 private int magic ; 46 private int scid ; 47 private int serverid ; 48 private String orbid ; 49 private ObjectAdapterId oaid ; 50 51 private byte[] adapterId ; 52 53 public byte[] getAdapterId() 54 { 55 return (byte[])(adapterId.clone()) ; 56 } 57 58 private byte[] computeAdapterId() 59 { 60 ByteBuffer buff = new ByteBuffer() ; 62 63 buff.append( getServerId() ) ; 64 buff.append( orbid ) ; 65 66 buff.append( oaid.getNumLevels() ) ; 67 Iterator iter = oaid.iterator() ; 68 while (iter.hasNext()) { 69 String comp = (String )(iter.next()) ; 70 buff.append( comp ) ; 71 } 72 73 buff.trimToSize() ; 74 75 return buff.toArray() ; 76 } 77 78 public ObjectKeyTemplateBase( ORB orb, int magic, int scid, int serverid, 79 String orbid, ObjectAdapterId oaid ) 80 { 81 this.orb = orb ; 82 this.wrapper = IORSystemException.get( orb, 83 CORBALogDomains.OA_IOR ) ; 84 this.magic = magic ; 85 this.scid = scid ; 86 this.serverid = serverid ; 87 this.orbid = orbid ; 88 this.oaid = oaid ; 89 90 adapterId = computeAdapterId() ; 91 } 92 93 public boolean equals( Object obj ) 94 { 95 if (!(obj instanceof ObjectKeyTemplateBase)) 96 return false ; 97 98 ObjectKeyTemplateBase other = (ObjectKeyTemplateBase)obj ; 99 100 return (magic == other.magic) && (scid == other.scid) && 101 (serverid == other.serverid) && (version.equals( other.version ) && 102 orbid.equals( other.orbid ) && oaid.equals( other.oaid )) ; 103 } 104 105 public int hashCode() 106 { 107 int result = 17 ; 108 result = 37*result + magic ; 109 result = 37*result + scid ; 110 result = 37*result + serverid ; 111 result = 37*result + version.hashCode() ; 112 result = 37*result + orbid.hashCode() ; 113 result = 37*result + oaid.hashCode() ; 114 return result ; 115 } 116 117 public int getSubcontractId() 118 { 119 return scid ; 120 } 121 122 public int getServerId() 123 { 124 return serverid ; 125 } 126 127 public String getORBId() 128 { 129 return orbid ; 130 } 131 132 public ObjectAdapterId getObjectAdapterId() 133 { 134 return oaid ; 135 } 136 137 public void write(ObjectId objectId, OutputStream os) 138 { 139 writeTemplate( os ) ; 140 objectId.write( os ) ; 141 } 142 143 public void write( OutputStream os ) 144 { 145 writeTemplate( os ) ; 146 } 147 148 abstract protected void writeTemplate( OutputStream os ) ; 149 150 protected int getMagic() 151 { 152 return magic ; 153 } 154 155 public void setORBVersion( ORBVersion version ) 158 { 159 this.version = version ; 160 } 161 162 public ORBVersion getORBVersion() 163 { 164 return version ; 165 } 166 167 protected byte[] readObjectKey( InputStream is ) 168 { 169 int len = is.read_long() ; 170 byte[] result = new byte[len] ; 171 is.read_octet_array( result, 0, len ) ; 172 return result ; 173 } 174 175 public CorbaServerRequestDispatcher getServerRequestDispatcher( ORB orb, ObjectId id ) 176 { 177 return orb.getRequestDispatcherRegistry().getServerRequestDispatcher( scid ) ; 178 } 179 } 180 | Popular Tags |