Search in sources :

Example 1 with RefInteger

use of lucee.commons.lang.types.RefInteger in project Lucee by lucee.

the class Reflector method getConstructorInstance.

public static ConstructorInstance getConstructorInstance(Class clazz, Object[] args, ConstructorInstance defaultValue) {
    args = cleanArgs(args);
    // getConstructors(clazz);
    Constructor[] constructors = cStorage.getConstructors(clazz, args.length);
    if (constructors != null) {
        Class[] clazzArgs = getClasses(args);
        // exact comparsion
        outer: for (int i = 0; i < constructors.length; i++) {
            if (constructors[i] != null) {
                Class[] parameterTypes = constructors[i].getParameterTypes();
                for (int y = 0; y < parameterTypes.length; y++) {
                    if (toReferenceClass(parameterTypes[y]) != clazzArgs[y])
                        continue outer;
                }
                return new ConstructorInstance(constructors[i], args);
            }
        }
        // like comparsion
        outer: for (int i = 0; i < constructors.length; i++) {
            if (constructors[i] != null) {
                Class[] parameterTypes = constructors[i].getParameterTypes();
                for (int y = 0; y < parameterTypes.length; y++) {
                    if (!like(clazzArgs[y], toReferenceClass(parameterTypes[y])))
                        continue outer;
                }
                return new ConstructorInstance(constructors[i], args);
            }
        }
        // convert comparsion
        ConstructorInstance ci = null;
        int _rating = 0;
        outer: for (int i = 0; i < constructors.length; i++) {
            if (constructors[i] != null) {
                RefInteger rating = (constructors.length > 1) ? new RefIntegerImpl(0) : null;
                Class[] parameterTypes = constructors[i].getParameterTypes();
                Object[] newArgs = new Object[args.length];
                for (int y = 0; y < parameterTypes.length; y++) {
                    try {
                        newArgs[y] = convert(args[y], toReferenceClass(parameterTypes[y]), rating);
                    } catch (PageException e) {
                        continue outer;
                    }
                }
                if (ci == null || rating.toInt() > _rating) {
                    if (rating != null)
                        _rating = rating.toInt();
                    ci = new ConstructorInstance(constructors[i], newArgs);
                }
            // return new ConstructorInstance(constructors[i],newArgs);
            }
        }
        return ci;
    }
    return defaultValue;
// throw new NoSuchMethodException("No matching Constructor for "+clazz.getName()+"("+getDspMethods(getClasses(args))+") found");
}
Also used : PageException(lucee.runtime.exp.PageException) Constructor(java.lang.reflect.Constructor) RefInteger(lucee.commons.lang.types.RefInteger) ConstructorInstance(lucee.runtime.reflection.pairs.ConstructorInstance) RefIntegerImpl(lucee.commons.lang.types.RefIntegerImpl)

Example 2 with RefInteger

use of lucee.commons.lang.types.RefInteger in project Lucee by lucee.

the class DatasourceConnectionPool method _dec.

private void _dec(DCStack stack, DataSource datasource, String username, String password) {
    RefInteger c = stack.getCounter();
    c.minus(1);
}
Also used : RefInteger(lucee.commons.lang.types.RefInteger)

Example 3 with RefInteger

use of lucee.commons.lang.types.RefInteger in project Lucee by lucee.

the class MacAddressWrap method getCallerClass.

/**
 * @return the class calling me and the first class not in bootdelegation if the the is in bootdelegation
 */
public static Caller getCallerClass() {
    final Ref ref = new Ref();
    new SecurityManager() {

        {
            ref.context = getClassContext();
        }
    };
    Caller rtn = new Caller();
    // element at position 2 is the caller
    Class<?> caller = ref.context[2];
    RefInteger index = new RefIntegerImpl(3);
    Class<?> clazz = _getCallerClass(ref.context, caller, index, true, true);
    // analyze the first result
    if (clazz == null)
        return rtn;
    if (isFromBundle(clazz)) {
        rtn.fromBundle = clazz;
        return rtn;
    }
    if (!OSGiUtil.isClassInBootelegation(clazz.getName())) {
        rtn.fromSystem = clazz;
    } else {
        rtn.fromBootDelegation = clazz;
    }
    clazz = null;
    if (rtn.fromBootDelegation != null) {
        index = new RefIntegerImpl(3);
        clazz = _getCallerClass(ref.context, caller, index, false, true);
        if (clazz == null)
            return rtn;
        if (isFromBundle(clazz)) {
            rtn.fromBundle = clazz;
            return rtn;
        } else
            rtn.fromSystem = clazz;
    }
    clazz = _getCallerClass(ref.context, caller, index, false, false);
    if (clazz == null)
        return rtn;
    rtn.fromBundle = clazz;
    return rtn;
}
Also used : RefInteger(lucee.commons.lang.types.RefInteger) RefIntegerImpl(lucee.commons.lang.types.RefIntegerImpl)

