Author: julien(a)jboss.com
Date: 2008-07-07 12:52:50 -0400 (Mon, 07 Jul 2008)
New Revision: 11322
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/DiffPhase.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/UpdatePhase.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java
Log:
create ui object impl only when necessary
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/DiffPhase.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/DiffPhase.java 2008-07-07
16:37:56 UTC (rev 11321)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/DiffPhase.java 2008-07-07
16:52:50 UTC (rev 11322)
@@ -25,7 +25,6 @@
import org.jboss.portal.presentation.model.ObjectTraversalType;
import org.jboss.portal.presentation.model.ViewPortContext;
import org.jboss.portal.presentation.model.ViewPortScope;
-import org.jboss.portal.presentation.state.navigational.NavigationalStateContext;
import org.jboss.portal.presentation.state.structural.StructuralObject;
import org.jboss.portal.presentation.state.structural.StructuralStateContext;
import org.jboss.portal.presentation.impl.model.ui.UIObjectImpl;
@@ -47,9 +46,6 @@
private final ViewPortScope scope;
/** . */
- private final NavigationalStateContext navigationalStateContext;
-
- /** . */
private final StructuralStateContext structuralStateContext;
/** . */
@@ -58,12 +54,10 @@
public DiffPhase(
ViewPortContext context,
ViewPortScope scope,
- NavigationalStateContext navigationalStateContext,
StructuralStateContext structuralStateContext)
{
this.context = context;
this.scope = scope;
- this.navigationalStateContext = navigationalStateContext;
this.structuralStateContext = structuralStateContext;
}
@@ -97,23 +91,20 @@
}
else
{
- return diff(object);
+ return diff((InternalObjectContext)object.getContext());
}
}
- private ObjectDiff.Evict createEvict(UIObjectImpl object)
+ private ObjectDiff.Evict createEvict(InternalObjectContext object)
{
Collection<ObjectDiff.Evict> evictedChildren =
createEvictedChildren(object);
//
- return ObjectDiff.createEvict(object, evictedChildren);
+ return ObjectDiff.createEvict(object.getStructuralObject().getId(),
evictedChildren);
}
- private Collection<ObjectDiff.Evict> createEvictedChildren(UIObjectImpl object)
+ private Collection<ObjectDiff.Evict> createEvictedChildren(InternalObjectContext
objectContext)
{
- InternalObjectContext objectContext = (InternalObjectContext)object.getContext();
-
- //
if (objectContext.childRefs != null)
{
Collection<ObjectDiff.Evict> evictedChildren = new
ArrayList<ObjectDiff.Evict>();
@@ -126,7 +117,7 @@
UIObjectImpl child =
(UIObjectImpl)context.getObject(removedChildRef.getId());
//
- evictedChildren.add(createEvict(child));
+
evictedChildren.add(createEvict((InternalObjectContext)child.getContext()));
}
}
@@ -141,9 +132,9 @@
}
}
- private ObjectDiff diff(UIObjectImpl object)
+ private ObjectDiff diff(InternalObjectContext object)
{
- ObjectTraversalType traversalType =
scope.enterObject(object.getContext().getStructuralObject());
+ ObjectTraversalType traversalType =
scope.enterObject(object.getStructuralObject());
//
try
@@ -165,7 +156,7 @@
Collection<ObjectDiff.Evict> removedObjects = new
ArrayList<ObjectDiff.Evict>();
//
- boolean createChildren =
((InternalObjectContext)object.getContext()).childRefs == null;
+ boolean createChildren = object.childRefs == null;
//
for (StructuralObject addedStructuralChild : refresh.getAddedChildren())
@@ -195,7 +186,7 @@
//
if (removedChild != null)
{
- ObjectDiff.Evict childVisit = createEvict(removedChild);
+ ObjectDiff.Evict childVisit =
createEvict((InternalObjectContext)removedChild.getContext());
removedObjects.add(childVisit);
}
else
@@ -207,7 +198,7 @@
//
return ObjectDiff.createRecursiveUpdate(
- object,
+ object.getStructuralObject().getId(),
refresh.getRemovedProperties(),
refresh.getUpdatedProperties(),
refresh.getAddedProperties(),
@@ -223,7 +214,7 @@
//
return ObjectDiff.createSingleUpdate(
- object,
+ object.getStructuralObject().getId(),
refresh.getRemovedProperties(),
refresh.getUpdatedProperties(),
refresh.getAddedProperties(),
@@ -233,15 +224,12 @@
}
finally
{
- scope.leaveObject(object.getContext().getStructuralObject());
+ scope.leaveObject(object.getStructuralObject());
}
}
private ObjectDiff load(StructuralObject structuralObject)
{
- UIObjectImpl object = UIObjectImpl.create(new
InternalObjectContext(navigationalStateContext, structuralObject));
-
- //
ObjectTraversalType traversalType = scope.enterObject(structuralObject);
//
@@ -249,7 +237,7 @@
{
if (traversalType == ObjectTraversalType.SKIP)
{
- return ObjectDiff.createSkip(object);
+ return ObjectDiff.createSkip(structuralObject.getId());
}
else
{
@@ -260,11 +248,11 @@
{
addedChildren.add(load(structuralChild));
}
- return ObjectDiff.createRecursiveLoad(object, addedChildren);
+ return ObjectDiff.createRecursiveLoad(structuralObject, addedChildren);
}
else
{
- return ObjectDiff.createSingleLoad(object);
+ return ObjectDiff.createSingleLoad(structuralObject);
}
}
}
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
16:37:56 UTC (rev 11321)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectDiff.java 2008-07-07
16:52:50 UTC (rev 11322)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.model;
-import org.jboss.portal.presentation.impl.model.ui.UIObjectImpl;
+import org.jboss.portal.presentation.state.structural.StructuralObject;
import java.util.Set;
import java.util.Map;
@@ -36,38 +36,38 @@
public abstract class ObjectDiff
{
- static ObjectDiff.Evict createEvict(UIObjectImpl object, Collection<Evict>
evictedChildren)
+ static ObjectDiff.Evict createEvict(String objectId, Collection<Evict>
evictedChildren)
{
- return new Evict(object, evictedChildren);
+ return new Evict(objectId, evictedChildren);
}
- static RecursiveLoad createRecursiveLoad(UIObjectImpl object,
Collection<ObjectDiff> addedChildren)
+ static RecursiveLoad createRecursiveLoad(StructuralObject object,
Collection<ObjectDiff> addedChildren)
{
return new RecursiveLoad(object, addedChildren);
}
- static ObjectDiff createSingleLoad(UIObjectImpl object)
+ static ObjectDiff createSingleLoad(StructuralObject object)
{
return new SingleLoad(object);
}
- static ObjectDiff createSkip(UIObjectImpl object)
+ static ObjectDiff createSkip(String objectId)
{
- return new Skip(object);
+ return new Skip(objectId);
}
static SingleUpdate createSingleUpdate(
- UIObjectImpl object,
+ String objectId,
Set<String> removedProperties,
Map<String, Serializable> updatedProperties,
Map<String, Serializable> addedProperties,
Collection<Evict> evictedChildren)
{
- return new SingleUpdate(object, removedProperties, updatedProperties,
addedProperties, evictedChildren);
+ return new SingleUpdate(objectId, removedProperties, updatedProperties,
addedProperties, evictedChildren);
}
static RecursiveUpdate createRecursiveUpdate(
- UIObjectImpl object,
+ String objectId,
Set<String> removedProperties,
Map<String, Serializable> updatedProperties,
Map<String, Serializable> addedProperties,
@@ -78,7 +78,7 @@
Collection<Evict> removedChildren)
{
return new RecursiveUpdate(
- object,
+ objectId,
removedProperties,
updatedProperties,
addedProperties,
@@ -90,54 +90,55 @@
}
/** . */
- private final UIObjectImpl object;
+ private final String objectId;
- private ObjectDiff(UIObjectImpl object)
+ private ObjectDiff(String objectId)
{
- if (object == null)
+ if (objectId == null)
{
throw new IllegalArgumentException();
}
//
- this.object = object;
+ this.objectId = objectId;
}
public String getObjectId()
{
- return object.getId();
+ return objectId;
}
- /**
- * Returns the object that either was created during the phase or is the same object
that
- * was retrieved from the viewport context.
- *
- * @return the object.
- */
- public UIObjectImpl getObject()
- {
- return object;
- }
-
public static class Skip extends ObjectDiff
{
- private Skip(UIObjectImpl object)
+ private Skip(String objectId)
{
- super(object);
+ super(objectId);
}
}
public abstract static class Load extends ObjectDiff
{
- private Load(UIObjectImpl object)
+
+ /** . */
+ private final StructuralObject object;
+
+ private Load(StructuralObject object)
{
- super(object);
+ super(object.getId());
+
+ //
+ this.object = object;
}
+
+ public StructuralObject getObject()
+ {
+ return object;
+ }
}
public static class SingleLoad extends Load
{
- private SingleLoad(UIObjectImpl object)
+ private SingleLoad(StructuralObject object)
{
super(object);
}
@@ -150,7 +151,7 @@
private final Collection<ObjectDiff> addedChildren;
private RecursiveLoad(
- UIObjectImpl object,
+ StructuralObject object,
Collection<ObjectDiff> addedChildren)
{
super(object);
@@ -199,7 +200,7 @@
private final Collection<Evict> removedChildren;
private RecursiveUpdate(
- UIObjectImpl object,
+ String objectId,
Set<String> removedProperties,
Map<String, Serializable> updatedProperties,
Map<String, Serializable> addedProperties,
@@ -210,7 +211,7 @@
Collection<Evict> removedChildren)
{
super(
- object,
+ objectId,
removedProperties,
updatedProperties,
addedProperties);
@@ -283,14 +284,14 @@
private final Collection<Evict> evictedChildren;
public SingleUpdate(
- UIObjectImpl object,
+ String objectId,
Set<String> removedProperties,
Map<String, Serializable> updatedProperties,
Map<String, Serializable> addedProperties,
Collection<Evict> evictedChildren)
{
super(
- object,
+ objectId,
removedProperties,
updatedProperties,
addedProperties);
@@ -325,12 +326,12 @@
private final Map<String, Serializable> addedProperties;
private Update(
- UIObjectImpl object,
+ String objectId,
Set<String> removedProperties,
Map<String, Serializable> updatedProperties,
Map<String, Serializable> addedProperties)
{
- super(object);
+ super(objectId);
//
this.removedProperties = removedProperties;
@@ -360,9 +361,9 @@
/** If null it means that we did not have any children initialized. */
private final Collection<Evict> evictedChildren;
- public Evict(UIObjectImpl object, Collection<Evict> evictedChildren)
+ public Evict(String objectId, Collection<Evict> evictedChildren)
{
- super(object);
+ super(objectId);
//
this.evictedChildren = evictedChildren;
Modified:
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 2008-07-07
16:37:56 UTC (rev 11321)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java 2008-07-07
16:52:50 UTC (rev 11322)
@@ -24,6 +24,7 @@
import org.jboss.portal.presentation.model.ViewPortContext;
import org.jboss.portal.presentation.impl.model.ui.UIObjectImpl;
+import org.jboss.portal.presentation.state.navigational.NavigationalStateContext;
import java.util.Collection;
import java.util.HashMap;
@@ -47,8 +48,15 @@
/** . */
private final ObjectDiff rootDiff;
- public UpdatePhase(ViewPortContext context, ObjectDiff rootDiff)
+ /** . */
+ private final NavigationalStateContext navigationalStateContext;
+
+ public UpdatePhase(
+ NavigationalStateContext navigationalStateContext,
+ ViewPortContext context,
+ ObjectDiff rootDiff)
{
+ this.navigationalStateContext = navigationalStateContext;
this.context = context;
this.rootDiff = rootDiff;
}
@@ -76,7 +84,7 @@
//
if (evict.getEvictedChildren() != null)
{
- perform1stPhase(diff.getObject(), evict.getEvictedChildren());
+ perform1stPhase(diff.getObjectId(), evict.getEvictedChildren());
//
context.destroyChildren(diff.getObjectId());
@@ -92,10 +100,10 @@
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());
+ perform1stPhase(diff.getObjectId(), recursiveUpdate.getAddedChildren());
+ perform1stPhase(diff.getObjectId(), recursiveUpdate.getStaleChildren());
+ perform1stPhase(diff.getObjectId(), recursiveUpdate.getValidChildren());
+ perform1stPhase(diff.getObjectId(), recursiveUpdate.getRemovedChildren());
}
else
{
@@ -104,7 +112,7 @@
//
if (singleUpdate.getEvictedChildren() != null)
{
- perform1stPhase(diff.getObject(), singleUpdate.getEvictedChildren());
+ perform1stPhase(diff.getObjectId(), singleUpdate.getEvictedChildren());
//
context.destroyChildren(diff.getObjectId());
@@ -113,7 +121,7 @@
}
}
- private void perform1stPhase(UIObjectImpl parent, Collection<? extends
ObjectDiff> diffs)
+ private void perform1stPhase(String parentId, Collection<? extends ObjectDiff>
diffs)
{
for (ObjectDiff diff : diffs)
{
@@ -122,10 +130,10 @@
String childId = diff.getObjectId();
//
- context.removeChild(parent.getId(), childId);
+ context.removeChild(parentId, childId);
//
- InternalObjectContext parentContext =
(InternalObjectContext)parent.getContext();
+ InternalObjectContext parentContext =
(InternalObjectContext)((UIObjectImpl)context.getObject(parentId)).getContext();
//
parentContext.childRefs.remove(childId);
@@ -146,26 +154,29 @@
private void perform2ndPhase(ObjectDiff diff)
{
- UIObjectImpl object = diff.getObject();
+ if (diff instanceof ObjectDiff.Load)
+ {
+ ObjectDiff.Load load = (ObjectDiff.Load)diff;
- //
- InternalObjectContext objectContext = (InternalObjectContext)object.getContext();
+ //
+ UIObjectImpl object = UIObjectImpl.create(new
InternalObjectContext(navigationalStateContext, load.getObject()));
- //
- if (diff instanceof ObjectDiff.Load)
- {
+ //
context.addObject(object);
//
if (diff instanceof ObjectDiff.RecursiveLoad)
{
+ InternalObjectContext objectContext =
(InternalObjectContext)object.getContext();
+
+ //
objectContext.childRefs = new HashMap<String, UIObjectRef>();
//
context.createChildren(object.getId());
//
- perform2ndPhase(diff.getObject(),
((ObjectDiff.RecursiveLoad)diff).getAddedChildren());
+ perform2ndPhase(objectContext,
((ObjectDiff.RecursiveLoad)diff).getAddedChildren());
}
}
else if (diff instanceof ObjectDiff.Update)
@@ -185,27 +196,27 @@
ObjectDiff.RecursiveUpdate recursiveUpdate =
(ObjectDiff.RecursiveUpdate)diff;
//
+ InternalObjectContext objectContext =
(InternalObjectContext)((UIObjectImpl)context.getObject(diff.getObjectId())).getContext();
+
+ //
if (recursiveUpdate.getCreateChildren())
{
objectContext.childRefs = new HashMap<String, UIObjectRef>();
//
- context.createChildren(object.getId());
+ context.createChildren(diff.getObjectId());
}
//
- perform2ndPhase(diff.getObject(), recursiveUpdate.getAddedChildren());
- perform2ndPhase(diff.getObject(), recursiveUpdate.getValidChildren());
- perform2ndPhase(diff.getObject(), recursiveUpdate.getStaleChildren());
+ perform2ndPhase(objectContext, recursiveUpdate.getAddedChildren());
+ perform2ndPhase(objectContext, recursiveUpdate.getValidChildren());
+ perform2ndPhase(objectContext, recursiveUpdate.getStaleChildren());
}
}
}
- private void perform2ndPhase(UIObjectImpl parent, Collection<ObjectDiff> diffs)
+ private void perform2ndPhase(InternalObjectContext parentContext,
Collection<ObjectDiff> diffs)
{
- InternalObjectContext objectContext = (InternalObjectContext)parent.getContext();
-
- //
for (ObjectDiff diff : diffs)
{
perform2ndPhase(diff);
@@ -213,8 +224,8 @@
//
if (diff instanceof ObjectDiff.Load)
{
- objectContext.childRefs.put(diff.getObjectId(), new
UIObjectRef(diff.getObjectId(), true));
- context.addChild(parent.getId(), diff.getObjectId());
+ parentContext.childRefs.put(diff.getObjectId(), new
UIObjectRef(diff.getObjectId(), true));
+ context.addChild(parentContext.getStructuralObject().getId(),
diff.getObjectId());
}
else if (diff instanceof ObjectDiff.Update)
{
@@ -222,7 +233,7 @@
}
else if (diff instanceof ObjectDiff.Skip)
{
- objectContext.childRefs.put(diff.getObjectId(), new
UIObjectRef(diff.getObjectId(), false));
+ parentContext.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
16:37:56 UTC (rev 11321)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java 2008-07-07
16:52:50 UTC (rev 11322)
@@ -51,7 +51,7 @@
public void refresh()
{
- DiffPhase diffPhase = new DiffPhase(context, scope, model.navigationalStateContext,
model.structuralStateContext);
+ DiffPhase diffPhase = new DiffPhase(context, scope, model.structuralStateContext);
//
diffPhase.perform();
@@ -60,7 +60,7 @@
ObjectDiff rootDiff = diffPhase.getRootVisit();
//
- UpdatePhase phase = new UpdatePhase(context, rootDiff);
+ UpdatePhase phase = new UpdatePhase(model.navigationalStateContext, context,
rootDiff);
//
phase.perform();