KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > trace > PI > RequestInfoReader


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Offroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.corba.trace.PI;
28
29 /**
30  * @author offroy@lifl.fr
31  *
32  * used to read common thing from a RequestInfo
33  */

34
35 public abstract class RequestInfoReader {
36     protected int id_unique = 0;
37
38     /**
39      * default log level for CORBA Interceptors
40      */

41     protected short logLevel = 1;
42
43     /**
44      * Service context identifiers
45      */

46     protected final int REQUEST_CONTEXT_ID = 100;
47     protected final int REPLY_CONTEXT_ID = 101;
48
49     /**
50      * Constructor
51      * @param logLevel
52      **/

53     public RequestInfoReader(short logLevel) {
54         setLogLevel(logLevel);
55     }
56
57     /************************************************************************
58      * Protected Method
59      ***********************************************************************/

60     /**
61      * Display PortableInterceptor::RequestInfo
62      */

63     protected String JavaDoc displayRequestInfo(
64         org.omg.PortableInterceptor.RequestInfo JavaDoc info,
65         short logLevel) {
66         String JavaDoc res = "";
67         res = res
68                 + displayRequestID(info)
69                 + displayOperation(info)
70                 + displayArguments(info)
71                 + displayExceptions(info)
72                 + displayResult(info)
73                 + displayResponseExpected(info)
74                 + displayReplyStatus(info);
75         if (logLevel > 1) {
76             res = res + displayRequestInfoMore(info);
77         }
78         return res;
79     }
80
81     /**
82      * Display PortableInterceptor::RequestInfo RequestID
83      * @param info
84      * @return String
85      */

86     protected String JavaDoc displayRequestID(
87         org.omg.PortableInterceptor.RequestInfo JavaDoc info) {
88         return "request id = " + info.request_id();
89     }
90
91     /**
92      * Display PortableInterceptor::RequestInfo Operation
93      * @param info
94      * @return String
95      */

96     protected String JavaDoc displayOperation(
97         org.omg.PortableInterceptor.RequestInfo JavaDoc info) {
98         return "\toperation = " + info.operation() + "\t";
99     }
100
101     /**
102      * Display PortableInterceptor::RequestInfo ResponseExpected
103      * @param info
104      * @return String
105      */

106     protected String JavaDoc displayResponseExpected(
107         org.omg.PortableInterceptor.RequestInfo JavaDoc info) {
108         return "\tresponse expected = "
109             + (info.response_expected() ? "true" : "false");
110     }
111
112     /**
113      * Display PortableInterceptor::RequestInfo Arguments
114      * @param info
115      * @return String
116      */

117     protected String JavaDoc displayArguments(
118         org.omg.PortableInterceptor.RequestInfo JavaDoc info) {
119         String JavaDoc res = "\targuments = ";
120         try {
121             org.omg.Dynamic.Parameter JavaDoc[] args = info.arguments();
122             if (args.length == 0) {
123                 res = res + "(no arguments)";
124             } else {
125                 for (int i = 0; i < args.length; i++) {
126                     res = res + "\n";
127                     if (args[i].mode == org.omg.CORBA.ParameterMode.PARAM_IN) {
128                         res = res + "in ";
129                     } else if (
130                         args[i].mode
131                             == org.omg.CORBA.ParameterMode.PARAM_OUT) {
132                         res = res + "out ";
133                     } else { // case PARAM_INOUT:
134
res = res + "inout ";
135                     }
136                     res = res + args[i].argument;
137                 }
138             }
139             res = res + "\n";
140         } catch (org.omg.CORBA.BAD_INV_ORDER JavaDoc ex) {
141             //res = res + "Operation not supported in this context";
142
} catch (org.omg.CORBA.NO_RESOURCES JavaDoc ex) {
143             //res = res + "Operation not supported in this environment";
144
}
145         return res;
146     }
147
148     /**
149      * Display PortableInterceptor::RequestInfo Exception
150      * @param info
151      * @return String
152      */

153     protected String JavaDoc displayException(
154         org.omg.PortableInterceptor.RequestInfo JavaDoc info) {
155         String JavaDoc res = "";
156         try {
157             org.omg.CORBA.Any JavaDoc exception = requestOpException(info);
158             res = res + "\t" + getLabelException() + exception;
159         } catch (org.omg.CORBA.BAD_INV_ORDER JavaDoc ex) {
160             //res = res + "Operation not supported in this context";
161
}
162         return res;
163     }
164
165     /**
166      * Display PortableInterceptor::RequestInfo Exceptions
167      * @param info
168      * @return String
169      */

170     protected String JavaDoc displayExceptions(
171         org.omg.PortableInterceptor.RequestInfo JavaDoc info) {
172         String JavaDoc res = "\texceptions = ";
173         try {
174             org.omg.CORBA.TypeCode JavaDoc[] exceptions = info.exceptions();
175             if (exceptions.length == 0) {
176                 res = res + "\n" + "(no exceptions)";
177             } else {
178                 res = res + "\n";
179                 for (int i = 0; i < exceptions.length; i++)
180                     res = res + exceptions[i];
181             }
182         } catch (org.omg.CORBA.BAD_INV_ORDER JavaDoc ex) {
183             //res = res + "Operation not supported in this context";
184
} catch (org.omg.CORBA.NO_RESOURCES JavaDoc ex) {
185             //res = res + "Operation not supported in this environment";
186
}
187         return res;
188     }
189
190     /**
191      * Display PortableInterceptor::RequestInfo Result
192      * @param info
193      * @return String
194      */

195     protected String JavaDoc displayResult(
196         org.omg.PortableInterceptor.RequestInfo JavaDoc info) {
197         String JavaDoc res = "";
198         try {
199             org.omg.CORBA.Any JavaDoc result = info.result();
200
201             res = res + "\tresult = ";
202             res = res + result;
203         } catch (org.omg.CORBA.BAD_INV_ORDER JavaDoc ex) {
204             //res = res + "Operation not supported in this context";
205
} catch (org.omg.CORBA.NO_RESOURCES JavaDoc ex) {
206             //res = res + "Operation not supported in this environment";
207
}
208         return res;
209     }
210
211     /**
212      * Display PortableInterceptor::RequestInfo Reply Status
213      * @param info
214      * @return String
215      */

216     protected String JavaDoc displayReplyStatus(
217         org.omg.PortableInterceptor.RequestInfo JavaDoc info) {
218         String JavaDoc res = "";
219         try {
220             short status = info.reply_status();
221
222             res = res + "\treply status = ";
223             if (status == org.omg.PortableInterceptor.SUCCESSFUL.value)
224                 res = res + "SUCCESSFUL";
225             else if (
226                 status == org.omg.PortableInterceptor.SYSTEM_EXCEPTION.value)
227                 res = res + "SYSTEM_EXCEPTION";
228             else if (
229                 status == org.omg.PortableInterceptor.USER_EXCEPTION.value)
230                 res = res + "USER_EXCEPTION";
231             else if (
232                 status == org.omg.PortableInterceptor.LOCATION_FORWARD.value)
233                 res = res + "LOCATION_FORWARD";
234             //else if (status == org.omg.PortableInterceptor.
235
// LOCATION_FORWARD_PERMANENT.value)
236
//res = res +"LOCATION_FORWARD_PERMANENT";
237
else if (
238                 status == org.omg.PortableInterceptor.TRANSPORT_RETRY.value)
239                 res = res + "TRANSPORT_RETRY";
240             else
241                 res = res + "UNKNOWN_REPLY_STATUS";
242         } catch (org.omg.CORBA.BAD_INV_ORDER JavaDoc ex) {
243             //res = res + "Operation not supported in this context";
244
}
245         return res;
246     }
247     /* Display PortableInterceptor::RequestInfo More */
248     protected String JavaDoc displayRequestInfoMore(
249         org.omg.PortableInterceptor.RequestInfo JavaDoc info) {
250         return displaySlotData(info)
251             + displayRequestServiceContext(info)
252             + displayReplyServiceContext(info);
253     }
254
255     /**
256      * Display PortableInterceptor::RequestInfo SlotData
257      * @param info
258      * @return String
259      */

260     protected String JavaDoc displaySlotData(
261         org.omg.PortableInterceptor.RequestInfo JavaDoc info) {
262         String JavaDoc res = "\n";
263         /*try{
264         org.omg.CORBA.Any slotData = info.get_slot(mySlotId_);
265         
266         res = res +"slot data " + mySlotId_ + " = \n";
267         
268         res = res +slotData;
269         res = res +"\n";
270         }catch(org.omg.PortableInterceptor.InvalidSlot ex){}
271         */

272         return res;
273     }
274
275     /**
276      * Display PortableInterceptor::RequestInfo RequestServiceContext
277      * @param info
278      * @return String
279      */

280     protected String JavaDoc displayRequestServiceContext(
281         org.omg.PortableInterceptor.RequestInfo JavaDoc info) {
282         String JavaDoc res = "";
283         try {
284             org.omg.IOP.ServiceContext JavaDoc context =
285                 info.get_request_service_context(REQUEST_CONTEXT_ID);
286
287             res = res + "request service context " + REQUEST_CONTEXT_ID + " = ";
288             for (int i = 0; i < context.context_data.length; i++)
289                 res = res + getOctet(context.context_data[i]);
290         } catch (org.omg.CORBA.BAD_INV_ORDER JavaDoc ex) {
291             //res = res + "Operation not supported in this context";
292
} catch (org.omg.CORBA.BAD_PARAM JavaDoc ex) {
293             //res = res + "No entry found";
294
}
295         return res;
296     }
297
298     /**
299      * Display PortableInterceptor::RequestInfo ReplyServiceContext
300      * @param info ResuestInfo to use
301      **/

302     protected String JavaDoc displayReplyServiceContext(
303         org.omg.PortableInterceptor.RequestInfo JavaDoc info) {
304         String JavaDoc res = "";
305         try {
306             org.omg.IOP.ServiceContext JavaDoc context =
307                 info.get_reply_service_context(REPLY_CONTEXT_ID);
308
309             res = res + "\treply service context " + REPLY_CONTEXT_ID + " = ";
310             for (int i = 0; i < context.context_data.length; i++)
311                 res = res + getOctet(context.context_data[i]);
312         } catch (org.omg.CORBA.BAD_INV_ORDER JavaDoc ex) {
313             //res = res + "Operation not supported in this context";
314
} catch (org.omg.CORBA.BAD_PARAM JavaDoc ex) {
315             //res = res + "No entry found";
316
}
317         return res;
318     }
319
320     /**
321      * Get next message id
322      * @return int
323      **/

324     protected int nextId() {
325         return id_unique++;
326     }
327
328     /**
329     * Sets the logLevel.
330     * @param logLevel The logLevel to set
331     */

332     public void setLogLevel(short logLevel) {
333         this.logLevel = logLevel;
334     }
335
336     /**
337      * Returns the logLevel.
338      * @return short
339      **/

340     public short getLogLevel() {
341         return logLevel;
342     }
343
344     /* Convert CORBA::Octet to string */
345     protected String JavaDoc getOctet(byte octet) {
346         String JavaDoc prefix;
347         if (octet < 0x10)
348             prefix = "<0";
349         else
350             prefix = "<";
351
352         return prefix + Integer.toHexString(octet) + ">";
353     }
354
355     /************************************************************************
356      * Abstract implementation Method
357      ***********************************************************************/

358     protected abstract String JavaDoc getLabelException();
359
360     protected abstract String JavaDoc displayMore(
361         org.omg.PortableInterceptor.RequestInfo JavaDoc info);
362
363     protected abstract org.omg.CORBA.Any JavaDoc requestOpException(
364         org.omg.PortableInterceptor.RequestInfo JavaDoc info);
365
366 }
367
Popular Tags