use of org.jaxen.ContextSupport 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);
}
}
Aggregations