List of usage examples for org.apache.commons.jxpath JXPathContext getFunctions
public Functions getFunctions()
From source file:org.chiba.xml.xforms.action.SetValueAction.java
/** * Performs the <code>setvalue</code> action. * * @return <code>true</code> if setvalue executed successfully, otherwise * <code>false</code>.// ww w . j a va 2s.c om * @throws XFormsException if an error occurred during <code>setvalue</code> * processing. */ public boolean perform() throws XFormsException { // get location path and instance id String locationPath = getLocationPath(); String instanceId = getInstanceId(locationPath); // get instance Instance instance = getModel().getInstance(instanceId); if (instance.existsNode(locationPath)) { if (this.valueAttribute != null) { // evaluate value expression JXPathContext context = instance.getInstanceContext(); Pointer instancePointer = context.getPointer(locationPath); JXPathContext valueContext = context.getRelativeContext(instancePointer); valueContext.setFunctions(context.getFunctions()); Object value = valueContext.getValue(this.valueAttribute); String newValue = value != null ? value.toString() : "null"; if (getLogger().isDebugEnabled()) { getLogger().debug(this + " perform: setting evaluated value '" + newValue + "'"); } // set node value instance.setNodeValue(locationPath, newValue); } else { if (getLogger().isDebugEnabled()) { getLogger().debug(this + " perform: setting literal value '" + this.nodeValue + "'"); } // set node value instance.setNodeValue(locationPath, this.nodeValue); } // update behaviour setDeferredRecalculate(this.model.getId(), true); setDeferredRevalidate(this.model.getId(), true); setDeferredRefresh(this.model.getId(), true); // indicate success return true; } // todo: error handling ? getLogger().warn(this + " perform: nodeset " + getLocationPath() + " does not exist"); // indicate failure return false; }
From source file:org.chiba.xml.xforms.constraints.MainDependencyGraph.java
/** * builds the dependency graph for a single Bind. Processes all instancenodes that are associated with * the bind and creates one Vertex-object for every Modelitem Property found. That means that if there are * two instancenodes in the evaluated nodeset, two Vertices for every property (readonly, required, relevant, * constraint, calculate) will be created. * <p/>/* ww w. j a v a2 s . c om*/ * Note: only dynamic Modelitem Properties will be processed. */ public void buildBindGraph(Bind bind, Model model) { Instance instance; String locationPath = bind.getLocationPath(); instance = model.getInstance(PathUtil.getInstanceId(model, locationPath)); if (instance == null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("ignoring " + bind); } // no instance - no dependencies ;-) return; } JXPathContext instanceContext = instance.getInstanceContext(); Iterator iterator = instance.getPointerIterator(locationPath); if (LOGGER.isDebugEnabled()) { LOGGER.debug("processing " + bind + " nodeset='" + bind.getBindingExpression() + "'"); LOGGER.debug("locationPath=" + locationPath); } while (iterator.hasNext()) { Pointer instancePointer = (Pointer) iterator.next(); JXPathContext relativeContext = instanceContext.getRelativeContext(instancePointer); relativeContext.setFunctions(instanceContext.getFunctions()); String s = instancePointer.asPath(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("processing path:" + s); } ModelItem modelItem = instance.getModelItem(s); NodeImpl node = (NodeImpl) modelItem.getNode(); if (bind.hasCalculate()) { modelItem.setCalculate(bind.getCalculate()); this.addReferredNodesToGraph(relativeContext, node, bind.getCalculate(), Vertex.CALCULATE_VERTEX); } if (bind.hasRelevant()) { modelItem.setRelevant(bind.getRelevant()); this.addReferredNodesToGraph(relativeContext, node, bind.getRelevant(), Vertex.RELEVANT_VERTEX); } if (bind.hasReadonly()) { modelItem.setReadonly(bind.getReadonly()); this.addReferredNodesToGraph(relativeContext, node, bind.getReadonly(), Vertex.READONLY_VERTEX); } if (bind.hasRequired()) { modelItem.setRequired(bind.getRequired()); this.addReferredNodesToGraph(relativeContext, node, bind.getRequired(), Vertex.REQUIRED_VERTEX); } if (bind.hasConstraint()) { modelItem.setConstraint(bind.getConstraint()); this.addReferredNodesToGraph(relativeContext, node, bind.getConstraint(), Vertex.CONSTRAINT_VERTEX); } if (bind.hasDatatype()) { modelItem.setDatatype(bind.getDatatype()); } if (bind.hasP3PType()) { modelItem.setP3PType(bind.getP3PType()); } } }
From source file:org.openvpms.component.system.common.jxpath.JXPathHelper.java
/** * Create a new context for the specified object that has access to the supplied functions. * * @param object the context bean/*from w w w . j a v a 2 s . co m*/ * @param functions the functions * @return JXPathContext the context object */ public static JXPathContext newContext(Object object, Functions functions) { JXPathContext context = JXPathContext.newContext(object); FunctionLibrary lib = new FunctionLibrary(); lib.addFunctions(context.getFunctions()); lib.addFunctions(functions); context.setFunctions(lib); context.setLenient(true); return context; }
From source file:org.paxml.core.Context.java
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 {//from ww w . j a va2 s. com 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); }
From source file:org.xchain.framework.jxpath.ScopedJXPathContextImpl.java
private Functions createFunctions(JXPathContext parent) { if (parent == null && Lifecycle.getLifecycleContext() != null) { FunctionLibrary library = new NamespaceResolvingFunctionLibrary(namespaceResolver); library.addFunctions(Lifecycle.getLifecycleContext().getFunctionLibrary()); return library; } else if (parent != null) { return parent.getFunctions(); } else {/*from w w w. j av a 2s . c o m*/ return getFunctions(); } }