KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > ior > iiop > IIOPProfileTemplateImpl


1 /*
2  * @(#)IIOPProfileTemplateImpl.java 1.20 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.iiop;
9
10 import java.util.Iterator JavaDoc ;
11
12 import org.omg.IOP.TAG_INTERNET_IOP JavaDoc ;
13
14 import org.omg.CORBA_2_3.portable.InputStream JavaDoc ;
15 import org.omg.CORBA_2_3.portable.OutputStream JavaDoc ;
16
17 import com.sun.corba.se.spi.ior.TaggedComponent ;
18 import com.sun.corba.se.spi.ior.TaggedProfile ;
19 import com.sun.corba.se.spi.ior.TaggedProfileTemplate ;
20 import com.sun.corba.se.spi.ior.TaggedProfileTemplateBase ;
21 import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
22 import com.sun.corba.se.spi.ior.ObjectId ;
23 import com.sun.corba.se.spi.ior.IdentifiableContainerBase ;
24 import com.sun.corba.se.spi.ior.IdentifiableBase ;
25
26 import com.sun.corba.se.impl.ior.EncapsulationUtility ;
27
28 import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ;
29 import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;
30 import com.sun.corba.se.spi.ior.iiop.IIOPFactories ;
31
32 import com.sun.corba.se.impl.encoding.EncapsOutputStream ;
33
34 import com.sun.corba.se.impl.encoding.CDROutputStream ;
35
36 import com.sun.corba.se.spi.ior.iiop.GIOPVersion ;
37 import com.sun.corba.se.spi.orb.ORB ;
38
39 /**
40  * @author
41  * If getMinorVersion==0, this does not contain any tagged components
42  */

43 public class IIOPProfileTemplateImpl extends TaggedProfileTemplateBase
44     implements IIOPProfileTemplate
45 {
46     private ORB orb ;
47     private GIOPVersion giopVersion ;
48     private IIOPAddress primary ;
49     
50     public boolean equals( Object JavaDoc obj )
51     {
52     if (!(obj instanceof IIOPProfileTemplateImpl))
53         return false ;
54
55     IIOPProfileTemplateImpl other = (IIOPProfileTemplateImpl)obj ;
56
57     return super.equals( obj ) && giopVersion.equals( other.giopVersion ) &&
58         primary.equals( other.primary ) ;
59     }
60
61     public int hashCode()
62     {
63     return super.hashCode() ^ giopVersion.hashCode() ^ primary.hashCode() ;
64     }
65
66     public TaggedProfile create( ObjectKeyTemplate oktemp, ObjectId id )
67     {
68     return IIOPFactories.makeIIOPProfile( orb, oktemp, id, this ) ;
69     }
70
71     public GIOPVersion getGIOPVersion()
72     {
73     return giopVersion ;
74     }
75
76     public IIOPAddress getPrimaryAddress()
77     {
78     return primary ;
79     }
80
81     public IIOPProfileTemplateImpl( ORB orb, GIOPVersion version, IIOPAddress primary )
82     {
83     this.orb = orb ;
84     this.giopVersion = version ;
85     this.primary = primary ;
86     if (giopVersion.getMinor() == 0)
87         // Adding tagged components is not allowed for IIOP 1.0,
88
// so this template is complete and should be made immutable.
89
makeImmutable() ;
90     }
91
92     public IIOPProfileTemplateImpl( InputStream JavaDoc istr )
93     {
94     byte major = istr.read_octet() ;
95     byte minor = istr.read_octet() ;
96     giopVersion = GIOPVersion.getInstance( major, minor ) ;
97     primary = new IIOPAddressImpl( istr ) ;
98     orb = (ORB)(istr.orb()) ;
99     // Handle any tagged components (if applicable)
100
if (minor > 0)
101         EncapsulationUtility.readIdentifiableSequence(
102         this, orb.getTaggedComponentFactoryFinder(), istr ) ;
103
104     makeImmutable() ;
105     }
106     
107     public void write( ObjectKeyTemplate okeyTemplate, ObjectId id, OutputStream JavaDoc os)
108     {
109     giopVersion.write( os ) ;
110     primary.write( os ) ;
111
112     // Note that this is NOT an encapsulation: do not marshal
113
// the endianness flag. However, the length is required.
114
// Note that this cannot be accomplished with a codec!
115

116         // Use the byte order of the given stream
117
OutputStream JavaDoc encapsulatedOS = new EncapsOutputStream( (ORB)os.orb(),
118         ((CDROutputStream)os).isLittleEndian() ) ;
119
120     okeyTemplate.write( id, encapsulatedOS ) ;
121     EncapsulationUtility.writeOutputStream( encapsulatedOS, os ) ;
122
123     if (giopVersion.getMinor() > 0)
124         EncapsulationUtility.writeIdentifiableSequence( this, os ) ;
125     }
126     
127     /** Write out this IIOPProfileTemplateImpl only.
128     */

129     public void writeContents( OutputStream JavaDoc os)
130     {
131     giopVersion.write( os ) ;
132     primary.write( os ) ;
133
134     if (giopVersion.getMinor() > 0)
135         EncapsulationUtility.writeIdentifiableSequence( this, os ) ;
136     }
137     
138     public int getId()
139     {
140     return TAG_INTERNET_IOP.value ;
141     }
142
143     public boolean isEquivalent( TaggedProfileTemplate temp )
144     {
145     if (!(temp instanceof IIOPProfileTemplateImpl))
146         return false ;
147
148     IIOPProfileTemplateImpl tempimp = (IIOPProfileTemplateImpl)temp ;
149
150     return primary.equals( tempimp.primary ) ;
151     }
152
153 }
154
Popular Tags