1 7 8 package com.sun.corba.se.impl.ior.iiop; 9 10 import java.util.List ; 11 import java.util.Iterator ; 12 13 import org.omg.CORBA.SystemException ; 14 15 import org.omg.CORBA_2_3.portable.OutputStream ; 16 import org.omg.CORBA_2_3.portable.InputStream ; 17 18 import org.omg.IOP.TAG_ALTERNATE_IIOP_ADDRESS ; 19 import org.omg.IOP.TAG_INTERNET_IOP ; 20 import org.omg.IOP.TAG_JAVA_CODEBASE ; 21 22 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry ; 23 24 import com.sun.corba.se.spi.oa.ObjectAdapter ; 25 import com.sun.corba.se.spi.oa.ObjectAdapterFactory ; 26 27 import com.sun.corba.se.spi.ior.ObjectId ; 28 import com.sun.corba.se.spi.ior.ObjectAdapterId ; 29 import com.sun.corba.se.spi.ior.TaggedProfile ; 30 import com.sun.corba.se.spi.ior.TaggedProfileTemplate ; 31 import com.sun.corba.se.spi.ior.ObjectKey ; 32 import com.sun.corba.se.spi.ior.ObjectKeyTemplate ; 33 import com.sun.corba.se.spi.ior.TaggedComponent ; 34 import com.sun.corba.se.spi.ior.IdentifiableBase ; 35 import com.sun.corba.se.spi.ior.IORFactories ; 36 import com.sun.corba.se.spi.ior.ObjectKeyFactory ; 37 38 import com.sun.corba.se.spi.ior.iiop.IIOPAddress ; 39 import com.sun.corba.se.spi.ior.iiop.IIOPProfile ; 40 import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ; 41 import com.sun.corba.se.spi.ior.iiop.IIOPFactories ; 42 import com.sun.corba.se.spi.ior.iiop.GIOPVersion ; 43 import com.sun.corba.se.spi.ior.iiop.JavaCodebaseComponent ; 44 45 import com.sun.corba.se.spi.orb.ORB ; 46 import com.sun.corba.se.spi.orb.ORBVersion ; 47 48 import com.sun.corba.se.spi.logging.CORBALogDomains ; 49 50 import com.sun.corba.se.impl.ior.EncapsulationUtility ; 51 52 import com.sun.corba.se.impl.encoding.EncapsInputStream ; 53 import com.sun.corba.se.impl.encoding.EncapsOutputStream ; 54 55 import com.sun.corba.se.impl.util.JDKBridge; 56 57 import com.sun.corba.se.impl.logging.IORSystemException; 58 59 62 public class IIOPProfileImpl extends IdentifiableBase implements IIOPProfile 63 { 64 private ORB orb ; 65 private IORSystemException wrapper ; 66 private ObjectId oid; 67 private IIOPProfileTemplate proftemp; 68 private ObjectKeyTemplate oktemp ; 69 70 protected String codebase = null ; 72 protected boolean cachedCodebase = false; 73 74 private boolean checkedIsLocal = false ; 75 private boolean cachedIsLocal = false ; 76 77 private static class LocalCodeBaseSingletonHolder { 79 public static JavaCodebaseComponent comp ; 80 81 static { 82 String localCodebase = JDKBridge.getLocalCodebase() ; 83 if (localCodebase == null) 84 comp = null ; 85 else 86 comp = IIOPFactories.makeJavaCodebaseComponent( 87 localCodebase ) ; 88 } 89 } 90 91 private GIOPVersion giopVersion = null; 92 93 public boolean equals( Object obj ) 94 { 95 if (!(obj instanceof IIOPProfileImpl)) 96 return false ; 97 98 IIOPProfileImpl other = (IIOPProfileImpl)obj ; 99 100 return oid.equals( other.oid ) && proftemp.equals( other.proftemp ) && 101 oktemp.equals( other.oktemp ) ; 102 } 103 104 public int hashCode() 105 { 106 return oid.hashCode() ^ proftemp.hashCode() ^ oktemp.hashCode() ; 107 } 108 109 public ObjectId getObjectId() 110 { 111 return oid ; 112 } 113 114 public TaggedProfileTemplate getTaggedProfileTemplate() 115 { 116 return proftemp ; 117 } 118 119 public ObjectKeyTemplate getObjectKeyTemplate() 120 { 121 return oktemp ; 122 } 123 124 private IIOPProfileImpl( ORB orb ) 125 { 126 this.orb = orb ; 127 wrapper = IORSystemException.get( orb, 128 CORBALogDomains.OA_IOR ) ; 129 } 130 131 public IIOPProfileImpl( ORB orb, ObjectKeyTemplate oktemp, ObjectId oid, 132 IIOPProfileTemplate proftemp ) 133 { 134 this( orb ) ; 135 this.oktemp = oktemp ; 136 this.oid = oid ; 137 this.proftemp = proftemp ; 138 } 139 140 public IIOPProfileImpl( InputStream is ) 141 { 142 this( (ORB)(is.orb()) ) ; 143 init( is ) ; 144 } 145 146 public IIOPProfileImpl( ORB orb, org.omg.IOP.TaggedProfile profile) 147 { 148 this( orb ) ; 149 150 if (profile == null || profile.tag != TAG_INTERNET_IOP.value || 151 profile.profile_data == null) { 152 throw wrapper.invalidTaggedProfile() ; 153 } 154 155 EncapsInputStream istr = new EncapsInputStream((ORB)orb, profile.profile_data, 156 profile.profile_data.length); 157 istr.consumeEndian(); 158 init( istr ) ; 159 } 160 161 private void init( InputStream istr ) 162 { 163 GIOPVersion version = new GIOPVersion() ; 165 version.read( istr ) ; 166 IIOPAddress primary = new IIOPAddressImpl( istr ) ; 167 byte[] key = EncapsulationUtility.readOctets( istr ) ; 168 169 ObjectKey okey = orb.getObjectKeyFactory().create( key ) ; 170 oktemp = okey.getTemplate() ; 171 oid = okey.getId() ; 172 173 proftemp = IIOPFactories.makeIIOPProfileTemplate( orb, 174 version, primary ) ; 175 176 if (version.getMinor() > 0) 178 EncapsulationUtility.readIdentifiableSequence( proftemp, 179 orb.getTaggedComponentFactoryFinder(), istr ) ; 180 181 if (uncachedGetCodeBase() == null) { 187 JavaCodebaseComponent jcc = LocalCodeBaseSingletonHolder.comp ; 188 189 if (jcc != null) { 190 if (version.getMinor() > 0) 191 proftemp.add( jcc ) ; 192 193 codebase = jcc.getURLs() ; 194 } 195 196 cachedCodebase = true; 199 } 200 } 201 202 public void writeContents(OutputStream os) 203 { 204 proftemp.write( oktemp, oid, os ) ; 205 } 206 207 public int getId() 208 { 209 return proftemp.getId() ; 210 } 211 212 public boolean isEquivalent( TaggedProfile prof ) 213 { 214 if (!(prof instanceof IIOPProfile)) 215 return false ; 216 217 IIOPProfile other = (IIOPProfile)prof ; 218 219 return oid.equals( other.getObjectId() ) && 220 proftemp.isEquivalent( other.getTaggedProfileTemplate() ) && 221 oktemp.equals( other.getObjectKeyTemplate() ) ; 222 } 223 224 public ObjectKey getObjectKey() 225 { 226 ObjectKey result = IORFactories.makeObjectKey( oktemp, oid ) ; 227 return result ; 228 } 229 230 public org.omg.IOP.TaggedProfile getIOPProfile() 231 { 232 EncapsOutputStream os = new EncapsOutputStream( orb ) ; 233 os.write_long( getId() ) ; 234 write( os ) ; 235 InputStream is = (InputStream )(os.create_input_stream()) ; 236 return org.omg.IOP.TaggedProfileHelper.read( is ) ; 237 } 238 239 private String uncachedGetCodeBase() { 240 Iterator iter = proftemp.iteratorById( TAG_JAVA_CODEBASE.value ) ; 241 242 if (iter.hasNext()) { 243 JavaCodebaseComponent jcbc = (JavaCodebaseComponent)(iter.next()) ; 244 return jcbc.getURLs() ; 245 } 246 247 return null ; 248 } 249 250 public synchronized String getCodebase() { 251 if (!cachedCodebase) { 252 cachedCodebase = true ; 253 codebase = uncachedGetCodeBase() ; 254 } 255 256 return codebase ; 257 } 258 259 262 public ORBVersion getORBVersion() { 263 return oktemp.getORBVersion(); 264 } 265 266 public synchronized boolean isLocal() 267 { 268 if (!checkedIsLocal) { 269 checkedIsLocal = true ; 270 String host = proftemp.getPrimaryAddress().getHost() ; 271 272 cachedIsLocal = orb.isLocalHost(host) && 273 orb.isLocalServerId(oktemp.getSubcontractId(), 274 oktemp.getServerId()) && 275 orb.getLegacyServerSocketManager() 276 .legacyIsLocalServerPort( 277 proftemp.getPrimaryAddress().getPort()); 278 } 279 280 return cachedIsLocal ; 281 } 282 283 289 public java.lang.Object getServant() 290 { 291 if (!isLocal()) 292 return null ; 293 294 RequestDispatcherRegistry scr = orb.getRequestDispatcherRegistry() ; 295 ObjectAdapterFactory oaf = scr.getObjectAdapterFactory( 296 oktemp.getSubcontractId() ) ; 297 298 ObjectAdapterId oaid = oktemp.getObjectAdapterId() ; 299 ObjectAdapter oa = null ; 300 301 try { 302 oa = oaf.find( oaid ) ; 303 } catch (SystemException exc) { 304 wrapper.getLocalServantFailure( exc, oaid.toString() ) ; 308 return null ; 309 } 310 311 byte[] boid = oid.getId() ; 312 java.lang.Object servant = oa.getLocalServant( boid ) ; 313 return servant ; 314 } 315 316 321 public synchronized GIOPVersion getGIOPVersion() 322 { 323 return proftemp.getGIOPVersion() ; 324 } 325 326 public void makeImmutable() 327 { 328 proftemp.makeImmutable() ; 329 } 330 } 331 | Popular Tags |