1 7 8 package com.sun.corba.se.impl.presentation.rmi ; 9 10 import java.security.AccessController ; 11 import java.security.PrivilegedAction ; 12 13 import java.lang.reflect.Method ; 14 import java.lang.reflect.InvocationHandler ; 15 import java.lang.reflect.Proxy ; 16 import java.lang.reflect.InvocationTargetException ; 17 18 import java.io.ObjectInputStream ; 19 import java.io.ObjectOutputStream ; 20 import java.io.IOException ; 21 22 import java.rmi.Remote ; 23 24 import javax.rmi.CORBA.Util ; 25 26 import org.omg.CORBA.portable.ObjectImpl ; 27 import org.omg.CORBA.portable.Delegate ; 28 import org.omg.CORBA.portable.ServantObject ; 29 import org.omg.CORBA.portable.ApplicationException ; 30 import org.omg.CORBA.portable.RemarshalException ; 31 32 import org.omg.CORBA.SystemException ; 33 34 import com.sun.corba.se.spi.orb.ORB ; 35 36 import com.sun.corba.se.pept.transport.ContactInfoList ; 37 38 import com.sun.corba.se.spi.transport.CorbaContactInfoList ; 39 40 import com.sun.corba.se.spi.protocol.CorbaClientDelegate ; 41 import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher ; 42 43 import com.sun.corba.se.spi.presentation.rmi.IDLNameTranslator ; 44 import com.sun.corba.se.spi.presentation.rmi.DynamicMethodMarshaller ; 45 import com.sun.corba.se.spi.presentation.rmi.PresentationManager ; 46 import com.sun.corba.se.spi.presentation.rmi.StubAdapter ; 47 48 import com.sun.corba.se.spi.orbutil.proxy.InvocationHandlerFactory ; 49 import com.sun.corba.se.spi.orbutil.proxy.LinkedInvocationHandler ; 50 51 import com.sun.corba.se.impl.corba.CORBAObjectImpl ; 52 53 public final class StubInvocationHandlerImpl implements LinkedInvocationHandler 54 { 55 private transient PresentationManager.ClassData classData ; 56 private transient PresentationManager pm ; 57 private transient org.omg.CORBA.Object stub ; 58 private transient Proxy self ; 59 60 public void setProxy( Proxy self ) 61 { 62 this.self = self ; 63 } 64 65 public Proxy getProxy() 66 { 67 return self ; 68 } 69 70 public StubInvocationHandlerImpl( PresentationManager pm, 71 PresentationManager.ClassData classData, org.omg.CORBA.Object stub ) 72 { 73 SecurityManager s = System.getSecurityManager(); 74 if (s != null) { 75 s.checkPermission(new DynamicAccessPermission("access")); 76 } 77 this.classData = classData ; 78 this.pm = pm ; 79 this.stub = stub ; 80 } 81 82 private boolean isLocal() 83 { 84 boolean result = false ; 85 Delegate delegate = StubAdapter.getDelegate( stub ) ; 86 87 if (delegate instanceof CorbaClientDelegate) { 88 CorbaClientDelegate cdel = (CorbaClientDelegate)delegate ; 89 ContactInfoList cil = cdel.getContactInfoList() ; 90 if (cil instanceof CorbaContactInfoList) { 91 CorbaContactInfoList ccil = (CorbaContactInfoList)cil ; 92 LocalClientRequestDispatcher lcrd = 93 ccil.getLocalClientRequestDispatcher() ; 94 result = lcrd.useLocalInvocation( null ) ; 95 } 96 } 97 98 return result ; 99 } 100 101 105 public Object invoke( Object proxy, final Method method, 106 Object [] args ) throws Throwable 107 { 108 String giopMethodName = classData.getIDLNameTranslator(). 109 getIDLName( method ) ; 110 DynamicMethodMarshaller dmm = 111 pm.getDynamicMethodMarshaller( method ) ; 112 113 Delegate delegate = null ; 114 try { 115 delegate = StubAdapter.getDelegate( stub ) ; 116 } catch (SystemException ex) { 117 throw Util.mapSystemException(ex) ; 118 } 119 120 if (!isLocal()) { 121 try { 122 org.omg.CORBA_2_3.portable.InputStream in = null ; 123 try { 124 org.omg.CORBA_2_3.portable.OutputStream out = 126 (org.omg.CORBA_2_3.portable.OutputStream ) 127 delegate.request( stub, giopMethodName, true); 128 129 dmm.writeArguments( out, args ) ; 131 132 in = (org.omg.CORBA_2_3.portable.InputStream ) 134 delegate.invoke( stub, out); 135 136 return dmm.readResult( in ) ; 138 } catch (ApplicationException ex) { 139 throw dmm.readException( ex ) ; 140 } catch (RemarshalException ex) { 141 return invoke( proxy, method, args ) ; 142 } finally { 143 delegate.releaseReply( stub, in ); 144 } 145 } catch (SystemException ex) { 146 throw Util.mapSystemException(ex) ; 147 } 148 } else { 149 ORB orb = (ORB)delegate.orb( stub ) ; 151 ServantObject so = delegate.servant_preinvoke( stub, giopMethodName, 152 method.getDeclaringClass() ); 153 if (so == null) { 154 return invoke( stub, method, args ) ; 155 } 156 try { 157 Object [] copies = dmm.copyArguments( args, orb ) ; 158 159 if (!method.isAccessible()) { 160 AccessController.doPrivileged(new PrivilegedAction () { 164 public Object run() { 165 method.setAccessible( true ) ; 166 return null ; 167 } 168 } ) ; 169 } 170 171 Object result = method.invoke( so.servant, copies ) ; 172 173 return dmm.copyResult( result, orb ) ; 174 } catch (InvocationTargetException ex) { 175 Throwable mex = ex.getCause() ; 176 Throwable exCopy = (Throwable )Util.copyObject(mex,orb); 178 if (dmm.isDeclaredException( exCopy )) 179 throw exCopy ; 180 else 181 throw Util.wrapException(exCopy); 182 } catch (Throwable thr) { 183 if (thr instanceof ThreadDeath ) 184 throw (ThreadDeath )thr ; 185 186 throw Util.wrapException( thr ) ; 190 } finally { 191 delegate.servant_postinvoke( stub, so); 192 } 193 } 194 } 195 } 196 | Popular Tags |