1 7 8 package com.sun.corba.se.impl.presentation.rmi ; 9 10 import java.lang.reflect.Field ; 11 12 import java.util.Hashtable ; 13 14 import javax.naming.*; 15 import javax.naming.spi.StateFactory ; 16 17 import java.security.AccessController ; 18 import java.security.PrivilegedAction ; 19 20 import javax.rmi.PortableRemoteObject ; 21 22 import com.sun.corba.se.spi.orb.ORB; 23 24 import java.rmi.Remote ; 25 import java.rmi.server.ExportException ; 26 27 import com.sun.jndi.cosnaming.CNCtx ; 30 31 import com.sun.corba.se.spi.presentation.rmi.StubAdapter ; 32 33 41 42 public class JNDIStateFactoryImpl implements StateFactory 43 { 44 private static final Field orbField ; 45 46 static { 47 orbField = (Field ) AccessController.doPrivileged( 48 new PrivilegedAction () { 49 public Object run() { 50 Field fld = null ; 51 try { 52 Class cls = CNCtx.class ; 53 fld = cls.getDeclaredField( "_orb" ) ; 54 fld.setAccessible( true ) ; 55 } catch (Exception exc) { 56 } 58 return fld ; 59 } 60 } 61 ) ; 62 } 63 64 public JNDIStateFactoryImpl() 65 { 66 } 67 68 84 public Object getStateToBind(Object orig, Name name, Context ctx, 85 Hashtable <?,?> env) throws NamingException 86 { 87 if (orig instanceof org.omg.CORBA.Object ) 88 return orig ; 89 90 if (!(orig instanceof Remote )) 91 return null ; 93 94 ORB orb = getORB( ctx ) ; 95 if (orb == null) 96 return null ; 99 100 Remote stub = null; 101 102 try { 103 stub = PortableRemoteObject.toStub( (Remote )orig ) ; 104 } catch (Exception exc) { 105 return null ; 110 } 111 112 if (StubAdapter.isStub( stub )) { 113 try { 114 StubAdapter.connect( stub, orb ) ; 115 } catch (Exception exc) { 116 if (!(exc instanceof java.rmi.RemoteException )) { 117 return null ; 121 } 122 123 } 126 } 127 128 return stub ; 129 } 130 131 private ORB getORB( Context ctx ) 138 { 139 ORB orb = null ; 140 141 try { 142 orb = (ORB)orbField.get( ctx ) ; 143 } catch (Exception exc) { 144 } 149 150 return orb ; 151 } 152 } 153 | Popular Tags |