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.util;
 
 import java.util.*;
 
 
 import java.io.File;
 import java.net.URL;
This is a utility class to obtain the properties of a RA JavaBean housed in a RAR module/deployment dir, without exploding the RAR contents. This method would be used by the admin-gui to configure RA properties during RA deployment to a cluster.

Author(s):
Sivakumar Thyagarajan
 
 public class RARUtils {
     private final static Logger _logger = LogDomains.getLogger(RARUtils.class.);
     private static StringManager localStrings = 
         StringManager.getManagerRARUtils.class );

    
Finds the properties of a RA JavaBean bundled in a RAR without exploding the RAR

Parameters:
pathToDeployableUnit a physical,accessible location of the connector module. [either a RAR for RAR-based deployments or a directory for Directory based deployments]
Returns:
A Map that is of <String RAJavaBeanPropertyName, String defaultPropertyValue> An empty map is returned in the case of a 1.0 RAR
 
 /* TODO V3
     public static Map getRABeanProperties (String pathToDeployableUnit) throws ConnectorRuntimeException {
         File f = new File(pathToDeployableUnit);
         if (!f.exists()){
             String i18nMsg = localStrings.getString(
                 "rar_archive_not_found", pathToDeployableUnit);
             throw new ConnectorRuntimeException( i18nMsg );
         }
         if(f.isDirectory()) {
             return getRABeanPropertiesForDirectoryBasedDeployment(pathToDeployableUnit);
         } else {
             return getRABeanPropertiesForRARBasedDeployment(pathToDeployableUnit);
         }
     }
 */
 
