This patch stores the Spring configurations as simple properties into the SynapseConfiguration; we also support inlined configuration

asankha


I wasn't suggesting that we put endpoints, sequences etc. into this
property bag. Rather, if any mediator wants to save some state /
context / whatever, then they can put it into the property bag and save
it. We just document saying the names are flat so use your creativity to
make good names!

Index: modules/core/src/org/apache/synapse/config/Configuration.java
===================================================================
--- modules/core/src/org/apache/synapse/config/Configuration.java       
(revision 407499)
+++ modules/core/src/org/apache/synapse/config/Configuration.java       
(working copy)
@@ -1,58 +0,0 @@
-/*
-* 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;
-
-import java.util.Map;
-import java.util.HashMap;
-
-public class Configuration {
-
-    /** The name of this configuration */
-    private String name;
-    /** The type of this named Configuration */
-    private String type;
-
-    /**
-     * Custom (extensible properties of this configuration
-     * e.g. type=Spring, file=url etc
-     */
-    private Map properties = new HashMap();
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getType() {
-        return type;
-    }
-
-    public void setType(String type) {
-        this.type = type;
-    }
-
-    public void addProperty(String name, String value) {
-        properties.put(name, value);
-    }
-
-    public String getProperty(String name) {
-        return (String) properties.get(name);
-    }
-}
-
Index: modules/core/src/org/apache/synapse/config/Extension.java
===================================================================
--- modules/core/src/org/apache/synapse/config/Extension.java   (revision 
405612)
+++ modules/core/src/org/apache/synapse/config/Extension.java   (working copy)
@@ -18,41 +18,11 @@
 import java.util.Map;
 import java.util.HashMap;
 
-public class Configuration {
+public interface Extension {
 
-    /** The name of this configuration */
-    private String name;
-    /** The type of this named Configuration */
-    private String type;
+    public String getName();
 
-    /**
-     * Custom (extensible properties of this configuration
-     * e.g. type=Spring, file=url etc
-     */
-    private Map properties = new HashMap();
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getType() {
-        return type;
-    }
-
-    public void setType(String type) {
-        this.type = type;
-    }
-
-    public void addProperty(String name, String value) {
-        properties.put(name, value);
-    }
-
-    public String getProperty(String name) {
-        return (String) properties.get(name);
-    }
+    public void setName(String name);
+    
 }
 
Index: modules/core/src/org/apache/synapse/config/SynapseConfiguration.java
===================================================================
--- modules/core/src/org/apache/synapse/config/SynapseConfiguration.java        
(revision 407499)
+++ modules/core/src/org/apache/synapse/config/SynapseConfiguration.java        
(working copy)
@@ -34,9 +34,6 @@
     /** Holds named endpoints (which results into absolute EPRs) for reuse */
     private Map namedEndpoints = new HashMap();
 
-    /** Holds named configurations (such as Spring configurations) */
-    private Map namedConfigurations = new HashMap();
-
     /** Holds global (system-wide) properties that apply to the synapse 
instance and every message */
     private Map globalProps = new HashMap();
 
@@ -80,11 +77,11 @@
     }
 
     /**
-     * Add a global (system-wide) property. These properties must be string 
literals
+     * Add a global (system-wide) property.
      * @param name the name of the property
-     * @param value its string value
+     * @param value its value
      */
