FileDocCategorySizeDatePackage
IORImpl.javaAPI DocJava SE 6 API8990Tue Jun 10 00:21:34 BST 2008com.sun.corba.se.impl.ior

IORImpl

public class IORImpl extends com.sun.corba.se.spi.ior.IdentifiableContainerBase implements com.sun.corba.se.spi.ior.IOR
An IOR is represented as a list of profiles. Only objects that extend TaggedProfile should be added to an IOR. However, enforcing this restriction requires overriding all of the addXXX methods inherited from List, so no check is included here.
author
Ken Cavanaugh

Fields Summary
private String
typeId
private com.sun.corba.se.spi.orb.ORB
factory
private boolean
isCachedHashValue
private int
cachedHashValue
com.sun.corba.se.impl.logging.IORSystemException
wrapper
private com.sun.corba.se.spi.ior.IORTemplateList
iortemps
Constructors Summary
public IORImpl(com.sun.corba.se.spi.orb.ORB orb)
Construct an empty IOR. This is needed for null object references.

	this( orb, "" ) ;
    
public IORImpl(com.sun.corba.se.spi.orb.ORB orb, String typeid)

	factory = orb ;
	wrapper = IORSystemException.get( orb,
	    CORBALogDomains.OA_IOR ) ;
	this.typeId = typeid ;
    
public IORImpl(com.sun.corba.se.spi.orb.ORB orb, String typeId, com.sun.corba.se.spi.ior.IORTemplate iortemp, com.sun.corba.se.spi.ior.ObjectId id)
Construct an IOR from an IORTemplate by applying the same object id to each TaggedProfileTemplate in the IORTemplate.

	this( orb, typeId ) ;

	this.iortemps = IORFactories.makeIORTemplateList() ;
	this.iortemps.add( iortemp ) ;
    
	addTaggedProfiles( iortemp, id ) ;
	
	makeImmutable() ;
    
public IORImpl(com.sun.corba.se.spi.orb.ORB orb, String typeId, com.sun.corba.se.spi.ior.IORTemplateList iortemps, com.sun.corba.se.spi.ior.ObjectId id)
Construct an IOR from an IORTemplate by applying the same object id to each TaggedProfileTemplate in the IORTemplate.

	this( orb, typeId ) ;

	this.iortemps = iortemps ;

	Iterator iter = iortemps.iterator() ;
	while (iter.hasNext()) {
	    IORTemplate iortemp = (IORTemplate)(iter.next()) ;
	    addTaggedProfiles( iortemp, id ) ;
	}
	
	makeImmutable() ;
    
public IORImpl(org.omg.CORBA_2_3.portable.InputStream is)

	this( (ORB)(is.orb()), is.read_string() ) ;

    	IdentifiableFactoryFinder finder = 
	    factory.getTaggedProfileFactoryFinder() ;

	EncapsulationUtility.readIdentifiableSequence( this, finder, is ) ;

	makeImmutable() ;
    
Methods Summary
private voidaddTaggedProfiles(com.sun.corba.se.spi.ior.IORTemplate iortemp, com.sun.corba.se.spi.ior.ObjectId id)

	ObjectKeyTemplate oktemp = iortemp.getObjectKeyTemplate() ;
	Iterator templateIterator = iortemp.iterator() ;

	while (templateIterator.hasNext()) {
	    TaggedProfileTemplate ptemp = 
		(TaggedProfileTemplate)(templateIterator.next()) ;

	    TaggedProfile profile = ptemp.create( oktemp, id ) ;

	    add( profile ) ;
	}	
    
public booleanequals(java.lang.Object obj)


         
    
	if (obj == null)
	    return false ;

	if (!(obj instanceof IOR))
	    return false ;

	IOR other = (IOR)obj ;

	return super.equals( obj ) && typeId.equals( other.getTypeId() ) ;
    
public org.omg.IOP.IORgetIOPIOR()

    
	EncapsOutputStream os = new EncapsOutputStream(factory);
	write(os);
	InputStream is = (InputStream) (os.create_input_stream());
	return org.omg.IOP.IORHelper.read(is);
    
public synchronized com.sun.corba.se.spi.ior.IORTemplateListgetIORTemplates()
Return the IORTemplateList for this IOR. Will throw exception if it is not possible to generate an IOR from the IORTemplateList that is equal to this IOR, which can only happen if not every TaggedProfile in the IOR has the same ObjectId.

	if (iortemps == null) 
	    initializeIORTemplateList() ;

	return iortemps ;
    
