synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sami...@apache.org
Subject svn commit: r405043 [2/4] - in /incubator/synapse/trunk/java: ./ bin/ etc/ modules/core/ modules/core/src/org/apache/synapse/ modules/core/src/org/apache/synapse/api/ modules/core/src/org/apache/synapse/axis2/ modules/core/src/org/apache/synapse/config...
Date Mon, 08 May 2006 13:16:08 GMT
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/HeaderMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/HeaderMediatorFactory.java?rev=405043&r1=405035&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/HeaderMediatorFactory.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/HeaderMediatorFactory.java Mon May  8 06:15:47 2006
@@ -13,45 +13,83 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.synapse.xml;
+package org.apache.synapse.config.xml;
 
 import javax.xml.namespace.QName;
 
-import org.apache.synapse.SynapseEnvironment;
 import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.xml.Constants;
 import org.apache.synapse.api.Mediator;
-import org.apache.synapse.mediators.builtin.HeaderMediator;
+import org.apache.synapse.mediators.transform.HeaderMediator;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
 
 /**
+ * This builds a Header Mediator parsing the XML configuration supplied
  *
- *         <p>
- *         <xmp><synapse:header name="optional" type="to|from|faultto|replyto|action"
- *         value="newvalue"/> </xmp>
- * 
- * 
+ * Set header
+ *   <header name="qname" (value="literal" | expression="xpath")/>
+ *
+ * Remove header
+ *   <header name="qname" action="remove"/>
  */
 public class HeaderMediatorFactory extends AbstractMediatorFactory {
-    private static final QName HEADER_Q = new QName(
-            Constants.SYNAPSE_NAMESPACE, "header");
 
+    private static final Log log = LogFactory.getLog(HeaderMediatorFactory.class);
+
+    private static final QName HEADER_Q = new QName(Constants.SYNAPSE_NAMESPACE, "header");
 
-        private static final QName TYPE_ATT_Q = new QName("type"),
-            VALUE_ATT_Q = new QName("value");
+    public Mediator createMediator(OMElement elem) {
 
-        public Mediator createMediator(SynapseEnvironment se, OMElement el) {
-            HeaderMediator hm = new HeaderMediator();
-            super.setNameOnMediator(se, el, hm);
-            OMAttribute val = el.getAttribute(VALUE_ATT_Q);
-            OMAttribute type = el.getAttribute(TYPE_ATT_Q);
-            if (val == null || type == null) {
-                throw new SynapseException("<header> must have both " + VALUE_ATT_Q
-                    + " and " + TYPE_ATT_Q + " attributes: " + el.toString());
+        HeaderMediator headerMediator = new HeaderMediator();
+        OMAttribute name   = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+        OMAttribute value  = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "value"));
+        OMAttribute exprn  = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "expression"));
+        OMAttribute action = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "action"));
+
+        if (name == null || name.getAttributeValue() == null) {
+            String msg = "A valid name attribute is required for the header mediator";
+            log.error(msg);
+            throw new SynapseException(msg);
+        } else {
+            headerMediator.setName(name.getAttributeValue());
+        }
+
+        // The action attribute is optional, if provided and equals to 'remove' the
+        // header mediator will act as a header remove mediator
+        if (action != null && "remove".equals(action.getAttributeValue())) {
+            headerMediator.setAction(HeaderMediator.ACTION_REMOVE);
+        }
+
+        if (value == null && exprn == null) {
+            String msg = "A 'value' or 'expression' attribute is required for a header mediator";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+
+        if (value != null && value.getAttributeValue() != null) {
+            headerMediator.setValue(value.getAttributeValue());
+
+        } else if (exprn != null && exprn.getAttributeValue() != null) {
+            try {
+                headerMediator.setExpression(new AXIOMXPath(exprn.getAttributeValue()));
+            } catch (JaxenException je) {
+                String msg = "Invalid XPath expression : " + exprn.getAttributeValue();
+                log.error(msg);
+                throw new SynapseException(msg, je);
             }
-            hm.setHeaderType(type.getAttributeValue());
-            hm.setValue( val.getAttributeValue());
-            return hm;
+            
+        } else {
+            String msg = "Invalid attribute value for the attribute 'expression' or 'value'";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+
+        return headerMediator;
     }
 
     public QName getTagQName() {

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java?rev=405043&r1=405035&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java Mon May  8 06:15:47 2006
@@ -14,39 +14,72 @@
  * limitations under the License.
  */
 
-package org.apache.synapse.xml;
+package org.apache.synapse.config.xml;
 
 import javax.xml.namespace.QName;
 
-import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseException;
 import org.apache.synapse.api.Mediator;
 import org.apache.synapse.mediators.builtin.LogMediator;
+import org.apache.synapse.mediators.MediatorProperty;
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+import java.util.Iterator;
+import java.util.List;
 
 /**
+ * Created a Log mediator that logs messages using commons-logging.
  *
- * 
- * <p>
- * Logs messages using Commons-logging. 
- * 
- * <xmp><log name="optional"/></xmp>
- * TODO add support for simple one-line log entry (doesn't cause body parsing)
- *
+ * <log [level="simple|headers|full|custom"]>
+ *      <property> *
+ * </log>
  */
 public class LogMediatorFactory extends AbstractMediatorFactory {
-    private static final QName LOG_Q = new QName(Constants.SYNAPSE_NAMESPACE,
-            "log");
 
+    private static final Log log = LogFactory.getLog(LogMediatorFactory.class);
+
+    private static final QName LOG_Q    = new QName(Constants.SYNAPSE_NAMESPACE, "log");
+    private static final String SIMPLE  = "simple";
+    private static final String HEADERS = "headers";
+    private static final String FULL    = "full";
+    private static final String CUSTOM  = "custom";
 
     public QName getTagQName() {
         return LOG_Q;
     }
 
+    public Mediator createMediator(OMElement elem) {
+
+        LogMediator logMediator = new LogMediator();
+
+        // Set the high level set of properties to be logged (i.e. log level)
+        OMAttribute level = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "level"));
+        if (level != null) {
+            if (SIMPLE.equals(level)) {
+                logMediator.setLogLevel(LogMediator.SIMPLE);
+            } else if (HEADERS.equals(level)) {
+                logMediator.setLogLevel(LogMediator.HEADERS);
+            } else if (FULL.equals(level)) {
+                logMediator.setLogLevel(LogMediator.FULL);
+            } else if (CUSTOM.equals(level)) {
+                logMediator.setLogLevel(LogMediator.CUSTOM);
+            }
+        }
+
+        // check if a custom seperator has been supplied, if so use it
+        OMAttribute seperator = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "seperator"));
+        if (seperator != null) {
+            logMediator.setSeperator(seperator.getAttributeValue());
+        }
+
+        logMediator.addAllProperties(MediatorPropertyFactory.getMediatorProperties(elem));
 
-    public Mediator createMediator(SynapseEnvironment se, OMElement el) {
-        LogMediator lm = new LogMediator();
-        super.setNameOnMediator(se,el,lm);
-        return lm;
+        return logMediator;
     }
 
 }

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorFactory.java?rev=405043&r1=405035&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorFactory.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorFactory.java Mon May  8 06:15:47 2006
@@ -14,15 +14,30 @@
  * limitations under the License.
  */
 
-package org.apache.synapse.xml;
+package org.apache.synapse.config.xml;
 
 import javax.xml.namespace.QName;
 
-import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.config.SynapseConfiguration;
 import org.apache.synapse.api.Mediator;
 import org.apache.axiom.om.OMElement;
 
