Author: hiranya
Date: Mon Aug 10 09:37:25 2009
New Revision: 802703

URL: http://svn.apache.org/viewvc?rev=802703&view=rev
Log:
Improved the multi XML config builder to read a synapse.xml file in the 
specified directory to build the Synapse configuration from. The 
local-entries.xml file was removed from the config builder (such things should 
go in the synapse.xml from now on). Updated the config serializer as necessary. 

The logic which creates default main and fault sequences in the 
SynapseXMLConfigurationFactory was moved to SynapseConfigurationBuilder where 
it can be shared across multiple config builder implementations.


Modified:
    
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java
    
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java
    
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationSerializer.java
    
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java

Modified: 
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java
URL: 
http://svn.apache.org/viewvc/synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java?rev=802703&r1=802702&r2=802703&view=diff
==============================================================================
--- 
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java
 (original)
+++ 
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java
 Mon Aug 10 09:37:25 2009
@@ -26,6 +26,7 @@
 import org.apache.synapse.config.xml.XMLConfigurationBuilder;
 import org.apache.synapse.config.xml.MultiXMLConfigurationBuilder;
 import org.apache.synapse.config.xml.MultiXMLConfigurationSerializer;
+import org.apache.synapse.config.xml.SynapseXMLConfigurationFactory;
 import org.apache.synapse.mediators.base.SequenceMediator;
 import org.apache.synapse.mediators.builtin.DropMediator;
 import org.apache.synapse.mediators.builtin.LogMediator;
@@ -98,6 +99,16 @@
             }
         }
 
+        // Check for the main sequence and add a default main sequence if not 
present
+        if (synCfg.getMainSequence() == null) {
+            SynapseXMLConfigurationFactory.setDefaultMainSequence(synCfg);
+        }
+
+        // Check for the fault sequence and add a deafult fault sequence if 
not present
+        if (synCfg.getFaultSequence() == null) {
+            SynapseXMLConfigurationFactory.setDefaultFaultSequence(synCfg);
+        }
+
 
         return synCfg;
     }

Modified: 
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java
URL: 
http://svn.apache.org/viewvc/synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java?rev=802703&r1=802702&r2=802703&view=diff
==============================================================================
--- 
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java
 (original)
+++ 
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java
 Mon Aug 10 09:37:25 2009
@@ -24,6 +24,7 @@
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.Startup;
 import org.apache.synapse.Mediator;
+import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.eventing.SynapseEventSource;
 import org.apache.synapse.endpoints.Endpoint;
 import org.apache.synapse.endpoints.AbstractEndpoint;
@@ -37,9 +38,7 @@
 import org.apache.axiom.om.OMNode;
 
 import javax.xml.stream.XMLStreamException;
-import javax.xml.namespace.QName;
 import java.io.*;
