| 7 | import com.sen.api.functions.Function; |
| 8 | |
| 9 | public class FunctionUtil{ |
| 10 | |
| 11 | private static final Map<String, Class<? extends Function>> functionsMap = new HashMap<String, Class<? extends Function>>(); |
| 12 | static { |
| 13 | //bodyfile 特殊处理 |
| 14 | functionsMap.put("bodyfile", null); |
| 15 | List<Class<?>> clazzes = ClassFinder.getAllAssignedClass(Function.class); |
| 16 | clazzes.forEach((clazz) -> { |
| 17 | try { |
| 18 | // function |
| 19 | Function tempFunc = (Function) clazz.newInstance(); |
| 20 | String referenceKey = tempFunc.getReferenceKey(); |
| 21 | if (referenceKey.length() > 0) { // ignore self |
| 22 | functionsMap.put(referenceKey, tempFunc.getClass()); |
| 23 | } |
| 24 | } catch (Exception ex) { |
| 25 | ex.printStackTrace(); |
| 26 | //TODO |
| 27 | } |
| 28 | }); |
| 29 | } |
| 30 | |
| 31 | public static boolean isFunction(String functionName){ |
| 32 | return functionsMap.containsKey(functionName); |
| 33 | } |
| 34 | |
| 35 | public static String getValue(String functionName,String[] args){ |
| 36 | try { |
| 37 | return functionsMap.get(functionName).newInstance().execute(args); |
| 38 | } catch (Exception e) { |
| 39 | // TODO Auto-generated catch block |
| 40 | e.printStackTrace(); |
| 41 | return ""; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | } |
| 46 |
nothing calls this directly
no test coverage detected