-    public void addProperty(String name, String value) {
+    public void addProperty(String name, Object value) {
         globalProps.put(name, value);
     }
 
@@ -93,8 +90,8 @@
      * @param name key of the property being looked up
      * @return its value
      */
-    public String getProperty(String name) {
-        return (String) globalProps.get(name);
+    public Object getProperty(String name) {
+        return globalProps.get(name);
     }
 
     /**
@@ -115,21 +112,4 @@
         return (Endpoint) namedEndpoints.get(name);
     }
 
-    /**
-     * Define a named Configuration with the given name
-     * @param name the name of the Configuration
-     * @param config the Configuration definition
-     */
-    public void addNamedConfiguration(String name, Configuration config) {
-        namedConfigurations.put(name, config);
-    }
-
-    /**
-     * Get the configuration definition with the given name
-     * @param name to be looked up
-     * @return the Configuration which maps to this name
-     */
-    public Configuration getNamedConfiguration(String name) {
-        return (Configuration) namedConfigurations.get(name);
-    }
 }
Index: modules/core/src/org/apache/synapse/config/xml/ConfigurationFactory.java
===================================================================
--- modules/core/src/org/apache/synapse/config/xml/ConfigurationFactory.java    
(revision 407499)
+++ modules/core/src/org/apache/synapse/config/xml/ConfigurationFactory.java    
(working copy)
@@ -1,41 +0,0 @@
-/*
-* 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.config.Configuration;
-import org.apache.axiom.om.OMElement;
-
-
-/**
- * A configuration factory that is capable of creating an instance of a
- * named Configuration, through a given XML, should implement this interface
- */
-
-public interface ConfigurationFactory {
-    /**
-     * Creates an instance of a named Configuration using the OMElement
-     * @param elem
-     * @return the created named Configuration
-     */
-    public Configuration createConfiguration(OMElement elem);
-
-    /**
-     * The type attribute of a configuration definition, that this factory 
could handle
-     * @return the type of configuration definition
-     */
-    public String getType();
-
-}
Index: 
modules/core/src/org/apache/synapse/config/xml/ConfigurationFactoryFinder.java
===================================================================
--- 
modules/core/src/org/apache/synapse/config/xml/ConfigurationFactoryFinder.java  
    (revision 407499)
+++ 
modules/core/src/org/apache/synapse/config/xml/ConfigurationFactoryFinder.java  
    (working copy)
@@ -1,122 +0,0 @@
-/*
-* 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.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.config.Configuration;
-import org.apache.synapse.SynapseException;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMAttribute;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import sun.misc.Service;
-
-import javax.xml.namespace.QName;
-
-/**
- *
- *
- * This class is based on J2SE Service Provider model
- * http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
- */
-
-public class ConfigurationFactoryFinder {
-
-    private static Map factoryMap = new HashMap();
-    private static final Log log = 
LogFactory.getLog(ConfigurationFactoryFinder.class);
-    private static ConfigurationFactoryFinder instance = null;
-
-    public static synchronized ConfigurationFactoryFinder getInstance() {
-        if (instance == null) {
-            instance = new ConfigurationFactoryFinder();
-        }
-        return instance;
-    }
-
-    /**
-     * Force re initialization next time
-     */
-    public synchronized void reset() {
-        factoryMap.clear();
-        instance = null;
-    }
-
-    private ConfigurationFactoryFinder() {
-        factoryMap = new HashMap();
-        // now iterate through the available pluggable mediator factories
-        registerExtensions();
-    }
-
-    /**
-     * Register pluggable Configuration factories from the classpath
-     *
-     * This looks for JAR files containing a META-INF/services that adheres to 
the following
-     * http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
-     */
-    private void registerExtensions() {
-
-        log.debug("registering extensions found in the classpath : " + 
System.getProperty("java.class.path"));
-
-        // register ConfigurationFactory extensions
-        Iterator it = Service.providers(ConfigurationFactory.class);
-        while (it.hasNext()) {
-            ConfigurationFactory cf = (ConfigurationFactory) it.next();
-            String type = cf.getType();
-            factoryMap.put(type, cf.getClass());
-            log.debug("Added ConfigurationFactory " + cf.getClass() +
-                " to handle '" + type + "' configuration definitions");
-        }
-    }
-
-    /**
-     * This method returns a Configuration of the correct type given an 
OMElement.
-     *
-     * @param elem an OMElement defining a named Configuration definition
-     * @return a correct Configuration object
-     */
-    public Configuration getConfiguration(OMElement elem) {
-
-        OMAttribute type = elem.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "type"));
-        log.debug("getConfiguration( type = " + type.getAttributeValue() + " 
)");
-
-        Class cls = (Class) factoryMap.get(type.getAttributeValue());
-
-        if (cls == null) {
-            String msg = "Unknown Configuration factory referenced by type : " 
+ type.getAttributeValue();
-            log.error(msg);
-            throw new SynapseException(msg);
-        }
-
-        try {
-            ConfigurationFactory cf = (ConfigurationFactory) cls.newInstance();
-            return cf.createConfiguration(elem);
-
-        } catch (InstantiationException e) {
-            String msg = "Error initializing Configuration factory : " + cls;
-            log.error(msg);
-            throw new SynapseException(msg, e);
-
-        } catch (IllegalAccessException e) {
-            String msg = "Error initializing Configuration factory : " + cls;
-            log.error(msg);
-            throw new SynapseException(msg, e);
-        }
-    }
-}
Index: modules/core/src/org/apache/synapse/config/xml/ExtensionFactory.java
===================================================================
--- modules/core/src/org/apache/synapse/config/xml/ExtensionFactory.java        
(revision 405612)
+++ modules/core/src/org/apache/synapse/config/xml/ExtensionFactory.java        
(working copy)
@@ -15,27 +15,29 @@
 */
 package org.apache.synapse.config.xml;
 
-import org.apache.synapse.config.Configuration;
+import org.apache.synapse.config.Extension;
 import org.apache.axiom.om.OMElement;
 
+import javax.xml.namespace.QName;
 
+
 /**
- * A configuration factory that is capable of creating an instance of a
- * named Configuration, through a given XML, should implement this interface
+ * A extension factory that is capable of creating an instance of a
+ * named extension, through a given XML, should implement this interface
  */
 