-import java.util.Iterator;
 
 /**
  * <p>
@@ -59,11 +58,10 @@
  * one configuration item (eg: a proxy service, an endpoint, a sequence).
  * </p>
  * <p>
- * In addition to the directories mentioned above one can have the following 
two files in
+ * In addition to the directories mentioned above one can have the following 
file in
  * CONF_HOME
  * <ul>
  *  <li>CONF_HOME/registry.xml</li>
- *  <li>CONF_HOME/local-entries.xml</li>
  * </ul>
  * </p>
  *
@@ -78,13 +76,8 @@
     public static final String EVENTS_DIR          = "events";
 
     public static final String REGISTRY_FILE       = "registry.xml";
-    public static final String LOCAL_ENTRIES_FILE  = "local-entries.xml";
 
-    public static final String LOCAL_ENTRIES_ROOT_ELT  = "localEntries";
-
-    public static final String LOCAL_ENTRIES_FILE_ID   =  "LocalEntries*?";
-
-    public static Log log = 
LogFactory.getLog(MultiXMLConfigurationBuilder.class);
+    private static Log log = 
LogFactory.getLog(MultiXMLConfigurationBuilder.class);
 
     private static FileFilter filter = new FileFilter() {
         public boolean accept(File pathname) {
@@ -98,11 +91,20 @@
             log.debug("Building Synapse configuration from the directory 
heirarchy at : " + root);
         }
 
-        SynapseConfiguration synapseConfig = 
SynapseConfigUtils.newConfiguration();
-        synapseConfig.setDefaultQName(XMLConfigConstants.DEFINITIONS_ELT);
-
+        SynapseConfiguration synapseConfig = null;
         try {
-            createRegistry(synapseConfig, root);
+            // First try to load the configuration from synapse.xml
+            synapseConfig = createConfigurationFromSynapseXML(root);
+            if (synapseConfig == null) {
+                synapseConfig = SynapseConfigUtils.newConfiguration();
+                
synapseConfig.setDefaultQName(XMLConfigConstants.DEFINITIONS_ELT);
+            }
+
+            if (synapseConfig.getRegistry() == null) {
+                // If the synapse.xml does not define a registry look for a 
registry.xml
+                createRegistry(synapseConfig, root);
+            }
+
             createLocalEntries(synapseConfig, root);
             createEndpoints(synapseConfig, root);
             createSequences(synapseConfig, root);
@@ -114,11 +116,13 @@
             handleException("Error while reading from configuration file", e);
         }
 
-        if (synapseConfig.getLocalRegistry().isEmpty() && 
synapseConfig.getProxyServices().isEmpty()
-                && synapseConfig.getRegistry() != null) {
+        if (synapseConfig.getLocalRegistry().isEmpty() &&
+                synapseConfig.getProxyServices().isEmpty() && 
synapseConfig.getRegistry() != null) {
+
+            log.info("No proxy service definitions or local entry definitions 
were " +
+                    "found at : " + root + ". Attempting to load the 
configuration from " +
+                    "the Synapse registry.");
 
-            log.info("No proxy service definitions or local entry definitions 
were found at : " + root + ". " +
-                    "Attempting to load the configuration from the Synapse 
registry.");
             OMNode remoteConfigNode = 
synapseConfig.getRegistry().lookup("synapse.xml");
             if (remoteConfigNode != null) {
                 synapseConfig = XMLConfigurationBuilder.getConfiguration(
@@ -128,62 +132,35 @@
             }
         }
 
-        // after all, if there is no sequence named main defined attach a 
default one
-        if (synapseConfig.getMainSequence() == null) {
-            log.info("Creating the default main sequence");
-            
SynapseXMLConfigurationFactory.setDefaultMainSequence(synapseConfig);
-        }
+        return synapseConfig;
+    }
+
+    private static SynapseConfiguration createConfigurationFromSynapseXML(
+            String rootDirPath) throws FileNotFoundException, 
XMLStreamException {
 
-        // after all, if there is no sequence named fault defined attach a 
default one
-        if (synapseConfig.getFaultSequence() == null) {
-            log.info("Creating the default fault sequence");
-            
SynapseXMLConfigurationFactory.setDefaultFaultSequence(synapseConfig);
+        File synapseXML = new File(rootDirPath, SynapseConstants.SYNAPSE_XML);
+        if (synapseXML.exists()) {
+            return XMLConfigurationBuilder.getConfiguration(new 
FileInputStream(synapseXML));
         }
-        return synapseConfig;
+        return null;
     }
 
-    private static void createRegistry(SynapseConfiguration synapseConfig,
-                                         String rootDirPath) throws 
FileNotFoundException, XMLStreamException {
+    private static void createRegistry(SynapseConfiguration synapseConfig, 
String rootDirPath)
+            throws FileNotFoundException, XMLStreamException {
 
         File registryDef = new File(rootDirPath, REGISTRY_FILE);
         if (registryDef.exists()) {
             if (log.isDebugEnabled()) {
-                log.debug("Initializing Synapse registry from the 
configuration at : " + registryDef.getPath());
+                log.debug("Initializing Synapse registry from the 
configuration at : " +
+                        registryDef.getPath());
             }
             OMElement document = parseFile(registryDef);
             SynapseXMLConfigurationFactory.defineRegistry(synapseConfig, 
document);
         }
     }
 
-    private static void createLocalEntries(SynapseConfiguration synapseConfig,
-                                         String rootDirPath) throws 
FileNotFoundException, XMLStreamException {
-
-        File localEntriesDef = new File(rootDirPath, LOCAL_ENTRIES_FILE);
-        if (localEntriesDef.exists()) {
-            if (log.isDebugEnabled()) {
-                log.debug("Loading local entry definitions from : " + 
localEntriesDef.getPath());
-            }
-            OMElement document = parseFile(localEntriesDef);
-            if (!document.getQName().equals(new 
QName(XMLConfigConstants.SYNAPSE_NAMESPACE, LOCAL_ENTRIES_ROOT_ELT))) {
-                throw new SynapseException("Invalid root element in the " + 
LOCAL_ENTRIES_FILE + " file. The local " +
-                        "entries definition file must have the root element : 
" + LOCAL_ENTRIES_ROOT_ELT);
-            }
-
-            Iterator childEntires = document.getChildren();
-            while (childEntires.hasNext()) {
-                Object o = childEntires.next();
-                if (o instanceof OMElement) {
-                    OMElement localEntry = (OMElement) o;
-                    if 
(XMLConfigConstants.ENTRY_ELT.equals(localEntry.getQName())) {
-                        Entry entry = 
SynapseXMLConfigurationFactory.defineEntry(synapseConfig, localEntry);
-                        entry.setFileName(LOCAL_ENTRIES_FILE_ID);
-                    } else {
-                        log.warn("Invalid element " + 
localEntry.getLocalName() + " in the " +
-                                LOCAL_ENTRIES_FILE + " file");
-                    }
-                }
-            }
-        }
+    private static void createLocalEntries(SynapseConfiguration synapseConfig, 
String rootDirPath) 
+            throws FileNotFoundException, XMLStreamException {
 
         File localEntriesDir = new File(rootDirPath, LOCAL_ENTRY_DIR);
         if (localEntriesDir.exists()) {
@@ -197,11 +174,10 @@
                 entry.setFileName(file.getName());
             }
         }
-
     }
 
-    private static void createProxyServices(SynapseConfiguration synapseConfig,
-                                         String rootDirPath) throws 
FileNotFoundException, XMLStreamException {
+    private static void createProxyServices(SynapseConfiguration 
synapseConfig, String rootDirPath)
+            throws FileNotFoundException, XMLStreamException {
 
         File proxyServicesDir = new File(rootDirPath, PROXY_SERVICES_DIR);
         if (proxyServicesDir.exists()) {
@@ -211,14 +187,15 @@
             File[] proxyDefinitions = proxyServicesDir.listFiles(filter);
             for (File file : proxyDefinitions) {
                 OMElement document = parseFile(file);
-                ProxyService proxy = 
SynapseXMLConfigurationFactory.defineProxy(synapseConfig, document);
+                ProxyService proxy = 
SynapseXMLConfigurationFactory.defineProxy(synapseConfig,
+                        document);
                 proxy.setFileName(file.getName());
             }
         }
     }
 
-    private static void createTasks(SynapseConfiguration synapseConfig,
-                                         String rootDirPath) throws 
FileNotFoundException, XMLStreamException {
+    private static void createTasks(SynapseConfiguration synapseConfig, String 
rootDirPath)
+            throws FileNotFoundException, XMLStreamException {
 
         File tasksDir = new File(rootDirPath, TASKS_DIR);
         if (tasksDir.exists()) {
@@ -228,7 +205,8 @@
             File[] taskDefinitions = tasksDir.listFiles(filter);
             for (File file : taskDefinitions) {
                 OMElement document = parseFile(file);
-                Startup startup = 
SynapseXMLConfigurationFactory.defineStartup(synapseConfig, document);
+                Startup startup = 
SynapseXMLConfigurationFactory.defineStartup(synapseConfig,
+                        document);
                 if (startup instanceof AbstractStartup) {
                     ((AbstractStartup) startup).setFileName(file.getName());
                 }
@@ -236,8 +214,8 @@
         }
     }
 
-    private static void createSequences(SynapseConfiguration synapseConfig,
-                                       String rootDirPath) throws 
FileNotFoundException, XMLStreamException {
+    private static void createSequences(SynapseConfiguration synapseConfig, 
String rootDirPath)
+            throws FileNotFoundException, XMLStreamException {
 
         File sequencesDir = new File(rootDirPath, SEQUENCES_DIR);
         if (sequencesDir.exists()) {
@@ -247,7 +225,8 @@
             File[] sequences = sequencesDir.listFiles(filter);
             for (File file : sequences) {
                 OMElement document = parseFile(file);
-                Mediator seq = 
SynapseXMLConfigurationFactory.defineSequence(synapseConfig, document);
+                Mediator seq = 
SynapseXMLConfigurationFactory.defineSequence(synapseConfig,
+                        document);
                 if (seq instanceof SequenceMediator) {
                     ((SequenceMediator) seq).setFileName(file.getName());
                 }
@@ -255,8 +234,8 @@
         }
     }
 
-    private static void createEndpoints(SynapseConfiguration synapseConfig,
-                                       String rootDirPath) throws 
FileNotFoundException, XMLStreamException {
+    private static void createEndpoints(SynapseConfiguration synapseConfig, 
String rootDirPath)
+            throws FileNotFoundException, XMLStreamException {
 
         File endpointsDir = new File(rootDirPath, ENDPOINTS_DIR);
         if (endpointsDir.exists()) {
@@ -266,7 +245,8 @@
             File[] endpoints = endpointsDir.listFiles(filter);
             for (File file : endpoints) {
                 OMElement document = parseFile(file);
-                Endpoint endpoint = 
SynapseXMLConfigurationFactory.defineEndpoint(synapseConfig, document);
+                Endpoint endpoint = 
SynapseXMLConfigurationFactory.defineEndpoint(synapseConfig,
+                        document);
                 if (endpoint instanceof AbstractEndpoint) {
                     ((AbstractEndpoint) endpoint).setFileName(file.getName());
                 }
@@ -274,8 +254,8 @@
         }
     }
 
-    private static void createEventSources(SynapseConfiguration synapseConfig,
-                                       String rootDirPath) throws 
FileNotFoundException, XMLStreamException {
+    private static void createEventSources(SynapseConfiguration synapseConfig, 
String rootDirPath)
+            throws FileNotFoundException, XMLStreamException {
 
         File eventsDir = new File(rootDirPath, EVENTS_DIR);
         if (eventsDir.exists()) {
@@ -292,7 +272,8 @@
         }
     }
 
-    private static OMElement parseFile(File file) throws 
FileNotFoundException, XMLStreamException {
+    private static OMElement parseFile(File file)
+            throws FileNotFoundException, XMLStreamException {
         InputStream is = new FileInputStream(file);
         OMElement document = new StAXOMBuilder(is).getDocumentElement();
         document.build();

Modified: 
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationSerializer.java
URL: 
http://svn.apache.org/viewvc/synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationSerializer.java?rev=802703&r1=802702&r2=802703&view=diff
==============================================================================
--- 
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationSerializer.java
 (original)
+++ 
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationSerializer.java
 Mon Aug 10 09:37:25 2009
@@ -34,10 +34,11 @@
 import org.apache.synapse.startup.AbstractStartup;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.xml.namespace.QName;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.OutputStream;
@@ -62,8 +63,13 @@
 
     public void serialize(SynapseConfiguration synapseConfig) {
         if (log.isDebugEnabled()) {
-            log.debug("Starting to serialize the Synapse configuration to the 
directory : " + rootDirectory);
+            log.debug("Starting to serialize the Synapse configuration to the 
directory : " +
+                    rootDirectory);
         }
+        
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        OMNamespace synNS = 
fac.createOMNamespace(XMLConfigConstants.SYNAPSE_NAMESPACE, "syn");
+        OMElement definitions = fac.createOMElement("definitions", synNS);
 
         try {
             // TO start with clean up the existing configuration files
@@ -76,22 +82,33 @@
 
             Collection<ProxyService> proxyServices = 
synapseConfig.getProxyServices();
             if (!proxyServices.isEmpty()) {
-                serializeProxyServices(proxyServices);
+                serializeProxyServices(proxyServices, definitions);
             }
 
             Collection<SynapseEventSource> eventSources = 
synapseConfig.getEventSources();
             if (!eventSources.isEmpty()) {
-                serializeEventSources(eventSources);
+                serializeEventSources(eventSources, definitions);
             }
 
             Collection<Startup> tasks = synapseConfig.getStartups();
             if (!tasks.isEmpty()) {
-                serializeTasks(tasks);
+                serializeTasks(tasks, definitions);
             }
 
             Collection localRegistryValues = 
synapseConfig.getLocalRegistry().values();
             if (!localRegistryValues.isEmpty()) {
-                serializeLocalRegistryValues(localRegistryValues);
+                serializeLocalRegistryValues(localRegistryValues, definitions);
+            }
+
+            // Now serialize the content to synapse.xml
+            File synapseXML = new File(rootDirectory, 
SynapseConstants.SYNAPSE_XML);
+            if (synapseXML.createNewFile()) {
+                OutputStream out = new FileOutputStream(synapseXML);
+                definitions.serializeAndConsume(out);
+                out.flush();
+            } else {
+                throw new Exception("Error while creating the Synapse 
configuration file at : " +
+                synapseXML.getAbsolutePath());
             }
 
             log.info("Done serializing the Synapse configuration to : " + 
rootDirectory.getPath());
@@ -127,7 +144,8 @@
         }
     }
 
-    private void serializeProxyServices(Collection<ProxyService> 
proxyServices) throws Exception {
+    private void serializeProxyServices(Collection<ProxyService> 
proxyServices, OMElement parent)
+            throws Exception {
 
         File proxyDir = new File(rootDirectory, 
MultiXMLConfigurationBuilder.PROXY_SERVICES_DIR);
         if (log.isDebugEnabled()) {
@@ -140,26 +158,26 @@
         }
 
         for (ProxyService service : proxyServices) {
-            File proxyFile;
             OMElement proxyElem = ProxyServiceSerializer.serializeProxy(null, 
service);
 
             if (service.getFileName() != null) {
-                proxyFile = new File(proxyDir, service.getFileName());
-            } else {
-                proxyFile = new File(proxyDir, service.getName() + ".xml");
-            }
-
-            if (proxyFile.createNewFile()) {
-                OutputStream out = new FileOutputStream(proxyFile);
-                proxyElem.serializeAndConsume(out);
-                out.flush();
+                File proxyFile = new File(proxyDir, service.getFileName());
+                if (proxyFile.createNewFile()) {
+                    OutputStream out = new FileOutputStream(proxyFile);
+                    proxyElem.serializeAndConsume(out);
+                    out.flush();
+                } else {
+                    throw new Exception("Error while creating the file : " +
+                            proxyFile.getAbsolutePath());
+                }
             } else {
-                throw new Exception("Error while creating the file : " + 
proxyFile.getAbsolutePath());
+                parent.addChild(proxyElem);
             }
         }
     }
 
-    private void serializeEventSources(Collection<SynapseEventSource> 
eventSources) throws Exception {
+    private void serializeEventSources(Collection<SynapseEventSource> 
eventSources,
+                                       OMElement parent) throws Exception {
 
         File eventsDir = new File(rootDirectory, 
MultiXMLConfigurationBuilder.EVENTS_DIR);
         if (log.isDebugEnabled()) {
@@ -167,30 +185,30 @@
         }
 
         if (!eventsDir.mkdir()) {
-            throw new Exception("Error while creating the directory for events 
: " + eventsDir.getAbsolutePath());
+            throw new Exception("Error while creating the directory for events 
: " +
+                    eventsDir.getAbsolutePath());
         }
 
         for (SynapseEventSource source : eventSources) {
-            File eventSrcFile;
             OMElement eventSrcElem = 
EventSourceSerializer.serializeEventSource(null, source);
 
             if (source.getFileName() != null) {
-                eventSrcFile = new File(eventsDir, source.getFileName());
-            } else {
-                eventSrcFile = new File(eventsDir, source.getName() + ".xml");
-            }
-
-            if (eventSrcFile.createNewFile()) {
-                OutputStream out = new FileOutputStream(eventSrcFile);
-                eventSrcElem.serializeAndConsume(out);
-                out.flush();
+                File eventSrcFile = new File(eventsDir, source.getFileName());
+                if (eventSrcFile.createNewFile()) {
+                    OutputStream out = new FileOutputStream(eventSrcFile);
+                    eventSrcElem.serializeAndConsume(out);
+                    out.flush();
+                } else {
+                    throw new Exception("Error while creating the file : " +
+                            eventSrcFile.getAbsolutePath());
+                }
             } else {
-                throw new Exception("Error while creating the file : " + 
eventSrcFile.getAbsolutePath());
+                parent.addChild(eventSrcElem);
             }
         }
     }
 
-    private void serializeTasks(Collection<Startup> tasks) throws Exception {
+    private void serializeTasks(Collection<Startup> tasks, OMElement parent) 
throws Exception {
 
         File tasksDir = new File(rootDirectory, 
MultiXMLConfigurationBuilder.TASKS_DIR);
         if (log.isDebugEnabled()) {
@@ -198,60 +216,64 @@
         }
 
         if (!tasksDir.mkdir()) {
-            throw new Exception("Error while creating the directory for tasks 
: " + tasksDir.getAbsolutePath());
+            throw new Exception("Error while creating the directory for tasks 
: " +
+                    tasksDir.getAbsolutePath());
         }
 
         for (Startup task : tasks) {
             File taskFile;
-            OMElement taslElem = 
StartupFinder.getInstance().serializeStartup(null, task);
+            OMElement taskElem = 
StartupFinder.getInstance().serializeStartup(null, task);
 
             if (task instanceof AbstractStartup && ((AbstractStartup) 
task).getFileName() != null) {
                 taskFile = new File(tasksDir, ((AbstractStartup) 
task).getFileName());
+                if (taskFile.createNewFile()) {
+                    OutputStream out = new FileOutputStream(taskFile);
+                    taskElem.serializeAndConsume(out);
+                    out.flush();
+                } else {
+                    throw new Exception("Error while creating the file : " +
+                            taskFile.getAbsolutePath());
+                }
             } else {
-                taskFile = new File(tasksDir, task.getName() + ".xml");
-            }
-
-            if (taskFile.createNewFile()) {
-                OutputStream out = new FileOutputStream(taskFile);
-                taslElem.serializeAndConsume(out);
-                out.flush();
-            } else {
-                throw new Exception("Error while creating the file : " + 
taskFile.getAbsolutePath());
+                parent.addChild(taskElem);
             }
         }
     }
 
-    private void serializeSequence(SequenceMediator seq) throws Exception {
+    private void serializeSequence(SequenceMediator seq, OMElement parent) 
throws Exception {
+
         File seqDir = new File(rootDirectory, 
MultiXMLConfigurationBuilder.SEQUENCES_DIR);
         if (!seqDir.exists()) {
             if (!seqDir.mkdir()) {
-                throw new Exception("Error while creating the directory for 
sequences : " + seqDir.getAbsolutePath());
+                throw new Exception("Error while creating the directory for 
sequences : " +
+                        seqDir.getAbsolutePath());
             }
         }
 
-        OMElement seqElem = 
MediatorSerializerFinder.getInstance().getSerializer(seq).serializeMediator(null,
 seq);
+        OMElement seqElem = 
MediatorSerializerFinder.getInstance().getSerializer(seq).
+                serializeMediator(null, seq);
         File seqFile;
         if (seq.getFileName() != null) {
             seqFile = new File(seqDir, seq.getFileName());
+            if (seqFile.createNewFile()) {
+                OutputStream out = new FileOutputStream(seqFile);
+                seqElem.serializeAndConsume(out);
+                out.flush();
+            } else {
+                throw new Exception("Error while creating the file : " + 
seqFile.getAbsolutePath());
+            }
         } else {
-            seqFile = new File(seqDir, seq.getName() + ".xml");
-        }
-
-        if (seqFile.createNewFile()) {
-            OutputStream out = new FileOutputStream(seqFile);
-            seqElem.serializeAndConsume(out);
-            out.flush();
-        } else {
-            throw new Exception("Error while creating the file : " + 
seqFile.getAbsolutePath());
+            parent.addChild(seqElem);
         }
 
     }
 
-    private void serializeEndpoint(Endpoint epr) throws Exception {
+    private void serializeEndpoint(Endpoint epr, OMElement parent) throws 
Exception {
         File eprDir = new File(rootDirectory, 
MultiXMLConfigurationBuilder.ENDPOINTS_DIR);
         if (!eprDir.exists()) {
             if (!eprDir.mkdir()) {
-                throw new Exception("Error while creating the directory for 
endpoints : " + eprDir.getAbsolutePath());
+                throw new Exception("Error while creating the directory for 
endpoints : " +
+                        eprDir.getAbsolutePath());
             }
         }
 
@@ -259,36 +281,33 @@
         File eprFile;
         if (epr instanceof AbstractEndpoint && ((AbstractEndpoint) 
epr).getFileName() != null) {
             eprFile = new File(eprDir, ((AbstractEndpoint) epr).getFileName());
-        } else if (epr.getName() != null) {
-            eprFile = new File(eprDir, epr.getName() + ".xml");
-        } else {
-            eprFile = new File(eprDir, "endpoint_" + new 
GregorianCalendar().getTimeInMillis() + ".xml");
-        }
-
-        if (eprFile.createNewFile()) {
-            OutputStream out = new FileOutputStream(eprFile);
-            eprElem.serializeAndConsume(out);
-            out.flush();
+            if (eprFile.createNewFile()) {
+                OutputStream out = new FileOutputStream(eprFile);
+                eprElem.serializeAndConsume(out);
+                out.flush();
+            } else {
+                throw new Exception("Error while creating the file : " + 
eprFile.getAbsolutePath());
+            }
         } else {
-            throw new Exception("Error while creating the file : " + 
eprFile.getAbsolutePath());
+            parent.addChild(eprElem);
         }
 
     }
 
-    private void serializeLocalRegistryValues(Collection localValues) throws 
Exception {
+    private void serializeLocalRegistryValues(Collection localValues, 
OMElement parent)
+            throws Exception {
 
         if (log.isDebugEnabled()) {
             log.debug("Serializing the local registry values 
(sequences/endpoints/local entries)");
         }
 
-        OMElement localEntriesRoot = null;
         boolean entriesDirCreated = false;
 
         for (Object o : localValues) {
             if (o instanceof SequenceMediator) {
-                serializeSequence((SequenceMediator) o);
+                serializeSequence((SequenceMediator) o, parent);
             } else if (o instanceof Endpoint) {
-                serializeEndpoint((Endpoint) o);
+                serializeEndpoint((Endpoint) o, parent);
             } else if (o instanceof Entry) {
                 Entry entry = (Entry) o;
                 if ((SynapseConstants.SERVER_HOST.equals(entry.getKey())
@@ -297,85 +316,68 @@
                     continue;
                 }
 
-                if 
(MultiXMLConfigurationBuilder.LOCAL_ENTRIES_FILE_ID.equals(entry.getFileName()))
 {
-                    // If this entry comes from the top level local entry 
definition file we simply add this
-                    // OMElement to a paranet element
-                    if (localEntriesRoot == null) {
-                        localEntriesRoot = 
OMAbstractFactory.getSOAP11Factory().createOMElement(
-                                new QName(XMLConfigConstants.SYNAPSE_NAMESPACE,
-                                        
MultiXMLConfigurationBuilder.LOCAL_ENTRIES_ROOT_ELT));
-                    }
-                    EntrySerializer.serializeEntry(entry, localEntriesRoot);
-
-                } else {
-                    File entriesDir = null;
-                    OMElement entryElem = 
EntrySerializer.serializeEntry(entry, null);
-                    if (!entriesDirCreated) {
-                        entriesDir = new File(rootDirectory, 
MultiXMLConfigurationBuilder.LOCAL_ENTRY_DIR);
-                        if (!entriesDir.mkdir()) {
-                            throw new Exception("Error while creating the 
local entries directory : " +
-                                    entriesDir.getAbsolutePath());
-                        }
-                        entriesDirCreated = true;
-                    }
-
-                    File entryFile;
-                    if (entry.getFileName() != null) {
-                       entryFile  = new File(entriesDir, entry.getFileName());
-                    } else {
-                        entryFile = new File(entriesDir, "entry_" + new 
GregorianCalendar().getTimeInMillis() + ".xml");
+                File entriesDir = null;
+                OMElement entryElem = EntrySerializer.serializeEntry(entry, 
null);
+                if (!entriesDirCreated) {
+                    entriesDir = new File(rootDirectory, 
MultiXMLConfigurationBuilder.
+                            LOCAL_ENTRY_DIR);
+                    if (!entriesDir.mkdir()) {
+                        throw new Exception("Error while creating the local 
entries directory : " +
+                                entriesDir.getAbsolutePath());
                     }
+                    entriesDirCreated = true;
+                }
 
+                File entryFile;
+                if (entry.getFileName() != null) {
+                   entryFile  = new File(entriesDir, entry.getFileName());
                     if (entryFile.createNewFile()) {
                         OutputStream out = new FileOutputStream(entryFile);
                         entryElem.serializeAndConsume(out);
                         out.flush();
                     } else {
-                        throw new Exception("Error while creating the file : " 
+ entryFile.getAbsolutePath());
+                        throw new Exception("Error while creating the file : " 
+
+                                entryFile.getAbsolutePath());
                     }
+                } else {
+                    parent.addChild(entryElem);
                 }
             }
         }
-
-        if (localEntriesRoot != null) {
-            File entryFile = new File(rootDirectory, 
MultiXMLConfigurationBuilder.LOCAL_ENTRIES_FILE);
-            if (entryFile.createNewFile()) {
-                OutputStream out = new FileOutputStream(entryFile);
-                localEntriesRoot.serializeAndConsume(out);
-                out.flush();
-            } else {
-                throw new Exception("Error while creating file : " + 
entryFile.getAbsolutePath());
-            }
-        }
     }
 
     private void cleanUpDirectory()  throws Exception {
-        // If the target directory already exists and contains any files 
simply rename it to create a backup
-        // This method does not delete the target directory
+        // If the target directory already exists and contains any files 
simply rename it to
+        // create a backup - This method does not delete the target directory
         if (rootDirectory.exists() && rootDirectory.isDirectory() &&
                 rootDirectory.listFiles().length > 0) {
             if (log.isDebugEnabled()) {
-                log.debug("The directory :" + rootDirectory.getPath() + " 
already exists. Creating a backup.");
+                log.debug("The directory :" + rootDirectory.getPath() + " 
already exists. " +
+                        "Creating a backup.");
             }
 
             backupDirectory = new File(rootDirectory.getParentFile(), "__tmp" +
                     new GregorianCalendar().getTimeInMillis());
             if (!rootDirectory.renameTo(backupDirectory)) {
-                throw new Exception("Error occured while backing up the 
existing file structure at : " +
-                        rootDirectory.getAbsolutePath());
+                throw new Exception("Error occured while backing up the 
existing file structure " +
+                        "at : " + rootDirectory.getAbsolutePath());
             }
         }
 
         // Create a new target directory
         if (!rootDirectory.mkdirs()) {
-            throw new Exception("Error while creating the directory at : " + 
rootDirectory.getAbsolutePath());
+            throw new Exception("Error while creating the directory at : " +
+                    rootDirectory.getAbsolutePath());
         }
     }
 
     private void restoreBackup() {
         if (backupDirectory != null) {
-            log.info("Attempting to restore the directory : " + 
rootDirectory.getPath() +
-                    " using the available backups");
+            if (log.isDebugEnabled()) {
+                log.debug("Attempting to restore the directory : " + 
rootDirectory.getPath() +
+                        " using the available backups");
+            }
+
             if (rootDirectory.exists() && rootDirectory.isDirectory()) {
                 deleteDirectory(rootDirectory);
             }
@@ -385,8 +387,8 @@
                 backupDirectory = null;
             } else {
                 log.error("Failed to restore the directory at : " + 
rootDirectory.getPath() +
-                        " from the available backup. You will need to restore 
the directory manually. A backup is" +
-                        "available at : " + backupDirectory.getPath());
+                        " from the available backup. You will need to restore 
the directory " +
+                        "manually. A backup is available at : " + 
backupDirectory.getPath());
             }
         }
     }
@@ -410,5 +412,4 @@
         return dir.delete();
     }
 
-
 }
\ No newline at end of file

Modified: 
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java
URL: 
http://svn.apache.org/viewvc/synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java?rev=802703&r1=802702&r2=802703&view=diff
==============================================================================
--- 
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java
 (original)
+++ 
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java
 Mon Aug 10 09:37:25 2009
@@ -122,11 +122,9 @@
         // the root level before trying to look in the registry (hence 
config.getMainSequence
         // can not be used here)
         if 
(!config.getLocalRegistry().containsKey(SynapseConstants.MAIN_SEQUENCE_KEY)) {
-            // if the root tag does not contain any mediators & registry does 
not have a
-            // entry with key main then use the defualt main sequence
-            if (rootSequence.getList().isEmpty() && config.getMainSequence() 
== null) {
-                setDefaultMainSequence(config);
-            } else {
+            // if the root tag contains child mediators & registry does not 
have an
+            // entry with key 'main' then set as main sequence
+            if (!rootSequence.getList().isEmpty() && config.getMainSequence() 
== null) {
                 config.addSequence(rootSequence.getName(), rootSequence);
             }
         } else if (!rootSequence.getList().isEmpty()) {
@@ -135,10 +133,6 @@
                     "toplevel mediators simultaniously");
         }
 
-        if (config.getFaultSequence() == null) {
-            setDefaultFaultSequence(config);
-        }
-
         return config;
     }
 


Reply via email to