59 |
import org.omg.CORBA.portable.InvokeHandler; |
import org.omg.CORBA.portable.InvokeHandler; |
60 |
import org.omg.CORBA.portable.ObjectImpl; |
import org.omg.CORBA.portable.ObjectImpl; |
61 |
import org.omg.CORBA.portable.OutputStream; |
import org.omg.CORBA.portable.OutputStream; |
62 |
import org.omg.CORBA_2_3.portable.Delegate; |
import org.omg.CORBA.portable.RemarshalException; |
63 |
import org.omg.PortableServer.ServantLocatorPackage.CookieHolder; |
import org.omg.PortableServer.ServantLocatorPackage.CookieHolder; |
64 |
|
|
65 |
import java.util.Arrays; |
import java.util.Arrays; |
66 |
|
|
67 |
/** |
/** |
68 |
* A local delegate, transferring all object requests to the locally |
* A local delegate, transferring all object requests to the locally available |
69 |
* available servant. This class is involved in handling the method |
* servant. This class is involved in handling the method invocations on the |
70 |
* invocations on the local object, obtained by |
* local object, obtained by POA.create_reference_with_id. |
|
* POA.create_reference_with_id. |
|
71 |
* |
* |
72 |
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) |
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) |
73 |
*/ |
*/ |
74 |
public class LocalDelegate |
public class LocalDelegate extends org.omg.CORBA_2_3.portable.Delegate |
|
extends org.omg.CORBA_2_3.portable.Delegate |
|
75 |
{ |
{ |
76 |
/** |
/** |
77 |
* The same servant as an invocation handler. |
* The same servant as an invocation handler. |
82 |
final byte[] Id; |
final byte[] Id; |
83 |
|
|
84 |
/** |
/** |
85 |
* Create a local delegate, forwarding requests to the |
* Create a local delegate, forwarding requests to the servant that must also |
86 |
* servant that must also be an invocation handler. |
* be an invocation handler. |
87 |
*/ |
*/ |
88 |
public LocalDelegate(gnuServantObject an_object, gnuPOA a_poa, byte[] an_id) |
public LocalDelegate(gnuServantObject an_object, gnuPOA a_poa, byte[] an_id) |
89 |
{ |
{ |
107 |
} |
} |
108 |
|
|
109 |
public boolean is_equivalent(org.omg.CORBA.Object target, |
public boolean is_equivalent(org.omg.CORBA.Object target, |
110 |
org.omg.CORBA.Object other |
org.omg.CORBA.Object other |
111 |
) |
) |
112 |
{ |
{ |
113 |
if (target == other) |
if (target == other) |
114 |
return true; |
return true; |
157 |
|
|
158 |
/** |
/** |
159 |
* Check if this object could be named by the given repository id. |
* Check if this object could be named by the given repository id. |
160 |
|
* |
161 |
* @param idl_id the repository id to check. |
* @param idl_id the repository id to check. |
162 |
* |
* |
163 |
* @return true if it is one of the possible repository ids of this |
* @return true if it is one of the possible repository ids of this object. |
|
* object. |
|
164 |
*/ |
*/ |
165 |
public boolean is_a(org.omg.CORBA.Object a_servant, String idl_id) |
public boolean is_a(org.omg.CORBA.Object a_servant, String idl_id) |
166 |
{ |
{ |
185 |
* Create request for using with DII. |
* Create request for using with DII. |
186 |
*/ |
*/ |
187 |
public Request create_request(org.omg.CORBA.Object target, Context context, |
public Request create_request(org.omg.CORBA.Object target, Context context, |
188 |
String method, NVList parameters, |
String method, NVList parameters, NamedValue returns, |
189 |
NamedValue returns, ExceptionList exceptions, |
ExceptionList exceptions, ContextList ctx_list |
190 |
ContextList ctx_list |
) |
|
) |
|
191 |
{ |
{ |
192 |
operation = method; |
operation = method; |
193 |
|
|
204 |
* Create request for using with DII. |
* Create request for using with DII. |
205 |
*/ |
*/ |
206 |
public Request create_request(org.omg.CORBA.Object target, Context context, |
public Request create_request(org.omg.CORBA.Object target, Context context, |
207 |
String method, NVList parameters, |
String method, NVList parameters, NamedValue returns |
208 |
NamedValue returns |
) |
|
) |
|
209 |
{ |
{ |
210 |
operation = method; |
operation = method; |
211 |
|
|
233 |
* |
* |
234 |
* @return the stream where the method arguments should be written. |
* @return the stream where the method arguments should be written. |
235 |
*/ |
*/ |
236 |
public org.omg.CORBA.portable.OutputStream request(org.omg.CORBA.Object target, |
public org.omg.CORBA.portable.OutputStream request( |
237 |
String method, |
org.omg.CORBA.Object target, |
238 |
boolean response_expected |
String method, |
239 |
) |
boolean response_expected |
240 |
|
) |
241 |
{ |
{ |
242 |
operation = method; |
operation = method; |
243 |
|
|
282 |
* Make an invocation. |
* Make an invocation. |
283 |
* |
* |
284 |
* @param target not in use. |
* @param target not in use. |
285 |
* @param output the stream request that should be returned by {@link #request} |
* @param output the stream request that should be returned by |
286 |
* in this method. |
* {@link #m_request} in this method. |
287 |
* @throws ApplicationException if the use exception is thrown by |
* @throws ApplicationException if the use exception is thrown by the servant |
288 |
* the servant method. |
* method. |
289 |
*/ |
*/ |
290 |
public InputStream invoke(org.omg.CORBA.Object target, OutputStream output) |
public InputStream invoke(org.omg.CORBA.Object target, OutputStream output) |
291 |
throws ApplicationException |
throws ApplicationException |
292 |
{ |
{ |
293 |
streamRequest sr = (streamRequest) output; |
try |
|
|
|
|
LocalRequest lr = (LocalRequest) sr.request; |
|
|
InvokeHandler handler = lr.object.getHandler(lr.operation(), lr.cookie, false); |
|
|
|
|
|
if (handler instanceof dynImpHandler) |
|
294 |
{ |
{ |
295 |
// The local request known how to handle it, but the different |
streamRequest sr = (streamRequest) output; |
|
// method must be called. |
|
|
lr.invoke(); |
|
296 |
|
|
297 |
// The encapsulation will inherit orb, endian, charsets, etc. |
LocalRequest lr = (LocalRequest) sr.request; |
298 |
cdrOutput buf = sr.createEncapsulation(); |
InvokeHandler handler = |
299 |
|
lr.object.getHandler(lr.operation(), lr.cookie, false); |
300 |
|
|
301 |
// Write all request parameters to the buffer stream. |
if (handler instanceof dynImpHandler) |
|
if (lr.env().exception() != null) |
|
302 |
{ |
{ |
303 |
|
// The local request known how to handle it, but the different |
304 |
|
// method must be called. |
305 |
|
lr.invoke(); |
306 |
|
|
307 |
|
// The encapsulation will inherit orb, endian, charsets, etc. |
308 |
|
cdrOutput buf = sr.createEncapsulation(); |
309 |
|
|
310 |
|
// Write all request parameters to the buffer stream. |
311 |
|
if (lr.env().exception() != null) |
312 |
|
{ |
313 |
|
try |
314 |
|
{ |
315 |
|
UnknownUserException uex = |
316 |
|
(UnknownUserException) lr.env().exception(); |
317 |
|
throw new ApplicationException(uex.except.type().id(), |
318 |
|
uex.except.create_input_stream() |
319 |
|
); |
320 |
|
} |
321 |
|
catch (BadKind ex) |
322 |
|
{ |
323 |
|
InternalError ierr = new InternalError(); |
324 |
|
ierr.initCause(ex); |
325 |
|
throw ierr; |
326 |
|
} |
327 |
|
} |
328 |
|
if (lr.return_value() != null) |
329 |
|
lr.return_value().write_value(buf); |
330 |
|
|
331 |
|
NamedValue a; |
332 |
try |
try |
333 |
{ |
{ |
334 |
UnknownUserException uex = |
for (int i = 0; i < lr.arguments().count(); i++) |
335 |
(UnknownUserException) lr.env().exception(); |
{ |
336 |
throw new ApplicationException(uex.except.type().id(), |
a = lr.arguments().item(i); |
337 |
uex.except.create_input_stream() |
if (a.flags() == ARG_INOUT.value || |
338 |
); |
a.flags() == ARG_INOUT.value |
339 |
|
) |
340 |
|
{ |
341 |
|
a.value().write_value(buf); |
342 |
|
} |
343 |
|
} |
344 |
} |
} |
345 |
catch (BadKind ex) |
catch (Bounds ex) |
346 |
{ |
{ |
347 |
InternalError ierr = new InternalError(); |
InternalError ierr = new InternalError(); |
348 |
ierr.initCause(ex); |
ierr.initCause(ex); |
349 |
throw ierr; |
throw ierr; |
350 |
} |
} |
|
} |
|
|
if (lr.return_value() != null) |
|
|
lr.return_value().write_value(buf); |
|
351 |
|
|
352 |
NamedValue a; |
return buf.create_input_stream(); |
353 |
|
} |
354 |
|
else |
355 |
|
{ |
356 |
|
LocalRequest lrq = (LocalRequest) sr.request; |
357 |
|
return lrq.s_invoke(handler); |
358 |
|
} |
359 |
|
} |
360 |
|
catch (gnuForwardRequest f) |
361 |
|
{ |
362 |
try |
try |
363 |
{ |
{ |
364 |
for (int i = 0; i < lr.arguments().count(); i++) |
return ((ObjectImpl) f.forward_reference)._invoke(f.forward_reference._request( |
365 |
{ |
operation, |
366 |
a = lr.arguments().item(i); |
true |
367 |
if (a.flags() == ARG_INOUT.value || |
) |
368 |
a.flags() == ARG_INOUT.value |
); |
|
) |
|
|
{ |
|
|
a.value().write_value(buf); |
|
|
} |
|
|
} |
|
369 |
} |
} |
370 |
catch (Bounds ex) |
catch (RemarshalException e) |
371 |
{ |
{ |
372 |
InternalError ierr = new InternalError(); |
// Never thrown in this place by Classpath implementation. |
373 |
ierr.initCause(ex); |
throw new NO_IMPLEMENT(); |
|
throw ierr; |
|
374 |
} |
} |
|
|
|
|
return buf.create_input_stream(); |
|
375 |
} |
} |
|
else |
|
|
return ((LocalRequest) sr.request).s_invoke(handler); |
|
376 |
} |
} |
377 |
|
|
378 |
public void releaseReply(org.omg.CORBA.Object target, InputStream input) |
public void releaseReply(org.omg.CORBA.Object target, InputStream input) |