Author: julien(a)jboss.com
Date: 2008-07-07 08:26:25 -0400 (Mon, 07 Jul 2008)
New Revision: 11311
Added:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/DiffPhase.java
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java
Log:
simple renaming of CreateDiffPhase to DiffPhase
Copied:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/DiffPhase.java
(from rev 11310,
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/DiffPhase.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/DiffPhase.java 2008-07-07
12:26:25 UTC (rev 11311)
@@ -0,0 +1,276 @@
+/******************************************************************************
+ * 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.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;
+
+import java.util.Collection;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class DiffPhase
+{
+
+ /** . */
+ private final ViewPortContext context;
+
+ /** . */
+ private final ViewPortScope scope;
+
+ /** . */
+ private final NavigationalStateContext navigationalStateContext;
+
+ /** . */
+ private final StructuralStateContext structuralStateContext;
+
+ /** . */
+ private ObjectDiff rootDiff;
+
+ public DiffPhase(
+ ViewPortContext context,
+ ViewPortScope scope,
+ NavigationalStateContext navigationalStateContext,
+ StructuralStateContext structuralStateContext)
+ {
+ this.context = context;
+ this.scope = scope;
+ this.navigationalStateContext = navigationalStateContext;
+ this.structuralStateContext = structuralStateContext;
+ }
+
+ public void perform()
+ {
+ rootDiff = diff(scope.getRootId());
+ }
+
+ public ObjectDiff getRootVisit()
+ {
+ return rootDiff;
+ }
+
+ private ObjectDiff diff(String objectId)
+ {
+ UIObjectImpl object = (UIObjectImpl)context.getObject(objectId);
+
+ //
+ if (object == null)
+ {
+ StructuralObject structuralObject = structuralStateContext.load(objectId);
+
+ //
+ if (structuralObject == null)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ //
+ return load(structuralObject);
+ }
+ else
+ {
+ return diff(object);
+ }
+ }
+
+ private ObjectDiff.Evict createEvict(UIObjectImpl object)
+ {
+ Collection<ObjectDiff.Evict> evictedChildren =
createEvictedChildren(object);
+
+ //
+ return ObjectDiff.createEvict(object, evictedChildren);
+ }
+
+ private Collection<ObjectDiff.Evict> createEvictedChildren(UIObjectImpl object)
+ {
+ 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)
+ {
+ UIObjectImpl child =
(UIObjectImpl)context.getObject(removedChildRef.getId());
+
+ //
+ evictedChildren.add(createEvict(child));
+ }
+ }
+
+ //
+ 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)
+ {
+ ObjectTraversalType traversalType = scope.enterObject(object);
+
+ //
+ try
+ {
+ if (traversalType == ObjectTraversalType.SKIP)
+ {
+ return createEvict(object);
+ }
+ else
+ {
+ StructuralObject.Refresh refresh =
structuralStateContext.refresh(object.getStructuralObject());
+
+ //
+ if (traversalType == ObjectTraversalType.RECURSIVE)
+ {
+ Collection<ObjectDiff> addedObjects = new
ArrayList<ObjectDiff>();
+ Collection<ObjectDiff> validObjects = new
ArrayList<ObjectDiff>();
+ Collection<ObjectDiff> staleObjects = 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));
+ }
+
+ //
+ for (StructuralObject staleStructuralChild :
refresh.getStaleChildren().values())
+ {
+ ObjectDiff childDiff = diff(staleStructuralChild.getId());
+ staleObjects.add(childDiff);
+ }
+
+ //
+ for (String validChildId : refresh.getValidChildren())
+ {
+ ObjectDiff childDiff = diff(validChildId);
+ validObjects.add(childDiff);
+ }
+
+ //
+ for (String removedChildId : refresh.getRemovedChildren())
+ {
+ UIObjectImpl removedChild =
(UIObjectImpl)context.getObject(removedChildId);
+
+ //
+ if (removedChild != null)
+ {
+ ObjectDiff.Evict childVisit = createEvict(removedChild);
+ removedObjects.add(childVisit);
+ }
+ else
+ {
+ // It means that the child was not loaded previously and it has
+ // been removed in the current refresh, so we do nothing
+ }
+ }
+
+ //
+ return ObjectDiff.createRecursiveUpdate(
+ object,
+ refresh.getRemovedProperties(),
+ refresh.getUpdatedProperties(),
+ refresh.getAddedProperties(),
+ createChildren,
+ addedObjects,
+ validObjects,
+ staleObjects,
+ removedObjects);
+ }
+ else
+ {
+ Collection<ObjectDiff.Evict> evictedChildren =
createEvictedChildren(object);
+
+ //
+ return ObjectDiff.createSingleUpdate(
+ object,
+ refresh.getRemovedProperties(),
+ refresh.getUpdatedProperties(),
+ refresh.getAddedProperties(),
+ evictedChildren);
+ }
+ }
+ }
+ finally
+ {
+ scope.leaveObject(object);
+ }
+ }
+
+ private ObjectDiff load(StructuralObject structuralObject)
+ {
+ UIObjectImpl object = UIObjectImpl.create(structuralObject, new
InternalObjectContext(navigationalStateContext));
+
+ //
+ ObjectTraversalType traversalType = scope.enterObject(object);
+
+ //
+ try
+ {
+ if (traversalType == ObjectTraversalType.SKIP)
+ {
+ return ObjectDiff.createSkip(object);
+ }
+ else
+ {
+ if (traversalType == ObjectTraversalType.RECURSIVE)
+ {
+ Collection<ObjectDiff> addedChildren = new
ArrayList<ObjectDiff>();
+ for (StructuralObject structuralChild :
structuralStateContext.loadChildren(structuralObject))
+ {
+ addedChildren.add(load(structuralChild));
+ }
+ return ObjectDiff.createRecursiveLoad(object, addedChildren);
+ }
+ else
+ {
+ return ObjectDiff.createSingleLoad(object);
+ }
+ }
+ }
+ finally
+ {
+ scope.leaveObject(object);
+ }
+ }
+}
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
12:25:32 UTC (rev 11310)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java 2008-07-07
12:26:25 UTC (rev 11311)
@@ -51,14 +51,15 @@
public void refresh()
{
- CreateDiffPhase createDiffPhase = new CreateDiffPhase(context, scope,
model.navigationalStateContext, model.structuralStateContext);
+ DiffPhase diffPhase = new DiffPhase(context, scope, model.navigationalStateContext,
model.structuralStateContext);
//
- createDiffPhase.perform();
+ diffPhase.perform();
//
- ObjectDiff rootDiff = createDiffPhase.getRootVisit();
+ ObjectDiff rootDiff = diffPhase.getRootVisit();
+ //
UpdatePhase phase = new UpdatePhase(context, rootDiff);
//