FileDocCategorySizeDatePackage
JNDIStateFactoryImpl.javaAPI DocJava SE 5 API4409Fri Aug 26 14:54:30 BST 2005com.sun.corba.se.impl.presentation.rmi

JNDIStateFactoryImpl

public class JNDIStateFactoryImpl extends Object implements StateFactory
StateFactory that turns java.rmi.Remote objects to org.omg.CORBA.Object. This version works either with standard RMI-IIOP or Dynamic RMI-IIOP. Based on the original com.sun.jndi.cosnaming.RemoteToCorba and com.sun.jndi.toolkit.corba.CorbaUtils.
author
Ken Cavanaugh

Fields Summary
private static final Field
orbField
Constructors Summary
public JNDIStateFactoryImpl()

	orbField = (Field) AccessController.doPrivileged( 
	    new PrivilegedAction() {
		public Object run() {
		    Field fld = null ;
		    try {
			Class cls = CNCtx.class ;
			fld = cls.getDeclaredField( "_orb" ) ;
			fld.setAccessible( true ) ;
		    } catch (Exception exc) {
			// XXX log exception at FINE
		    }
		    return fld ;
		}
	    } 
	) ;
    
    
Methods Summary
private com.sun.corba.se.spi.orb.ORBgetORB(javax.naming.Context ctx)

	ORB orb = null ;

	try {
	    orb = (ORB)orbField.get( ctx ) ;
	} catch (Exception exc) {
	    // XXX log this exception at FINE level
	    // ignore the exception and return null.
	    // Note that the exception may be because ctx
	    // is not a CosNaming context.
	}

	return orb ;
    
public java.lang.ObjectgetStateToBind(java.lang.Object orig, javax.naming.Name name, javax.naming.Context ctx, java.util.Hashtable env)
Returns the CORBA object for a Remote object. If input is not a Remote object, or if Remote object uses JRMP, return null. If the RMI-IIOP library is not available, throw ConfigurationException.

param
orig The object to turn into a CORBA object. If not Remote, or if is a JRMP stub or impl, return null.
param
name Ignored
param
ctx The non-null CNCtx whose ORB to use.
param
env Ignored
return
The CORBA object for orig or null.
exception
ConfigurationException If the CORBA object cannot be obtained due to configuration problems
exception
NamingException If some other problem prevented a CORBA object from being obtained from the Remote object.

	if (orig instanceof org.omg.CORBA.Object)
	    return orig ;

        if (!(orig instanceof Remote)) 
	    // Not for this StateFactory
	    return null ;

	ORB orb = getORB( ctx ) ; 
	if (orb == null)
	    // Wrong kind of context, so just give up and let another StateFactory
	    // try to satisfy getStateToBind.
	    return null ;

	Remote stub = null;

	try {
	    stub = PortableRemoteObject.toStub( (Remote)orig ) ;
	} catch (Exception exc) {
	    // XXX log at FINE level?
	    // Wrong sort of object: just return null to allow another StateFactory
	    // to handle this.  This can happen easily because this StateFactory
	    // is specified for the application, not the service context provider.
	    return null ;
	}

	if (StubAdapter.isStub( stub )) {
	    try {
		StubAdapter.connect( stub, orb ) ; 
	    } catch (Exception exc) {
		if (!(exc instanceof java.rmi.RemoteException)) {
		    // XXX log at FINE level?
		    // Wrong sort of object: just return null to allow another StateFactory
		    // to handle this call.
		    return null ;
		}

		// ignore RemoteException because stub might have already
		// been connected
	    }
	}

	return stub ;