/** * 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")); }
/** * Actually add global functions and packages as well as those * listed in the configuration object. * * @param setup The JXPathHelperConfiguration. * @param context a <code>JXPathContext</code> value. * @param conf a <code>Configuration</code> value holding local. * packages and functions. */ private static void setup(JXPathHelperConfiguration setup, JXPathContext context, Configuration conf) throws ConfigurationException { // Create local config (if necessary) JXPathHelperConfiguration local = conf == null ? setup : new JXPathHelperConfiguration(setup, conf); // Setup context with local config context.setLenient(setup.isLenient()); context.setFunctions(local.getLibrary()); if (local.getNamespaces() != null) { for (Iterator i = local.getNamespaces().entrySet().iterator(); i.hasNext();) { final Map.Entry entry = (Map.Entry) i.next(); context.registerNamespace((String) entry.getKey(), (String) entry.getValue()); } } }
public JXPathContext newContext(Object ctxObject) { JXPathContext context = JXPathContext.newContext(ctxObject); TypeUtils.setTypeConverter(new MyTypeConverter()); context.setFunctions(functionLibrary.getConverterFunctions()); context.setLenient(this.lenient); return context; }
/** 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); }