Revision 44750 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/CallStaticMethodFunction.java
CallStaticMethodFunction.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator.impl.function.programming; |
2 | 2 |
|
3 | 3 |
import java.lang.reflect.Method; |
4 |
import java.util.List; |
|
4 | 5 |
import org.apache.commons.lang3.Range; |
6 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
7 |
import org.gvsig.expressionevaluator.ExpressionRuntimeException; |
|
5 | 8 |
import org.gvsig.expressionevaluator.Function; |
6 | 9 |
import org.gvsig.expressionevaluator.Interpreter; |
7 | 10 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
8 | 11 |
|
12 |
@SuppressWarnings("UseSpecificCatch") |
|
9 | 13 |
public class CallStaticMethodFunction extends AbstractFunction { |
10 | 14 |
|
11 | 15 |
public static final String NAME = "CALL_STATIC"; |
... | ... | |
34 | 38 |
if( theMethodName == null ) { |
35 | 39 |
throw new NullPointerException("A method name was expected to invoke and a null methd name was received"); |
36 | 40 |
} |
41 |
List<ClassLoader> loaders = ExpressionEvaluatorLocator.getManager().getClassLoaders(); |
|
42 |
Class<?> theClass = null; |
|
43 |
for (ClassLoader loader : loaders) { |
|
44 |
try { |
|
45 |
theClass = loader.loadClass(theClassName); |
|
46 |
if( theClass!=null ) { |
|
47 |
break; |
|
48 |
} |
|
49 |
} catch(Throwable th) { |
|
50 |
// Do nothing skip |
|
51 |
} |
|
52 |
} |
|
53 |
if( theClass == null ) { |
|
54 |
throw new ExpressionRuntimeException("Can't localte the class '"+theClassName+"'."); |
|
55 |
} |
|
56 |
|
|
37 | 57 |
Class[] parameterTypes = new Class[args.length-firstArg]; |
38 | 58 |
Object[] parameters = new Object[args.length-firstArg]; |
39 | 59 |
for (int i = 0; i < parameters.length; i++) { |
... | ... | |
45 | 65 |
parameterTypes[i] = parameter.getClass(); |
46 | 66 |
} |
47 | 67 |
} |
48 |
Class<?> theClass = Class.forName(theClassName); |
|
49 | 68 |
Method method = theClass.getMethod(theMethodName, parameterTypes); |
50 | 69 |
Object value = method.invoke(null, parameters); |
51 | 70 |
return value; |
Also available in: Unified diff