1 /*
   2  * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.corba.se.impl.ior;
  27 
  28 import java.util.Iterator ;
  29 
  30 import org.omg.CORBA.INTERNAL ;
  31 
  32 import org.omg.CORBA_2_3.portable.OutputStream ;
  33 import org.omg.CORBA_2_3.portable.InputStream ;
  34 
  35 import org.omg.IOP.TAG_INTERNET_IOP ;
  36 
  37 import com.sun.corba.se.spi.ior.IdentifiableContainerBase ;
  38 import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ;
  39 import com.sun.corba.se.spi.ior.IORTemplate ;
  40 import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
  41 import com.sun.corba.se.spi.ior.TaggedProfileTemplate ;
  42 import com.sun.corba.se.spi.ior.ObjectId ;
  43 import com.sun.corba.se.spi.ior.IOR ;
  44 import com.sun.corba.se.spi.ior.IORFactory ;
  45 
  46 import com.sun.corba.se.spi.orb.ORB ;
  47 
  48 /**
  49  * This class is a container of TaggedProfileTemplates.
  50  * @author
  51  */
  52 public class IORTemplateImpl extends IdentifiableContainerBase implements IORTemplate
  53 {
  54     private ObjectKeyTemplate oktemp ;
  55 
  56     public boolean equals( Object obj )
  57     {
  58         if (obj == null)
  59             return false ;
  60 
  61         if (!(obj instanceof IORTemplateImpl))
  62             return false ;
  63 
  64         IORTemplateImpl other = (IORTemplateImpl)obj ;
  65 
  66         return super.equals( obj ) && oktemp.equals( other.getObjectKeyTemplate() ) ;
  67     }
  68 
  69     public int hashCode()
  70     {
  71         return super.hashCode() ^ oktemp.hashCode() ;
  72     }
  73 
  74     public ObjectKeyTemplate getObjectKeyTemplate()
  75     {
  76         return oktemp ;
  77     }
  78 
  79     public IORTemplateImpl( ObjectKeyTemplate oktemp )
  80     {
  81         this.oktemp = oktemp ;
  82     }
  83 
  84     public IOR makeIOR( ORB orb, String typeid, ObjectId oid )
  85     {
  86         return new IORImpl( orb, typeid, this, oid ) ;
  87     }
  88 
  89     public boolean isEquivalent( IORFactory other )
  90     {
  91         if (!(other instanceof IORTemplate))
  92             return false ;
  93 
  94         IORTemplate list = (IORTemplate)other ;
  95 
  96         Iterator thisIterator = iterator() ;
  97         Iterator listIterator = list.iterator() ;
  98         while (thisIterator.hasNext() && listIterator.hasNext()) {
  99             TaggedProfileTemplate thisTemplate =
 100                 (TaggedProfileTemplate)thisIterator.next() ;
 101             TaggedProfileTemplate listTemplate =
 102                 (TaggedProfileTemplate)listIterator.next() ;
 103             if (!thisTemplate.isEquivalent( listTemplate ))
 104                 return false ;
 105         }
 106 
 107         return (thisIterator.hasNext() == listIterator.hasNext()) &&
 108             getObjectKeyTemplate().equals( list.getObjectKeyTemplate() ) ;
 109     }
 110 
 111     /** Ensure that this IORTemplate and all of its profiles can not be
 112     * modified.  This overrides the method inherited from
 113     * FreezableList through IdentifiableContainerBase.
 114     */
 115     public void makeImmutable()
 116     {
 117         makeElementsImmutable() ;
 118         super.makeImmutable() ;
 119     }
 120 
 121     public void write( OutputStream os )
 122     {
 123         oktemp.write( os ) ;
 124         EncapsulationUtility.writeIdentifiableSequence( this, os ) ;
 125     }
 126 
 127     public IORTemplateImpl( InputStream is )
 128     {
 129         ORB orb = (ORB)(is.orb()) ;
 130         IdentifiableFactoryFinder finder =
 131             orb.getTaggedProfileTemplateFactoryFinder() ;
 132 
 133         oktemp = orb.getObjectKeyFactory().createTemplate( is ) ;
 134         EncapsulationUtility.readIdentifiableSequence( this, finder, is ) ;
 135 
 136         makeImmutable() ;
 137     }
 138 }