private CustomFunctionsLibrary() { this.converterLibrary = new FunctionLibrary(); }
@Override public FunctionLibrary getScriptFunctions(IScriptEvalProvider factory) { FunctionLibrary library = new FunctionLibrary(); for (String propertyKey : this.properties.keySet()) { FunctionblockModel fbm = this.properties.get(propertyKey); if (fbm.getStereotype("functions").isPresent()) { Stereotype functionsStereoType = fbm.getStereotype("functions").get(); IScriptEvaluator evaluator = factory.createEvaluator(propertyKey.toLowerCase()); functionsStereoType.getAttributes().keySet().stream() .filter(functionName -> !functionName.equalsIgnoreCase("_namespace")).forEach( functionName -> evaluator.addScriptFunction(new ScriptClassFunction(functionName, functionsStereoType.getAttributes().get(functionName)))); library.addFunctions(evaluator.getFunctions()); } } return library; } }
/** * Create child jxpath configuration */ public JXPathHelperConfiguration(JXPathHelperConfiguration global, Configuration config) throws ConfigurationException { this.lenient = global.lenient; this.library = new FunctionLibrary(); this.library.addFunctions(global.getLibrary()); if (global.getNamespaces() != null) { this.namespaces = new HashMap(global.getNamespaces()); } setup(config); }
/** * Create root jxpath configuration */ public JXPathHelperConfiguration(Configuration config) throws ConfigurationException { this.lenient = config.getChild("lenient").getValueAsBoolean(true); this.library = new FunctionLibrary(); setup(config); // the following is necessary to be able to use methods on objects without // explicitely registering extension functions (see PackageFunctions javadoc) this.library.addFunctions(new PackageFunctions("", null)); }
/** access the jxpath context object for this object (lazily initialized) * @modified NWW - renamed, to avoid using 'get*' naming convention - otherwise * is accessed when traversing the tree, which leads to recursion and out of memory errors.*/ public final synchronized JXPathContext accessJXPathContext() { if (cxt == null) { this.cxt = JXPathContext.newContext(this); this.cxt.setLenient(true); FunctionLibrary lib = new FunctionLibrary(); this.cxt.setFunctions(lib); lib.addFunctions(new ClassFunctions(BaseBean.Fns.class,"fn")); } return cxt; } /** add a new funciton library to the xpath interpreter */
private void setXpathFunctions(JXPathContext xpathContext) { Functions existing = xpathContext.getFunctions(); final FunctionLibrary funcLib; if (existing == null) { funcLib = new FunctionLibrary(); } else if (existing instanceof FunctionLibrary) { funcLib = (FunctionLibrary) existing; } else { funcLib = new FunctionLibrary(); funcLib.addFunctions(existing); } for (ITagLibrary lib : getPaxml().getParser().getTagLibraries()) { for (String name : lib.getUtilFunctionsFactoryNames()) { Class<? extends IUtilFunctionsFactory> clazz = lib.getUtilFunctionsFactory(name); Class<?> xpathFunClass = ReflectUtils.createObject(clazz).getXpathUtilFunctions(this); if (xpathFunClass == null) { // skip this one continue; } Util util = ReflectUtils.getAnnotation(clazz, Util.class); if (util == null) { throw new PaxmlRuntimeException("Internal error: util function factory is not annotated: " + clazz.getName()); } funcLib.addFunctions(new ClassFunctions(xpathFunClass, util.value())); } } xpathContext.setFunctions(funcLib); }
private void setXpathFunctions(JXPathContext xpathContext) { Functions existing = xpathContext.getFunctions(); final FunctionLibrary funcLib; if (existing == null) { funcLib = new FunctionLibrary(); } else if (existing instanceof FunctionLibrary) { funcLib = (FunctionLibrary) existing; } else { funcLib = new FunctionLibrary(); funcLib.addFunctions(existing); } for (ITagLibrary lib : getPaxml().getParser().getTagLibraries()) { for (String name : lib.getUtilFunctionsFactoryNames()) { Class<? extends IUtilFunctionsFactory> clazz = lib.getUtilFunctionsFactory(name); Class<?> xpathFunClass = ReflectUtils.createObject(clazz).getXpathUtilFunctions(this); if (xpathFunClass == null) { // skip this one continue; } Util util = ReflectUtils.getAnnotation(clazz, Util.class); if (util == null) { throw new PaxmlRuntimeException("Internal error: util function factory is not annotated: " + clazz.getName()); } funcLib.addFunctions(new ClassFunctions(xpathFunClass, util.value())); } } xpathContext.setFunctions(funcLib); }