+/**
+ * A mediator factory capable of creating an instance of a mediator through a given
+ * XML should implement this interface
+ */
 public interface MediatorFactory {
-    public Mediator createMediator(SynapseEnvironment se, OMElement el);
+    /**
+     * Creates an instance of the mediator using the OMElement
+     * @param elem
+     * @return the created mediator
+     */
+    public Mediator createMediator(OMElement elem);
+
+    /**
+     * The QName of this mediator element in the XML config
+     * @return QName of the mediator element
+     */
     public QName getTagQName();
 }

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java?rev=405043&r1=405035&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java Mon May  8 06:15:47 2006
@@ -15,7 +15,7 @@
  */
 
 
-package org.apache.synapse.xml;
+package org.apache.synapse.config.xml;
 
 import java.util.HashMap;
 import java.util.Iterator;
@@ -27,14 +27,10 @@
 import org.apache.commons.logging.LogFactory;
 
 
-import org.apache.synapse.SynapseEnvironment;
 import org.apache.synapse.SynapseException;
-import org.apache.synapse.mediators.builtin.xslt.XSLTMediatorFactory;
-import org.apache.synapse.resources.xml.PropertyMediatorFactory;
-import org.apache.synapse.resources.xml.ResourceMediatorFactory;
+import org.apache.synapse.config.xml.MediatorFactory;
 import org.apache.synapse.api.Mediator;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNamespace;
 
 import sun.misc.Service;
 
