.
This commit is contained in:
53
src/main/java/net/tccn/qtask/impl/QTaskMethod.java
Normal file
53
src/main/java/net/tccn/qtask/impl/QTaskMethod.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package net.tccn.qtask.impl;
|
||||
|
||||
import net.tccn.qtask.E;
|
||||
import net.tccn.base.Kv;
|
||||
import net.tccn.qtask.QTask;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class QTaskMethod extends QTaskAbs implements QTask {
|
||||
|
||||
public QTaskMethod(E 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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user