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.connectors.service;
 
 
 import java.io.File;
 import java.net.URI;
This is the base class for all the connector services. It defines the enviroment of execution (client or server), and holds the reference to connector runtime for inter service method invocations.

Author(s):
Srikanth P
 
 public class ConnectorService implements ConnectorConstants {
     protected static final Logger _logger = LogDomains.getLogger(ConnectorService.class.);
 
     protected static final ConnectorRegistry _registry =
             ConnectorRegistry.getInstance();
 
     protected ConnectorRuntime _runtime;
     private ResourcesUtil resourcesUtil;

    
Default Constructor
 
     public ConnectorService() {
          = ConnectorRuntime.getRuntime();
     }
 
     public ResourcesUtil getResourcesUtil(){
         if( == null){
              = ResourcesUtil.createInstance();
         }
         return ;
     }

    
Returns the generated default connection poolName for a connection definition.

Parameters:
moduleName rar module name
connectionDefName connection definition name
Returns:
generated connection poolname
    // TODO V3 can the default pool name generation be fully done by connector-admin-service-utils ?
    public String getDefaultPoolName(String moduleName,
                                     String connectionDefName) {
        return moduleName +  + connectionDefName;
    }

    
Returns the generated default connector resource for a connection definition.

Parameters:
moduleName resource-adapter name
connectionDefName connection definition name
Returns:
generated default connector resource name
    // TODO V3 can the default resource name generation be fully done by connector-admin-service-utils ?
    public String getDefaultResourceName(String moduleName,
                                         String connectionDefName) {
        //Construct the default resource name as
        // <JNDIName_of_RA>#<connectionDefnName>
        String resourceJNDIName = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForResource(moduleName);
        return resourceJNDIName +  + connectionDefName;
    }
/*    public boolean checkAndLoadResource(Object resource, Object pool, String resourceType, String resourceName,
                                        String raName)
            throws ConnectorRuntimeException {
        String resname = ConnectorAdminServiceUtils.getOriginalResourceName(resourceName);
        if(_logger.isLoggable(Level.FINE)) {
            _logger.fine("ConnectorService :: checkAndLoadResource resolved to load " + resname);
        }
        DeferredResourceConfig defResConfig = getResourcesUtil().getDeferredResourceConfig(resource, pool, resourceType, raName);
        //DeferredResourceConfig defResConfig = resUtil.getDeferredResourceConfig(resname);
        return loadResourcesAndItsRar(defResConfig);
    }
*/
    public boolean loadResourcesAndItsRar(DeferredResourceConfig defResConfig) {
        if (defResConfig != null) {
            try {
                loadDeferredResources(defResConfig.getResourceAdapterConfig());
                final String rarName = defResConfig.getRarName();
                loadDeferredResourceAdapter(rarName);
                final Resource[] resToLoad = defResConfig.getResourcesToLoad();
                AccessController.doPrivileged(new PrivilegedAction() {
                    public Object run() {
                        try {
                            loadDeferredResources(resToLoad);
                        } catch (Exception ex) {
                            Object params[] = new Object[]{rarNameex};
                            .log(."failed.to.load.deferred.resources"params);
                        }
                        return null;
                    }
                });
            } catch (Exception ex) {
                Object params[] = new Object[]{defResConfig.getRarName(), ex};
                .log(."failed.to.load.deferred.ra"params);
                return false;
            }
            return true;
        }
        return false;
    }
    public void loadDeferredResourceAdapter(String rarModuleName)
            throws ConnectorRuntimeException {
        //load the RA if its not already loaded
        if (.getActiveResourceAdapter(rarModuleName) == null) {
            try {
                //Do this only for System RA
                if (ConnectorsUtil.belongsToSystemRA(rarModuleName)) {
                    String systemModuleLocation = ConnectorsUtil.getSystemModuleLocation(rarModuleName);
                    if(.isServer()){
                        .getMonitoringBootstrap().registerProbes(rarModuleName,
                                new File(systemModuleLocation), .getSystemRARClassLoader(rarModuleName));
                    }
                    .createActiveResourceAdapter(systemModuleLocationrarModuleNamenull);
                } /* not needed as long as standalone + embedded rars are loaded before recovery
                else if (rarModuleName.indexOf(ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER) != -1) {
                    createActiveResourceAdapterForEmbeddedRar(rarModuleName);
                } else{
                    _runtime.createActiveResourceAdapter(ConnectorsUtil.getLocation(rarModuleName), rarModuleName, null);
                }*/
            } catch (Exception e) {
                ConnectorRuntimeException ce =
                        new ConnectorRuntimeException(e.getMessage());
                ce.initCause(e);
                throw ce;
            }
        }
    }
    public void createActiveResourceAdapterForEmbeddedRar(String rarModuleNamethrows ConnectorRuntimeException {
        ConnectorDescriptor cdesc = loadConnectorDescriptorForEmbeddedRAR(rarModuleName);
        String appName = ConnectorAdminServiceUtils.getApplicationName(rarModuleName);
        String rarFileName = ConnectorAdminServiceUtils
                        .getConnectorModuleName(rarModuleName) + ".rar";
        String loc = getResourcesUtil().getApplicationDeployLocation(appName);
        loc = loc + . + FileUtils.makeFriendlyFilename(rarFileName);
        String path = null;
        try {
            URI uri = new URI(loc);
            path = uri.getPath();
        } catch (URISyntaxException use) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException("Invalid path [ "+use.getMessage()+" ]");
            cre.setStackTrace(use.getStackTrace());
            .log(.cre.getMessage(), cre);
            throw cre;
        }
        // start RA
        .createActiveResourceAdapter(cdescrarModuleNamepath);
    }
    public void loadDeferredResources(Resource[] resourcesToLoad)
            throws Exception {
        if (resourcesToLoad == null || resourcesToLoad.length == 0) {
            return;
        }
        for (Resource resource : resourcesToLoad) {
            if (resource == null) {
                continue;
            } else if (getResourcesUtil().isEnabled(resource)) {
                try {
                    .getResourceDeployer(resource).deployResource(resource);
                } catch (Exception e) {
                    ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
                    cre.initCause(e);
                    throw cre;
                }
            }
        }
    }

    
Obtains the connector Descriptor pertaining to rar. If ConnectorDescriptor is present in registry, it is obtained from registry and returned. Else it is explicitly read from directory where rar is exploded.

Parameters:
rarName Name of the rar
Returns:
ConnectorDescriptor pertaining to rar.
Throws:
com.sun.appserv.connectors.internal.api.ConnectorRuntimeException when unable to get descriptor
            throws ConnectorRuntimeException {
        if (rarName == null) {
            return null;
        }
        ConnectorDescriptor desc = null;
        desc = .getDescriptor(rarName);
        if (desc != null) {
            return desc;
        }
        String moduleDir;
        //If the RAR is embedded try loading the descriptor directly
        //using the applicationarchivist
        if (rarName.indexOf(.) != -1){
            try {
                desc = loadConnectorDescriptorForEmbeddedRAR(rarName);
                if (desc != nullreturn desc;
            } catch (ConnectorRuntimeException e) {
                throw e;
            }
        }
        if (ConnectorsUtil.belongsToSystemRA(rarName)) {
            moduleDir = ConnectorsUtil.getSystemModuleLocation(rarName);
        } else {
            moduleDir = ConnectorsUtil.getLocation(rarName);
        }
        if (moduleDir != null) {
            desc = ConnectorDDTransformUtils.getConnectorDescriptor(moduleDirrarName);
        } else {
            .log(.,
                    "rardeployment.no_module_deployed"rarName);
        }
        return desc;
    }


    
Matching will be switched off in the pool, by default. This will be switched on if the connections with different resource principals reach the pool.

Parameters:
poolInfo Name of the pool to switchOn matching.
rarName Name of the resource adater.
    public void switchOnMatching(String rarNamePoolInfo poolInfo) {
        // At present it is applicable to only JDBC resource adapters
        // Later other resource adapters also become applicable.
                || rarName.equals(.) ||
                rarName.equals(.)) {
            PoolManager poolMgr = .getPoolManager();
            boolean result = poolMgr.switchOnMatching(poolInfo);
            if (!result) {
                try {
                    .switchOnMatchingInJndi(poolInfo);
                } catch (ConnectorRuntimeException cre) {
                    // This will never happen.
                }
            }
        }
    }
    public boolean checkAndLoadPool(PoolInfo poolInfo) {
        boolean status = false;
        try {
            ResourcePool pool = .getConnectionPoolConfig(poolInfo);
            //DeferredResourceConfig defResConfig = resutil.getDeferredPoolConfig(poolName);
            DeferredResourceConfig defResConfig =
                    getResourcesUtil().getDeferredResourceConfig(nullpoolnullnull);
            status = loadResourcesAndItsRar(defResConfig);
        } catch (ConnectorRuntimeException cre) {
            Object params[] = new Object[]{poolInfocre};
            .log(."unable.to.load.connection.pool"params);
        }
        return status;
    }
/*
    public boolean checkAndLoadJdbcPool(String poolName) {
        boolean status = false;
        try {
            ResourcesUtil resutil = ResourcesUtil.createInstance();
            JdbcConnectionPool pool = _runtime.getJdbcConnectionPoolConfig(poolName);
            DeferredResourceConfig defResConfig =
                    resutil.getDeferredResourceConfig(null, pool, ConnectorConstants.RES_TYPE_JDBC, null);
            status = loadResourcesAndItsRar(defResConfig);
        } catch (ConnectorRuntimeException cre) {
            _logger.log(Level.WARNING, "unable to load Jdbc Connection Pool [ " + poolName + " ]", cre);
        }
        return status;
    }
*/
    public void ifSystemRarLoad(String rarName)
                           throws ConnectorRuntimeException {
        if(ConnectorsUtil.belongsToSystemRA(rarName)){
            loadDeferredResourceAdapter(rarName);
        }
    }
    //TODO V3 with annotations, is it right a approach to load the descriptor using Archivist ?
        //If the RAR is embedded try loading the descriptor directly
        //using the applicationarchivist
        ResourcesUtil resutil = ResourcesUtil.createInstance();
        String rarFileName = ConnectorAdminServiceUtils.getConnectorModuleName(rarName) + ".rar";
        return resutil.getConnectorDescriptorFromUri(rarNamerarFileName);
    }

    
