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;
 
 
 import  javax.resource.ResourceException;
 import  javax.resource.spi.*;
 import java.util.*;
This class represents a live outbound resource adapter (1.5 compliant) i.e.

A resource adapter is considered active after start() and before stop() is called.

Author(s):
Binod P G, Sivakumar Thyagarajan
 
 
     @Inject
 
     protected ResourceAdapter resourceadapter_//runtime instance
 
     protected static final Logger _logger = LogDomains.getLogger(ActiveOutboundResourceAdapter.class.);
 
     private StringManager localStrings =
             StringManager.getManager(ActiveOutboundResourceAdapter.class);
 
     protected BootstrapContext bootStrapContextImpl;
 
     public ActiveOutboundResourceAdapter() {
     }

    
Creates an active inbound resource adapter. Sets all RA java bean properties and issues a start.

Parameters:
ra ResourceAdapter java bean.
desc ConnectorDescriptor object.
moduleName Resource adapter module name.
jcl ClassLoader instance.
Throws:
ConnectorRuntimeException If there is a failure in loading or starting the resource adapter.
    public void init(
            ResourceAdapter raConnectorDescriptor descString moduleName,
            ClassLoader jclthrows ConnectorRuntimeException {
        super.init(radescmoduleNamejcl);
        this. = ra;
        if ( != null) {
            try {
                loadRAConfiguration();
                // now the RA bean would have been fully configured (taking into account, resource-adapter-config),
                // validate the RA bean now.
                .validateJavaBean(ramoduleName);
                ConnectorRegistry registry = ConnectorRegistry.getInstance();
                String poolId = null;
                ResourceAdapterConfig raConfig = registry.getResourceAdapterConfig();
                if (raConfig != null) {
                    poolId = raConfig.getThreadPoolIds();
                }
                this. = new BootstrapContextImpl(poolIdjcl);
                validateWorkContextSupport(desc);
                startResourceAdapter();
            } catch (ResourceAdapterInternalException ex) {
                .log(."rardeployment.start_failed"ex);
                String i18nMsg = .getString("rardeployment.start_failed"ex.getMessage());
                ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
                cre.initCause(ex);
                throw cre;
            } catch (Throwable t) {
                .log(."rardeployment.start_failed"t);
                String i18nMsg = .getString("rardeployment.start_failed"t.getMessage());
                ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
                if (t.getCause() != null) {
                    cre.initCause(t.getCause());
                } else {
                    cre.initCause(t);
                }
                throw cre;
            }
        }
    }

    
check whether the required-work-context list mandated by the resource-adapter is supported by the application server

Parameters:
desc ConnectorDescriptor
Throws:
ConnectorRuntimeException when unable to support any of the requested work-context type.
        Set workContexts = desc.getRequiredWorkContexts();
        Iterator workContextsIterator = workContexts.iterator();
        WorkContextHandler workContextHandler = .getWorkContextHandler();
        workContextHandler.init();
        while(workContextsIterator.hasNext()){
            String ic = (String)workContextsIterator.next();
            boolean supported = workContextHandler.isContextSupported(trueic );
            if(!supported){
                String errorMsg = "Unsupported work context [ "ic + " ] ";
                Object params[] = new Object[]{icdesc.getName()};
                .log(.,"unsupported.work.context"params);
                throw new ConnectorRuntimeException(errorMsg);
            }
        }
    }


    
called by connector runtime to start the resource-adapter java bean

