1 7 8 package com.sun.corba.se.impl.presentation.rmi ; 9 10 import java.lang.reflect.InvocationHandler ; 11 import java.lang.reflect.Proxy ; 12 import java.lang.reflect.Method ; 13 14 import org.omg.CORBA.portable.ObjectImpl ; 15 16 import java.io.ObjectStreamException ; 17 import java.io.Serializable ; 18 19 import com.sun.corba.se.spi.presentation.rmi.IDLNameTranslator ; 20 import com.sun.corba.se.spi.presentation.rmi.PresentationManager ; 21 import com.sun.corba.se.spi.presentation.rmi.DynamicStub ; 22 23 import com.sun.corba.se.spi.orbutil.proxy.LinkedInvocationHandler ; 24 import com.sun.corba.se.spi.orbutil.proxy.InvocationHandlerFactory ; 25 import com.sun.corba.se.spi.orbutil.proxy.DelegateInvocationHandlerImpl ; 26 import com.sun.corba.se.spi.orbutil.proxy.CompositeInvocationHandler ; 27 import com.sun.corba.se.spi.orbutil.proxy.CompositeInvocationHandlerImpl ; 28 29 public class InvocationHandlerFactoryImpl implements InvocationHandlerFactory 30 { 31 private final PresentationManager.ClassData classData ; 32 private final PresentationManager pm ; 33 private Class [] proxyInterfaces ; 34 35 public InvocationHandlerFactoryImpl( PresentationManager pm, 36 PresentationManager.ClassData classData ) 37 { 38 this.classData = classData ; 39 this.pm = pm ; 40 41 Class [] remoteInterfaces = 42 classData.getIDLNameTranslator().getInterfaces() ; 43 proxyInterfaces = new Class [ remoteInterfaces.length + 1 ] ; 44 for (int ctr=0; ctr<remoteInterfaces.length; ctr++) 45 proxyInterfaces[ctr] = remoteInterfaces[ctr] ; 46 47 proxyInterfaces[remoteInterfaces.length] = DynamicStub.class ; 48 } 49 50 private class CustomCompositeInvocationHandlerImpl extends 51 CompositeInvocationHandlerImpl implements LinkedInvocationHandler, 52 Serializable 53 { 54 private transient DynamicStub stub ; 55 56 public void setProxy( Proxy proxy ) 57 { 58 ((DynamicStubImpl)stub).setSelf( (DynamicStub)proxy ) ; 59 } 60 61 public Proxy getProxy() 62 { 63 return (Proxy )((DynamicStubImpl)stub).getSelf() ; 64 } 65 66 public CustomCompositeInvocationHandlerImpl( DynamicStub stub ) 67 { 68 this.stub = stub ; 69 } 70 71 78 public Object writeReplace() throws ObjectStreamException 79 { 80 return stub ; 81 } 82 } 83 84 public InvocationHandler getInvocationHandler() 85 { 86 final DynamicStub stub = new DynamicStubImpl( 87 classData.getTypeIds() ) ; 88 89 return getInvocationHandler( stub ) ; 90 } 91 92 InvocationHandler getInvocationHandler( DynamicStub stub ) 94 { 95 InvocationHandler dynamicStubHandler = 100 DelegateInvocationHandlerImpl.create( stub ) ; 101 102 InvocationHandler stubMethodHandler = new StubInvocationHandlerImpl( 105 pm, classData, stub ) ; 106 107 final CompositeInvocationHandler handler = 110 new CustomCompositeInvocationHandlerImpl( stub ) ; 111 handler.addInvocationHandler( DynamicStub.class, 112 dynamicStubHandler ) ; 113 handler.addInvocationHandler( org.omg.CORBA.Object .class, 114 dynamicStubHandler ) ; 115 handler.addInvocationHandler( Object .class, 116 dynamicStubHandler ) ; 117 118 handler.setDefaultHandler( stubMethodHandler ) ; 132 133 return handler ; 134 } 135 136 public Class [] getProxyInterfaces() 137 { 138 return proxyInterfaces ; 139 } 140 } 141 | Popular Tags |