synapse-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ind...@apache.org
Subject svn commit: r745804 - in /synapse/trunk/java: modules/core/src/main/java/org/apache/synapse/config/ modules/core/src/main/java/org/apache/synapse/eventing/ modules/core/src/main/java/org/apache/synapse/mediators/ modules/core/src/main/java/org/apache/s...
Date Thu, 19 Feb 2009 10:16:47 GMT
Author: indika
Date: Thu Feb 19 10:16:46 2009
New Revision: 745804

URL: http://svn.apache.org/viewvc?rev=745804&view=rev
Log:
remove unneccessary code from SynapseXPath 
some minor code improvements

Modified:
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/eventing/SynapseEventSource.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.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/db/DBLookupMediator.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eventing/EventPublisherMediator.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/XQueryMediator.java
    synapse/trunk/java/repository/conf/sample/resources/xquery/xquery_commisson.xq
    synapse/trunk/java/repository/conf/sample/synapse_sample_391.xml

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java?rev=745804&r1=745803&r2=745804&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
(original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
Thu Feb 19 10:16:46 2009
@@ -21,6 +21,7 @@
 
 import org.apache.axiom.om.*;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.llom.util.AXIOMUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.SynapseException;
@@ -611,14 +612,10 @@
 
     public static OMElement stringToOM(String xml) {
         try {
-            //TODO if there are any better way of converting string to OM , use it
-            XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(
-                    new StringReader(xml));
-            StAXOMBuilder builder = new StAXOMBuilder(reader);
-            return builder.getDocumentElement();
+            return AXIOMUtil.stringToOM(xml);  // Just wrapp to add loging for any errors
         } catch (XMLStreamException e) {
             handleException("Unable to convert a string to OM Node as the string " +
-                    "is malformed , String : " + xml);
+                    "is malformed , String : " + xml, e);
         }
         return null;
     }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/eventing/SynapseEventSource.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/eventing/SynapseEventSource.java?rev=745804&r1=745803&r2=745804&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/eventing/SynapseEventSource.java
