KickJava   Java API By Example, From Geeks To Geeks.

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


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.PortableInterceptor.*;
24 import org.omg.CORBA.UserException JavaDoc;
25
26 import org.jacorb.orb.SystemExceptionHelper;
27
28 /**
29  * This class is an iterator over an array
30  * of ClientRequestInterceptors.
31  *
32  * @author Nicolas Noffke
33  * @version $Id: ClientInterceptorIterator.java,v 1.12 2004/05/06 12:40:00 nicolas Exp $
34  */

35
36 public class ClientInterceptorIterator
37     extends RequestInterceptorIterator
38 {
39     public static final short SEND_REQUEST = 0;
40     public static final short SEND_POLL = 1;
41     public static final short RECEIVE_REPLY = 2;
42     public static final short RECEIVE_EXCEPTION = 3;
43     public static final short RECEIVE_OTHER = 4;
44
45     private ClientRequestInfoImpl info = null;
46
47     public ClientInterceptorIterator(Interceptor[] interceptors)
48     {
49     super(interceptors);
50     }
51
52     public void iterate(ClientRequestInfoImpl info, short op)
53     throws UserException JavaDoc
54     {
55     this.info = info;
56     this.op = op;
57     
58     // ok, op <= SEND_POLL is more efficient but
59
// less understandable
60
setDirection((op == SEND_REQUEST) || (op == SEND_POLL));
61
62     iterate();
63
64     //propagate last exception upwards
65
if (interceptor_ex != null)
66         if (interceptor_ex instanceof ForwardRequest)
67         throw (ForwardRequest) interceptor_ex;
68         else
69         throw (org.omg.CORBA.SystemException JavaDoc) interceptor_ex;
70     }
71
72     /**
73      * Iterates over the enumeration, i.e. calls "op" on
74      * nextElement() until !hasMoreElements().
75      */

76     protected void invoke(Interceptor interceptor)
77     throws UserException JavaDoc
78     {
79     info.caller_op = op;
80
81     try
82         {
83             switch (op)
84             {
85         case SEND_REQUEST :
86         ((ClientRequestInterceptor) interceptor).send_request(info);
87         break;
88         case SEND_POLL :
89         ((ClientRequestInterceptor) interceptor).send_poll(info);
90         break;
91         case RECEIVE_REPLY :
92         ((ClientRequestInterceptor) interceptor).receive_reply(info);
93         break;
94         case RECEIVE_EXCEPTION :
95         ((ClientRequestInterceptor) interceptor).receive_exception(info);
96         break;
97         case RECEIVE_OTHER :
98         ((ClientRequestInterceptor) interceptor).receive_other(info);
99         }
100     }
101         catch (ForwardRequest _fwd)
102         {
103         reverseDirection();
104         op = RECEIVE_OTHER;
105     
106             info.reply_status = LOCATION_FORWARD.value;
107
108         info.forward_reference = _fwd.forward;
109         interceptor_ex = _fwd;
110     }
111         catch (org.omg.CORBA.SystemException JavaDoc _sysex)
112         {
113         reverseDirection();
114         op = RECEIVE_EXCEPTION;
115         interceptor_ex = _sysex;
116
117         SystemExceptionHelper.insert(info.received_exception, _sysex);
118     
119         try
120             {
121         info.received_exception_id = SystemExceptionHelper.type(_sysex).id();
122         }
123             catch(org.omg.CORBA.TypeCodePackage.BadKind JavaDoc _bk)
124             {
125         }
126     }
127         catch (Throwable JavaDoc th)
128         {
129     }
130       
131     info.caller_op = op;
132     }
133 } // ClientInterceptorIterator
134

135
136
Popular Tags