Search in sources :

Example 1 with RunMethod

use of org.nutz.el.opt.RunMethod 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);
    }
}
Also used : RunMethod(org.nutz.el.opt.RunMethod) ElException(org.nutz.el.ElException) Method(java.lang.reflect.Method) RunMethod(org.nutz.el.opt.RunMethod) ElException(org.nutz.el.ElException)

Example 2 with RunMethod

use of org.nutz.el.opt.RunMethod in project nutz by nutzam.

the class CustomMake method init.

/**
     * 加载插件
     */
@SuppressWarnings({ "unchecked", "rawtypes" })
public CustomMake init() {
    List<String> plug = (List<String>) ((Map) NutConf.get("EL")).get("custom");
    String[] t = plug.toArray(new String[0]);
    PluginManager<RunMethod> rm = new SimplePluginManager<RunMethod>(t);
    for (RunMethod r : rm.gets()) {
        me().runms.put(r.fetchSelf(), r);
    }
    return this;
}
Also used : RunMethod(org.nutz.el.opt.RunMethod) List(java.util.List) SimplePluginManager(org.nutz.plugin.SimplePluginManager)

Aggregations

RunMethod (org.nutz.el.opt.RunMethod)2 Method (java.lang.reflect.Method)1 List (java.util.List)1 ElException (org.nutz.el.ElException)1 SimplePluginManager (org.nutz.plugin.SimplePluginManager)1