54 lines
1.4 KiB
Java
54 lines
1.4 KiB
Java
package net.tccn.qtask.impl;
|
|
|
|
import net.tccn.base.Kv;
|
|
import net.tccn.qtask.QTask;
|
|
import net.tccn.qtask.Task;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
|
|
public class QTaskMethod extends QTaskAbs implements QTask {
|
|
|
|
public QTaskMethod(Task e) {
|
|
super(e);
|
|
}
|
|
|
|
public String getClazz(){
|
|
String queryId = getE().queryId;
|
|
return queryId.substring(0, queryId.lastIndexOf("."));
|
|
}
|
|
|
|
public String getMethod(){
|
|
String queryId = getE().queryId;
|
|
return queryId.substring(queryId.lastIndexOf(".") + 1);
|
|
}
|
|
public Kv getPara() {
|
|
return getE().para;
|
|
}
|
|
|
|
// execute JAVA method by CLASS AND METHOD
|
|
@Override
|
|
public Object execute() {
|
|
try {
|
|
Class<?> type = Class.forName(getClazz());
|
|
Object obj = type.newInstance();
|
|
|
|
Method method = type.getMethod(getMethod(), Kv.class);
|
|
|
|
return method.invoke(obj, getPara());
|
|
} catch (ClassNotFoundException e) {
|
|
e.printStackTrace();
|
|
} catch (IllegalAccessException e) {
|
|
e.printStackTrace();
|
|
} catch (InstantiationException e) {
|
|
e.printStackTrace();
|
|
} catch (NoSuchMethodException e) {
|
|
e.printStackTrace();
|
|
} catch (InvocationTargetException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
}
|