Author: julien(a)jboss.com
Date: 2007-03-04 09:38:16 -0500 (Sun, 04 Mar 2007)
New Revision: 6530
Removed:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectBean.java
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/BeanDecorators.java
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/objectNavigation.xhtml
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/objectTemplate.xhtml
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
trunk/faces/src/main/org/jboss/portal/faces/el/DelegatingPropertyResolver.java
Log:
added a decorator class for PortalObject
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-03-04
13:39:03 UTC (rev 6529)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2007-03-04
14:38:16 UTC (rev 6530)
@@ -142,157 +142,172 @@
return getChildren(ALL_TYPES_MASK);
}
- public Collection getChildren(int wantedMask)
+ private class ChildrenCollection implements Collection
{
- /// Correct eventually the mask
- final int mask = wantedMask & ALL_TYPES_MASK;
- // Compute the lookup cache key
- Integer key = new Integer(mask);
+ /** . */
+ private final int mask;
- //
- Collection children = null;
- if (childrenMap == null)
+ public ChildrenCollection(int mask)
{
- childrenMap = new HashMap();
+ this.mask = mask;
}
- else
+
+ public void clear()
{
- children = (Collection)childrenMap.get(key);
+ throw new UnsupportedOperationException();
}
- //
- if (children == null)
+ public boolean add(Object o)
{
- children = new Collection()
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean remove(Object o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean removeAll(Collection c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean retainAll(Collection c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean containsAll(Collection c)
+ {
+ throw new NotYetImplemented();
+ }
+
+ public boolean contains(Object o)
+ {
+ throw new NotYetImplemented();
+ }
+
+ public boolean isEmpty()
+ {
+ return objectNode.getChildren().isEmpty();
+ }
+
+ public int size()
+ {
+ if (mask == ALL_TYPES_MASK)
{
- public void clear()
+ return objectNode.getChildren().size();
+ }
+ else
+ {
+ int count = 0;
+ for (Iterator i = iterator();i.hasNext();)
{
- throw new UnsupportedOperationException();
+ i.next();
+ count++;
}
+ return count;
+ }
+ }
- public boolean add(Object o)
- {
- throw new UnsupportedOperationException();
- }
+ public Object[] toArray()
+ {
+ return toArray(new Object[0]);
+ }
- public boolean remove(Object o)
- {
- throw new UnsupportedOperationException();
- }
+ public Iterator iterator()
+ {
+ return new ChildrenIterator();
+ }
- public boolean addAll(Collection c)
- {
- throw new UnsupportedOperationException();
- }
+ public Object[] toArray(Object a[])
+ {
+ ArrayList tmp = new ArrayList(objectNode.getChildren().size());
+ for (Iterator i = iterator(); i.hasNext();)
+ {
+ PortalObject child = (PortalObject)i.next();
+ tmp.add(child);
+ }
+ return tmp.toArray(a);
+ }
- public boolean removeAll(Collection c)
- {
- throw new UnsupportedOperationException();
- }
+ private class ChildrenIterator implements Iterator
+ {
- public boolean retainAll(Collection c)
- {
- throw new UnsupportedOperationException();
- }
+ /** . */
+ private final Iterator iterator = objectNode.getChildren().values().iterator();
- public boolean containsAll(Collection c)
- {
- throw new NotYetImplemented();
- }
+ /** . */
+ private PortalObject next = null;
- public boolean contains(Object o)
- {
- throw new NotYetImplemented();
- }
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
- public boolean isEmpty()
+ public boolean hasNext()
+ {
+ if (next == null)
{
- return objectNode.getChildren().isEmpty();
- }
-
- public int size()
- {
- if (mask == ALL_TYPES_MASK)
+ while (next == null && iterator.hasNext())
{
- return objectNode.getChildren().size();
- }
- else
- {
- int count = 0;
- for (Iterator i = iterator();i.hasNext();)
+ ObjectNode node = (ObjectNode)iterator.next();
+ PortalObjectImpl object = node.getObject();
+ if (mask == ALL_TYPES_MASK || (object.getMask() & mask) != 0)
{
- i.next();
- count++;
+ next = object;
}
- return count;
}
}
+ return next != null;
+ }
- public Object[] toArray()
+ public Object next()
+ {
+ if (next == null)
{
- return toArray(new Object[0]);
+ hasNext();
}
-
- public Iterator iterator()
+ if (next == null)
{
- return iterator(mask);
+ throw new NoSuchElementException();
}
+ PortalObject next = this.next;
+ this.next = null;
+ return next;
+ }
+ }
+ }
- public Object[] toArray(Object a[])
- {
- ArrayList tmp = new ArrayList(objectNode.getChildren().size());
- for (Iterator i = iterator(); i.hasNext();)
- {
- PortalObject child = (PortalObject)i.next();
- tmp.add(child);
- }
- return tmp.toArray(a);
- }
+ public Collection getChildren(int wantedMask)
+ {
+ /// Correct eventually the mask
+ final int mask = wantedMask & ALL_TYPES_MASK;
- public Iterator iterator(final int mask)
- {
- return new Iterator()
- {
- Iterator iterator = objectNode.getChildren().values().iterator();
- PortalObject next = null;
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
- public boolean hasNext()
- {
- if (next == null)
- {
- while (next == null && iterator.hasNext())
- {
- ObjectNode node = (ObjectNode)iterator.next();
- PortalObjectImpl object = node.getObject();
- if (mask == ALL_TYPES_MASK || (object.getMask() & mask)
!= 0)
- {
- next = object;
- }
- }
- }
- return next != null;
- }
- public Object next()
- {
- if (next == null)
- {
- hasNext();
- }
- if (next == null)
- {
- throw new NoSuchElementException();
- }
- PortalObject next = this.next;
- this.next = null;
- return next;
- }
- };
- }
- };
+ // Compute the lookup cache key
+ Integer key = new Integer(mask);
+
+ //
+ Collection children = null;
+ if (childrenMap == null)
+ {
+ childrenMap = new HashMap();
+ }
+ else
+ {
+ children = (Collection)childrenMap.get(key);
+ }
+
+ //
+ if (children == null)
+ {
+ children = new ChildrenCollection(mask);
childrenMap.put(key, children);
}
return children;
Modified: trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/BeanDecorators.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/BeanDecorators.java 2007-03-04
13:39:03 UTC (rev 6529)
+++
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/BeanDecorators.java 2007-03-04
14:38:16 UTC (rev 6530)
@@ -33,12 +33,14 @@
import org.jboss.portal.portlet.info.MetaInfo;
import org.jboss.portal.portlet.info.PortletInfo;
import org.jboss.portal.core.model.instance.Instance;
-import org.jboss.portal.core.model.instance.InstanceDefinition;
+import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.model.portal.PortalObjectId;
import javax.faces.context.FacesContext;
import java.util.Set;
import java.util.Locale;
import java.util.ArrayList;
+import java.util.List;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -151,6 +153,7 @@
});
DelegatingPropertyResolver.registerDecorator(Portlet.class, portletDecorator);
+ //
SimpleBeanDecorator instanceDecorator = new SimpleBeanDecorator();
instanceDecorator.setProperty("portlet", new
AbstractPropertyDecorator(Portlet.class)
{
@@ -168,9 +171,52 @@
}
}
});
+ DelegatingPropertyResolver.registerDecorator(Instance.class, instanceDecorator);
//
- DelegatingPropertyResolver.registerDecorator(InstanceDefinition.class,
instanceDecorator);
+ SimpleBeanDecorator portalObjectDecorator = new SimpleBeanDecorator()
+ {
+ private List getChildren(PortalObject object, int mask)
+ {
+ return new ArrayList(object.getChildren(mask));
+ }
+ {
+ setProperty("portals", new
AbstractPropertyDecorator(PortalObject.class)
+ {
+ public Object getValue(Object bean)
+ {
+ PortalObject object = (PortalObject)bean;
+ return getChildren(object, PortalObject.PORTAL_MASK);
+ }
+ });
+ setProperty("pages", new
AbstractPropertyDecorator(PortalObject.class)
+ {
+ public Object getValue(Object bean)
+ {
+ PortalObject object = (PortalObject)bean;
+ return getChildren(object, PortalObject.PAGE_MASK);
+ }
+ });
+ setProperty("windows", new
AbstractPropertyDecorator(PortalObject.class)
+ {
+ public Object getValue(Object bean)
+ {
+ PortalObject object = (PortalObject)bean;
+ return getChildren(object, PortalObject.WINDOW_MASK);
+ }
+ });
+ }
+ };
+ portalObjectDecorator.setProperty("id", new
AbstractPropertyDecorator(PortalObject.class)
+ {
+ public Object getValue(Object bean)
+ {
+ PortalObject object = (PortalObject)bean;
+ PortalObjectId id = object.getId();
+ return id.toString(PortalObjectId.LEGACY_BASE64_FORMAT);
+ }
+ });
+ DelegatingPropertyResolver.registerDecorator(PortalObject.class,
portalObjectDecorator);
}
}
Deleted: trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectBean.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectBean.java 2007-03-04
13:39:03 UTC (rev 6529)
+++
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectBean.java 2007-03-04
14:38:16 UTC (rev 6530)
@@ -1,72 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * 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.jboss.portal.core.admin.ui;
-
-import org.jboss.portal.core.model.portal.PortalObject;
-import org.jboss.portal.core.model.portal.PortalObjectId;
-
-/**
- * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
- * @version $Revision$
- */
-public class PortalObjectBean
-{
- private PortalObject po;
- private PortalObjectBean parent;
-
-
- public PortalObjectBean(PortalObject po)
- {
- this.po = po;
- }
-
- public String getId()
- {
- return po.getId().toString(PortalObjectId.LEGACY_BASE64_FORMAT);
- }
-
- public String getName()
- {
- return po.getName();
- }
-
- public PortalObjectBean getParent()
- {
- if ((parent == null) || (po.getParent() != parent.getPortalObject()))
- {
- parent = new PortalObjectBean(po.getParent());
- }
- return parent;
- }
-
- public int getType()
- {
- return po.getType();
- }
-
- public PortalObject getPortalObject()
- {
- return po;
- }
-
-}
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2007-03-04
13:39:03 UTC (rev 6529)
+++
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2007-03-04
14:38:16 UTC (rev 6530)
@@ -132,9 +132,6 @@
private PortalObject selectedObject;
/** . */
- private PortalObjectBean selectedObjectBean;
-
- /** . */
private List selectedProperties;
// Wired services
@@ -267,21 +264,6 @@
return portalObjectContainer.getObject(id);
}
- public List getPortalNodes()
- {
- return getNodes(PortalObject.PORTAL_MASK);
- }
-
- public List getPageNodes()
- {
- return getNodes(PortalObject.PAGE_MASK);
- }
-
- public List getWindowNodes()
- {
- return getNodes(PortalObject.WINDOW_MASK);
- }
-
public SelectItem[] getInstanceItems()
{
if (instanceItems == null)
@@ -325,7 +307,7 @@
ArrayList path = new ArrayList();
while (o != null)
{
- path.add(new PortalObjectBean(o));
+ path.add(o);
o = o.getParent();
}
Collections.reverse(path);
@@ -347,15 +329,6 @@
return selectedObject;
}
- public PortalObjectBean getSelectedObjectBean()
- {
- if (selectedObjectBean == null)
- {
- selectedObjectBean = new PortalObjectBean(getSelectedObject());
- }
- return selectedObjectBean;
- }
-
public List getSelectedProperties()
{
if (selectedProperties == null)
@@ -507,19 +480,6 @@
}
}
- private List getNodes(int mask)
- {
- Collection test = getSelectedObject().getChildren(mask);
- ArrayList result = new ArrayList();
- Iterator it = test.iterator();
- while (it.hasNext())
- {
- PortalObject po = (PortalObject)it.next();
- result.add(new PortalObjectBean(po));
- }
- return result;
- }
-
/** Returns a <Region,<Window>SortedSet>Map. */
private Map getWindows(Page page) throws Exception
{
@@ -604,7 +564,6 @@
portalPageItems = null;
selectedObjectPath = null;
selectedObject = null;
- selectedObjectBean = null;
selectedProperties = null;
}
Modified:
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/objectNavigation.xhtml
===================================================================
---
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/objectNavigation.xhtml 2007-03-04
13:39:03 UTC (rev 6529)
+++
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/objectNavigation.xhtml 2007-03-04
14:38:16 UTC (rev 6530)
@@ -10,7 +10,7 @@
<table width="100%">
- <c:if test="#{not empty portalobjectmgr.portalNodes}">
+ <c:if test="#{not empty portalobjectmgr.selectedObject.portals}">
<tbody class="portlet-section-header">
<tr>
<th>Portal</th>
@@ -18,7 +18,7 @@
</tr>
</tbody>
<tbody>
- <c:forEach items="#{portalobjectmgr.portalNodes}"
var="object" varStatus="status">
+ <c:forEach items="#{portalobjectmgr.selectedObject.portals}"
var="object" varStatus="status">
<tr class="#{status.index % 2 == 0 ?
'portlet-section-body' : 'portlet-section-alternate'}">
<td>
<h:commandLink
action="#{portalobjectmgr.selectObject}">
@@ -43,7 +43,7 @@
</tbody>
</c:if>
- <c:if test="#{not empty portalobjectmgr.pageNodes}">
+ <c:if test="#{not empty portalobjectmgr.selectedObject.pages}">
<tbody class="portlet-section-header">
<tr>
<th>Page</th>
@@ -51,7 +51,7 @@
</tr>
</tbody>
<tbody>
- <c:forEach items="#{portalobjectmgr.pageNodes}"
var="object" varStatus="status">
+ <c:forEach items="#{portalobjectmgr.selectedObject.pages}"
var="object" varStatus="status">
<tr class="#{status.index % 2 == 0 ?
'portlet-section-body' : 'portlet-section-alternate'}">
<td>
<h:commandLink
action="#{portalobjectmgr.selectObject}">
@@ -79,7 +79,7 @@
</tbody>
</c:if>
- <c:if test="#{not empty portalobjectmgr.windowNodes}">
+ <c:if test="#{not empty portalobjectmgr.selectedObject.windows}">
<tbody class="portlet-section-header">
<tr>
<th>Window</th>
@@ -87,7 +87,7 @@
</tr>
</tbody>
<tbody>
- <c:forEach items="#{portalobjectmgr.windowNodes}"
var="object" varStatus="status">
+ <c:forEach items="#{portalobjectmgr.selectedObject.windows}"
var="object" varStatus="status">
<tr class="#{status.index % 2 == 0 ?
'portlet-section-body' : 'portlet-section-alternate'}">
<td>
<h:commandLink
action="#{portalobjectmgr.selectObject}">
Modified:
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/objectTemplate.xhtml
===================================================================
---
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/objectTemplate.xhtml 2007-03-04
13:39:03 UTC (rev 6529)
+++
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/objectTemplate.xhtml 2007-03-04
14:38:16 UTC (rev 6530)
@@ -20,7 +20,7 @@
>
</li>
<c:choose>
- <c:when test="#{node.id ==
portalobjectmgr.selectedObjectBean.id}">
+ <c:when test="#{node.id ==
portalobjectmgr.selectedObject.id}">
<li class="selected">
<c:if test="#{node.name ==
''}">root</c:if>
<c:if test="#{node.name !=
''}">#{node.name}</c:if>
Modified: trunk/faces/src/main/org/jboss/portal/faces/el/DelegatingPropertyResolver.java
===================================================================
---
trunk/faces/src/main/org/jboss/portal/faces/el/DelegatingPropertyResolver.java 2007-03-04
13:39:03 UTC (rev 6529)
+++
trunk/faces/src/main/org/jboss/portal/faces/el/DelegatingPropertyResolver.java 2007-03-04
14:38:16 UTC (rev 6530)
@@ -90,14 +90,10 @@
}
//
- BeanDecorator decorator = resolveTypeDef(base);
- if (decorator != null)
+ GetTypeBeanAction beanAction = new GetTypeBeanAction(base, property);
+ if (resolveAction(base.getClass(), beanAction))
{
- Class type = decorator.getType(base, property);
- if (type != null)
- {
- return type;
- }
+ return beanAction.type;
}
//
@@ -122,7 +118,7 @@
throw createPNFE(base, property);
}
- public Object getValue(Object base, Object property) throws EvaluationException,
PropertyNotFoundException
+ public Object getValue(final Object base, final Object property) throws
EvaluationException, PropertyNotFoundException
{
// See if the object can handle itself the property
if (base instanceof DynamicBean)
@@ -136,14 +132,10 @@
}
//
- BeanDecorator decorator = resolveTypeDef(base);
- if (decorator != null)
+ GetValueBeanAction beanAction = new GetValueBeanAction(base, property);
+ if (resolveAction(base.getClass(), beanAction))
{
- PropertyValue nav = decorator.getValue(base, property);
- if (nav != null)
- {
- return nav.getObject();
- }
+ return beanAction.value.getObject();
}
//
@@ -169,13 +161,10 @@
}
//
- BeanDecorator decorator = resolveTypeDef(base);
- if (decorator != null)
+ SetValueBeanAction beanAction = new SetValueBeanAction(base, property, value);
+ if (resolveAction(base.getClass(), beanAction))
{
- if (decorator.setValue(base, property, value))
- {
- return;
- }
+ return;
}
//
@@ -236,32 +225,101 @@
throw createPNFE(base, index);
}
- /**
- * Resolve the type def from the provided object. First the class name is used to
lookup a type def. If none is found
- * then the implemented interfaces are examined to see if one can provide a type def.
- *
- * @param base the object to resolve the type def
- * @return the type def if found, null otherwise
- * @todo implement merging of type def if more than one is found
- */
- private BeanDecorator resolveTypeDef(Object base)
+ private static interface BeanAction
{
- Class clazz = base.getClass();
- BeanDecorator typeDef = (BeanDecorator)decoratorMap.get(clazz.getName());
- if (typeDef == null)
+ boolean execute(BeanDecorator decorator);
+ }
+
+ private abstract static class AbstractBeanAction implements BeanAction
+ {
+
+ /** . */
+ protected final Object base;
+
+ /** . */
+ protected final Object property;
+
+ public AbstractBeanAction(Object base, Object property)
{
- Class[] itfs = clazz.getInterfaces();
- for (int i = 0; i < itfs.length; i++)
+ this.base = base;
+ this.property = property;
+ }
+ }
+
+ private static class GetTypeBeanAction extends AbstractBeanAction
+ {
+
+ /** . */
+ private Class type;
+
+ public GetTypeBeanAction(Object base, Object property)
+ {
+ super(base, property);
+ }
+
+ public boolean execute(BeanDecorator decorator)
+ {
+ type = decorator.getType(base, property);
+ return type != null;
+ }
+ }
+
+ private static class GetValueBeanAction extends AbstractBeanAction
+ {
+
+ /** . */
+ private PropertyValue value;
+
+ public GetValueBeanAction(Object base, Object property)
+ {
+ super(base, property);
+ }
+
+ public boolean execute(BeanDecorator decorator)
+ {
+ value = decorator.getValue(base, property);
+ return value != null;
+ }
+ }
+
+ private static class SetValueBeanAction extends AbstractBeanAction
+ {
+
+ /** . */
+ private Object value;
+
+ public SetValueBeanAction(Object base, Object property, Object value)
+ {
+ super(base, property);
+ this.value = value;
+ }
+
+ public boolean execute(BeanDecorator decorator)
+ {
+ return decorator.setValue(base, property, value);
+ }
+ }
+
+ private boolean resolveAction(Class clazz, BeanAction action)
+ {
+ BeanDecorator decorator = (BeanDecorator)decoratorMap.get(clazz.getName());
+ if (decorator != null)
+ {
+ if (action.execute(decorator))
{
- Class itf = clazz.getInterfaces()[i];
- typeDef = (BeanDecorator)decoratorMap.get(itf.getName());
- if (typeDef != null)
- {
- break;
- }
+ return true;
}
}
- return typeDef;
+ Class[] itfs = clazz.getInterfaces();
+ for (int i = 0; i < itfs.length; i++)
+ {
+ Class itf = clazz.getInterfaces()[i];
+ if (resolveAction(itf, action))
+ {
+ return true;
+ }
+ }
+ return false;
}
private PropertyNotFoundException createPNFE(Object base, int index)