Example usage for org.apache.commons.jxpath.util MethodLookupUtils lookupStaticMethod

List of usage examples for org.apache.commons.jxpath.util MethodLookupUtils lookupStaticMethod

Introduction

In this page you can find the example usage for org.apache.commons.jxpath.util MethodLookupUtils lookupStaticMethod.

Prototype

public static Method lookupStaticMethod(Class targetClass, String name, Object[] parameters) 

Source Link

Document

Look up a static method.

Usage

From source file:org.chiba.xml.xforms.xpath.ExtensionFunctions.java

private MethodFunction getMethodFunction(Class clazz, String name, Object[] parameters) {
    Method method = MethodLookupUtils.lookupStaticMethod(clazz, name, parameters);
    if (method != null) {
        return new MethodFunction(method);
    }//from ww w .j a  v a2  s.  c om

    return null;
}

From source file:org.openvpms.component.system.common.jxpath.AbstractObjectFunctions.java

/**
 * Returns a Function, if any, for the specified namespace,
 * name and parameter types.//from  w  w  w  .j a  va 2 s.  c  om
 *
 * @param namespace if it is not the namespace specified in the constructor,
 *                  the method returns null
 * @param name      is a function name.
 * @return a MethodFunction, or null if there is no such function.
 */
public Function getFunction(String namespace, String name, Object[] parameters) {
    if (!namespace.equals(this.namespace)) {
        return null;
    }

    if (parameters == null) {
        parameters = EMPTY_ARRAY;
    }

    Method method = MethodLookupUtils.lookupStaticMethod(objectClass, name, parameters);
    if (method != null && Modifier.isStatic(method.getModifiers())) {
        // need to check static due to bug in MethodLookupUtils
        return new MethodFunction(method);
    }

    Object[] params = getParameters(parameters);
    method = MethodLookupUtils.lookupMethod(objectClass, name, params);
    if (method != null) {
        return new MethodFunction(method) {
            @Override
            public Object invoke(ExpressionContext context, Object[] parameters) {
                return super.invoke(context, getParameters(parameters));
            }
        };
    }

    return null;
}

From source file:org.xchain.framework.jxpath.StandardFunctions.java

public Function getFunction(String namespace, String name, Object[] parameters) {
    if ((this.namespace == null && namespace != null)
            || (this.namespace != null && !this.namespace.equals(namespace))) {
        return null;
    }/*from   www  . ja  va  2  s .  c  o m*/

    if (parameters == null) {
        parameters = new Object[] {};
    }

    if ("string-join".equals(name)) {
        Method method = MethodLookupUtils.lookupStaticMethod(StandardFunctions.class, "stringJoin", parameters);

        if (method == null) {
            return packageFunctions.getFunction(namespace, name, parameters);
        }

        return new MethodFunction(method);
    }

    return packageFunctions.getFunction(namespace, name, parameters);
}

From source file:org.xchain.framework.lifecycle.NamespaceFunctionLibrary.java

public Function getFunction(String namespace, String name, Object[] parameters) {
    // make sure that we are requesting the correct namespace.
    if (namespace == null && this.namespace != null) {
        return null;
    } else if (!namespace.equals(this.namespace)) {
        return null;
    }// w  ww  .j a va2  s  .  c o  m

    if (parameters == null) {
        parameters = EMPTY_ARRAY;
    }

    Set<Class> constructorClassSet = constructorClassMap.get(name);
    Constructor constructor;
    if (constructorClassSet != null) {
        for (Class constructorClass : constructorClassSet) {
            constructor = MethodLookupUtils.lookupConstructor(constructorClass, parameters);
            if (constructor != null) {
                return new ConstructorFunction(constructor);
            }
        }
    }

    Set<MethodInfo> methodInfoSet = staticMethodInfoMap.get(name);
    Method method;

    if (methodInfoSet != null) {
        for (MethodInfo methodInfo : methodInfoSet) {
            method = MethodLookupUtils.lookupStaticMethod(methodInfo.getMethodClass(),
                    methodInfo.getMethodName(), parameters);
            if (method != null) {
                return new MethodFunction(method);
            }
        }
    }

    methodInfoSet = instanceMethodInfoMap.get(name);

    if (methodInfoSet != null) {
        for (MethodInfo methodInfo : methodInfoSet) {
            Object[] instanceParameters = parameters;
            Method singletonAccessor = methodInfo.getSingletonAccessor();
            if (singletonAccessor != null) {
                try {
                    Object singleton = singletonAccessor.invoke(null, EMPTY_ARRAY);
                    instanceParameters = new Object[parameters.length + 1];
                    instanceParameters[0] = singleton;
                    for (int i = 0; i < parameters.length; i++) {
                        instanceParameters[i + 1] = parameters[i];
                    }
                    method = MethodLookupUtils.lookupMethod(methodInfo.getMethodClass(),
                            methodInfo.getMethodName(), instanceParameters);
                    if (method != null) {
                        return new SingletonMethodFunction(method, singleton);
                    }
                } catch (Exception e) {
                    if (log.isDebugEnabled()) {
                        log.debug("Could not find singleton for class '" + methodInfo.getMethodClass().getName()
                                + "'.", e);
                    }
                }
            } else {
                method = MethodLookupUtils.lookupMethod(methodInfo.getMethodClass(), methodInfo.getMethodName(),
                        instanceParameters);
                if (method != null) {
                    return new MethodFunction(method);
                }
            }
        }
    }

    return null;
}