1 7 8 package com.sun.corba.se.impl.ior; 9 10 import java.util.ListIterator ; 11 import java.util.Iterator ; 12 import java.util.Map ; 13 import java.util.HashMap ; 14 15 import java.io.StringWriter ; 16 import java.io.IOException ; 17 18 import javax.rmi.CORBA.Util ; 19 20 import org.omg.CORBA_2_3.portable.InputStream ; 21 import org.omg.CORBA_2_3.portable.OutputStream ; 22 23 import org.omg.IOP.TAG_INTERNET_IOP ; 24 25 import com.sun.corba.se.spi.ior.ObjectId ; 26 import com.sun.corba.se.spi.ior.TaggedProfileTemplate ; 27 import com.sun.corba.se.spi.ior.TaggedProfile ; 28 import com.sun.corba.se.spi.ior.IOR ; 29 import com.sun.corba.se.spi.ior.IORTemplate ; 30 import com.sun.corba.se.spi.ior.IORTemplateList ; 31 import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ; 32 import com.sun.corba.se.spi.ior.IdentifiableContainerBase ; 33 import com.sun.corba.se.spi.ior.ObjectKeyTemplate ; 34 import com.sun.corba.se.spi.ior.IORFactories ; 35 36 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 37 38 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry; 39 40 import com.sun.corba.se.spi.orb.ORB; 41 42 import com.sun.corba.se.spi.logging.CORBALogDomains; 43 44 import com.sun.corba.se.impl.encoding.MarshalOutputStream; 45 46 import com.sun.corba.se.impl.encoding.EncapsOutputStream; 47 48 import com.sun.corba.se.impl.orbutil.HexOutputStream; 49 import com.sun.corba.se.impl.orbutil.ORBConstants; 50 51 import com.sun.corba.se.impl.logging.IORSystemException ; 52 53 import com.sun.corba.se.spi.ior.iiop.IIOPProfile ; 55 56 63 public class IORImpl extends IdentifiableContainerBase implements IOR 64 { 65 private String typeId; 66 private ORB factory = null ; 67 private boolean isCachedHashValue = false; 68 private int cachedHashValue; 69 IORSystemException wrapper ; 70 71 public ORB getORB() 72 { 73 return factory ; 74 } 75 76 84 private IORTemplateList iortemps = null ; 85 86 public boolean equals( Object obj ) 87 { 88 if (obj == null) 89 return false ; 90 91 if (!(obj instanceof IOR)) 92 return false ; 93 94 IOR other = (IOR)obj ; 95 96 return super.equals( obj ) && typeId.equals( other.getTypeId() ) ; 97 } 98 99 public synchronized int hashCode() 100 { 101 if (! isCachedHashValue) { 102 cachedHashValue = (super.hashCode() ^ typeId.hashCode()); 103 isCachedHashValue = true; 104 } 105 return cachedHashValue; 106 } 107 108 110 public IORImpl( ORB orb ) 111 { 112 this( orb, "" ) ; 113 } 114 115 public IORImpl( ORB orb, String typeid ) 116 { 117 factory = orb ; 118 wrapper = IORSystemException.get( orb, 119 CORBALogDomains.OA_IOR ) ; 120 this.typeId = typeid ; 121 } 122 123 126 public IORImpl( ORB orb, String typeId, IORTemplate iortemp, ObjectId id) 127 { 128 this( orb, typeId ) ; 129 130 this.iortemps = IORFactories.makeIORTemplateList() ; 131 this.iortemps.add( iortemp ) ; 132 133 addTaggedProfiles( iortemp, id ) ; 134 135 makeImmutable() ; 136 } 137 138 private void addTaggedProfiles( IORTemplate iortemp, ObjectId id ) 139 { 140 ObjectKeyTemplate oktemp = iortemp.getObjectKeyTemplate() ; 141 Iterator templateIterator = iortemp.iterator() ; 142 143 while (templateIterator.hasNext()) { 144 TaggedProfileTemplate ptemp = 145 (TaggedProfileTemplate)(templateIterator.next()) ; 146 147 TaggedProfile profile = ptemp.create( oktemp, id ) ; 148 149 add( profile ) ; 150 } 151 } 152 153 156 public IORImpl( ORB orb, String typeId, IORTemplateList iortemps, ObjectId id) 157 { 158 this( orb, typeId ) ; 159 160 this.iortemps = iortemps ; 161 162 Iterator iter = iortemps.iterator() ; 163 while (iter.hasNext()) { 164 IORTemplate iortemp = (IORTemplate)(iter.next()) ; 165 addTaggedProfiles( iortemp, id ) ; 166 } 167 168 makeImmutable() ; 169 } 170 171 public IORImpl(InputStream is) 172 { 173 this( (ORB)(is.orb()), is.read_string() ) ; 174 175 IdentifiableFactoryFinder finder = 176 factory.getTaggedProfileFactoryFinder() ; 177 178 EncapsulationUtility.readIdentifiableSequence( this, finder, is ) ; 179 180 makeImmutable() ; 181 } 182 183 public String getTypeId() 184 { 185 return typeId ; 186 } 187 188 public void write(OutputStream os) 189 { 190 os.write_string( typeId ) ; 191 EncapsulationUtility.writeIdentifiableSequence( this, os ) ; 192 } 193 194 public String stringify() 195 { 196 StringWriter bs; 197 198 MarshalOutputStream s = new EncapsOutputStream(factory); 199 s.putEndian(); 200 write( (OutputStream )s ); 201 bs = new StringWriter (); 202 try { 203 s.writeTo(new HexOutputStream(bs)); 204 } catch (IOException ex) { 205 throw wrapper.stringifyWriteError( ex ) ; 206 } 207 208 return ORBConstants.STRINGIFY_PREFIX + bs; 209 } 210 211 public synchronized void makeImmutable() 212 { 213 makeElementsImmutable() ; 214 215 if (iortemps != null) 216 iortemps.makeImmutable() ; 217 218 super.makeImmutable() ; 219 } 220 221 public org.omg.IOP.IOR getIOPIOR() { 222 EncapsOutputStream os = new EncapsOutputStream(factory); 223 write(os); 224 InputStream is = (InputStream ) (os.create_input_stream()); 225 return org.omg.IOP.IORHelper.read(is); 226 } 227 228 public boolean isNil() 229 { 230 return ((size() == 0) ); 236 } 237 238 public boolean isEquivalent(IOR ior) 239 { 240 Iterator myIterator = iterator() ; 241 Iterator otherIterator = ior.iterator() ; 242 while (myIterator.hasNext() && otherIterator.hasNext()) { 243 TaggedProfile myProfile = (TaggedProfile)(myIterator.next()) ; 244 TaggedProfile otherProfile = (TaggedProfile)(otherIterator.next()) ; 245 if (!myProfile.isEquivalent( otherProfile )) 246 return false ; 247 } 248 249 return myIterator.hasNext() == otherIterator.hasNext() ; 250 } 251 252 private void initializeIORTemplateList() 253 { 254 Map oktempToIORTemplate = new HashMap () ; 256 257 iortemps = IORFactories.makeIORTemplateList() ; 258 Iterator iter = iterator() ; 259 ObjectId oid = null ; while (iter.hasNext()) { 261 TaggedProfile prof = (TaggedProfile)(iter.next()) ; 262 TaggedProfileTemplate ptemp = prof.getTaggedProfileTemplate() ; 263 ObjectKeyTemplate oktemp = prof.getObjectKeyTemplate() ; 264 265 if (oid == null) 268 oid = prof.getObjectId() ; 269 else if (!oid.equals( prof.getObjectId() )) 270 throw wrapper.badOidInIorTemplateList() ; 271 272 IORTemplate iortemp = (IORTemplate)(oktempToIORTemplate.get( oktemp )) ; 274 if (iortemp == null) { 275 iortemp = IORFactories.makeIORTemplate( oktemp ) ; 276 oktempToIORTemplate.put( oktemp, iortemp ) ; 277 iortemps.add( iortemp ) ; 278 } 279 280 iortemp.add( ptemp ) ; 281 } 282 283 iortemps.makeImmutable() ; 284 } 285 286 292 public synchronized IORTemplateList getIORTemplates() 293 { 294 if (iortemps == null) 295 initializeIORTemplateList() ; 296 297 return iortemps ; 298 } 299 300 304 public IIOPProfile getProfile() 305 { 306 IIOPProfile iop = null ; 307 Iterator iter = iteratorById( TAG_INTERNET_IOP.value ) ; 308 if (iter.hasNext()) 309 iop = (IIOPProfile)(iter.next()) ; 310 311 if (iop != null) 312 return iop ; 313 314 throw wrapper.iorMustHaveIiopProfile() ; 317 } 318 } 319 | Popular Tags |