-public interface ConfigurationFactory {
+public interface ExtensionFactory {
     /**
-     * Creates an instance of a named Configuration using the OMElement
+     * Creates an instance of a named extension using the OMElement
      * @param elem
-     * @return the created named Configuration
+     * @return the created named extension
      */
-    public Configuration createConfiguration(OMElement elem);
+    public Extension createExtension(OMElement elem);
 
     /**
-     * The type attribute of a configuration definition, that this factory 
could handle
-     * @return the type of configuration definition
+     * The QName of the extension element in the XML config
+     * @return QName of the extension element
      */
-    public String getType();
+    public QName getTagQName();
 
 }
Index: 
modules/core/src/org/apache/synapse/config/xml/ExtensionFactoryFinder.java
===================================================================
--- modules/core/src/org/apache/synapse/config/xml/ExtensionFactoryFinder.java  
(revision 405612)
+++ modules/core/src/org/apache/synapse/config/xml/ExtensionFactoryFinder.java  
(working copy)
@@ -17,7 +17,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.config.Configuration;
+import org.apache.synapse.config.Extension;
 import org.apache.synapse.SynapseException;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMAttribute;
@@ -31,21 +31,22 @@
 import javax.xml.namespace.QName;
 
 /**
+ * This class loads available ConfigurationFactory implementations from the
+ * classpath and makes them available to the Synapse configuration builder.
  *
- *
  * This class is based on J2SE Service Provider model
  * http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
  */
 
-public class ConfigurationFactoryFinder {
+public class ExtensionFactoryFinder {
 
     private static Map factoryMap = new HashMap();
-    private static final Log log = 
LogFactory.getLog(ConfigurationFactoryFinder.class);
-    private static ConfigurationFactoryFinder instance = null;
+    private static final Log log = 
LogFactory.getLog(ExtensionFactoryFinder.class);
+    private static ExtensionFactoryFinder instance = null;
 
-    public static synchronized ConfigurationFactoryFinder getInstance() {
+    public static synchronized ExtensionFactoryFinder getInstance() {
         if (instance == null) {
-            instance = new ConfigurationFactoryFinder();
+            instance = new ExtensionFactoryFinder();
         }
         return instance;
     }
@@ -58,7 +59,7 @@
         instance = null;
     }
 
-    private ConfigurationFactoryFinder() {
+    private ExtensionFactoryFinder() {
         factoryMap = new HashMap();
         // now iterate through the available pluggable mediator factories
         registerExtensions();
@@ -72,49 +73,49 @@
      */
     private void registerExtensions() {
 
-        log.debug("registering extensions found in the classpath : " + 
System.getProperty("java.class.path"));
+        log.debug("Registering extensions found in the classpath : " +
+            System.getProperty("java.class.path"));
 
-        // register ConfigurationFactory extensions
-        Iterator it = Service.providers(ConfigurationFactory.class);
+        // register ExtensionFactory extensions
+        Iterator it = Service.providers(ExtensionFactory.class);
         while (it.hasNext()) {
-            ConfigurationFactory cf = (ConfigurationFactory) it.next();
-            String type = cf.getType();
-            factoryMap.put(type, cf.getClass());
-            log.debug("Added ConfigurationFactory " + cf.getClass() +
-                " to handle '" + type + "' configuration definitions");
+            ExtensionFactory ef = (ExtensionFactory) it.next();
+            factoryMap.put(ef.getTagQName(), ef.getClass());
+            log.debug("Added extension factory " + ef.getClass() +
+                " to handle '" + ef.getTagQName() + "' extension elements");
         }
     }
 
     /**
-     * This method returns a Configuration of the correct type given an 
OMElement.
+     * This method returns an Extension instance of the correct type given an 
OMElement.
      *
-     * @param elem an OMElement defining a named Configuration definition
-     * @return a correct Configuration object
+     * @param elem an OMElement defining extension
+     * @return a correct Extension instance
      */
-    public Configuration getConfiguration(OMElement elem) {
+    public Extension getExtension(OMElement elem) {
 
-        OMAttribute type = elem.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "type"));
-        log.debug("getConfiguration( type = " + type.getAttributeValue() + " 
)");
+        QName qName = new QName(elem.getNamespace().getName(), 
elem.getLocalName());
+        log.debug("getConfiguration(" + qName + ")");
 
-        Class cls = (Class) factoryMap.get(type.getAttributeValue());
+        Class cls = (Class) factoryMap.get(qName);
 
         if (cls == null) {
-            String msg = "Unknown Configuration factory referenced by type : " 
+ type.getAttributeValue();
+            String msg = "Unknown extension factory referenced by element : " 
+ qName;
             log.error(msg);
             throw new SynapseException(msg);
         }
 
         try {
-            ConfigurationFactory cf = (ConfigurationFactory) cls.newInstance();
-            return cf.createConfiguration(elem);
+            ExtensionFactory ef = (ExtensionFactory) cls.newInstance();
+            return ef.createExtension(elem);
 
         } catch (InstantiationException e) {
-            String msg = "Error initializing Configuration factory : " + cls;
+            String msg = "Error initializing extension factory : " + cls;
             log.error(msg);
             throw new SynapseException(msg, e);
 
         } catch (IllegalAccessException e) {
-            String msg = "Error initializing Configuration factory : " + cls;
+            String msg = "Error initializing extension factory : " + cls;
             log.error(msg);
             throw new SynapseException(msg, e);
         }
Index: modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java
===================================================================
--- modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java   
(revision 407499)
+++ modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java   
(working copy)
@@ -105,7 +105,7 @@
      */
     private void registerExtensions() {
 
-        log.debug("registering extensions found in the classpath : " + 
System.getProperty("java.class.path"));
+        log.debug("Registering mediator extensions found in the classpath : " 
+ System.getProperty("java.class.path"));
 
         // register MediatorFactory extensions
         Iterator it = Service.providers(MediatorFactory.class);
Index: 
modules/core/src/org/apache/synapse/config/xml/SynapseConfigurationBuilder.java
===================================================================
--- 
modules/core/src/org/apache/synapse/config/xml/SynapseConfigurationBuilder.java 
    (revision 407499)
+++ 
modules/core/src/org/apache/synapse/config/xml/SynapseConfigurationBuilder.java 
    (working copy)
@@ -22,7 +22,6 @@
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.config.SynapseConfiguration;
 import org.apache.synapse.config.Endpoint;
-import org.apache.synapse.config.Configuration;
 import org.apache.synapse.mediators.base.SequenceMediator;
 import org.apache.synapse.mediators.base.SynapseMediator;
 import org.apache.commons.logging.Log;
@@ -44,7 +43,7 @@
 
     private static Log log = 
LogFactory.getLog(SynapseConfigurationBuilder.class);
     private SynapseConfiguration config = new SynapseConfiguration();
-    ConfigurationFactoryFinder configFacFinder = 
ConfigurationFactoryFinder.getInstance();
+    ExtensionFactoryFinder extensionFacFinder = 
ExtensionFactoryFinder.getInstance();
 
     public SynapseConfigurationBuilder() {}
 
@@ -65,33 +64,22 @@
         OMContainer definitions = 
root.getFirstChildWithName(Constants.DEFINITIONS_ELT);
         if (definitions != null) {
 
-            // digest defined Sequences
-            Iterator iter = 
definitions.getChildrenWithName(Constants.SEQUENCE_ELT);
+            Iterator iter = definitions.getChildren();
             while (iter.hasNext()) {
-                OMElement elt = (OMElement) iter.next();
-                defineSequence(elt);
+                Object o = iter.next();
+                if (o instanceof OMElement) {
+                    OMElement elt = (OMElement) o;
+                    if (Constants.SEQUENCE_ELT.equals(elt.getQName())) {
+                        defineSequence(elt);
+                    } else if (Constants.ENDPOINT_ELT.equals(elt.getQName())) {
+                        defineEndpoint(elt);
+                    } else if (Constants.PROPERTY_ELT.equals(elt.getQName())) {
+                        defineProperty(elt);
+                    } else {
+                        defineExtension(elt);
+                    }
+                }
             }
-
-            // digest defined Endpoints
-            iter = definitions.getChildrenWithName(Constants.ENDPOINT_ELT);
-            while (iter.hasNext()) {
-                OMElement elt = (OMElement) iter.next();
-                defineEndpoint(elt);
-            }
-
-            // digest defined named Configurations
-            iter = definitions.getChildrenWithName(Constants.CONFIG_ELT);
-            while (iter.hasNext()) {
-                OMElement elt = (OMElement) iter.next();
-                defineConfiguration(elt);
-            }
-
-            // digest defined Global properties
-            iter = definitions.getChildrenWithName(Constants.PROPERTY_ELT);
-            while (iter.hasNext()) {
-                OMElement elt = (OMElement) iter.next();
-                defineProperty(elt);
-            }
         }
 
         OMElement elem = root.getFirstChildWithName(Constants.RULES_ELT);
@@ -161,24 +149,26 @@
     }
 
     /**
-     * Digest a named configuratino definition and add it to the 
SynapseConfiguration
+     * Digest extensions into Synapse configuration definitions
      *
-     * <configuration name="string" type="string">
-     *    <property name="string" value="string"/>*
-     * </configuration>
+     * An extension *must* have a unique 'name' attribute. The instance
+     * created through the ExtensionFactoryFinder will be set as a
+     * global property into the SynapseConfiguration with this name as
+     * the key.
+     *
+     * e.g. The Spring configuration extension is as follows
+     * <configuration name="string" src="string"/>
+     *
      * @param elem the XML element defining the configuration
      */
-    private void defineConfiguration(OMElement elem) {
+    private void defineExtension(OMElement elem) {
 
         OMAttribute name = elem.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "name"));
-        OMAttribute type = elem.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "type"));
 
         if (name == null) {
-            handleException("The 'name' attribute is required for a named 
configuration definition");
-        } else if (type == null) {
-            handleException("The 'type' attribute is required for a named 
configuration definition");
+            handleException("The 'name' attribute is required for an extension 
configuration definition");
         } else {
-            config.addNamedConfiguration(name.getAttributeValue(), 
configFacFinder.getConfiguration(elem));
+            config.addProperty(name.getAttributeValue(), 
extensionFacFinder.getExtension(elem));
         }
     }
 
Index: modules/extensions/project.xml
===================================================================
--- modules/extensions/project.xml      (revision 407499)
+++ modules/extensions/project.xml      (working copy)
@@ -45,7 +45,7 @@
                     <directory>src</directory>
                     <includes>
                         
<include>**/org.apache.synapse.config.xml.MediatorFactory</include>
-                        
<include>**/org.apache.synapse.config.xml.ConfigurationFactory</include>
+                        
<include>**/org.apache.synapse.config.xml.ExtensionFactory</include>
                     </includes>
                 </resource>
             </resources>
Index: 
modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.ConfigurationFactory
===================================================================
--- 
modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.ConfigurationFactory
 (revision 407499)
+++ 
modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.ConfigurationFactory
 (working copy)
@@ -1 +0,0 @@
-org.apache.synapse.config.xml.SpringConfigurationFactory
\ No newline at end of file
Index: 
modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.ExtensionFactory
===================================================================
--- 
modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.ExtensionFactory
     (revision 405612)
+++ 
modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.ExtensionFactory
     (working copy)
@@ -1 +1 @@
-org.apache.synapse.config.xml.SpringConfigurationFactory
\ No newline at end of file
+org.apache.synapse.config.xml.SpringConfigExtensionFactory
\ No newline at end of file
Index: 
modules/extensions/src/org/apache/synapse/config/SpringConfigExtension.java
===================================================================
--- modules/extensions/src/org/apache/synapse/config/SpringConfigExtension.java 
(revision 407499)
+++ modules/extensions/src/org/apache/synapse/config/SpringConfigExtension.java 
(working copy)
@@ -15,25 +15,38 @@
 */
 package org.apache.synapse.config;
 
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.springframework.context.support.GenericApplicationContext;
-import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.springframework.core.io.FileSystemResource;
-import org.apache.synapse.config.xml.SpringConfigurationFactory;
 
-public class SpringConfiguration extends Configuration {
+/**
+ * This defines an extension to Synapse to process a Spring Configuration.
+ * This keeps the Spring dependency out from the Synapse core, and the
+ * dependent Jars from the core distribution.
+ *
+ * A Spring configuration is usually named, but this class allows an
+ * inlined configuration to be built up as well, where the Spring mediator
+ * defines an inline Spring configuration
+ */
+public class SpringConfigExtension implements Extension {
 
-    /** This is the Spring ApplicationContext/BeanFactory */
-    GenericApplicationContext appContext = null;
+    /**
+     * The name of this Spring configuration
+     */
+    private String name = null;
 
-    public static final String SPRING_TYPE = "spring";
+    /**
+     * This is the Spring ApplicationContext/BeanFactory
+     */
+    private GenericApplicationContext appContext = null;
 
     /**
      * Create a Spring configuration from the given configuration
+     *
      * @param configFile the configuration file to be used
      */
-    public SpringConfiguration(String name, String configFile) {
-        super.setName(name);
-        super.setType(SPRING_TYPE);
+    public SpringConfigExtension(String name, String configFile) {
+        setName(name);
         appContext = new GenericApplicationContext();
         XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
         xbdr.setValidating(false);
@@ -45,4 +58,11 @@
         return appContext;
     }
 
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
 }
Index: modules/extensions/src/org/apache/synapse/config/SpringConfiguration.java
===================================================================
--- modules/extensions/src/org/apache/synapse/config/SpringConfiguration.java   
(revision 407499)
+++ modules/extensions/src/org/apache/synapse/config/SpringConfiguration.java   
(working copy)
@@ -1,48 +0,0 @@
-/*
-* 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;
-
-import org.springframework.context.support.GenericApplicationContext;
-import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.core.io.FileSystemResource;
-import org.apache.synapse.config.xml.SpringConfigurationFactory;
-
-public class SpringConfiguration extends Configuration {
-
-    /** This is the Spring ApplicationContext/BeanFactory */
-    GenericApplicationContext appContext = null;
-
-    public static final String SPRING_TYPE = "spring";
-
-    /**
-     * Create a Spring configuration from the given configuration
-     * @param configFile the configuration file to be used
-     */
-    public SpringConfiguration(String name, String configFile) {
-        super.setName(name);
-        super.setType(SPRING_TYPE);
-        appContext = new GenericApplicationContext();
-        XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
-        xbdr.setValidating(false);
-        xbdr.loadBeanDefinitions(new FileSystemResource(configFile));
-        appContext.refresh();
-    }
-
-    public GenericApplicationContext getAppContext() {
-        return appContext;
-    }
-
-}
Index: 
modules/extensions/src/org/apache/synapse/config/xml/SpringConfigExtensionFactory.java
===================================================================
--- 
modules/extensions/src/org/apache/synapse/config/xml/SpringConfigExtensionFactory.java
      (revision 407499)
+++ 
modules/extensions/src/org/apache/synapse/config/xml/SpringConfigExtensionFactory.java
      (working copy)
@@ -19,46 +19,50 @@
 import org.apache.axiom.om.OMElement;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.config.Configuration;
-import org.apache.synapse.config.SpringConfiguration;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.Extension;
+import org.apache.synapse.config.SpringConfigExtension;
 
 import javax.xml.namespace.QName;
-import java.util.Iterator;
 
-public class SpringConfigurationFactory implements ConfigurationFactory {
+/**
+ * Creates a Spring configuration extension from XML configuration. A Spring
+ * configuration extension keeps Spring away from the core of synapse
+ */
+public class SpringConfigExtensionFactory implements ExtensionFactory {
 
-    private static final Log log = 
LogFactory.getLog(SpringConfigurationFactory.class);
+    private static final Log log = 
LogFactory.getLog(SpringConfigExtensionFactory.class);
 
-    private static final String CONFIG_NAME = "config_name";
+    private static final QName SPRING_CFG_Q = new 
QName(Constants.SYNAPSE_NAMESPACE + "/spring", "config");
 
     /**
-     * <configuration name="string" type="spring">
-     *    <property name="config_src" value="string"/>
-     *    <property>*
-     * </configuration>
+     * <spring:config name="string" src="file"/>
      *
-     * @param elem
+     * @param elem the XML configuration element
      * @return A named Spring Configuration
      */
-    public Configuration createConfiguration(OMElement elem) {
+    public Extension createExtension(OMElement elem) {
 
-        Iterator iter = elem.getChildrenWithName(new 
QName(Constants.NULL_NAMESPACE, "property"));
-        while (iter.hasNext()) {
-            Object o = iter.next();
-            if (o instanceof OMElement) {
-                OMElement prop = (OMElement) o;
-                OMAttribute name = prop.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "name"));
-                OMAttribute value = prop.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "value"));
+        SpringConfigExtension springCfgExt = null;
+        OMAttribute name = elem.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "name"));
+        OMAttribute src  = elem.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "src"));
 
-                if (name != null && value != null && 
CONFIG_NAME.equals(name.getAttributeValue())) {
-                    return new SpringConfiguration(name.getAttributeValue(), 
value.getAttributeValue());
-                }
-            }
+        if (name == null) {
+            handleException("The 'name' attribute is required for a Spring 
configuration definition");
+        } else if (src == null) {
+            handleException("The 'src' attribute is required for a Spring 
configuration definition");
+        } else {
+            springCfgExt = new SpringConfigExtension(name.getAttributeValue(), 
src.getAttributeValue());
         }
-        return null;
+        return springCfgExt;
     }
 
-    public String getType() {
-        return SpringConfiguration.SPRING_TYPE;
+    private void handleException(String msg) {
+        log.error(msg);
+        throw new SynapseException(msg);
     }
+
+    public QName getTagQName() {
+        return SPRING_CFG_Q;
+    }
 }
Index: 
modules/extensions/src/org/apache/synapse/config/xml/SpringConfigurationFactory.java
===================================================================
--- 
modules/extensions/src/org/apache/synapse/config/xml/SpringConfigurationFactory.java
        (revision 407499)
+++ 
modules/extensions/src/org/apache/synapse/config/xml/SpringConfigurationFactory.java
        (working copy)
@@ -1,64 +0,0 @@
-/*
-* 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.OMAttribute;
-import org.apache.axiom.om.OMElement;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.config.Configuration;
-import org.apache.synapse.config.SpringConfiguration;
-
-import javax.xml.namespace.QName;
-import java.util.Iterator;
-
-public class SpringConfigurationFactory implements ConfigurationFactory {
-
-    private static final Log log = 
LogFactory.getLog(SpringConfigurationFactory.class);
-
-    private static final String CONFIG_NAME = "config_name";
-
-    /**
-     * <configuration name="string" type="spring">
-     *    <property name="config_src" value="string"/>
-     *    <property>*
-     * </configuration>
-     *
-     * @param elem
-     * @return A named Spring Configuration
-     */
-    public Configuration createConfiguration(OMElement elem) {
-
-        Iterator iter = elem.getChildrenWithName(new 
QName(Constants.NULL_NAMESPACE, "property"));
-        while (iter.hasNext()) {
-            Object o = iter.next();
-            if (o instanceof OMElement) {
-                OMElement prop = (OMElement) o;
-                OMAttribute name = prop.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "name"));
-                OMAttribute value = prop.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "value"));
-
-                if (name != null && value != null && 
CONFIG_NAME.equals(name.getAttributeValue())) {
-                    return new SpringConfiguration(name.getAttributeValue(), 
value.getAttributeValue());
-                }
-            }
-        }
-        return null;
-    }
-
-    public String getType() {
-        return SpringConfiguration.SPRING_TYPE;
-    }
-}
Index: 
modules/extensions/src/org/apache/synapse/config/xml/SpringMediatorFactory.java
===================================================================
--- 
modules/extensions/src/org/apache/synapse/config/xml/SpringMediatorFactory.java 
    (revision 407499)
