KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jacorb.orb.portableInterceptor;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose, Nicolas Noffke
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

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 iterates over an array of
30  * ServerRequestInterceptors.
31  *
32  * @author Nicolas Noffke
33  * @version $Id: ServerInterceptorIterator.java,v 1.10 2004/05/06 12:40:00 nicolas Exp $
34  */

35
36 public class ServerInterceptorIterator
37     extends RequestInterceptorIterator
38 {
39     public static final short RECEIVE_REQUEST_SERVICE_CONTEXTS = 0;
40     public static final short RECEIVE_REQUEST = 1;
41     public static final short SEND_REPLY = 2;
42     public static final short SEND_EXCEPTION = 3;
43     public static final short SEND_OTHER = 4;
44
45     private ServerRequestInfoImpl info = null;
46
47     public ServerInterceptorIterator(Interceptor[] interceptors)
48     {
49     super(interceptors);
50     }
51
52     /**
53      * Iterates over the enumeration, i.e. calls "op" on
54      * nextElement() until !hasMoreElements().
55      */

56     public void iterate( ServerRequestInfoImpl info, short op )
57     throws UserException JavaDoc
58     {
59       
60     this.info = info;
61     this.op = op;
62
63     //set sending_exception right
64
info.update();
65     info.caller_op = op;
66
67     // ok, op <= RECEIVE_REQUEST is more efficient but
68
// less understandable
69
setDirection( (op == RECEIVE_REQUEST_SERVICE_CONTEXTS) ||
70               (op == RECEIVE_REQUEST));
71
72     iterate();
73
74     //propagate last exception upwards
75
if ( interceptor_ex != null )
76         if (interceptor_ex instanceof ForwardRequest)
77         throw (ForwardRequest) interceptor_ex;
78         else
79         throw (org.omg.CORBA.SystemException JavaDoc) interceptor_ex;
80     }
81
82     protected void invoke(Interceptor interceptor)
83     throws UserException JavaDoc
84     {
85
86     try
87         {
88         switch (op)
89             {
90         case RECEIVE_REQUEST_SERVICE_CONTEXTS :
91         ((ServerRequestInterceptor) interceptor).
92             receive_request_service_contexts(info);
93         break;
94         case RECEIVE_REQUEST :
95         ((ServerRequestInterceptor) interceptor).receive_request(info);
96         break;
97         case SEND_REPLY :
98         ((ServerRequestInterceptor) interceptor).send_reply(info);
99         break;
100         case SEND_EXCEPTION :
101         ((ServerRequestInterceptor) interceptor).send_exception(info);
102         break;
103         case SEND_OTHER :
104         ((ServerRequestInterceptor) interceptor).send_other(info);
105         break;
106         }
107     }
108         catch (ForwardRequest _fwd)
109         {
110         reverseDirection();
111         op = SEND_OTHER;
112     
113             info.reply_status = LOCATION_FORWARD.value;
114
115         info.forward_reference = _fwd.forward;
116
117         interceptor_ex = _fwd;
118     }
119         catch (org.omg.CORBA.SystemException JavaDoc _sysex)
120         {
121         reverseDirection();
122         op = SEND_EXCEPTION;
123         interceptor_ex = _sysex;
124
125         SystemExceptionHelper.insert(info.sending_exception, _sysex);
126     }
127         catch (Throwable JavaDoc th)
128         {
129             th.printStackTrace();
130     }
131
132     info.caller_op = op;
133     }
134 } // ServerInterceptorIterator
135

136
137
138
Popular Tags