public static Bean createBean()

in src/main/java/org/apache/bsf/util/ReflectionUtils.java [205:252]


    public static Bean createBean(final ClassLoader cld, final String className, final Class[] argTypes, final Object[] args) throws ClassNotFoundException,
            NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException {
        if (argTypes != null) {

            // if class loader given, use that one, else try
            // the Thread's context class loader (if set) and then
            // the BSFMananger defining class loader
            Class cl = null;
            ClassNotFoundException exCTX = null;

// -----------------------------
            if (cld != null) { // class loader supplied as argument
                try { // CL passed as argument
                    cl = cld.loadClass(className);
                } catch (final ClassNotFoundException e02) {
                    exCTX = e02;
                }
            }

            if (cl == null) {
                // load context class loader, only use it, if not null
                final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
                if (tccl != null) {
                    try { // CTXCL
                        cl = tccl.loadClass(className);
                    } catch (final ClassNotFoundException e01) {
                    }
                }
            }

            if (cl == null) { // class not loaded yet
                // defined CL
                if (cld != bsfManagerDefinedCL) { // if not used already, attempt to load
                    cl = bsfManagerDefinedCL.loadClass(className);
                } else { // classloader was already used, hence re-throw exception
                    throw exCTX; // re-throw very first exception
                }
            }
// -----------------------------

            final Constructor c = MethodUtils.getConstructor(cl, argTypes);
            return new Bean(cl, c.newInstance(args));
        } else {
            // create the bean with no args constructor
            final Object obj = Beans.instantiate(cld, className);
            return new Bean(obj.getClass(), obj);
        }
    }