Author: indika
Date: Mon Feb 16 05:55:50 2009
New Revision: 744814

URL: http://svn.apache.org/viewvc?rev=744814&view=rev
Log:
update XQuery mediator to use SynapseXpath

Modified:
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SourceXPathSupport.java
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPath.java
    
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/MediatorCustomVariable.java
    
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java
    
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediatorFactory.java
    
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediatorSerializer.java

Modified: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SourceXPathSupport.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SourceXPathSupport.java?rev=744814&r1=744813&r2=744814&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SourceXPathSupport.java
 (original)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SourceXPathSupport.java
 Mon Feb 16 05:55:50 2009
@@ -32,15 +32,15 @@
  * without actually parsing or evaluating it.
  */
 public class SourceXPathSupport {
-    private static final String DEFAULT_XPATH = 
"s11:Body/child::*[position()=1] | " +
+    public static final String DEFAULT_XPATH = 
"s11:Body/child::*[position()=1] | " +
             "s12:Body/child::*[position()=1]";
-    
+
     private SynapseXPath xpath;
     private String xpathString;
 
     /**
      * Get the XPath expression.
-     * 
+     *
      * @return the XPath expression
      */
     public SynapseXPath getXPath() {
@@ -49,38 +49,37 @@
 
     /**
      * Set the XPath expression.
-     * 
+     *
      * @param xpath the XPath expression
      */
     public void setXPath(SynapseXPath xpath) {
         this.xpath = xpath;
     }
-    
+
     /**
      * Set the string representation of the XPath expression.
      * Note that this information is not mandatory and only used for debugging
      * purposes. Setting the string representation explicitly may be useful to
      * make sure that debugging messages contain the XPath expression in the
      * exact form as specified by the user.
-     * 
+     *
      * @param xpathString a string representation of the XPath expression
      */
     public void setXPathString(String xpathString) {
         this.xpathString = xpathString;
     }
-    
+
     /**
      * Get the first node selected by the configured XPath expression.
      * If no XPath expression is set, the first child element of the SOAP body
      * is returned, i.e. in this case the method behaves as if the XPath 
expression is
      * <code>s11:Body/child::*[position()=1] | 
s12:Body/child::*[position()=1]</code>.
-     * 
+     *
      * @param synCtx the message context
      * @param synLog
      * @return the first node selected by the XPath expression
-     * @throws SynapseException
-     *            if the evaluation of the XPath expression failed or didn't 
result in an
-     *            {...@link OMNode}
+     * @throws SynapseException if the evaluation of the XPath expression 
failed or didn't result in an
+     *                          {...@link OMNode}
      */
     public OMNode selectOMNode(MessageContext synCtx, SynapseLog synLog) {
         if (xpath == null) {
@@ -96,7 +95,7 @@
                 return (OMNode) result;
             } else {
                 throw new SynapseException("The evaluation of the XPath 
expression "
-                    + xpath + " did not result in an OMNode : " + result, 
synLog);
+                        + xpath + " did not result in an OMNode : " + result, 
synLog);
             }
         }
     }

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=744814&r1=744813&r2=744814&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
 Mon Feb 16 05:55:50 2009
@@ -20,6 +20,7 @@
 package org.apache.synapse.util.xpath;
 
 import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.impl.llom.OMDocumentImpl;
 import org.apache.axiom.om.impl.llom.OMElementImpl;
 import org.apache.axiom.om.impl.llom.OMTextImpl;
@@ -111,7 +112,7 @@
                 xPath = false;
                 String prefix = "rp" + count++;
                 nameSpaces.put(prefix, curSegment);
