KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > ior > IORTemplateImpl


1 /*
2  * @(#)IORTemplateImpl.java 1.14 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.ior;
9
10 import java.util.Iterator JavaDoc ;
11
12 import org.omg.CORBA.INTERNAL JavaDoc ;
13
14 import org.omg.CORBA_2_3.portable.OutputStream JavaDoc ;
15 import org.omg.CORBA_2_3.portable.InputStream JavaDoc ;
16
17 import org.omg.IOP.TAG_INTERNET_IOP JavaDoc ;
18
19 import com.sun.corba.se.spi.ior.IdentifiableContainerBase ;
20 import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ;
21 import com.sun.corba.se.spi.ior.IORTemplate ;
22 import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
23 import com.sun.corba.se.spi.ior.TaggedProfileTemplate ;
24 import com.sun.corba.se.spi.ior.ObjectId ;
25 import com.sun.corba.se.spi.ior.IOR ;
26 import com.sun.corba.se.spi.ior.IORFactory ;
27
28 import com.sun.corba.se.spi.orb.ORB ;
29
30 /**
31  * This class is a container of TaggedProfileTemplates.
32  * @author
33  */

34 public class IORTemplateImpl extends IdentifiableContainerBase implements IORTemplate
35 {
36     private ObjectKeyTemplate oktemp ;
37
38     public boolean equals( Object JavaDoc obj )
39     {
40     if (obj == null)
41         return false ;
42
43     if (!(obj instanceof IORTemplateImpl))
44         return false ;
45
46     IORTemplateImpl other = (IORTemplateImpl)obj ;
47
48     return super.equals( obj ) && oktemp.equals( other.getObjectKeyTemplate() ) ;
49     }
50
51     public int hashCode()
52     {
53     return super.hashCode() ^ oktemp.hashCode() ;
54     }
55
56     public ObjectKeyTemplate getObjectKeyTemplate()
57     {
58     return oktemp ;
59     }
60
61     public IORTemplateImpl( ObjectKeyTemplate oktemp )
62     {
63     this.oktemp = oktemp ;
64     }
65
66     public IOR makeIOR( ORB orb, String JavaDoc typeid, ObjectId oid )
67     {
68     return new IORImpl( orb, typeid, this, oid ) ;
69     }
70
71     public boolean isEquivalent( IORFactory other )
72     {
73     if (!(other instanceof IORTemplate))
74         return false ;
75
76     IORTemplate list = (IORTemplate)other ;
77
78     Iterator JavaDoc thisIterator = iterator() ;
79     Iterator JavaDoc listIterator = list.iterator() ;
80     while (thisIterator.hasNext() && listIterator.hasNext()) {
81         TaggedProfileTemplate thisTemplate =
82         (TaggedProfileTemplate)thisIterator.next() ;
83         TaggedProfileTemplate listTemplate =
84         (TaggedProfileTemplate)listIterator.next() ;
85         if (!thisTemplate.isEquivalent( listTemplate ))
86         return false ;
87     }
88
89     return (thisIterator.hasNext() == listIterator.hasNext()) &&
90         getObjectKeyTemplate().equals( list.getObjectKeyTemplate() ) ;
91     }
92
93     /** Ensure that this IORTemplate and all of its profiles can not be
94     * modified. This overrides the method inherited from
95     * FreezableList through IdentifiableContainerBase.
96     */

97     public void makeImmutable()
98     {
99     makeElementsImmutable() ;
100     super.makeImmutable() ;
101     }
102
103     public void write( OutputStream JavaDoc os )
104     {
105     oktemp.write( os ) ;
106     EncapsulationUtility.writeIdentifiableSequence( this, os ) ;
107     }
108
109     public IORTemplateImpl( InputStream JavaDoc is )
110     {
111     ORB orb = (ORB)(is.orb()) ;
112         IdentifiableFactoryFinder finder =
113         orb.getTaggedProfileTemplateFactoryFinder() ;
114
115     oktemp = orb.getObjectKeyFactory().createTemplate( is ) ;
116     EncapsulationUtility.readIdentifiableSequence( this, finder, is ) ;
117
118     makeImmutable() ;
119     }
120 }
121
Popular Tags