@@ -47,90 +43,104 @@
 
 public class MediatorFactoryFinder {
 
-	private static Map lookup = null;
+    private static Map factoryMap = new HashMap();
+	private static final Log log = LogFactory.getLog(MediatorFactoryFinder.class);
 
-	private static Log log = LogFactory
-			.getLog(MediatorFactoryFinder.class);
+	private static final Class[] mediatorFactories = {
+        SequenceMediatorFactory.class,
+        LogMediatorFactory.class,
+        SendMediatorFactory.class,
+        FilterMediatorFactory.class,
+        SynapseMediatorFactory.class,
+        DropMediatorFactory.class,
+        HeaderMediatorFactory.class,
+        FaultMediatorFactory.class,
+        TransformMediatorFactory.class,
+        ValidateMediatorFactory.class,
+        PropertyMediatorFactory.class,
+        SwitchMediatorFactory.class,
+        SwitchCaseMediatorFactory.class,
+        SwitchCaseDefaultMediatorFactory.class
+      };
+
+    private static MediatorFactoryFinder instance = null;
+
+    public static synchronized MediatorFactoryFinder getInstance() {
+        if (instance == null) {
+            instance = new MediatorFactoryFinder();
+        }
+        return instance;
+    }
+
+    /**
+     * Force re initialization next time
+     */
+    public synchronized void reset() {
+        factoryMap.clear();
+        instance = null;
+    }
 
-	private static Class[] mediatorFactories = {
-			SynapseMediatorFactory.class,
-			StageMediatorFactory.class, RegexMediatorFactory.class,
-			XPathMediatorFactory.class,
-			HeaderMediatorFactory.class,
-			ClassMediatorFactory.class,
-			ServiceMediatorFactory.class,
-			LogMediatorFactory.class, SendMediatorFactory.class,
-			FaultMediatorFactory.class,
-			AddressingInMediatorFactory.class,
-			AddressingOutMediatorFactory.class,
-			InMediatorFactory.class, OutMediatorFactory.class,
-			NeverMediatorFactory.class, RefMediatorFactory.class,
-            XSLTMediatorFactory.class,DefineMediatorFactory.class,
-            SendNowMediatorFactory.class,SendMediatorFactory.class,
-            DropMediatorFactory.class,
-            RefDefineMediatorFactory.class, ExactlyOneMediatorFactory.class,
-            DefaultMediatorFactory.class,
-            PropertyMediatorFactory.class, ResourceMediatorFactory.class,
-            };
-
-	private static void initialise() {
-
-		if (lookup != null)
-			return;
-		lookup = new HashMap();
+    private MediatorFactoryFinder() {
 
+		factoryMap = new HashMap();
 		for (int i = 0; i < mediatorFactories.length; i++) {
 			Class c = mediatorFactories[i];
 			try {
-				lookup.put(((MediatorFactory) c.newInstance())
-						.getTagQName(), c);
+				factoryMap.put(((MediatorFactory) c.newInstance()).getTagQName(), c);
 			} catch (Exception e) {
-				throw new SynapseException("problem instantiating "+c.getName(), e);
+				throw new SynapseException("Error instantiating " + c.getName(), e);
 			}
 		}
-		log.debug("registering extensions");
-		log.debug(System.getProperty("java.class.path"));
-		// now try additional processors
-		Iterator it = Service.providers(MediatorFactory.class);
-		while (it.hasNext()) {
-			MediatorFactory mf = (MediatorFactory) it.next();
-			QName tag = mf.getTagQName();
-			lookup.put(tag, mf.getClass());
-			log.debug("added MediatorFactory " + mf.getClass() + " to handle " + tag);
-		}
-	}
+        // TODO revisit later registerExtensions();
+    }
+
+    //TODO revist later
+    private void registerExtensions() {
+        log.debug("registering extensions");
+        log.debug(System.getProperty("java.class.path"));
+        // now try additional processors
+        Iterator it = Service.providers(MediatorFactory.class);
+        while (it.hasNext()) {
+            MediatorFactory mf = (MediatorFactory) it.next();
+            QName tag = mf.getTagQName();
+            factoryMap.put(tag, mf.getClass());
+            log.debug("added MediatorFactory " + mf.getClass() + " to handle " + tag);
+        }
+    }
 
-                            	/**
-	 * @param qn
-	 * @return the class which implements the Processor for the given QName
-	 */
-	public static Class find(QName qn) {
-		initialise();
-		return (Class) lookup.get(qn);
-	}
-	
 	/**
 	 * This method returns a Processor given an OMElement. This will be used
 	 * recursively by the elements which contain processor elements themselves
 	 * (e.g. rules)
 	 * 
-	 * @param synapseEnv
 	 * @param element
-	 * @return Processor
+     * @return Processor
 	 */
-	public static Mediator getMediator(SynapseEnvironment synapseEnv, OMElement element) {
-		OMNamespace n = element.getNamespace();
-		
-		Class cls = find(new QName(n.getName(), element
-				.getLocalName()));
-		try {
+	public Mediator getMediator(OMElement element) {
+
+		QName qName = new QName(element.getNamespace().getName(), element.getLocalName());
+        log.debug("getMediator(" + qName + ")");
+        Class cls = (Class) factoryMap.get(qName);
+
+        if (cls == null) {
+            String msg = "Unknown mediator referenced by configuration element : " + qName;
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+
+        try {
 			MediatorFactory mf = (MediatorFactory) cls.newInstance();
-			Mediator m = mf.createMediator(synapseEnv, element);
-			return m;
-		} catch (InstantiationException e) {
-			throw new SynapseException(e);
-		} catch (IllegalAccessException e) {
-			throw new SynapseException(e);
+			return mf.createMediator(element);
+
+        } catch (InstantiationException e) {
+            String msg = "Error initializing mediator factory : " + cls;
+            log.error(msg);
+            throw new SynapseException(msg, e);
+
+        } catch (IllegalAccessException e) {
+            String msg = "Error initializing mediator factory : " + cls;
+            log.error(msg);
+            throw new SynapseException(msg, e);
 		}
 	}
 }

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorPropertyFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorPropertyFactory.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorPropertyFactory.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorPropertyFactory.java Mon May  8 06:15:47 2006
@@ -0,0 +1,106 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.synapse.mediators.MediatorProperty;
+import org.apache.synapse.SynapseException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+import javax.xml.namespace.QName;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * A utility class capable of creating instances of MediatorProperty objects by reading
+ * through a given XML configuration
+ *
+ * <element>
+ *    <property name="string" (value="literal" | expression="xpath")/>*
+ * </element>
+ */
+public class MediatorPropertyFactory {
+
+    private static final Log log = LogFactory.getLog(MediatorPropertyFactory.class);
+
+    public static List getMediatorProperties(OMElement elem) {
+
+        List propertyList = new ArrayList();
+
+        Iterator iter = elem.getChildrenWithName(new QName(Constants.NULL_NAMESPACE, "property"));
+        while (iter.hasNext()) {
+
+            OMElement propEle = (OMElement) iter.next();
+            OMAttribute attName  = propEle.getAttribute(MediatorProperty.ATT_NAME_Q);
+            OMAttribute attValue = propEle.getAttribute(MediatorProperty.ATT_VALUE_Q);
+            OMAttribute attExpr  = propEle.getAttribute(MediatorProperty.ATT_EXPR_Q);
+
+            MediatorProperty prop = new MediatorProperty();
+
+            if (attName == null || attName.getAttributeValue() == null ||
+                attName.getAttributeValue().trim().length() == 0) {
+                String msg = "Property name is a required attribute for a Log property";
+                log.error(msg);
+                throw new SynapseException(msg);
+            } else {
+                prop.setName(attName.getAttributeValue());
+            }
+
+            // if a value is specified, use it, else look for an expression
+            if (attValue != null) {
+                if (attValue.getAttributeValue() == null || attValue.getAttributeValue().trim().length() == 0) {
+                    String msg = "Property attribute value (if specified) is required for a Log property";
+                    log.error(msg);
+                    throw new SynapseException(msg);
+                } else {
+                    prop.setValue(attValue.getAttributeValue());
+                }
+
+            } else if (attExpr != null) {
+
+                if (attExpr.getAttributeValue() == null || attExpr.getAttributeValue().trim().length() == 0) {
+                    String msg = "Property attribute expression (if specified) is required for a mediator property";
+                    log.error(msg);
+                    throw new SynapseException(msg);
+
+                } else {
+                    try {
+                        prop.setExpression(new AXIOMXPath(attExpr.getAttributeValue()));
+
+                    } catch (JaxenException e) {
+                        String msg = "Invalid XPapth expression : " + attExpr.getAttributeValue();
+                        log.error(msg);
+                        throw new SynapseException(msg, e);
+                    }
+                }
+
+            } else {
+                String msg = "Property attribute value OR expression must be specified for a mediator property";
+                log.error(msg);
+                throw new SynapseException(msg);
+            }
+
+            propertyList.add(prop);
+        }
+
+        return propertyList;
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/PropertyMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/PropertyMediatorFactory.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/PropertyMediatorFactory.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/PropertyMediatorFactory.java Mon May  8 06:15:47 2006
@@ -0,0 +1,77 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.builtin.PropertyMediator;
+import org.apache.synapse.SynapseException;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Creates a set-property mediator through the supplied XML configuration
+ *
+ * <set-property name="string" (value="literal" | expression="xpath")/>
+ */
+public class PropertyMediatorFactory extends AbstractMediatorFactory {
+
+    private static final Log log = LogFactory.getLog(LogMediatorFactory.class);
+
+    private static final QName PROP_Q    = new QName(Constants.SYNAPSE_NAMESPACE, "set-property");
+
+    public Mediator createMediator(OMElement elem) {
+
+        PropertyMediator propMediator = new PropertyMediator();
+        OMAttribute name = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+        OMAttribute value = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "value"));
+        OMAttribute expression = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "expression"));
+
+        if (name == null) {
+            String msg = "The 'name' attribute is required for the configuration of a property mediator";
+            log.error(msg);
+            throw new SynapseException(msg);
+        } else if (value == null && expression == null) {
+            String msg = "Either an 'value' or 'expression' attribute is required for a property mediator";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+
+        propMediator.setName(name.getAttributeValue());
+        if (value != null) {
+            propMediator.setValue(value.getAttributeValue());
+        } else {
+            try {
+                propMediator.setExpression(new AXIOMXPath(expression.getAttributeValue()));
+            } catch (JaxenException e) {
+                String msg = "Invalid XPath expression for attribute 'expression' : " + expression.getAttributeValue();
+                log.error(msg);
+                throw new SynapseException(msg);
+            }
+        }
+
+        return propMediator;
+    }
+
+    public QName getTagQName() {
+        return PROP_Q;
+    }
+}

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SendMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SendMediatorFactory.java?rev=405043&r1=405035&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SendMediatorFactory.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SendMediatorFactory.java Mon May  8 06:15:47 2006
@@ -14,33 +14,57 @@
  * limitations under the License.
  */
 
-package org.apache.synapse.xml;
+package org.apache.synapse.config.xml;
 
 import javax.xml.namespace.QName;
 
 
 import org.apache.synapse.api.Mediator;
 import org.apache.synapse.mediators.builtin.SendMediator;
-import org.apache.synapse.SynapseEnvironment;
 import org.apache.axiom.om.OMElement;
 
+/**
+ * The Send mediator factory parses a Send element and creates an instance of the mediator
+ *
+ * //TODO support endpoints, failover and loadbalacing
+ *
+ * The <send> element is used to send messages out of Synapse to some endpoint. In the simplest case,
+ * the place to send the message to is implicit in the message (via a property of the message itself)-
+ * that is indicated by the following
+ *  <send/>
+ *
+ * If the message is to be sent to one or more endpoints, then the following is used:
+ *  <send>
+ *   (endpointref | endpoint)+
+ *  </send>
+ * where the endpointref token refers to the following:
+ * <endpoint ref="name"/>
+ * and the endpoint token refers to an anonymous endpoint defined inline:
+ *  <endpoint address="url"/>
+ * If the message is to be sent to an endpoint selected by load balancing across a set of endpoints,
+ * then it is indicated by the following:
+ * <send>
+ *   <load-balance algorithm="uri">
+ *     (endpointref | endpoint)+
+ *   </load-balance>
+ * </send>
+ * Similarly, if the message is to be sent to an endpoint with failover semantics, then it is indicated by the following:
+ * <send>
+ *   <failover>
+ *     (endpointref | endpoint)+
+ *   </failover>
+ * </send>
+ */
 public class SendMediatorFactory extends AbstractMediatorFactory {
 
+    private static final QName SEND_Q = new QName(Constants.SYNAPSE_NAMESPACE, "send");
 
-    private static final QName SEND_Q = new QName(Constants.SYNAPSE_NAMESPACE,
-            "send");
-
-
-
-    public Mediator createMediator(SynapseEnvironment se, OMElement el) {
+    public Mediator createMediator(OMElement el) {
         SendMediator sm =  new SendMediator();
-        super.setNameOnMediator(se, el,sm);
         return sm;
-
     }
 
     public QName getTagQName() {
-
         return SEND_Q;
     }
 

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SequenceMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SequenceMediatorFactory.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SequenceMediatorFactory.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SequenceMediatorFactory.java Mon May  8 06:15:47 2006
@@ -0,0 +1,73 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.mediators.base.SequenceMediator;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Builds an instance of a Sequence mediator through the Synapse configuration. It follows the following
+ *
+ * <sequence name="string">
+ *   mediator+
+ * </sequence>
+ *
+ * OR
+ *
+ * <sequence ref="name"/>
+ */
+public class SequenceMediatorFactory extends AbstractListMediatorFactory {
+
+    private static final Log log = LogFactory.getLog(SequenceMediatorFactory.class);
+
+    private static final QName SEQUENCE_Q = new QName(Constants.SYNAPSE_NAMESPACE, "sequence");
+
+    public QName getTagQName() {
+        return SEQUENCE_Q;
+    }
+
+    public Mediator createMediator(OMElement elem) {
+
+        SequenceMediator seqMediator = new SequenceMediator();
+
+        OMAttribute n = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+        if (n != null) {
+            seqMediator.setName(n.getAttributeValue());
+            super.addChildren(elem, seqMediator);
+
+        } else {
+            n = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "ref"));
+            if (n != null) {
+                seqMediator.setRef(n.getAttributeValue());
+                
+            } else {
+                String msg = "A sequence mediator should be a named sequence or a reference to another sequence " +
+                    "(i.e. a name attribute or ref attribute is required.";
+                log.error(msg);
+                throw new SynapseException(msg);
+            }
+        }
+        return seqMediator;
+    }
+
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SwitchCaseDefaultMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SwitchCaseDefaultMediatorFactory.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SwitchCaseDefaultMediatorFactory.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SwitchCaseDefaultMediatorFactory.java Mon May  8 06:15:47 2006
@@ -0,0 +1,47 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.filters.SwitchCaseMediator;
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Create an instance of a Switch mediators' default case (i.e. a SwitchCaseMedaitor
+ * which returns isDefault() true
+ */
+public class SwitchCaseDefaultMediatorFactory extends AbstractListMediatorFactory {
+
+    private static final Log log = LogFactory.getLog(SwitchCaseDefaultMediatorFactory.class);
+
+    private final QName SWITCH_CASE_DEFAULT_Q = new QName(Constants.SYNAPSE_NAMESPACE, "default");
+
+    public Mediator createMediator(OMElement elem) {
+
+        SwitchCaseMediator switchCaseMediator = new SwitchCaseMediator();
+        switchCaseMediator.setDefaultCase(true);
+        super.addChildren(elem, switchCaseMediator);
+        return switchCaseMediator;
+    }
+
+    public QName getTagQName() {
+        return SWITCH_CASE_DEFAULT_Q;
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SwitchCaseMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SwitchCaseMediatorFactory.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SwitchCaseMediatorFactory.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SwitchCaseMediatorFactory.java Mon May  8 06:15:47 2006
@@ -0,0 +1,61 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.filters.SwitchCaseMediator;
+import org.apache.synapse.SynapseException;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+public class SwitchCaseMediatorFactory extends AbstractListMediatorFactory {
+
+    private static final Log log = LogFactory.getLog(SwitchCaseMediatorFactory.class);
+
+    private final QName SWITCH_CASE_Q = new QName(Constants.SYNAPSE_NAMESPACE, "case");
+
+    public Mediator createMediator(OMElement elem) {
+
+        SwitchCaseMediator switchCaseMediator = new SwitchCaseMediator();
+        OMAttribute regex = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "regex"));
+        if (regex == null) {
+            String msg = "The 'regex' attribute is required for a switch case definition";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+
+        try {
+            switchCaseMediator.setRegex(Pattern.compile(regex.getAttributeValue()));
+        } catch (PatternSyntaxException pse) {
+            String msg = "Invalid Regular Expression for attribute 'regex' : " + regex.getAttributeValue();
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+
+        super.addChildren(elem, switchCaseMediator);
+        return switchCaseMediator;
+    }
+
+    public QName getTagQName() {
+        return SWITCH_CASE_Q;
+    }
+}
\ No newline at end of file

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SwitchMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SwitchMediatorFactory.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SwitchMediatorFactory.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SwitchMediatorFactory.java Mon May  8 06:15:47 2006
@@ -0,0 +1,70 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.filters.SwitchMediator;
+import org.apache.synapse.mediators.filters.SwitchCaseMediator;
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+
+/**
+ * Constructs a Switch mediator instance from the given XML configuration
+ *
+ * <switch source="xpath">
+ *   <case regex="string">
+ *     mediator+
+ *   </case>+
+ *   <default>
+ *     mediator+
+ *   </default>?
+ * </switch>
+ */
+public class SwitchMediatorFactory extends AbstractMediatorFactory {
+
+    private static final Log log = LogFactory.getLog(SwitchMediatorFactory.class);
+
+    private static final QName SWITCH_Q  = new QName(Constants.SYNAPSE_NAMESPACE, "switch");
+    private static final QName CASE_Q    = new QName(Constants.SYNAPSE_NAMESPACE, "case");
+    private static final QName DEFAULT_Q = new QName(Constants.SYNAPSE_NAMESPACE, "default");
+
+    public Mediator createMediator(OMElement elem) {
+
+        SwitchMediator switchMediator = new SwitchMediator();
+        Iterator iter = elem.getChildrenWithName(CASE_Q);
+        while (iter.hasNext()) {
+            switchMediator.addCase((SwitchCaseMediator)
+                MediatorFactoryFinder.getInstance().getMediator((OMElement) iter.next()));
+        }
+
+        iter = elem.getChildrenWithName(DEFAULT_Q);
+        while (iter.hasNext()) {
+            switchMediator.addCase((SwitchCaseMediator)
+                MediatorFactoryFinder.getInstance().getMediator((OMElement) iter.next()));
+            break; // add only the *first* default if multiple are specified, ignore rest if any
+        }
+
+        return switchMediator;
+    }
+
+    public QName getTagQName() {
+        return SWITCH_Q;
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SynapseConfigurationBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SynapseConfigurationBuilder.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SynapseConfigurationBuilder.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SynapseConfigurationBuilder.java Mon May  8 06:15:47 2006
@@ -0,0 +1,135 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.mediators.base.SequenceMediator;
+import org.apache.synapse.mediators.base.SynapseMediator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.namespace.QName;
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Iterator;
+
+
+/**
+ * Builds a Synapse Configuration model from an XML input stream.
+ */
+public class SynapseConfigurationBuilder {
+
+    private static Log log = LogFactory.getLog(SynapseConfigurationBuilder.class);
+    private SynapseConfiguration config = new SynapseConfiguration();
+
+    public SynapseConfigurationBuilder() {}
+
+    public SynapseConfiguration getConfig() {
+        return config;
+    }
+
+    public void setConfiguration(InputStream is) {
+
+        OMElement root = null;
+        try {
+            root = new StAXOMBuilder(is).getDocumentElement();
+        } catch (XMLStreamException e) {
+            String msg = "Error parsing Synapse configuration : " + e.getMessage();
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+        root.build();
+
+        // digest defined Sequences
+        OMContainer definitions = root.getFirstChildWithName(Constants.DEFINITIONS_ELT);
+        if (definitions != null) {
+            Iterator iter = definitions.getChildrenWithName(Constants.SEQUENCE_ELT);
+            while (iter.hasNext()) {
+                OMElement elt = (OMElement) iter.next();
+                defineSequence(elt);
+            }
+        }
+
+        // digest defined Endpoints
+        OMContainer endpoints = root.getFirstChildWithName(Constants.ENDPOINT_ELT);
+        if (endpoints != null) {
+            Iterator iter = endpoints.getChildrenWithName(Constants.ENDPOINT_ELT);
+            while (iter.hasNext()) {
+                OMElement elt = (OMElement) iter.next();
+                //defineEndpoint(synCfg, elt); //TODO process Endpoints
+            }
+        }
+
+        // digest defined Global properties
+        OMContainer properties = root.getFirstChildWithName(Constants.PROPERTY_ELT);
+        if (properties != null) {
+            Iterator iter = properties.getChildrenWithName(Constants.PROPERTY_ELT);
+            while (iter.hasNext()) {
+                OMElement elt = (OMElement) iter.next();
+                defineProperty(elt);
+            }
+        }
+
+        OMElement elem = root.getFirstChildWithName(Constants.RULES_ELT);
+        if (elem == null) {
+            String msg = "A valid Synapse configuration MUST specify the main mediator using the <rules> element";
+            log.error(msg);
+            throw new SynapseException(msg);
+        } else {
+            SynapseMediator sm = (SynapseMediator) MediatorFactoryFinder.getInstance().getMediator(elem);
+            if (sm.getList().isEmpty()) {
+                String msg = "Invalid configuration, the main mediator specified by the <rules> element is empty";
+                log.error(msg);
+                throw new SynapseException(msg);
+            } else {
+                config.setMainMediator(sm);
+            }
+        }
+
+        if (is != null) {
+            try {
+                is.close();
+            } catch (IOException e) {}
+        }
+    }
+
+    /**
+     * <set-property name="string" value="string"/>
+     * @param elem
+     */
+    private void defineProperty(OMElement elem) {
+        OMAttribute name  = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+        OMAttribute value = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "value"));
+        if (name == null || value == null) {
+            String msg = "The 'name' and 'value' attributes are required";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+        config.addProperty(name.getAttributeValue(), value.getAttributeValue());
+    }
+
+    private void defineSequence(OMElement ele) {
+        SequenceMediator seq = (SequenceMediator) MediatorFactoryFinder.getInstance().getMediator(ele);
+        config.addNamedMediator(seq.getName(), seq);
+    }
+
+}

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SynapseMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SynapseMediatorFactory.java?rev=405043&r1=405035&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SynapseMediatorFactory.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/SynapseMediatorFactory.java Mon May  8 06:15:47 2006
@@ -14,28 +14,33 @@
  * limitations under the License.
  */
 
-package org.apache.synapse.xml;
+package org.apache.synapse.config.xml;
 
 import javax.xml.namespace.QName;
 
-import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.config.xml.Constants;
 import org.apache.synapse.api.Mediator;
 import org.apache.synapse.mediators.base.SynapseMediator;
 import org.apache.axiom.om.OMElement;
 
-public class SynapseMediatorFactory extends
-        AbstractListMediatorFactory {
+/**
+ * Builds the main mediator (@see SynapseConfiguration) of the Synapse instance
+ *
+ * <rules>
+ *   mediator+
+ * <rules>
+ */
+public class SynapseMediatorFactory extends AbstractListMediatorFactory {
 
-    private final static QName tagname = new QName(Constants.SYNAPSE_NAMESPACE,
-            "synapse");
+    private final static QName tagname = new QName(Constants.SYNAPSE_NAMESPACE, "rules");
 
     public QName getTagQName() {
         return tagname;
     }
 
-    public Mediator createMediator(SynapseEnvironment se, OMElement el) {
+    public Mediator createMediator(OMElement elem) {
         SynapseMediator sm = new SynapseMediator();
-        super.addChildrenAndSetName(se, el, sm);
+        super.addChildren(elem, sm);
         return sm;
     }
 

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/TransformMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/TransformMediatorFactory.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/TransformMediatorFactory.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/TransformMediatorFactory.java Mon May  8 06:15:47 2006
@@ -0,0 +1,94 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.mediators.transform.TransformMediator;
+import org.apache.synapse.api.Mediator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+import javax.xml.namespace.QName;
+import java.net.URL;
+import java.net.MalformedURLException;
+
+/**
+ * Creates a transform mediator from the given XML
+ *
+ * <transform xslt|xquery="url" [source="xpath"]>
+ *   <property name="string" (value="literal" | expression="xpath")/>*
+ * </transform>
+ */
+public class TransformMediatorFactory extends AbstractMediatorFactory {
+
+    private static final Log log = LogFactory.getLog(TransformMediatorFactory.class);
+    private static final QName LOG_Q    = new QName(Constants.SYNAPSE_NAMESPACE, "transform");
+
+    public QName getTagQName() {
+        return LOG_Q;
+    }
+
+    public Mediator createMediator(OMElement elem) {
+
+        TransformMediator transformMediator = new TransformMediator();
+
+        OMAttribute attXslt   = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "xslt"));
+        OMAttribute attXQuery = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "xquery"));
+        OMAttribute attSource = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "source"));
+
+        if (attXslt != null) {
+            try {
+                transformMediator.setXsltUrl(new URL(attXslt.getAttributeValue()));
+            } catch (MalformedURLException e) {
+                String msg = "Invalid URL specified for the xslt attribute : " + attXslt.getAttributeValue();
+                log.error(msg);
+                throw new SynapseException(msg);
+            }
+
+        } else  if (attXQuery != null) {
+            try {
+                transformMediator.setXQueryUrl(new URL(attXQuery.getAttributeValue()));
+            } catch (MalformedURLException e) {
+                String msg = "Invalid URL specified for the xquery attribute : " + attXQuery.getAttributeValue();
+                log.error(msg);
+                throw new SynapseException(msg);
+            }
+
+        } else {
+            String msg = "The 'xslt' or 'xquery' attributes are required for the Transform mediator";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+
+        if (attSource != null) {
+            try {
+                transformMediator.setSource(new AXIOMXPath(attSource.getAttributeValue()));
+            } catch (JaxenException e) {
+                String msg = "Invalid XPath specified for the source attribute : " + attSource.getAttributeValue();
+                log.error(msg);
+                throw new SynapseException(msg);
+            }
+
+        }
+
+        return transformMediator;
+    }
+
+}
\ No newline at end of file

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/ValidateMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/ValidateMediatorFactory.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/ValidateMediatorFactory.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/ValidateMediatorFactory.java Mon May  8 06:15:47 2006
@@ -0,0 +1,88 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.builtin.ValidateMediator;
+import org.apache.synapse.SynapseException;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Creates a validation mediator from the XML configuration
+ *
+ * <validate schema="url" [source="xpath"]>
+ *   <on-fail>
+ *     mediator+
+ *   </on-fail>
+ * </validate>
+ */
+public class ValidateMediatorFactory extends AbstractListMediatorFactory {
+
+    private static final Log log = LogFactory.getLog(TransformMediatorFactory.class);
+    private static final QName VALIDATE_Q    = new QName(Constants.SYNAPSE_NAMESPACE, "validate");
+
+    public Mediator createMediator(OMElement elem) {
+
+        ValidateMediator validateMediator = new ValidateMediator();
+        OMAttribute attSchema = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "schema"));
+        OMAttribute attSource = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "source"));
+
+        if (attSchema != null) {
+            validateMediator.setSchemaUrl(attSchema.getAttributeValue());
+        } else {
+            String msg = "The 'schema' attribute is required for the validate mediator configuration";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+
+        if (attSource != null) {
+            try {
+                AXIOMXPath xp = new AXIOMXPath(attSource.getAttributeValue());
+                validateMediator.setSource(xp);
+                addNameSpaces(elem, xp, log);
+
+            } catch (JaxenException e) {
+                String msg = "Invalid XPath expression specified for attribute 'source'";
+                log.error(msg);
+                throw new SynapseException(msg, e);
+            }
+        }
+
+        OMElement onFail = elem.getFirstElement();
+        if (new QName(Constants.SYNAPSE_NAMESPACE, "on-fail").equals(onFail.getQName()) &&
+            onFail.getChildElements().hasNext()) {
+            super.addChildren(onFail, validateMediator);
+
+        } else {
+            String msg = "A non-empty on-fail element is required for the validate mediator";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+
+        return validateMediator;
+    }
+
+    public QName getTagQName() {
+        return VALIDATE_Q;
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/SynapseEnvironment.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/SynapseEnvironment.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/SynapseEnvironment.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/SynapseEnvironment.java Mon May  8 06:15:47 2006
@@ -0,0 +1,44 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.core;
+
+import org.apache.synapse.SynapseContext;
+
+/**
+ * The SynapseEnvironment allows access into the the host SOAP engine. It allows
+ * the sending of messages, classloader access etc.
+ */
+public interface SynapseEnvironment {
+
+    /**
+     * This method injects a new message into the Synapse engine. This is used by
+     * the underlying SOAP engine to inject messages into Synapse for mediation.
+     * e.g. The SynapseMessageReceiver used by Axis2 invokes this to inject new messages
+     */
+    public void injectMessage(SynapseContext smc);
+
+    /**
+     * Mediators may get access to the relevant classloader through this
+     */
+    public ClassLoader getClassLoader();
+
+    /**
+     * This method allows a message to be sent through the underlying SOAP engine.
+     * <p/>
+     * This will send request messages on (forward), and send the response messages back to the client
+     */
+    public void send(SynapseContext smc);
+}

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java?rev=405043&r1=405035&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java Mon May  8 06:15:47 2006
@@ -14,33 +14,30 @@
  * limitations under the License.
  */
 
-package org.apache.synapse.axis2;
+package org.apache.synapse.core.axis2;
 
 
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axiom.soap.SOAPHeaderBlock;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.client.OperationClient;
+import org.apache.axis2.client.Options;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.ServiceContext;
 import org.apache.axis2.context.ServiceGroupContext;
+import org.apache.axis2.deployment.util.PhasesInfo;
 import org.apache.axis2.description.*;
 import org.apache.axis2.engine.AxisConfiguration;
-
 import org.apache.axis2.util.UUIDGenerator;
 import org.apache.axis2.wsdl.WSDLConstants;
-import org.apache.axis2.deployment.util.PhasesInfo;
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.addressing.AddressingConstants;
-import org.apache.axis2.client.OperationClient;
-import org.apache.axis2.client.Options;
-
 import org.apache.synapse.Constants;
-import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.SOAPHeader;
-import org.apache.axiom.soap.SOAPHeaderBlock;
-
 
 import javax.xml.namespace.QName;
-import java.util.Iterator;
 import java.util.ArrayList;
+import java.util.Iterator;
 
 
 /**
@@ -54,13 +51,13 @@
         ArrayList addressingHeaders;
         if (soapHeader != null) {
             addressingHeaders = soapHeader.getHeaderBlocksWithNSURI(
-                    AddressingConstants.Submission.WSA_NAMESPACE);
+                AddressingConstants.Submission.WSA_NAMESPACE);
             if (addressingHeaders != null && addressingHeaders.size() != 0) {
                 detachAddressingInformation(addressingHeaders);
 
             } else {
                 addressingHeaders = soapHeader.getHeaderBlocksWithNSURI(
-                        AddressingConstants.Final.WSA_NAMESPACE);
+                    AddressingConstants.Final.WSA_NAMESPACE);
                 if (addressingHeaders != null && addressingHeaders.size() != 0) {
                     detachAddressingInformation(addressingHeaders);
                 }
@@ -70,7 +67,6 @@
     }
 
     /**
-     *
      * @param headerInformation
      */
     private static void detachAddressingInformation(ArrayList headerInformation) {
@@ -97,18 +93,18 @@
         if (ac.getService("__ANONYMOUS_SERVICE__") == null) {
             // Lets default be OUT_IN
             OutInAxisOperation outInOperation =
-                    new OutInAxisOperation(new QName(
-                            "__OPERATION_OUT_IN__"));
+                new OutInAxisOperation(new QName(
+                    "__OPERATION_OUT_IN__"));
             AxisService axisAnonymousService =
-                    new AxisService("__ANONYMOUS_SERVICE__");
+                new AxisService("__ANONYMOUS_SERVICE__");
             axisAnonymousService.addOperation(outInOperation);
             ac.addService(axisAnonymousService);
             phasesInfo.setOperationPhases(outInOperation);
         }
         ServiceGroupContext sgc = new ServiceGroupContext(cc,
-                (AxisServiceGroup)ac.getService("__ANONYMOUS_SERVICE__").getParent());
+            (AxisServiceGroup) ac.getService("__ANONYMOUS_SERVICE__").getParent());
         ServiceContext sc =
-                sgc.getServiceContext(new AxisService("__ANONYMOUS_SERVICE__"));
+            sgc.getServiceContext(new AxisService("__ANONYMOUS_SERVICE__"));
 
         MessageContext mc = new MessageContext();
         mc.setConfigurationContext(sc.getConfigurationContext());
@@ -124,17 +120,17 @@
             mc.setMessageID(smc.getMessageID());
         else
             mc.setMessageID(String.valueOf("uuid:"
-                    + UUIDGenerator.getUUID()));
+                + UUIDGenerator.getUUID()));
         if (smc.getReplyTo() != null)
             mc.setReplyTo(smc.getReplyTo());
-        if (smc.getRelatesTo() != null)
-            mc.setRelatesTo(smc.getRelatesTo());
-        if (smc.getTo() != null) {
-            mc.setTo(smc.getTo());
-        } else {
-            throw new AxisFault(
+        //if (smc.getRelatesTo() != null)
+            //mc.setRelatesTo(smc.getRelatesTo());
+            if (smc.getTo() != null) {
+                mc.setTo(smc.getTo());
+            } else {
+                throw new AxisFault(
                     "To canno't be null, if null Synapse can't infer the transport");
-        }
+            }
         if (smc.isDoingREST()) {
             mc.setDoingREST(true);
         }
@@ -142,37 +138,35 @@
         // handling the outbound message with addressing
         AxisModule module = ac.getModule(new QName(org.apache.axis2.Constants.MODULE_ADDRESSING));
         if ((smc.getProperty(Constants.ENGAGE_ADDRESSING_IN_MESSAGE) != null) ||
-                (smc.getProperty(
-                        Constants.ENGAGE_ADDRESSING_OUT_BOUND_MESSAGE) != null)){
+            (smc.getProperty(
+                Constants.ENGAGE_ADDRESSING_OUT_BOUND_MESSAGE) != null)) {
             if (!ac.getService("__ANONYMOUS_SERVICE__")
-                    .isEngaged(module.getName())) {
+                .isEngaged(module.getName())) {
                 ac.getService("__ANONYMOUS_SERVICE__").engageModule(module, ac);
             }
         }
 
-
         //TODO; following line needed to be removed
 
         mc.setEnvelope(outEnvelopeConfiguration(smc));
 
         AxisOperation axisAnonymousOperation =
-                ac.getService("__ANONYMOUS_SERVICE__")
-                        .getOperation(new QName("__OPERATION_OUT_IN__"));
+            ac.getService("__ANONYMOUS_SERVICE__")
+                .getOperation(new QName("__OPERATION_OUT_IN__"));
 
         //Options class from Axis2 holds client side settings
         Options options = new Options();
         OperationClient mepClient =
-                axisAnonymousOperation.createClient(sc, options);
+            axisAnonymousOperation.createClient(sc, options);
         mepClient.addMessageContext(mc);
         mepClient.execute(true);
         MessageContext response = mepClient
-                .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+            .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
         response.setProperty(MessageContext.TRANSPORT_OUT,
-                smc.getProperty(MessageContext.TRANSPORT_OUT));
+            smc.getProperty(MessageContext.TRANSPORT_OUT));
         response.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO,
-                smc.getProperty(
-                        org.apache.axis2.Constants.OUT_TRANSPORT_INFO));
-
+            smc.getProperty(
+                org.apache.axis2.Constants.OUT_TRANSPORT_INFO));
 
         // If request is REST we assume the response is REST, so set the
         // variable
@@ -180,9 +174,9 @@
         response.setProperty(Constants.ISRESPONSE_PROPERTY, Boolean.TRUE);
 
         if (ac.getService("__ANONYMOUS_SERVICE__")
-                .isEngaged(module.getName())) {
+            .isEngaged(module.getName())) {
             ac.getService("__ANONYMOUS_SERVICE__")
-                    .disEngageModule(ac.getModule(module.getName()));
+                .disEngageModule(ac.getModule(module.getName()));
         }
         return response;
     }

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2Sender.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2Sender.java?rev=405043&r1=405035&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2Sender.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2Sender.java Mon May  8 06:15:47 2006
@@ -14,19 +14,16 @@
  * limitations under the License.
  */
 