(original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/eventing/SynapseEventSource.java
Thu Feb 19 10:16:46 2009
@@ -253,7 +253,7 @@
             }
             List<SynapseSubscription> subscribers = subscriptionManager.getMatchingSubscribers(smc);
             for (SynapseSubscription subscription : subscribers) {
-                smc.setProperty("OUT_ONLY", "true");    // Set one way message for events
+                smc.setProperty(SynapseConstants.OUT_ONLY, "true");    // Set one way message
for events
                 subscription.getEndpoint().send(MessageHelper.cloneMessageContext(smc));
                 if (log.isDebugEnabled()) {
                     log.debug("Event push to  : " + subscription.getEndpointUrl());

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java?rev=745804&r1=745803&r2=745804&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java
(original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java
Thu Feb 19 10:16:46 2009
@@ -38,7 +38,7 @@
     implements ListMediator, ManagedLifecycle {
 
     /** the list of child mediators held. These are executed sequentially */
-    protected List<Mediator> mediators = new ArrayList<Mediator>();
+    protected final List<Mediator> mediators = new ArrayList<Mediator>();
 
     public boolean mediate(MessageContext synCtx) {
 

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=745804&r1=745803&r2=745804&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
Thu Feb 19 10:16:46 2009
@@ -34,7 +34,6 @@
 
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
 public class RMSequenceMediator extends AbstractMediator {
@@ -48,7 +47,8 @@
     private static final String WSRM_SpecVersion_1_1 = "Spec_2007_02";
     // set sequence expiry time to 5 minutes
     private static final long SEQUENCE_EXPIRY_TIME = 300000;
-    private static Map sequenceMap = Collections.synchronizedMap(new HashMap());
+    private static final Map<String, Entry> sequenceMap =
+            Collections.synchronizedMap(new HashMap<String, Entry>());
 
     public boolean mediate(MessageContext synCtx) {
 
@@ -128,7 +128,7 @@
     }
 
     private String retrieveSequenceID(String correlationValue) {
-        String sequenceID = null;
+        String sequenceID;
         if (!sequenceMap.containsKey(correlationValue)) {
             sequenceID = UUIDGenerator.getUUID();
             if (log.isDebugEnabled()) {
@@ -148,20 +148,18 @@
     }
 
     private String getCorrelationValue(MessageContext smc) {
-        OMElement node = null;
         try {
-            node = (OMElement) getCorrelation().selectSingleNode(smc);
-
+            OMElement node = (OMElement) getCorrelation().selectSingleNode(smc);
             if (node != null) {
                 return node.getText();
             } else {
                 handleException("XPath expression : " + getCorrelation() +
-                    " did not return any node", smc);
+                        " did not return any node", smc);
             }
 
         } catch (JaxenException e) {
             handleException("Error evaluating XPath expression to determine correlation :
" +
-                getCorrelation(), e, smc);
+                    getCorrelation(), e, smc);
         }
         return null; // never called
     }
@@ -189,10 +187,8 @@
     }
 
     private synchronized void cleanupSequenceMap() {
-        Iterator itKey = sequenceMap.keySet().iterator();
-        while (itKey.hasNext()) {
-            Object key = itKey.next();
-            Entry sequenceEntry = (Entry) sequenceMap.get(key);
+        for (String key : sequenceMap.keySet()) {
+            Entry sequenceEntry = sequenceMap.get(key);
             if (sequenceEntry.isExpired()) {
                 sequenceMap.remove(key);
             }
@@ -200,12 +196,7 @@
     }
 
     public boolean isSingle() {
-        if (getSingle() != null && getSingle().booleanValue()) {
-            return true;
-
-        } else {
-            return false;
-        }
+        return getSingle() != null && getSingle();
     }
 
     public SynapseXPath getCorrelation() {

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=745804&r1=745803&r2=745804&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
Thu Feb 19 10:16:46 2009
@@ -51,7 +51,7 @@
      */
     private DBPoolView dbPoolView;
     /** Statements */
-    List statementList = new ArrayList();
+    private final List<Statement> statementList = new ArrayList<Statement>();
 
     /**
      * Initializes the mediator. Does nothing right now. If DataSource lookup is supported,
could
@@ -97,8 +97,10 @@
             }
         }
 
-        for (Iterator iter = statementList.iterator(); iter.hasNext(); ) {
-            processStatement((Statement) iter.next(), synCtx);
+        for (Statement aStatement : statementList) {
+            if (aStatement != null) {
+                processStatement(aStatement, synCtx);
+            }
         }
 
         if (synLog.isTraceOrDebugEnabled()) {
@@ -162,7 +164,8 @@
      * @return
      * @throws SQLException
      */
-    protected PreparedStatement getPreparedStatement(Statement stmnt, MessageContext msgCtx)
throws SQLException {
+    protected PreparedStatement getPreparedStatement(Statement stmnt,
+                                                     MessageContext msgCtx) throws SQLException
{
 
         SynapseLog synLog = getLog(msgCtx);
 
@@ -205,18 +208,20 @@
         PreparedStatement ps = con.prepareStatement(stmnt.getRawStatement());
 
         // set parameters if any
-        List params = stmnt.getParameters();
+        List<Statement.Parameter> params = stmnt.getParameters();
         int column = 1;
 
-        for (Iterator pi = params.iterator(); pi.hasNext(); ) {
-
-            Statement.Parameter param = (Statement.Parameter) pi.next();
+        for (Statement.Parameter param : params) {
+            if (param == null) {
+                continue;
+            }
             String value = (param.getPropertyName() != null ?
-                param.getPropertyName() : param.getXpath().stringValueOf(msgCtx));
+                    param.getPropertyName() : param.getXpath().stringValueOf(msgCtx));
 
             if (synLog.isTraceOrDebugEnabled()) {
                 synLog.traceOrDebug("Setting as parameter : " + column + " value : " + value
+
-                    " as JDBC Type : " + param.getType() + "(see java.sql.Types for valid
types)");
+                        " as JDBC Type : " + param.getType() + "(see java.sql.Types for valid
" +
+                        "types)");
             }
 
             switch (param.getType()) {
@@ -280,9 +285,10 @@
                 // skip CLOB, BLOB, ARRAY, DISTINCT, STRUCT, REF, JAVA_OBJECT
                 default: {
                     String msg = "Trying to set an un-supported JDBC Type : " + param.getType()
+
-                        " against column : " + column + " and statement : " + stmnt.getRawStatement()
+
-                        " used by a DB mediator against DataSource : " + getDSName() +
-                        " (see java.sql.Types for valid type values)";
+                            " against column : " + column + " and statement : " +
+                            stmnt.getRawStatement() +
+                            " used by a DB mediator against DataSource : " + getDSName()
+
+                            " (see java.sql.Types for valid type values)";
                     handleException(msg, msgCtx);
                 }
             }
@@ -301,5 +307,5 @@
 
     public void setDbPoolView(DBPoolView dbPoolView) {
         this.dbPoolView = dbPoolView;
-    }     
+    }
 }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBLookupMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBLookupMediator.java?rev=745804&r1=745803&r2=745804&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBLookupMediator.java
(original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBLookupMediator.java
Thu Feb 19 10:16:46 2009
@@ -51,13 +51,10 @@
                         "Processing the first row returned : " + stmnt.getRawStatement());
                 }
 
-                Iterator propNameIter = stmnt.getResultsMap().keySet().iterator();
-                while (propNameIter.hasNext()) {
+                for (String propName : stmnt.getResultsMap().keySet()) {
 
-                    String propName = (String) propNameIter.next();
-                    String columnStr = (String) stmnt.getResultsMap().get(propName);
-
-                    Object obj = null;
+                    String columnStr =  stmnt.getResultsMap().get(propName);
+                    Object obj;
                     try {
                         int colNum = Integer.parseInt(columnStr);
                         obj = rs.getObject(colNum);
@@ -68,14 +65,14 @@
                     if (obj != null) {
                         if (synLog.isTraceOrDebugEnabled()) {
                             synLog.traceOrDebug("Column : " + columnStr +
-                                " returned value : " + obj +
-                                " Setting this as the message property : " + propName);
+                                    " returned value : " + obj +
+                                    " Setting this as the message property : " + propName);
                         }
                         msgCtx.setProperty(propName, obj.toString());
                     } else {
                         if (synLog.isTraceOrDebugEnabled()) {
                             synLog.traceOrDebugWarn("Column : " + columnStr +
-                                " returned null Skip setting message property : " + propName);
+                                    " returned null Skip setting message property : " + propName);
                         }
                     }
                 }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eventing/EventPublisherMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eventing/EventPublisherMediator.java?rev=745804&r1=745803&r2=745804&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eventing/EventPublisherMediator.java
(original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eventing/EventPublisherMediator.java
Thu Feb 19 10:16:46 2009
@@ -22,6 +22,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.eventing.SynapseEventSource;
 import org.apache.synapse.eventing.SynapseSubscription;
 import org.apache.synapse.eventing.SynapseSubscriptionManager;
@@ -69,7 +70,7 @@
 
         public void run() {
             for (SynapseSubscription subscription : subscribers) {
-                synCtx.setProperty("OUT_ONLY", "true");    // Set one way message for events
+                synCtx.setProperty(SynapseConstants.OUT_ONLY, "true");    // Set one way
message for events
                 try {
                     subscription.getEndpoint().send(MessageHelper.cloneMessageContext(synCtx));
                 } catch (AxisFault axisFault) {

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=745804&r1=745803&r2=745804&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
Thu Feb 19 10:16:46 2009
@@ -240,11 +240,6 @@
             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/XQueryMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/xquery/XQueryMediator.java?rev=745804&r1=745803&r2=745804&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
Thu Feb 19 10:16:46 2009
@@ -116,7 +116,8 @@
                 if (synLog.isTraceTraceEnabled()) {
                     synLog.traceTrace("Message : " + synCtx.getEnvelope());
                 }
-                synLog.traceOrDebug("Performing XQuery using query resource with key : "
+ queryKey);
+                synLog.traceOrDebug("Performing XQuery using query resource with key : "
+
+                        queryKey);
             }
 
             // perform the xquery
@@ -197,7 +198,8 @@
                             }
 
                             //create an XQPreparedExpression using the query source
-                            cachedPreparedExpression = cachedConnection.prepareExpression(querySource);
+                            cachedPreparedExpression =
+                                    cachedConnection.prepareExpression(querySource);
                             // need binding because the expression just has recreated
                             needBind = true;
                         }
@@ -347,7 +349,8 @@
                     } else if (XQItemType.XQBASETYPE_BYTE == baseType) {
                         ((OMElement) destination).setText(String.valueOf(xqItem.getByte()));
                     } else if (XQItemType.XQBASETYPE_STRING == baseType) {
-                        ((OMElement) destination).setText(String.valueOf(xqItem.getItemAsString()));
+                        ((OMElement) destination).setText(
+                                String.valueOf(xqItem.getItemAsString()));
                     }
                 }
                 break;   // Only take the *first* value of the result sequence
@@ -424,7 +427,8 @@
                             try {
                                 intValue = Integer.parseInt((String) value);
                             } catch (NumberFormatException e) {
-                                handleException("Incompatible value '" + value + "' for the
Int", e);
+                                handleException("Incompatible value '" + value +
+                                        "' for the Int", e);
                             }
                         } else if (value instanceof Integer) {
                             intValue = (Integer) value;
@@ -562,27 +566,28 @@
 
     }
 
-    private void bindOMNode(QName name, Object value, XQDynamicContext xqDynamicContext)
throws XQException {
+    private void bindOMNode(QName name, Object value,
+                            XQDynamicContext xqDynamicContext) throws XQException {
 
-        OMElement varibleValue = null;
+        OMElement variableValue = null;
         if (value instanceof String) {
-            varibleValue = SynapseConfigUtils.stringToOM((String) value);
+            variableValue = SynapseConfigUtils.stringToOM((String) value);
         } else if (value instanceof OMElement) {
-            varibleValue = (OMElement) value;
+            variableValue = (OMElement) value;
         }
 
-        if (varibleValue != null) {
+        if (variableValue != null) {
             if (useDOMSource) {
                 xqDynamicContext.
                         bindObject(name,
                                 new DOMSource(((Element) ElementHelper.
-                                        importOMElement(varibleValue,
+                                        importOMElement(variableValue,
                                                 DOOMAbstractFactory.getOMFactory())).
                                         getOwnerDocument()), null);
             } else {
                 xqDynamicContext.bindDocument(name,
                         new InputSource(SynapseConfigUtils.getInputStream(
-                                varibleValue)));
+                                variableValue)));
             }
         }
     }

Modified: synapse/trunk/java/repository/conf/sample/resources/xquery/xquery_commisson.xq
URL: http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/sample/resources/xquery/xquery_commisson.xq?rev=745804&r1=745803&r2=745804&view=diff
==============================================================================
--- synapse/trunk/java/repository/conf/sample/resources/xquery/xquery_commisson.xq (original)
+++ synapse/trunk/java/repository/conf/sample/resources/xquery/xquery_commisson.xq Thu Feb
19 10:16:46 2009
@@ -1,9 +1,10 @@
 <x><![CDATA[
-  declare namespace m0="http://services.samples/xsd";
+  declare namespace ns="http://services.samples";
+  declare namespace m1="http://services.samples/xsd";
   declare variable $payload as document-node() external;
   declare variable $commission as document-node() external;
   <m0:return xmlns:m0="http://services.samples/xsd">
-  	<m0:symbol>{$payload//m0:return/m0:symbol/child::text()}</m0:symbol>
-  	<m0:last>{$payload//m0:return/m0:last/child::text()+ $commission//commission/vendor[@symbol=$payload//m0:return/m0:symbol/child::text()]}</m0:last>
+  	<m0:symbol>{$payload//ns:return/m1:symbol/child::text()}</m0:symbol>
+  	<m0:last>{$payload//ns:return/m1:last/child::text()+ $commission//commission/vendor[@symbol=$payload//ns:return/m1:symbol/child::text()]}</m0:last>
   </m0:return>  
 ]]></x>
\ No newline at end of file

Modified: synapse/trunk/java/repository/conf/sample/synapse_sample_391.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/sample/synapse_sample_391.xml?rev=745804&r1=745803&r2=745804&view=diff
==============================================================================
--- synapse/trunk/java/repository/conf/sample/synapse_sample_391.xml (original)
+++ synapse/trunk/java/repository/conf/sample/synapse_sample_391.xml Thu Feb 19 10:16:46 2009
@@ -41,7 +41,7 @@
                 <out>
                     <xquery key="xquery/xquery_commisson.xq">
                         <variable name="payload" type="ELEMENT"></variable>
-                            <variable name="commission" type="ELEMENT" key="misc/commission.xml"></variable>
+                        <variable name="commission" type="ELEMENT" key="misc/commission.xml"></variable>
                     </xquery>
                     <send/>
                 </out>



Mime
View raw message