KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > interceptors > IORInfoImpl


1 /*
2  * @(#)IORInfoImpl.java 1.23 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.interceptors;
9
10 import java.util.Iterator JavaDoc ;
11
12 import org.omg.IOP.TaggedComponent JavaDoc;
13
14 import org.omg.CORBA.BAD_INV_ORDER JavaDoc;
15 import org.omg.CORBA.BAD_PARAM JavaDoc;
16 import org.omg.CORBA.INTERNAL JavaDoc;
17 import org.omg.CORBA.CompletionStatus JavaDoc;
18 import org.omg.CORBA.INV_POLICY JavaDoc;
19 import org.omg.CORBA.NO_IMPLEMENT JavaDoc;
20 import org.omg.CORBA.Policy JavaDoc;
21 import org.omg.CORBA.LocalObject JavaDoc;
22
23 import org.omg.PortableInterceptor.IORInfo JavaDoc;
24 import org.omg.PortableInterceptor.ObjectReferenceTemplate JavaDoc;
25 import org.omg.PortableInterceptor.ObjectReferenceFactory JavaDoc;
26
27 import com.sun.corba.se.spi.orb.ORB ;
28
29 import com.sun.corba.se.spi.oa.ObjectAdapter;
30
31 import com.sun.corba.se.spi.legacy.interceptor.IORInfoExt;
32 import com.sun.corba.se.spi.legacy.interceptor.UnknownType;
33
34 import com.sun.corba.se.spi.ior.IORTemplate;
35 import com.sun.corba.se.spi.ior.TaggedProfileTemplate;
36 import com.sun.corba.se.spi.ior.TaggedComponentFactoryFinder ;
37
38 import com.sun.corba.se.spi.logging.CORBALogDomains ;
39
40 import com.sun.corba.se.impl.logging.InterceptorsSystemException ;
41 import com.sun.corba.se.impl.logging.OMGSystemException ;
42 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
43
44 /**
45  * IORInfoImpl is the implementation of the IORInfo class, as described
46  * in orbos/99-12-02, section 7.
47  */