Check whether ClassLoader is permitted to access this resource adapter. If the RAR is deployed and is not a standalone RAR, then only the ClassLoader that loaded the archive (any of its child) should be able to access it. Otherwise everybody can access the RAR.

Parameters:
rarName Resource adapter module name.
loader ClassLoader to verify.
    public boolean checkAccessibility(String rarNameClassLoader loader) {
        if (ar != null && loader != null) { // If RA is deployed
            ClassLoader rarLoader = ar.getClassLoader();
            //If the RAR is not standalone.
            if (rarLoader != null && ConnectorAdminServiceUtils.isEmbeddedConnectorModule(rarName)
                /*&& (!(rarLoader instanceof ConnectorClassFinder))*/) {
                ClassLoader rarLoaderParent = rarLoader.getParent();
                ClassLoader parent = loader;
                while (true) {
                    if (parent.equals(rarLoaderParent)) {
                        return true;
                    }
                    final ClassLoader temp = parent;
                    Object obj = AccessController.doPrivileged(new PrivilegedAction() {
                        public Object run() {
                            return temp.getParent();
                        }
                    });
                    if (obj == null) {
                        break;
                    } else {
                        parent = (ClassLoaderobj;
                    }
                }
                // If no parent matches return false;
                return false;
            }
        }
        return true;
    }
New to GrepCode? Check out our FAQ X