Search in sources :

Example 1 with Context

use of org.jaxen.Context in project wso2-synapse by wso2.

the class SynapseXPath method getContext.

/**
 * Create a {@link Context} wrapper for the provided object.
 * This methods implements the following class specific behavior:
 * <dl>
 *   <dt>{@link MessageContext}</dt>
 *   <dd>The XPath expression is evaluated against the SOAP envelope
 *       and the functions and variables defined by
 *       {@link SynapseXPathFunctionContext} and
 *       {@link SynapseXPathVariableContext} are
 *       available.</dd>
 *   <dt>{@link SOAPEnvelope}</dt>
 *   <dd>The variables defined by {@link SynapseXPathVariableContext}
 *       are available.</dd>
 * </dl>
 * For all other object types, the behavior is identical to
 * {@link BaseXPath#getContext(Object)}.
 * <p>
 * Note that the behavior described here also applies to all evaluation
 * methods such as {@link #evaluate(Object)} or {@link #selectSingleNode(Object)},
 * given that these methods all use {@link #getContext(Object)}.
 *
 * @see SynapseXPathFunctionContext#getFunction(String, String, String)
 * @see SynapseXPathVariableContext#getVariableValue(String, String, String)
 */
@Override
protected Context getContext(Object obj) {
    if (obj instanceof MessageContext) {
        MessageContext synCtx = (MessageContext) obj;
        ContextSupport baseContextSupport = getContextSupport();
        ContextSupport contextSupport = new ContextSupport(baseContextSupport.getNamespaceContext(), new SynapseXPathFunctionContext(baseContextSupport.getFunctionContext(), synCtx), new SynapseXPathVariableContext(baseContextSupport.getVariableContext(), synCtx), baseContextSupport.getNavigator());
        Context context = new Context(contextSupport);
        context.setNodeSet(new SingletonList(synCtx.getEnvelope()));
        return context;
    } else if (obj instanceof SOAPEnvelope) {
        SOAPEnvelope env = (SOAPEnvelope) obj;
        ContextSupport baseContextSupport = getContextSupport();
        ContextSupport contextSupport = new ContextSupport(baseContextSupport.getNamespaceContext(), baseContextSupport.getFunctionContext(), new SynapseXPathVariableContext(baseContextSupport.getVariableContext(), env), baseContextSupport.getNavigator());
        Context context = new Context(contextSupport);
        context.setNodeSet(new SingletonList(env));
        return context;
    } else if (obj instanceof ContextWrapper) {
        ContextWrapper wrapper = (ContextWrapper) obj;
        ContextSupport baseContextSupport = getContextSupport();
        ContextSupport contextSupport = new ContextSupport(baseContextSupport.getNamespaceContext(), baseContextSupport.getFunctionContext(), new SynapseXPathVariableContext(baseContextSupport.getVariableContext(), wrapper.getMessageCtxt(), wrapper.getEnvelope()), baseContextSupport.getNavigator());
        Context context = new Context(contextSupport);
        context.setNodeSet(new SingletonList(wrapper.getEnvelope()));
        return context;
    } else {
        return super.getContext(obj);
    }
}
Also used : MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Context(org.jaxen.Context) ContextSupport(org.jaxen.ContextSupport) SingletonList(org.jaxen.util.SingletonList) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 2 with Context

use of org.jaxen.Context in project pmd by pmd.

the class MatchesFunctionTest method tryRegexp.

private Object tryRegexp(MyNode myNode, String exp) throws FunctionCallException, NoSuchMethodException {
    MatchesFunction function = new MatchesFunction();
    List<Object> list = new ArrayList<>();
    List<Attribute> attrs = new ArrayList<>();
    attrs.add(new Attribute(myNode, "matches", myNode.getClass().getMethod("getClassName", new Class[0])));
    list.add(attrs);
    list.add(exp);
    Context c = new Context(null);
    c.setNodeSet(new ArrayList<>());
    return function.call(c, list);
}
Also used : Context(org.jaxen.Context) Attribute(net.sourceforge.pmd.lang.ast.xpath.Attribute) ArrayList(java.util.ArrayList) MatchesFunction(net.sourceforge.pmd.lang.xpath.MatchesFunction)

Aggregations

Context (org.jaxen.Context)2 ArrayList (java.util.ArrayList)1 Attribute (net.sourceforge.pmd.lang.ast.xpath.Attribute)1 MatchesFunction (net.sourceforge.pmd.lang.xpath.MatchesFunction)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 MessageContext (org.apache.synapse.MessageContext)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1 ContextSupport (org.jaxen.ContextSupport)1 SingletonList (org.jaxen.util.SingletonList)1