Author: julien(a)jboss.com
Date: 2007-06-26 21:10:07 -0400 (Tue, 26 Jun 2007)
New Revision: 7572
Modified:
trunk/core/build.xml
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java
Log:
port bug fixes from GA branch
Modified: trunk/core/build.xml
===================================================================
--- trunk/core/build.xml 2007-06-27 00:58:53 UTC (rev 7571)
+++ trunk/core/build.xml 2007-06-27 01:10:07 UTC (rev 7572)
@@ -334,7 +334,6 @@
<fileset dir="${jboss.portal-search.root}/lib"
includes="portal-search-lib.jar"/>
<fileset dir="${jboss.portal-identity.root}/lib"
includes="portal-identity-lib.jar"/>
<fileset dir="${jboss.portal-registration.root}/lib"
includes="portal-registration-lib.jar"/>
- <fileset dir="${jboss.portal-samples.root}/lib"
includes="portal-samples-lib.jar"/>
<fileset dir="${ehcache.ehcache.lib}"
includes="ehcache.jar"/>
<fileset dir="${apache.collections.lib}"
includes="commons-collections.jar"/>
<fileset dir="${javassist.javassist.lib}"
includes="javassist.jar"/>
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2007-06-27
00:58:53 UTC (rev 7571)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2007-06-27
01:10:07 UTC (rev 7572)
@@ -69,6 +69,7 @@
private Map childrenMap;
private Map properties;
private Map unmodifiableProperties;
+ private boolean childrenAccessed;
public PortalObjectImpl()
{
@@ -79,6 +80,12 @@
{
this.declaredPropertyMap = new HashMap();
this.listener = null;
+
+ //
+ this.childrenMap = null;
+ this.properties = null;
+ this.unmodifiableProperties = null;
+ this.childrenAccessed = false;
}
public Long getKey()
@@ -236,11 +243,19 @@
{
/** . */
- private final Iterator iterator = objectNode.getChildren().values().iterator();
+ private final Iterator iterator;
/** . */
private PortalObject next = null;
+
+ public ChildrenIterator()
+ {
+ Map childrenMap = objectNode.getChildren();
+ Collection children = childrenMap.values();
+ iterator = children.iterator();
+ }
+
public void remove()
{
throw new UnsupportedOperationException();
@@ -293,6 +308,7 @@
if (childrenMap == null)
{
childrenMap = new HashMap();
+ childrenAccessed = true;
}
else
{
@@ -339,7 +355,8 @@
ObjectNode childNode = (ObjectNode)objectNode.getChildren().get(name);
if (childNode != null)
{
- return childNode.getObject();
+ childrenAccessed = true;
+ return childNode.getObject();
}
else
{
@@ -347,6 +364,9 @@
}
}
+ /**
+ * Get the aggregated properties in a lazy manner.
+ */
public Map getProperties()
{
// Lazy compute properties
@@ -368,6 +388,8 @@
//
this.unmodifiableProperties = Collections.unmodifiableMap(properties);
}
+
+ //
return unmodifiableProperties;
}
@@ -404,21 +426,53 @@
if (value == null)
{
declaredPropertyMap.remove(name);
-
- // If aggregated properties is loaded then we udpate it
- if (properties != null)
- {
- properties.remove(name);
- }
+ String parentValue = getParent().getProperty(name);
+ propagatePropertyUpdate(name, parentValue, true);
}
else
{
declaredPropertyMap.put(name, value);
+ propagatePropertyUpdate(name, value, true);
+ }
+ }
- // If aggregated properties is loaded then we udpate it
- if (properties != null)
+ /**
+ * This method propagates a property value update to descendants which have been
*loaded* from the database.
+ * It considers that if the <code>properties</code> field of the runtime
state is null then it means that
+ * the object is loaded but children have not made an attempt to read the properties
of this object. Indeed
+ * if a child is loaded any attempt to access its aggregated properties will trigger
the computation of
+ * the aggregated properties of this object.
+ *
+ * Null property values are considered as removal
+ *
+ * @param name the property name
+ * @param value the new property value
+ * @param force the update
+ */
+ private void propagatePropertyUpdate(String name, String value, boolean force)
+ {
+ if (properties != null)
+ {
+ if (force || !declaredPropertyMap.containsKey(name))
{
- properties.put(name, value);
+ if (value == null)
+ {
+ properties.remove(name);
+ }
+ else
+ {
+ properties.put(name, value);
+ }
+
+ //
+ if (childrenAccessed)
+ {
+ for (Iterator i = this.getChildren().iterator(); i.hasNext();)
+ {
+ PortalObjectImpl child = (PortalObjectImpl)i.next();
+ child.propagatePropertyUpdate(name, value, false);
+ }
+ }
}
}
}
@@ -437,11 +491,6 @@
return (String)properties.get(name);
}
-// public final boolean isDashboard()
-// {
-// return getDashboardContext() != null;
-// }
-
public abstract int getType();
public String toString()
@@ -543,6 +592,7 @@
protected final void addChild(String name, PortalObjectImpl childObject) throws
DuplicatePortalObjectException, IllegalArgumentException
{
objectNode.addChild(name, childObject);
+ childrenAccessed = true;
}
private PortalObjectImpl copy(PortalObjectImpl parent, String name, boolean deep)
throws DuplicatePortalObjectException
Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java 2007-06-27
00:58:53 UTC (rev 7571)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java 2007-06-27
01:10:07 UTC (rev 7572)
@@ -85,7 +85,7 @@
this.uri = contentURI;
//
- setDeclaredProperty(PORTAL_PROP_WINDOW_CONTENT_TYPE, contentType.toString());
+ setDeclaredProperty(WindowImpl.PORTAL_PROP_WINDOW_CONTENT_TYPE,
contentType.toString());
}
private ContentStateImpl getContentState()
Modified:
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java 2007-06-27
00:58:53 UTC (rev 7571)
+++
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java 2007-06-27
01:10:07 UTC (rev 7572)
@@ -39,10 +39,7 @@
import org.jboss.portal.test.core.model.content.SimpleContent;
import org.jboss.portal.test.framework.AbstractPortalTestCase;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
+import java.util.*;
/**
* Portal Object Container Test Cases based on the microcontainer architecture
@@ -68,6 +65,96 @@
TransactionAssert.commitTransaction();
}
+ /**
+ *
+ */
+ public void testPropertyUpdateCascadeToDescendantsWhenTheyDoNotDeclareIt() throws
Exception
+ {
+ TransactionAssert.beginTransaction();
+ PortalContainer ctx = container.getContext();
+ Portal n1 = ctx.createPortal("default");
+ Page n2 = n1.createPage("default");
+ Page n3 = n2.createPage("default");
+ Map p1 = n1.getProperties();
+ Map p2 = n2.getProperties();
+ Map p3 = n3.getProperties();
+
+ //
+ n1.setDeclaredProperty("foo", "bar1");
+ assertEquals("bar1", p1.get("foo"));
+ assertEquals("bar1", p2.get("foo"));
+ assertEquals("bar1", p3.get("foo"));
+
+ //
+ n2.setDeclaredProperty("foo", "bar2");
+ assertEquals("bar1", p1.get("foo"));
+ assertEquals("bar2", p2.get("foo"));
+ assertEquals("bar2", p3.get("foo"));
+
+ TransactionAssert.commitTransaction();
+ }
+
+ /**
+ *
+ */
+ public void testPropertyUpdateDoesNotCascadeToDescendantsWhenTheyDeclareIt() throws
Exception
+ {
+ TransactionAssert.beginTransaction();
+ PortalContainer ctx = container.getContext();
+ Portal n1 = ctx.createPortal("default");
+ Page n2 = n1.createPage("default");
+ Page n3 = n2.createPage("default");
+ Map p1 = n1.getProperties();
+ Map p2 = n2.getProperties();
+ Map p3 = n3.getProperties();
+
+ //
+ n2.setDeclaredProperty("foo", "bar1");
+ assertEquals(null, p1.get("foo"));
+ assertEquals("bar1", p2.get("foo"));
+ assertEquals("bar1", p3.get("foo"));
+
+ //
+ n1.setDeclaredProperty("foo", "bar2");
+ assertEquals("bar2", p1.get("foo"));
+ assertEquals("bar1", p2.get("foo"));
+ assertEquals("bar1", p3.get("foo"));
+
+ //
+ TransactionAssert.commitTransaction();
+ }
+
+ /**
+ *
+ */
+ public void testOverridenPropertyRemovalPropagateParentValueToDescendants() throws
Exception
+ {
+ TransactionAssert.beginTransaction();
+ PortalContainer ctx = container.getContext();
+ Portal n1 = ctx.createPortal("default");
+ Page n2 = n1.createPage("default");
+ Page n3 = n2.createPage("default");
+ Map p1 = n1.getProperties();
+ Map p2 = n2.getProperties();
+ Map p3 = n3.getProperties();
+
+ //
+ n1.setDeclaredProperty("foo", "bar1");
+ n2.setDeclaredProperty("foo", "bar2");
+ assertEquals("bar1", p1.get("foo"));
+ assertEquals("bar2", p2.get("foo"));
+ assertEquals("bar2", p3.get("foo"));
+
+ //
+ n2.setDeclaredProperty("foo", null);
+ assertEquals("bar1", p1.get("foo"));
+ assertEquals("bar1", p2.get("foo"));
+ assertEquals("bar1", p3.get("foo"));
+
+ //
+ TransactionAssert.commitTransaction();
+ }
+
public void testCRUD() throws Exception
{
TransactionAssert.beginTransaction();