001: package org.jacorb.orb.portableInterceptor;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1999-2004 Gerald Brose
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: import java.util.Enumeration;
025:
026: import org.jacorb.orb.dsi.ServerRequest;
027: import org.omg.CORBA.Any;
028: import org.omg.CORBA.BAD_INV_ORDER;
029: import org.omg.CORBA.CompletionStatus;
030: import org.omg.CORBA.INV_POLICY;
031: import org.omg.CORBA.NO_RESOURCES;
032: import org.omg.CORBA.Policy;
033: import org.omg.CORBA.SystemException;
034: import org.omg.CORBA.TypeCode;
035: import org.omg.Dynamic.Parameter;
036: import org.omg.IOP.ServiceContext;
037: import org.omg.PortableInterceptor.InvalidSlot;
038: import org.omg.PortableInterceptor.LOCATION_FORWARD;
039: import org.omg.PortableInterceptor.ServerRequestInfo;
040: import org.omg.PortableServer.Servant;
041:
042: /**
043: * This class represents the type of info object
044: * that will be passed to the ServerRequestInterceptors. <br>
045: * See PI Spec p.5-50ff
046: *
047: * @author Nicolas Noffke
048: * @version $Id: ServerRequestInfoImpl.java,v 1.18 2006/07/14 12:02:41 nick.cross Exp $
049: */
050:
051: public class ServerRequestInfoImpl extends RequestInfoImpl implements
052: ServerRequestInfo {
053:
054: //from ServerRequestInfo
055: private byte[] adapter_id = null;
056: private String target_most_derived_interface = null;
057:
058: private Servant servant = null;
059: private final org.jacorb.orb.ORB orb;
060:
061: public final ServerRequest request;
062:
063: public Any sending_exception = null;
064:
065: public ServerRequestInfoImpl(org.jacorb.orb.ORB orb,
066: ServerRequest request, Servant servant) {
067: super ();
068:
069: this .orb = orb;
070: this .request = request;
071:
072: if (servant != null) {
073: setServant(servant);
074: }
075:
076: setRequestServiceContexts(request.getServiceContext());
077:
078: sending_exception = orb.create_any();
079: }
080:
081: /**
082: * The servant is sometimes not available on calling
083: * receive_request_service_contexts (e.g. in case of
084: * ServantLocators or ServantActivators).
085: */
086:
087: public final void setServant(Servant servant) {
088: this .servant = servant;
089: org.jacorb.poa.POA poa = (org.jacorb.poa.POA) servant._poa();
090: adapter_id = poa.getPOAId();
091: String[] all_ifs = servant._all_interfaces(poa, servant
092: ._object_id());
093: target_most_derived_interface = all_ifs[0];
094: }
095:
096: /**
097: * Set the sending_exception attribute.
098: */
099:
100: public void update() {
101: if (!request.streamBased()) {
102: Any user_ex = request.except();
103: if (user_ex != null) {
104: sending_exception = user_ex;
105: }
106: }
107:
108: SystemException sys_ex = request.getSystemException();
109: if (sys_ex != null) {
110: org.jacorb.orb.SystemExceptionHelper.insert(
111: sending_exception, sys_ex);
112: }
113:
114: forward_reference = request.getForwardReference();
115: }
116:
117: public Enumeration getReplyServiceContexts() {
118: return reply_ctx.elements();
119: }
120:
121: /**
122: * returns a reference to the calls target.
123: */
124:
125: public org.omg.CORBA.Object target() {
126: return servant._this _object();
127: }
128:
129: // implementation of RequestInfoOperations interface
130:
131: public Parameter[] arguments() {
132: if (!(caller_op == ServerInterceptorIterator.RECEIVE_REQUEST)
133: && !(caller_op == ServerInterceptorIterator.SEND_REPLY)) {
134: throw new BAD_INV_ORDER(
135: "The attribute \"arguments\" is currently invalid!",
136: 10, CompletionStatus.COMPLETED_MAYBE);
137: }
138:
139: if (arguments == null) {
140: throw new NO_RESOURCES(
141: "Stream-based skeletons/stubs do not support this op",
142: 1, CompletionStatus.COMPLETED_MAYBE);
143: }
144:
145: return arguments;
146: }
147:
148: public TypeCode[] exceptions() {
149: throw new NO_RESOURCES(
150: "This feature is not supported on the server side", 1,
151: CompletionStatus.COMPLETED_MAYBE);
152: }
153:
154: public Any result() {
155: if (caller_op != ServerInterceptorIterator.SEND_REPLY) {
156: throw new BAD_INV_ORDER(
157: "The attribute \"result\" is currently invalid!",
158: 10, CompletionStatus.COMPLETED_MAYBE);
159: }
160:
161: Any result = null;
162:
163: try {
164: result = request.result();
165: } catch (Exception e) {
166: }
167:
168: if (result == null) {
169: throw new NO_RESOURCES(
170: "Stream-based skeletons/stubs do not support this op",
171: 1, CompletionStatus.COMPLETED_MAYBE);
172: }
173:
174: return result;
175: }
176:
177: public short sync_scope() {
178: return org.omg.Messaging.SYNC_WITH_TRANSPORT.value;
179: }
180:
181: public short reply_status() {
182: if ((caller_op == ServerInterceptorIterator.RECEIVE_REQUEST)
183: || (caller_op == ServerInterceptorIterator.RECEIVE_REQUEST_SERVICE_CONTEXTS)) {
184: throw new BAD_INV_ORDER(
185: "The attribute \"reply_status\" is currently invalid!",
186: 10, CompletionStatus.COMPLETED_MAYBE);
187: }
188:
189: return reply_status;
190: }
191:
192: public org.omg.CORBA.Object forward_reference() {
193: if (!(caller_op != ServerInterceptorIterator.SEND_OTHER)
194: || (reply_status != LOCATION_FORWARD.value)) {
195: throw new BAD_INV_ORDER(
196: "The attribute \"forward_reference\" is currently "
197: + "invalid!", 10,
198: CompletionStatus.COMPLETED_MAYBE);
199: }
200:
201: return forward_reference;
202: }
203:
204: public ServiceContext get_reply_service_context(int id) {
205: if ((caller_op == ServerInterceptorIterator.RECEIVE_REQUEST)
206: || (caller_op == ServerInterceptorIterator.RECEIVE_REQUEST_SERVICE_CONTEXTS)) {
207: throw new BAD_INV_ORDER(
208: "The operation \"get_reply_service_context\" is "
209: + "currently invalid!", 10,
210: CompletionStatus.COMPLETED_MAYBE);
211: }
212:
213: return super .get_reply_service_context(id);
214: }
215:
216: public String operation() {
217: return request.operation();
218: }
219:
220: public int request_id() {
221: return request.requestId();
222: }
223:
224: public boolean response_expected() {
225: return request.responseExpected();
226: }
227:
228: // implementation of ServerRequestInfoOperations interface
229: public Any sending_exception() {
230: if (caller_op != ServerInterceptorIterator.SEND_EXCEPTION) {
231: throw new BAD_INV_ORDER(
232: "The attribute \"sending_exception\" is "
233: + "currently invalid!", 10,
234: CompletionStatus.COMPLETED_MAYBE);
235: }
236:
237: return sending_exception;
238: }
239:
240: public byte[] object_id() {
241: if (caller_op == ServerInterceptorIterator.RECEIVE_REQUEST_SERVICE_CONTEXTS) {
242: throw new BAD_INV_ORDER(
243: "The attribute \"object_id\" is currently invalid!",
244: 10, CompletionStatus.COMPLETED_MAYBE);
245: }
246:
247: return request.objectId();
248: }
249:
250: public byte[] adapter_id() {
251: if (caller_op == ServerInterceptorIterator.RECEIVE_REQUEST_SERVICE_CONTEXTS) {
252: throw new BAD_INV_ORDER(
253: "The attribute \"adapter_id\" is currently invalid!",
254: 10, CompletionStatus.COMPLETED_MAYBE);
255: }
256:
257: return adapter_id;
258: }
259:
260: public String target_most_derived_interface() {
261: if (caller_op == ServerInterceptorIterator.RECEIVE_REQUEST_SERVICE_CONTEXTS) {
262: throw new BAD_INV_ORDER(
263: "The attribute \"target_most_derived_interface\" is "
264: + "currently invalid!", 10,
265: CompletionStatus.COMPLETED_MAYBE);
266: }
267:
268: return target_most_derived_interface;
269: }
270:
271: /**
272: * WARNING: This method relies on the DomainService to be available.
273: * Make shure that the DS is running, if you want to call this method.
274: */
275: public Policy get_server_policy(int type) {
276: if (!orb.hasPolicyFactoryForType(type)) {
277: throw new INV_POLICY("No PolicyFactory for type " + type
278: + " has been registered!", 2,
279: CompletionStatus.COMPLETED_MAYBE);
280: }
281:
282: try {
283: org.jacorb.orb.ServantDelegate delegate = (org.jacorb.orb.ServantDelegate) servant
284: ._get_delegate();
285: return delegate._get_policy(servant._this _object(), type);
286: } catch (INV_POLICY e) {
287: e.minor = 2;
288: throw e;
289: }
290: }
291:
292: public void set_slot(int id, Any data) throws InvalidSlot {
293: current.set_slot(id, data);
294: }
295:
296: public boolean target_is_a(String id) {
297: if (caller_op == ServerInterceptorIterator.RECEIVE_REQUEST_SERVICE_CONTEXTS) {
298: throw new BAD_INV_ORDER(
299: "The operation \"target_is_a\" is currently invalid!",
300: 10, CompletionStatus.COMPLETED_MAYBE);
301: }
302:
303: return servant._is_a(id);
304: }
305:
306: public void add_reply_service_context(
307: ServiceContext service_context, boolean replace) {
308: Integer _id = new Integer(service_context.context_id);
309:
310: if (!replace && reply_ctx.containsKey(_id)) {
311: throw new BAD_INV_ORDER("The ServiceContext with id "
312: + _id.toString() + " has already been set!", 11,
313: CompletionStatus.COMPLETED_MAYBE);
314: }
315:
316: reply_ctx.put(_id, service_context);
317: }
318: }
|