[exo-jcr-commits] exo-jcr SVN: r2535 - in kernel/trunk/exo.kernel.container/src: test/java/org/exoplatform/container/configuration and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Jun 10 05:33:55 EDT 2010
Author: nfilotto
Date: 2010-06-10 05:33:54 -0400 (Thu, 10 Jun 2010)
New Revision: 2535
Added:
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/config-manager-configuration-a.xml
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/config-manager-configuration-b.xml
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/config-manager-configuration-c.xml
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestConfigurationManagerImpl.java
Log:
EXOJCR-745: Allow cascading imports in configuration files
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java 2010-06-10 09:25:00 UTC (rev 2534)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java 2010-06-10 09:33:54 UTC (rev 2535)
@@ -167,32 +167,11 @@
configurations_ = conf;
else
configurations_.mergeConfiguration(conf);
- List urls = conf.getImports();
- if (urls != null)
- {
- for (int i = 0; i < urls.size(); i++)
- {
- String uri = (String)urls.get(i);
- URL urlObject = getURL(uri);
- if (urlObject != null)
- {
- if (LOG_DEBUG)
- log.info("\timport " + urlObject);
- // Set the URL of imported file
- currentURL.set(urlObject);
- conf = unmarshaller.unmarshall(urlObject);
- configurations_.mergeConfiguration(conf);
- }
- else
- {
- log.warn("Couldn't process the URL for " + uri + " configuration file ignored ");
- }
- }
- }
+ importConf(unmarshaller, conf);
}
catch (Exception ex)
{
- log.error("Cannot process the configuration " + url, ex);
+ log.error("Cannot process the configuration " + currentURL.get(), ex);
}
finally
{
@@ -200,6 +179,58 @@
}
}
+ /**
+ * Recursively import the configuration files
+ *
+ * @param unmarshaller the unmarshaller used to unmarshall the configuration file to import
+ * @param conf the configuration in which we get the list of files to import
+ * @throws Exception if an exception occurs while loading the files to import
+ */
+ private void importConf(ConfigurationUnmarshaller unmarshaller, Configuration conf) throws Exception
+ {
+ importConf(unmarshaller, conf, 1);
+ }
+
+ /**
+ * Recursively import the configuration files
+ *
+ * @param unmarshaller the unmarshaller used to unmarshall the configuration file to import
+ * @param conf the configuration in which we get the list of files to import
+ * @param depth used to log properly the URL of the file to import
+ * @throws Exception if an exception occurs while loading the files to import
+ */
+ private void importConf(ConfigurationUnmarshaller unmarshaller, Configuration conf, int depth) throws Exception
+ {
+ List urls = conf.getImports();
+ if (urls != null)
+ {
+ StringBuilder prefix = new StringBuilder(depth);
+ for (int i = 0; i < depth; i++)
+ {
+ prefix.append('\t');
+ }
+ for (int i = 0; i < urls.size(); i++)
+ {
+ String uri = (String)urls.get(i);
+ URL urlObject = getURL(uri);
+ if (urlObject != null)
+ {
+ if (LOG_DEBUG)
+ log.info(prefix + "import " + urlObject);
+ // Set the URL of imported file
+ currentURL.set(urlObject);
+ conf = unmarshaller.unmarshall(urlObject);
+ configurations_.mergeConfiguration(conf);
+ importConf(unmarshaller, conf, depth + 1);
+ }
+ else
+ {
+ log.warn("Couldn't process the URL for " + uri + " configuration file ignored ");
+ }
+ }
+ }
+ }
+
public void processRemoveConfiguration()
{
if (configurations_ == null)
Modified: kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestConfigurationManagerImpl.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestConfigurationManagerImpl.java 2010-06-10 09:25:00 UTC (rev 2534)
+++ kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestConfigurationManagerImpl.java 2010-06-10 09:33:54 UTC (rev 2535)
@@ -18,6 +18,8 @@
import junit.framework.TestCase;
+import org.exoplatform.container.xml.Configuration;
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -199,6 +201,39 @@
checkURL(url, true);
}
+ public void testImport() throws Exception
+ {
+ // no import
+ ConfigurationManager cm = new ConfigurationManagerImpl();
+ cm.addConfiguration("classpath:/org/exoplatform/container/configuration/config-manager-configuration-a.xml");
+ Configuration conf = cm.getConfiguration();
+ assertNotNull(conf.getComponent("A"));
+ assertTrue(conf.getComponent("A").getDocumentURL().getFile().endsWith("config-manager-configuration-a.xml"));
+ assertNull(conf.getComponent("B"));
+ assertNull(conf.getComponent("C"));
+
+ // b import a
+ cm = new ConfigurationManagerImpl();
+ cm.addConfiguration("classpath:/org/exoplatform/container/configuration/config-manager-configuration-b.xml");
+ conf = cm.getConfiguration();
+ assertNotNull(conf.getComponent("A"));
+ assertTrue(conf.getComponent("A").getDocumentURL().getFile().endsWith("config-manager-configuration-a.xml"));
+ assertNotNull(conf.getComponent("B"));
+ assertTrue(conf.getComponent("B").getDocumentURL().getFile().endsWith("config-manager-configuration-b.xml"));
+ assertNull(conf.getComponent("C"));
+
+ // c import b and b import a
+ cm = new ConfigurationManagerImpl();
+ cm.addConfiguration("classpath:/org/exoplatform/container/configuration/config-manager-configuration-c.xml");
+ conf = cm.getConfiguration();
+ assertNotNull(conf.getComponent("A"));
+ assertTrue(conf.getComponent("A").getDocumentURL().getFile().endsWith("config-manager-configuration-a.xml"));
+ assertNotNull(conf.getComponent("B"));
+ assertTrue(conf.getComponent("B").getDocumentURL().getFile().endsWith("config-manager-configuration-b.xml"));
+ assertNotNull(conf.getComponent("C"));
+ assertTrue(conf.getComponent("C").getDocumentURL().getFile().endsWith("config-manager-configuration-c.xml"));
+ }
+
private void checkURL(URL url) throws Exception
{
checkURL(url, false);
Added: kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/config-manager-configuration-a.xml
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/config-manager-configuration-a.xml (rev 0)
+++ kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/config-manager-configuration-a.xml 2010-06-10 09:33:54 UTC (rev 2535)
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+-->
+<configuration
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
+ xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
+
+ <component>
+ <type>A</type>
+ </component>
+
+</configuration>
\ No newline at end of file
Added: kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/config-manager-configuration-b.xml
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/config-manager-configuration-b.xml (rev 0)
+++ kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/config-manager-configuration-b.xml 2010-06-10 09:33:54 UTC (rev 2535)
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+-->
+<configuration
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
+ xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
+
+ <component>
+ <type>B</type>
+ </component>
+
+ <import>classpath:/org/exoplatform/container/configuration/config-manager-configuration-a.xml</import>
+</configuration>
\ No newline at end of file
Added: kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/config-manager-configuration-c.xml
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/config-manager-configuration-c.xml (rev 0)
+++ kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/config-manager-configuration-c.xml 2010-06-10 09:33:54 UTC (rev 2535)
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+-->
+<configuration
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
+ xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
+
+ <component>
+ <type>C</type>
+ </component>
+
+ <import>classpath:/org/exoplatform/container/configuration/config-manager-configuration-b.xml</import>
+</configuration>
\ No newline at end of file
More information about the exo-jcr-commits
mailing list