FileDocCategorySizeDatePackage
RARUtils.javaAPI DocGlassfish v2 API11182Tue Jul 31 04:33:34 BST 2007com.sun.enterprise.connectors.util

RARUtils

public class RARUtils extends Object
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
Sivakumar Thyagarajan

Fields Summary
static Logger
_logger
private static com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
Methods Summary
private static java.util.MapextractRABeanProps(java.lang.String raClassName, java.lang.ClassLoader classLoader)
Extracts RA Bean properties via reflection.

param
raClassName The RA Bean class name.
param
ucl the classloader to use to find the class.

        Map hMap = new HashMap();
        //Only if RA is a 1.5 RAR, we need to get RA JavaBean properties, else
        //return an empty map.
        if(raClassName.trim().length() != 0) {
            Class c = classLoader.loadClass(raClassName);
            if(_logger.isLoggable(Level.FINER)) printClassDetails(c);
            hMap = getJavaBeanProperties(c);
        }
        return hMap;
    
private static java.util.MapgetJavaBeanProperties(java.lang.Class c)

        Method[] m = c.getMethods();
        Map hMap = new HashMap();
        for (int i = 0; i < m.length; i++) {
            _logger.finer(m[i].getName());
            if(m[i].getName().startsWith("get") 
                    && isValidRABeanConfigProperty(m[i].getReturnType())) {
                hMap.put(m[i].getName().substring(3), m[i].getReturnType());
            }
        }
        
        //remove Object's Class attribute.
        hMap.remove("Class");
        return hMap;
    
public static java.util.SetgetMergedActivationConfigProperties(com.sun.enterprise.deployment.EjbMessageBeanDescriptor msgDesc)
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 = (EnvironmentProperty) iter.next();
                mergedProps.add(entry);
                String propName = (String) entry.getName();
                runtimePropNames.add(propName);
            }
        }
        
        Set standardProps = msgDesc.getActivationConfigProperties();
        if(standardProps != null){
            Iterator iter = standardProps.iterator();
            while (iter.hasNext()) {
                EnvironmentProperty entry = (EnvironmentProperty) iter.next();
                String propName = (String) entry.getName();
                if (runtimePropNames.contains(propName))
                    continue;
                mergedProps.add(entry);
            }
        }
        
        return mergedProps;
        
    
public static java.util.MapgetRABeanProperties(java.lang.String pathToDeployableUnit)
Finds the properties of a RA JavaBean bundled in a RAR without exploding the RAR

param
pathToDeployableUnit a physical,accessible location of the connector module. [either a RAR for RAR-based deployments or a directory for Directory based deployments]
return
A Map that is of An empty map is returned in the case of a 1.0 RAR


                                                                       
           
        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 java.util.MapgetRABeanPropertiesForDirectoryBasedDeployment(java.lang.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()}, 
                                                                                                RARUtils.class.getClassLoader());
            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;
    
private static java.util.MapgetRABeanPropertiesForRARBasedDeployment(java.lang.String rarLocation)

        ConnectorRARClassLoader jarCL = 
                            (new ConnectorRARClassLoader(rarLocation, RARUtils.class.getClassLoader()));
        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 booleanisPrimitiveWrapper(java.lang.Class clz)
Determines if a class is one of the eight java primitive wrapper classes

        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));
    
public static booleanisValidRABeanConfigProperty(java.lang.Class clz)
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

        return (clz.isPrimitive() || clz.equals(String.class) 
                        || isPrimitiveWrapper(clz));
    
public static voidmain(java.lang.String[] args)

        if(!(args.length >= 1)){
            System.out.println("<Usage> java RARUtils directory-path ");
            return;
        }
        
        Map hMap = RARUtils.getRABeanPropertiesForDirectoryBasedDeployment(args[0]);
        System.out.println("RA JavaBean Properties");
        System.out.println(hMap);
    
private static voidprintClassDetails(java.lang.Class c)

        Method[] m = c.getMethods();
        _logger.finer("Methods in " + c.getName());
        for (int i = 0; i < m.length; i++) {
            _logger.finer(m[i].toString());
        }