+++ 
modules/extensions/src/org/apache/synapse/config/xml/SpringMediatorFactory.java 
    (working copy)
@@ -5,17 +5,18 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.SynapseException;
-import org.apache.synapse.config.SpringConfiguration;
 import org.apache.synapse.api.Mediator;
+import org.apache.synapse.config.SpringConfigExtension;
 import org.apache.synapse.mediators.ext.spring.SpringMediator;
 
 import javax.xml.namespace.QName;
 
 /**
  * Creates an instance of a Spring mediator that refers to the given Spring
- * configuration and bean.
+ * configuration and bean. Optionally, one could specify an inlined Spring
+ * configuration as opposed to a globally defined Spring configuration
  * <p/>
- * <spring ref_bean="exampleBean1" (config_name="spring1" | 
config_src="spring.xml)"/>
+ * <spring bean="exampleBean1" (config="spring1" | src="spring.xml)"/>
  */
 public class SpringMediatorFactory implements MediatorFactory {
 
@@ -33,24 +34,25 @@
     public Mediator createMediator(OMElement elem) {
 
         SpringMediator sm = new SpringMediator();
-        OMAttribute ref = elem.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "ref_bean"));
-        OMAttribute cfg = elem.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "config_name"));
-        OMAttribute src = elem.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "config_src"));
+        OMAttribute bean = elem.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "bean"));
+        OMAttribute cfg = elem.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "config"));
+        OMAttribute src = elem.getAttribute(new 
QName(Constants.NULL_NAMESPACE, "src"));
 
