FileDocCategorySizeDatePackage
AdministeredObjectFactory.javaAPI DocGlassfish v2 API5099Fri May 04 22:35:08 BST 2007com.sun.enterprise.naming.factory

AdministeredObjectFactory

public class AdministeredObjectFactory extends Object implements ObjectFactory
An object factory to handle creation of administered object
author
Qingqing Ouyang

Fields Summary
private static Logger
logger
Constructors Summary
public AdministeredObjectFactory()


    //required by ObjectFactory
      
Methods Summary
public java.lang.ObjectgetObjectInstance(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable env)


	Reference ref = (Reference) obj;
	logger.fine("AdministeredObjectFactory: " + ref + 
		    " Name:" + name);	

        //String jndiName = (String) ref.get(0).getContent();
        AdministeredObjectResource aor = 
            (AdministeredObjectResource) ref.get(0).getContent();
        String jndiName = aor.getName();
        String moduleName = aor.getResourceAdapter();
	
	ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
    
        //If call fom application client, start resource adapter lazily.
        //todo: Similar code in ConnectorObjectFactory - to refactor.
        if(runtime.getEnviron() == ConnectorRuntime.CLIENT) {
            ConnectorDescriptor connectorDescriptor = null; 
            try {        
                Context ic = new InitialContext();              
                String descriptorJNDIName = ConnectorAdminServiceUtils.
                    getReservePrefixedJNDINameForDescriptor(moduleName);
                connectorDescriptor = (ConnectorDescriptor)ic.lookup(descriptorJNDIName); 
            } catch(NamingException ne) {
                logger.log(Level.FINE, "Failed to look up ConnectorDescriptor " +
                                            "from JNDI", moduleName); 
                throw new ConnectorRuntimeException("Failed to look up " +
                                                "ConnectorDescriptor from JNDI");
            }
            runtime.createActiveResourceAdapter(connectorDescriptor, moduleName,
                            null);
        }
    
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        if (runtime.checkAccessibility(moduleName, loader) == false) {
	    throw new NamingException("Only the application that has the embedded resource" + 
	                               "adapter can access the resource adapter");
	}

	logger.fine("[AdministeredObjectFactory] ==> Got AdministeredObjectResource = " + aor);    

	return aor.createAdministeredObject(null);