@Test public void getFunction(){ assertNotNull(FunctionRegistry.getFunction("if")); assertNull(FunctionRegistry.getFunction("x-sin")); assertNotNull(FunctionRegistry.getFunction("sin")); try { FunctionRegistry.getFunction(Thread.class.getName()); fail(); } catch(TypeCheckException tce){ } try { FunctionRegistry.getFunction(MaliciousThread.class.getName()); fail(); } catch(TypeCheckException tce){ } Function firstEcho = FunctionRegistry.getFunction(EchoFunction.class.getName()); Function secondEcho = FunctionRegistry.getFunction(EchoFunction.class.getName()); assertNotSame(firstEcho, secondEcho); try { FunctionRegistry.getFunction(MaliciousEchoFunction.class.getName()); fail(); } catch(EvaluationException ee){ Throwable cause = ee.getCause(); assertTrue(cause instanceof ExceptionInInitializerError); } }
static public Function getFunction(String name){ if(name == null){ return null; } if(FunctionRegistry.pmmlFunctions.containsKey(name)){ Function function = FunctionRegistry.pmmlFunctions.get(name); return function; } if(FunctionRegistry.userDefinedFunctions.containsKey(name)){ Function function = FunctionRegistry.userDefinedFunctions.get(name); return function; } Class<?> functionClazz; if(FunctionRegistry.userDefinedFunctionClazzes.containsKey(name)){ functionClazz = FunctionRegistry.userDefinedFunctionClazzes.get(name); } else { functionClazz = loadFunctionClass(name); FunctionRegistry.userDefinedFunctionClazzes.put(name, functionClazz); } if(functionClazz != null){ Function function; try { function = (Function)functionClazz.newInstance(); } catch(IllegalAccessException | InstantiationException | ExceptionInInitializerError e){ throw new EvaluationException("Function class " + PMMLException.formatKey(functionClazz.getName()) + " could not be instantiated") .initCause(e); } return function; } return null; }
FunctionRegistry { static public Function getFunction(String name){ if(name == null){ return null; } if(FunctionRegistry.pmmlFunctions.containsKey(name)){ Function function = FunctionRegistry.pmmlFunctions.get(name); return function; } if(FunctionRegistry.userDefinedFunctions.containsKey(name)){ Function function = FunctionRegistry.userDefinedFunctions.get(name); return function; } Class<?> functionClazz; if(FunctionRegistry.userDefinedFunctionClazzes.containsKey(name)){ functionClazz = FunctionRegistry.userDefinedFunctionClazzes.get(name); } else { functionClazz = loadFunctionClass(name); FunctionRegistry.userDefinedFunctionClazzes.put(name, functionClazz); } if(functionClazz != null){ Function function; try { function = (Function)functionClazz.newInstance(); } catch(IllegalAccessException | InstantiationException | ExceptionInInitializerError e){ throw new EvaluationException("Function class " + PMMLException.formatKey(functionClazz.getName()) + " could not be instantiated") .initCause(e); } return function; } return null; } }
FunctionRegistry { static public Function getFunction(String name){ if(name == null){ return null; } if(FunctionRegistry.pmmlFunctions.containsKey(name)){ Function function = FunctionRegistry.pmmlFunctions.get(name); return function; } if(FunctionRegistry.userDefinedFunctions.containsKey(name)){ Function function = FunctionRegistry.userDefinedFunctions.get(name); return function; } Class<?> functionClazz; if(FunctionRegistry.userDefinedFunctionClazzes.containsKey(name)){ functionClazz = FunctionRegistry.userDefinedFunctionClazzes.get(name); } else { functionClazz = loadFunctionClass(name); FunctionRegistry.userDefinedFunctionClazzes.put(name, functionClazz); } if(functionClazz != null){ Function function; try { function = (Function)functionClazz.newInstance(); } catch(IllegalAccessException | InstantiationException | ExceptionInInitializerError e){ throw new EvaluationException("Function class " + PMMLException.formatKey(functionClazz.getName()) + " could not be instantiated") .initCause(e); } return function; } return null; } private  FunctionRegistry(); }
FunctionRegistry { static public Function getFunction(String name){ if(name == null){ return null; } if(FunctionRegistry.pmmlFunctions.containsKey(name)){ Function function = FunctionRegistry.pmmlFunctions.get(name); return function; } if(FunctionRegistry.userDefinedFunctions.containsKey(name)){ Function function = FunctionRegistry.userDefinedFunctions.get(name); return function; } Class<?> functionClazz; if(FunctionRegistry.userDefinedFunctionClazzes.containsKey(name)){ functionClazz = FunctionRegistry.userDefinedFunctionClazzes.get(name); } else { functionClazz = loadFunctionClass(name); FunctionRegistry.userDefinedFunctionClazzes.put(name, functionClazz); } if(functionClazz != null){ Function function; try { function = (Function)functionClazz.newInstance(); } catch(IllegalAccessException | InstantiationException | ExceptionInInitializerError e){ throw new EvaluationException("Function class " + PMMLException.formatKey(functionClazz.getName()) + " could not be instantiated") .initCause(e); } return function; } return null; } private  FunctionRegistry(); static Function getFunction(String name); static void putFunction(Function function); static void putFunction(String name, Function function); static void putFunction(String name, Class<? extends Function> functionClazz); static void removeFunction(String name); }
FunctionRegistry { static public Function getFunction(String name){ if(name == null){ return null; } if(FunctionRegistry.pmmlFunctions.containsKey(name)){ Function function = FunctionRegistry.pmmlFunctions.get(name); return function; } if(FunctionRegistry.userDefinedFunctions.containsKey(name)){ Function function = FunctionRegistry.userDefinedFunctions.get(name); return function; } Class<?> functionClazz; if(FunctionRegistry.userDefinedFunctionClazzes.containsKey(name)){ functionClazz = FunctionRegistry.userDefinedFunctionClazzes.get(name); } else { functionClazz = loadFunctionClass(name); FunctionRegistry.userDefinedFunctionClazzes.put(name, functionClazz); } if(functionClazz != null){ Function function; try { function = (Function)functionClazz.newInstance(); } catch(IllegalAccessException | InstantiationException | ExceptionInInitializerError e){ throw new EvaluationException("Function class " + PMMLException.formatKey(functionClazz.getName()) + " could not be instantiated") .initCause(e); } return function; } return null; } private  FunctionRegistry(); static Function getFunction(String name); static void putFunction(Function function); static void putFunction(String name, Function function); static void putFunction(String name, Class<? extends Function> functionClazz); static void removeFunction(String name);  }