use of org.nutz.el.ElException in project nutz by nutzam.
the class ByMake method run.
public Object run(List<Object> fetchParam) {
if (fetchParam.isEmpty())
throw new ElException("'by' must have params");
String p = (String) fetchParam.remove(0);
String className = p;
String methodName = null;
if (p.contains("#")) {
String[] tmp = p.split("#");
className = tmp[0];
methodName = tmp[1];
}
try {
Class<?> klass = Lang.loadClass(className);
if (methodName == null) {
methodName = "run";
}
if (RunMethod.class.isAssignableFrom(klass)) {
return ((RunMethod) klass.newInstance()).run(fetchParam);
}
Object[] args = fetchParam.toArray();
Method method = Mirror.me(klass).findMethod(methodName, args);
if (Modifier.isStatic(method.getModifiers())) {
return method.invoke(null, args);
} else {
return method.invoke(klass.newInstance(), args);
}
} catch (Exception e) {
throw new ElException(e);
}
}
use of org.nutz.el.ElException in project nutz by nutzam.
the class AccessOpt method calculate.
public Object calculate() {
//如果直接调用计算方法,那基本上就是直接调用属性了吧...我也不知道^^
Object obj = fetchVar();
if (obj == null) {
throw new ElException("obj is NULL, can't call obj." + right);
}
if (obj instanceof Map) {
Map<?, ?> om = (Map<?, ?>) obj;
if (om.containsKey(right.toString())) {
return om.get(right.toString());
}
}
if (obj instanceof Context) {
Context sc = (Context) obj;
if (sc.has(right.toString())) {
return sc.get(right.toString());
}
}
Mirror<?> me = Mirror.me(obj);
return me.getValue(obj, right.toString());
}
Aggregations