List of usage examples for org.apache.commons.jxpath.util MethodLookupUtils lookupMethod
public static Method lookupMethod(Class targetClass, String name, Object[] parameters)
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 ww w .j av a2s . co m*/ * * @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.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; }/*from w ww. j av a2 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; }