KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)ObjectReferenceTemplateImpl.java 1.35 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.portable.InputStream JavaDoc ;
13 import org.omg.CORBA.portable.OutputStream JavaDoc ;
14 import org.omg.CORBA.portable.StreamableValue JavaDoc ;
15
16 import org.omg.CORBA.TypeCode JavaDoc ;
17
18 import org.omg.PortableInterceptor.ObjectReferenceTemplate JavaDoc ;
19 import org.omg.PortableInterceptor.ObjectReferenceTemplateHelper JavaDoc ;
20
21 import com.sun.corba.se.spi.oa.ObjectAdapter ;
22
23 import com.sun.corba.se.spi.ior.ObjectId ;
24 import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
25 import com.sun.corba.se.spi.ior.ObjectAdapterId ;
26 import com.sun.corba.se.spi.ior.IOR;
27 import com.sun.corba.se.spi.ior.IORFactory;
28 import com.sun.corba.se.spi.ior.IORTemplate;
29 import com.sun.corba.se.spi.ior.IORTemplateList;
30 import com.sun.corba.se.spi.ior.IORFactories;
31
32 import com.sun.corba.se.impl.orbutil.ORBUtility ;
33
34 import com.sun.corba.se.spi.orb.ORB ;
35
36 /** This is an implementation of the ObjectReferenceTemplate abstract value
37 * type defined by the portable interceptors IDL.
38 * Note that this is a direct Java implementation
39 * of the abstract value type: there is no stateful value type defined in IDL,
40 * since defining the state in IDL is awkward and inefficient. The best way
41 * to define the state is to use internal data structures that can be written
42 * to and read from CORBA streams.
43 */

44 public class ObjectReferenceTemplateImpl extends ObjectReferenceProducerBase
45     implements ObjectReferenceTemplate JavaDoc, StreamableValue JavaDoc
46 {
47     transient private IORTemplate iorTemplate ;
48
49     public ObjectReferenceTemplateImpl( InputStream JavaDoc is )
50     {
51     super( (ORB)(is.orb()) ) ;
52     _read( is ) ;
53     }
54
55     public ObjectReferenceTemplateImpl( ORB orb, IORTemplate iortemp )
56     {
57     super( orb ) ;
58     iorTemplate = iortemp ;
59     }
60
61     public boolean equals( Object JavaDoc obj )
62     {
63     if (!(obj instanceof ObjectReferenceTemplateImpl))
64         return false ;
65
66     ObjectReferenceTemplateImpl other = (ObjectReferenceTemplateImpl)obj ;
67
68     return (iorTemplate != null) &&
69         iorTemplate.equals( other.iorTemplate ) ;
70     }
71
72     public int hashCode()
73     {
74     return iorTemplate.hashCode() ;
75     }
76
77     // Note that this repository ID must reflect the implementation
78
// of the abstract valuetype (that is, this class), not the
79
// repository ID of the org.omg.PortableInterceptor.ObjectReferenceTemplate
80
// class. This allows for multiple independent implementations
81
// of the abstract valuetype, should that become necessary.
82
public static final String JavaDoc repositoryId =
83     "IDL:com/sun/corba/se/impl/ior/ObjectReferenceTemplateImpl:1.0" ;
84
85     public String JavaDoc[] _truncatable_ids()
86     {
87     return new String JavaDoc[] { repositoryId } ;
88     }
89
90     public TypeCode JavaDoc _type()
91     {
92     return ObjectReferenceTemplateHelper.type() ;
93     }
94
95     /** Read the data into a (presumably) empty ORTImpl. This sets the
96     * orb to the ORB of the InputStream.
97     */

98     public void _read( InputStream JavaDoc is )
99     {
100     org.omg.CORBA_2_3.portable.InputStream JavaDoc istr =
101         (org.omg.CORBA_2_3.portable.InputStream JavaDoc)is ;
102     iorTemplate = IORFactories.makeIORTemplate( istr ) ;
103     orb = (ORB)(istr.orb()) ;
104     }
105
106     /** Write the state to the OutputStream.
107      */

108     public void _write( OutputStream JavaDoc os )
109     {
110     org.omg.CORBA_2_3.portable.OutputStream JavaDoc ostr =
111         (org.omg.CORBA_2_3.portable.OutputStream JavaDoc)os ;
112
113     iorTemplate.write( ostr ) ;
114     }
115
116     public String JavaDoc server_id ()
117     {
118     int val = iorTemplate.getObjectKeyTemplate().getServerId() ;
119     return Integer.toString( val ) ;
120     }
121
122     public String JavaDoc orb_id ()
123     {
124     return iorTemplate.getObjectKeyTemplate().getORBId() ;
125     }
126
127     public String JavaDoc[] adapter_name()
128     {
129     ObjectAdapterId poaid =
130         iorTemplate.getObjectKeyTemplate().getObjectAdapterId() ;
131
132     return poaid.getAdapterName() ;
133     }
134
135     public IORFactory getIORFactory()
136     {
137     return iorTemplate ;
138     }
139
140     public IORTemplateList getIORTemplateList()
141     {
142     IORTemplateList tl = IORFactories.makeIORTemplateList() ;
143     tl.add( iorTemplate ) ;
144     tl.makeImmutable() ;
145     return tl ;
146     }
147 }
148
Popular Tags