Example usage for org.apache.commons.jxpath JXPathContext setValue

List of usage examples for org.apache.commons.jxpath JXPathContext setValue

Introduction

In this page you can find the example usage for org.apache.commons.jxpath JXPathContext setValue.

Prototype

public abstract void setValue(String xpath, Object value);

Source Link

Document

Modifies the value of the property described by the supplied xpath.

Usage

From source file:org.mule.module.xml.filters.JXPathFilter.java

/**
 * Initializes the JXPathContext based on any relevant properties set for the
 * filter./*  www .  jav a2 s . co  m*/
 *
 * @param context the JXPathContext to initialize
 */
protected void initialise(JXPathContext context) {
    if (namespaces != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Initializing JXPathContext with namespaces: " + namespaces);
        }

        for (Map.Entry<String, String> entry : namespaces.entrySet()) {
            context.registerNamespace(entry.getKey(), entry.getValue());
        }
    }

    Map.Entry entry;
    if (contextProperties != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Initializing JXPathContext with properties: " + contextProperties);
        }

        for (Iterator iterator = contextProperties.entrySet().iterator(); iterator.hasNext();) {
            entry = (Map.Entry) iterator.next();
            context.setValue(entry.getKey().toString(), entry.getValue());
        }
    }

    if (factory != null) {
        context.setFactory(factory);
    }

    context.setLenient(lenient);
}

From source file:org.onecmdb.core.utils.xpath.commands.CreateCommand.java

@Override
public void transfer(OutputStream out) {
    this.context.put("create", true);

    JXPathContext xPathContext = getXPathContext();
    xPathContext.setLenient(true);/*ww w .j a v  a 2  s.c om*/
    Object o = xPathContext.getValue(getPath());
    if (o != null) {
        throw new IllegalArgumentException("Path '" + getPath() + "' exists.");
    }
    setupTX();

    Pointer p = xPathContext.createPath(getPath());

    JXPathContext relContext = getRelativeContext(p);

    for (String outputAttribute : getInputAttributeNameAsArray()) {

        /*
        Iterator<Pointer> outputAttrPointersIter = context.iteratePointers(outputAttribute);
        while(outputAttrPointersIter.hasNext()) {
           Pointer vPointer = outputAttrPointersIter.next();
           Object values = getValues(outputAttribute);
           //NodePointer nP = (NodePointer)vPointer;
           //nP.getImmediateValuePointer().setValue(values);
           vPointer.setValue(values);
        }
        */
        Object values = getValues(outputAttribute);
        relContext.setValue(outputAttribute, values);
    }

    processTX();
}

From source file:org.onecmdb.core.utils.xpath.commands.UpdateCommand.java

/**
 * Transfer the content to the stream./*from  www .  j a  va  2s  . c o  m*/
 * Execute the update.
 * 
 * @param out
 */
public void transfer(OutputStream out) {

    String[] inputAttributes = getInputAttributeNameAsArray();

    setupTX();

    Iterator<Pointer> iter = getPathPointers();

    // Check that we have found the root object.
    if (!iter.hasNext()) {
        throw new IllegalArgumentException("No object matching path " + getPath() + " found!");
    }

    while (iter.hasNext()) {
        Pointer p = (Pointer) iter.next();

        JXPathContext context = getRelativeContext(p);

        for (String outputAttribute : inputAttributes) {

            /*
            Iterator<Pointer> outputAttrPointersIter = context.iteratePointers(outputAttribute);
            while(outputAttrPointersIter.hasNext()) {
               Pointer vPointer = outputAttrPointersIter.next();
               Object values = getValues(outputAttribute);
               //NodePointer nP = (NodePointer)vPointer;
               //nP.getImmediateValuePointer().setValue(values);
               vPointer.setValue(values);
            }
            */
            Object values = getValues(outputAttribute);
            if (values == null) {
                String valueExpr = attributeMap.get(outputAttribute);
                throw new IllegalArgumentException("No value matching expr " + valueExpr + " found!");
            }
            context.setValue(outputAttribute, values);
        }
    }

    // Process the TX.
    processTX();

}

From source file:org.openvpms.component.system.service.jxpath.JXPathTestCase.java

/**
 * Test the set value on a PropertyMap/*from   www.  j a va 2  s . c  o  m*/
 */
@Test
public void testSetValueOnPropertyMap() {
    PropertyMap map = new PropertyMap();
    map.setName("archetypes");

    AssertionProperty prop = new AssertionProperty();
    prop.setName("shortName");
    prop.setType("java.lang.String");
    map.addProperty(prop);

    JXPathContext context = JXPathHelper.newContext(map);
    context.setValue("/properties/shortName/value", "descripor.archetypeRange");
    assertTrue(prop.getValue().equals("descripor.archetypeRange"));
}

From source file:org.xchain.namespaces.core.FilterTestCommand.java

public boolean postProcess(JXPathContext context, Exception exception) {
    context.setValue("$" + TestFilter.RESULT_VARIABLE, TestFilter.RESULT_VALUE);
    return false;
}

From source file:org.xchain.namespaces.hibernate.AbstractQueryResultCommand.java

protected void storeValue(JXPathContext context, Object value) throws Exception {
    if (hasResult()) {
        // TODO This should check that the path exists first.  If it doesn't exist, create it.
        context.setValue(getResult(context), value);
    } else if (hasVariable()) {
        ((ScopedQNameVariables) context.getVariables()).declareVariable(getVariable(context), value,
                getScope(context));/*from w  w w  .ja v  a2  s.c om*/
    } else {
        throw new Exception("Result or Variable must be given.");
    }
}

From source file:org.xchain.namespaces.hibernate.test.command.TestIterateCompare.java

public boolean execute(JXPathContext context) throws Exception {
    Iterator<Person> sourceIterator = getSource(context);
    Iterator<Person> testIterator = getText(context);

    boolean equal = true;

    while (sourceIterator.hasNext() && testIterator.hasNext() && equal) {
        equal = sourceIterator.next().getName().equalsIgnoreCase(testIterator.next().getName());
    }/*w  ww . j  ava2s. com*/

    context.setValue(getResult(context), equal);

    // Allow execution to continue.
    return false;
}

From source file:org.xchain.namespaces.hibernate.test.command.TestIterateEmpty.java

public boolean execute(JXPathContext context) throws Exception {
    Iterator<Person> sourceIterator = getSource(context);

    context.setValue(getResult(context), !sourceIterator.hasNext());

    // Allow execution to continue.
    return false;
}

From source file:org.xsystem.bpm2machineservice.impl.execution.AssociationsResolver.java

public void resolve(List<DataAssociation> associations) {
    JXPathContext fromdata = scriptingService.makeJXPathContext(fromCtx);

    JXPathContext todata = scriptingService.makeJXPathContext(toCtx);

    associations.stream().flatMap(association -> association.getAssignment().stream()).forEach(assignment -> {
        FormalExpression fromExp = (FormalExpression) assignment.getFrom();
        String from = fromExp.getBody();
        Object fromValue = fromdata.getValue(from);

        FormalExpression toExp = (FormalExpression) assignment.getTo();
        String to = toExp.getBody();

        todata.setValue(to, fromValue);
    });/*from w ww  . jav  a2  s.c  o  m*/

}