KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > portableInterceptor > ClientRequestInfoImpl


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.orb.portableInterceptor;
22
23 import org.omg.IOP.*;
24 import org.omg.CORBA.*;
25 import org.omg.PortableInterceptor.*;
26 import org.omg.Dynamic.Parameter JavaDoc;
27 import org.omg.ETF.*;
28
29 import org.apache.avalon.framework.logger.*;
30
31 import java.util.*;
32 import org.jacorb.orb.iiop.IIOPProfile;
33
34 /**
35  * This class represents the type of info object,
36  * that will be passed to the ClientRequestInterceptors. <br>
37  * See PI Spec p.5-46ff
38  *
39  * @author Nicolas Noffke
40  * @version $Id: ClientRequestInfoImpl.java,v 1.27 2005/05/12 21:59:12 andre.spiegel Exp $
41  */

42
43 public class ClientRequestInfoImpl
44     extends RequestInfoImpl
45     implements ClientRequestInfo
46 {
47     private Logger logger;
48
49     //from ClientRequestInfo
50
public org.omg.CORBA.Object JavaDoc target = null;
51     public org.omg.CORBA.Object JavaDoc effective_target = null;
52     public TaggedProfile effective_profile = null;
53     public Any received_exception = null;
54     public String JavaDoc received_exception_id = null;
55     public TaggedComponent[] effective_components = null;
56     public org.jacorb.orb.Delegate delegate = null;
57     public org.jacorb.orb.ORB orb = null;
58
59     public org.jacorb.orb.giop.RequestOutputStream request_os = null;
60     public org.jacorb.orb.giop.ReplyInputStream reply_is = null;
61
62     public org.jacorb.orb.giop.ClientConnection connection = null;
63
64     public ClientRequestInfoImpl
65                       ( org.jacorb.orb.ORB orb,
66                         org.jacorb.orb.giop.RequestOutputStream ros,
67                         org.omg.CORBA.Object JavaDoc self,
68                         org.jacorb.orb.Delegate delegate,
69                         org.jacorb.orb.ParsedIOR piorOriginal,
70                         org.jacorb.orb.giop.ClientConnection connection )
71     {
72          this.orb = orb;
73          logger = orb.getConfiguration().getNamedLogger("jacorb.orb.interceptors");
74
75          this.operation = ros.operation();
76          this.response_expected = ros.response_expected();
77          this.received_exception = orb.create_any();
78
79          if ( ros.getRequest() != null )
80              this.setRequest( ros.getRequest() );
81
82          this.effective_target = self;
83
84          org.jacorb.orb.ParsedIOR pior = delegate.getParsedIOR();
85
86          if ( piorOriginal != null )
87              this.target = orb._getObject( pior );
88          else
89              this.target = self;
90
91          Profile profile = pior.getEffectiveProfile();
92          if (profile instanceof org.jacorb.orb.etf.ProfileBase)
93          {
94              this.effective_profile = ((org.jacorb.orb.etf.ProfileBase)profile).asTaggedProfile();
95              this.effective_components = ((org.jacorb.orb.etf.ProfileBase)profile).getComponents().asArray();
96          }
97
98          if ( this.effective_components == null )
99          {
100              this.effective_components = new org.omg.IOP.TaggedComponent JavaDoc[ 0 ];
101          }
102
103          this.delegate = delegate;
104
105          this.request_id = ros.requestId();
106          InterceptorManager manager = orb.getInterceptorManager();
107
108          this.current = manager.getCurrent();
109
110          //allow interceptors access to request output stream
111
this.request_os = ros;
112
113          //allow (BiDir) interceptor to inspect the connection
114
this.connection = connection;
115     }
116
117     public void setRequest(org.jacorb.orb.dii.Request request)
118     {
119         arguments = new org.omg.Dynamic.Parameter JavaDoc[request.arguments.count()];
120         for (int i = 0; i < arguments.length; i++)
121         {
122             try
123             {
124                 NamedValue value = request.arguments.item(i);
125
126                 ParameterMode mode = null;
127                 if (value.flags() == ARG_IN.value)
128                     mode = ParameterMode.PARAM_IN;
129                 else if (value.flags() == ARG_OUT.value)
130                     mode = ParameterMode.PARAM_OUT;
131                 else if (value.flags() == ARG_INOUT.value)
132                     mode = ParameterMode.PARAM_INOUT;
133
134                 arguments[i] = new org.omg.Dynamic.Parameter JavaDoc(value.value(), mode);
135             }
136             catch (Exception JavaDoc e)
137             {
138                 if( logger.isDebugEnabled() )
139                 {
140                     logger.debug(e.getMessage());
141                 }
142             }
143         }
144         //exceptions will be set when available
145
}
146
147     /**
148      * This method builds an array of ServiceContexts.
149      * The last ServiceContext is a dummy object for
150      * data aligning purposes.
151      */

152
153     public Enumeration getRequestServiceContexts()
154     {
155         return request_ctx.elements();
156     }
157
158     // implementation of
159
// org.omg.PortableInterceptor.RequestInfoOperations interface
160

161     public Parameter JavaDoc[] arguments()
162     {
163         if (! (caller_op == ClientInterceptorIterator.SEND_REQUEST) &&
164             ! (caller_op == ClientInterceptorIterator.RECEIVE_REPLY))
165             throw new BAD_INV_ORDER("The attribute \"arguments\" is currently invalid!",
166                                     10, CompletionStatus.COMPLETED_MAYBE);
167
168         if (arguments == null)
169             throw new NO_RESOURCES("Stream-based skeletons/stubs do not support this op",
170                                    1, CompletionStatus.COMPLETED_MAYBE);
171         else
172             return arguments;
173     }
174
175     public TypeCode[] exceptions()
176     {
177         if (caller_op == ClientInterceptorIterator.SEND_POLL)
178             throw new BAD_INV_ORDER("The attribute \"exceptions\" is currently invalid!",
179                                     10, CompletionStatus.COMPLETED_MAYBE);
180
181         if (exceptions == null)
182             throw new NO_RESOURCES("Stream-based skeletons/stubs do not support this op",
183                                    1, CompletionStatus.COMPLETED_MAYBE);
184         else
185             return exceptions;
186     }
187
188     public Any result()
189     {
190         if (caller_op != ClientInterceptorIterator.RECEIVE_REPLY)
191             throw new BAD_INV_ORDER("The attribute \"result\" is currently invalid!",
192                                     10, CompletionStatus.COMPLETED_MAYBE);
193
194         if (result == null)
195             throw new NO_RESOURCES("Stream-based skeletons/stubs do not support this op",
196                                    1, CompletionStatus.COMPLETED_MAYBE);
197         else
198             return result;
199     }
200
201     public short sync_scope()
202     {
203         if (caller_op == ClientInterceptorIterator.SEND_POLL)
204             throw new BAD_INV_ORDER("The attribute \"sync_scope\" is currently invalid!",
205                                     10, CompletionStatus.COMPLETED_MAYBE);
206
207         return org.omg.Messaging.SYNC_WITH_TRANSPORT.value;
208     }
209
210     public short reply_status()
211     {
212         if ((caller_op == ClientInterceptorIterator.SEND_REQUEST) ||
213             (caller_op == ClientInterceptorIterator.SEND_POLL))
214             throw new BAD_INV_ORDER("The attribute \"reply_status\" is currently invalid!",
215                                     10, CompletionStatus.COMPLETED_MAYBE);
216
217         return reply_status;
218     }
219
220     public org.omg.CORBA.Object JavaDoc forward_reference()
221     {
222         if( (caller_op != ClientInterceptorIterator.RECEIVE_OTHER) ||
223             (reply_status != LOCATION_FORWARD.value) )
224             throw new BAD_INV_ORDER("The attribute \"forward_reference\" is currently " +
225                                     "invalid!", 10, CompletionStatus.COMPLETED_MAYBE);
226
227         return forward_reference;
228     }
229
230     public ServiceContext get_request_service_context(int id)
231     {
232         if (caller_op == ClientInterceptorIterator.SEND_POLL)
233             throw new BAD_INV_ORDER("The attribute \"operation_context\" is currently " +
234                                     "invalid!", 10, CompletionStatus.COMPLETED_MAYBE);
235
236         return super.get_request_service_context(id);
237     }
238
239     public ServiceContext get_reply_service_context(int id)
240     {
241         if ((caller_op == ClientInterceptorIterator.SEND_REQUEST) ||
242             (caller_op == ClientInterceptorIterator.SEND_POLL))
243             throw new BAD_INV_ORDER("The attribute \"reply_status\" is currently invalid!",
244                                     10, CompletionStatus.COMPLETED_MAYBE);
245
246         return super.get_reply_service_context(id);
247     }
248
249     // implementation of ClientRequestInfoOperations interface
250
public org.omg.CORBA.Object JavaDoc target()
251     {
252         return target;
253     }
254
255     public org.omg.CORBA.Object JavaDoc effective_target()
256     {
257         return effective_target;
258     }
259
260     public TaggedProfile effective_profile() {
261         return effective_profile;
262     }
263
264     public Any received_exception()
265     {
266         if (caller_op != ClientInterceptorIterator.RECEIVE_EXCEPTION)
267             throw new BAD_INV_ORDER("The attribute \"received_exception\" is currently " +
268                                     "invalid!", 10, CompletionStatus.COMPLETED_MAYBE);
269
270         return received_exception;
271     }
272
273     public String JavaDoc received_exception_id()
274     {
275         if (caller_op != ClientInterceptorIterator.RECEIVE_EXCEPTION)
276             throw new BAD_INV_ORDER("The attribute \"received_exception_id\" is " +
277                                     "currently invalid!", 10,
278                                     CompletionStatus.COMPLETED_MAYBE);
279
280         return received_exception_id;
281     }
282
283     public TaggedComponent get_effective_component(int id)
284     {
285         if (caller_op == ClientInterceptorIterator.SEND_POLL)
286             throw new BAD_INV_ORDER("The operation \"get_effective_component\" is " +
287                                     "currently invalid!", 10,
288                                     CompletionStatus.COMPLETED_MAYBE);
289
290         for(int _i = 0; _i < effective_components.length; _i++)
291             if (effective_components[_i].tag == id)
292                 return effective_components[_i];
293
294         throw new BAD_PARAM("No TaggedComponent with id " + id + " found",
295                             25, CompletionStatus.COMPLETED_MAYBE);
296     }
297
298     public TaggedComponent[] get_effective_components(int id)
299     {
300         if (caller_op == ClientInterceptorIterator.SEND_POLL)
301             throw new BAD_INV_ORDER("The operation \"get_effective_components\" is " +
302                                     "currently invalid!", 10,
303                                     CompletionStatus.COMPLETED_MAYBE);
304
305         Vector _store = new Vector();
306         for(int _i = 0; _i < effective_components.length; _i++)
307             if (effective_components[_i].tag == id)
308                 _store.addElement(effective_components[_i]);
309
310         if (_store.size() == 0)
311             throw new BAD_PARAM("No TaggedComponents with id " + id + " found",
312                                 25, CompletionStatus.COMPLETED_MAYBE);
313         else
314         {
315             TaggedComponent[] _result = new TaggedComponent[_store.size()];
316             for (int _i = 0; _i < _result.length; _i++)
317                 _result[_i] = (TaggedComponent) _store.elementAt(_i);
318
319             return _result;
320         }
321     }
322
323     /**
324      * WARNING: This method relies on the DomainService to be available.
325      * Make shure that the DS is running, if you want to call this method.
326      */

327
328     public Policy get_request_policy(int type)
329     {
330         if (caller_op == ClientInterceptorIterator.SEND_POLL)
331             throw new BAD_INV_ORDER("The operation \"get_request_policy\" is currently " +
332                                     "invalid!", 10, CompletionStatus.COMPLETED_MAYBE);
333
334         if (! orb.hasPolicyFactoryForType(type))
335             throw new INV_POLICY("No PolicyFactory for type " + type +
336                                  " has been registered!", 1,
337                                  CompletionStatus.COMPLETED_MAYBE);
338         try
339         {
340             return delegate.get_policy (target, type);
341         }
342         catch(INV_POLICY _e)
343         {
344             _e.minor = 1;
345             throw _e;
346         }
347     }
348
349     public void add_request_service_context(ServiceContext service_context,
350                                             boolean replace)
351     {
352
353         if (caller_op != ClientInterceptorIterator.SEND_REQUEST)
354             throw new BAD_INV_ORDER("The operation \"add_request_service_context\" is " +
355                                     "currently invalid!", 10,
356                                     CompletionStatus.COMPLETED_MAYBE);
357
358         Integer JavaDoc _id = new Integer JavaDoc(service_context.context_id);
359
360         if (! replace && request_ctx.containsKey(_id))
361             throw new BAD_INV_ORDER("The ServiceContext with id " + _id.toString()
362                                     + " has already been set!", 11,
363                                     CompletionStatus.COMPLETED_MAYBE);
364
365         request_ctx.put(_id, service_context);
366     }
367
368 } // ClientRequestInfoImpl
369
Popular Tags