FileDocCategorySizeDatePackage
ClassFileLoaderFactory.javaAPI DocGlassfish v2 API5187Fri May 04 22:33:24 BST 2007com.sun.enterprise.tools.verifier.apiscan.classfile

ClassFileLoaderFactory

public class ClassFileLoaderFactory extends Object
A factory for ClassFileLoader so that we can control the creation of ClassFileLoaders. More over, this factory can be dynamically configured by setting the Java class name of the actual ClassFileLoader type in the system property apiscan.ClassFileLoader. See newInstance() method.
author
Sanjeeb.Sahoo@Sun.COM

Fields Summary
private static String
resourceBundleName
private static Logger
logger
private static final String
myClassName
Constructors Summary
Methods Summary
public static ClassFileLoadernewInstance(java.lang.Object[] args)
a factory method to create ClassFileLoader instance. It decides which kind of loader class to instantioate based on the class name supplied by the system property ClassFileLoader. If there is no such property set, it defaults to {@link BCELClassFileLoader}

param
args Search path to be used by the ClassFileLoader. Depending on the type of the ClassFileLoader requested, the semantics of this argument varies.
throws
RuntimeException If it could not instantiate the loader type requested. The actual error is wrapped in this exception.

 // NOI18N
                                                                                                                                                                     
        
              
        logger.entering(myClassName, "newInstance", args); // NOI18N
        String loaderClassName = System.getProperty("apiscan.ClassFileLoader");
        if (loaderClassName == null) {
            loaderClassName =
                    com.sun.enterprise.tools.verifier.apiscan.classfile.BCELClassFileLoader.class.getName();
            logger.logp(Level.FINE, myClassName, "newInstance", // NOI18N
                    "System Property apiscan.ClassFileLoader is null, so defaulting to " + // NOI18N
                    loaderClassName);
        }
        try {
            Class clazz = Class.forName(loaderClassName);
            Object o = null;
            Constructor[] constrs = clazz.getConstructors();
            for (int i = 0; i < constrs.length; ++i) {
                try {
                    o = constrs[i].newInstance(args);
                } catch (IllegalArgumentException e) {
                 //try another constr as this argument did not match the reqd types for this constr.
                }
            }
            if (o == null) throw new Exception(
                    "Could not find a suitable constructor for this argument types.");
            logger.exiting(myClassName, "<init>", o); // NOI18N
            return (ClassFileLoader) o;
        } catch (Exception e) {
            logger.log(Level.SEVERE, "com.sun.enterprise.tools.verifier.apiscan.classfile.ClassFileLoaderFactory.exception1", e);
            throw new RuntimeException("Unable to instantiate a loader.", e);
        }