1 21 package org.jacorb.orb.portableInterceptor; 22 23 import org.omg.IOP.*; 24 import org.omg.CORBA.*; 25 import org.omg.PortableInterceptor.*; 26 import org.omg.Dynamic.Parameter ; 27 import org.omg.ETF.*; 28 29 import org.apache.avalon.framework.logger.*; 30 31 import java.util.*; 32 import org.jacorb.orb.iiop.IIOPProfile; 33 34 42 43 public class ClientRequestInfoImpl 44 extends RequestInfoImpl 45 implements ClientRequestInfo 46 { 47 private Logger logger; 48 49 public org.omg.CORBA.Object target = null; 51 public org.omg.CORBA.Object effective_target = null; 52 public TaggedProfile effective_profile = null; 53 public Any received_exception = null; 54 public String received_exception_id = null; 55 public TaggedComponent[] effective_components = null; 56 public org.jacorb.orb.Delegate delegate = null; 57 public org.jacorb.orb.ORB orb = null; 58 59 public org.jacorb.orb.giop.RequestOutputStream request_os = null; 60 public org.jacorb.orb.giop.ReplyInputStream reply_is = null; 61 62 public org.jacorb.orb.giop.ClientConnection connection = null; 63 64 public ClientRequestInfoImpl 65 ( org.jacorb.orb.ORB orb, 66 org.jacorb.orb.giop.RequestOutputStream ros, 67 org.omg.CORBA.Object self, 68 org.jacorb.orb.Delegate delegate, 69 org.jacorb.orb.ParsedIOR piorOriginal, 70 org.jacorb.orb.giop.ClientConnection connection ) 71 { 72 this.orb = orb; 73 logger = orb.getConfiguration().getNamedLogger("jacorb.orb.interceptors"); 74 75 this.operation = ros.operation(); 76 this.response_expected = ros.response_expected(); 77 this.received_exception = orb.create_any(); 78 79 if ( ros.getRequest() != null ) 80 this.setRequest( ros.getRequest() ); 81 82 this.effective_target = self; 83 84 org.jacorb.orb.ParsedIOR pior = delegate.getParsedIOR(); 85 86 if ( piorOriginal != null ) 87 this.target = orb._getObject( pior ); 88 else 89 this.target = self; 90 91 Profile profile = pior.getEffectiveProfile(); 92 if (profile instanceof org.jacorb.orb.etf.ProfileBase) 93 { 94 this.effective_profile = ((org.jacorb.orb.etf.ProfileBase)profile).asTaggedProfile(); 95 this.effective_components = ((org.jacorb.orb.etf.ProfileBase)profile).getComponents().asArray(); 96 } 97 98 if ( this.effective_components == null ) 99 { 100 this.effective_components = new org.omg.IOP.TaggedComponent [ 0 ]; 101 } 102 103 this.delegate = delegate; 104 105 this.request_id = ros.requestId(); 106 InterceptorManager manager = orb.getInterceptorManager(); 107 108 this.current = manager.getCurrent(); 109 110 this.request_os = ros; 112 113 this.connection = connection; 115 } 116 117 public void setRequest(org.jacorb.orb.dii.Request request) 118 { 119 arguments = new org.omg.Dynamic.Parameter [request.arguments.count()]; 120 for (int i = 0; i < arguments.length; i++) 121 { 122 try 123 { 124 NamedValue value = request.arguments.item(i); 125 126 ParameterMode mode = null; 127 if (value.flags() == ARG_IN.value) 128 mode = ParameterMode.PARAM_IN; 129 else if (value.flags() == ARG_OUT.value) 130 mode = ParameterMode.PARAM_OUT; 131 else if (value.flags() == ARG_INOUT.value) 132 mode = ParameterMode.PARAM_INOUT; 133 134 arguments[i] = new org.omg.Dynamic.Parameter (value.value(), mode); 135 } 136 catch (Exception e) 137 { 138 if( logger.isDebugEnabled() ) 139 { 140 logger.debug(e.getMessage()); 141 } 142 } 143 } 144 } 146 147 152 153 public Enumeration getRequestServiceContexts() 154 { 155 return request_ctx.elements(); 156 } 157 158 161 public Parameter [] arguments() 162 { 163 if (! (caller_op == ClientInterceptorIterator.SEND_REQUEST) && 164 ! (caller_op == ClientInterceptorIterator.RECEIVE_REPLY)) 165 throw new BAD_INV_ORDER("The attribute \"arguments\" is currently invalid!", 166 10, CompletionStatus.COMPLETED_MAYBE); 167 168 if (arguments == null) 169 throw new NO_RESOURCES("Stream-based skeletons/stubs do not support this op", 170 1, CompletionStatus.COMPLETED_MAYBE); 171 else 172 return arguments; 173 } 174 175 public TypeCode[] exceptions() 176 { 177 if (caller_op == ClientInterceptorIterator.SEND_POLL) 178 throw new BAD_INV_ORDER("The attribute \"exceptions\" is currently invalid!", 179 10, CompletionStatus.COMPLETED_MAYBE); 180 181 if (exceptions == null) 182 throw new NO_RESOURCES("Stream-based skeletons/stubs do not support this op", 183 1, CompletionStatus.COMPLETED_MAYBE); 184 else 185 return exceptions; 186 } 187 188 public Any result() 189 { 190 if (caller_op != ClientInterceptorIterator.RECEIVE_REPLY) 191 throw new BAD_INV_ORDER("The attribute \"result\" is currently invalid!", 192 10, CompletionStatus.COMPLETED_MAYBE); 193 194 if (result == null) 195 throw new NO_RESOURCES("Stream-based skeletons/stubs do not support this op", 196 1, CompletionStatus.COMPLETED_MAYBE); 197 else 198 return result; 199 } 200 201 public short sync_scope() 202 { 203 if (caller_op == ClientInterceptorIterator.SEND_POLL) 204 throw new BAD_INV_ORDER("The attribute \"sync_scope\" is currently invalid!", 205 10, CompletionStatus.COMPLETED_MAYBE); 206 207 return org.omg.Messaging.SYNC_WITH_TRANSPORT.value; 208 } 209 210 public short reply_status() 211 { 212 if ((caller_op == ClientInterceptorIterator.SEND_REQUEST) || 213 (caller_op == ClientInterceptorIterator.SEND_POLL)) 214 throw new BAD_INV_ORDER("The attribute \"reply_status\" is currently invalid!", 215 10, CompletionStatus.COMPLETED_MAYBE); 216 217 return reply_status; 218 } 219 220 public org.omg.CORBA.Object forward_reference() 221 { 222 if( (caller_op != ClientInterceptorIterator.RECEIVE_OTHER) || 223 (reply_status != LOCATION_FORWARD.value) ) 224 throw new BAD_INV_ORDER("The attribute \"forward_reference\" is currently " + 225 "invalid!", 10, CompletionStatus.COMPLETED_MAYBE); 226 227 return forward_reference; 228 } 229 230 public ServiceContext get_request_service_context(int id) 231 { 232 if (caller_op == ClientInterceptorIterator.SEND_POLL) 233 throw new BAD_INV_ORDER("The attribute \"operation_context\" is currently " + 234 "invalid!", 10, CompletionStatus.COMPLETED_MAYBE); 235 236 return super.get_request_service_context(id); 237 } 238 239 public ServiceContext get_reply_service_context(int id) 240 { 241 if ((caller_op == ClientInterceptorIterator.SEND_REQUEST) || 242 (caller_op == ClientInterceptorIterator.SEND_POLL)) 243 throw new BAD_INV_ORDER("The attribute \"reply_status\" is currently invalid!", 244 10, CompletionStatus.COMPLETED_MAYBE); 245 246 return super.get_reply_service_context(id); 247 } 248 249 public org.omg.CORBA.Object target() 251 { 252 return target; 253 } 254 255 public org.omg.CORBA.Object effective_target() 256 { 257 return effective_target; 258 } 259 260 public TaggedProfile effective_profile() { 261 return effective_profile; 262 } 263 264 public Any received_exception() 265 { 266 if (caller_op != ClientInterceptorIterator.RECEIVE_EXCEPTION) 267 throw new BAD_INV_ORDER("The attribute \"received_exception\" is currently " + 268 "invalid!", 10, CompletionStatus.COMPLETED_MAYBE); 269 270 return received_exception; 271 } 272 273 public String received_exception_id() 274 { 275 if (caller_op != ClientInterceptorIterator.RECEIVE_EXCEPTION) 276 throw new BAD_INV_ORDER("The attribute \"received_exception_id\" is " + 277 "currently invalid!", 10, 278 CompletionStatus.COMPLETED_MAYBE); 279 280 return received_exception_id; 281 } 282 283 public TaggedComponent get_effective_component(int id) 284 { 285 if (caller_op == ClientInterceptorIterator.SEND_POLL) 286 throw new BAD_INV_ORDER("The operation \"get_effective_component\" is " + 287 "currently invalid!", 10, 288 CompletionStatus.COMPLETED_MAYBE); 289 290 for(int _i = 0; _i < effective_components.length; _i++) 291 if (effective_components[_i].tag == id) 292 return effective_components[_i]; 293 294 throw new BAD_PARAM("No TaggedComponent with id " + id + " found", 295 25, CompletionStatus.COMPLETED_MAYBE); 296 } 297 298 public TaggedComponent[] get_effective_components(int id) 299 { 300 if (caller_op == ClientInterceptorIterator.SEND_POLL) 301 throw new BAD_INV_ORDER("The operation \"get_effective_components\" is " + 302 "currently invalid!", 10, 303 CompletionStatus.COMPLETED_MAYBE); 304 305 Vector _store = new Vector(); 306 for(int _i = 0; _i < effective_components.length; _i++) 307 if (effective_components[_i].tag == id) 308 _store.addElement(effective_components[_i]); 309 310 if (_store.size() == 0) 311 throw new BAD_PARAM("No TaggedComponents with id " + id + " found", 312 25, CompletionStatus.COMPLETED_MAYBE); 313 else 314 { 315 TaggedComponent[] _result = new TaggedComponent[_store.size()]; 316 for (int _i = 0; _i < _result.length; _i++) 317 _result[_i] = (TaggedComponent) _store.elementAt(_i); 318 319 return _result; 320 } 321 } 322 323 327 328 public Policy get_request_policy(int type) 329 { 330 if (caller_op == ClientInterceptorIterator.SEND_POLL) 331 throw new BAD_INV_ORDER("The operation \"get_request_policy\" is currently " + 332 "invalid!", 10, CompletionStatus.COMPLETED_MAYBE); 333 334 if (! orb.hasPolicyFactoryForType(type)) 335 throw new INV_POLICY("No PolicyFactory for type " + type + 336 " has been registered!", 1, 337 CompletionStatus.COMPLETED_MAYBE); 338 try 339 { 340 return delegate.get_policy (target, type); 341 } 342 catch(INV_POLICY _e) 343 { 344 _e.minor = 1; 345 throw _e; 346 } 347 } 348 349 public void add_request_service_context(ServiceContext service_context, 350 boolean replace) 351 { 352 353 if (caller_op != ClientInterceptorIterator.SEND_REQUEST) 354 throw new BAD_INV_ORDER("The operation \"add_request_service_context\" is " + 355 "currently invalid!", 10, 356 CompletionStatus.COMPLETED_MAYBE); 357 358 Integer _id = new Integer (service_context.context_id); 359 360 if (! replace && request_ctx.containsKey(_id)) 361 throw new BAD_INV_ORDER("The ServiceContext with id " + _id.toString() 362 + " has already been set!", 11, 363 CompletionStatus.COMPLETED_MAYBE); 364 365 request_ctx.put(_id, service_context); 366 } 367 368 } | Popular Tags |