1 26 27 package org.objectweb.corba.trace.PI; 28 29 34 35 public abstract class RequestInfoReader { 36 protected int id_unique = 0; 37 38 41 protected short logLevel = 1; 42 43 46 protected final int REQUEST_CONTEXT_ID = 100; 47 protected final int REPLY_CONTEXT_ID = 101; 48 49 53 public RequestInfoReader(short logLevel) { 54 setLogLevel(logLevel); 55 } 56 57 60 63 protected String displayRequestInfo( 64 org.omg.PortableInterceptor.RequestInfo info, 65 short logLevel) { 66 String 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 86 protected String displayRequestID( 87 org.omg.PortableInterceptor.RequestInfo info) { 88 return "request id = " + info.request_id(); 89 } 90 91 96 protected String displayOperation( 97 org.omg.PortableInterceptor.RequestInfo info) { 98 return "\toperation = " + info.operation() + "\t"; 99 } 100 101 106 protected String displayResponseExpected( 107 org.omg.PortableInterceptor.RequestInfo info) { 108 return "\tresponse expected = " 109 + (info.response_expected() ? "true" : "false"); 110 } 111 112 117 protected String displayArguments( 118 org.omg.PortableInterceptor.RequestInfo info) { 119 String res = "\targuments = "; 120 try { 121 org.omg.Dynamic.Parameter [] 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 { res = res + "inout "; 135 } 136 res = res + args[i].argument; 137 } 138 } 139 res = res + "\n"; 140 } catch (org.omg.CORBA.BAD_INV_ORDER ex) { 141 } catch (org.omg.CORBA.NO_RESOURCES ex) { 143 } 145 return res; 146 } 147 148 153 protected String displayException( 154 org.omg.PortableInterceptor.RequestInfo info) { 155 String res = ""; 156 try { 157 org.omg.CORBA.Any exception = requestOpException(info); 158 res = res + "\t" + getLabelException() + exception; 159 } catch (org.omg.CORBA.BAD_INV_ORDER ex) { 160 } 162 return res; 163 } 164 165 170 protected String displayExceptions( 171 org.omg.PortableInterceptor.RequestInfo info) { 172 String res = "\texceptions = "; 173 try { 174 org.omg.CORBA.TypeCode [] 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 ex) { 183 } catch (org.omg.CORBA.NO_RESOURCES ex) { 185 } 187 return res; 188 } 189 190 195 protected String displayResult( 196 org.omg.PortableInterceptor.RequestInfo info) { 197 String res = ""; 198 try { 199 org.omg.CORBA.Any result = info.result(); 200 201 res = res + "\tresult = "; 202 res = res + result; 203 } catch (org.omg.CORBA.BAD_INV_ORDER ex) { 204 } catch (org.omg.CORBA.NO_RESOURCES ex) { 206 } 208 return res; 209 } 210 211 216 protected String displayReplyStatus( 217 org.omg.PortableInterceptor.RequestInfo info) { 218 String 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 ( 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 ex) { 243 } 245 return res; 246 } 247 248 protected String displayRequestInfoMore( 249 org.omg.PortableInterceptor.RequestInfo info) { 250 return displaySlotData(info) 251 + displayRequestServiceContext(info) 252 + displayReplyServiceContext(info); 253 } 254 255 260 protected String displaySlotData( 261 org.omg.PortableInterceptor.RequestInfo info) { 262 String res = "\n"; 263 272 return res; 273 } 274 275 280 protected String displayRequestServiceContext( 281 org.omg.PortableInterceptor.RequestInfo info) { 282 String res = ""; 283 try { 284 org.omg.IOP.ServiceContext 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 ex) { 291 } catch (org.omg.CORBA.BAD_PARAM ex) { 293 } 295 return res; 296 } 297 298 302 protected String displayReplyServiceContext( 303 org.omg.PortableInterceptor.RequestInfo info) { 304 String res = ""; 305 try { 306 org.omg.IOP.ServiceContext 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 ex) { 313 } catch (org.omg.CORBA.BAD_PARAM ex) { 315 } 317 return res; 318 } 319 320 324 protected int nextId() { 325 return id_unique++; 326 } 327 328 332 public void setLogLevel(short logLevel) { 333 this.logLevel = logLevel; 334 } 335 336 340 public short getLogLevel() { 341 return logLevel; 342 } 343 344 345 protected String getOctet(byte octet) { 346 String prefix; 347 if (octet < 0x10) 348 prefix = "<0"; 349 else 350 prefix = "<"; 351 352 return prefix + Integer.toHexString(octet) + ">"; 353 } 354 355 358 protected abstract String getLabelException(); 359 360 protected abstract String displayMore( 361 org.omg.PortableInterceptor.RequestInfo info); 362 363 protected abstract org.omg.CORBA.Any requestOpException( 364 org.omg.PortableInterceptor.RequestInfo info); 365 366 } 367 | Popular Tags |