IORTemplateImpl.java revision 672:2bb058ce572e
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
26package com.sun.corba.se.impl.ior;
27
28import java.util.Iterator ;
29
30import org.omg.CORBA.INTERNAL ;
31
32import org.omg.CORBA_2_3.portable.OutputStream ;
33import org.omg.CORBA_2_3.portable.InputStream ;
34
35import org.omg.IOP.TAG_INTERNET_IOP ;
36
37import com.sun.corba.se.spi.ior.IdentifiableContainerBase ;
38import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ;
39import com.sun.corba.se.spi.ior.IORTemplate ;
40import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
41import com.sun.corba.se.spi.ior.TaggedProfileTemplate ;
42import com.sun.corba.se.spi.ior.ObjectId ;
43import com.sun.corba.se.spi.ior.IOR ;
44import com.sun.corba.se.spi.ior.IORFactory ;
45
46import com.sun.corba.se.spi.orb.ORB ;
47
48/**
49 * This class is a container of TaggedProfileTemplates.
50 */
51public class IORTemplateImpl extends IdentifiableContainerBase implements IORTemplate
52{
53    private ObjectKeyTemplate oktemp ;
54
55    public boolean equals( Object obj )
56    {
57        if (obj == null)
58            return false ;
59
60        if (!(obj instanceof IORTemplateImpl))
61            return false ;
62
63        IORTemplateImpl other = (IORTemplateImpl)obj ;
64
65        return super.equals( obj ) && oktemp.equals( other.getObjectKeyTemplate() ) ;
66    }
67
68    public int hashCode()
69    {
70        return super.hashCode() ^ oktemp.hashCode() ;
71    }
72
73    public ObjectKeyTemplate getObjectKeyTemplate()
74    {
75        return oktemp ;
76    }
77
78    public IORTemplateImpl( ObjectKeyTemplate oktemp )
79    {
80        this.oktemp = oktemp ;
81    }
82
83    public IOR makeIOR( ORB orb, String typeid, ObjectId oid )
84    {
85        return new IORImpl( orb, typeid, this, oid ) ;
86    }
87
88    public boolean isEquivalent( IORFactory other )
89    {
90        if (!(other instanceof IORTemplate))
91            return false ;
92
93        IORTemplate list = (IORTemplate)other ;
94
95        Iterator thisIterator = iterator() ;
96        Iterator listIterator = list.iterator() ;
97        while (thisIterator.hasNext() && listIterator.hasNext()) {
98            TaggedProfileTemplate thisTemplate =
99                (TaggedProfileTemplate)thisIterator.next() ;
100            TaggedProfileTemplate listTemplate =
101                (TaggedProfileTemplate)listIterator.next() ;
102            if (!thisTemplate.isEquivalent( listTemplate ))
103                return false ;
104        }
105
106        return (thisIterator.hasNext() == listIterator.hasNext()) &&
107            getObjectKeyTemplate().equals( list.getObjectKeyTemplate() ) ;
108    }
109
110    /** Ensure that this IORTemplate and all of its profiles can not be
111    * modified.  This overrides the method inherited from
112    * FreezableList through IdentifiableContainerBase.
113    */
114    public void makeImmutable()
115    {
116        makeElementsImmutable() ;
117        super.makeImmutable() ;
118    }
119
120    public void write( OutputStream os )
121    {
122        oktemp.write( os ) ;
123        EncapsulationUtility.writeIdentifiableSequence( this, os ) ;
124    }
125
126    public IORTemplateImpl( InputStream is )
127    {
128        ORB orb = (ORB)(is.orb()) ;
129        IdentifiableFactoryFinder finder =
130            orb.getTaggedProfileTemplateFactoryFinder() ;
131
132        oktemp = orb.getObjectKeyFactory().createTemplate( is ) ;
133        EncapsulationUtility.readIdentifiableSequence( this, finder, is ) ;
134
135        makeImmutable() ;
136    }
137}
138