FileDocCategorySizeDatePackage
ConnectorObjectFactory.javaAPI DocGlassfish v2 API5944Fri May 04 22:35:10 BST 2007com.sun.enterprise.naming.factory

ConnectorObjectFactory

public class ConnectorObjectFactory extends Object implements ObjectFactory
An object factory to handle creation of Connection Factories
author
Tony Ng

Fields Summary
static Logger
_logger
private static com.sun.enterprise.util.LocalStringManagerImpl
localStrings
private ConnectorRuntime
runtime
Constructors Summary
public ConnectorObjectFactory()


      
    
Methods Summary
private java.lang.StringderiveJndiName(java.lang.String name, java.util.Hashtable env)

        String suffix = (String) env.get(ConnectorConstants.JNDI_SUFFIX_PROPERTY);
        if (runtime.isValidJndiSuffix(suffix)) {
            _logger.log(Level.FINE, "JNDI name will be suffixed with :" + suffix);
            return name + suffix;
        }
        return name;
    
public java.lang.ObjectgetObjectInstance(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable env)

	Reference ref = (Reference) obj;
	if(_logger.isLoggable(Level.FINE)) {
	    _logger.log(Level.FINE,"ConnectorObjectFactory: " + ref +
			" Name:" + name);
	}
        String poolName = (String) ref.get(0).getContent();
        String moduleName  = (String) ref.get(1).getContent();

        Switch sw = Switch.getSwitch();

        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");
	}
	

        ManagedConnectionFactory mcf = runtime.obtainManagedConnectionFactory(poolName);
        if(mcf == null) {
                _logger.log(Level.FINE,"Failed to create MCF ",poolName);
                throw new ConnectorRuntimeException("Failed to create MCF");
        }

        String jndiName = name.toString();
        boolean forceNoLazyAssoc = false;
        if ( jndiName.endsWith( ConnectorConstants.PM_JNDI_SUFFIX ) ) {
            forceNoLazyAssoc = true;
        }
        ConnectionManagerImpl mgr = (ConnectionManagerImpl) 
            runtime.obtainConnectionManager(poolName, forceNoLazyAssoc);
        mgr.setJndiName(deriveJndiName(jndiName, env));
        mgr.setRarName( moduleName );
        mgr.initialize();

        Object cf = mcf.createConnectionFactory(mgr);
        if (cf == null) {
            String msg = localStrings.getLocalString
                ("no.resource.adapter", "");
            throw new ConfigurationException(msg);
        }
	if(_logger.isLoggable(Level.FINE)) {
	    _logger.log(Level.FINE,"Connection Factory:" + cf);
	}

	return cf;