001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021: package org.jacorb.orb.portableInterceptor;
022:
023: import org.omg.PortableInterceptor.*;
024: import org.omg.CORBA.UserException;
025:
026: import org.apache.avalon.framework.logger.Logger;
027: import org.jacorb.orb.SystemExceptionHelper;
028:
029: /**
030: * This class is an iterator over an array
031: * of ClientRequestInterceptors.
032: *
033: * @author Nicolas Noffke
034: * @version $Id: ClientInterceptorIterator.java,v 1.14 2006/07/07 10:55:57 alphonse.bendt Exp $
035: */
036:
037: public class ClientInterceptorIterator extends
038: RequestInterceptorIterator {
039: public static final short SEND_REQUEST = 0;
040: public static final short SEND_POLL = 1;
041: public static final short RECEIVE_REPLY = 2;
042: public static final short RECEIVE_EXCEPTION = 3;
043: public static final short RECEIVE_OTHER = 4;
044:
045: private ClientRequestInfoImpl info = null;
046: private final Logger logger;
047:
048: public ClientInterceptorIterator(Logger logger,
049: Interceptor[] interceptors) {
050: super (interceptors);
051:
052: this .logger = logger;
053: }
054:
055: public void iterate(ClientRequestInfoImpl info, short op)
056: throws UserException {
057: this .info = info;
058: this .op = op;
059:
060: // ok, op <= SEND_POLL is more efficient but
061: // less understandable
062: setDirection((op == SEND_REQUEST) || (op == SEND_POLL));
063:
064: iterate();
065:
066: //propagate last exception upwards
067: if (interceptor_ex != null) {
068: if (interceptor_ex instanceof ForwardRequest) {
069: throw (ForwardRequest) interceptor_ex;
070: }
071: throw (org.omg.CORBA.SystemException) interceptor_ex;
072: }
073: }
074:
075: /**
076: * Iterates over the enumeration, i.e. calls "op" on
077: * nextElement() until !hasMoreElements().
078: */
079: protected void invoke(Interceptor interceptor) throws UserException {
080: info.caller_op = op;
081:
082: try {
083: switch (op) {
084: case SEND_REQUEST:
085: ((ClientRequestInterceptor) interceptor)
086: .send_request(info);
087: break;
088: case SEND_POLL:
089: ((ClientRequestInterceptor) interceptor)
090: .send_poll(info);
091: break;
092: case RECEIVE_REPLY:
093: ((ClientRequestInterceptor) interceptor)
094: .receive_reply(info);
095: break;
096: case RECEIVE_EXCEPTION:
097: ((ClientRequestInterceptor) interceptor)
098: .receive_exception(info);
099: break;
100: case RECEIVE_OTHER:
101: ((ClientRequestInterceptor) interceptor)
102: .receive_other(info);
103: }
104: } catch (ForwardRequest _fwd) {
105: reverseDirection();
106: op = RECEIVE_OTHER;
107:
108: info.reply_status = LOCATION_FORWARD.value;
109:
110: info.forward_reference = _fwd.forward;
111: interceptor_ex = _fwd;
112: } catch (org.omg.CORBA.SystemException _sysex) {
113: reverseDirection();
114: op = RECEIVE_EXCEPTION;
115: interceptor_ex = _sysex;
116:
117: SystemExceptionHelper.insert(info.received_exception,
118: _sysex);
119:
120: try {
121: info.received_exception_id = SystemExceptionHelper
122: .type(_sysex).id();
123: } catch (org.omg.CORBA.TypeCodePackage.BadKind _bk) {
124: logger.error("unexpected exception", _bk);
125: }
126: } catch (Exception e) {
127: logger.error("unexpected exception during invoke", e);
128: }
129:
130: info.caller_op = op;
131: }
132: } // ClientInterceptorIterator
|