Invoke the given method with the args and return the result.
This may result in a remote invocation.
String giopMethodName = classData.getIDLNameTranslator().
getIDLName( method ) ;
DynamicMethodMarshaller dmm =
pm.getDynamicMethodMarshaller( method ) ;
Delegate delegate = null ;
try {
delegate = StubAdapter.getDelegate( stub ) ;
} catch (SystemException ex) {
throw Util.mapSystemException(ex) ;
}
if (!isLocal()) {
try {
org.omg.CORBA_2_3.portable.InputStream in = null ;
try {
// create request
org.omg.CORBA_2_3.portable.OutputStream out =
(org.omg.CORBA_2_3.portable.OutputStream)
delegate.request( stub, giopMethodName, true);
// marshal arguments
dmm.writeArguments( out, args ) ;
// finish invocation
in = (org.omg.CORBA_2_3.portable.InputStream)
delegate.invoke( stub, out);
// unmarshal result
return dmm.readResult( in ) ;
} catch (ApplicationException ex) {
throw dmm.readException( ex ) ;
} catch (RemarshalException ex) {
return invoke( proxy, method, args ) ;
} finally {
delegate.releaseReply( stub, in );
}
} catch (SystemException ex) {
throw Util.mapSystemException(ex) ;
}
} else {
// local branch
ORB orb = (ORB)delegate.orb( stub ) ;
ServantObject so = delegate.servant_preinvoke( stub, giopMethodName,
method.getDeclaringClass() );
if (so == null) {
return invoke( stub, method, args ) ;
}
try {
Object[] copies = dmm.copyArguments( args, orb ) ;
if (!method.isAccessible()) {
// Make sure that we can invoke a method from a normally
// inaccessible package, as this reflective class must always
// be able to invoke a non-public method.
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
method.setAccessible( true ) ;
return null ;
}
} ) ;
}
Object result = method.invoke( so.servant, copies ) ;
return dmm.copyResult( result, orb ) ;
} catch (InvocationTargetException ex) {
Throwable mex = ex.getCause() ;
// mex should never be null, as null cannot be thrown
Throwable exCopy = (Throwable)Util.copyObject(mex,orb);
if (dmm.isDeclaredException( exCopy ))
throw exCopy ;
else
throw Util.wrapException(exCopy);
} catch (Throwable thr) {
if (thr instanceof ThreadDeath)
throw (ThreadDeath)thr ;
// This is not a user thrown exception from the
// method call, so don't copy it. This is either
// an error or a reflective invoke exception.
throw Util.wrapException( thr ) ;
} finally {
delegate.servant_postinvoke( stub, so);
}
}