public com.sun.corba.se.spi.orb.ORBgetORB()


      
    
	return factory ;
    
public com.sun.corba.se.spi.ior.iiop.IIOPProfilegetProfile()
Return the first IIOPProfile in this IOR. XXX THIS IS TEMPORARY FOR BACKWARDS COMPATIBILITY AND WILL BE REMOVED SOON!

	IIOPProfile iop = null ;
	Iterator iter = iteratorById( TAG_INTERNET_IOP.value ) ;
	if (iter.hasNext())
	    iop = (IIOPProfile)(iter.next()) ;
 
        if (iop != null)
            return iop ;
 
        // if we come to this point then no IIOP Profile
        // is present.  Therefore, throw an exception.
	throw wrapper.iorMustHaveIiopProfile() ;
    
public java.lang.StringgetTypeId()

	return typeId ;
    
public synchronized inthashCode()

        if (! isCachedHashValue) {
              cachedHashValue =  (super.hashCode() ^ typeId.hashCode());
              isCachedHashValue = true;
        }
        return cachedHashValue;
    
private voidinitializeIORTemplateList()

	// Maps ObjectKeyTemplate to IORTemplate
	Map oktempToIORTemplate = new HashMap() ;

	iortemps = IORFactories.makeIORTemplateList() ;
	Iterator iter = iterator() ;
	ObjectId oid = null ; // used to check that all profiles have the same oid.
	while (iter.hasNext()) {
	    TaggedProfile prof = (TaggedProfile)(iter.next()) ;
	    TaggedProfileTemplate ptemp = prof.getTaggedProfileTemplate() ;
	    ObjectKeyTemplate oktemp = prof.getObjectKeyTemplate() ;

	    // Check that all oids for all profiles are the same: if they are not,
	    // throw exception.
	    if (oid == null)
		oid = prof.getObjectId() ;
	    else if (!oid.equals( prof.getObjectId() ))
		throw wrapper.badOidInIorTemplateList() ;

	    // Find or create the IORTemplate for oktemp.
	    IORTemplate iortemp = (IORTemplate)(oktempToIORTemplate.get( oktemp )) ;
	    if (iortemp == null) {
		iortemp = IORFactories.makeIORTemplate( oktemp ) ;
		oktempToIORTemplate.put( oktemp, iortemp ) ;
		iortemps.add( iortemp ) ;
	    }

	    iortemp.add( ptemp ) ;
	}

	iortemps.makeImmutable() ;
    
public booleanisEquivalent(com.sun.corba.se.spi.ior.IOR ior)

	Iterator myIterator = iterator() ;
	Iterator otherIterator = ior.iterator() ;
	while (myIterator.hasNext() && otherIterator.hasNext()) {
	    TaggedProfile myProfile = (TaggedProfile)(myIterator.next()) ;
	    TaggedProfile otherProfile = (TaggedProfile)(otherIterator.next()) ;
	    if (!myProfile.isEquivalent( otherProfile ))
		return false ;
	}

	return myIterator.hasNext() == otherIterator.hasNext() ; 
    
public booleanisNil()

        //
        // The check for typeId length of 0 below is commented out
        // as a workaround for a bug in ORBs which send a
        // null objref with a non-empty typeId string.
        //
	return ((size() == 0) /* && (typeId.length() == 0) */);
    
public synchronized voidmakeImmutable()

	makeElementsImmutable() ;

	if (iortemps != null)
	    iortemps.makeImmutable() ;

	super.makeImmutable() ;
    
public java.lang.Stringstringify()

        StringWriter bs;

        MarshalOutputStream s = new EncapsOutputStream(factory);
        s.putEndian();
        write( (OutputStream)s );
        bs = new StringWriter();
        try {
            s.writeTo(new HexOutputStream(bs));
        } catch (IOException ex) {
	    throw wrapper.stringifyWriteError( ex ) ;
        }

        return ORBConstants.STRINGIFY_PREFIX + bs;
    
public voidwrite(org.omg.CORBA_2_3.portable.OutputStream os)

	os.write_string( typeId ) ;
	EncapsulationUtility.writeIdentifiableSequence( this, os ) ;