Author: julien_viet
Date: 2009-12-11 08:04:44 -0500 (Fri, 11 Dec 2009)
New Revision: 1005
Added:
kernel/branches/config-branch/
kernel/branches/config-branch/exo.kernel.commons/src/main/java/org/exoplatform/commons/Platform.java
kernel/branches/config-branch/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/Tools.java
kernel/branches/config-branch/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestEnvironment.java
kernel/branches/config-branch/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestTools.java
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestComponentPluginProfile.java
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestComponentProfile.java
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestImportProfile.java
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestInitParamProfile.java
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/component-configuration.xml
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/component-plugin-configuration.xml
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/import-configuration.xml
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/init-param-configuration.xml
Removed:
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/Environnment.java
Modified:
kernel/branches/config-branch/exo.kernel.commons/src/main/java/org/exoplatform/commons/Environment.java
kernel/branches/config-branch/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PropertyManager.java
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/StandaloneContainer.java
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationUnmarshaller.java
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/MockConfigurationManagerImpl.java
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/NoKernelNamespaceSAXFilter.java
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/AbstractTestContainer.java
Log:
configuration branch
Copied: kernel/branches/config-branch (from rev 760, kernel/tags/2.2.0-Beta03)
Modified:
kernel/branches/config-branch/exo.kernel.commons/src/main/java/org/exoplatform/commons/Environment.java
===================================================================
---
kernel/tags/2.2.0-Beta03/exo.kernel.commons/src/main/java/org/exoplatform/commons/Environment.java 2009-11-18
16:40:15 UTC (rev 760)
+++
kernel/branches/config-branch/exo.kernel.commons/src/main/java/org/exoplatform/commons/Environment.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -21,63 +21,80 @@
public class Environment
{
- static final public int UNKNOWN = 0;
+ /** The jonas profile name. */
+ public static final String JONAS_PROFILE = "jonas";
- static final public int STAND_ALONE = 1;
+ /** The JBoss profile name. */
+ public static final String JBOSS_PROFILE = "jboss";
- static final public int TOMCAT_PLATFORM = 2;
+ /** The test profile name. */
+ public static final String TEST_PROFILE = "test";
- static final public int JBOSS_PLATFORM = 3;
+ /** The standalone profile name. */
+ public static final String STANDALONE_PROFILE = "standalone";
- static final public int JETTY_PLATFORM = 4;
+ /** The jetty profile name. */
+ public static final String JETTY_PROFILE = "jetty";
- static final public int WEBSHPERE_PLATFORM = 5;
+ /** The websphere profile name. */
+ public static final String WEBSPHERE_PROFILE = "webpshere";
- static final public int WEBLOGIC_PLATFORM = 6;
+ /** The weblogic profile name. */
+ public static final String WEBLOGIC_PROFILE = "weblogic";
+ /** The tomcat profile name. */
+ public static final String TOMCAT_PROFILE = "tomcat";
+
static private Environment singleton_;
- private int platform_;
+ private final Platform platform_;
private Environment()
{
+ String jonasHome = System.getProperty("jonas.base");
String catalinaHome = System.getProperty("catalina.home");
String jbossHome = System.getProperty("jboss.home.dir");
String jettyHome = System.getProperty("jetty.home");
String websphereHome = System.getProperty("was.install.root");
String weblogicHome = System.getProperty("weblogic.Name");
String standAlone = System.getProperty("maven.exoplatform.dir");
- if (jbossHome != null)
+
+ //
+ if (jonasHome != null)
{
- platform_ = JBOSS_PLATFORM;
+ platform_ = Platform.JONAS_PLATFORM;
}
+ else if (jbossHome != null)
+ {
+ platform_ = Platform.JBOSS_PLATFORM;
+ }
else if (catalinaHome != null)
{
- platform_ = TOMCAT_PLATFORM;
+ platform_ = Platform.TOMCAT_PLATFORM;
}
else if (jettyHome != null)
{
- platform_ = JETTY_PLATFORM;
+ platform_ = Platform.JETTY_PLATFORM;
}
else if (websphereHome != null)
{
- platform_ = WEBSHPERE_PLATFORM;
+ platform_ = Platform.WEBSHPERE_PLATFORM;
}
else if (weblogicHome != null)
{
- platform_ = WEBLOGIC_PLATFORM;
+ platform_ = Platform.WEBLOGIC_PLATFORM;
}
else if (standAlone != null)
{
- platform_ = STAND_ALONE;
+ platform_ = Platform.STAND_ALONE;
}
else
{
- platform_ = UNKNOWN;
+ platform_ = Platform.UNKNOWN_PLATFORM;
}
}
- public int getPlatform()
+ public Platform getPlatform()
{
return platform_;
}
@@ -93,4 +110,9 @@
}
return singleton_;
}
+
+ public static boolean isJBoss()
+ {
+ return getInstance().getPlatform() == Platform.JBOSS_PLATFORM;
+ }
}
Added:
kernel/branches/config-branch/exo.kernel.commons/src/main/java/org/exoplatform/commons/Platform.java
===================================================================
---
kernel/branches/config-branch/exo.kernel.commons/src/main/java/org/exoplatform/commons/Platform.java
(rev 0)
+++
kernel/branches/config-branch/exo.kernel.commons/src/main/java/org/exoplatform/commons/Platform.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.commons;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.UndeclaredThrowableException;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public enum Platform
+{
+
+ JONAS_PLATFORM(Environment.JONAS_PROFILE, getDefaultDataDir()),
+
+ STAND_ALONE(Environment.STANDALONE_PROFILE, getDefaultDataDir()),
+
+ TOMCAT_PLATFORM(Environment.TOMCAT_PROFILE, getDefaultDataDir()),
+
+ JBOSS_PLATFORM(Environment.JBOSS_PROFILE,
System.getProperty("jboss.server.data.dir")),
+
+ JETTY_PLATFORM(Environment.JETTY_PROFILE, getDefaultDataDir()),
+
+ WEBSHPERE_PLATFORM(Environment.WEBSPHERE_PROFILE, getDefaultDataDir()),
+
+ WEBLOGIC_PLATFORM(Environment.WEBLOGIC_PROFILE, getDefaultDataDir()),
+
+ UNKNOWN_PLATFORM(null, getDefaultDataDir());
+
+ /** The profile name of the server. */
+ private final String profile;
+
+ /** The profile name of the server. */
+ private final String dataDir;
+
+ Platform(String profile, String dataDir)
+ {
+ this.profile = profile;
+ this.dataDir = dataDir;
+ }
+
+ public String getProfile()
+ {
+ return profile;
+ }
+
+ public String getDataDir()
+ {
+ return dataDir;
+ }
+
+ private static String getDefaultDataDir()
+ {
+ try
+ {
+ File dataDir = new File("../temp");
+ return dataDir.getCanonicalPath();
+ }
+ catch (IOException e)
+ {
+ throw new UndeclaredThrowableException(e);
+ }
+ }
+}
Modified:
kernel/branches/config-branch/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PropertyManager.java
===================================================================
---
kernel/tags/2.2.0-Beta03/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PropertyManager.java 2009-11-18
16:40:15 UTC (rev 760)
+++
kernel/branches/config-branch/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PropertyManager.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.commons.utils;
+import org.exoplatform.commons.Environment;
+
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -38,6 +40,12 @@
public static final String DEVELOPING = "exo.product.developing";
/** . */
+ public static final String RUNTIME_PROFILES = "exo.profiles";
+
+ /** . */
+ public static final String DATA_DIR = "exo.data.dir";
+
+ /** . */
private static final ConcurrentMap<String, String> cache = new
ConcurrentHashMap<String, String>();
/** This is read only once at startup. */
@@ -59,8 +67,12 @@
*/
public static String getProperty(String propertyName)
{
- if (useCache)
+ if (DATA_DIR.endsWith(propertyName))
{
+ return Environment.getInstance().getPlatform().getProfile();
+ }
+ else if (useCache)
+ {
if (DEVELOPING.equals(propertyName))
{
return developping ? "true" : "false";
Added:
kernel/branches/config-branch/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/Tools.java
===================================================================
---
kernel/branches/config-branch/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/Tools.java
(rev 0)
+++
kernel/branches/config-branch/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/Tools.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.commons.utils;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class Tools
+{
+
+ /**
+ * Instantiates a {@link HashSet} object and fills it with the provided element
array.
+ *
+ * @param elements the list of elements to add
+ * @param <E> the element type
+ * @return the set of elements
+ * @throws NullPointerException if the element array is null
+ */
+ public static <E> Set<E> set(E... elements) throws NullPointerException
+ {
+ if (elements == null)
+ {
+ throw new NullPointerException("No null element array accepted");
+ }
+ HashSet<E> set = new HashSet<E>();
+ if (elements.length > 0)
+ {
+ for (E element : elements)
+ {
+ set.add(element);
+ }
+ }
+ return set;
+ }
+
+}
Added:
kernel/branches/config-branch/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestEnvironment.java
===================================================================
---
kernel/branches/config-branch/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestEnvironment.java
(rev 0)
+++
kernel/branches/config-branch/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestEnvironment.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.commons.utils;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+import org.exoplatform.commons.Environment;
+import org.exoplatform.commons.Platform;
+
+import java.lang.reflect.Field;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestEnvironment extends TestCase
+{
+
+ private void forceEnvReset()
+ {
+ try
+ {
+ Field field = Environment.class.getDeclaredField("singleton_");
+ field.setAccessible(true);
+ field.set(null, null);
+ }
+ catch (Exception e)
+ {
+ AssertionFailedError afe = new AssertionFailedError();
+ afe.initCause(e);
+ throw afe;
+ }
+
+ System.clearProperty("jboss.home.dir");
+ System.clearProperty("jboss.server.data.dir");
+ System.clearProperty("catalina.home");
+ }
+
+ public void testJBoss()
+ {
+ forceEnvReset();
+ System.setProperty("jboss.home.dir", "jboss_home");
+ System.setProperty("jboss.server.data.dir",
"jboss_server_data");
+ Environment env = Environment.getInstance();
+ Platform platform = env.getPlatform();
+ assertEquals(Platform.JBOSS_PLATFORM, platform);
+ assertEquals(Environment.JBOSS_PROFILE, platform.getProfile());
+ assertEquals("jboss_server_data", platform.getDataDir());
+ }
+
+ public void testTomcat()
+ {
+ forceEnvReset();
+ System.setProperty("catalina.home", "catalina_home");
+ Environment env = Environment.getInstance();
+ Platform platform = env.getPlatform();
+ assertEquals(Platform.TOMCAT_PLATFORM, platform);
+ assertEquals(Environment.TOMCAT_PROFILE, platform.getProfile());
+ }
+}
Added:
kernel/branches/config-branch/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestTools.java
===================================================================
---
kernel/branches/config-branch/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestTools.java
(rev 0)
+++
kernel/branches/config-branch/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestTools.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.commons.utils;
+
+import junit.framework.TestCase;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestTools extends TestCase
+{
+
+ public void testEmtySet()
+ {
+ Set<String> strings = Tools.set();
+ assertTrue(strings instanceof HashSet);
+ assertTrue(strings.isEmpty());
+ }
+
+ public void testSingletonSet1()
+ {
+ Set<String> strings = Tools.set("a");
+ assertTrue(strings instanceof HashSet);
+ assertEquals(1, strings.size());
+ assertTrue(strings.contains("a"));
+ }
+
+ public void testSingletonSet2()
+ {
+ Set<String> strings = Tools.set("a", "a");
+ assertTrue(strings instanceof HashSet);
+ assertEquals(1, strings.size());
+ assertTrue(strings.contains("a"));
+ }
+
+ public void testTwoElementsInSet()
+ {
+ Set<String> strings = Tools.set("a", "b");
+ assertTrue(strings instanceof HashSet);
+ assertEquals(2, strings.size());
+ assertTrue(strings.contains("a"));
+ assertTrue(strings.contains("b"));
+ }
+
+ public void testSetThrowsNPE()
+ {
+ try
+ {
+ Tools.set((String[])null);
+ fail();
+ }
+ catch (NullPointerException expected)
+ {
+ }
+ }
+}
Deleted:
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/Environnment.java
===================================================================
---
kernel/tags/2.2.0-Beta03/exo.kernel.container/src/main/java/org/exoplatform/container/Environnment.java 2009-11-18
16:40:15 UTC (rev 760)
+++
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/Environnment.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -1,31 +0,0 @@
-/*
- * 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.
- */
-package org.exoplatform.container;
-
-/**
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
- * @version $Revision$
- */
-class Environnment
-{
- static boolean isJBoss()
- {
- return System.getProperty("jboss.server.name") != null;
- }
-}
Modified:
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java
===================================================================
---
kernel/tags/2.2.0-Beta03/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java 2009-11-18
16:40:15 UTC (rev 760)
+++
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.container;
+import org.exoplatform.commons.utils.PropertyManager;
import org.exoplatform.container.component.ComponentLifecyclePlugin;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.jmx.ManageableContainer;
@@ -31,9 +32,12 @@
import java.lang.reflect.Constructor;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* Created by The eXo Platform SAS Author : Tuan Nguyen
@@ -42,6 +46,32 @@
public class ExoContainer extends ManageableContainer
{
+ /**
+ * Returns an unmodifable set of profiles defined by the value returned by invoking
+ * {@link PropertyManager#getProperty(String)} with the {@link
org.exoplatform.commons.utils.PropertyManager#RUNTIME_PROFILES}
+ * property.
+ *
+ * @return the set of profiles
+ */
+ public static Set<String> getProfiles()
+ {
+ //
+ Set<String> profiles = new HashSet<String>();
+
+ // Obtain profile list by runtime properties
+ String profileList =
PropertyManager.getProperty(PropertyManager.RUNTIME_PROFILES);
+ if (profileList != null)
+ {
+ for (String profile : profileList.split(","))
+ {
+ profiles.add(profile.trim());
+ }
+ }
+
+ //
+ return Collections.unmodifiableSet(profiles);
+ }
+
Log log = ExoLogger.getLogger(ExoContainer.class);
private Map<String, ComponentLifecyclePlugin> componentLifecylePlugin_ =
Modified:
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java
===================================================================
---
kernel/tags/2.2.0-Beta03/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java 2009-11-18
16:40:15 UTC (rev 760)
+++
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.container;
+import org.exoplatform.commons.Environment;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.configuration.ConfigurationManagerImpl;
import org.exoplatform.container.configuration.MockConfigurationManagerImpl;
@@ -40,6 +41,7 @@
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Queue;
import java.util.Set;
@@ -84,6 +86,8 @@
private final J2EEServerInfo serverenv_ = new J2EEServerInfo();
+ private final Set<String> profiles;
+
/**
* The list of all the tasks to execute while initializing the corresponding portal
containers
*/
@@ -98,7 +102,26 @@
public RootContainer()
{
super(new ManagementContextImpl(findMBeanServer(), new HashMap<String,
String>()));
+
+ //
+ Set<String> profiles = new HashSet<String>();
+
+ // Add the profile defined by the server
+ String envProfile = Environment.getInstance().getPlatform().getProfile();
+ if (envProfile != null)
+ {
+ profiles.add(envProfile);
+ }
+
+ // Obtain profile list by runtime properties
+ profiles.addAll(ExoContainer.getProfiles());
+
+ // Lof the active profiles
+ log.info("Active profiles " + profiles);
+
+ //
Runtime.getRuntime().addShutdownHook(new ShutdownThread(this));
+ this.profiles= profiles;
this.registerComponentInstance(J2EEServerInfo.class, serverenv_);
}
@@ -259,7 +282,7 @@
// Set the full classloader of the portal container
Thread.currentThread().setContextClassLoader(pcontainer.getPortalClassLoader());
hasChanged = true;
- ConfigurationManagerImpl cService = new
ConfigurationManagerImpl(pcontainer.getPortalContext());
+ ConfigurationManagerImpl cService = new
ConfigurationManagerImpl(pcontainer.getPortalContext(), profiles);
// add configs from services
try
@@ -273,7 +296,7 @@
// Add configuration that depends on the environment
String uri;
- if (Environnment.isJBoss())
+ if (Environment.isJBoss())
{
uri = "conf/portal/jboss-configuration.xml";
}
@@ -379,7 +402,7 @@
try
{
RootContainer rootContainer = new RootContainer();
- ConfigurationManagerImpl service = new ConfigurationManagerImpl();
+ ConfigurationManagerImpl service = new
ConfigurationManagerImpl(rootContainer.profiles);
service.addConfiguration(ContainerUtil.getConfigurationURL("conf/configuration.xml"));
if (System.getProperty("maven.exoplatform.dir") != null)
{
@@ -638,7 +661,7 @@
* Executes the task
*
* @param context the servlet context of the web application
- * @param container The portal container on which we would like to execute the
task
+ * @param portalContainer The portal container on which we would like to execute
the task
*/
public void execute(ServletContext context, PortalContainer portalContainer);
Modified:
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/StandaloneContainer.java
===================================================================
---
kernel/tags/2.2.0-Beta03/exo.kernel.container/src/main/java/org/exoplatform/container/StandaloneContainer.java 2009-11-18
16:40:15 UTC (rev 760)
+++
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/StandaloneContainer.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.container;
+import org.exoplatform.commons.utils.PropertyManager;
import org.exoplatform.container.configuration.ConfigurationException;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.configuration.ConfigurationManagerImpl;
@@ -28,7 +29,9 @@
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* Created by The eXo Platform SAS .
@@ -71,7 +74,9 @@
private StandaloneContainer(ClassLoader configClassLoader)
{
super(new MX4JComponentAdapterFactory(), null);
- configurationManager = new ConfigurationManagerImpl(configClassLoader);
+
+ //
+ configurationManager = new ConfigurationManagerImpl(configClassLoader,
ExoContainer.getProfiles());
this.registerComponentInstance(ConfigurationManager.class, configurationManager);
registerComponentImplementation(SessionManagerImpl.class);
}
Modified:
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java
===================================================================
---
kernel/tags/2.2.0-Beta03/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java 2009-11-18
16:40:15 UTC (rev 760)
+++
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationManagerImpl.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -34,6 +34,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import javax.servlet.ServletContext;
@@ -67,6 +68,9 @@
private boolean validateSchema = true;
+ /** . */
+ private final Set<String> profiles;
+
/** The URL of the current document being unmarshalled. */
private static final ThreadLocal<URL> currentURL = new
ThreadLocal<URL>();
@@ -79,18 +83,21 @@
return currentURL.get();
}
- public ConfigurationManagerImpl()
+ public ConfigurationManagerImpl(Set<String> profiles)
{
+ this.profiles = profiles;
}
- public ConfigurationManagerImpl(ServletContext context)
+ public ConfigurationManagerImpl(ServletContext context, Set<String> profiles)
{
scontext_ = context;
+ this.profiles = profiles;
}
- public ConfigurationManagerImpl(ClassLoader loader)
+ public ConfigurationManagerImpl(ClassLoader loader, Set<String> profiles)
{
scontextClassLoader_ = loader;
+ this.profiles = profiles;
}
public Configuration getConfiguration()
Modified:
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationUnmarshaller.java
===================================================================
---
kernel/tags/2.2.0-Beta03/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationUnmarshaller.java 2009-11-18
16:40:15 UTC (rev 760)
+++
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/ConfigurationUnmarshaller.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.container.configuration;
+import org.exoplatform.commons.utils.PropertyManager;
import org.exoplatform.container.xml.Configuration;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -33,6 +34,9 @@
import java.io.StringReader;
import java.io.StringWriter;
import java.net.URL;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
import javax.xml.XMLConstants;
import javax.xml.parsers.SAXParser;
@@ -105,6 +109,19 @@
}
}
+ /** . */
+ private final Set<String> profiles;
+
+ public ConfigurationUnmarshaller(Set<String> profiles)
+ {
+ this.profiles = profiles;
+ }
+
+ public ConfigurationUnmarshaller()
+ {
+ this.profiles = Collections.emptySet();
+ }
+
/**
* Returns true if the configuration file is valid according to its schema
declaration. If the file
* does not have any schema declaration, the file will be reported as valid.
@@ -180,7 +197,9 @@
InputSource source = new InputSource(url.openStream());
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser saxParser = spf.newSAXParser();
- saxParser.parse(source, new NoKernelNamespaceSAXFilter(hd));
+
saxParser.getXMLReader().setFeature("http://xml.org/sax/features/nam...;,
true);
+
saxParser.getXMLReader().setFeature("http://xml.org/sax/features/nam...;,
true);
+ saxParser.parse(source, new NoKernelNamespaceSAXFilter(profiles, hd));
// Reuse the parsed document
String document = buffer.toString();
Modified:
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/MockConfigurationManagerImpl.java
===================================================================
---
kernel/tags/2.2.0-Beta03/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/MockConfigurationManagerImpl.java 2009-11-18
16:40:15 UTC (rev 760)
+++
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/MockConfigurationManagerImpl.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.container.configuration;
+import org.exoplatform.container.ExoContainer;
+
import java.net.URL;
import javax.servlet.ServletContext;
@@ -36,7 +38,7 @@
public MockConfigurationManagerImpl(ServletContext context) throws Exception
{
- super(context);
+ super(context, ExoContainer.getProfiles());
confDir_ = System.getProperty("mock.portal.dir") + "/WEB-INF";
}
Modified:
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/NoKernelNamespaceSAXFilter.java
===================================================================
---
kernel/tags/2.2.0-Beta03/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/NoKernelNamespaceSAXFilter.java 2009-11-18
16:40:15 UTC (rev 760)
+++
kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/configuration/NoKernelNamespaceSAXFilter.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.container.configuration;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
@@ -25,8 +27,12 @@
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.DefaultHandler;
+import java.util.HashSet;
+import java.util.Set;
+
/**
* Removes kernel namespace declaration from the document to not confuse the jibx thing.
+ * It also filters the active profiles from the XML stream.
*
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
@@ -34,11 +40,28 @@
class NoKernelNamespaceSAXFilter extends DefaultHandler
{
+ /** . */
+ private static final Log log =
ExoLogger.getExoLogger(NoKernelNamespaceSAXFilter.class);
+
+ /** . */
+ private static final String KERNEL_URI =
"http://www.exoplaform.org/xml/ns/kernel_1_0.xsd";
+
+ /** . */
+ private static final String XSI_URI =
"http://www.w3.org/2001/XMLSchema-instance";
+
+ /** . */
+ private final Set<String> activeProfiles;
+
+ /** . */
private ContentHandler contentHandler;
- NoKernelNamespaceSAXFilter(ContentHandler contentHandler)
+ /** . */
+ private final Set<String> blackListedPrefixes = new HashSet<String>();
+
+ NoKernelNamespaceSAXFilter(Set<String> activeProfiles, ContentHandler
contentHandler)
{
this.contentHandler = contentHandler;
+ this.activeProfiles = activeProfiles;
}
public void setDocumentLocator(Locator locator)
@@ -58,47 +81,176 @@
public void startPrefixMapping(String prefix, String uri) throws SAXException
{
- contentHandler.startPrefixMapping(prefix, uri);
+ if (depth == 0)
+ {
+ if (KERNEL_URI.equals(uri) || XSI_URI.equals(uri))
+ {
+ blackListedPrefixes.add(prefix);
+ log.debug("Black listing prefix " + prefix + " with uri "
+ uri);
+ }
+ else
+ {
+ contentHandler.startPrefixMapping(prefix, uri);
+ log.debug("Start prefix mapping " + prefix + " with uri "
+ uri);
+ }
+ }
}
public void endPrefixMapping(String prefix) throws SAXException
{
- contentHandler.endPrefixMapping(prefix);
+ if (depth == 0)
+ {
+ if (!blackListedPrefixes.remove(prefix))
+ {
+ log.debug("Ending prefix mapping " + prefix);
+ contentHandler.endPrefixMapping(prefix);
+ }
+ else
+ {
+ log.debug("Removed prefix mapping " + prefix + " from black
list ");
+ }
+ }
}
public void startElement(String uri, String localName, String qName, Attributes atts)
throws SAXException
{
- if (qName.equals("configuration"))
+ if (depth == 0)
{
- atts = new AttributesImpl();
+ AttributesImpl noNSAtts = new AttributesImpl();
+ for (int i = 0;i < atts.getLength();i++)
+ {
+ String attQName = atts.getQName(i);
+ if ((attQName.equals("xmlns")) &&
blackListedPrefixes.contains(""))
+ {
+ // Skip
+ log.debug("Skipping black listed xmlns attribute");
+ }
+ else if (attQName.startsWith("xmlns:") &&
blackListedPrefixes.contains(attQName.substring(6)))
+ {
+ // Skip
+ log.debug("Skipping black listed " + attQName + "
attribute");
+ }
+ else
+ {
+ String attURI = atts.getURI(i);
+ String attLocalName = atts.getLocalName(i);
+ String attType = atts.getType(i);
+ String attValue = atts.getValue(i);
+
+ //
+ if (XSI_URI.equals(attURI))
+ {
+ // Skip
+ log.debug("Skipping XSI " + attQName + "
attribute");
+ continue;
+ }
+
+ //
+ noNSAtts.addAttribute(attURI, attLocalName, attQName, attType, attValue);
+ }
+ }
+
+ //
+ if (KERNEL_URI.equals(uri))
+ {
+ if (!localName.equals(qName))
+ {
+ String prefix = qName.substring(0, qName.indexOf(':'));
+ if (activeProfiles.contains(prefix))
+ {
+ log.debug("Requalifying active profile " + qName + "
start element to " + localName);
+ qName = localName;
+ uri = null;
+ }
+ else
+ {
+ log.debug("Inhibitting element passive profile " + qName +
" start element");
+ depth++;
+ }
+ }
+ else
+ {
+ // Need to clear the URI
+ uri = null;
+ }
+ }
+
+ //
+ if (depth == 0)
+ {
+ log.debug("Propagatting " + qName + " start element");
+ contentHandler.startElement(uri, localName, qName, noNSAtts);
+ }
}
+ else
+ {
+ log.debug("Skipping " + qName + " start element");
+ depth++;
+ }
- //
- contentHandler.startElement(uri, localName, qName, atts);
}
+ private int depth;
+
public void endElement(String uri, String localName, String qName) throws
SAXException
{
- contentHandler.endElement(uri, localName, qName);
+ if (depth == 0)
+ {
+ if (KERNEL_URI.endsWith(uri))
+ {
+ log.debug("Requalifying " + qName + " end element");
+ qName = localName;
+ uri = null;
+ }
+
+ //
+ log.debug("Propagatting " + qName + " end element");
+ contentHandler.endElement(uri, localName, qName);
+ }
+ else
+ {
+ log.debug("Skipping " + qName + " end element");
+ depth--;
+ }
}
public void characters(char[] ch, int start, int length) throws SAXException
{
- contentHandler.characters(ch, start, length);
+ if (depth == 0)
+ {
+ contentHandler.characters(ch, start, length);
+ }
+ else
+ {
+ log.debug("Skipping " + new String(ch, start, length) + " end
element");
+ }
}
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
{
- contentHandler.ignorableWhitespace(ch, start, length);
+ if (depth == 0)
+ {
+ contentHandler.ignorableWhitespace(ch, start, length);
+ }
+ else
+ {
+ log.debug("Skipping " + new String(ch, start, length) + " white
space");
+ }
}
public void processingInstruction(String target, String data) throws SAXException
{
- contentHandler.processingInstruction(target, data);
+ if (depth == 0)
+ {
+ contentHandler.processingInstruction(target, data);
+ }
}
public void skippedEntity(String name) throws SAXException
{
- contentHandler.skippedEntity(name);
+ if (depth == 0)
+ {
+ contentHandler.skippedEntity(name);
+ }
}
}
Added:
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestComponentPluginProfile.java
===================================================================
---
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestComponentPluginProfile.java
(rev 0)
+++
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestComponentPluginProfile.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.container.configuration.test;
+
+import junit.framework.TestCase;
+import org.exoplatform.commons.utils.PropertyManager;
+import org.exoplatform.commons.utils.Tools;
+import org.exoplatform.container.configuration.ConfigurationUnmarshaller;
+import org.exoplatform.container.xml.Component;
+import org.exoplatform.container.xml.Configuration;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.ValueParam;
+
+import java.io.File;
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestComponentPluginProfile extends TestCase
+{
+
+/*
+ public void testNoProfile() throws Exception
+ {
+ String basedir = System.getProperty("basedir");
+ File f = new File(basedir +
"/src/test/resources/org/exoplatform/container/configuration/init-param-configuration.xml");
+ ConfigurationUnmarshaller unmarshaller = new ConfigurationUnmarshaller();
+ URL url = f.toURI().toURL();
+ PropertyManager.setProperty(PropertyManager.RUNTIME_PROFILES, "");
+ Configuration config = unmarshaller.unmarshall(url);
+ Component component = config.getComponent("Component");
+ InitParams initParams = component.getInitParams();
+ ValueParam valueParam = initParams.getValueParam("param");
+ assertEquals("empty", valueParam.getValue());
+ }
+*/
+
+ public void testFooProfile() throws Exception
+ {
+ String basedir = System.getProperty("basedir");
+ File f = new File(basedir +
"/src/test/resources/org/exoplatform/container/configuration/component-plugin-configuration.xml");
+ ConfigurationUnmarshaller unmarshaller = new
ConfigurationUnmarshaller(Tools.set("foo"));
+ URL url = f.toURI().toURL();
+ Configuration config = unmarshaller.unmarshall(url);
+ Component component = config.getComponent("Component");
+ System.out.println("component.getComponentPlugins() = " +
component.getComponentPlugins());
+/*
+ InitParams initParams = component.getInitParams();
+ ValueParam valueParam = initParams.getValueParam("param");
+ assertEquals("foo", valueParam.getValue());
+*/
+ }
+
+/*
+ public void testFooBarProfiles() throws Exception
+ {
+ String basedir = System.getProperty("basedir");
+ File f = new File(basedir +
"/src/test/resources/org/exoplatform/container/configuration/init-param-configuration.xml");
+ ConfigurationUnmarshaller unmarshaller = new ConfigurationUnmarshaller();
+ URL url = f.toURI().toURL();
+ PropertyManager.setProperty(PropertyManager.RUNTIME_PROFILES,
"foo,bar");
+ Configuration config = unmarshaller.unmarshall(url);
+ Component component = config.getComponent("Component");
+ InitParams initParams = component.getInitParams();
+ ValueParam valueParam = initParams.getValueParam("param");
+ assertEquals("bar", valueParam.getValue());
+ }
+*/
+}
\ No newline at end of file
Added:
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestComponentProfile.java
===================================================================
---
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestComponentProfile.java
(rev 0)
+++
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestComponentProfile.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.container.configuration.test;
+
+import junit.framework.TestCase;
+import org.exoplatform.commons.utils.PropertyManager;
+import org.exoplatform.commons.utils.Tools;
+import org.exoplatform.container.configuration.ConfigurationUnmarshaller;
+import org.exoplatform.container.xml.Configuration;
+
+import java.io.File;
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestComponentProfile extends TestCase
+{
+
+ public void testNoProfile() throws Exception
+ {
+ String basedir = System.getProperty("basedir");
+ File f = new File(basedir +
"/src/test/resources/org/exoplatform/container/configuration/component-configuration.xml");
+ ConfigurationUnmarshaller unmarshaller = new
ConfigurationUnmarshaller(Tools.<String>set());
+ URL url = f.toURI().toURL();
+ Configuration config = unmarshaller.unmarshall(url);
+ assertEquals(0, config.getComponents().size());
+ }
+
+ public void testFooProfile() throws Exception
+ {
+ String basedir = System.getProperty("basedir");
+ File f = new File(basedir +
"/src/test/resources/org/exoplatform/container/configuration/component-configuration.xml");
+ ConfigurationUnmarshaller unmarshaller = new
ConfigurationUnmarshaller(Tools.set("foo"));
+ URL url = f.toURI().toURL();
+ Configuration config = unmarshaller.unmarshall(url);
+ assertEquals(1, config.getComponents().size());
+ }
+
+ public void testFooBarProfiles() throws Exception
+ {
+ String basedir = System.getProperty("basedir");
+ File f = new File(basedir +
"/src/test/resources/org/exoplatform/container/configuration/component-configuration.xml");
+ ConfigurationUnmarshaller unmarshaller = new
ConfigurationUnmarshaller(Tools.set("foo", "bar"));
+ URL url = f.toURI().toURL();
+ Configuration config = unmarshaller.unmarshall(url);
+ assertEquals(1, config.getComponents().size());
+ }
+}
Added:
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestImportProfile.java
===================================================================
---
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestImportProfile.java
(rev 0)
+++
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestImportProfile.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.container.configuration.test;
+
+import junit.framework.TestCase;
+import org.exoplatform.commons.utils.PropertyManager;
+import org.exoplatform.commons.utils.Tools;
+import org.exoplatform.container.configuration.ConfigurationUnmarshaller;
+import org.exoplatform.container.xml.Configuration;
+
+import java.io.File;
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestImportProfile extends TestCase
+{
+
+ public void testNoProfile() throws Exception
+ {
+ String basedir = System.getProperty("basedir");
+ File f = new File(basedir +
"/src/test/resources/org/exoplatform/container/configuration/import-configuration.xml");
+ ConfigurationUnmarshaller unmarshaller = new
ConfigurationUnmarshaller(Tools.<String>set());
+ URL url = f.toURI().toURL();
+ Configuration config = unmarshaller.unmarshall(url);
+ assertEquals(1, config.getImports().size());
+ }
+
+ public void testFooProfile() throws Exception
+ {
+ String basedir = System.getProperty("basedir");
+ File f = new File(basedir +
"/src/test/resources/org/exoplatform/container/configuration/import-configuration.xml");
+ ConfigurationUnmarshaller unmarshaller = new
ConfigurationUnmarshaller(Tools.set("foo"));
+ URL url = f.toURI().toURL();
+ Configuration config = unmarshaller.unmarshall(url);
+ assertEquals(2, config.getImports().size());
+ }
+
+ public void testFooBarProfiles() throws Exception
+ {
+ String basedir = System.getProperty("basedir");
+ File f = new File(basedir +
"/src/test/resources/org/exoplatform/container/configuration/import-configuration.xml");
+ ConfigurationUnmarshaller unmarshaller = new
ConfigurationUnmarshaller(Tools.set("foo", "bar"));
+ URL url = f.toURI().toURL();
+ Configuration config = unmarshaller.unmarshall(url);
+ assertEquals(3, config.getImports().size());
+ }
+}
\ No newline at end of file
Added:
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestInitParamProfile.java
===================================================================
---
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestInitParamProfile.java
(rev 0)
+++
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/test/TestInitParamProfile.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2003-2007 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.container.configuration.test;
+
+import junit.framework.TestCase;
+import org.exoplatform.commons.utils.PropertyManager;
+import org.exoplatform.commons.utils.Tools;
+import org.exoplatform.container.configuration.ConfigurationUnmarshaller;
+import org.exoplatform.container.xml.Component;
+import org.exoplatform.container.xml.Configuration;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.ValueParam;
+
+import java.io.File;
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestInitParamProfile extends TestCase
+{
+
+ public void testNoProfile() throws Exception
+ {
+ String basedir = System.getProperty("basedir");
+ File f = new File(basedir +
"/src/test/resources/org/exoplatform/container/configuration/init-param-configuration.xml");
+ ConfigurationUnmarshaller unmarshaller = new
ConfigurationUnmarshaller(Tools.<String>set());
+ URL url = f.toURI().toURL();
+ Configuration config = unmarshaller.unmarshall(url);
+ Component component = config.getComponent("Component");
+ InitParams initParams = component.getInitParams();
+ ValueParam valueParam = initParams.getValueParam("param");
+ assertEquals("empty", valueParam.getValue());
+ }
+
+ public void testFooProfile() throws Exception
+ {
+ String basedir = System.getProperty("basedir");
+ File f = new File(basedir +
"/src/test/resources/org/exoplatform/container/configuration/init-param-configuration.xml");
+ ConfigurationUnmarshaller unmarshaller = new
ConfigurationUnmarshaller(Tools.set("foo"));
+ URL url = f.toURI().toURL();
+ Configuration config = unmarshaller.unmarshall(url);
+ Component component = config.getComponent("Component");
+ InitParams initParams = component.getInitParams();
+ ValueParam valueParam = initParams.getValueParam("param");
+ assertEquals("foo", valueParam.getValue());
+ }
+
+ public void testFooBarProfiles() throws Exception
+ {
+ String basedir = System.getProperty("basedir");
+ File f = new File(basedir +
"/src/test/resources/org/exoplatform/container/configuration/init-param-configuration.xml");
+ ConfigurationUnmarshaller unmarshaller = new
ConfigurationUnmarshaller(Tools.set("foo", "bar"));
+ URL url = f.toURI().toURL();
+ Configuration config = unmarshaller.unmarshall(url);
+ Component component = config.getComponent("Component");
+ InitParams initParams = component.getInitParams();
+ ValueParam valueParam = initParams.getValueParam("param");
+ assertEquals("bar", valueParam.getValue());
+ }
+}
\ No newline at end of file
Modified:
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/AbstractTestContainer.java
===================================================================
---
kernel/tags/2.2.0-Beta03/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/AbstractTestContainer.java 2009-11-18
16:40:15 UTC (rev 760)
+++
kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/AbstractTestContainer.java 2009-12-11
13:04:44 UTC (rev 1005)
@@ -25,6 +25,7 @@
import org.exoplatform.container.configuration.ConfigurationManagerImpl;
import java.net.URL;
+import java.util.HashSet;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
@@ -38,7 +39,7 @@
try
{
RootContainer container = new RootContainer();
- ConfigurationManager manager = new ConfigurationManagerImpl();
+ ConfigurationManager manager = new ConfigurationManagerImpl(new
HashSet<String>());
URL url = AbstractTestContainer.class.getResource(relativeConfigurationFile);
assertNotNull(url);
manager.addConfiguration(url);
Added:
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/component-configuration.xml
===================================================================
---
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/component-configuration.xml
(rev 0)
+++
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/component-configuration.xml 2009-12-11
13:04:44 UTC (rev 1005)
@@ -0,0 +1,39 @@
+<?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_0.xsd
http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns:foo="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns:bar="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+
+ <bar:component>
+ <key>Component</key>
+ <type>ComponentImpl</type>
+ </bar:component>
+
+ <foo:component>
+ <key>Component</key>
+ <type>FooComponent</type>
+ </foo:component>
+
+</configuration>
\ No newline at end of file
Added:
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/component-plugin-configuration.xml
===================================================================
---
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/component-plugin-configuration.xml
(rev 0)
+++
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/component-plugin-configuration.xml 2009-12-11
13:04:44 UTC (rev 1005)
@@ -0,0 +1,46 @@
+<?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_0.xsd
http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns:foo="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns:bar="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+
+ <component>
+ <key>Component</key>
+ <type>ComponentImpl</type>
+ <component-plugins>
+ <component-plugin>
+ <name>Plugin</name>
+ <set-method>set_method</set-method>
+ <type>PluginA</type>
+ </component-plugin>
+ <foo:component-plugin>
+ <name>Plugin</name>
+ <set-method>set_method</set-method>
+ <type>PluginA</type>
+ </foo:component-plugin>
+ </component-plugins>
+ </component>
+
+</configuration>
\ No newline at end of file
Added:
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/import-configuration.xml
===================================================================
---
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/import-configuration.xml
(rev 0)
+++
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/import-configuration.xml 2009-12-11
13:04:44 UTC (rev 1005)
@@ -0,0 +1,33 @@
+<?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_0.xsd
http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns:foo="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns:bar="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+
+ <import>empty</import>
+ <foo:import>foo</foo:import>
+ <bar:import>bar</bar:import>
+
+</configuration>
\ No newline at end of file
Added:
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/init-param-configuration.xml
===================================================================
---
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/init-param-configuration.xml
(rev 0)
+++
kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/init-param-configuration.xml 2009-12-11
13:04:44 UTC (rev 1005)
@@ -0,0 +1,48 @@
+<?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_0.xsd
http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns:foo="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns:bar="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+
+ <component>
+ <key>Component</key>
+ <type>ComponentImpl</type>
+ <init-params>
+ <value-param>
+ <name>param</name>
+ <value>empty</value>
+ </value-param>
+ <foo:value-param>
+ <name>param</name>
+ <value>foo</value>
+ </foo:value-param>
+ <bar:value-param>
+ <name>param</name>
+ <value>bar</value>
+ </bar:value-param>
+ </init-params>
+ </component>
+
+</configuration>
\ No newline at end of file