001: package org.jacorb.orb.portableInterceptor;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1997-2004 Gerald Brose, Nicolas Noffke
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: import org.omg.PortableInterceptor.*;
024: import org.omg.CORBA.UserException;
025:
026: import org.jacorb.orb.SystemExceptionHelper;
027:
028: /**
029: * This class iterates over an array of
030: * ServerRequestInterceptors.
031: *
032: * @author Nicolas Noffke
033: * @version $Id: ServerInterceptorIterator.java,v 1.12 2006/07/07 10:55:57 alphonse.bendt Exp $
034: */
035:
036: public class ServerInterceptorIterator extends
037: RequestInterceptorIterator {
038: public static final short RECEIVE_REQUEST_SERVICE_CONTEXTS = 0;
039: public static final short RECEIVE_REQUEST = 1;
040: public static final short SEND_REPLY = 2;
041: public static final short SEND_EXCEPTION = 3;
042: public static final short SEND_OTHER = 4;
043:
044: private ServerRequestInfoImpl info = null;
045:
046: public ServerInterceptorIterator(Interceptor[] interceptors) {
047: super (interceptors);
048: }
049:
050: /**
051: * Iterates over the enumeration, i.e. calls "op" on
052: * nextElement() until !hasMoreElements().
053: */
054: public void iterate(ServerRequestInfoImpl info, short op)
055: throws UserException {
056: this .info = info;
057: this .op = op;
058:
059: //set sending_exception right
060: info.update();
061: info.caller_op = op;
062:
063: // ok, op <= RECEIVE_REQUEST is more efficient but
064: // less understandable
065: setDirection((op == RECEIVE_REQUEST_SERVICE_CONTEXTS)
066: || (op == RECEIVE_REQUEST));
067:
068: iterate();
069:
070: //propagate last exception upwards
071: if (interceptor_ex != null) {
072: if (interceptor_ex instanceof ForwardRequest) {
073: throw (ForwardRequest) interceptor_ex;
074: }
075: throw (org.omg.CORBA.SystemException) interceptor_ex;
076: }
077: }
078:
079: protected void invoke(Interceptor interceptor) throws UserException {
080: try {
081: switch (op) {
082: case RECEIVE_REQUEST_SERVICE_CONTEXTS: {
083: ((ServerRequestInterceptor) interceptor)
084: .receive_request_service_contexts(info);
085: break;
086: }
087: case RECEIVE_REQUEST: {
088: ((ServerRequestInterceptor) interceptor)
089: .receive_request(info);
090: break;
091: }
092: case SEND_REPLY: {
093: ((ServerRequestInterceptor) interceptor)
094: .send_reply(info);
095: break;
096: }
097: case SEND_EXCEPTION: {
098: ((ServerRequestInterceptor) interceptor)
099: .send_exception(info);
100: break;
101: }
102: case SEND_OTHER: {
103: ((ServerRequestInterceptor) interceptor)
104: .send_other(info);
105: break;
106: }
107: }
108: } catch (ForwardRequest _fwd) {
109: reverseDirection();
110: op = SEND_OTHER;
111:
112: info.reply_status = LOCATION_FORWARD.value;
113:
114: info.forward_reference = _fwd.forward;
115:
116: interceptor_ex = _fwd;
117: } catch (org.omg.CORBA.SystemException _sysex) {
118: reverseDirection();
119: op = SEND_EXCEPTION;
120: interceptor_ex = _sysex;
121:
122: SystemExceptionHelper
123: .insert(info.sending_exception, _sysex);
124: }
125:
126: info.caller_op = op;
127: }
128: }
|