Author: julien(a)jboss.com
Date: 2008-07-04 10:44:10 -0400 (Fri, 04 Jul 2008)
New Revision: 11295
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/CreateUpdatePhase.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectVisit.java
Log:
refactor object visits for cleaner semantic
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-04
13:38:12 UTC (rev 11294)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java 2008-07-04
14:44:10 UTC (rev 11295)
@@ -107,7 +107,7 @@
{
if (traversalType == ObjectTraversalType.SKIP)
{
- return new ObjectVisit(object, false);
+ return ObjectVisit.createEvict(object);
}
else
{
@@ -145,7 +145,7 @@
}
//
- return new ObjectVisit(object, childrenVisit);
+ return ObjectVisit.createUpdate(object, childrenVisit);
}
}
finally
@@ -166,7 +166,7 @@
{
if (traversalType == ObjectTraversalType.SKIP)
{
- return new ObjectVisit(object, false);
+ return ObjectVisit.createSkip(object);
}
else
{
@@ -184,7 +184,7 @@
}
//
- return new ObjectVisit(object, childrenVisit);
+ return ObjectVisit.createLoad(object, childrenVisit);
}
}
finally
Modified:
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-04
13:38:12 UTC (rev 11294)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateUpdatePhase.java 2008-07-04
14:44:10 UTC (rev 11295)
@@ -80,18 +80,18 @@
}
}
- private ObjectUpdate createUpdate(ObjectVisit objectVisit)
+ private ObjectUpdate createUpdate(ObjectVisit visit)
{
- UIObjectImpl object = (UIObjectImpl)context.getObject(objectVisit.getObjectId());
+ UIObjectImpl object = (UIObjectImpl)context.getObject(visit.getObjectId());
- if (objectVisit.getLoaded())
+ if (visit instanceof ObjectVisit.Load || visit instanceof ObjectVisit.Update)
{
- ChildrenVisit childrenVisit = objectVisit.getChildrenVisit();
+ ChildrenVisit childrenVisit = visit instanceof ObjectVisit.Load ?
((ObjectVisit.Load)visit).getChildrenVisit() :
((ObjectVisit.Update)visit).getChildrenVisit();
//
if (object != null)
{
- if (object != objectVisit.getObject())
+ if (object != visit.getObject())
{
// The object is stale, we need to update the state maybe
}
@@ -113,7 +113,7 @@
//
if (childUpdate instanceof ObjectUpdate.AddObject)
{
- addedChildrenUpdates.add(new
ObjectUpdate.AddChild(objectVisit.getObjectId(), (ObjectUpdate.AddObject)childUpdate));
+ addedChildrenUpdates.add(new ObjectUpdate.AddChild(visit.getObjectId(),
(ObjectUpdate.AddObject)childUpdate));
childrenStatus.put(addedObjectVisit.getObjectId(), true);
}
else if (childUpdate == null)
@@ -135,7 +135,7 @@
updateChildUpdate.updateChildrenUpdates);
//
- ObjectUpdate.AddChild addChildUpdate = new
ObjectUpdate.AddChild(objectVisit.getObjectId(), addObjectUpdate);
+ ObjectUpdate.AddChild addChildUpdate = new
ObjectUpdate.AddChild(visit.getObjectId(), addObjectUpdate);
//
if (removedChildren.contains(addedObjectVisit.getObjectId()))
@@ -160,7 +160,7 @@
for (String removeObjectId : childrenVisit.getRemovedObjects())
{
UIObjectImpl child = (UIObjectImpl)context.getObject(removeObjectId);
- removedChildrenUpdates.add(new
ObjectUpdate.RemoveChild(objectVisit.getObjectId(), createRemove(child)));
+ removedChildrenUpdates.add(new
ObjectUpdate.RemoveChild(visit.getObjectId(), createRemove(child)));
}
List<ObjectVisit> existingObjectVisits = new
ArrayList<ObjectVisit>();
@@ -184,12 +184,12 @@
}
else if (childUpdate instanceof ObjectUpdate.RemoveObject)
{
- removedChildrenUpdates.add(new
ObjectUpdate.RemoveChild(objectVisit.getObjectId(),
(ObjectUpdate.RemoveObject)childUpdate));
+ removedChildrenUpdates.add(new
ObjectUpdate.RemoveChild(visit.getObjectId(), (ObjectUpdate.RemoveObject)childUpdate));
childrenStatus.put(validObjectVisit.getObjectId(), false);
}
else if (childUpdate instanceof ObjectUpdate.AddObject)
{
- addedChildrenUpdates.add(new
ObjectUpdate.AddChild(objectVisit.getObjectId(), (ObjectUpdate.AddObject)childUpdate));
+ addedChildrenUpdates.add(new ObjectUpdate.AddChild(visit.getObjectId(),
(ObjectUpdate.AddObject)childUpdate));
childrenStatus.put(validObjectVisit.getObjectId(), true);
}
else
@@ -217,7 +217,7 @@
else
{
return new ObjectUpdate.AddObject(
- objectVisit.getObject(),
+ visit.getObject(),
childrenStatus,
addedChildrenUpdates,
removedChildrenUpdates,
@@ -243,7 +243,7 @@
UIObjectImpl child =
(UIObjectImpl)context.getObject(removedChildRef.getId());
//
- removedChildrenUpdates.add(new
ObjectUpdate.RemoveChild(objectVisit.getObjectId(), createRemove(child)));
+ removedChildrenUpdates.add(new
ObjectUpdate.RemoveChild(visit.getObjectId(), createRemove(child)));
}
}
}
@@ -259,21 +259,34 @@
}
else
{
- return new ObjectUpdate.AddObject(objectVisit.getObject());
+ return new ObjectUpdate.AddObject(visit.getObject());
}
}
}
- else
+ else if (visit instanceof ObjectVisit.Skip)
{
if (object != null)
{
- return createRemove(object);
+ throw new AssertionError();
}
- else
+
+ //
+ return null;
+ }
+ else if (visit instanceof ObjectVisit.Evict)
+ {
+ if (object == null)
{
- return null;
+ throw new AssertionError();
}
+
+ //
+ return createRemove(object);
}
+ else
+ {
+ throw new AssertionError();
+ }
}
private ObjectUpdate.RemoveObject createRemove(UIObjectImpl object)
Modified:
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-04
13:38:12 UTC (rev 11294)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectVisit.java 2008-07-04
14:44:10 UTC (rev 11295)
@@ -31,50 +31,94 @@
public class ObjectVisit
{
+ static ObjectVisit createEvict(UIObjectImpl object)
+ {
+ return new Evict(object);
+ }
- /*
- public static class Skip extends ObjectVisit
+ static ObjectVisit createLoad(UIObjectImpl object, ChildrenVisit children)
{
+ return new Load(object, children);
+ }
+ static ObjectVisit createSkip(UIObjectImpl object)
+ {
+ return new Skip(object);
}
+ static ObjectVisit createUpdate(UIObjectImpl object, ChildrenVisit children)
+ {
+ return new Update(object, children);
+ }
+
+ public static class Skip extends ObjectVisit
+ {
+ public Skip(UIObjectImpl object)
+ {
+ super(object);
+ }
+ }
+
public static class Load extends ObjectVisit
{
+ /** . */
+ private final ChildrenVisit children;
+
+ public Load(UIObjectImpl object, ChildrenVisit children)
+ {
+ super(object);
+
+ //
+ this.children = children;
+ }
+
+ public ChildrenVisit getChildrenVisit()
+ {
+ return children;
+ }
}
public static class Update extends ObjectVisit
{
+ /** . */
+ private final ChildrenVisit children;
+
+ public Update(UIObjectImpl object, ChildrenVisit children)
+ {
+ super(object);
+
+ //
+ this.children = children;
+ }
+
+ public ChildrenVisit getChildrenVisit()
+ {
+ return children;
+ }
}
public static class Evict extends ObjectVisit
{
-
+ public Evict(UIObjectImpl object)
+ {
+ super(object);
+ }
}
-*/
/** . */
private final UIObjectImpl object;
- /** . */
- private final boolean loaded;
-
- /** . */
- private final ChildrenVisit children;
-
- ObjectVisit(UIObjectImpl object, ChildrenVisit children)
+ public ObjectVisit(UIObjectImpl object)
{
- this.object = object;
- this.loaded = true;
- this.children = children;
- }
+ if (object == null)
+ {
+ throw new IllegalArgumentException();
+ }
- ObjectVisit(UIObjectImpl object, boolean loaded)
- {
+ //
this.object = object;
- this.loaded = loaded;
- this.children = null;
}
public String getObjectId()
@@ -86,14 +130,4 @@
{
return object;
}
-
- public boolean getLoaded()
- {
- return loaded;
- }
-
- public ChildrenVisit getChildrenVisit()
- {
- return children;
- }
}