Example 4 with RefInteger

use of lucee.commons.lang.types.RefInteger in project Lucee by lucee.

the class Reflector method getMethodInstanceEL.

/**
 * gets the MethodInstance matching given Parameter
 * @param objMaybeNull maybe null
 * @param clazz Class Of the Method to get
 * @param methodName Name of the Method to get
 * @param args Arguments of the Method to get
 * @return return Matching Method
 * @throws
 */
public static MethodInstance getMethodInstanceEL(Object objMaybeNull, Class clazz, Collection.Key methodName, Object[] args) {
    checkAccessibility(objMaybeNull, clazz, methodName);
    args = cleanArgs(args);
    // getDeclaredMethods(clazz);
    Method[] methods = mStorage.getMethods(clazz, methodName, args.length);
    if (methods != null) {
        Class[] clazzArgs = getClasses(args);
        // print.e("exact:"+methodName);
        outer: for (int i = 0; i < methods.length; i++) {
            if (methods[i] != null) {
                Class[] parameterTypes = methods[i].getParameterTypes();
                for (int y = 0; y < parameterTypes.length; y++) {
                    if (toReferenceClass(parameterTypes[y]) != clazzArgs[y])
                        continue outer;
                }
                return new MethodInstance(methods[i], args);
            }
        }
        // print.e("like:"+methodName);
        outer: for (int i = 0; i < methods.length; i++) {
            if (methods[i] != null) {
                Class[] parameterTypes = methods[i].getParameterTypes();
                for (int y = 0; y < parameterTypes.length; y++) {
                    if (!like(clazzArgs[y], toReferenceClass(parameterTypes[y])))
                        continue outer;
                }
                return new MethodInstance(methods[i], args);
            }
        }
        // convert comparsion
        // print.e("convert:"+methodName);
        MethodInstance mi = null;
        int _rating = 0;
        outer: for (int i = 0; i < methods.length; i++) {
            if (methods[i] != null) {
                RefInteger rating = (methods.length > 1) ? new RefIntegerImpl(0) : null;
                Class[] parameterTypes = methods[i].getParameterTypes();
                Object[] newArgs = new Object[args.length];
                for (int y = 0; y < parameterTypes.length; y++) {
                    try {
                        newArgs[y] = convert(args[y], toReferenceClass(parameterTypes[y]), rating);
                    } catch (PageException e) {
                        continue outer;
                    }
                }
                if (mi == null || rating.toInt() > _rating) {
                    if (rating != null)
                        _rating = rating.toInt();
                    mi = new MethodInstance(methods[i], newArgs);
                }
            // return new MethodInstance(methods[i],newArgs);
            }
        }
        return mi;
    }
    return null;
}
Also used : PageException(lucee.runtime.exp.PageException) MethodInstance(lucee.runtime.reflection.pairs.MethodInstance) RefInteger(lucee.commons.lang.types.RefInteger) Method(java.lang.reflect.Method) RefIntegerImpl(lucee.commons.lang.types.RefIntegerImpl)

Example 5 with RefInteger

use of lucee.commons.lang.types.RefInteger in project Lucee by lucee.

the class DatasourceConnectionPool method _inc.

private void _inc(DCStack stack, DataSource datasource, String username, String password) {
    RefInteger c = stack.getCounter();
    c.plus(1);
}
Also used : RefInteger(lucee.commons.lang.types.RefInteger)

Aggregations

RefInteger (lucee.commons.lang.types.RefInteger)6 RefIntegerImpl (lucee.commons.lang.types.RefIntegerImpl)4 PageException (lucee.runtime.exp.PageException)2 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1 ConstructorInstance (lucee.runtime.reflection.pairs.ConstructorInstance)1 MethodInstance (lucee.runtime.reflection.pairs.MethodInstance)1 ArrayVisitor (lucee.transformer.bytecode.visitor.ArrayVisitor)1 DataMember (lucee.transformer.expression.var.DataMember)1 Member (lucee.transformer.expression.var.Member)1 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)1