-package org.apache.synapse.axis2;
+package org.apache.synapse.core.axis2;
 
 import org.apache.axis2.AxisFault;
-
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.TransportInDescription;
-
 import org.apache.axis2.engine.AxisEngine;
-
 import org.apache.synapse.Constants;
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.SynapseMessage;
-
+import org.apache.synapse.SynapseContext;
 
 
 /**
@@ -34,71 +31,66 @@
  */
 public class Axis2Sender {
 
-    public static void sendOn(SynapseMessage smc) {
+    public static void sendOn(SynapseContext smc) {
 
         try {
 
-            MessageContext messageContext = ((Axis2SynapseMessage) smc)
-                    .getMessageContext();
+            MessageContext messageContext = ((Axis2SynapseMessage) smc.getSynapseMessage()).getMessageContext();
             // At any time any QOS is disengaged. It's engaged iff, a flag is
             // set in execution chain.
             // ex: addressing will be engage in outpath iff ADDRESSING_PROCESSED
             // is set.
 
-            if (smc.getProperty(Constants.ENGAGE_ADDRESSING_IN_MESSAGE) != null)
-            {
+            if (smc.getProperty(Constants.ENGAGE_ADDRESSING_IN_MESSAGE) != null) {
 
                 messageContext.setProperty(
-                        Constants.ENGAGE_ADDRESSING_IN_MESSAGE, Boolean.TRUE);
+                    Constants.ENGAGE_ADDRESSING_IN_MESSAGE, Boolean.TRUE);
 
             }
             //Now hadle the outbound message with addressing
             if (smc.getProperty(
-                    Constants.ENGAGE_ADDRESSING_OUT_BOUND_MESSAGE) != null) {
+                Constants.ENGAGE_ADDRESSING_OUT_BOUND_MESSAGE) != null) {
                 messageContext.setProperty(
-                        Constants.ENGAGE_ADDRESSING_OUT_BOUND_MESSAGE,
-                        Boolean.TRUE);
+                    Constants.ENGAGE_ADDRESSING_OUT_BOUND_MESSAGE,
+                    Boolean.TRUE);
 
             }
 
             MessageContext outMsgContext = Axis2FlexibleMEPClient
-                    .send(messageContext);
+                .send(messageContext);
 
             // run all rules on response
 
-            smc.setResponse(true);//
+            smc.getSynapseMessage().setResponse(true);//
 
             outMsgContext.setServerSide(true);
 
             Object os = messageContext
-                    .getProperty(MessageContext.TRANSPORT_OUT);
+                .getProperty(MessageContext.TRANSPORT_OUT);
             outMsgContext.setProperty(MessageContext.TRANSPORT_OUT, os);
             TransportInDescription ti = messageContext.getTransportIn();
 
             outMsgContext.setTransportIn(ti);
 
-            if (smc.getSynapseEnvironment() == null) {
-                throw new SynapseException("no Synapse Env set on message");
-            }
-            smc.getSynapseEnvironment().injectMessage(new Axis2SynapseMessage(
-                    outMsgContext, smc.getSynapseEnvironment()));
+            smc.setSynapseMessage(new Axis2SynapseMessage(outMsgContext, smc));
+            smc.getSynapseEnvironment().injectMessage(smc);
+
         } catch (Exception e) {
             e.printStackTrace();
             throw new SynapseException(e);
         }
     }
 
