Author: julien(a)jboss.com
Date: 2008-07-07 08:25:32 -0400 (Mon, 07 Jul 2008)
New Revision: 11310
Added:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java
Removed:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateUpdatePhase.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectUpdate.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectVisit.java
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectDiff.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java
Log:
rewrote the update phase in a simpler manner
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java 2008-07-07
06:23:05 UTC (rev 11309)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java 2008-07-07
12:25:32 UTC (rev 11310)
@@ -111,14 +111,14 @@
private Collection<ObjectDiff.Evict> createEvictedChildren(UIObjectImpl object)
{
- Collection<ObjectDiff.Evict> evictedChildren = new
ArrayList<ObjectDiff.Evict>();
-
- //
InternalObjectContext objectContext = (InternalObjectContext)object.getContext();
//
if (objectContext.childRefs != null)
{
+ Collection<ObjectDiff.Evict> evictedChildren = new
ArrayList<ObjectDiff.Evict>();
+
+ //
for (UIObjectRef removedChildRef : objectContext.childRefs.values())
{
if (removedChildRef.loaded)
@@ -129,8 +129,16 @@
evictedChildren.add(createEvict(child));
}
}
+
+ //
+ return evictedChildren;
}
- return evictedChildren;
+ else
+ {
+ // On purpose to indicate that no children was initialized and therefore there
is no
+ // destroy children callback to do
+ return null;
+ }
}
private ObjectDiff diff(UIObjectImpl object)
@@ -154,9 +162,12 @@
Collection<ObjectDiff> addedObjects = new
ArrayList<ObjectDiff>();
Collection<ObjectDiff> validObjects = new
ArrayList<ObjectDiff>();
Collection<ObjectDiff> staleObjects = new
ArrayList<ObjectDiff>();
- Collection<ObjectDiff> removedObjects = new
ArrayList<ObjectDiff>();
+ Collection<ObjectDiff.Evict> removedObjects = new
ArrayList<ObjectDiff.Evict>();
//
+ boolean createChildren =
((InternalObjectContext)object.getContext()).childRefs == null;
+
+ //
for (StructuralObject addedStructuralChild : refresh.getAddedChildren())
{
addedObjects.add(load(addedStructuralChild));
@@ -200,6 +211,7 @@
refresh.getRemovedProperties(),
refresh.getUpdatedProperties(),
refresh.getAddedProperties(),
+ createChildren,
addedObjects,
validObjects,
staleObjects,
@@ -207,7 +219,6 @@
}
else
{
-
Collection<ObjectDiff.Evict> evictedChildren =
createEvictedChildren(object);
//
Deleted:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateUpdatePhase.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateUpdatePhase.java 2008-07-07
06:23:05 UTC (rev 11309)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateUpdatePhase.java 2008-07-07
12:25:32 UTC (rev 11310)
@@ -1,308 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2008, 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.ViewPortContext;
-import org.jboss.portal.presentation.impl.model.ui.UIObjectImpl;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Collection;
-import java.util.Collections;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
- * @version $Revision: 630 $
- */
-public class CreateUpdatePhase
-{
-
- /** . */
- private final ViewPortContext context;
-
- /** . */
- private ObjectDiff rootDiff;
-
- /** . */
- private ObjectUpdate rootUpdate;
-
- /** . */
- private Map<String, ObjectUpdate.AddChild> deferredAddChildUpdates;
-
- /** . */
- private Set<String> removedChildren;
-
- public CreateUpdatePhase(ViewPortContext context, ObjectDiff rootDiff)
- {
- this.context = context;
- this.rootDiff = rootDiff;
- }
-
- public ObjectUpdate getRootUpdate()
- {
- return rootUpdate;
- }
-
- public void perform()
- {
- deferredAddChildUpdates = new HashMap<String, ObjectUpdate.AddChild>();
- removedChildren = new HashSet<String>();
-
- //
- rootUpdate = createUpdate(rootDiff);
-
- //
- if (deferredAddChildUpdates.size() > 0)
- {
- throw new IllegalStateException("Was expecting the deferred update to be
empty");
- }
- }
-
- private ObjectUpdate createUpdate(ObjectDiff diff)
- {
- UIObjectImpl object = (UIObjectImpl)context.getObject(diff.getObjectId());
-
- if (diff instanceof ObjectDiff.RecursiveLoad || diff instanceof
ObjectDiff.RecursiveUpdate)
- {
- Collection<ObjectDiff> addedObjects;
- Collection<ObjectDiff> validObjects;
- Collection<ObjectDiff> staleObjects;
- Collection<ObjectDiff> removedObjects;
- if (diff instanceof ObjectDiff.RecursiveUpdate)
- {
- addedObjects = ((ObjectDiff.RecursiveUpdate)diff).getAddedChildren();
- validObjects = ((ObjectDiff.RecursiveUpdate)diff).getValidChildren();
- staleObjects = ((ObjectDiff.RecursiveUpdate)diff).getStaleChildren();
- removedObjects = ((ObjectDiff.RecursiveUpdate)diff).getRemovedChildren();
- }
- else
- {
- addedObjects = ((ObjectDiff.RecursiveLoad)diff).getAddedChildren();
- validObjects = Collections.emptyList();
- staleObjects = Collections.emptyList();
- removedObjects = Collections.emptyList();
- }
-
- //
- if (object != null)
- {
- if (object != diff.getObject())
- {
- // The object is stale, we need to update the state maybe
- }
- }
-
- //
- Map<String, Boolean> childrenStatus = new HashMap<String,
Boolean>();
- List<ObjectUpdate.AddChild> addedChildrenUpdates = new
ArrayList<ObjectUpdate.AddChild>();
- List<ObjectUpdate.RemoveChild> removedChildrenUpdates = new
ArrayList<ObjectUpdate.RemoveChild>();
- List<ObjectUpdate.UpdateObject> updateChildrenUpdates = new
ArrayList<ObjectUpdate.UpdateObject>();
-
- //
- for (ObjectDiff addedObjectDiff : addedObjects)
- {
- ObjectUpdate childUpdate = createUpdate(addedObjectDiff);
-
- //
- if (childUpdate instanceof ObjectUpdate.AddObject)
- {
- addedChildrenUpdates.add(new ObjectUpdate.AddChild(diff.getObjectId(),
(ObjectUpdate.AddObject)childUpdate));
- childrenStatus.put(addedObjectDiff.getObjectId(), true);
- }
- else if (childUpdate == null)
- {
- childrenStatus.put(addedObjectDiff.getObjectId(), false);
- }
- else if (childUpdate instanceof ObjectUpdate.UpdateObject)
- {
- // This is 'the' trick becaue this is likely a 'move'
operation that we may need
- // to handle differently as a deferred add child
- ObjectUpdate.UpdateObject updateChildUpdate =
(ObjectUpdate.UpdateObject)childUpdate;
-
- //
- ObjectUpdate.AddObject addObjectUpdate = new ObjectUpdate.AddObject(
- addedObjectDiff.getObject(),
- updateChildUpdate.childrenStatus,
- updateChildUpdate.addedChildrenUpdates,
- updateChildUpdate.removedChildrenUpdates,
- updateChildUpdate.updateChildrenUpdates);
-
- //
- ObjectUpdate.AddChild addChildUpdate = new
ObjectUpdate.AddChild(diff.getObjectId(), addObjectUpdate);
-
- //
- if (removedChildren.contains(addedObjectDiff.getObjectId()))
- {
- addedChildrenUpdates.add(addChildUpdate);
- }
- else
- {
- deferredAddChildUpdates.put(addedObjectDiff.getObjectId(),
addChildUpdate);
- }
-
- //
- childrenStatus.put(addedObjectDiff.getObjectId(), true);
- }
- else
- {
- throw new UnsupportedOperationException("Was not expecting update of
type " + childUpdate.getClass().getSimpleName());
- }
- }
-
- //
- for (ObjectDiff removedChildDiff : removedObjects)
- {
- removedChildrenUpdates.add(new ObjectUpdate.RemoveChild(diff.getObjectId(),
createRemove((ObjectDiff.Evict)removedChildDiff)));
- }
-
- List<ObjectDiff> existingObjectDiffs = new ArrayList<ObjectDiff>();
- existingObjectDiffs.addAll(validObjects);
- existingObjectDiffs.addAll(staleObjects);
-
- //
- for (ObjectDiff validObjectDiff : existingObjectDiffs)
- {
- ObjectUpdate childUpdate = createUpdate(validObjectDiff);
-
- //
- if (childUpdate == null)
- {
- childrenStatus.put(validObjectDiff.getObjectId(), false);
- }
- else if (childUpdate instanceof ObjectUpdate.UpdateObject)
- {
- updateChildrenUpdates.add((ObjectUpdate.UpdateObject)childUpdate);
- childrenStatus.put(validObjectDiff.getObjectId(), true);
- }
- else if (childUpdate instanceof ObjectUpdate.RemoveObject)
- {
- removedChildrenUpdates.add(new
ObjectUpdate.RemoveChild(diff.getObjectId(), (ObjectUpdate.RemoveObject)childUpdate));
- childrenStatus.put(validObjectDiff.getObjectId(), false);
- }
- else if (childUpdate instanceof ObjectUpdate.AddObject)
- {
- addedChildrenUpdates.add(new ObjectUpdate.AddChild(diff.getObjectId(),
(ObjectUpdate.AddObject)childUpdate));
- childrenStatus.put(validObjectDiff.getObjectId(), true);
- }
- else
- {
- throw new UnsupportedOperationException("Was not expecting update of
type " + childUpdate.getClass().getSimpleName());
- }
- }
-
- //
- for (ObjectUpdate.RemoveChild removeChildUpdate : removedChildrenUpdates)
- {
- removedChildren.add(removeChildUpdate.removedObjectUpdate.objectId);
- }
-
- //
- if (object != null)
- {
- return new ObjectUpdate.UpdateObject(
- object.getStructuralObject(),
- childrenStatus,
- addedChildrenUpdates,
- removedChildrenUpdates,
- updateChildrenUpdates);
- }
- else
- {
- return new ObjectUpdate.AddObject(
- diff.getObject(),
- childrenStatus,
- addedChildrenUpdates,
- removedChildrenUpdates,
- updateChildrenUpdates);
- }
- }
- else if (diff instanceof ObjectDiff.Load)
- {
- return new ObjectUpdate.AddObject(diff.getObject());
- }
- else if (diff instanceof ObjectDiff.SingleUpdate)
- {
- List<ObjectUpdate.RemoveChild> removedChildrenUpdates = new
ArrayList<ObjectUpdate.RemoveChild>();
-
- //
- for (ObjectDiff.Evict evict :
((ObjectDiff.SingleUpdate)diff).getEvictedChildren())
- {
- removedChildrenUpdates.add(new ObjectUpdate.RemoveChild(diff.getObjectId(),
createRemove(evict)));
- }
-
- //
- for (ObjectUpdate.RemoveChild removeChildUpdate : removedChildrenUpdates)
- {
- removedChildren.add(removeChildUpdate.removedObjectUpdate.objectId);
- }
-
- //
- return new ObjectUpdate.UpdateObject(object.getStructuralObject(),
removedChildrenUpdates);
- }
- else if (diff instanceof ObjectDiff.Skip)
- {
- if (object != null)
- {
- throw new AssertionError();
- }
-
- //
- return null;
- }
- else if (diff instanceof ObjectDiff.Evict)
- {
- if (object == null)
- {
- throw new AssertionError();
- }
-
- //
- return createRemove((ObjectDiff.Evict)diff);
- }
- else
- {
- throw new AssertionError("Cannot execute visit of " + diff);
- }
- }
-
- private ObjectUpdate.RemoveObject createRemove(ObjectDiff.Evict evict)
- {
- List<ObjectUpdate.RemoveObject> removedChildrenUpdates = new
ArrayList<ObjectUpdate.RemoveObject>();
-
- //
- for (ObjectDiff.Evict evictedChild : evict.evictedChildren)
- {
- removedChildrenUpdates.add(createRemove(evictedChild));
- }
-
- //
- ObjectUpdate.AddChild addChildUpdate =
deferredAddChildUpdates.remove(evict.getObjectId());
-
- //
- return new ObjectUpdate.RemoveObject(evict.getObjectId(), removedChildrenUpdates,
addChildUpdate);
- }
-}
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectDiff.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectDiff.java 2008-07-07
06:23:05 UTC (rev 11309)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectDiff.java 2008-07-07
12:25:32 UTC (rev 11310)
@@ -71,16 +71,18 @@
Set<String> removedProperties,
Map<String, Serializable> updatedProperties,
Map<String, Serializable> addedProperties,
+ boolean createChildren,
Collection<ObjectDiff> addedChildren,
Collection<ObjectDiff> validChildren,
Collection<ObjectDiff> staleChildren,
- Collection<ObjectDiff> removedChildren)
+ Collection<Evict> removedChildren)
{
return new RecursiveUpdate(
object,
removedProperties,
updatedProperties,
addedProperties,
+ createChildren,
addedChildren,
validChildren,
staleChildren,
@@ -176,6 +178,9 @@
{
/** . */
+ private final boolean createChildren;
+
+ /** . */
private final Collection<ObjectDiff> addedChildren;
/** . */
@@ -185,17 +190,18 @@
private final Collection<ObjectDiff> staleChildren;
/** . */
- private final Collection<ObjectDiff> removedChildren;
+ private final Collection<Evict> removedChildren;
private RecursiveUpdate(
UIObjectImpl object,
Set<String> removedProperties,
Map<String, Serializable> updatedProperties,
Map<String, Serializable> addedProperties,
+ boolean createChildren,
Collection<ObjectDiff> addedChildren,
Collection<ObjectDiff> validChildren,
Collection<ObjectDiff> staleChildren,
- Collection<ObjectDiff> removedChildren)
+ Collection<Evict> removedChildren)
{
super(
object,
@@ -231,12 +237,18 @@
}
//
+ this.createChildren = createChildren;
this.addedChildren = addedChildren;
this.validChildren = validChildren;
this.staleChildren = staleChildren;
this.removedChildren = removedChildren;
}
+ public boolean getCreateChildren()
+ {
+ return createChildren;
+ }
+
public Collection<ObjectDiff> getAddedChildren()
{
return addedChildren;
@@ -252,7 +264,7 @@
return staleChildren;
}
- public Collection<ObjectDiff> getRemovedChildren()
+ public Collection<Evict> getRemovedChildren()
{
return removedChildren;
}
@@ -281,6 +293,13 @@
this.evictedChildren = evictedChildren;
}
+ /**
+ * Returns the list of children to evict. If the list is not null it means that the
children
+ * collection should be destroyed even if the list is empty. If the list is null it
means
+ * that there is no operation to perform on the object with respect to its
children.
+ *
+ * @return the list of evicted children
+ */
public Collection<Evict> getEvictedChildren()
{
return evictedChildren;
@@ -332,8 +351,8 @@
public static class Evict extends ObjectDiff
{
- /** . */
- final Collection<Evict> evictedChildren;
+ /** If null it means that we did not have any children initialized. */
+ private final Collection<Evict> evictedChildren;
public Evict(UIObjectImpl object, Collection<Evict> evictedChildren)
{
@@ -342,5 +361,17 @@
//
this.evictedChildren = evictedChildren;
}
+
+ /**
+ * Returns the list of children to evict. If the list is not null it means that the
children
+ * collection should be destroyed even if the list is empty. If the list is null it
means
+ * that there is no operation to perform on the object with respect to its
children.
+ *
+ * @return the list of evicted children
+ */
+ public Collection<Evict> getEvictedChildren()
+ {
+ return evictedChildren;
+ }
}
}
Deleted:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectUpdate.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectUpdate.java 2008-07-07
06:23:05 UTC (rev 11309)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectUpdate.java 2008-07-07
12:25:32 UTC (rev 11310)
@@ -1,365 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2008, 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.ViewPortContext;
-import org.jboss.portal.presentation.state.structural.StructuralObject;
-import org.jboss.portal.presentation.impl.model.ui.UIObjectImpl;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
- * @version $Revision: 630 $
- */
-public abstract class ObjectUpdate
-{
-
- public abstract void execute(ViewPortContext context);
-
- /**
- * Not really carrying any state for now... until we really implement it.
- */
- public static class UpdateObject extends ObjectUpdate
- {
-
- /** . */
- final StructuralObject structuralObject;
-
- /** . */
- final Map<String, Boolean> childrenStatus;
-
- /** . */
- final List<AddChild> addedChildrenUpdates;
-
- /** . */
- final List<RemoveChild> removedChildrenUpdates;
-
- /** . */
- final List<UpdateObject> updateChildrenUpdates;
-
- public UpdateObject(StructuralObject structuralObject, List<RemoveChild>
removeChildrenUpdates)
- {
- if (structuralObject == null)
- {
- throw new IllegalArgumentException("No null object id accepted");
- }
- if (removeChildrenUpdates == null)
- {
- throw new IllegalArgumentException("No null removed children
accepted");
- }
-
- //
- this.structuralObject = structuralObject;
- this.childrenStatus = null;
- this.addedChildrenUpdates = null;
- this.removedChildrenUpdates = removeChildrenUpdates;
- this.updateChildrenUpdates = null;
- }
-
- public UpdateObject(
- StructuralObject structuralObject,
- Map<String, Boolean> childrenStatus,
- List<AddChild> addedChildrenUpdates,
- List<RemoveChild> removedChildrenUpdates,
- List<UpdateObject> updateChildrenUpdates)
- {
- if (structuralObject == null)
- {
- throw new IllegalArgumentException("No null object id accepted");
- }
- if (addedChildrenUpdates == null)
- {
- throw new IllegalArgumentException("No null added children
accepted");
- }
- if (removedChildrenUpdates == null)
- {
- throw new IllegalArgumentException("No null removed children
accepted");
- }
- if (updateChildrenUpdates == null)
- {
- throw new IllegalArgumentException("No null update children
accepted");
- }
-
- //
- this.structuralObject = structuralObject;
- this.childrenStatus = childrenStatus;
- this.addedChildrenUpdates = addedChildrenUpdates;
- this.removedChildrenUpdates = removedChildrenUpdates;
- this.updateChildrenUpdates = updateChildrenUpdates;
- }
-
- public void execute(ViewPortContext context)
- {
- UIObjectImpl object =
(UIObjectImpl)context.getObject(structuralObject.getId());
-
- // Normally should be ok because if we have removed children updates it means
- // that it was created because the existing object was referencing children
- for (RemoveChild removedChildUpdate : removedChildrenUpdates)
- {
- removedChildUpdate.execute(context);
- }
-
- // Perform state update
- if (object.getStructuralObject().equals(structuralObject))
- {
- object.setStructuralObject(structuralObject);
- context.updateObject(structuralObject.getId());
- }
-
- //
- InternalObjectContext objectContext =
(InternalObjectContext)object.getContext();
-
- //
- if (childrenStatus != null)
- {
- if (objectContext.childRefs == null)
- {
- objectContext.childRefs = new HashMap<String, UIObjectRef>();
- for (Map.Entry<String, Boolean> childRefEntry :
childrenStatus.entrySet())
- {
- objectContext.childRefs.put(childRefEntry.getKey(), new
UIObjectRef(childRefEntry.getKey(), childRefEntry.getValue()));
- }
-
- //
- context.createChildren(structuralObject.getId());
- }
-
- //
- for (AddChild addedChildUpdate : addedChildrenUpdates)
- {
- addedChildUpdate.execute(context);
- }
-
- //
- for (UpdateObject updateChildUpdate : updateChildrenUpdates)
- {
- updateChildUpdate.execute(context);
- }
- }
- else
- {
- if (objectContext.childRefs != null)
- {
- context.destroyChildren(structuralObject.getId());
- }
- }
- }
- }
-
- public static class AddObject extends ObjectUpdate
- {
-
- /** . */
- private final UIObjectImpl object;
-
- /** . */
- private final Map<String, Boolean> childrenStatus;
-
- /** . */
- private final List<AddChild> addedChildrenUpdates;
-
- /** . */
- private final List<RemoveChild> removedChildrenUpdates;
-
- /** . */
- private final List<UpdateObject> updateChildrenUpdates;
-
- public AddObject(UIObjectImpl object)
- {
- if (object == null)
- {
- throw new IllegalArgumentException("No null object accepted");
- }
-
- //
- this.object = object;
- this.childrenStatus = null;
- this.addedChildrenUpdates = null;
- this.removedChildrenUpdates = null;
- this.updateChildrenUpdates = null;
- }
-
- public AddObject(
- UIObjectImpl object,
- Map<String, Boolean> childrenStatus,
- List<AddChild> addedChildrenUpdates,
- List<RemoveChild> removedChildrenUpdates,
- List<UpdateObject> updateChildrenUpdates)
- {
- if (object == null)
- {
- throw new IllegalArgumentException("No null object accepted");
- }
- if (addedChildrenUpdates == null)
- {
- throw new IllegalArgumentException("No null added children
accepted");
- }
- if (removedChildrenUpdates == null)
- {
- throw new IllegalArgumentException("No null removed children
accepted");
- }
- if (updateChildrenUpdates == null)
- {
- throw new IllegalArgumentException("No null update children
accepted");
- }
-
-
- //
- this.object = object;
- this.childrenStatus = childrenStatus;
- this.addedChildrenUpdates = addedChildrenUpdates;
- this.removedChildrenUpdates = removedChildrenUpdates;
- this.updateChildrenUpdates = updateChildrenUpdates;
- }
-
- public void execute(ViewPortContext context)
- {
- context.addObject(object);
-
- //
- if (childrenStatus != null)
- {
- InternalObjectContext objectContext =
(InternalObjectContext)object.getContext();
-
- //
- objectContext.childRefs = new HashMap<String, UIObjectRef>();
- for (Map.Entry<String, Boolean> childRefEntry :
childrenStatus.entrySet())
- {
- objectContext.childRefs.put(childRefEntry.getKey(), new
UIObjectRef(childRefEntry.getKey(), childRefEntry.getValue()));
- }
-
- //
- context.createChildren(object.getId());
-
- //
- for (AddChild addedChildUpdate : addedChildrenUpdates)
- {
- addedChildUpdate.execute(context);
- }
-
- //
- for (RemoveChild removedChildUpdate : removedChildrenUpdates)
- {
- removedChildUpdate.execute(context);
- }
-
- //
- for (UpdateObject updateChildUpdate : updateChildrenUpdates)
- {
- updateChildUpdate.execute(context);
- }
- }
- }
- }
-
- public static class RemoveObject extends ObjectUpdate
- {
-
- /** . */
- final String objectId;
-
- /** . */
- private final List<RemoveObject> removedChildrenUpdates;
-
- /** . */
- private final AddChild addChildUpdate;
-
- public RemoveObject(String objectId, List<RemoveObject>
removedChildrenUpdates, AddChild addChildUpdate)
- {
- this.objectId = objectId;
- this.removedChildrenUpdates = removedChildrenUpdates;
- this.addChildUpdate = addChildUpdate;
- }
-
- public void execute(ViewPortContext context)
- {
- for (RemoveObject removedChildUpdate : removedChildrenUpdates)
- {
- context.removeChild(objectId, removedChildUpdate.objectId);
-
- //
- removedChildUpdate.execute(context);
- }
-
- //
- context.removeObject(objectId);
-
- //
- if (addChildUpdate != null)
- {
- addChildUpdate.execute(context);
- }
- }
- }
-
- public static class AddChild extends ObjectUpdate
- {
-
- /** . */
- private final String parentId;
-
- /** . */
- private final AddObject addedObjectUpdate;
-
- public AddChild(String parentId, AddObject addedObjectUpdate)
- {
- this.parentId = parentId;
- this.addedObjectUpdate = addedObjectUpdate;
- }
-
- public void execute(ViewPortContext context)
- {
- addedObjectUpdate.execute(context);
-
- //
- context.addChild(parentId, addedObjectUpdate.object.getId());
- }
- }
-
- public static class RemoveChild extends ObjectUpdate
- {
-
- /** . */
- private final String parentId;
-
- /** . */
- final RemoveObject removedObjectUpdate;
-
- public RemoveChild(String parentId, RemoveObject removedObjectUpdate)
- {
- this.parentId = parentId;
- this.removedObjectUpdate = removedObjectUpdate;
- }
-
- public void execute(ViewPortContext context)
- {
- context.removeChild(parentId, removedObjectUpdate.objectId);
-
- //
- removedObjectUpdate.execute(context);
- }
- }
-}
Deleted:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectVisit.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectVisit.java 2008-07-07
06:23:05 UTC (rev 11309)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectVisit.java 2008-07-07
12:25:32 UTC (rev 11310)
@@ -1,339 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2008, 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.impl.model.ui.UIObjectImpl;
-
-import java.util.Set;
-import java.util.Map;
-import java.util.Collection;
-import java.io.Serializable;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
- * @version $Revision: 630 $
- */
-public abstract class ObjectVisit
-{
-
- static ObjectVisit.Evict createEvict(UIObjectImpl object, Collection<Evict>
evictedChildren)
- {
- return new Evict(object, evictedChildren);
- }
-
- static RecursiveLoad createRecursiveLoad(UIObjectImpl object,
Collection<ObjectVisit> addedChildren)
- {
- return new RecursiveLoad(object, addedChildren);
- }
-
- static ObjectVisit createLoad(UIObjectImpl object)
- {
- return new Load(object);
- }
-
- static ObjectVisit createSkip(UIObjectImpl object)
- {
- return new Skip(object);
- }
-
- static SingleUpdate createSingleUpdate(
- UIObjectImpl object,
- Set<String> removedProperties,
- Map<String, Serializable> updatedProperties,
- Map<String, Serializable> addedProperties,
- Collection<Evict> evictedChildren)
- {
- return new SingleUpdate(object, removedProperties, updatedProperties,
addedProperties, evictedChildren);
- }
-
- static RecursiveUpdate createRecursiveUpdate(
- UIObjectImpl object,
- Set<String> removedProperties,
- Map<String, Serializable> updatedProperties,
- Map<String, Serializable> addedProperties,
- Collection<ObjectVisit> addedChildren,
- Collection<ObjectVisit> validChildren,
- Collection<ObjectVisit> staleChildren,
- Collection<ObjectVisit> removedChildren)
- {
- return new RecursiveUpdate(
- object,
- removedProperties,
- updatedProperties,
- addedProperties,
- addedChildren,
- validChildren,
- staleChildren,
- removedChildren);
- }
-
- /** . */
- private final UIObjectImpl object;
-
- private ObjectVisit(UIObjectImpl object)
- {
- if (object == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- this.object = object;
- }
-
- public String getObjectId()
- {
- return object.getId();
- }
-
- public UIObjectImpl getObject()
- {
- return object;
- }
-
- public static class Skip extends ObjectVisit
- {
- private Skip(UIObjectImpl object)
- {
- super(object);
- }
- }
-
- public static class Load extends ObjectVisit
- {
-
- private Load(UIObjectImpl object)
- {
- super(object);
- }
- }
-
- public static class RecursiveLoad extends Load
- {
-
- /** . */
- private final Collection<ObjectVisit> addedChildren;
-
- private RecursiveLoad(
- UIObjectImpl object,
- Collection<ObjectVisit> addedChildren)
- {
- super(object);
-
- //
- if (addedChildren == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- for (ObjectVisit addedChild : addedChildren)
- {
- if (!(addedChild instanceof Skip || addedChild instanceof Load))
- {
- throw new AssertionError("Cannot accept added child " +
addedChild);
- }
- }
-
- //
- this.addedChildren = addedChildren;
- }
-
- public Collection<ObjectVisit> getAddedChildren()
- {
- return addedChildren;
- }
- }
-
- public static class RecursiveUpdate extends Update
- {
-
- /** . */
- private final Collection<ObjectVisit> addedChildren;
-
- /** . */
- private final Collection<ObjectVisit> validChildren;
-
- /** . */
- private final Collection<ObjectVisit> staleChildren;
-
- /** . */
- private final Collection<ObjectVisit> removedChildren;
-
- private RecursiveUpdate(
- UIObjectImpl object,
- Set<String> removedProperties,
- Map<String, Serializable> updatedProperties,
- Map<String, Serializable> addedProperties,
- Collection<ObjectVisit> addedChildren,
- Collection<ObjectVisit> validChildren,
- Collection<ObjectVisit> staleChildren,
- Collection<ObjectVisit> removedChildren)
- {
- super(
- object,
- removedProperties,
- updatedProperties,
- addedProperties);
-
- //
- if (addedChildren == null)
- {
- throw new IllegalArgumentException();
- }
- if (validChildren == null)
- {
- throw new IllegalArgumentException();
- }
- if (staleChildren == null)
- {
- throw new IllegalArgumentException();
- }
- if (removedChildren == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- for (ObjectVisit addedChild : addedChildren)
- {
- if (!(addedChild instanceof Evict || addedChild instanceof Load))
- {
- throw new AssertionError();
- }
- }
-
- //
- this.addedChildren = addedChildren;
- this.validChildren = validChildren;
- this.staleChildren = staleChildren;
- this.removedChildren = removedChildren;
- }
-
- public Collection<ObjectVisit> getAddedChildren()
- {
- return addedChildren;
- }
-
- public Collection<ObjectVisit> getValidChildren()
- {
- return validChildren;
- }
-
- public Collection<ObjectVisit> getStaleChildren()
- {
- return staleChildren;
- }
-
- public Collection<ObjectVisit> getRemovedChildren()
- {
- return removedChildren;
- }
- }
-
- public static class SingleUpdate extends Update
- {
-
- /** . */
- private final Collection<Evict> evictedChildren;
-
- public SingleUpdate(
- UIObjectImpl object,
- Set<String> removedProperties,
- Map<String, Serializable> updatedProperties,
- Map<String, Serializable> addedProperties,
- Collection<Evict> evictedChildren)
- {
- super(
- object,
- removedProperties,
- updatedProperties,
- addedProperties);
-
- //
- this.evictedChildren = evictedChildren;
- }
-
- public Collection<Evict> getEvictedChildren()
- {
- return evictedChildren;
- }
- }
-
- public static class Update extends ObjectVisit
- {
-
- /** . */
- private final Set<String> removedProperties;
-
- /** . */
- private final Map<String, Serializable> updatedProperties;
-
- /** . */
- private final Map<String, Serializable> addedProperties;
-
- private Update(
- UIObjectImpl object,
- Set<String> removedProperties,
- Map<String, Serializable> updatedProperties,
- Map<String, Serializable> addedProperties)
- {
- super(object);
-
- //
- this.removedProperties = removedProperties;
- this.updatedProperties = updatedProperties;
- this.addedProperties = addedProperties;
- }
-
- public Set<String> getRemovedProperties()
- {
- return removedProperties;
- }
-
- public Map<String, Serializable> getUpdatedProperties()
- {
- return updatedProperties;
- }
-
- public Map<String, Serializable> getAddedProperties()
- {
- return addedProperties;
- }
- }
-
- public static class Evict extends ObjectVisit
- {
-
- /** . */
- final Collection<Evict> evictedChildren;
-
- public Evict(UIObjectImpl object, Collection<Evict> evictedChildren)
- {
- super(object);
-
- //
- this.evictedChildren = evictedChildren;
- }
- }
-}
Added:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java 2008-07-07
12:25:32 UTC (rev 11310)
@@ -0,0 +1,207 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.ViewPortContext;
+import org.jboss.portal.presentation.impl.model.ui.UIObjectImpl;
+
+import java.util.Collection;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UpdatePhase
+{
+
+ /** . */
+ private final ViewPortContext context;
+
+ /** . */
+ private final ObjectDiff rootDiff;
+
+ public UpdatePhase(ViewPortContext context, ObjectDiff rootDiff)
+ {
+ this.context = context;
+ this.rootDiff = rootDiff;
+ }
+
+ public void perform()
+ {
+ perform1stPhase();
+ perform2ndPhase();
+ }
+
+ private void perform1stPhase()
+ {
+ perform1stPhase(rootDiff);
+ }
+
+ private void perform1stPhase(ObjectDiff diff)
+ {
+ if (diff instanceof ObjectDiff.Evict)
+ {
+ ObjectDiff.Evict evict = (ObjectDiff.Evict)diff;
+
+ //
+ if (evict.getEvictedChildren() != null)
+ {
+ perform1stPhase(diff.getObject(), evict.getEvictedChildren());
+
+ //
+ context.destroyChildren(diff.getObjectId());
+ }
+
+ //
+ context.removeObject(evict.getObjectId());
+ }
+ else if (diff instanceof ObjectDiff.Update)
+ {
+ if (diff instanceof ObjectDiff.RecursiveUpdate)
+ {
+ ObjectDiff.RecursiveUpdate recursiveUpdate =
(ObjectDiff.RecursiveUpdate)diff;
+
+ //
+ perform1stPhase(diff.getObject(), recursiveUpdate.getAddedChildren());
+ perform1stPhase(diff.getObject(), recursiveUpdate.getStaleChildren());
+ perform1stPhase(diff.getObject(), recursiveUpdate.getValidChildren());
+ perform1stPhase(diff.getObject(), recursiveUpdate.getRemovedChildren());
+ }
+ else
+ {
+ ObjectDiff.SingleUpdate singleUpdate = (ObjectDiff.SingleUpdate)diff;
+
+ //
+ if (singleUpdate.getEvictedChildren() != null)
+ {
+ perform1stPhase(diff.getObject(), singleUpdate.getEvictedChildren());
+
+ //
+ context.destroyChildren(diff.getObjectId());
+ }
+ }
+ }
+ }
+
+ private void perform1stPhase(UIObjectImpl parent, Collection<? extends
ObjectDiff> diffs)
+ {
+ for (ObjectDiff diff : diffs)
+ {
+ if (diff instanceof ObjectDiff.Evict)
+ {
+ String childId = diff.getObjectId();
+
+ //
+ context.removeChild(parent.getId(), childId);
+
+ //
+ InternalObjectContext parentContext =
(InternalObjectContext)parent.getContext();
+
+ //
+ parentContext.childRefs.remove(childId);
+ }
+
+ //
+ perform1stPhase(diff);
+ }
+ }
+
+ private void perform2ndPhase()
+ {
+ perform2ndPhase(rootDiff);
+ }
+
+ private void perform2ndPhase(ObjectDiff diff)
+ {
+ UIObjectImpl object = diff.getObject();
+
+ //
+ InternalObjectContext objectContext = (InternalObjectContext)object.getContext();
+
+ //
+ if (diff instanceof ObjectDiff.Load)
+ {
+ context.addObject(object);
+
+ //
+ if (diff instanceof ObjectDiff.RecursiveLoad)
+ {
+ objectContext.childRefs = new HashMap<String, UIObjectRef>();
+
+ //
+ context.createChildren(object.getId());
+
+ //
+ perform2ndPhase(diff.getObject(),
((ObjectDiff.RecursiveLoad)diff).getAddedChildren());
+ }
+ }
+ else if (diff instanceof ObjectDiff.Update)
+ {
+ if (diff instanceof ObjectDiff.RecursiveUpdate)
+ {
+ ObjectDiff.RecursiveUpdate recursiveUpdate =
(ObjectDiff.RecursiveUpdate)diff;
+
+ //
+ if (recursiveUpdate.getCreateChildren())
+ {
+ objectContext.childRefs = new HashMap<String, UIObjectRef>();
+
+ //
+ context.createChildren(object.getId());
+ }
+
+ //
+ perform2ndPhase(diff.getObject(), recursiveUpdate.getAddedChildren());
+ perform2ndPhase(diff.getObject(), recursiveUpdate.getValidChildren());
+ perform2ndPhase(diff.getObject(), recursiveUpdate.getStaleChildren());
+ }
+ }
+ }
+
+ private void perform2ndPhase(UIObjectImpl parent, Collection<ObjectDiff> diffs)
+ {
+ InternalObjectContext objectContext = (InternalObjectContext)parent.getContext();
+
+ //
+ for (ObjectDiff diff : diffs)
+ {
+ perform2ndPhase(diff);
+
+ //
+ if (diff instanceof ObjectDiff.Load)
+ {
+ objectContext.childRefs.put(diff.getObjectId(), new
UIObjectRef(diff.getObjectId(), true));
+ context.addChild(parent.getId(), diff.getObjectId());
+ }
+ else if (diff instanceof ObjectDiff.Update)
+ {
+ // Nothing ?
+ }
+ else if (diff instanceof ObjectDiff.Skip)
+ {
+ objectContext.childRefs.put(diff.getObjectId(), new
UIObjectRef(diff.getObjectId(), false));
+ }
+ }
+ }
+}
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java 2008-07-07
06:23:05 UTC (rev 11309)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java 2008-07-07
12:25:32 UTC (rev 11310)
@@ -59,17 +59,10 @@
//
ObjectDiff rootDiff = createDiffPhase.getRootVisit();
- //
- CreateUpdatePhase createUpdatePhase = new CreateUpdatePhase(context, rootDiff);
+ UpdatePhase phase = new UpdatePhase(context, rootDiff);
//
- createUpdatePhase.perform();
-
- //
- ObjectUpdate rootUpdate = createUpdatePhase.getRootUpdate();
-
- //
- rootUpdate.execute(context);
+ phase.perform();
}
public ViewPortContext getContext()