Thu, 31 Aug 2017 18:10:36 +0800
merge
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 */
26 package com.sun.corba.se.impl.ior;
28 import java.util.Iterator ;
30 import org.omg.CORBA.INTERNAL ;
32 import org.omg.CORBA_2_3.portable.OutputStream ;
33 import org.omg.CORBA_2_3.portable.InputStream ;
35 import org.omg.IOP.TAG_INTERNET_IOP ;
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 ;
46 import com.sun.corba.se.spi.orb.ORB ;
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 ;
56 public boolean equals( Object obj )
57 {
58 if (obj == null)
59 return false ;
61 if (!(obj instanceof IORTemplateImpl))
62 return false ;
64 IORTemplateImpl other = (IORTemplateImpl)obj ;
66 return super.equals( obj ) && oktemp.equals( other.getObjectKeyTemplate() ) ;
67 }
69 public int hashCode()
70 {
71 return super.hashCode() ^ oktemp.hashCode() ;
72 }
74 public ObjectKeyTemplate getObjectKeyTemplate()
75 {
76 return oktemp ;
77 }
79 public IORTemplateImpl( ObjectKeyTemplate oktemp )
80 {
81 this.oktemp = oktemp ;
82 }
84 public IOR makeIOR( ORB orb, String typeid, ObjectId oid )
85 {
86 return new IORImpl( orb, typeid, this, oid ) ;
87 }
89 public boolean isEquivalent( IORFactory other )
90 {
91 if (!(other instanceof IORTemplate))
92 return false ;
94 IORTemplate list = (IORTemplate)other ;
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 }
107 return (thisIterator.hasNext() == listIterator.hasNext()) &&
108 getObjectKeyTemplate().equals( list.getObjectKeyTemplate() ) ;
109 }
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 }
121 public void write( OutputStream os )
122 {
123 oktemp.write( os ) ;
124 EncapsulationUtility.writeIdentifiableSequence( this, os ) ;
125 }
127 public IORTemplateImpl( InputStream is )
128 {
129 ORB orb = (ORB)(is.orb()) ;
130 IdentifiableFactoryFinder finder =
131 orb.getTaggedProfileTemplateFactoryFinder() ;
133 oktemp = orb.getObjectKeyFactory().createTemplate( is ) ;
134 EncapsulationUtility.readIdentifiableSequence( this, finder, is ) ;
136 makeImmutable() ;
137 }
138 }