-    public static void sendBack(SynapseMessage smc) {
-        MessageContext messageContext = ((Axis2SynapseMessage) smc)
-                .getMessageContext();
+    public static void sendBack(SynapseContext smc) {
+        MessageContext messageContext = ((Axis2SynapseMessage) smc.getSynapseMessage()).getMessageContext();
         AxisEngine ae =
-                new AxisEngine(messageContext.getConfigurationContext());
+            new AxisEngine(messageContext.getConfigurationContext());
         try {
 //
 
 
             messageContext
-                    .setProperty(Constants.ISRESPONSE_PROPERTY, Boolean.TRUE);
+                .setProperty(Constants.ISRESPONSE_PROPERTY, Boolean.TRUE);
             // check for addressing is alredy engaged for this message.
             // if engage we should use the address enable Configuraion context.
 //

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseContextFinder.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseContextFinder.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseContextFinder.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseContextFinder.java Mon May  8 06:15:47 2006
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.synapse.core.axis2;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.Constants;
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.synapse.config.xml.SynapseConfigurationBuilder;
+import org.apache.synapse.config.SynapseConfiguration;
+
+import java.io.InputStream;
+
+/**
+ * <p/>
+ * The SynapseContext needs to be set up and then is used by the SynapseMessageReceiver to inject messages.
+ * This class is used by the SynapseMessageReceiver to find the environment. The env is stored in a Parameter to the Axis2 config
+ */
+public class Axis2SynapseContextFinder implements Constants {
+
+    private static Log log = LogFactory.getLog(Axis2SynapseContextFinder.class);
+
+    public static synchronized SynapseContext getSynapseContext(MessageContext mc) {
+
+        SynapseConfiguration synCfg = getSynapseConfig(mc);
+        SynapseEnvironment   synEnv = getSynapseEnvironment(mc);
+
+        if (synCfg == null || synEnv == null) {
+            initializeSynapse(mc);
+            synCfg = getSynapseConfig(mc);
+            synEnv = getSynapseEnvironment(mc);
+        }
+
+        if (synCfg == null || synEnv == null) {
+            String msg = "Synapse could/has not been properly initialized";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+
+        SynapseContext synCtx = new Axis2SynapseMessageContext();
+        synCtx.setSynapseEnvironment(synEnv);
+        synCtx.setConfiguration(synCfg);
+        synCtx.setSynapseMessage(new Axis2SynapseMessage(mc, synCtx));
+        return synCtx;        
+    }
+
+    /**
+     * Create the SynapseConfiguration and SynapseEnvironment objects and set them into the Axis2 configuration
+     * for reuse
+     * @param mc the current Axis2 message context
+     */
+    private static synchronized void initializeSynapse(MessageContext mc) {
+
+        if (getSynapseConfig(mc) != null && getSynapseEnvironment(mc) != null) {
+            // is this a second thread which came in just after initialization?
+            return;
+        }
+
+        log.debug("Synapse Config not available. Creating...");
+        AxisConfiguration ac = mc.getConfigurationContext().getAxisConfiguration();
+        Parameter param = ac.getParameter(SYNAPSE_CONFIGURATION);
+        if (param == null) {
+            throw new SynapseException(
+                "Axis2 configuration does not specify a '" + SYNAPSE_CONFIGURATION + "' parameter");
+        }
+        InputStream is = mc.getAxisService().getClassLoader().getResourceAsStream(((String) param.getValue()).trim());
+
+        SynapseConfigurationBuilder cfgBuilder = new SynapseConfigurationBuilder();
+        cfgBuilder.setConfiguration(is);
+
+        Parameter synapseCtxParam = new Parameter(SYNAPSE_CONFIG, null);
+        synapseCtxParam.setValue(cfgBuilder.getConfig());
+
+        Parameter synapseEnvParam = new Parameter(SYNAPSE_ENV, null);
+        synapseEnvParam.setValue(new Axis2SynapseEnvironment(mc.getAxisService().getClassLoader()));
+
+        try {
+            ac.addParameter(synapseCtxParam);
+            ac.addParameter(synapseEnvParam);
+
+        } catch (AxisFault e) {
+            String msg = "Could not set parameters '" + SYNAPSE_CONFIG + "' and/or '" + SYNAPSE_ENV +
+                "'to the Axis2 configuration";
+            log.error(msg);
+            throw new SynapseException(msg, e);
+        }
+    }
+
+    private static SynapseConfiguration getSynapseConfig(MessageContext mc) {
+        AxisConfiguration ac = mc.getConfigurationContext().getAxisConfiguration();
+        Parameter synConfigParam = ac.getParameter(SYNAPSE_CONFIG);
+        if (synConfigParam != null) {
+            return (SynapseConfiguration) synConfigParam.getValue();
+        }
+        return null;
+    }
+
+    private static SynapseEnvironment getSynapseEnvironment(MessageContext mc) {
+        AxisConfiguration ac = mc.getConfigurationContext().getAxisConfiguration();
+        Parameter synEnvParam = ac.getParameter(SYNAPSE_ENV);
+        if (synEnvParam != null) {
+            return (SynapseEnvironment) synEnvParam.getValue();
+        }
+        return null;
+    }
+
+}

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseMessage.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseMessage.java?rev=405043&r1=405035&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseMessage.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseMessage.java Mon May  8 06:15:47 2006
@@ -14,40 +14,40 @@
  * limitations under the License.
  */
 
-package org.apache.synapse.axis2;
+package org.apache.synapse.core.axis2;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
+import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.addressing.RelatesTo;
 import org.apache.axis2.context.MessageContext;
 import org.apache.synapse.Constants;
-import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseContext;
 import org.apache.synapse.SynapseMessage;
-import org.apache.axiom.soap.SOAPEnvelope;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 /**
- *
- * 
- * <p>
+ * <p/>
  * A wrapper on Axis2's Message Context that implements the SynapseMessage interface
- *
  */
 public class Axis2SynapseMessage implements SynapseMessage {
 
+    /** The Axis2 MessageContext reference */
     private MessageContext mc = null;
 
-    private Map props = new HashMap();
+    /** The Synapse Context reference*/
+    private SynapseContext synCtx = null;
 
     private boolean response = false;
 
     private boolean faultResponse = false;
 
-    public Axis2SynapseMessage(MessageContext mc, SynapseEnvironment se) {
+    public Axis2SynapseMessage(MessageContext mc, SynapseContext synCtx) {
         setMessageContext(mc);
-        setSynapseEnvironment(se);
+        setSynapseContext(synCtx);
     }
 
     public EndpointReference getFaultTo() {
@@ -64,17 +64,14 @@
 
     public void setFrom(EndpointReference reference) {
         mc.setFrom(reference);
-
     }
 
     public SOAPEnvelope getEnvelope() {
-
         return mc.getEnvelope();
     }
 
     public void setEnvelope(SOAPEnvelope envelope) throws AxisFault {
         mc.setEnvelope(envelope);
-
     }
 
     public String getMessageID() {
@@ -83,120 +80,76 @@
 
     public void setMessageID(String string) {
         mc.setMessageID(string);
-
     }
 
     public RelatesTo getRelatesTo() {
         return mc.getRelatesTo();
-
     }
 
-    public void setRelatesTo(RelatesTo reference) {
-        mc.setRelatesTo(reference);
-
+    public void setRelatesTo(RelatesTo[] reference) {
+        mc.setRelationships(reference);
     }
 
     public EndpointReference getReplyTo() {
         return mc.getReplyTo();
-
     }
 
     public void setReplyTo(EndpointReference reference) {
         mc.setReplyTo(reference);
-
     }
 
     public EndpointReference getTo() {
         return mc.getTo();
-
     }
 
     public void setTo(EndpointReference reference) {
         mc.setTo(reference);
-
     }
 
     public void setWSAAction(String actionURI) {
         mc.setWSAAction(actionURI);
-
     }
 
     public String getWSAAction() {
-
         return mc.getWSAAction();
     }
 
     public void setMessageId(String messageID) {
         mc.setWSAMessageId(messageID);
-
     }
 
     public String getMessageId() {
         return mc.getMessageID();
     }
 
-    public Object getProperty(String key) {
-        Object obj = props.get(key);
-        if ( obj == null) {
-            obj = mc.getProperty(key);
-        }
-        return obj;
-
-    }
-
-    public void setProperty(String key, Object value) {
-        props.put(key, value);
-    }
-
-    public Iterator getPropertyNames() {
-        return props.keySet().iterator();
-    }
-
     public String getSoapAction() {
         return mc.getSoapAction();
     }
 
     public void setSoapAction(String string) {
         mc.setSoapAction(string);
-
     }
 
     public boolean isDoingMTOM() {
-
         return mc.isDoingMTOM();
     }
 
     public void setDoingMTOM(boolean b) {
         mc.setDoingMTOM(b);
-
     }
 
     public boolean isDoingREST() {
-
         return mc.isDoingREST();
     }
 
     public void setDoingREST(boolean b) {
         mc.setDoingREST(b);
-
     }
 
     public boolean isSOAP11() {
-
         return mc.isSOAP11();
     }
 
-    public MessageContext getMessageContext() {
-        return mc;
-    }
-
-    public void setMessageContext(MessageContext mc) {
-        this.mc = mc;
-        Boolean resp = (Boolean) mc.getProperty(Constants.ISRESPONSE_PROPERTY);
-        if (resp != null)
-            response = resp.booleanValue();
-    }
-
     public void setResponse(boolean b) {
         response = b;
         mc.setProperty(Constants.ISRESPONSE_PROPERTY, Boolean.valueOf(b));
@@ -214,15 +167,23 @@
         return this.faultResponse;
     }
 
-	public SynapseEnvironment getSynapseEnvironment() {
-		return Axis2SynapseEnvironmentFinder.getSynapseEnvironment(mc);
-	}
-
-	public void setSynapseEnvironment(SynapseEnvironment env) {
-		Axis2SynapseEnvironmentFinder.setSynapseEnvironment(mc, env);
-		return;
-	}
-	
-	
+    public SynapseContext getSynapseContext() {
+        return synCtx;
+    }
+
+    public void setSynapseContext(SynapseContext synCtx) {
+        this.synCtx = synCtx;
+    }
+
+    public MessageContext getMessageContext() {
+        return mc;
+    }
+
+    public void setMessageContext(MessageContext mc) {
+        this.mc = mc;
+        Boolean resp = (Boolean) mc.getProperty(Constants.ISRESPONSE_PROPERTY);
+        if (resp != null)
+            response = resp.booleanValue();
+    }
 
 }

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseMessageContext.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseMessageContext.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseMessageContext.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseMessageContext.java Mon May  8 06:15:47 2006
@@ -0,0 +1,64 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.core.axis2;
+
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.synapse.config.SynapseConfiguration;
+
+import java.util.Map;
+import java.util.HashMap;
+
+public class Axis2SynapseMessageContext implements SynapseContext {
+
+    private SynapseConfiguration cfg = null;
+    private SynapseEnvironment   env = null;
+    private SynapseMessage       msg = null;
+    private Map properties = new HashMap();
+
+    public SynapseConfiguration getConfiguration() {
+        return cfg;
+    }
+
+    public void setConfiguration(SynapseConfiguration cfg) {
+        this.cfg = cfg;
+    }
+
+    public SynapseEnvironment getSynapseEnvironment() {
+        return env;
+    }
+
+    public void setSynapseEnvironment(SynapseEnvironment env) {
+        this.env = env;
+    }
+
+    public void setSynapseMessage(SynapseMessage msg) {
+        this.msg = msg;
+    }
+
+    public SynapseMessage getSynapseMessage() {
+        return msg;
+    }
+
+    public Object getProperty(String key) {
+        return properties.get(key);
+    }
+
+    public void setProperty(String key, Object value) {
+        properties.put(key, value);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org


Mime
View raw message