public static Object createBean()

in src/main/java/org/apache/bsf/util/EngineUtils.java [223:263]


    public static Object createBean(final String className, final Object args[]) throws BSFException {
        Bean obj;
        Class[] argTypes = null;

        if (args != null) {
            argTypes = new Class[args.length];
            for (int i = 0; i < args.length; i++) {
                argTypes[i] = (args[i] != null) ? args[i].getClass() : null;
            }
        }

        try {
            try {
                obj = ReflectionUtils.createBean(null, className, argTypes, args);
                return obj.value;
            } catch (final NoSuchMethodException me) {
                // ok, so that didn't work - now try converting any primitive
                // wrapper types to their primitive counterparts
                try {
                    // if args is null the NullPointerException will get caught
                    // below and the right thing'll happen .. ugly but works
                    for (int i = 0; i < args.length; i++) {
                        if (args[i] instanceof Number) {
                            argTypes[i] = byte.class;
                        } else if (args[i] instanceof Boolean) {
                            argTypes[i] = boolean.class;
                        } else if (args[i] instanceof Character) {
                            argTypes[i] = char.class;
                        }
                    }
                    obj = ReflectionUtils.createBean(null, className, argTypes, args);
                    return obj.value;
                } catch (final Exception e) {
                    // throw the previous exception
                    throw me;
                }
            }
        } catch (final Exception e) {
            throw new BSFException(BSFException.REASON_OTHER_ERROR, "[EngineUtils.createBean()]" + e.getMessage(), e);
        }
    }