Author: julien(a)jboss.com
Date: 2007-12-03 16:24:24 -0500 (Mon, 03 Dec 2007)
New Revision: 9252
Added:
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralObjectImpl.java
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectList.java
Modified:
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralState.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
- remove direct usage of structural ids in the ui model and replace it with
StructuralObject which allows the structural context implementation to add information in
addition of the id to make stale state detection during an structural state operation
Added:
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralObjectImpl.java
===================================================================
---
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralObjectImpl.java
(rev 0)
+++
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralObjectImpl.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -0,0 +1,57 @@
+/******************************************************************************
+ * 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.presentation.model;
+
+import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.model.state.structural.StructuralState;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class StructuralObjectImpl implements StructuralObject
+{
+
+ /** . */
+ private final String id;
+
+ /** . */
+ private final StructuralStateImpl state;
+
+ public StructuralObjectImpl(PortalObject portalObject)
+ {
+ this.id = portalObject.getId().toString();
+ this.state = new StructuralStateImpl(portalObject);
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public StructuralState getState()
+ {
+ return state;
+ }
+}
Modified:
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java
===================================================================
---
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java 2007-12-03
18:47:21 UTC (rev 9251)
+++
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -22,32 +22,22 @@
******************************************************************************/
package org.jboss.portal.core.presentation.model;
-import org.jboss.portal.core.model.portal.Page;
-import org.jboss.portal.core.model.portal.Portal;
import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.core.model.portal.PortalObjectContainer;
import org.jboss.portal.core.model.portal.PortalObjectId;
import org.jboss.portal.core.model.portal.PortalObjectPath;
-import org.jboss.portal.core.model.portal.Window;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.UIPage;
-import org.jboss.portal.presentation.model.UIPortal;
-import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.model.state.structural.StructuralState;
-import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
-import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import
org.jboss.portal.presentation.model.state.structural.AbstractStructuralStateContext;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public class StructuralStateContextImpl implements StructuralStateContext
+public class StructuralStateContextImpl extends AbstractStructuralStateContext
{
/**
*
@@ -81,99 +71,63 @@
/**
*
*/
- public StructuralState load(String objectId) throws IllegalArgumentException
+ public StructuralObject load(String objectId) throws IllegalArgumentException
{
- StructuralState structuralState = null;
-
// Get the PortalObject corresponding to this objectId from the
PortalObjectContainer
- PortalObject portalObject =
this.portalObjectContainer.getObject(PortalObjectId.parse(objectId,
- PortalObjectPath.CANONICAL_FORMAT));
+ PortalObject portalObject =
this.portalObjectContainer.getObject(PortalObjectId.parse(objectId,
PortalObjectPath.CANONICAL_FORMAT));
+ // Object by this id was not found in the Portal
if(portalObject == null)
{
- // Object by this id was not found in the Portal
return null;
}
- // Type
- Class<? extends UIObject> type = this.getType(portalObject);
-
- // Name
- String name = portalObject.getName();
-
- // Properties
- Map<String, String> properties = portalObject.getDeclaredProperties();
-
// Parent Id
- String parentId = null;
- if(portalObject.getParent() != null)
- {
- parentId = portalObject.getParent().getId().toString();
- }
+// String parentId = null;
+// if(portalObject.getParent() != null)
+// {
+// parentId = portalObject.getParent().getId().toString();
+// }
+//
+// //Children Ids
+// List<String> childrenIds = new ArrayList<String>();
+// Collection children = portalObject.getChildren();
+// for(Iterator itr=children.iterator(); itr.hasNext();)
+// {
+// PortalObject child = (PortalObject)itr.next();
+// childrenIds.add(child.getId().toString());
+// }
- //Children Ids
- List<String> childrenIds = new ArrayList<String>();
- Collection children = portalObject.getChildren();
- for(Iterator itr=children.iterator(); itr.hasNext();)
- {
- PortalObject child = (PortalObject)itr.next();
- childrenIds.add(child.getId().toString());
- }
-
- structuralState = new StructuralState(
- type, //type
- name,
- properties, //properties
- parentId,
- childrenIds // childrenIds
- );
-
- return structuralState;
+ return new StructuralObjectImpl(portalObject);
}
-
- /**
- *
- * @param portalObject
- * @return
- */
- private Class<? extends UIObject> getType(PortalObject portalObject)
+
+
+ public List<StructuralObject> loadChildren(StructuralObject object)
{
- Class<? extends UIObject> type = null;
-
- if(portalObject instanceof Portal)
+ // Get the PortalObject corresponding to this objectId from the
PortalObjectContainer
+ PortalObject portalObject =
this.portalObjectContainer.getObject(PortalObjectId.parse(object.getId(),
PortalObjectPath.CANONICAL_FORMAT));
+
+ //
+ ArrayList<StructuralObject> children = new
ArrayList<StructuralObject>();
+ for (PortalObject childObject :
(Collection<PortalObject>)portalObject.getChildren())
{
- type = UIPortal.class;
+ children.add(new StructuralObjectImpl(childObject));
}
- else if(portalObject instanceof Page)
- {
- type = UIPage.class;
- }
- else if(portalObject instanceof Window)
- {
- type = UIWindow.class;
- }
-
- return type;
- }
- public String create(String parentId, Class<? extends UIObject> type, String
name, Map<String, String> properties) throws StateChangeVetoException
- {
- throw new StateChangeVetoException();
+ //
+ return children;
}
- public void destroy(String objectId) throws StateChangeVetoException
+ public StructuralObject loadParent(StructuralObject object)
{
- throw new StateChangeVetoException();
- }
+ // Get the PortalObject corresponding to this objectId from the
PortalObjectContainer
+ PortalObject portalObject =
this.portalObjectContainer.getObject(PortalObjectId.parse(object.getId(),
PortalObjectPath.CANONICAL_FORMAT));
- public void move(String objectId, String parentId) throws StateChangeVetoException
- {
- throw new StateChangeVetoException();
- }
+ //
+ PortalObject parent = portalObject.getParent();
- public void update(String objectId, Map<String, String> changes) throws
StateChangeVetoException
- {
- throw new StateChangeVetoException();
+ //
+ return parent == null ? null : new StructuralObjectImpl(parent);
}
/**
Added:
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateImpl.java
===================================================================
---
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateImpl.java
(rev 0)
+++
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateImpl.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -0,0 +1,99 @@
+/******************************************************************************
+ * 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.presentation.model;
+
+import org.jboss.portal.presentation.model.state.structural.StructuralState;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.UIPortal;
+import org.jboss.portal.presentation.model.UIPage;
+import org.jboss.portal.presentation.model.UIWindow;
+import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.model.portal.Portal;
+import org.jboss.portal.core.model.portal.Page;
+import org.jboss.portal.core.model.portal.Window;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class StructuralStateImpl implements StructuralState
+{
+
+ /** . */
+ private Class<? extends UIObject> type;
+
+ /** . */
+ private String name;
+
+ /** . */
+ private Map<String, String> properties;
+
+ StructuralStateImpl(PortalObject portalObject)
+ {
+ type = this.getType(portalObject);
+ portalObject.getName();
+ properties = portalObject.getDeclaredProperties();
+ }
+
+ public Class<? extends UIObject> getType()
+ {
+ return type;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Map<String, String> getProperties()
+ {
+ return properties;
+ }
+
+ /**
+ *
+ * @param portalObject
+ * @return
+ */
+ private Class<? extends UIObject> getType(PortalObject portalObject)
+ {
+ Class<? extends UIObject> type = null;
+
+ if(portalObject instanceof Portal)
+ {
+ type = UIPortal.class;
+ }
+ else if(portalObject instanceof Page)
+ {
+ type = UIPage.class;
+ }
+ else if(portalObject instanceof Window)
+ {
+ type = UIWindow.class;
+ }
+
+ return type;
+ }
+}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java 2007-12-03
18:47:21 UTC (rev 9251)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -26,6 +26,7 @@
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIWindow;
import org.jboss.portal.presentation.model.state.structural.StructuralState;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -34,17 +35,11 @@
public class UIContainerImpl extends UIObjectImpl implements UIContainer
{
- public UIContainerImpl(UIContextImpl context, String id, StructuralState state)
+ public UIContainerImpl(UIContextImpl context, StructuralObject object)
{
- super(context, id, state);
+ super(context, object);
}
- /**
- *
- * @param <T>
- * @param type
- * @return
- */
protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
{
boolean isAllowedAsChild = false;
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-03
18:47:21 UTC (rev 9251)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -31,7 +31,7 @@
import org.jboss.portal.presentation.model.UIPortal;
import org.jboss.portal.presentation.model.UIWindow;
import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
-import org.jboss.portal.presentation.model.state.structural.StructuralState;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import java.util.ArrayList;
@@ -43,11 +43,11 @@
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public class UIContextImpl extends UIObjectImpl implements UIContext
+public final class UIContextImpl extends UIObjectImpl implements UIContext
{
/** . */
- private final Map<String, UIObject> objects = new HashMap<String,
UIObject>();
+ private final Map<String, UIObjectImpl> objects = new HashMap<String,
UIObjectImpl>();
/** . */
protected final StructuralStateContext structuralStateContext;
@@ -58,13 +58,8 @@
/** . */
protected final List<ModelListener> listeners;
- private static String getRootId(StructuralStateContext loader)
+ private static StructuralObject getRootState(StructuralStateContext loader)
{
- return loader.getRootId();
- }
-
- private static StructuralState getRootState(StructuralStateContext loader)
- {
return loader.load(loader.getRootId());
}
@@ -72,7 +67,7 @@
StructuralStateContext structuralStateContext,
NavigationalStateContext navigationalStateContext)
{
- super(getRootId(structuralStateContext), getRootState(structuralStateContext));
+ super(getRootState(structuralStateContext));
//
this.structuralStateContext = structuralStateContext;
@@ -94,9 +89,8 @@
if (object == null)
{
//Fetch the state of the UIObject in question
- StructuralState structuralState = this.structuralStateContext.load(id);
- object = getImplementation(id, structuralState);
- objects.put(id, object);
+ StructuralObject structuralObject = this.structuralStateContext.load(id);
+ return loadObject(structuralObject);
}
return object;
}
@@ -120,27 +114,35 @@
}
}
- /**
- * @return
- */
- protected UIObject getImplementation(String id, StructuralState state) throws
Exception
+ protected UIObjectImpl loadObject(StructuralObject structuralObject)
{
- Class type = state.getType();
+ UIObjectImpl object = objects.get(structuralObject.getId());
+ if (object == null)
+ {
+ object = getImplementation(structuralObject);
+ objects.put(structuralObject.getId(), object);
+ }
+ return object;
+ }
+
+ private UIObjectImpl getImplementation(StructuralObject state)
+ {
+ Class type = state.getState().getType();
if(type == UIPortal.class)
{
- return new UIPortalImpl(this, id, state);
+ return new UIPortalImpl(this, state);
}
else if(type == UIPage.class)
{
- return new UIPageImpl(this, id, state);
+ return new UIPageImpl(this, state);
}
else if(type == UIContainer.class)
{
- return new UIContainerImpl(this, id, state);
+ return new UIContainerImpl(this, state);
}
else if(type == UIWindow.class)
{
- return new UIWindowImpl(this, id, state);
+ return new UIWindowImpl(this, state);
}
else
{
@@ -148,12 +150,6 @@
}
}
- /**
- *
- * @param <T>
- * @param type
- * @return
- */
protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
{
boolean isAllowedAsChild = false;
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-03
18:47:21 UTC (rev 9251)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -28,10 +28,11 @@
import org.jboss.portal.presentation.model.state.StateChangeEvent;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
import
org.jboss.portal.presentation.model.state.navigational.NavigationalStateModification;
-import org.jboss.portal.presentation.model.state.structural.StructuralState;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralStateModification;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -48,37 +49,43 @@
protected final UIContextImpl context;
/** . */
- protected final String id;
+ private List<UIObject> children;
/** . */
- protected final UIObjectList children;
+ private UIObjectImpl parent;
/** This is used to assist with data needed during lazy loading, other state related
data etc... */
- private StructuralState state;
+ private StructuralObject structuralObject;
- public UIObjectImpl(UIContextImpl context, String id, StructuralState state)
+ public UIObjectImpl(UIContextImpl context, StructuralObject object)
{
- this.id = id;
- this.state = state;
+ this.structuralObject = object;
this.context = context;
- this.children = new UIObjectList(this.context, state.getChildrenIds());
+ this.children = null;
+ this.parent = null;
}
- public UIObjectImpl(String id, StructuralState state)
+ public UIObjectImpl(StructuralObject object)
{
- this.id = id;
- this.state = state;
+ this.structuralObject = object;
this.context = (UIContextImpl)this;
- this.children = new UIObjectList(this.context, state.getChildrenIds());
+ this.children = null;
+ this.parent = null;
}
+ protected final StructuralObject getStructuralObject()
+ {
+ return structuralObject;
+ }
+
//UIObject interface
implementation-----------------------------------------------------------------------------------------------------------------------------
+
/**
*
*/
public String getId()
{
- return this.id;
+ return structuralObject.getId();
}
/**
@@ -129,10 +136,10 @@
switch (scopeType)
{
case NAVIGATIONAL:
- value = context.navigationalStateContext.get(id, propertyName);
+ value = context.navigationalStateContext.get(getId(), propertyName);
break;
case STRUCTURAL:
- value = state.getProperties().get(propertyName);
+ value = structuralObject.getState().getProperties().get(propertyName);
break;
default:
throw new AssertionError();
@@ -160,7 +167,7 @@
case NAVIGATIONAL:
{
NavigationalStateModification mod = new
NavigationalStateModification(propertyName, propertyValue);
- StateChange<NavigationalStateModification> change = new
StateChange<NavigationalStateModification>(id, mod);
+ StateChange<NavigationalStateModification> change = new
StateChange<NavigationalStateModification>(getId(), mod);
// Have context process the change
context.navigationalStateContext.update(change);
@@ -178,16 +185,14 @@
changes.put(propertyName, (String)propertyValue);
// Have context process change
- context.structuralStateContext.update(id, changes);
+ context.structuralStateContext.update(structuralObject, changes);
// Update state locally to reflect correct state
- Map<String, String> updatedProperties = new HashMap<String,
String>(state.getProperties());
- updateProperty(updatedProperties, propertyName, (String)propertyValue);
- state = new StructuralState(state.getType(), state.getName(),
updatedProperties, state.getParentId(), state.getChildrenIds());
+ structuralObject =
context.structuralStateContext.load(structuralObject.getId());
// Broadcast event
StructuralStateModification mod = new
StructuralStateModification.Update(changes);
- StateChange<StructuralStateModification> change = new
StateChange<StructuralStateModification>(id, mod);
+ StateChange<StructuralStateModification> change = new
StateChange<StructuralStateModification>(getId(), mod);
StateChangeEvent event = new StateChangeEvent(change);
context.fireEvent(event);
}
@@ -202,18 +207,6 @@
}
}
- private <T> void updateProperty(Map<String, T> map, String propertyName, T
propertyValue)
- {
- if (propertyValue == null)
- {
- map.remove(propertyName);
- }
- else
- {
- map.put(propertyName, propertyValue);
- }
- }
-
public UIObject getChild(String name)
{
for (UIObject child : getChildren())
@@ -231,23 +224,46 @@
*/
public String getName()
{
- return state.getName();
+ return structuralObject.getState().getName();
}
/**
*
*/
- public UIObject getParent()
+ public final UIObject getParent()
{
- return state.getParentId() != null ? context.getObject(state.getParentId()) :
null;
+ if (this instanceof UIContextImpl)
+ {
+ return null;
+ }
+
+ //
+ if (parent == null)
+ {
+ StructuralObject parentStructuralState =
context.structuralStateContext.loadParent(structuralObject);
+ parent = context.loadObject(parentStructuralState);
+ }
+
+ //
+ return parent;
}
/**
*
*/
- public List<UIObject> getChildren()
- {
- return this.children;
+ public final List<UIObject> getChildren()
+ {
+ if (children == null)
+ {
+ ArrayList<UIObject> tmp = new ArrayList<UIObject>();
+ for (StructuralObject structuralChild :
context.structuralStateContext.loadChildren(structuralObject))
+ {
+ UIObjectImpl child = context.loadObject(structuralChild);
+ tmp.add(child);
+ }
+ return tmp;
+ }
+ return children;
}
/**
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectList.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectList.java 2007-12-03
18:47:21 UTC (rev 9251)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectList.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -1,58 +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.presentation.impl.model;
-
-import org.jboss.portal.presentation.model.UIObject;
-
-import java.util.AbstractList;
-import java.util.List;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class UIObjectList extends AbstractList<UIObject>
-{
-
- /** . */
- private final UIContextImpl context;
-
- /** . */
- private final List<String> ids;
-
- public UIObjectList(UIContextImpl context, List<String> ids)
- {
- this.context = context;
- this.ids = ids;
- }
-
- public UIObject get(int i)
- {
- return context.getObject(ids.get(i));
- }
-
- public int size()
- {
- return ids.size();
- }
-}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java 2007-12-03
18:47:21 UTC (rev 9251)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -27,6 +27,7 @@
import org.jboss.portal.presentation.model.UIPage;
import org.jboss.portal.presentation.model.UIWindow;
import org.jboss.portal.presentation.model.state.structural.StructuralState;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -35,17 +36,11 @@
public class UIPageImpl extends UIObjectImpl implements UIPage
{
- public UIPageImpl(UIContextImpl context, String id, StructuralState state)
+ public UIPageImpl(UIContextImpl context, StructuralObject object)
{
- super(context, id, state);
+ super(context, object);
}
- /**
- *
- * @param <T>
- * @param type
- * @return
- */
protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
{
boolean isAllowedAsChild = false;
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java 2007-12-03
18:47:21 UTC (rev 9251)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -26,6 +26,7 @@
import org.jboss.portal.presentation.model.UIPortal;
import org.jboss.portal.presentation.model.UIPage;
import org.jboss.portal.presentation.model.state.structural.StructuralState;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -34,24 +35,16 @@
public class UIPortalImpl extends UIObjectImpl implements UIPortal
{
- public UIPortalImpl(UIContextImpl context, String id, StructuralState state)
+ public UIPortalImpl(UIContextImpl context, StructuralObject object)
{
- super(context, id, state);
+ super(context, object);
}
- /**
- *
- * @param <T>
- * @param type
- * @return
- */
protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
{
boolean isAllowedAsChild = false;
- if(
- type == UIPage.class
- )
+ if(type == UIPage.class)
{
isAllowedAsChild = true;
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java 2007-12-03
18:47:21 UTC (rev 9251)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -28,6 +28,7 @@
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIWindow;
import org.jboss.portal.presentation.model.state.structural.StructuralState;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -36,9 +37,9 @@
public class UIWindowImpl extends UIObjectImpl implements UIWindow
{
- public UIWindowImpl(UIContextImpl context, String id, StructuralState state)
+ public UIWindowImpl(UIContextImpl context, StructuralObject object)
{
- super(context, id, state);
+ super(context, object);
}
/**
@@ -73,12 +74,6 @@
setProperty(StateScopeType.NAVIGATIONAL, "windowstate", windowState);
}
- /**
- *
- * @param <T>
- * @param type
- * @return
- */
protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
{
return false;
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java 2007-12-03
18:47:21 UTC (rev 9251)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -23,9 +23,11 @@
package org.jboss.portal.presentation.model.state.structural;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.UIObject;
import java.util.Map;
+import java.util.List;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -34,22 +36,22 @@
public abstract class AbstractStructuralStateContext implements StructuralStateContext
{
- public String create(String parentId, Class<? extends UIObject> type, String
name, Map<String, String> properties) throws StateChangeVetoException
+ public String create(StructuralObject parent, Class<? extends UIObject> type,
String name, Map<String, String> properties) throws StateChangeVetoException,
StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
- public void destroy(String objectId) throws StateChangeVetoException
+ public void destroy(StructuralObject object) throws StateChangeVetoException,
StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
- public void move(String objectId, String parentId) throws StateChangeVetoException
+ public void move(StructuralObject object, StructuralObject parent) throws
StateChangeVetoException, StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
- public void update(String objectId, Map<String, String> changes) throws
StateChangeVetoException
+ public void update(StructuralObject object, Map<String, String> changes) throws
StateChangeVetoException, StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * 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.presentation.model.state.structural;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface StructuralObject
+{
+
+ String getId();
+
+ StructuralState getState();
+
+}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralState.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralState.java 2007-12-03
18:47:21 UTC (rev 9251)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralState.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -24,9 +24,7 @@
import org.jboss.portal.presentation.model.UIObject;
-import java.io.Serializable;
import java.util.Map;
-import java.util.List;
/**
* The structural state.
@@ -34,55 +32,12 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class StructuralState implements Serializable
+public interface StructuralState
{
- /** . */
- private final Class<? extends UIObject> type;
+ Class<? extends UIObject> getType();
- /** . */
- private final String name;
+ String getName();
- /** . */
- private final Map<String, String> properties;
-
- /** . */
- private final String parentId;
-
- /** . */
- private final List<String> childrenIds;
-
- public StructuralState(Class<? extends UIObject> type, String name,
Map<String, String> properties, String parentId, List<String> childrenIds)
- {
- this.type = type;
- this.name = name;
- this.properties = properties;
- this.parentId = parentId;
- this.childrenIds = childrenIds;
- }
-
- public Class<? extends UIObject> getType()
- {
- return type;
- }
-
- public String getName()
- {
- return name;
- }
-
- public Map<String, String> getProperties()
- {
- return properties;
- }
-
- public String getParentId()
- {
- return parentId;
- }
-
- public List<String> getChildrenIds()
- {
- return childrenIds;
- }
+ Map<String, String> getProperties();
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-03
18:47:21 UTC (rev 9251)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -24,7 +24,6 @@
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
-import org.jboss.portal.presentation.model.state.StateChange;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
import org.jboss.portal.presentation.model.state.StateException;
@@ -47,8 +46,12 @@
* @return the state of the object or null if such state does not exist
* @throws IllegalArgumentException if the object id argument is null
*/
- StructuralState load(String objectId) throws IllegalArgumentException;
+ StructuralObject load(String objectId) throws IllegalArgumentException;
+ List<StructuralObject> loadChildren(StructuralObject object);
+
+ StructuralObject loadParent(StructuralObject object);
+
/**
* Returns the id of the root object.
*
@@ -59,7 +62,7 @@
/**
* Create an object.
*
- * @param parentId the id of the parent object
+ * @param parent the parent
* @param type the type of the child
* @param name the name of the child
* @param properties the initial properties of the child
@@ -69,41 +72,41 @@
* @throws NoSuchStateException if the parent id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
*/
- String create(String parentId, Class<? extends UIObject> type, String name,
Map<String, String> properties) throws StateChangeVetoException, StateException,
IllegalArgumentException;
+ String create(StructuralObject parent, Class<? extends UIObject> type, String
name, Map<String, String> properties) throws StateChangeVetoException,
StateException, IllegalArgumentException;
/**
* Destroy a specified object.
*
- * @param objectId the object id to destroy
+ * @param object the object to destroy
* @throws StateChangeVetoException if the creation is vetoed
* @throws StateException a generic state exception
* @throws NoSuchStateException if the object id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
*/
- void destroy(String objectId) throws StateChangeVetoException, StateException,
IllegalArgumentException;
+ void destroy(StructuralObject object) throws StateChangeVetoException, StateException,
IllegalArgumentException;
/**
* Move an object to a new parent.
*
- * @param objectId the object id to move
- * @param parentId the id of the new parent
+ * @param object the object to move
+ * @param parent the new parent
* @throws StateChangeVetoException if the creation is vetoed
* @throws StateException a generic state exception
* @throws NoSuchStateException if the object id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
*/
- void move(String objectId, String parentId) throws StateChangeVetoException,
StateException, IllegalArgumentException;
+ void move(StructuralObject object, StructuralObject parent) throws
StateChangeVetoException, StateException, IllegalArgumentException;
/**
* Update the state of a specified object.
*
- * @param objectId the id of the object to udpate
+ * @param object the object to udpate
* @param changes the changes
* @throws StateChangeVetoException if the creation is vetoed
* @throws StateException a generic state exception
* @throws NoSuchStateException if the object id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
*/
- void update(String objectId, Map<String, String> changes) throws
StateChangeVetoException, StateException, IllegalArgumentException;
+ void update(StructuralObject object, Map<String, String> changes) throws
StateChangeVetoException, StateException, IllegalArgumentException;
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java 2007-12-03
18:47:21 UTC (rev 9251)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -22,16 +22,19 @@
******************************************************************************/
package org.jboss.portal.presentation.test.model;
+import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
import org.jboss.portal.presentation.model.state.StateException;
import
org.jboss.portal.presentation.model.state.structural.AbstractStructuralStateContext;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralState;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -53,7 +56,7 @@
private final StructuralStateContext structuralStateContext = new
AbstractStructuralStateContext()
{
- public StructuralState load(String objectId) throws IllegalArgumentException
+ public StructuralObject load(String objectId) throws IllegalArgumentException
{
if (objectId == null)
{
@@ -68,9 +71,9 @@
return root.id;
}
- public void update(String objectId, Map<String, String> changes) throws
StateChangeVetoException
+ public void update(StructuralObject structuralObject, Map<String, String>
changes) throws StateChangeVetoException
{
- MockObjectImpl object = universe.get(objectId);
+ MockObjectImpl object =
universe.get(((MockStructuralObject)structuralObject).getId());
if (object == null)
{
throw new NoSuchStateException();
@@ -106,6 +109,25 @@
}
}
}
+
+ public List<StructuralObject> loadChildren(StructuralObject object)
+ {
+ MockStructuralObject mockStructuralObject = (MockStructuralObject)object;
+ MockObjectImpl mockObject = universe.get(mockStructuralObject.id);
+ List<StructuralObject> tmp = new ArrayList<StructuralObject>();
+ for (MockObjectImpl mockChild : mockObject.children.values())
+ {
+ tmp.add(mockChild.takeSnapshot());
+ }
+ return tmp;
+ }
+
+ public StructuralObject loadParent(StructuralObject object)
+ {
+ MockStructuralObject mockStructuralObject = (MockStructuralObject)object;
+ MockObjectImpl mockObject = universe.get(mockStructuralObject.id);
+ return mockObject.parent.takeSnapshot();
+ }
};
public StructuralStateContext getStructuralStateContext()
@@ -207,14 +229,9 @@
return id;
}
- public StructuralState takeSnapshot()
+ public StructuralObject takeSnapshot()
{
- ArrayList<String> childrenIds = new ArrayList<String>();
- for (MockObjectImpl child : children.values())
- {
- childrenIds.add(child.id);
- }
- return new StructuralState(type.clazz, name, new HashMap<String,
String>(propertyValues), parent != null ? parent.id : null, childrenIds);
+ return new MockStructuralObject(id, new MockStructuralState(type.clazz, name,
new HashMap<String, String>(propertyValues)));
}
public String getPropertyValue(String propertyName)
@@ -275,4 +292,65 @@
}
}
}
+
+ public class MockStructuralState implements StructuralState
+ {
+
+ /** . */
+ private final Class<? extends UIObject> type;
+
+ /** . */
+ private final String name;
+
+ /** . */
+ private final Map<String, String> properties;
+
+ public MockStructuralState(Class<? extends UIObject> type, String name,
Map<String, String> properties)
+ {
+ this.type = type;
+ this.name = name;
+ this.properties = properties;
+ }
+
+ public Class<? extends UIObject> getType()
+ {
+ return type;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Map<String, String> getProperties()
+ {
+ return properties;
+ }
+ }
+
+ public class MockStructuralObject implements StructuralObject
+ {
+
+ /** . */
+ private final String id;
+
+ /** . */
+ private final MockStructuralState state;
+
+ public MockStructuralObject(String id, MockStructuralState state)
+ {
+ this.id = id;
+ this.state = state;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public StructuralState getState()
+ {
+ return state;
+ }
+ }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockObject.java 2007-12-03
18:47:21 UTC (rev 9251)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockObject.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -28,6 +28,7 @@
import org.jboss.portal.presentation.model.UIPortal;
import org.jboss.portal.presentation.model.UIWindow;
import org.jboss.portal.presentation.model.state.structural.StructuralState;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import java.util.Set;
@@ -115,5 +116,5 @@
*
* @return the state snapshot
*/
- StructuralState takeSnapshot();
+ StructuralObject takeSnapshot();
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-03
18:47:21 UTC (rev 9251)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-03
21:24:24 UTC (rev 9252)
@@ -142,6 +142,12 @@
assertTrue(pageChildren == null || pageChildren.size() == 0);
}*/
+ public void testUIContextParentIsNull()
+ {
+ UIContext context = createContext();
+ assertEquals(null, context.getParent());
+ }
+
public void testSetPropertyThrowsIAE()
{
UIContext context = createContext();