KickJava   Java API By Example, From Geeks To Geeks.

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


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.CORBA.portable.*;
26 import org.omg.PortableInterceptor.*;
27 import org.omg.Dynamic.Parameter JavaDoc;
28 import org.omg.PortableServer.Servant JavaDoc;
29
30 import org.apache.avalon.framework.logger.*;
31
32 import java.util.Enumeration JavaDoc;
33
34 import org.jacorb.orb.dsi.ServerRequest;
35
36 /**
37  * This class represents the type of info object
38  * that will be passed to the ServerRequestInterceptors. <br>
39  * See PI Spec p.5-50ff
40  *
41  * @author Nicolas Noffke
42  * @version $Id: ServerRequestInfoImpl.java,v 1.16 2005/06/01 11:30:43 andre.spiegel Exp $
43  */

44
45 public class ServerRequestInfoImpl
46     extends RequestInfoImpl
47     implements ServerRequestInfo
48 {
49
50     //from ServerRequestInfo
51
private byte[] adapter_id = null;
52     private String JavaDoc target_most_derived_interface = null;
53
54     private Servant JavaDoc servant = null;
55     private org.jacorb.orb.ORB orb = null;
56
57     public ServerRequest request = null;
58
59     public Any sending_exception = null;
60     
61     public ServerRequestInfoImpl( org.jacorb.orb.ORB orb,
62                                   ServerRequest request,
63                                   Servant JavaDoc servant)
64     {
65         super();
66     
67         this.orb = orb;
68         this.request = request;
69         if (servant != null){
70           setServant(servant);
71         }
72
73         setRequestServiceContexts(request.getServiceContext());
74
75         sending_exception = orb.create_any();
76     }
77
78     /**
79      * The servant is sometimes not available on calling
80      * receive_request_service_contexts (e.g. in case of
81      * ServantLocators or ServantActivators).
82      */

83
84     public void setServant(Servant JavaDoc servant)
85     {
86         this.servant = servant;
87         org.jacorb.poa.POA poa = (org.jacorb.poa.POA) servant._poa();
88         adapter_id = poa.getPOAId();
89         String JavaDoc[] all_ifs = servant._all_interfaces(poa, servant._object_id());
90         target_most_derived_interface = all_ifs[0];
91     }
92
93     /**
94      * Set the sending_exception attribute.
95      */

96
97     public void update()
98     {
99         if (! request.streamBased())
100         {
101             Any user_ex = request.except();
102             if (user_ex != null)
103                 sending_exception = user_ex;
104         }
105
106         SystemException sys_ex = request.getSystemException();
107         if (sys_ex != null)
108             org.jacorb.orb.SystemExceptionHelper.insert(sending_exception, sys_ex);
109
110         forward_reference = request.getForwardReference();
111     }
112
113     public Enumeration JavaDoc getReplyServiceContexts()
114     {
115         return reply_ctx.elements();
116     }
117
118     /**
119      * returns a reference to the calls target.
120      */

121
122     public org.omg.CORBA.Object JavaDoc target()
123     {
124         return servant._this_object();
125     }
126
127     // implementation of RequestInfoOperations interface
128

129     public Parameter JavaDoc[] arguments()
130     {
131         if (!(caller_op == ServerInterceptorIterator.RECEIVE_REQUEST) &&
132             !(caller_op == ServerInterceptorIterator.SEND_REPLY))
133             throw new BAD_INV_ORDER("The attribute \"arguments\" is currently invalid!",
134                                     10, CompletionStatus.COMPLETED_MAYBE);
135
136         if (arguments == null)
137             throw new NO_RESOURCES("Stream-based skeletons/stubs do not support this op",
138                                    1, CompletionStatus.COMPLETED_MAYBE);
139         else
140             return arguments;
141     }
142
143     public TypeCode[] exceptions()
144     {
145         throw new NO_RESOURCES("This feature is not supported on the server side",
146                                1, CompletionStatus.COMPLETED_MAYBE);
147     }
148
149     public Any result()
150     {
151         if ( caller_op != ServerInterceptorIterator.SEND_REPLY )
152             throw new BAD_INV_ORDER("The attribute \"result\" is currently invalid!",
153                                     10, CompletionStatus.COMPLETED_MAYBE);
154
155         Any result = null;
156         try
157         {
158             result = request.result();
159         }
160         catch(Exception JavaDoc e)
161         {
162         }
163
164         if (result == null)
165         {
166             throw new NO_RESOURCES("Stream-based skeletons/stubs do not support this op",
167                                    1, CompletionStatus.COMPLETED_MAYBE);
168         }
169         else
170             return result;
171     }
172
173     public short sync_scope() {
174         return org.omg.Messaging.SYNC_WITH_TRANSPORT.value;
175     }
176  
177     public short reply_status() {
178         if ((caller_op == ServerInterceptorIterator.RECEIVE_REQUEST) ||
179             (caller_op == ServerInterceptorIterator.RECEIVE_REQUEST_SERVICE_CONTEXTS))
180             throw new BAD_INV_ORDER("The attribute \"reply_status\" is currently invalid!",
181                                     10, CompletionStatus.COMPLETED_MAYBE);
182
183         return reply_status;
184     }
185
186     public org.omg.CORBA.Object JavaDoc forward_reference() {
187         if (! (caller_op != ServerInterceptorIterator.SEND_OTHER) ||
188             (reply_status != LOCATION_FORWARD.value))
189             throw new BAD_INV_ORDER("The attribute \"forward_reference\" is currently " +
190                                     "invalid!", 10, CompletionStatus.COMPLETED_MAYBE);
191
192         return forward_reference;
193     }
194
195     public ServiceContext get_reply_service_context(int id) {
196         if ((caller_op == ServerInterceptorIterator.RECEIVE_REQUEST) ||
197             (caller_op == ServerInterceptorIterator.RECEIVE_REQUEST_SERVICE_CONTEXTS))
198             throw new BAD_INV_ORDER("The operation \"get_reply_service_context\" is " +
199                                     "currently invalid!", 10,
200                                     CompletionStatus.COMPLETED_MAYBE);
201
202         return super.get_reply_service_context(id);
203     }
204
205     public String JavaDoc operation() {
206         return request.operation();
207     }
208   
209     public int request_id() {
210         return request.requestId();
211     }
212   
213     public boolean response_expected() {
214         return request.responseExpected();
215     }
216
217     // implementation of ServerRequestInfoOperations interface
218
public Any sending_exception() {
219         if (caller_op != ServerInterceptorIterator.SEND_EXCEPTION)
220             throw new BAD_INV_ORDER("The attribute \"sending_exception\" is " +
221                                     "currently invalid!", 10,
222                                     CompletionStatus.COMPLETED_MAYBE);
223
224         return sending_exception;
225     }
226
227     public byte[] object_id() {
228         if (caller_op == ServerInterceptorIterator.RECEIVE_REQUEST_SERVICE_CONTEXTS)
229             throw new BAD_INV_ORDER("The attribute \"object_id\" is currently invalid!",
230                                     10, CompletionStatus.COMPLETED_MAYBE);
231
232         return request.objectId();
233     }
234
235     public byte[] adapter_id() {
236         if (caller_op == ServerInterceptorIterator.RECEIVE_REQUEST_SERVICE_CONTEXTS)
237             throw new BAD_INV_ORDER("The attribute \"adapter_id\" is currently invalid!",
238                                     10, CompletionStatus.COMPLETED_MAYBE);
239
240         return adapter_id;
241     }
242
243     public String JavaDoc target_most_derived_interface() {
244         if (caller_op == ServerInterceptorIterator.RECEIVE_REQUEST_SERVICE_CONTEXTS)
245             throw new BAD_INV_ORDER("The attribute \"target_most_derived_interface\" is " +
246                                     "currently invalid!", 10,
247                                     CompletionStatus.COMPLETED_MAYBE);
248
249         return target_most_derived_interface;
250     }
251
252     /**
253      * WARNING: This method relies on the DomainService to be available.
254      * Make shure that the DS is running, if you want to call this method.
255      */

256     public Policy get_server_policy(int type) {
257         if (! orb.hasPolicyFactoryForType(type))
258             throw new INV_POLICY("No PolicyFactory for type " + type +
259                                  " has been registered!", 2,
260                                  CompletionStatus.COMPLETED_MAYBE);
261
262         try{
263             org.jacorb.orb.ServantDelegate delegate = (org.jacorb.orb.ServantDelegate) servant._get_delegate();
264             return delegate._get_policy(servant._this_object(), type);
265         }catch(INV_POLICY _e){
266             _e.minor = 2;
267             throw _e;
268         }
269     }
270
271     public void set_slot(int id, Any data) throws InvalidSlot {
272         current.set_slot(id, data);
273     }
274   
275     public boolean target_is_a(String JavaDoc id) {
276         if (caller_op == ServerInterceptorIterator.RECEIVE_REQUEST_SERVICE_CONTEXTS)
277             throw new BAD_INV_ORDER("The operation \"target_is_a\" is currently invalid!",
278                                     10, CompletionStatus.COMPLETED_MAYBE);
279
280         return servant._is_a(id);
281     }
282
283     public void add_reply_service_context(ServiceContext service_context,
284                                           boolean replace) {
285
286         Integer JavaDoc _id = new Integer JavaDoc(service_context.context_id);
287
288         if (! replace && reply_ctx.containsKey(_id))
289             throw new BAD_INV_ORDER("The ServiceContext with id " + _id.toString()
290                                     + " has already been set!", 11,
291                                     CompletionStatus.COMPLETED_MAYBE);
292
293         reply_ctx.put(_id, service_context);
294     }
295 } // ServerRequestInfoImpl
296

297
298
299
300
301
302
Popular Tags