/*
    private static Map getRABeanPropertiesForRARBasedDeployment(String rarLocation){
        ConnectorRARClassLoader jarCL = 
                            (new ConnectorRARClassLoader(rarLocation,  
                             ApplicationServer.getServerContext().getCommonClassLoader()));
        String raClassName = ConnectorDDTransformUtils.
                                    getResourceAdapterClassName(rarLocation);
        _logger.finer("RA class :  " + raClassName);
        Map hMap = new HashMap();
        try {
           hMap = extractRABeanProps(raClassName, jarCL);
        } catch (ClassNotFoundException e) {
            _logger.info(e.getMessage());
            _logger.log(Level.FINE, "Error while trying to find class " 
                            + raClassName + "in RAR at " + rarLocation, e);
        }
        return hMap;
    }
*/
/*
    private static Map getRABeanPropertiesForDirectoryBasedDeployment(
                    String directoryLocation) {
        Map hMap = new HashMap();
        //Use the deployment APIs to get the name of the resourceadapter
        //class through the connector descriptor
        try {
            ConnectorDescriptor cd = ConnectorDDTransformUtils.
                                getConnectorDescriptor(directoryLocation);
            String raClassName = cd.getResourceAdapterClass();
            
            File f = new File(directoryLocation);
            URLClassLoader ucl = new URLClassLoader(new URL[]{f.toURI().toURL()}, 
                                  ApplicationServer.getServerContext().getCommonClassLoader());
            hMap = extractRABeanProps(raClassName, ucl);
        } catch (IOException e) {
            _logger.info(e.getMessage());
            _logger.log(Level.FINE, "IO Error while trying to read connector" +
                   "descriptor to get resource-adapter properties", e);
        } catch (ClassNotFoundException e) {
            _logger.info(e.getMessage());
            _logger.log(Level.FINE, "Unable to find class while trying to read connector" +
                   "descriptor to get resource-adapter properties", e);
        } catch (ConnectorRuntimeException e) {
            _logger.info(e.getMessage());
            _logger.log(Level.FINE, "Error while trying to read connector" +
                   "descriptor to get resource-adapter properties", e);
        } catch (Exception e) {
            _logger.info(e.getMessage());
            _logger.log(Level.FINE, "Error while trying to read connector" +
                   "descriptor to get resource-adapter properties", e);
        }
        return hMap;
    }
*/

    
A valid resource adapter java bean property should either be one of the following 1. A Java primitive or a primitve wrapper 2. A String
    public static boolean isValidRABeanConfigProperty(Class clz) {
        return (clz.isPrimitive() || clz.equals(String.class
                        || isPrimitiveWrapper(clz));
    }

    
Determines if a class is one of the eight java primitive wrapper classes
    private static boolean isPrimitiveWrapper(Class clz) {
        return (clz.equals(Boolean.class) || clz.equals(Character.class
                 || clz.equals(Byte.class) || clz.equals(Short.class
                 || clz.equals(Integer.class) || clz.equals(Long.class)
                 || clz.equals(Float.class) || clz.equals(Double.class));
    }

   
Prepares the name/value pairs for ActivationSpec.

Rule:

1. The name/value pairs are the union of activation-config on standard DD (message-driven) and runtime DD (mdb-resource-adapter) 2. If there are duplicate property settings, the value in runtime activation-config will overwrite the one in the standard activation-config.

        
        Set mergedProps = new HashSet();
        Set runtimePropNames = new HashSet();
        
        Set runtimeProps = msgDesc.getRuntimeActivationConfigProperties();
        if(runtimeProps != null){
            Iterator iter = runtimeProps.iterator();
            while (iter.hasNext()) {
                EnvironmentProperty entry = (EnvironmentPropertyiter.next();
                mergedProps.add(entry);
                String propName = (Stringentry.getName();
                runtimePropNames.add(propName);
            }
        }
        
        Set standardProps = msgDesc.getActivationConfigProperties();
        if(standardProps != null){
            Iterator iter = standardProps.iterator();
            while (iter.hasNext()) {
                EnvironmentProperty entry = (EnvironmentPropertyiter.next();
                String propName = (Stringentry.getName();
                if (runtimePropNames.contains(propName))
                    continue;
                mergedProps.add(entry);
            }
        }
        
        return mergedProps;
        
    }
    public static Class loadClassFromRar(String rarNameString beanClassNamethrows ConnectorRuntimeException{
        String rarLocation = getRarLocation(rarName);
        return loadClass(rarLocationbeanClassName);
    }

    
given the rar name, location of rar will be returned

Parameters:
rarName resource-adapter name
Returns:
location of resource-adapter
    private static String getRarLocation(String rarNamethrows ConnectorRuntimeException{
        return ConnectorsUtil.getLocation(rarName);
    }


    
given the location of .rar (archive / exploded dir), the specified class will be loaded

Parameters:
pathToDeployableUnit location of .rar (archive / exploded dir)
beanClassName class that has to be loaded
Returns:
loaded class
Throws:
com.sun.appserv.connectors.internal.api.ConnectorRuntimeException when unable to load the class
    private static Class loadClass(String pathToDeployableUnitString beanClassNamethrows ConnectorRuntimeException {
        Class cls = null;
        ClassLoader cl = getClassLoader(pathToDeployableUnit);
        try {
            //Only if RA is a 1.5 RAR, we need to get RA JavaBean properties, else
            //return an empty map.
            if (beanClassName != null && beanClassName.trim().length() != 0) {
                cls = cl.loadClass(beanClassName);
            }
            return cls;
        } catch (ClassNotFoundException e) {
            .info(e.getMessage());
            if(.isLoggable(.)) {
                .log(."Unable to find class while trying to read connector" +
                    "descriptor to get resource-adapter properties"e);
            }
            ConnectorRuntimeException cre = new ConnectorRuntimeException("unable to find class : " + beanClassName);
            cre.setStackTrace(e.getStackTrace());
            throw cre;
        }
    }

    
based on the provided file type (dir or archive) appropriate class-loader will be selected

Parameters:
file file (dir/ archive)
Returns:
classloader that is capable of loading the .rar
Throws:
com.sun.appserv.connectors.internal.api.ConnectorRuntimeException when unable to load the .rar
    private static ClassLoader getClassLoader(String filethrows ConnectorRuntimeException {
        ClassLoader cl = null;
        File f = new File(file);
        validateRARLocation(f);
        try {
            ClassLoader commonClassLoader =
                    ConnectorRuntime.getRuntime().getClassLoaderHierarchy().getCommonClassLoader();
            if (f.isDirectory()) {
                List<URLurls = new ArrayList<URL>();
                urls.add(f.toURI().toURL());
                appendURLs(urlsf);
                cl = new URLClassLoader(urls.toArray(new URL[urls.size()]), commonClassLoader);
            } else {
                cl = new ConnectorRARClassLoader(filecommonClassLoader);
            }
            return cl;
        } catch (IOException ioe) {
            .info(ioe.getMessage());
            if (.isLoggable(.)) {
                .log(."IO Error while trying to read connector"
                        + "descriptor to get resource-adapter properties"ioe);
            }
            ConnectorRuntimeException cre = new ConnectorRuntimeException(
                    "unable to read connector descriptor from : " + file);
            cre.setStackTrace(ioe.getStackTrace());
            throw cre;
        }
    }
    private static void appendURLs(List<URLurlsFile fthrows MalformedURLException {
        for (File file : f.listFiles()) {
            if (file.getName().toUpperCase(Locale.getDefault()).endsWith(".JAR")) {
                urls.add(file.toURI().toURL());
            } else if (file.isDirectory()) {
                appendURLs(urlsfile);
            }
        }
    }

    
check whether the provided location is valid

Parameters:
f location where the .rar is present
Throws:
com.sun.appserv.connectors.internal.api.ConnectorRuntimeException
    private static void validateRARLocation(File fthrows ConnectorRuntimeException {
        if (!f.exists()) {
            String i18nMsg = .getString(
                    "rar_archive_not_found"f);
            throw new ConnectorRuntimeException(i18nMsg);
        }
    }
    
New to GrepCode? Check out our FAQ X