-        if (ref == null) {
-            handleException("The 'ref_bean' attribute is required for a Spring 
mediator definition");
+        if (bean == null) {
+            handleException("The 'bean' attribute is required for a Spring 
mediator definition");
         } else if (cfg == null && src == null) {
-            handleException("A 'config_name' or 'config_src' attribute is 
required for a Spring mediator definition");
+            handleException("A 'config' or 'src' attribute is required for a 
Spring mediator definition");
 
         } else {
-            sm.setBeanName(ref.getAttributeValue());
+            sm.setBeanName(bean.getAttributeValue());
             if (cfg != null) {
+                log.debug("Creating a Spring mediator using configuration 
named : " + cfg.getAttributeValue());
                 sm.setConfigName(cfg.getAttributeValue());
 
             } else {
-                log.debug("Creating an anonymous Spring configuration using 
source : " + src.getAttributeValue());
-                SpringConfiguration sc = new SpringConfiguration("anonymous", 
src.getAttributeValue());
-                sm.setAppContext(sc.getAppContext());
+                log.debug("Creating an inline Spring configuration using 
source : " + src.getAttributeValue());
+                SpringConfigExtension sce = new 
SpringConfigExtension("inline", src.getAttributeValue());
+                sm.setAppContext(sce.getAppContext());
             }
             return sm;
         }
Index: 
modules/extensions/src/org/apache/synapse/mediators/ext/spring/SpringMediator.java
===================================================================
--- 
modules/extensions/src/org/apache/synapse/mediators/ext/spring/SpringMediator.java
  (revision 407499)
+++ 
modules/extensions/src/org/apache/synapse/mediators/ext/spring/SpringMediator.java
  (working copy)
@@ -15,35 +15,37 @@
 */
 package org.apache.synapse.mediators.ext.spring;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.MessageContext;
 import org.apache.synapse.SynapseException;
-import org.apache.synapse.config.Configuration;
-import org.apache.synapse.config.SpringConfiguration;
 import org.apache.synapse.api.Mediator;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.config.SpringConfigExtension;
 import org.springframework.context.ApplicationContext;
 
 /**
- * This mediator allows
- * <p> This class is the class that "plugs" Spring-based mediators into 
Synapse.
- * <p> A spring based mediator is any object that implements mediator and can 
be instantiated by
- * Spring (see www.springframework.org). The mediator definition is set up 
using the 
- *  SpringMediatorProcessorConfigurator class.
- *  
- * This class simply has a Context property which is set with a Spring 
GenericApplicationContext and 
- * a BeanName property, which is set with the name of the bean  
+ * This mediator allows Spring beans implementing the 
org.apache.synapse.api.Mediator
+ * interface to mediate messages passing through Synapse.
  *
+ * A Spring mediator is instantiated by Spring (see www.springframework.org). 
The mediator
+ * refers to a Spring bean name, and also either a Spring configuration 
defined to Synapse
+ * or an inlined Spring configuration.
  */
 public class SpringMediator implements Mediator {
 
     private static final Log log = LogFactory.getLog(SpringMediator.class);
 
-    /** The Spring bean ref to be used */
+    /**
+     * The Spring bean ref to be used
+     */
     private String beanName = null;
-    /** The named Spring configName to be used */
+    /**
+     * The named Spring configName to be used
+     */
     private String configName = null;
-    /** The Spring ApplicationContext to be used */
+    /**
+     * The Spring ApplicationContext to be used
+     */
     private ApplicationContext appContext = null;
 
     public boolean mediate(MessageContext synCtx) {
@@ -54,12 +56,13 @@
 
         // if a named configuration is referenced, use it
         if (configName != null) {
-            // get named Spring configName
-            Configuration config = 
synCtx.getConfiguration().getNamedConfiguration(configName);
+            // get named Spring configuration
+            Object cfg = synCtx.getConfiguration().getProperty(configName);
 
-            if (config != null && config instanceof SpringConfiguration) {
+            if (cfg != null && cfg instanceof SpringConfigExtension) {
 
-                ApplicationContext appContext = ((SpringConfiguration) 
config).getAppContext();
+                ApplicationContext appContext = ((SpringConfigExtension) 
cfg).getAppContext();
+                log.debug("Loading bean : " + beanName + " from Spring 
configuration named : " + configName);
                 Object o = appContext.getBean(beanName);
 
                 if (o != null && 
Mediator.class.isAssignableFrom(o.getClass())) {
@@ -71,11 +74,12 @@
                         " from the Spring configuration named : " + 
configName);
                 }
             } else {
-                handleException("Could not get a reference to the Spring 
configuration named : " + configName);
+                handleException("Could not get a reference to a valid Spring 
configuration named : " + configName);
             }
 
         } else if (appContext != null) {
 
+            log.debug("Loading bean : " + beanName + " from inline Spring 
configuration");
             Object o = appContext.getBean(beanName);
 
             if (o != null && Mediator.class.isAssignableFrom(o.getClass())) {
@@ -84,7 +88,7 @@
 
             } else {
                 handleException("Could not find the bean named : " + beanName +
-                    " from the anonymous Spring configuration");
+                    " from the inline Spring configuration");
             }
 
         } else {
Index: modules/extensions/test/org/apache/synapse/spring/SpringMediatorTest.java
===================================================================
--- modules/extensions/test/org/apache/synapse/spring/SpringMediatorTest.java   
(revision 407499)
+++ modules/extensions/test/org/apache/synapse/spring/SpringMediatorTest.java   
(working copy)
@@ -42,7 +42,7 @@
         msgCtx.setConfiguration(synCfgBuilder.getConfig());
         msgCtx.getConfiguration().getMainMediator().mediate(msgCtx);
 
-        assertEquals(TestMediateHandlerImpl.invokeCount, 2);
+        assertEquals(TestMediateHandlerImpl.invokeCount, 202);
     }
 
 }
Index: modules/extensions/test/org/apache/synapse/spring/SpringTestBean.java
===================================================================
--- modules/extensions/test/org/apache/synapse/spring/SpringTestBean.java       
(revision 407499)
+++ modules/extensions/test/org/apache/synapse/spring/SpringTestBean.java       
(working copy)
@@ -18,6 +18,11 @@
 import org.apache.synapse.api.Mediator;
 import org.apache.synapse.MessageContext;
 
+/**
+ * This is a very simple Spring bean, that has one int property, and a
+ * reference to another bean. This second bean is invoked on each mediate()
+ * call, and it keeps a count of the invocations to be tested by JUnit
+ */
 public class SpringTestBean implements Mediator {
 
     private int testProperty;
@@ -48,6 +53,7 @@
 
     public void setTestProperty(int i) {
         this.testProperty = i;
+        TestMediateHandlerImpl.invokeCount += i;
     }
 
     public int getTestProperty() {
Index: repository/conf/sample/springsample.xml
===================================================================
--- repository/conf/sample/springsample.xml     (revision 407499)
+++ repository/conf/sample/springsample.xml     (working copy)
@@ -5,7 +5,7 @@
 <beans>
 
    <bean id="springtest" class="org.apache.synapse.spring.SpringTestBean" 
singleton="false">
-          <property name="testProperty"><value>1</value></property>
+          <property name="testProperty"><value>100</value></property>
           <property name="handler"><ref bean="handler"/></property>
    </bean>
    
Index: repository/conf/sample/synapse_sample_3.xml
===================================================================
--- repository/conf/sample/synapse_sample_3.xml (revision 407499)
+++ repository/conf/sample/synapse_sample_3.xml (working copy)
@@ -1,16 +1,12 @@
-<synapse xmlns="http://ws.apache.org/ns/synapse";>
+<synapse xmlns="http://ws.apache.org/ns/synapse"; 
xmlns:spring="http://ws.apache.org/ns/synapse/spring";>
   
   <definitions>
-
-               <configuration name="springconfig" type="spring">    
-                       <property name="config_name" 
value="./../../repository/conf/sample/springsample.xml"/>
-               </configuration>
-
+               <spring:config name="springconfig" 
src="./../../repository/conf/sample/springsample.xml"/>
   </definitions>
 
   <rules>
-       <spring ref_bean="springtest" config_name="springconfig"/>
-       <spring ref_bean="springtest" 
config_src="./../../repository/conf/sample/springsample.xml"/>
+       <spring bean="springtest" config="springconfig"/>
+       <spring bean="springtest" 
src="./../../repository/conf/sample/springsample.xml"/>
   </rules>
 
 </synapse> 
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to