Author: julien(a)jboss.com
Date: 2008-07-03 17:59:22 -0400 (Thu, 03 Jul 2008)
New Revision: 11288
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/model/AjaxViewPortContext.java
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/ObjectVisit.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/structural/adapter/StructuralObjectImpl.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/structural/adapter/StructuralStateContextImpl.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/structural/StructuralObject.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/structural/StructuralState.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/MockModelImpl.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java
Log:
minor refactor of switch logic
Modified:
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/model/AjaxViewPortContext.java
===================================================================
---
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/model/AjaxViewPortContext.java 2008-07-03
21:52:24 UTC (rev 11287)
+++
modules/presentation/trunk/ajax/src/main/java/org/jboss/portal/presentation/ajax/server/model/AjaxViewPortContext.java 2008-07-03
21:59:22 UTC (rev 11288)
@@ -118,8 +118,8 @@
public void updateObject(String objectId)
{
- updates
-
+// updates
+//
throw new NotYetImplemented();
}
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-03
21:52:24 UTC (rev 11287)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java 2008-07-03
21:59:22 UTC (rev 11288)
@@ -105,16 +105,20 @@
//
try
{
- switch (traversalType)
+ if (traversalType == ObjectTraversalType.SKIP)
{
- case SKIP:
- return new ObjectVisit(object, false);
- case SINGLE:
- return new ObjectVisit(object, true);
- case RECURSIVE:
- StructuralObject.Refresh refresh =
structuralStateContext.refresh(object.getStructuralObject());
- ChildrenVisit childrenVisit = new ChildrenVisit();
+ return new ObjectVisit(object, false);
+ }
+ else
+ {
+ StructuralObject.Refresh refresh =
structuralStateContext.refresh(object.getStructuralObject());
+ //
+ ChildrenVisit childrenVisit = null;
+ if (traversalType == ObjectTraversalType.RECURSIVE)
+ {
+ childrenVisit = new ChildrenVisit();
+
//
for (StructuralObject addedStructuralChild : refresh.getAddedChildren())
{
@@ -138,11 +142,10 @@
//
childrenVisit.removedObjects.addAll(refresh.getRemovedChildren());
+ }
- //
- return new ObjectVisit(object, childrenVisit);
- default:
- throw new AssertionError();
+ //
+ return new ObjectVisit(object, childrenVisit);
}
}
finally
@@ -161,30 +164,28 @@
//
try
{
- ObjectVisit visit;
- switch (traversalType)
+ if (traversalType == ObjectTraversalType.SKIP)
{
- case SKIP:
- visit = new ObjectVisit(object, false);
- break;
- case SINGLE:
- visit = new ObjectVisit(object, true);
- break;
- case RECURSIVE:
- ChildrenVisit childrenVisit = new ChildrenVisit();
+ return new ObjectVisit(object, false);
+ }
+ else
+ {
+ ChildrenVisit childrenVisit = null;
+
+ //
+ if (traversalType == ObjectTraversalType.RECURSIVE)
+ {
+ childrenVisit = new ChildrenVisit();
for (StructuralObject structuralChild :
structuralStateContext.loadChildren(structuralObject))
{
ObjectVisit childVisit = load(structuralChild);
childrenVisit.addedObjects.add(childVisit);
}
- visit = new ObjectVisit(object, childrenVisit);
- break;
- default:
- throw new AssertionError();
+ }
+
+ //
+ return new ObjectVisit(object, childrenVisit);
}
-
- //
- return visit;
}
finally
{
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-03
21:52:24 UTC (rev 11287)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectVisit.java 2008-07-03
21:59:22 UTC (rev 11288)
@@ -31,6 +31,29 @@
public class ObjectVisit
{
+
+ /*
+ public static class Skip extends ObjectVisit
+ {
+
+ }
+
+ public static class Load extends ObjectVisit
+ {
+
+ }
+
+ public static class Update extends ObjectVisit
+ {
+
+ }
+
+ public static class Evict extends ObjectVisit
+ {
+
+ }
+*/
+
/** . */
private final UIObjectImpl object;
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/structural/adapter/StructuralObjectImpl.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/structural/adapter/StructuralObjectImpl.java 2008-07-03
21:52:24 UTC (rev 11287)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/structural/adapter/StructuralObjectImpl.java 2008-07-03
21:59:22 UTC (rev 11288)
@@ -117,5 +117,6 @@
return that.childrenIds.equals(this.childrenIds);
}
return false;
+// throw new UnsupportedOperationException();
}
}
\ No newline at end of file
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/structural/adapter/StructuralStateContextImpl.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/structural/adapter/StructuralStateContextImpl.java 2008-07-03
21:52:24 UTC (rev 11287)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/structural/adapter/StructuralStateContextImpl.java 2008-07-03
21:59:22 UTC (rev 11288)
@@ -35,6 +35,7 @@
import java.util.Set;
import java.util.HashSet;
import java.util.Map;
+import java.io.Serializable;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -259,6 +260,7 @@
return new StructuralObject.Refresh(
parentNode != null ? takeSnapshot(parentNode) : null,
nodeSnapshot,
+ new HashMap<String, Serializable>(),
addedStructuralChildren,
removedChildrenIds,
staleStructuralChildren,
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/structural/StructuralObject.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/structural/StructuralObject.java 2008-07-03
21:52:24 UTC (rev 11287)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/structural/StructuralObject.java 2008-07-03
21:59:22 UTC (rev 11288)
@@ -24,6 +24,7 @@
import java.util.Map;
import java.util.Set;
+import java.io.Serializable;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -51,6 +52,9 @@
private final StructuralObject object;
/** . */
+ private final Map<String, Serializable> propertiesUpdate;
+
+ /** . */
private final Set<StructuralObject> addedChildren;
/** . */
@@ -65,11 +69,20 @@
public Refresh(
StructuralObject parent,
StructuralObject object,
+ Map<String, Serializable> propertiesUpdate,
Set<StructuralObject> addedChildren,
Set<String> removedChildren,
Map<String, StructuralObject> staleChildren,
Set<String> validChildren)
{
+ if (object == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertiesUpdate == null)
+ {
+ throw new IllegalArgumentException();
+ }
if (addedChildren == null)
{
throw new IllegalArgumentException();
@@ -86,7 +99,10 @@
{
throw new IllegalArgumentException();
}
+
+ //
this.parent = parent;
+ this.propertiesUpdate = propertiesUpdate;
this.object = object;
this.addedChildren = addedChildren;
this.validChildren = validChildren;
@@ -99,6 +115,11 @@
return parent;
}
+ public Map<String, Serializable> getPropertiesUpdate()
+ {
+ return propertiesUpdate;
+ }
+
public StructuralObject getObject()
{
return object;
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/structural/StructuralState.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/structural/StructuralState.java 2008-07-03
21:52:24 UTC (rev 11287)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/structural/StructuralState.java 2008-07-03
21:59:22 UTC (rev 11288)
@@ -35,8 +35,17 @@
*/
public interface StructuralState
{
-
+ /**
+ * Returns the object type.
+ *
+ * @return the type
+ */
Class<? extends UIObject> getType();
+ /**
+ * Returns an immutable map containing the object properties.
+ *
+ * @return the properties
+ */
Map<String, Serializable> getProperties();
}
\ No newline at end of file
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/MockModelImpl.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/MockModelImpl.java 2008-07-03
21:52:24 UTC (rev 11287)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/MockModelImpl.java 2008-07-03
21:59:22 UTC (rev 11288)
@@ -40,6 +40,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Collections;
+import java.io.Serializable;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -146,6 +148,40 @@
}
//
+ Map<String, Serializable> currentProperties =
current.getState().getProperties();
+ Map<String, Serializable> previousProperties =
previous.getState().getProperties();
+ Map<String, Serializable> propertiesUpdate = Collections.emptyMap();
+
+ // Find all removed properties
+ for (String key : previousProperties.keySet())
+ {
+ if (!currentProperties.containsKey(key))
+ {
+ if (propertiesUpdate.isEmpty())
+ {
+ propertiesUpdate = new HashMap<String, Serializable>();
+ }
+ propertiesUpdate.put(key, null);
+ }
+ }
+
+ // Now put updated or new properties
+ for (Map.Entry<String, Serializable> entry :
currentProperties.entrySet())
+ {
+ String currentKey = entry.getKey();
+ Serializable currentValue = entry.getValue();
+ Serializable previousValue = previousProperties.get(currentKey);
+ if (previousValue == null || !previousValue.equals(currentValue))
+ {
+ if (propertiesUpdate.isEmpty())
+ {
+ propertiesUpdate = new HashMap<String, Serializable>();
+ }
+ propertiesUpdate.put(currentKey, currentValue);
+ }
+ }
+
+ //
Map<String, StructuralObjectHandle> previousChildren = new
HashMap<String, StructuralObjectHandle>();
for (StructuralObjectHandle childHandle : previous.childrenHandles)
{
@@ -210,7 +246,14 @@
}
//
- return new StructuralObject.Refresh(parent, current, addedChildren,
removedChildren, staleChildrenHandleMap, validChildren);
+ return new StructuralObject.Refresh(
+ parent,
+ current,
+ propertiesUpdate,
+ addedChildren,
+ removedChildren,
+ staleChildrenHandleMap,
+ validChildren);
}
public Collection<StructuralObject> loadChildren(StructuralObject parent)
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java
===================================================================
---
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java 2008-07-03
21:52:24 UTC (rev 11287)
+++
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java 2008-07-03
21:59:22 UTC (rev 11288)
@@ -82,5 +82,6 @@
return handle.equals(that.handle);
}
return false;
+// throw new UnsupportedOperationException();
}
}