/** * Create a new context * * @param contextBean * the context bean (=root of the xpath expression) */ JXPathContextImpl(Object contextBean) { this.context = JXPathContext.newContext(contextBean); this.context.setFunctions(new ClassFunctions(EMFFunctions.class, "ecore")); }
/** * Create a new context * * @param contextBean * the context bean (=root of the xpath expression) */ JXPathContextImpl(Object contextBean) { this.context = JXPathContext.newContext(contextBean); this.context.setFunctions(new ClassFunctions(EMFFunctions.class, "ecore")); }
public void addConverterFunction(IFunction function) { this.converterLibrary .addFunctions(new ClassFunctions(function.getFunctionClass(), function.getNamespace())); }
/** * Register all extension functions listed in the configuration * through <code><function name="fully.qualified.Class" * prefix="prefix"/></code> in the given FunctionLibrary. * * @param conf a <code>Configuration</code> value */ private void getFunctions(Configuration conf) { Configuration[] children = conf.getChildren("function"); int i = children.length; while (i-- > 0) { String clazzName = children[i].getAttribute("name", null); String prefix = children[i].getAttribute("prefix", null); if (clazzName != null && prefix != null) { try { Class clazz = Class.forName(clazzName); this.library.addFunctions(new ClassFunctions(clazz, prefix)); } catch (ClassNotFoundException cnf) { // ignore } } } }
/** 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); }