Author: julien(a)jboss.com
Date: 2007-02-15 08:50:31 -0500 (Thu, 15 Feb 2007)
New Revision: 6297
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPageCommand.java
Log:
JBPORTAL-1240 : Nested pages issue in JS for navigation
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-02-15
13:43:33 UTC (rev 6296)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2007-02-15
13:50:31 UTC (rev 6297)
@@ -47,6 +47,9 @@
/** The logger. */
protected static final Logger log = Logger.getLogger(PortalObjectImpl.class);
+ /** . */
+ protected static final int ALL_TYPES_MASK = CONTEXT_MASK | PORTAL_MASK | PAGE_MASK |
WINDOW_MASK;
+
// Persistent fields
/** The primary key when the object is persisted */
@@ -63,7 +66,7 @@
// Runtime fields
- private Collection collection;
+ private Map childrenMap;
private Map properties;
private PortalObjectIdImpl id;
private DashboardContext dashboardContext;
@@ -79,11 +82,6 @@
this.listener = null;
}
- void addChild(String name, PortalObjectImpl childObject) throws
DuplicatePortalObjectException, IllegalArgumentException
- {
- objectNode.addChild(name, childObject);
- }
-
public Long getKey()
{
return key;
@@ -139,47 +137,34 @@
return copy((PortalObjectImpl)parent, name, deep);
}
- private PortalObjectImpl copy(PortalObjectImpl parent, String name, boolean deep)
throws DuplicatePortalObjectException
+ public Collection getChildren()
{
- // Clone this node
- PortalObjectImpl clone = cloneObject();
+ return getChildren(ALL_TYPES_MASK);
+ }
- // Add the clone to the specified parent
- parent.addChild(name, clone);
+ public Collection getChildren(int wantedMask)
+ {
+ /// Correct eventually the mask
+ final int mask = wantedMask & ALL_TYPES_MASK;
- // Clone children recursively
- if (deep)
+ // Compute the lookup cache key
+ Integer key = new Integer(mask);
+
+ //
+ Collection children = null;
+ if (childrenMap == null)
{
- for (Iterator i = getChildren().iterator();i.hasNext();)
- {
- PortalObjectImpl child = (PortalObjectImpl)i.next();
-
- //
- child.copy(clone, child.getName(), true);
- }
+ childrenMap = new HashMap();
}
+ else
+ {
+ children = (Collection)childrenMap.get(key);
+ }
//
- return clone;
- }
-
- protected abstract PortalObjectImpl cloneObject();
-
- public Collection getChildren(int type)
- {
- return getChildren(new Integer(type));
- }
-
- public Collection getChildren()
- {
- return getChildren(null);
- }
-
- public Collection getChildren(final Integer type)
- {
- if (collection == null)
+ if (children == null)
{
- collection = new Collection()
+ children = new Collection()
{
public void clear()
{
@@ -228,7 +213,7 @@
public int size()
{
- if (type == null)
+ if (mask == ALL_TYPES_MASK)
{
return objectNode.getChildren().size();
}
@@ -251,7 +236,7 @@
public Iterator iterator()
{
- return iterator(type);
+ return iterator(mask);
}
public Object[] toArray(Object a[])
@@ -265,7 +250,7 @@
return tmp.toArray(a);
}
- public Iterator iterator(final Integer type)
+ public Iterator iterator(final int mask)
{
return new Iterator()
{
@@ -282,8 +267,8 @@
while (next == null && iterator.hasNext())
{
ObjectNode node = (ObjectNode)iterator.next();
- PortalObject object = node.getObject();
- if (type == null || object.getType() == type.intValue())
+ PortalObjectImpl object = node.getObject();
+ if (mask == ALL_TYPES_MASK || (object.getMask() & mask)
!= 0)
{
next = object;
}
@@ -308,8 +293,9 @@
};
}
};
+ childrenMap.put(key, children);
}
- return collection;
+ return children;
}
public String getListener()
@@ -426,13 +412,18 @@
return (String)properties.get(name);
}
+ public final boolean isDashboard()
+ {
+ return getDashboardContext() != null;
+ }
+
+ public abstract int getType();
+
public String toString()
{
return objectNode.toString();
}
- public abstract int getType();
-
/** Return the default child of this object based on the declared property that
specifies the default object name. */
protected PortalObject getDefaultChild()
{
@@ -444,10 +435,7 @@
return getChild(portalName);
}
- public final boolean isDashboard()
- {
- return getDashboardContext() != null;
- }
+ protected abstract PortalObjectImpl cloneObject();
/**
* Overridable callback.
@@ -456,6 +444,31 @@
{
}
+ protected final int getMask()
+ {
+ return getMask(getType());
+ }
+
+ /**
+ * Returns the mask for this kind of object.
+ */
+ protected final int getMask(int portalObjectType)
+ {
+ switch (portalObjectType)
+ {
+ case TYPE_CONTEXT:
+ return CONTEXT_MASK;
+ case TYPE_PORTAL:
+ return PORTAL_MASK;
+ case TYPE_PAGE:
+ return PAGE_MASK;
+ case TYPE_WINDOW:
+ return WINDOW_MASK;
+ default:
+ throw new IllegalArgumentException("Unknown type " +
portalObjectType);
+ }
+ }
+
protected final DashboardContext getDashboardContext()
{
if (dashboardContext == null)
@@ -485,6 +498,35 @@
//
return dashboardContext;
}
+
+ protected final void addChild(String name, PortalObjectImpl childObject) throws
DuplicatePortalObjectException, IllegalArgumentException
+ {
+ objectNode.addChild(name, childObject);
+ }
+
+ private PortalObjectImpl copy(PortalObjectImpl parent, String name, boolean deep)
throws DuplicatePortalObjectException
+ {
+ // Clone this node
+ PortalObjectImpl clone = cloneObject();
+
+ // Add the clone to the specified parent
+ parent.addChild(name, clone);
+
+ // Clone children recursively
+ if (deep)
+ {
+ for (Iterator i = getChildren().iterator();i.hasNext();)
+ {
+ PortalObjectImpl child = (PortalObjectImpl)i.next();
+
+ //
+ child.copy(clone, child.getName(), true);
+ }
+ }
+
+ //
+ return clone;
+ }
}
Modified: trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java 2007-02-15
13:43:33 UTC (rev 6296)
+++ trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java 2007-02-15
13:50:31 UTC (rev 6297)
@@ -52,6 +52,18 @@
/** . */
int TYPE_WINDOW = 3;
+ /** . */
+ int CONTEXT_MASK = 0x00000001;
+
+ /** . */
+ int PORTAL_MASK = 0x00000002;
+
+ /** . */
+ int PAGE_MASK = 0x00000004;
+
+ /** . */
+ int WINDOW_MASK = 0x00000008;
+
/**
* Return the object id unique in the scope of its container.
*
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPageCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPageCommand.java 2007-02-15
13:43:33 UTC (rev 6296)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPageCommand.java 2007-02-15
13:50:31 UTC (rev 6297)
@@ -127,7 +127,7 @@
super.create();
// All windows on the page
- windows = new ArrayList(getPage().getChildren(PortalObject.TYPE_WINDOW));
+ windows = new ArrayList(getPage().getChildren(PortalObject.WINDOW_MASK));
//
LayoutService layoutService =
context.getController().getPageService().getLayoutService();