1 7 8 package com.sun.corba.se.impl.presentation.rmi ; 9 10 import java.rmi.Remote ; 11 import java.rmi.RemoteException ; 12 13 import javax.rmi.CORBA.Tie ; 14 15 import java.lang.reflect.Method ; 16 import java.lang.reflect.InvocationTargetException ; 17 18 import org.omg.CORBA.SystemException ; 19 import org.omg.CORBA_2_3.portable.InputStream ; 20 import org.omg.CORBA_2_3.portable.OutputStream ; 21 import org.omg.CORBA.portable.ResponseHandler ; 22 import org.omg.CORBA.portable.UnknownException ; 23 import org.omg.PortableServer.Servant ; 24 import org.omg.PortableServer.POA ; 25 import org.omg.PortableServer.POAManager ; 26 27 import com.sun.corba.se.spi.presentation.rmi.PresentationManager ; 28 import com.sun.corba.se.spi.presentation.rmi.IDLNameTranslator ; 29 import com.sun.corba.se.spi.presentation.rmi.DynamicMethodMarshaller ; 30 31 import com.sun.corba.se.spi.orb.ORB ; 32 33 import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 34 35 import com.sun.corba.se.impl.oa.poa.POAManagerImpl ; 36 37 public final class ReflectiveTie extends Servant implements Tie 38 { 39 private Remote target = null ; 40 private PresentationManager pm ; 41 private PresentationManager.ClassData classData = null ; 42 private ORBUtilSystemException wrapper = null ; 43 44 public ReflectiveTie( PresentationManager pm, ORBUtilSystemException wrapper ) 45 { 46 SecurityManager s = System.getSecurityManager(); 47 if (s != null) { 48 s.checkPermission(new DynamicAccessPermission("access")); 49 } 50 this.pm = pm ; 51 this.wrapper = wrapper ; 52 } 53 54 public String [] _all_interfaces(org.omg.PortableServer.POA poa, 55 byte[] objectId) 56 { 57 return classData.getTypeIds() ; 58 } 59 60 public void setTarget(Remote target) 61 { 62 this.target = target; 63 64 if (target == null) { 65 classData = null ; 66 } else { 67 Class targetClass = target.getClass() ; 68 classData = pm.getClassData( targetClass ) ; 69 } 70 } 71 72 public Remote getTarget() 73 { 74 return target; 75 } 76 77 public org.omg.CORBA.Object thisObject() 78 { 79 return _this_object(); 80 } 81 82 public void deactivate() 83 { 84 try{ 85 _poa().deactivate_object(_poa().servant_to_id(this)); 86 } catch (org.omg.PortableServer.POAPackage.WrongPolicy exception){ 87 } catch (org.omg.PortableServer.POAPackage.ObjectNotActive exception){ 89 } catch (org.omg.PortableServer.POAPackage.ServantNotActive exception){ 91 } 93 } 94 95 public org.omg.CORBA.ORB orb() { 96 return _orb(); 97 } 98 99 public void orb(org.omg.CORBA.ORB orb) { 100 try { 101 ORB myORB = (ORB)orb ; 102 103 ((org.omg.CORBA_2_3.ORB )orb).set_delegate(this); 104 } catch (ClassCastException e) { 105 throw wrapper.badOrbForServant( e ) ; 106 } 107 } 108 109 public org.omg.CORBA.portable.OutputStream _invoke(String method, 110 org.omg.CORBA.portable.InputStream _in, ResponseHandler reply) 111 { 112 Method javaMethod = null ; 113 DynamicMethodMarshaller dmm = null; 114 115 try { 116 InputStream in = (InputStream ) _in; 117 118 javaMethod = classData.getIDLNameTranslator().getMethod( method ) ; 119 if (javaMethod == null) 120 throw wrapper.methodNotFoundInTie( method, 121 target.getClass().getName() ) ; 122 123 dmm = pm.getDynamicMethodMarshaller( javaMethod ) ; 124 125 Object [] args = dmm.readArguments( in ) ; 126 127 Object result = javaMethod.invoke( target, args ) ; 128 129 OutputStream os = (OutputStream )reply.createReply() ; 130 131 dmm.writeResult( os, result ) ; 132 133 return os ; 134 } catch (IllegalAccessException ex) { 135 throw wrapper.invocationErrorInReflectiveTie( ex, 136 javaMethod.getName(), 137 javaMethod.getDeclaringClass().getName() ) ; 138 } catch (IllegalArgumentException ex) { 139 throw wrapper.invocationErrorInReflectiveTie( ex, 140 javaMethod.getName(), 141 javaMethod.getDeclaringClass().getName() ) ; 142 } catch (InvocationTargetException ex) { 143 Throwable thr = ex.getCause() ; 147 if (thr instanceof SystemException ) 148 throw (SystemException )thr ; 149 else if ((thr instanceof Exception ) && 150 dmm.isDeclaredException( thr )) { 151 OutputStream os = (OutputStream )reply.createExceptionReply() ; 152 dmm.writeException( os, (Exception )thr ) ; 153 return os ; 154 } else 155 throw new UnknownException ( thr ) ; 156 } 157 } 158 } 159 | Popular Tags |