Author: nfilotto
Date: 2010-07-07 09:16:02 -0400 (Wed, 07 Jul 2010)
New Revision: 2751
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainer.java
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java
Log:
EXOJCR-842: Now if at least one portal container definition has been defined, which means
that we expect the new behavior, the portal container will be only created if the related
portal container definition has been defined otherwise we assume that we don't want to
create the portal container. Thanks to this feature the portal container
"portal" is no more mandatory.
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java
===================================================================
---
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java 2010-07-07
12:19:10 UTC (rev 2750)
+++
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java 2010-07-07
13:16:02 UTC (rev 2751)
@@ -189,12 +189,20 @@
public void registerPortalContainer(ServletContext context)
{
PortalContainerConfig config = getPortalContainerConfig();
- // Ensure that the portal container has been registered
- config.registerPortalContainerName(context.getServletContextName());
if (config.hasDefinition())
{
// The new behavior has been detected thus, the creation will be done at the end
asynchronously
- portalContexts.add(new WebAppInitContext(context));
+ if (config.isPortalContainerName(context.getServletContextName()))
+ {
+ // The portal context has been registered has a portal container
+ portalContexts.add(new WebAppInitContext(context));
+ }
+ else
+ {
+ log.info("We assume that the ServletContext '" +
context.getServletContextName()
+ + "' is not a portal since no portal container with the same name
has been"
+ + " registered to the component PortalContainerConfig.");
+ }
// We assume that a ServletContext of a portal container owns configuration
files
final PortalContainerPreInitTask task = new PortalContainerPreInitTask()
{
@@ -208,6 +216,8 @@
}
else
{
+ // Ensure that the portal container has been registered
+ config.registerPortalContainerName(context.getServletContextName());
// The old behavior has been detected thus, the creation will be done
synchronously
createPortalContainer(context);
}
@@ -244,11 +254,14 @@
PortalContainerConfig config = getPortalContainerConfig();
for (String portalContainerName : initTasks.keySet())
{
- // Unregister name of portal container that doesn't exist
- log.warn("The portal container '" + portalContainerName +
"' doesn't not exist or"
- + " it has not yet been registered, please check your
PortalContainerDefinitions and "
- + "the loading order.");
- config.unregisterPortalContainerName(portalContainerName);
+ if (config.isPortalContainerName(portalContainerName))
+ {
+ // Unregister name of portal container that doesn't exist
+ log.warn("The portal container '" + portalContainerName +
"' doesn't not exist or"
+ + " it has not yet been registered, please check your
PortalContainerDefinitions and "
+ + "the loading order.");
+ config.unregisterPortalContainerName(portalContainerName);
+ }
}
// remove all the unneeded tasks
initTasks.clear();
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java
===================================================================
---
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java 2010-07-07
12:19:10 UTC (rev 2750)
+++
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java 2010-07-07
13:16:02 UTC (rev 2751)
@@ -39,8 +39,10 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.servlet.ServletContext;
@@ -105,9 +107,9 @@
private volatile boolean initialized;
/**
- * The list of all the portal containers
+ * The set of all the portal containers
*/
- private List<String> portalContainerNames;
+ private Set<String> portalContainerNames;
/**
* The list of all the web application scopes
@@ -354,10 +356,10 @@
{
if (!portalContainerNames.contains(name))
{
- final List<String> lPortalContainerNames = new
ArrayList<String>(portalContainerNames.size() + 1);
+ final Set<String> lPortalContainerNames = new
LinkedHashSet<String>(portalContainerNames.size() + 1);
lPortalContainerNames.add(name);
lPortalContainerNames.addAll(portalContainerNames);
- this.portalContainerNames =
Collections.unmodifiableList(lPortalContainerNames);
+ this.portalContainerNames = Collections.unmodifiableSet(lPortalContainerNames);
}
}
@@ -369,9 +371,9 @@
{
if (portalContainerNames.contains(name))
{
- final List<String> lPortalContainerNames = new
ArrayList<String>(portalContainerNames);
+ final Set<String> lPortalContainerNames = new
LinkedHashSet<String>(portalContainerNames);
lPortalContainerNames.remove(name);
- this.portalContainerNames =
Collections.unmodifiableList(lPortalContainerNames);
+ this.portalContainerNames = Collections.unmodifiableSet(lPortalContainerNames);
}
}
@@ -438,7 +440,7 @@
else if (scopes.isEmpty())
{
// we assume that the old behavior is expected
- return defaultDefinition.getName();
+ return defaultDefinition.getName();
}
final List<String> result = scopes.get(contextName);
if (result == null || result.isEmpty())
@@ -542,7 +544,7 @@
if (portalContainerName == null)
{
throw new IllegalArgumentException("The portal container name cannot be
null");
- }
+ }
return getPortalContainerNames(contextName).contains(portalContainerName);
}
@@ -975,9 +977,12 @@
*/
private void initialize(Map<String, PortalContainerDefinition> mDefinitions)
{
- final List<String> lPortalContainerNames = new
ArrayList<String>(mDefinitions.size() + 1);
- // Add the default portal container name
- lPortalContainerNames.add(defaultDefinition.getName());
+ final Set<String> lPortalContainerNames = new
LinkedHashSet<String>(mDefinitions.size() + 1);
+ if (mDefinitions.isEmpty())
+ {
+ // Add the default portal container name
+ lPortalContainerNames.add(defaultDefinition.getName());
+ }
final Map<String, List<String>> mScopes = new HashMap<String,
List<String>>();
boolean first = true;
for (Map.Entry<String, PortalContainerDefinition> entry :
mDefinitions.entrySet())
@@ -985,10 +990,7 @@
PortalContainerDefinition definition = entry.getValue();
String name = definition.getName();
boolean hasChanged = false;
- if (!name.equals(defaultDefinition.getName()))
- {
- lPortalContainerNames.add(name);
- }
+ lPortalContainerNames.add(name);
if (first)
{
first = false;
@@ -1032,7 +1034,7 @@
registerDependencies(defaultDefinition, mScopes);
}
}
- this.portalContainerNames = Collections.unmodifiableList(lPortalContainerNames);
+ this.portalContainerNames = Collections.unmodifiableSet(lPortalContainerNames);
this.scopes = Collections.unmodifiableMap(mScopes);
// clear the changes
changes.clear();
Modified:
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainer.java
===================================================================
---
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainer.java 2010-07-07
12:19:10 UTC (rev 2750)
+++
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainer.java 2010-07-07
13:16:02 UTC (rev 2751)
@@ -43,7 +43,7 @@
assertEquals("myRest", portal.getRestContextName());
assertEquals("my-exo-domain", portal.getRealmName());
- assertTrue(PortalContainer.isPortalContainerName("myPortal"));
+ assertFalse(PortalContainer.isPortalContainerName("myPortal"));
assertTrue(PortalContainer.isPortalContainerName("portal"));
assertFalse(PortalContainer.isPortalContainerName("foo"));
@@ -73,7 +73,7 @@
assertEquals("myRest",
PortalContainer.getRestContextName("foo"));
assertEquals("my-exo-domain",
PortalContainer.getRealmName("foo"));
- assertTrue(PortalContainer.isPortalContainerName("myPortal"));
+ assertFalse(PortalContainer.isPortalContainerName("myPortal"));
assertTrue(PortalContainer.isPortalContainerName("portal"));
assertFalse(PortalContainer.isPortalContainerName("foo"));
@@ -84,7 +84,7 @@
assertEquals("myRest", PortalContainer.getCurrentRestContextName());
assertEquals("my-exo-domain", PortalContainer.getCurrentRealmName());
- assertTrue(PortalContainer.isPortalContainerName("myPortal"));
+ assertFalse(PortalContainer.isPortalContainerName("myPortal"));
assertTrue(PortalContainer.isPortalContainerName("portal"));
assertFalse(PortalContainer.isPortalContainerName("foo"));
}
Modified:
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java
===================================================================
---
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java 2010-07-07
12:19:10 UTC (rev 2750)
+++
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java 2010-07-07
13:16:02 UTC (rev 2751)
@@ -48,6 +48,9 @@
assertEquals(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME,
config.getDefaultPortalContainer());
assertEquals(PortalContainerConfig.DEFAULT_REST_CONTEXT_NAME,
config.getDefaultRestContext());
assertEquals(PortalContainerConfig.DEFAULT_REALM_NAME,
config.getDefaultRealmName());
+ assertTrue(config.isPortalContainerName("portal"));
+ assertFalse(config.isPortalContainerName("myPortal"));
+ assertFalse(config.isPortalContainerName("myPortal-dpcdef"));
assertFalse(config.hasDefinition());
rootContainer =
createRootContainer("portal-container-config-with-default-values.xml");
@@ -56,6 +59,9 @@
assertEquals("myPortal", config.getDefaultPortalContainer());
assertEquals("myRest", config.getDefaultRestContext());
assertEquals("my-exo-domain", config.getDefaultRealmName());
+ assertFalse(config.isPortalContainerName("portal"));
+ assertTrue(config.isPortalContainerName("myPortal"));
+ assertFalse(config.isPortalContainerName("myPortal-dpcdef"));
assertFalse(config.hasDefinition());
rootContainer =
@@ -65,6 +71,9 @@
assertEquals("myPortal-dpcdef", config.getDefaultPortalContainer());
assertEquals("myRest-dpcdef", config.getDefaultRestContext());
assertEquals("my-exo-domain-dpcdef", config.getDefaultRealmName());
+ assertFalse(config.isPortalContainerName("portal"));
+ assertFalse(config.isPortalContainerName("myPortal"));
+ assertTrue(config.isPortalContainerName("myPortal-dpcdef"));
assertFalse(config.hasDefinition());
rootContainer =
createRootContainer("portal-container-config-with-default-values-and-with-portal-def.xml");
@@ -282,7 +291,7 @@
assertEquals("my-exo-domain",
config.getRealmName("myPortal"));
assertEquals("my-exo-domain-pcdef",
config.getRealmName("myPortal-pcdef"));
assertFalse(config.isPortalContainerName("foo"));
- assertTrue(config.isPortalContainerName("myPortal"));
+ assertFalse(config.isPortalContainerName("myPortal"));
assertTrue(config.isPortalContainerName("myPortal-pcdef"));
// Needed for backward compatibility
assertFalse(config.isScopeValid("foo", "foo"));
@@ -345,7 +354,7 @@
assertEquals("my-exo-domain",
config.getRealmName("myPortal"));
assertEquals("my-exo-domain",
config.getRealmName("myPortal-pcdef"));
assertFalse(config.isPortalContainerName("foo"));
- assertTrue(config.isPortalContainerName("myPortal"));
+ assertFalse(config.isPortalContainerName("myPortal"));
assertTrue(config.isPortalContainerName("myPortal-pcdef"));
// Needed for backward compatibility
assertFalse(config.isScopeValid("foo", "foo"));
@@ -466,13 +475,12 @@
assertTrue(names != null && !names.isEmpty());
assertEquals("myPortal-pcdef", names.get(0));
names = config.getPortalContainerNames("myPortal");
- assertTrue(names != null && !names.isEmpty());
- assertEquals("myPortal", names.get(0));
+ assertTrue(names != null && names.isEmpty());
names = config.getPortalContainerNames("myPortal-pcdef");
assertTrue(names != null && !names.isEmpty());
assertEquals("myPortal-pcdef", names.get(0));
assertEquals("myPortal-pcdef",
config.getPortalContainerName("foo"));
- assertEquals("myPortal",
config.getPortalContainerName("myPortal"));
+ assertNull(config.getPortalContainerName("myPortal"));
assertEquals("myPortal-pcdef",
config.getPortalContainerName("myPortal-pcdef"));
assertEquals("myRest", config.getRestContextName("foo"));
assertEquals("myRest", config.getRestContextName("myPortal"));
@@ -481,7 +489,7 @@
assertEquals("my-exo-domain",
config.getRealmName("myPortal"));
assertEquals("my-exo-domain-pcdef",
config.getRealmName("myPortal-pcdef"));
assertFalse(config.isPortalContainerName("foo"));
- assertTrue(config.isPortalContainerName("myPortal"));
+ assertFalse(config.isPortalContainerName("myPortal"));
assertTrue(config.isPortalContainerName("myPortal-pcdef"));
assertFalse(config.isScopeValid("foo", "foo"));
assertFalse(config.isScopeValid("myPortal", "foo"));
@@ -523,13 +531,12 @@
assertTrue(names != null && !names.isEmpty());
assertEquals("myPortal-pcdef", names.get(0));
names = config.getPortalContainerNames("myPortal");
- assertTrue(names != null && !names.isEmpty());
- assertEquals("myPortal", names.get(0));
+ assertTrue(names != null && names.isEmpty());
names = config.getPortalContainerNames("myPortal-pcdef");
assertTrue(names != null && !names.isEmpty());
assertEquals("myPortal-pcdef", names.get(0));
assertEquals("myPortal-pcdef",
config.getPortalContainerName("foo"));
- assertEquals("myPortal",
config.getPortalContainerName("myPortal"));
+ assertNull(config.getPortalContainerName("myPortal"));
assertEquals("myPortal-pcdef",
config.getPortalContainerName("myPortal-pcdef"));
assertEquals("myRest", config.getRestContextName("foo"));
assertEquals("myRest",
config.getRestContextName("myPortal"));
@@ -538,7 +545,7 @@
assertEquals("my-exo-domain",
config.getRealmName("myPortal"));
assertEquals("my-exo-domain-pcdef",
config.getRealmName("myPortal-pcdef"));
assertFalse(config.isPortalContainerName("foo"));
- assertTrue(config.isPortalContainerName("myPortal"));
+ assertFalse(config.isPortalContainerName("myPortal"));
assertTrue(config.isPortalContainerName("myPortal-pcdef"));
assertFalse(config.isScopeValid("foo", "foo"));
assertFalse(config.isScopeValid("myPortal", "foo"));
@@ -565,13 +572,12 @@
assertEquals(1, names.size());
assertEquals("myPortal-pcdef", names.get(0));
names = config.getPortalContainerNames("myPortal");
- assertTrue(names != null && !names.isEmpty());
- assertEquals("myPortal", names.get(0));
+ assertTrue(names != null && names.isEmpty());
names = config.getPortalContainerNames("myPortal-pcdef");
assertTrue(names != null && !names.isEmpty());
assertEquals("myPortal-pcdef", names.get(0));
assertEquals("myPortal-pcdef",
config.getPortalContainerName("foo"));
- assertEquals("myPortal",
config.getPortalContainerName("myPortal"));
+ assertNull(config.getPortalContainerName("myPortal"));
assertEquals("myPortal-pcdef",
config.getPortalContainerName("myPortal-pcdef"));
assertEquals("myRest", config.getRestContextName("foo"));
assertEquals("myRest", config.getRestContextName("myPortal"));
@@ -580,7 +586,7 @@
assertEquals("my-exo-domain",
config.getRealmName("myPortal"));
assertEquals("my-exo-domain-pcdef",
config.getRealmName("myPortal-pcdef"));
assertFalse(config.isPortalContainerName("foo"));
- assertTrue(config.isPortalContainerName("myPortal"));
+ assertFalse(config.isPortalContainerName("myPortal"));
assertTrue(config.isPortalContainerName("myPortal-pcdef"));
assertFalse(config.isScopeValid("foo", "foo"));
assertFalse(config.isScopeValid("myPortal", "foo"));