1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43:
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58:
59: import ;
60:
61:
70: public class IorDelegate extends SimpleDelegate
71: {
72:
75: public IorDelegate(ORB an_orb, IOR an_ior)
76: {
77: super(an_orb, an_ior);
78: }
79:
80:
91: public Request create_request(org.omg.CORBA.Object target, Context context,
92: String operation, NVList parameters, NamedValue returns
93: )
94: {
95: gnuRequest request = getRequestInstance(target);
96:
97: request.setIor(getIor());
98: request.set_target(target);
99:
100: request.setOperation(operation);
101: request.set_args(parameters);
102: request.m_context = context;
103: request.set_result(returns);
104: request.setORB(orb);
105:
106: return request;
107: }
108:
109:
120: public Request create_request(org.omg.CORBA.Object target, Context context,
121: String operation, NVList parameters, NamedValue returns,
122: ExceptionList exceptions, ContextList ctx_list
123: )
124: {
125: gnuRequest request = getRequestInstance(target);
126:
127: request.setIor(ior);
128: request.set_target(target);
129:
130: request.setOperation(operation);
131: request.set_args(parameters);
132: request.m_context = context;
133: request.set_result(returns);
134: request.set_exceptions(exceptions);
135: request.set_context_list(ctx_list);
136: request.setORB(orb);
137:
138: return request;
139: }
140:
141:
144: protected gnuRequest getRequestInstance(org.omg.CORBA.Object target)
145: {
146: return new gnuRequest();
147: }
148:
149:
170: public InputStream invoke(org.omg.CORBA.Object target, OutputStream output)
171: throws ApplicationException, RemarshalException
172: {
173: StreamBasedRequest request = (StreamBasedRequest) output;
174: while (true)
175: {
176: try
177: {
178: if (request.response_expected)
179: {
180: RawReply response = request.request.submit();
181:
182:
183: ReplyHeader rh = response.header.create_reply_header();
184: BufferredCdrInput input = response.getStream();
185: input.setOrb(orb);
186: rh.read(input);
187: request.request.m_rph = rh;
188:
189: boolean moved_permanently = false;
190:
191: switch (rh.reply_status)
192: {
193: case ReplyHeader.NO_EXCEPTION:
194: if (request.request.m_interceptor != null)
195: request.request.m_interceptor.receive_reply(request.request.m_info);
196: if (response.header.version.since_inclusive(1, 2))
197: input.align(8);
198: return input;
199:
200: case ReplyHeader.SYSTEM_EXCEPTION:
201: if (response.header.version.since_inclusive(1, 2))
202: input.align(8);
203: showException(request, input);
204:
205: throw ObjectCreator.readSystemException(input,
206: rh.service_context);
207:
208: case ReplyHeader.USER_EXCEPTION:
209: if (response.header.version.since_inclusive(1, 2))
210: input.align(8);
211: showException(request, input);
212:
213: throw new ApplicationException(
214: request.request.m_exception_id, input);
215:
216: case ReplyHeader.LOCATION_FORWARD_PERM:
217: moved_permanently = true;
218:
219: case ReplyHeader.LOCATION_FORWARD:
220: if (response.header.version.since_inclusive(1, 2))
221: input.align(8);
222:
223: IOR forwarded = new IOR();
224: try
225: {
226: forwarded._read_no_endian(input);
227: }
228: catch (IOException ex)
229: {
230: MARSHAL t = new MARSHAL("Cant read forwarding info",
231: 5102, CompletionStatus.COMPLETED_NO);
232: t.initCause(ex);
233: throw t;
234: }
235:
236: gnuRequest prev = request.request;
237: gnuRequest r = getRequestInstance(target);
238:
239: r.m_interceptor = prev.m_interceptor;
240: r.m_slots = prev.m_slots;
241:
242: r.m_args = prev.m_args;
243: r.m_context = prev.m_context;
244: r.m_context_list = prev.m_context_list;
245: r.m_environment = prev.m_environment;
246: r.m_exceptions = prev.m_exceptions;
247: r.m_operation = prev.m_operation;
248: r.m_parameter_buffer = prev.m_parameter_buffer;
249: r.m_parameter_buffer.request = r;
250: r.m_result = prev.m_result;
251: r.m_target = prev.m_target;
252: r.oneWay = prev.oneWay;
253: r.m_forward_ior = forwarded;
254:
255: if (r.m_interceptor != null)
256: r.m_interceptor.receive_other(r.m_info);
257:
258: r.setIor(forwarded);
259:
260: IorObject it = new IorObject(orb,
261: forwarded);
262:
263: r.m_target = it;
264:
265: request.request = r;
266:
267: IOR prev_ior = getIor();
268:
269: setIor(forwarded);
270:
271: try
272: {
273: return invoke(it, request);
274: }
275: finally
276: {
277: if (!moved_permanently)
278: setIor(prev_ior);
279: }
280:
281: default:
282: throw new MARSHAL("Unknow reply status: "
283: + rh.reply_status, 8000 + rh.reply_status,
284: CompletionStatus.COMPLETED_NO);
285: }
286: }
287: else
288: {
289: request.request.send_oneway();
290: return null;
291: }
292: }
293: catch (ForwardRequest forwarded)
294: {
295: ForwardRequest fw = forwarded;
296: Forwarding2: while (true)
297: {
298: try
299: {
300: gnuRequest prev = request.request;
301: gnuRequest r = getRequestInstance(target);
302:
303: r.m_interceptor = prev.m_interceptor;
304: r.m_args = prev.m_args;
305: r.m_context = prev.m_context;
306: r.m_context_list = prev.m_context_list;
307: r.m_environment = prev.m_environment;
308: r.m_exceptions = prev.m_exceptions;
309: r.m_operation = prev.m_operation;
310: r.m_parameter_buffer = prev.m_parameter_buffer;
311: r.m_parameter_buffer.request = r;
312: r.m_result = prev.m_result;
313: r.m_target = prev.m_target;
314: r.oneWay = prev.oneWay;
315:
316: r.m_forwarding_target = fw.forward;
317:
318: if (r.m_interceptor != null)
319: r.m_interceptor.receive_other(r.m_info);
320:
321: r.m_target = fw.forward;
322: request.request = r;
323: break Forwarding2;
324: }
325: catch (ForwardRequest e)
326: {
327: forwarded = e;
328: }
329: }
330: }
331: }
332: }
333:
334:
337: void showException(StreamBasedRequest request, BufferredCdrInput input)
338: throws ForwardRequest
339: {
340: input.mark(2048);
341: request.request.m_exception_id = input.read_string();
342: input.reset();
343:
344: if (request.request.m_interceptor != null)
345: request.request.m_interceptor.receive_exception(request.request.m_info);
346: }
347:
348:
356: public Request request(org.omg.CORBA.Object target, String operation)
357: {
358: gnuRequest request = getRequestInstance(target);
359:
360: request.setIor(ior);
361: request.set_target(target);
362:
363: request.setOperation(operation);
364: request.setORB(orb);
365:
366: return request;
367: }
368:
369:
379: public OutputStream request(org.omg.CORBA.Object target, String operation,
380: boolean response_expected
381: )
382: {
383: gnuRequest request = getRequestInstance(target);
384:
385: request.setIor(ior);
386: request.set_target(target);
387: request.setOperation(operation);
388:
389: StreamBasedRequest out = request.getParameterStream();
390: out.response_expected = response_expected;
391: request.setORB(orb);
392: out.setOrb(orb);
393:
394: return out;
395: }
396:
397:
404: public void release(org.omg.CORBA.Object target)
405: {
406:
407: }
408:
409:
413: public void setIor(IOR an_ior)
414: {
415: super.setIor(an_ior);
416: }
417:
418:
421: public boolean is_local(org.omg.CORBA.Object self)
422: {
423: return false;
424: }
425: }