1 23 24 package com.sun.enterprise.iiop; 25 26 import java.io.*; 27 28 import javax.ejb.*; 29 import javax.ejb.spi.HandleDelegate ; 30 import javax.naming.*; 31 32 import javax.rmi.PortableRemoteObject ; 33 import javax.rmi.CORBA.Stub ; 34 35 import com.sun.enterprise.util.ORBManager; 36 import org.omg.CORBA.portable.Delegate ; 37 import com.sun.corba.ee.spi.presentation.rmi.DynamicStub; 38 import com.sun.corba.ee.spi.presentation.rmi.StubAdapter; 39 40 44 45 public final class IIOPHandleDelegate 46 implements HandleDelegate 47 { 48 49 public static HandleDelegate getHandleDelegate() { 50 HandleDelegate handleDelegate = 51 (HandleDelegate ) java.security.AccessController.doPrivileged( 52 new java.security.PrivilegedAction () { 53 public Object run() { 54 try { 55 ClassLoader cl = new HandleDelegateClassLoader(); 56 Class c = cl.loadClass( 57 "com.sun.enterprise.iiop.IIOPHandleDelegate"); 58 return c.newInstance(); 59 } catch ( Exception ex ) { 60 ex.printStackTrace(); 61 return null; 62 } 63 } 64 } 65 ); 66 return handleDelegate; 67 } 68 69 70 public void writeEJBObject(javax.ejb.EJBObject ejbObject, 71 java.io.ObjectOutputStream ostream) 72 throws java.io.IOException 73 { 74 ostream.writeObject(ejbObject); } 76 77 public javax.ejb.EJBObject readEJBObject(java.io.ObjectInputStream istream) 78 throws java.io.IOException , ClassNotFoundException 79 { 80 return (EJBObject)getStub(istream, EJBObject.class); 81 } 82 83 public void writeEJBHome(javax.ejb.EJBHome ejbHome, 84 java.io.ObjectOutputStream ostream) 85 throws java.io.IOException 86 { 87 ostream.writeObject(ejbHome); } 89 90 public javax.ejb.EJBHome readEJBHome(java.io.ObjectInputStream istream) 91 throws java.io.IOException , ClassNotFoundException 92 { 93 return (EJBHome)getStub(istream, EJBHome.class); 94 } 95 96 private Object getStub(java.io.ObjectInputStream istream, Class stubClass) 97 throws IOException, ClassNotFoundException 98 { 99 Object obj = istream.readObject(); 101 102 if( StubAdapter.isStub(obj) ) { 103 104 try { 105 106 Delegate delegate = StubAdapter.getDelegate(obj); 111 112 } catch(org.omg.CORBA.BAD_OPERATION bo) { 113 114 115 StubAdapter.connect 118 (obj, (com.sun.corba.ee.spi.orb.ORB) ORBManager.getORB()); 119 } 120 121 } else { 122 throw new IOException("Unable to create stub for class " + 123 stubClass.getName() + 124 ", object deserialized is not a CORBA object, it's type is " + 125 obj.getClass().getName()); 126 } 127 128 Object stub = PortableRemoteObject.narrow(obj, stubClass); 130 131 return stub; 132 } 133 134 } 135 | Popular Tags |