Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 1997-2012 Oracle and/or its affiliates. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  *
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  *
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  *
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
 
 package com.sun.enterprise.resource.naming;
 
 
 import javax.naming.*;
 import  javax.resource.spi.ManagedConnectionFactory;
 import java.util.Map;
An object factory to handle creation of Connection Factories

Author(s):
Tony Ng
 
 public class ConnectorObjectFactory implements ObjectFactory {
 
     private ConnectorRuntime runtime ;
 
     private static Logger _logger = LogDomains.getLogger(ConnectorObjectFactory.class.);
     protected final static StringManager localStrings =
             StringManager.getManager(ConnectorRuntime.class);
 
     public ConnectorObjectFactory() {
     }
     
     public Object getObjectInstance(Object objName nameContext nameCtxHashtable envthrows Exception {
 
         Reference ref = (Referenceobj;
         if(.isLoggable(.)) {
             .log(.,"ConnectorObjectFactory: " + ref +
                 " Name:" + name);
         }
             PoolInfo poolInfo = (PoolInforef.get(0).getContent();
             String moduleName  = (Stringref.get(1).getContent();
             ResourceInfo resourceInfo = (ResourceInforef.get(2).getContent();
 
 
         if (getRuntime().isACCRuntime() || getRuntime().isNonACCRuntime()) {
            ConnectorDescriptor connectorDescriptor = null;
            String descriptorJNDIName = ConnectorAdminServiceUtils.
                    getReservePrefixedJNDINameForDescriptor(moduleName);
            Context ic = new InitialContext(env);
            connectorDescriptor = (ConnectorDescriptoric.lookup(descriptorJNDIName);
            try {
                getRuntime().createActiveResourceAdapter(connectorDescriptormoduleNamenull);
            } catch (ConnectorRuntimeException e) {
                if(.isLoggable(.)) {
                    .log(.,
                            "Failed to look up ConnectorDescriptor from JNDI",
                            moduleName);
                }
                NamingException ne = new NamingException("Failed to look up ConnectorDescriptor from JNDI");
                ne.setRootCause(e);
                throw ne;
            }
        }
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        if (!getRuntime().checkAccessibility(moduleNameloader)) {
            String msg = .getString("cof.no_access_to_embedded_rar"moduleName);
            throw new NamingException(msg);
        }
        Object cf = null;
        try {
            ManagedConnectionFactory mcf = getRuntime().obtainManagedConnectionFactory(poolInfoenv);
            if (mcf == null) {
                if(.isLoggable(.)) {
                    .log(."Failed to create MCF "poolInfo);
                }
                throw new ConnectorRuntimeException("Failed to create MCF");
            }
            boolean forceNoLazyAssoc = false;
            String jndiName = name.toString();
            if (jndiName.endsWith(.)) {
                forceNoLazyAssoc = true;
            }
            String derivedJndiName = ConnectorsUtil.deriveJndiName(jndiNameenv);
            ConnectionManagerImpl mgr = (ConnectionManagerImpl)
                    getRuntime().obtainConnectionManager(poolInfoforceNoLazyAssocresourceInfo);
            mgr.setJndiName(derivedJndiName);
            mgr.setRarName(moduleName);
            String logicalName = (String)env.get(.);
            if(logicalName != null){
                mgr.setLogicalName(logicalName);
            }
            
            mgr.initialize();
            cf = mcf.createConnectionFactory(mgr);
            if (cf == null) {
                String msg = .getString("cof.no.resource.adapter");
                throw new RuntimeException(new ConfigurationException(msg));
            }
            if (getRuntime().isServer() || getRuntime().isEmbedded()) {
                ConnectorRegistry registry = ConnectorRegistry.getInstance();
                if (registry.isTransparentDynamicReconfigPool(poolInfo)) {
                    Resources resources = getRuntime().getResources(poolInfo);
                    ResourcePool resourcePool = null;
                    if (resources != null) {
                        resourcePool = (ResourcePool) ConnectorsUtil.getResourceByName(resourcesResourcePool.classpoolInfo.getName());
                        if (resourcePool != null) {
                            ResourceDeployer deployer = getRuntime().getResourceDeployer(resourcePool);
                            if (deployer != null && deployer.supportsDynamicReconfiguration() &&
                                    ConnectorsUtil.isDynamicReconfigurationEnabled(resourcePool)) {
                                Object o = env.get(.);
                                if (o == null || Boolean.valueOf(o.toString()).equals(false)) {
                                    //TODO use list ? (even in the ResourceDeployer API)
                                    Class[] classes = deployer.getProxyClassesForDynamicReconfiguration();
                                    Class[] proxyClasses = new Class[classes.length + 1];
                                    for (int i = 0; i < classes.lengthi++) {
                                        proxyClasses[i] = classes[i];
                                    }
                                    proxyClasses[proxyClasses.length - 1] = DynamicallyReconfigurableResource.class;
                                    cf = getProxyObject(cfproxyClassesresourceInfo);
                                    Map<DynamicallyReconfigurableResourceBooleanresourceFactories =
                                            ConnectorRegistry.getInstance().getResourceFactories(resourceInfo);
                                    resourceFactories.put((DynamicallyReconfigurableResource) Proxy.getInvocationHandler(cf), true);
                                }
                            }
                        }
                    }
                }
            }
            if (.isLoggable(.)) {
                .log(."Connection Factory:" + cf);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return cf;
    }
      protected <T> T getProxyObject(final Object actualObjectClass<T>[] ifacesResourceInfo resourceInfothrows Exception {
        InvocationHandler ih = new DynamicResourceReconfigurator(actualObjectresourceInfo);
        return (T) Proxy.newProxyInstance(actualObject.getClass().getClassLoader(), ifacesih);
    }
    private ConnectorRuntime getRuntime() {
        if ( == null) {
             = ConnectorNamingUtils.getRuntime();
        }
        return ;
    }
New to GrepCode? Check out our FAQ X