synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Veithen <andreas.veit...@skynet.be>
Subject Re: svn commit: r644758 - in /synapse/trunk/java/modules/core/src: main/java/org/apache/synapse/config/xml/ main/java/org/apache/synapse/mediators/ main/java/org/apache/synapse/mediators/builtin/ main/java/org/apache/synapse/mediators/db/ main/java/o
Date Tue, 08 Apr 2008 23:04:01 GMT
Ruwan,

Since the variable and function contexts to use depend on the object  
on which the expression is evaluated, the desired behavior can't be  
achieved by overriding create(Variable|Function)Context. Inside the  
getContext method we have the possibility to substitute these contexts  
depending on the object type. Since this doesn't alter the state of  
the SynapseXPath object, it is automatically thread safe. Also this  
approach makes sure that the behavior of SynapseXPath is compatible  
with AXIOMXPath (justifying inheritance) and simplifies the code a lot.

I committed the change and ran the test cases (I improved  
SynapseXPathTest a bit to cover more methods). Since it is quite a  
drastic change, don't hesitate to roll it back if there are any  
problems. We can clean up (e.g. remove the  
ThreadSafeDelegating*Context classes) later.

Regards,

Andreas


On 08 Apr 2008, at 01:23, Ruwan Linton wrote:

> I too had a look at the code of BaseXPath ....
>
> I think we just need to over right the create createVariableContext  
> and the createFunctionContext methods, but not the getContext. Also  
> I think we will need to extend AXIOMXPath but not BaseXPath.
>
> WDYT?
>
> Thanks,
> Ruwan
>
> On Tue, Apr 8, 2008 at 4:44 AM, Ruwan Linton  
> <ruwan.linton@gmail.com> wrote:
> Yeah... Please go ahead Andreas.
>
> Thanks,
> Ruwan
>
> On Tue, Apr 8, 2008 at 4:30 AM, Andreas Veithen <andreas.veithen@skynet.be 
> > wrote:
> Ruwan,
>
> I had a closer look at the Jaxen code and I found out that what we  
> are trying to do can probably be achieved in a much simpler way by  
> extending BaseXPath (or AXIOMXPath) and overriding the  
> BaseXPath#getContext(Object) method. If this works as I expect, it  
> would guarantee that SynapseXPath preserves the BaseXPath/AXOMXPath  
> behavior while making the code a lot simpler. In particular there  
> would be no need for the ThreadLocal pattern (i.e. the  
> ThreadSafeDelegatingXxxContext classes) any more. Do you want me to  
> give it a try?
>
> Andreas
>
>
>
> On 04 Apr 2008, at 18:24, ruwan@apache.org wrote:
> Author: ruwan
> Date: Fri Apr  4 09:24:12 2008
> New Revision: 644758
>
> URL: http://svn.apache.org/viewvc?rev=644758&view=rev
> Log:
> Earlier SynapseXPath was extended from the AXIOMXPath, and this lead  
> to some problems hence we are using a custom Variable and Function  
> contexts and delegate the resolver action. As proposed by andreas,  
> removing the inheritance and used composition instead to overcome  
> the issues. So now, SynapseXPath is *not* an AXIOMXPath rather  
> SynapseXPath contains an AXIOMXPath.
>
> Modified:
>   synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> config/xml/OMElementUtils.java
>   synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/MediatorProperty.java
>   synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/builtin/PropertyMediator.java
>   synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/builtin/RMSequenceMediator.java
>   synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/db/AbstractDBMediator.java
>   synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/ext/AnnotatedCommandMediator.java
>   synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/ext/POJOCommandMediator.java
>   synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/filters/FilterMediator.java
>   synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/filters/SwitchMediator.java
>   synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/transform/FaultMediator.java
>   synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/transform/HeaderMediator.java
>   synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> util/xpath/SynapseXPath.java
>   synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> util/xpath/ThreadSafeDelegatingVariableContext.java
>   synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/ 
> core/axis2/Axis2MessageContextTest.java
>   synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/ 
> mediators/builtin/PropertyMediatorTest.java
>   synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/ 
> util/SynapseXPathTest.java
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/config/xml/OMElementUtils.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/OMElementUtils.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> config/xml/OMElementUtils.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> config/xml/OMElementUtils.java Fri Apr  4 09:24:12 2008
> @@ -27,6 +27,7 @@
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.apache.synapse.SynapseException;
> +import org.apache.synapse.util.xpath.SynapseXPath;
> import org.jaxen.JaxenException;
>
> import java.util.Iterator;
> @@ -88,6 +89,41 @@
>
>                    try {
>                        xpath.addNamespace(n.getPrefix(),  
> n.getNamespaceURI());
> +                    } catch (JaxenException je) {
> +                        String msg = "Error adding declared name  
> space with prefix : "
> +                            + n.getPrefix() + "and uri : " +  
> n.getNamespaceURI()
> +                            + " to the XPath : " + xpath;
> +                        log.error(msg);
> +                        throw new SynapseException(msg, je);
> +                    }
> +                }
> +            }
> +
> +            OMContainer parent = currentElem.getParent();
> +            //if the parent is a document element or parent is  
> null ,then return
> +            if (parent == null || parent instanceof OMDocument) {
> +                return;
> +            }
> +            if (parent instanceof OMElement) {
> +                currentElem = (OMElement) parent;
> +            }
> +        }
> +    }
> +
> +    public static void addNameSpaces(SynapseXPath xpath, OMElement  
> elem, Log log) {
> +
> +        OMElement currentElem = elem;
> +
> +        while (currentElem != null) {
> +            Iterator it = currentElem.getAllDeclaredNamespaces();
> +            while (it.hasNext()) {
> +
> +                OMNamespace n = (OMNamespace) it.next();
> +                // assume the behavior of attributes as unqualified  
> from default
> +                if (n != null && !"".equals(n.getPrefix())) {
> +
> +                    try {
> +                        xpath.addNamespace(n);
>                    } catch (JaxenException je) {
>                        String msg = "Error adding declared name  
> space with prefix : "
>                            + n.getPrefix() + "and uri : " +  
> n.getNamespaceURI()
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/mediators/MediatorProperty.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/MediatorProperty.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/MediatorProperty.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/MediatorProperty.java Fri Apr  4 09:24:12 2008
> @@ -68,7 +68,7 @@
>    }
>
>    public String getEvaluatedExpression(MessageContext synCtx) {
> -        return expression.getStringValue(synCtx);
> +        return expression.stringValueOf(synCtx);
>    }
>
> }
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/mediators/builtin/PropertyMediator.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/builtin/PropertyMediator.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/builtin/PropertyMediator.java Fri Apr  4 09:24:12 2008
> @@ -75,7 +75,7 @@
>
>        if (action == ACTION_SET) {
>
> -            String resultValue = (value != null ? value :  
> expression.getStringValue(synCtx));
> +            String resultValue = (value != null ? value :  
> expression.stringValueOf(synCtx));
>
>            if (traceOrDebugOn) {
>                traceOrDebug(traceOn, "Setting property : " + name +  
> " at scope : " +
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/mediators/builtin/RMSequenceMediator.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RMSequenceMediator.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/builtin/RMSequenceMediator.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/builtin/RMSequenceMediator.java Fri Apr  4 09:24:12 2008
> @@ -154,7 +154,7 @@
>    private String getCorrelationValue(MessageContext smc) {
>        OMElement node = null;
>        try {
> -            node = (OMElement)  
> getCorrelation().selectSingleNode(smc.getEnvelope());
> +            node = (OMElement)  
> getCorrelation().selectSingleNode(smc);
>
>            if (node != null) {
>                return node.getText();
> @@ -183,7 +183,7 @@
>            return false;
>        } else {
>            try {
> -                return  
> getLastMessage().booleanValueOf(smc.getEnvelope());
> +                return getLastMessage().booleanValueOf(smc);
>            } catch (JaxenException e) {
>                handleException("Error evaluating XPath expression to  
> determine if last message : " +
>                    getLastMessage(), e, smc);
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/mediators/db/AbstractDBMediator.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/AbstractDBMediator.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/db/AbstractDBMediator.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/db/AbstractDBMediator.java Fri Apr  4 09:24:12 2008
> @@ -175,7 +175,7 @@
>
>            Statement.Parameter param = (Statement.Parameter)  
> pi.next();
>            String value = (param.getPropertyName() != null ?
> -                param.getPropertyName() :  
> param.getXpath().getStringValue(msgCtx));
> +                param.getPropertyName() :  
> param.getXpath().stringValueOf(msgCtx));
>
>            if (traceOrDebugOn) {
>                traceOrDebug(traceOn, "Setting as parameter : " +  
> column + " value : " + value +
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/mediators/ext/AnnotatedCommandMediator.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/AnnotatedCommandMediator.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/ext/AnnotatedCommandMediator.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/ext/AnnotatedCommandMediator.java Fri Apr  4 09:24:12 2008
> @@ -84,7 +84,7 @@
>            SynapseXPath xpath = beforeFields.get(f);
>            Object v;
>            if (f.getType().equals(String.class)) {
> -                v = xpath.getStringValue(synCtx);
> +                v = xpath.stringValueOf(synCtx);
>            } else {
>                throw new UnsupportedOperationException("non-String  
> types not supportted yet");
>            }
> @@ -99,7 +99,7 @@
>            SynapseXPath xpath = beforeMethods.get(m);
>            Object v;
>            if (m.getParameterTypes().length == 1 &&  
> m.getParameterTypes()[0].equals(String.class)) {
> -                v = xpath.getStringValue(synCtx);
> +                v = xpath.stringValueOf(synCtx);
>            } else {
>                throw new UnsupportedOperationException("non-String  
> types not supportted yet");
>            }
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/mediators/ext/POJOCommandMediator.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/ext/POJOCommandMediator.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/ext/POJOCommandMediator.java Fri Apr  4 09:24:12 2008
> @@ -137,7 +137,7 @@
>
>            String name = (String) iter.next();
>            SynapseXPath xpath = messageSetterProperties.get(name);
> -            String value = xpath.getStringValue(synCtx);
> +            String value = xpath.stringValueOf(synCtx);
>
>            setInstanceProperty(name, value, commandObject, synCtx);
>        }
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/mediators/filters/FilterMediator.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/FilterMediator.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/filters/FilterMediator.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/filters/FilterMediator.java Fri Apr  4 09:24:12 2008
> @@ -159,13 +159,13 @@
>
>        if (xpath != null) {
>            try {
> -                return xpath.booleanValueOf(synCtx.getEnvelope());
> +                return xpath.booleanValueOf(synCtx);
>            } catch (JaxenException e) {
>                handleException("Error evaluating XPath expression :  
> " + xpath, e, synCtx);
>            }
>
>        } else if (source != null && regex != null) {
> -            String sourceString = source.getStringValue(synCtx);
> +            String sourceString = source.stringValueOf(synCtx);
>            if (sourceString == null) {
>                if (traceOrDebugOn) {
>                    traceOrDebug(traceOn, "Source String : " + source  
> + " evaluates to null");
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/mediators/filters/SwitchMediator.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/filters/SwitchMediator.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/filters/SwitchMediator.java Fri Apr  4 09:24:12 2008
> @@ -68,7 +68,7 @@
>        setEffectiveTraceState(synCtx);
>        int myEffectiveTraceState = synCtx.getTracingState();
>
> -        String sourceText = source.getStringValue(synCtx);
> +        String sourceText = source.stringValueOf(synCtx);
>        if (traceOrDebugOn) {
>            traceOrDebug(traceOn, "XPath : " + source + " evaluates  
> to : " + sourceText);
>        }
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/mediators/transform/FaultMediator.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/transform/FaultMediator.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/transform/FaultMediator.java Fri Apr  4 09:24:12 2008
> @@ -146,7 +146,7 @@
>
>        } else if (faultDetailExpr != null) {
>
> -            String faultDetail =  
> faultDetailExpr.getStringValue(synCtx);
> +            String faultDetail =  
> faultDetailExpr.stringValueOf(synCtx);
>
>            if (traceOrDebugOn) {
>                traceOrDebug(traceOn, "Setting the fault detail : "
> @@ -166,7 +166,7 @@
>
>        } else if (faultReasonExpr != null) {
>
> -            String faultReason =  
> faultReasonExpr.getStringValue(synCtx);
> +            String faultReason =  
> faultReasonExpr.stringValueOf(synCtx);
>            faultPayload.setText(faultReason);
>
>            if (traceOrDebugOn) {
> @@ -304,7 +304,7 @@
>        } else if (faultCodeValue != null) {
>            fault_code = faultCodeValue;
>        } else {
> -            fault_code =  
> QName.valueOf(faultCodeExpr.getStringValue(synCtx));
> +            fault_code =  
> QName.valueOf(faultCodeExpr.stringValueOf(synCtx));
>        }
>
>        SOAPFaultCode code = factory.createSOAPFaultCode();
> @@ -328,7 +328,7 @@
>        } else if (faultReasonValue != null) {
>            reasonString = faultReasonValue;
>        } else {
> -            reasonString = faultReasonExpr.getStringValue(synCtx);
> +            reasonString = faultReasonExpr.stringValueOf(synCtx);
>        }
>
>        SOAPFaultReason reason = factory.createSOAPFaultReason();
> @@ -368,7 +368,7 @@
>            fault.setDetail(soapFaultDetail);
>        } else if (faultDetailExpr != null) {
>            SOAPFaultDetail soapFaultDetail =  
> factory.createSOAPFaultDetail();
> -             
> soapFaultDetail.setText(faultDetailExpr.getStringValue(synCtx));
> +             
> soapFaultDetail.setText(faultDetailExpr.stringValueOf(synCtx));
>            fault.setDetail(soapFaultDetail);
>        } else if (fault.getDetail() != null) {
>            // work around for a rampart issue in the following thread
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/mediators/transform/HeaderMediator.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/HeaderMediator.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/transform/HeaderMediator.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> mediators/transform/HeaderMediator.java Fri Apr  4 09:24:12 2008
> @@ -78,7 +78,7 @@
>        if (action == ACTION_SET) {
>
>            String value = (getExpression() == null ? getValue() :
> -                expression.getStringValue(synCtx));
> +                    expression.stringValueOf(synCtx));
>
>            if (traceOrDebugOn) {
>                traceOrDebug(traceOn, "Set SOAP header : " + qName +  
> " to : " + value);
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/util/xpath/SynapseXPath.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPath.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> util/xpath/SynapseXPath.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> util/xpath/SynapseXPath.java Fri Apr  4 09:24:12 2008
> @@ -19,6 +19,7 @@
>
> package org.apache.synapse.util.xpath;
>
> +import org.apache.axiom.om.OMNamespace;
> import org.apache.axiom.om.impl.llom.OMDocumentImpl;
> import org.apache.axiom.om.impl.llom.OMElementImpl;
> import org.apache.axiom.om.impl.llom.OMTextImpl;
> @@ -31,6 +32,7 @@
> import org.jaxen.*;
>
> import java.util.List;
> +import java.util.Map;
>
> /**
>  * <p>XPath that has been used inside Synapse xpath processing. This  
> has a extension function named
> @@ -71,10 +73,12 @@
>  * @see org.apache.synapse.util.xpath.SynapseXPathFunctionContext
>  * @see org.apache.synapse.util.xpath.SynapseXPathVariableContext
>  */
> -public class SynapseXPath extends AXIOMXPath {
> +public class SynapseXPath implements XPath {
>
>    private static final Log log =  
> LogFactory.getLog(SynapseXPath.class);
>
> +    private AXIOMXPath xpath;
> +
>    /**
>     * <p>Initializes the <code>SynapseXPath</code> with the given 

> <code>xpathString</code> as the
>     * XPath</p>
> @@ -83,84 +87,105 @@
>     * @throws JaxenException in case of an initialization failure
>     */
>    public SynapseXPath(String xpathString) throws JaxenException {
> -        super(xpathString);
> -        setVariableContext(new  
> ThreadSafeDelegatingVariableContext());
> -        setFunctionContext(new  
> ThreadSafeDelegatingFunctionContext());
> +        xpath = new AXIOMXPath(xpathString);
> +        xpath.setVariableContext(new  
> ThreadSafeDelegatingVariableContext());
> +        xpath.setFunctionContext(new  
> ThreadSafeDelegatingFunctionContext());
>    }
>
>    /**
> -     * <p>Evaluates the XPath over the specified MessageContext.  
> This overides the evaluate method
> -     * of the <code>BaseXPath</code> and provides a better acceess  
> to the message context
> -     * properties and transport information</p>
> +     * <p>Evaluates the XPath over the specified SOAPEnvelope. This  
> overides the evaluate method
> +     * of the <code>BaseXPath</code> and provides a better acceess  
> to the envelope using the XPath
> +     * variables for <code>SOAPBody</code> and <code>SOAPHeader</

> code>.</p>
>     *
> -     * @param synCtx context to be evaluated for the XPath
> -     * @return evaluated value of the xpath over the given message  
> context
> +     * @param o object to be evaluated to get the result  
> (MessageContext | SOAPEnvelope | OMElement)
> +     * @return evaluated value of the xpath over the given message
>     * @throws JaxenException in case of a failure in evaluation
>     *
>     * @see org.jaxen.BaseXPath#evaluate(Object)
> -     * @see  
> org.apache.synapse.util.xpath.SynapseXPathFunctionContext#getFunction(
> -     * String, String, String)
>     * @see  
> org 
> .apache 
> .synapse.util.xpath.SynapseXPathVariableContext#getVariableValue(
> -     * String, String, String)
> +     * String, String, String)
>     */
> -    public Object evaluate(MessageContext synCtx) throws  
> JaxenException {
> +    public Object evaluate(Object o) throws JaxenException {
> +        setContexts(o);
> +        return xpath.evaluate(getEvaluationObject(o));
> +    }
>
> -        // retrieves the variable context and the function context  
> to restore after
> -        VariableContext varCtx =  
> ((ThreadSafeDelegatingVariableContext)
> -                getVariableContext()).getDelegate();
> -        FunctionContext funCtx =  
> ((ThreadSafeDelegatingFunctionContext)
> -            getFunctionContext()).getDelegate();
> +    /**
> +     * @deprecated
> +     */
> +    public String valueOf(Object o) throws JaxenException {
> +        return xpath.valueOf(o);
> +    }
>
> -        try {
> +    public String stringValueOf(Object o) throws JaxenException {
>
> -            // set the synapse variable and function contexts  
> before evaluation
> -            ((ThreadSafeDelegatingVariableContext)
> -                getVariableContext()).setDelegate(new  
> SynapseXPathVariableContext(synCtx));
> -            ((ThreadSafeDelegatingFunctionContext)
> -                getFunctionContext()).setDelegate(new  
> SynapseXPathFunctionContext(synCtx, true));
> +        if (o instanceof MessageContext) {
> +            return stringValueOf((MessageContext) o);
> +        } else {
> +            setContexts(o);
> +            return xpath.stringValueOf(getEvaluationObject(o));
> +        }
> +    }
>
> -            return super.evaluate(synCtx.getEnvelope());
> +    public boolean booleanValueOf(Object o) throws JaxenException {
> +        setContexts(o);
> +        return xpath.booleanValueOf(getEvaluationObject(o));
> +    }
>
> -        } finally {
> +    public Number numberValueOf(Object o) throws JaxenException {
> +        setContexts(o);
> +        return xpath.numberValueOf(getEvaluationObject(o));
> +    }
>
> -            // restore the variable and function contexts
> -            ((ThreadSafeDelegatingVariableContext)  
> getVariableContext()).setDelegate(varCtx);
> -            ((ThreadSafeDelegatingFunctionContext)  
> getFunctionContext()).setDelegate(funCtx);
> -        }
> +    public List selectNodes(Object o) throws JaxenException {
> +        setContexts(o);
> +        return xpath.selectNodes(getEvaluationObject(o));
>    }
>
> -    /**
> -     * <p>Evaluates the XPath over the specified SOAPEnvelope. This  
> overides the evaluate method
> -     * of the <code>BaseXPath</code> and provides a better acceess  
> to the envelope using the XPath
> -     * variables for <code>SOAPBody</code> and <code>SOAPHeader</

> code>.</p>
> -     *
> -     * @param env message to be evaluated to get the result
> -     * @return evaluated value of the xpath over the given message
> -     * @throws JaxenException in case of a failure in evaluation
> -     *
> -     * @see org.jaxen.BaseXPath#evaluate(Object)
> -     * @see  
> org 
> .apache 
> .synapse.util.xpath.SynapseXPathVariableContext#getVariableValue(
> -     * String, String, String)
> -     */
> -    public Object evaluate(SOAPEnvelope env) throws JaxenException {
> +    public Object selectSingleNode(Object o) throws JaxenException {
>
> -        // retrieves the variable context to restore after
> -        VariableContext varCtx =  
> ((ThreadSafeDelegatingVariableContext)
> -                getVariableContext()).getDelegate();
> +        return xpath.selectSingleNode(o);
> +    }
>
> -        try {
> +    public void addNamespace(String prefix, String nsURI) throws  
> JaxenException {
> +        xpath.addNamespace(prefix, nsURI);
> +    }
>
> -            // set the synapse variable context before evaluation
> -            ((ThreadSafeDelegatingVariableContext)
> -                getVariableContext()).setDelegate(new  
> SynapseXPathVariableContext(env));
> +    public void setNamespaceContext(NamespaceContext  
> namespaceContext) {
> +        xpath.setNamespaceContext(namespaceContext);
> +    }
>
> -            return super.evaluate(env);
> +    public void setFunctionContext(FunctionContext functionContext) {
> +        throw new UnsupportedOperationException("Setting the  
> function context directly is " +
> +                "prohibited, use ((ThreadSafeFunctionContext) " +
> +                "getFunctionContext()).setDelegate() instead");
> +    }
>
> -        } finally {
> +    public void setVariableContext(VariableContext variableContext) {
> +
> +        throw new UnsupportedOperationException("Setting the  
> variable context directly is " +
> +                "prohibited, use ((ThreadSafeVariableContext) " +
> +                "getVariableContext()).setDelegate() instead");
> +    }
>
> -            // restore the variable context
> -            ((ThreadSafeDelegatingVariableContext)  
> getVariableContext()).setDelegate(varCtx);
> -        }
> +    public NamespaceContext getNamespaceContext() {
> +        return xpath.getNamespaceContext();
> +    }
> +
> +    public FunctionContext getFunctionContext() {
> +        return xpath.getFunctionContext();
> +    }
> +
> +    public VariableContext getVariableContext() {
> +        return xpath.getVariableContext();
> +    }
> +
> +    public Navigator getNavigator() {
> +        return xpath.getNavigator();
> +    }
> +
> +    public String toString() {
> +        return xpath.toString();
>    }
>
>    /**
> @@ -170,7 +195,7 @@
>     * @param synCtx the source message which holds the  
> MessageContext against full context
>     * @return a String representation of the result of evaluation
>     */
> -    public String getStringValue(MessageContext synCtx) {
> +    public String stringValueOf(MessageContext synCtx) {
>
>        try {
>
> @@ -222,9 +247,62 @@
>        return null;
>    }
>
> +    public void addNamespace(OMNamespace ns) throws JaxenException {
> +        xpath.addNamespace(ns.getPrefix(), ns.getNamespaceURI());
> +    }
> +
> +    public Map getNamespaces() {
> +        return xpath.getNamespaces();
> +    }
> +
> +    private Object getEvaluationObject(Object obj) {
> +        if (obj instanceof MessageContext) {
> +            return ((MessageContext) obj).getEnvelope();
> +        } else {
> +            return obj;
> +        }
> +    }
> +
> +    private void setContexts(Object obj) {
> +
> +        if (obj instanceof MessageContext) {
> +            setContexts((MessageContext) obj);
> +        } else if (obj instanceof SOAPEnvelope) {
> +            setContexts((SOAPEnvelope) obj);
> +        } else {
> +
> +            ((ThreadSafeDelegatingVariableContext)
> +                    xpath.getVariableContext()).setDelegate(new  
> SimpleVariableContext());
> +
> +            ((ThreadSafeDelegatingFunctionContext)
> +                    xpath.getFunctionContext()).setDelegate(new  
> XPathFunctionContext(true));
> +        }
> +    }
> +
> +    private void setContexts(SOAPEnvelope env) {
> +
> +        ((ThreadSafeDelegatingVariableContext)
> +                xpath.getVariableContext()).setDelegate(
> +                new SynapseXPathVariableContext(env));
> +
> +        ((ThreadSafeDelegatingFunctionContext)
> +                xpath.getFunctionContext()).setDelegate(
> +                new XPathFunctionContext(true));
> +    }
> +
> +    private void setContexts(MessageContext synCtx) {
> +
> +        ((ThreadSafeDelegatingVariableContext)
> +                xpath.getVariableContext()).setDelegate(
> +                new SynapseXPathVariableContext(synCtx));
> +
> +        ((ThreadSafeDelegatingFunctionContext)
> +                xpath.getFunctionContext()).setDelegate(
> +                new SynapseXPathFunctionContext(synCtx, true));
> +    }
> +
>    private void handleException(String msg, Throwable e) {
>        log.error(msg, e);
>        throw new SynapseException(msg, e);
>    }
> -
> }
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/util/xpath/ThreadSafeDelegatingVariableContext.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/ThreadSafeDelegatingVariableContext.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> util/xpath/ThreadSafeDelegatingVariableContext.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> util/xpath/ThreadSafeDelegatingVariableContext.java Fri Apr  4  
> 09:24:12 2008
> @@ -27,7 +27,7 @@
>
>    private final ThreadLocal<VariableContext> delegate = new  
> ThreadLocal<VariableContext>();
>
> -    public void setDelegate() {
> +    public ThreadSafeDelegatingVariableContext() {
>        this.delegate.set(new SimpleVariableContext());
>    }
>
>
> Modified: synapse/trunk/java/modules/core/src/test/java/org/apache/ 
> synapse/core/axis2/Axis2MessageContextTest.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/core/axis2/Axis2MessageContextTest.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/ 
> core/axis2/Axis2MessageContextTest.java (original)
> +++ synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/ 
> core/axis2/Axis2MessageContextTest.java Fri Apr  4 09:24:12 2008
> @@ -38,7 +38,7 @@
>        axiomXpath.addNamespace("ns1", nsNamespace1);
>        MessageContext synCtx = TestUtils.getTestContext(sampleBody);
>
> -        String result = axiomXpath.getStringValue(synCtx);
> +        String result = axiomXpath.stringValueOf(synCtx);
>        assertEquals("second", result);
>    }
>
> @@ -49,7 +49,7 @@
>
>        MessageContext synCtx = TestUtils.getTestContext(sampleBody);
>
> -        String result = axiomXpath.getStringValue(synCtx);
> +        String result = axiomXpath.stringValueOf(synCtx);
>        assertEquals("second", result);
>    }
>
>
> Modified: synapse/trunk/java/modules/core/src/test/java/org/apache/ 
> synapse/mediators/builtin/PropertyMediatorTest.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/PropertyMediatorTest.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/ 
> mediators/builtin/PropertyMediatorTest.java (original)
> +++ synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/ 
> mediators/builtin/PropertyMediatorTest.java Fri Apr  4 09:24:12 2008
> @@ -43,19 +43,19 @@
>        propMediatorTwo.mediate(synCtx);
>        assertTrue(
>            "value".equals((new SynapseXPath(
> -                "synapse:get- 
> property('name')")).getStringValue(synCtx)));
> +                "synapse:get- 
> property('name')")).stringValueOf(synCtx)));
>        assertTrue(
>            "valueTwo".equals((new SynapseXPath(
> -                "synapse:get- 
> property('nameTwo')")).getStringValue(synCtx)));
> +                "synapse:get- 
> property('nameTwo')")).stringValueOf(synCtx)));
>
>        PropertyMediator propMediatorThree = new PropertyMediator();
>        propMediatorThree.setName("name");
>        propMediatorThree.setValue("value");
>        propMediatorThree.setAction(PropertyMediator.ACTION_REMOVE);
>        propMediatorThree.mediate(synCtx) ;
> -        assertNull((new SynapseXPath("synapse:get- 
> property('name')")).getStringValue(synCtx));
> +        assertNull((new SynapseXPath("synapse:get- 
> property('name')")).stringValueOf(synCtx));
>        assertTrue("valueTwo".equals((new SynapseXPath(
> -            "synapse:get- 
> property('nameTwo')")).getStringValue(synCtx)));
> +            "synapse:get- 
> property('nameTwo')")).stringValueOf(synCtx)));
>
>    }
>
>
> Modified: synapse/trunk/java/modules/core/src/test/java/org/apache/ 
> synapse/util/SynapseXPathTest.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/util/SynapseXPathTest.java?rev=644758&r1=644757&r2=644758&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/ 
> util/SynapseXPathTest.java (original)
> +++ synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/ 
> util/SynapseXPathTest.java Fri Apr  4 09:24:12 2008
> @@ -40,13 +40,13 @@
>    public void testAbsoluteXPath() throws Exception {
>        SynapseXPath xpath = new SynapseXPath("//test");
>        MessageContext ctx =  TestUtils.getTestContext("<test>" +  
> message + "</test>");
> -        assertEquals(xpath.getStringValue(ctx), message);
> +        assertEquals(xpath.stringValueOf(ctx), message);
>    }
>
>    public void testBodyRelativeXPath() throws Exception {
>        SynapseXPath xpath = new SynapseXPath("$body/test");
>        MessageContext ctx =  TestUtils.getTestContext("<test>" +  
> message + "</test>");
> -        assertEquals(xpath.getStringValue(ctx), message);
> +        assertEquals(xpath.stringValueOf(ctx), message);
>    }
>
>    public void testHeaderRelativeXPath() throws Exception {
> @@ -57,7 +57,7 @@
>        SOAPHeaderBlock block =  
> ctx.getEnvelope().getHeader().addHeaderBlock("test",
>            fac.createOMNamespace("http://test", "t"));
>        block.setText(message);
> -        assertEquals(xpath.getStringValue(ctx), message);
> +        assertEquals(xpath.stringValueOf(ctx), message);
>    }
>
>    public void testContextProperties() throws Exception {
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> For additional commands, e-mail: dev-help@synapse.apache.org
>
>
>
>
> -- 
> Ruwan Linton
> http://www.wso2.org - "Oxygenating the Web Services Platform"
>
>
>
> -- 
> Ruwan Linton
> http://www.wso2.org - "Oxygenating the Web Services Platform"


Mime
View raw message