Parameters:
bootstrapContext BootstrapContext
Throws:
ResourceAdapterInternalException
    protected void startResourceAdapter(BootstrapContext bootstrapContextthrows ResourceAdapterInternalException {
        .start(bootstrapContext);
    }

    
    public boolean handles(ConnectorDescriptor cdString moduleName) {
        boolean adminObjectsDefined = false;
        Set adminObjects = cd.getAdminObjects();
        if (adminObjects != null && adminObjects.size() > 0) {
            adminObjectsDefined = true;
        }
        /*
        this class can handle Connector 1.5 Spec. compliant RAR that has no inbound artifacts
        criteria for 1.5 RAR :
          * No inbound artifacts
          * Any one of the following conditions hold true :
          *     -> admin object is defined or
          *     -> resource-adapter-class is defined or
          *     -> more than one connection-definition is defined.
        */
        boolean canHandle = false;
        if(!cd.getInBoundDefined()){
            if(cd.getOutBoundDefined() && cd.getOutboundResourceAdapter().getConnectionDefs().size() > 1){
                canHandle = true;
            }else if (adminObjectsDefined){
                canHandle = true;
            }else if(!cd.getResourceAdapterClass().equals("")){
                canHandle = true;
            }
        }
        return canHandle;
    }


    
Retrieves the resource adapter java bean.

Returns:
ResourceAdapter
    public ResourceAdapter getResourceAdapter() {
        return this.;
    }

    
Does the necessary initial setup. Creates the default pool and resource.

Throws:
ConnectorRuntimeException If there is a failure
    public void setup() throws ConnectorRuntimeException {
        if ( == null || . == 0) {
            return;
        }
        if (isServer() && !isSystemRar()) {
            createAllConnectorResources();
        }
        if(.isLoggable(.)) {
            .log(."Completed Active Resource adapter setup");
        }
    }

    
Destroys default pools and resources. Stops the Resource adapter java bean.
    public void destroy() {
        //it is possible that a 1.5 ra may not have connection-definition at all
        if (( != null) && (. != 0)) {
            super.destroy();
        }
        stopResourceAdapter();
    }
    private void stopResourceAdapter() {
        if ( != null) {
            try {
                if(.isLoggable(.)) {
                    .fine("Calling Resource Adapter stop" + this.getModuleName());
                }
                .stop();
                if(.isLoggable(.)){
                    .fine("Resource Adapter stop call of " + this.getModuleName() + " returned successfully");
                    .fine("rar_stop_call_successful");
                }
            } catch (Throwable t) {
                .log(."rardeployment.stop_warning"t);
            } finally {
                //not needed when there is no ResourceAdapter instance (implementation)
                removeProxiesFromRegistry();
            }
        }
    }


    
Remove all the proxy objects (Work-Manager) from connector registry

Parameters:
moduleName_ resource-adapter name
    private void removeProxiesFromRegistry(String moduleName_) {
        ConnectorRuntime.getRuntime().removeWorkManagerProxy(moduleName_);
    }


    
Creates an instance of ManagedConnectionFactory object using the connection pool properties. Also set the ResourceAdapterAssociation

Parameters:
pool ConnectorConnectionPool properties.
jcl ClassLoader
    public ManagedConnectionFactory createManagedConnectionFactory(
            ConnectorConnectionPool poolClassLoader jcl) {
        ManagedConnectionFactory mcf;
        mcf = super.createManagedConnectionFactory(pooljcl);
        if (mcf instanceof ResourceAdapterAssociation) {
            try {
                ((ResourceAdapterAssociation) mcf).setResourceAdapter(this.);
            } catch (ResourceException ex) {
                .log(."rardeployment.assoc_failed"ex);
            }
        }
        return mcf;
    }

    
Loads RA javabean. This method is protected, so that any system resource adapter can have specific configuration done during the loading.

Throws:
ConnectorRuntimeException if there is a failure.
    protected void loadRAConfiguration() throws ConnectorRuntimeException {
        try {
            Set mergedProps;
            ConnectorRegistry registry = ConnectorRegistry.getInstance();
            ResourceAdapterConfig raConfig = registry.getResourceAdapterConfig();
            List<PropertyraConfigProps = new ArrayList<Property>();
            mergedProps = mergeRAConfiguration(raConfigraConfigProps);
            logMergedProperties(mergedProps);
            SetMethodAction setMethodAction = new SetMethodAction(this.mergedProps);
            setMethodAction.run();
        } catch (Exception e) {
            String i18nMsg = .getString("ccp_adm.wrong_params_for_create"e.getMessage());
            ConnectorRuntimeException cre = new ConnectorRuntimeException(i18nMsg);
            cre.initCause(e);
            throw cre;
        }
    }

    
merge RA bean configuration with resource-adapter-config properties Union of both. resource-adapter-config properties will override the values of resource-adapter bean's config

Parameters:
raConfig resource-adapter-config
raConfigProps resource-adapter bean configuration
Returns:
merged set of config properties
    protected Set mergeRAConfiguration(ResourceAdapterConfig raConfigList<PropertyraConfigProps) {
        Set mergedProps;
        if (raConfig != null) {
            raConfigProps = raConfig.getProperty();
        }
        mergedProps = ConnectorDDTransformUtils.mergeProps(raConfigPropsgetDescriptor().getConfigProperties());
        return mergedProps;
    }
    private void logMergedProperties(Set mergedProps) {
        if (.isLoggable(.)) {
            .fine("Passing in the following properties " +
                    "before calling RA.start of " + this.);
            StringBuffer b = new StringBuffer();
            for (Iterator iter = mergedProps.iterator(); iter.hasNext();) {
                ConnectorConfigProperty element = (ConnectorConfigProperty ) iter.next();
                b.append("\nName: " + element.getName()
                        + " Value: " + element.getValue());
            }
            .fine(b.toString());
        }
    }
    public BootstrapContext getBootStrapContext() {
        return this.;
    }

    
Creates an admin object.

Parameters:
appName Name of application, in case of embedded rar.
connectorName Module name of the resource adapter.
jndiName JNDI name to be registered.
adminObjectType Interface name of the admin object.
props Properties object containing name/value pairs of properties.
    public void addAdminObject(
            String appName,
            String connectorName,
            ResourceInfo resourceInfo,
            String adminObjectType,
            String adminObjectClassName,
            Properties props)
            throws ConnectorRuntimeException {
        if (props == null) {
            // empty properties
            props = new Properties();
        }
        ConnectorRegistry registry = ConnectorRegistry.getInstance();
        ConnectorDescriptor desc = registry.getDescriptor(connectorName);
        AdminObject aoDesc = null;
        if(adminObjectClassName == null){
            List<AdminObjectadminObjects =
                    desc.getAdminObjectsByType(adminObjectType);
            if(adminObjects.size() > 1){
                String msg = .getString("aor.could_not_determine_aor_type"adminObjectType);
                throw new ConnectorRuntimeException(msg);
            }else{
                aoDesc = adminObjects.get(0);
            }
        }else{
            aoDesc = desc.getAdminObject(adminObjectTypeadminObjectClassName);
        }
        AdministeredObjectResource aor = new AdministeredObjectResource(resourceInfo);
        aor.initialize(aoDesc);
        aor.setResourceAdapter(connectorName);
        Object[] envProps = aoDesc.getConfigProperties().toArray();
        //Add default config properties to aor
        //Override them if same config properties are provided by the user
        for (int i = 0; i < envProps.lengthi++) {
            ConnectorConfigProperty  envProp = (ConnectorConfigProperty ) envProps[i];
            String name = envProp.getName();
            String userValue = (Stringprops.remove(name);
            if (userValue != null)
                aor.addConfigProperty(new ConnectorConfigProperty (
                        nameuserValueuserValueenvProp.getType()));
            else
                aor.addConfigProperty(envProp);
        }
        //Add non-default config properties provided by the user to aor
        Iterator iter = props.keySet().iterator();
        while (iter.hasNext()) {
            String name = (Stringiter.next();
            String userValue = props.getProperty(name);
            if (userValue != null)
                aor.addConfigProperty(new ConnectorConfigProperty (
                        nameuserValueuserValue));
        }
        // bind to JNDI namespace
        try {
            Reference ref = aor.createAdminObjectReference();
            .getResourceNamingService().publishObject(resourceInforeftrue);
        } catch (NamingException ex) {
            String i18nMsg = .getString(
                    "aira.cannot_bind_admin_obj");
            throw new ConnectorRuntimeException(i18nMsg);
        }
    }
New to GrepCode? Check out our FAQ X