48 public final class IORInfoImpl
49     extends LocalObject JavaDoc
50     implements IORInfo JavaDoc, IORInfoExt
51 {
52     // State values that determine which methods are allowed.
53
// get_effective_policy, manager_id, and adapter_state are valid unless STATE_DONE
54

55     // add_component, and add_component_to_profile are valid.
56
private static final int STATE_INITIAL = 0 ;
57
58     // adapter_template, and R/W to current_factory are valid
59
private static final int STATE_ESTABLISHED = 1 ;
60
61     // No methods are valid in this state
62
private static final int STATE_DONE = 2 ;
63
64     // The current state of this object
65
private int state = STATE_INITIAL ;
66
67     // The ObjectAdapter associated with this IORInfo object.
68
private ObjectAdapter adapter;
69
70     private ORB orb ;
71
72     private ORBUtilSystemException orbutilWrapper ;
73     private InterceptorsSystemException wrapper ;
74     private OMGSystemException omgWrapper ;
75
76     /**
77      * Creates a new IORInfo implementation. This info object will establish
78      * tagged components with the template for the provided IOR Template.
79      */

80     IORInfoImpl( ObjectAdapter adapter ) {
81         this.orb = adapter.getORB() ;
82
83     orbutilWrapper = ORBUtilSystemException.get( orb,
84         CORBALogDomains.RPC_PROTOCOL ) ;
85     wrapper = InterceptorsSystemException.get( orb,
86         CORBALogDomains.RPC_PROTOCOL ) ;
87     omgWrapper = OMGSystemException.get( orb,
88         CORBALogDomains.RPC_PROTOCOL ) ;
89
90     this.adapter = adapter;
91     }
92
93     /**
94      * An ORB service implementation may determine what server side policy
95      * of a particular type is in effect for an IOR being constructed by
96      * calling the get_effective_policy operation. When the IOR being
97      * constructed is for an object implemented using a POA, all Policy
98      * objects passed to the PortableServer::POA::create_POA call that
99      * created that POA are accessible via get_effective_policy.
100      * <p>
101      * If a policy for the given type is not known to the ORB, then this
102      * operation will raise INV_POLICY with a standard minor code of 2.
103      *
104      * @param type The CORBA::PolicyType specifying the type of policy to
105      * return.
106      * @return The effective CORBA::Policy object of the requested type.
107      * If the given policy type is known, but no policy of that tpye is
108      * in effect, then this operation will return a nil object reference.
109      */

110     public Policy JavaDoc get_effective_policy (int type) {
111     checkState( STATE_INITIAL, STATE_ESTABLISHED ) ;
112
113     return adapter.getEffectivePolicy( type );
114     }
115
116     /**
117      * A portable ORB service implementation calls this method from its
118      * implementation of establish_components to add a tagged component to
119      * the set which will be included when constructing IORs. The
120      * components in this set will be included in all profiles.
121      * <p>
122      * Any number of components may exist with the same component ID.
123      *
124      * @param tagged_component The IOP::TaggedComponent to add
125      */

126     public void add_ior_component (TaggedComponent JavaDoc tagged_component) {
127     checkState( STATE_INITIAL ) ;
128
129     if( tagged_component == null ) nullParam();
130         addIORComponentToProfileInternal( tagged_component,
131                       adapter.getIORTemplate().iterator());
132     }
133
134     /**
135      * A portable ORB service implementation calls this method from its
136      * implementation of establish_components to add a tagged component to
137      * the set which will be included when constructing IORs. The
138      * components in this set will be included in the specified profile.
139      * <p>
140      * Any number of components may exist with the same component ID.
141      * <p>
142      * If the given profile ID does not define a known profile or it is
143      * impossible to add components to thgat profile, BAD_PARAM is raised
144      * with a minor code of TBD_BP + 3.
145      *
146      * @param tagged_component The IOP::TaggedComponent to add.
147      * @param profile_id The IOP::ProfileId tof the profile to which this
148      * component will be added.
149      */

150     public void add_ior_component_to_profile (
151         TaggedComponent JavaDoc tagged_component, int profile_id )
152     {
153     checkState( STATE_INITIAL ) ;
154
155     if( tagged_component == null ) nullParam();
156         addIORComponentToProfileInternal(
157         tagged_component, adapter.getIORTemplate().iteratorById(
158         profile_id ) );
159     }
160
161     /**
162      * @param type The type of the server port
163      * (see connection.ORBSocketFactory for discussion).
164      * @return The listen port number for that type.
165      * @throws UnknownType if no port of the given type is found.
166      */

167     public int getServerPort(String JavaDoc type)
168     throws UnknownType
169     {
170     checkState( STATE_INITIAL, STATE_ESTABLISHED ) ;
171
172     int port =
173         orb.getLegacyServerSocketManager()
174             .legacyGetTransientOrPersistentServerPort(type);
175     if (port == -1) {
176         throw new UnknownType();
177     }
178     return port;
179     }
180
181     public ObjectAdapter getObjectAdapter()
182     {
183     return adapter;
184     }
185     
186     public int manager_id()
187     {
188     checkState( STATE_INITIAL, STATE_ESTABLISHED) ;
189
190     return adapter.getManagerId() ;
191     }
192
193     public short state()
194     {
195     checkState( STATE_INITIAL, STATE_ESTABLISHED) ;
196
197     return adapter.getState() ;
198     }
199
200     public ObjectReferenceTemplate JavaDoc adapter_template()
201     {
202     checkState( STATE_ESTABLISHED) ;
203
204     // At this point, the iortemp must contain only a single
205
// IIOPProfileTemplate. This is a restriction of our
206
// implementation. Also, note the the ObjectReferenceTemplate
207
// is called when a certain POA is created in a certain ORB
208
// in a certain server, so the server_id, orb_id, and
209
// poa_id operations must be well-defined no matter what
210
// kind of implementation is used: e.g., if a POA creates
211
// IORs with multiple profiles, they must still all agree
212
// about this information. Thus, we are justified in
213
// extracting the single IIOPProfileTemplate to create
214
// an ObjectReferenceTemplate here.
215

216     return adapter.getAdapterTemplate() ;
217     }
218
219     public ObjectReferenceFactory JavaDoc current_factory()
220     {
221     checkState( STATE_ESTABLISHED) ;
222
223     return adapter.getCurrentFactory() ;
224     }
225
226     public void current_factory( ObjectReferenceFactory JavaDoc factory )
227     {
228     checkState( STATE_ESTABLISHED) ;
229
230     adapter.setCurrentFactory( factory ) ;
231     }
232
233     /**
234      * Internal utility method to add an IOR component to the set of profiles
235      * present in the iterator.
236      */

237     private void addIORComponentToProfileInternal(
238         TaggedComponent JavaDoc tagged_component, Iterator JavaDoc iterator )
239     {
240         // Convert the given IOP::TaggedComponent into the appropriate
241
// type for the TaggedProfileTemplate
242
TaggedComponentFactoryFinder finder =
243             orb.getTaggedComponentFactoryFinder();
244         Object JavaDoc newTaggedComponent = finder.create( orb, tagged_component );
245         
246         // Iterate through TaggedProfileTemplates and add the given tagged
247
// component to the appropriate one(s).
248
boolean found = false;
249         while( iterator.hasNext() ) {
250         found = true;
251             TaggedProfileTemplate taggedProfileTemplate =
252                 (TaggedProfileTemplate)iterator.next();
253         taggedProfileTemplate.add( newTaggedComponent );
254         }
255
256     // If no profile was found with the given id, throw a BAD_PARAM:
257
// (See orbos/00-08-06, section 21.5.3.3.)
258
if( !found ) {
259         throw omgWrapper.invalidProfileId() ;
260     }
261     }
262     
263     /**
264      * Called when an invalid null parameter was passed. Throws a
265      * BAD_PARAM with a minor code of 1
266      */

267     private void nullParam()
268     {
269     throw orbutilWrapper.nullParam() ;
270     }
271
272     // REVISIT: add minor codes!
273

274     private void checkState( int expectedState )
275     {
276     if (expectedState != state)
277         throw wrapper.badState1( new Integer JavaDoc(expectedState), new Integer JavaDoc(state) ) ;
278     }
279
280     private void checkState( int expectedState1, int expectedState2 )
281     {
282     if ((expectedState1 != state) && (expectedState2 != state))
283         throw wrapper.badState2( new Integer JavaDoc(expectedState1),
284         new Integer JavaDoc(expectedState2), new Integer JavaDoc(state) ) ;
285     }
286
287     void makeStateEstablished()
288     {
289     checkState( STATE_INITIAL ) ;
290
291     state = STATE_ESTABLISHED ;
292     }
293
294     void makeStateDone()
295     {
296     checkState( STATE_ESTABLISHED ) ;
297
298     state = STATE_DONE ;
299     }
300 }
301
Popular Tags