-                newXPath.append(prefix + ":");
+                newXPath.append(prefix).append(":");
             } else {
                 if (xPath) {
                     curSegment = s;
@@ -239,6 +240,11 @@
             Context context = new Context(contextSupport);
             context.setNodeSet(new SingletonList(env));
             return context;
+        } else if (obj instanceof OMNode) {
+            ContextSupport baseContextSupport = getContextSupport();
+            Context context = new Context(baseContextSupport);
+            context.setNodeSet(new SingletonList(obj));
+            return context;
         } else {
             return super.getContext(obj);
         }

Modified: 
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/MediatorCustomVariable.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/MediatorCustomVariable.java?rev=744814&r1=744813&r2=744814&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/MediatorCustomVariable.java
 (original)
+++ 
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/MediatorCustomVariable.java
 Mon Feb 16 05:55:50 2009
@@ -31,6 +31,7 @@
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.config.Entry;
 import org.apache.synapse.util.xpath.SynapseXPath;
+import org.apache.synapse.util.xpath.SourceXPathSupport;
 import org.jaxen.JaxenException;
 
 import javax.xml.namespace.QName;
@@ -46,34 +47,18 @@
 
     private static final Log log = 
LogFactory.getLog(MediatorCustomVariable.class);
 
-    /**
-     * The XPath expression which yeilds the element from given XMLDocument
-     */
-    private AXIOMXPath expression;
-
-    /**
-     * The key to lookup the xml document from registry
-     */
+    /* The key to lookup the xml document from registry */
     private String regKey;
-
-    /**
-     * The default XPath which yeilds the first child of the SOAP Envelop
-     */
-//    public static final String DEFAULT_XPATH = 
"//s11:Envelope/s11:Body/child::*[position()=1] | " +
-//                                               
"//s12:Envelope/s12:Body/child::*[position()=1]";
-    public static final String DEFAULT_XPATH = 
"s11:Body/child::*[position()=1] | " +
-        "s12:Body/child::*[position()=1]";
-
-    /**
-     * Lock used to ensure thread-safe lookup of the object from the registry
-     */
+    /* The XPath expression*/
+    private SynapseXPath expression;
+    /*Lock used to ensure thread-safe lookup of the object from the registry */
     private final Object resourceLock = new Object();
 
     public MediatorCustomVariable(QName name) {
         super(name);
         // create the default XPath
         try {
-            this.expression = new AXIOMXPath(DEFAULT_XPATH);
+            this.expression = new 
SynapseXPath(SourceXPathSupport.DEFAULT_XPATH);
             this.expression.addNamespace("s11", 
SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
             this.expression.addNamespace("s12", 
SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
         } catch (JaxenException e) {
@@ -108,7 +93,7 @@
                     hasValueChanged = true;
                     Object o = synCtx.getEntry(this.regKey);
                     if (o != null) {
-                        if (!DEFAULT_XPATH.equals(expression.toString())) {
+                        if 
(!SourceXPathSupport.DEFAULT_XPATH.equals(expression.toString())) {
                             this.value = evaluate(o);
                         } else {
                             this.value = o;
@@ -135,8 +120,8 @@
             if (result instanceof OMNode) {
                 //if the type is not document-node(), then get the text value 
of the node
                 if (this.getType() != XQItemType.XQITEMKIND_DOCUMENT
-                    && this.getType() != XQItemType.XQITEMKIND_DOCUMENT_ELEMENT
-                    && this.getType() != XQItemType.XQITEMKIND_ELEMENT) {
+                        && this.getType() != 
XQItemType.XQITEMKIND_DOCUMENT_ELEMENT
+                        && this.getType() != XQItemType.XQITEMKIND_ELEMENT) {
 
                     int nodeType = ((OMNode) result).getType();
                     if (nodeType == OMNode.TEXT_NODE) {
@@ -165,7 +150,7 @@
         throw new SynapseException(msg);
     }
 
-    public void setExpression(AXIOMXPath expression) {
+    public void setExpression(SynapseXPath expression) {
         this.expression = expression;
     }
 
@@ -177,7 +162,7 @@
         return regKey;
     }
 
-    public AXIOMXPath getExpression() {
+    public SynapseXPath getExpression() {
         return expression;
     }
 }

Modified: 
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java?rev=744814&r1=744813&r2=744814&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java
 (original)
+++ 
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java
 Mon Feb 16 05:55:50 2009
@@ -26,17 +26,15 @@
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.impl.dom.DOOMAbstractFactory;
 import org.apache.axiom.om.util.ElementHelper;
-import org.apache.axiom.om.xpath.AXIOMXPath;
-import org.apache.axiom.soap.SOAP11Constants;
-import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.synapse.MessageContext;
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.SynapseLog;
+import org.apache.synapse.util.xpath.SourceXPathSupport;
+import org.apache.synapse.util.xpath.SynapseXPath;
 import org.apache.synapse.config.Entry;
 import org.apache.synapse.config.SynapseConfigUtils;
 import org.apache.synapse.mediators.AbstractMediator;
 import org.apache.synapse.mediators.MediatorProperty;
-import org.jaxen.JaxenException;
 import org.w3c.dom.Element;
 import org.xml.sax.InputSource;
 
@@ -66,73 +64,37 @@
 
 public class XQueryMediator extends AbstractMediator {
 
-    /**
-     * Properties that must set to the XQDataSource
-     */
-    private List dataSourceProperties = new ArrayList();
+    /* Properties that must set to the XQDataSource  */
+    private final List<MediatorProperty> dataSourceProperties = new 
ArrayList<MediatorProperty>();
 
-    /**
-     * The key for lookup the xquery
-     */
+    /* The key for lookup the xquery */
     private String queryKey;
 
-    /**
-     * The source of the xquery
-     */
+    /* The source of the xquery */
     private String querySource;
 
-    /**
-     * The default xpath to get the first child of the SOAPBody
-     */
-//    public static final String DEFAULT_XPATH = 
"//s11:Envelope/s11:Body/child::*[position()=1] | " +
-//                                               
"//s12:Envelope/s12:Body/child::*[position()=1]";
-    public static final String DEFAULT_XPATH = 
"s11:Body/child::*[position()=1] | " +
-            "s12:Body/child::*[position()=1]";
-
-    /**
-     * The (optional) XPath expression which yeilds the target element to 
attached the result
-     */
-    private AXIOMXPath target = null;
+    /*The target node*/
+    private final SourceXPathSupport target = new SourceXPathSupport();
 
-    /**
-     * The list of variables for binding to the DyanamicContext in order to 
available for querying
-     */
-    private List variables = new ArrayList();
+    /* The list of variables for binding to the DyanamicContext in order to 
available for querying */
+    private final List<MediatorVariable> variables = new 
ArrayList<MediatorVariable>();
 
-    /**
-     * Lock used to ensure thread-safe lookup of the object from the registry
-     */
+    /*Lock used to ensure thread-safe lookup of the object from the registry */
     private final Object resourceLock = new Object();
 
-    /**
-     * Is it need to use DOMSource and DOMResult?
-     */
+    /* Is it need to use DOMSource and DOMResult? */
     private boolean useDOMSource = false;
 
-    /**
-     * The DataSource which use to create a connection to XML database
-     */
+    /*The DataSource which use to create a connection to XML database */
     private XQDataSource cachedXQDataSource = null;
 
-    /**
-     * connection with a specific XQuery engine.Connection will live as long 
as synapse live
-     */
+    /* connection with a specific XQuery engine.Connection will live as long 
as synapse live */
     private XQConnection cachedConnection = null;
 
-    /**
-     * An expression that use for multiple  executions.Expression will 
recreate if query has changed
-     */
+    /* An expression that use for multiple  executions.Expression will 
recreate if query has changed */
     private XQPreparedExpression cachedPreparedExpression = null;
 
     public XQueryMediator() {
-        // create the default XPath
-        try {
-            this.target = new AXIOMXPath(DEFAULT_XPATH);
-            this.target.addNamespace("s11", 
SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-            this.target.addNamespace("s12", 
SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-        } catch (JaxenException e) {
-            handleException("Error creating target XPath expression", e);
-        }
     }
 
     /**
@@ -172,8 +134,8 @@
     /**
      * Perform the quering and get the result and attached to the target node
      *
-     * @param synCtx         The current MessageContext
-     * @param synLog         the Synapse log to use
+     * @param synCtx The current MessageContext
+     * @param synLog the Synapse log to use
      */
     private void performQuery(MessageContext synCtx, SynapseLog synLog) {
 
@@ -182,7 +144,7 @@
         XQResultSequence resultSequence;
 
         if (queryKey != null && !"".equals(queryKey)) {
-           
+
             Entry dp = synCtx.getConfiguration().getEntryDefinition(queryKey);
             // if the queryKey refers to a dynamic resource
             if (dp != null && dp.isDynamic()) {
@@ -202,10 +164,10 @@
                     //setting up the properties to the XQDataSource
                     if (dataSourceProperties != null && 
!dataSourceProperties.isEmpty()) {
                         synLog.traceOrDebug("Setting up properties to the 
XQDataSource");
-                        for (int i = 0; i < dataSourceProperties.size(); i++) {
-                            MediatorProperty prop = (MediatorProperty) 
dataSourceProperties.get(i);
-                            if (prop != null) {
-                                cachedXQDataSource.setProperty(prop.getName(), 
prop.getValue());
+                        for (MediatorProperty dataSourceProperty : 
dataSourceProperties) {
+                            if (dataSourceProperty != null) {
+                                
cachedXQDataSource.setProperty(dataSourceProperty.getName(),
+                                        dataSourceProperty.getValue());
                             }
                         }
                     }
@@ -307,13 +269,14 @@
                 //Bind the external variables to the DynamicContext
                 if (variables != null && !variables.isEmpty()) {
                     synLog.traceOrDebug("Binding  external variables to the 
DynamicContext");
-                    for (int i = 0; i < variables.size(); i++) {
-                        MediatorVariable variable = (MediatorVariable) 
variables.get(i);
-                        boolean hasValueChanged = 
variable.evaluateValue(synCtx);
-                        //if the value has changed or need binding because the 
expression has recreated
-                        if (hasValueChanged || needBind) {
-                            //Binds the external variable to the DynamicContext
-                            bindVariable(cachedPreparedExpression, variable, 
synLog);
+                    for (MediatorVariable variable : variables) {
+                        if (variable != null) {
+                            boolean hasValueChanged = 
variable.evaluateValue(synCtx);
+                            //if the value has changed or need binding because 
the expression has recreated
+                            if (hasValueChanged || needBind) {
+                                //Binds the external variable to the 
DynamicContext
+                                bindVariable(cachedPreparedExpression, 
variable, synLog);
+                            }
                         }
                     }
                 }
@@ -346,7 +309,7 @@
                 }
 
                 //The target node that is going to modify
-                OMNode destination = getTargetNode(synCtx);
+                OMNode destination = target.selectOMNode(synCtx, synLog);
                 if (destination != null) {
                     if (synLog.isTraceOrDebugEnabled()) {
                         synLog.traceOrDebug("The target node " + destination);
@@ -428,7 +391,7 @@
                         if (value instanceof String) {
                             booleanValue = Boolean.parseBoolean((String) 
value);
                         } else if (value instanceof Boolean) {
-                            booleanValue = ((Boolean) value).booleanValue();
+                            booleanValue = (Boolean) value;
                         } else {
                             handleException("Incompatible type for the 
Boolean");
                         }
@@ -445,7 +408,7 @@
                                         "for the Integer", e);
                             }
                         } else if (value instanceof Integer) {
-                            intValue = ((Integer) value).intValue();
+                            intValue = (Integer) value;
                         } else {
                             handleException("Incompatible type for the 
Integer");
                         }
@@ -463,7 +426,7 @@
                                 handleException("Incompatible value '" + value 
+ "' for the Int", e);
                             }
                         } else if (value instanceof Integer) {
-                            intValue = ((Integer) value).intValue();
+                            intValue = (Integer) value;
                         } else {
                             handleException("Incompatible type for the Int");
                         }
@@ -482,7 +445,7 @@
                                         "for the long ", e);
                             }
                         } else if (value instanceof Long) {
-                            longValue = ((Long) value).longValue();
+                            longValue = (Long) value;
                         } else {
                             handleException("Incompatible type for the Long");
                         }
@@ -501,7 +464,7 @@
                                         "for the short ", e);
                             }
                         } else if (value instanceof Short) {
-                            shortValue = ((Short) value).shortValue();
+                            shortValue = (Short) value;
                         } else {
                             handleException("Incompatible type for the Short");
                         }
@@ -520,7 +483,7 @@
                                         "for the double ", e);
                             }
                         } else if (value instanceof Double) {
-                            doubleValue = ((Double) value).doubleValue();
+                            doubleValue = (Double) value;
                         } else {
                             handleException("Incompatible type for the 
Double");
                         }
@@ -539,7 +502,7 @@
                                         "for the float ", e);
                             }
                         } else if (value instanceof Float) {
-                            floatValue = ((Float) value).floatValue();
+                            floatValue = (Float) value;
                         } else {
                             handleException("Incompatible type for the Float");
                         }
@@ -558,7 +521,7 @@
                                         "for the byte ", e);
                             }
                         } else if (value instanceof Byte) {
-                            byteValue = ((Byte) value).byteValue();
+                            byteValue = (Byte) value;
                         } else {
                             handleException("Incompatible type for the Byte");
                         }
@@ -637,37 +600,6 @@
 
     }
 
-    /**
-     * Return the OMNode to be used for the attached the query result. If a 
target XPath is not specified,
-     * this will default to the first child of the SOAP body i.e. - 
//*:Envelope/*:Body/child::*
-     *
-     * @param synCtx the message context
-     * @return the OMNode against which the result should be attached
-     */
-    public OMNode getTargetNode(MessageContext synCtx) {
-        try {
-            Object o = target.evaluate(synCtx.getEnvelope());
-            if (o instanceof OMNode) {
-                return (OMNode) o;
-            } else if (o instanceof List && !((List) o).isEmpty()) {
-                Object nodeObject = ((List) o).get(0); // Always fetches 
*only* the first
-                if (nodeObject instanceof OMNode) {
-                    return (OMNode) nodeObject;
-                } else {
-                    handleException("The evaluation of the XPath expression "
-                            + target + " must target in an OMNode");
-                }
-            } else {
-                handleException("The evaluation of the XPath expression "
-                        + target + " must target in an OMNode");
-            }
-        } catch (JaxenException e) {
-            handleException("Error evaluating XPath " + target +
-                    " on message" + synCtx.getEnvelope());
-        }
-        return null;
-    }
-
     private void handleException(String msg, Exception e) {
         log.error(msg, e);
         throw new SynapseException(msg, e);
@@ -694,7 +626,7 @@
         this.querySource = querySource;
     }
 
-    public void addAllVariables(List list) {
+    public void addAllVariables(List<MediatorVariable> list) {
         this.variables.addAll(list);
     }
 
@@ -702,23 +634,23 @@
         this.variables.add(variable);
     }
 
-    public List getDataSourceProperties() {
+    public List<MediatorProperty> getDataSourceProperties() {
         return dataSourceProperties;
     }
 
-    public List getVariables() {
+    public List<MediatorVariable> getVariables() {
         return variables;
     }
 
-    public AXIOMXPath getTarget() {
-        return target;
+    public SynapseXPath getTarget() {
+        return target.getXPath();
     }
 
-    public void setTarget(AXIOMXPath target) {
-        this.target = target;
+    public void setTarget(SynapseXPath source) {
+        this.target.setXPath(source);
     }
 
-    public void addAllDataSoureProperties(List list) {
+    public void addAllDataSourceProperties(List<MediatorProperty> list) {
         this.dataSourceProperties.addAll(list);
     }
 

Modified: 
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediatorFactory.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediatorFactory.java?rev=744814&r1=744813&r2=744814&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediatorFactory.java
 (original)
+++ 
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediatorFactory.java
 Mon Feb 16 05:55:50 2009
@@ -21,10 +21,10 @@
 import net.sf.saxon.javax.xml.xquery.XQItemType;
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.xpath.AXIOMXPath;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.Mediator;
+import org.apache.synapse.util.xpath.SynapseXPath;
 import org.apache.synapse.config.xml.*;
 import org.jaxen.JaxenException;
 
@@ -47,7 +47,7 @@
     private static final Log log = 
LogFactory.getLog(XQueryMediatorFactory.class);
 
     private static final QName TAG_NAME
-        = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "xquery");
+            = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "xquery");
     public static final QName ATT_NAME_Q = new 
QName(XMLConfigConstants.NULL_NAMESPACE, "name");
     public static final QName ATT_VALUE_Q = new 
QName(XMLConfigConstants.NULL_NAMESPACE, "value");
     public static final QName ATT_EXPR_Q = new 
QName(XMLConfigConstants.NULL_NAMESPACE, "expression");
@@ -72,11 +72,10 @@
         }
         if (attrTarget != null) {
             String targetValue = attrTarget.getAttributeValue();
-            if (targetValue != null) {
+            if (targetValue != null && !"".equals(targetValue)) {
                 try {
-                    AXIOMXPath xpath = new 
AXIOMXPath(attrTarget.getAttributeValue());
-                    OMElementUtils.addNameSpaces(xpath, elem, log);
-                    xQueryMediator.setTarget(xpath);
+                    xQueryMediator.setQuerySource(targetValue);
+                    
xQueryMediator.setTarget(SynapseXPathFactory.getSynapseXPath(elem, ATT_TARGET));
                 } catch (JaxenException e) {
                     handleException("Invalid XPath specified for the target 
attribute : " + targetValue);
                 }
@@ -86,10 +85,10 @@
         // set its common attributes such as tracing etc
         processAuditStatus(xQueryMediator, elem);
         OMElement dataSource = elem.getFirstChildWithName(
-            new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "dataSource"));
+                new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "dataSource"));
         if (dataSource != null) {
-            xQueryMediator.addAllDataSoureProperties(
-                MediatorPropertyFactory.getMediatorProperties(dataSource));
+            xQueryMediator.addAllDataSourceProperties(
+                    MediatorPropertyFactory.getMediatorProperties(dataSource));
         }
 
         Iterator it = elem.getChildrenWithName(new 
QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "variable"));
@@ -103,25 +102,25 @@
                     MediatorVariable variable;
                     if (value != null && !"".equals(value)) {
                         variable = new MediatorBaseVariable(
-                            new QName(name.trim()));
+                                new QName(name.trim()));
                         variable.setValue(value.trim());
                     } else {
                         String key = variableOM.getAttributeValue(ATT_KEY_Q);
                         String expr = variableOM.getAttributeValue(ATT_EXPR_Q);
                         variable = new MediatorCustomVariable(
-                            new QName(name.trim()));
+                                new QName(name.trim()));
                         if (key != null) {
                             ((MediatorCustomVariable) 
variable).setRegKey(key.trim());
                         }
                         if (expr != null && !"".equals(expr)) {
                             try {
-                                AXIOMXPath xpath = new AXIOMXPath(expr);
+                                SynapseXPath xpath = new SynapseXPath(expr);
                                 OMElementUtils.addNameSpaces(xpath, 
variableOM, log);
                                 ((MediatorCustomVariable) 
variable).setExpression(xpath);
 
                             } catch (JaxenException e) {
                                 handleException("Invalid XPath specified for" +
-                                    " the expression attribute : " + expr);
+                                        " the expression attribute : " + expr);
                             }
                         }
                     }

Modified: 
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediatorSerializer.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediatorSerializer.java?rev=744814&r1=744813&r2=744814&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediatorSerializer.java
 (original)
+++ 
synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediatorSerializer.java
 Mon Feb 16 05:55:50 2009
@@ -20,15 +20,12 @@
 
 import net.sf.saxon.javax.xml.xquery.XQItemType;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.xpath.AXIOMXPath;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.Mediator;
+import org.apache.synapse.mediators.MediatorProperty;
 import org.apache.synapse.config.xml.AbstractMediatorSerializer;
 import org.apache.synapse.config.xml.SynapseXPathSerializer;
-import org.apache.synapse.config.xml.XMLConfigConstants;
 import org.apache.synapse.util.xpath.SynapseXPath;
+import org.apache.synapse.util.xpath.SourceXPathSupport;
 
 import javax.xml.namespace.QName;
 import java.util.List;
@@ -45,11 +42,6 @@
  */
 public class XQueryMediatorSerializer extends AbstractMediatorSerializer {
 
-    private static final Log log = 
LogFactory.getLog(XQueryMediatorSerializer.class);
-
-    private static final OMNamespace XQUERY_NS
-        = fac.createOMNamespace(XMLConfigConstants.SYNAPSE_NAMESPACE, 
"xquery");
-
     public OMElement serializeMediator(OMElement parent, Mediator m) {
 
         if (!(m instanceof XQueryMediator)) {
@@ -61,20 +53,18 @@
         String key = queryMediator.getQueryKey();
         if (key != null) {
             xquery.addAttribute(fac.createOMAttribute(
-                "key", nullNS, key));
+                    "key", nullNS, key));
 
         }
 
         saveTracingState(xquery, queryMediator);
 
-        AXIOMXPath targetXPath = queryMediator.getTarget();
-        if (targetXPath != null && 
!XQueryMediator.DEFAULT_XPATH.equals(targetXPath.toString())) {
-
-            xquery.addAttribute(fac.createOMAttribute("target", nullNS, 
targetXPath.toString()));
-            serializeNamespaces(xquery, targetXPath);
+        SynapseXPath targetXPath = queryMediator.getTarget();
+        if (targetXPath != null && 
!SourceXPathSupport.DEFAULT_XPATH.equals(targetXPath.toString())) {
+            SynapseXPathSerializer.serializeXPath(targetXPath, xquery, 
"target");
         }
 
-        List pros = queryMediator.getDataSourceProperties();
+        List<MediatorProperty> pros = queryMediator.getDataSourceProperties();
         if (pros != null && !pros.isEmpty()) {
             OMElement dataSource = fac.createOMElement("dataSource", synNS);
             serializeProperties(dataSource, pros);
@@ -83,8 +73,7 @@
 
         List list = queryMediator.getVariables();
         if (list != null && !list.isEmpty()) {
-            for (int i = 0; i < list.size(); i++) {
-                Object o = list.get(i);
+            for (Object o : list) {
                 if (o instanceof MediatorBaseVariable) {
                     MediatorBaseVariable variable = (MediatorBaseVariable) o;
                     QName name = variable.getName();
@@ -92,9 +81,9 @@
                     if (name != null && value != null) {
                         OMElement baseElement = 
fac.createOMElement("variable", synNS);
                         baseElement.addAttribute(fac.createOMAttribute(
-                            "name", nullNS, name.getLocalPart()));
+                                "name", nullNS, name.getLocalPart()));
                         baseElement.addAttribute(fac.createOMAttribute(
-                            "value", nullNS, (String) value));
+                                "value", nullNS, (String) value));
                         String type = null;
                         int varibelType = variable.getType();
                         if (XQItemType.XQBASETYPE_INT == varibelType) {
@@ -126,7 +115,7 @@
                         }
                         if (type != null) {
                             baseElement.addAttribute(fac.createOMAttribute(
-                                "type", nullNS, type));
+                                    "type", nullNS, type));
 
                         }
                         xquery.addChild(baseElement);
@@ -137,19 +126,15 @@
                     if (name != null) {
                         OMElement customElement = 
fac.createOMElement("variable", synNS);
                         customElement.addAttribute(fac.createOMAttribute(
-                            "name", nullNS, name.getLocalPart()));
+                                "name", nullNS, name.getLocalPart()));
                         String regkey = variable.getRegKey();
                         if (regkey != null) {
                             customElement.addAttribute(fac.createOMAttribute(
-                                "key", nullNS, regkey));
+                                    "key", nullNS, regkey));
                         }
-                        AXIOMXPath expression = variable.getExpression();
-                        if (expression != null &&
-                            
!XQueryMediator.DEFAULT_XPATH.equals(expression.toString())) {
-
-                            customElement.addAttribute(fac.createOMAttribute(
-                                    "expression", nullNS, 
expression.toString()));
-                            serializeNamespaces(customElement, expression);
+                        SynapseXPath expression = variable.getExpression();
+                        if (expression != null && 
!SourceXPathSupport.DEFAULT_XPATH.equals(expression.toString())) {
+                            SynapseXPathSerializer.serializeXPath(expression, 
customElement, "expression");
                         }
                         String type = null;
                         int varibelType = variable.getType();
@@ -182,7 +167,7 @@
                         }
                         if (type != null) {
                             customElement.addAttribute(fac.createOMAttribute(
-                                "type", nullNS, type));
+                                    "type", nullNS, type));
 
                         }
                         xquery.addChild(customElement);


Reply via email to