Author: julien(a)jboss.com
Date: 2008-03-28 15:49:52 -0400 (Fri, 28 Mar 2008)
New Revision: 10403
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/UIModelImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/UIObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/UIObjectRef.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/ViewPortImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/diff/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/diff/ChildrenVisit.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/diff/CreateDiffPhase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/diff/ObjectVisit.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/update/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/update/CreateUpdatePhase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/update/ObjectUpdate.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/AbstractModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/AddChildTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/CustomScope.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/ModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/MoveChildTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/NodeDef.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/RemoveChildTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/TraversalModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectNode.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectTree.java
Modified:
branches/presentation/presentation/build.xml
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ObjectTraversalType.java
Log:
a new implementation of refresh that handles object moves
Modified: branches/presentation/presentation/build.xml
===================================================================
--- branches/presentation/presentation/build.xml 2008-03-28 17:53:50 UTC (rev 10402)
+++ branches/presentation/presentation/build.xml 2008-03-28 19:49:52 UTC (rev 10403)
@@ -311,13 +311,22 @@
-->
</x-sysproperty>
<x-test>
- <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.MockModelTestCase"/>
- <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.ModelTestCase"/>
- <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.EventTestCase"/>
+ <!--<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.MockModelTestCase"/>-->
+ <!--<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.ModelTestCase"/>-->
+ <!--<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.EventTestCase"/>-->
+
+<!--
<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model2.ModelTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model2.AddChildTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model2.RemoveChildTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model2.MoveChildTestCase"/>
+-->
+
+ <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model3.ModelTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model3.AddChildTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model3.RemoveChildTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model3.MoveChildTestCase"/>
+
</x-test>
<x-classpath>
<path refid="jboss.portal/modules/common.classpath"/>
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/UIModelImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/UIModelImpl.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/UIModelImpl.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,70 @@
+/******************************************************************************
+ * 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.model2.refresh;
+
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
+import org.jboss.portal.presentation.model2.UIModel;
+import org.jboss.portal.presentation.model2.ViewPortContext;
+import org.jboss.portal.presentation.model2.ViewPortScope;
+import org.jboss.portal.presentation.model2.ViewPort;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UIModelImpl implements UIModel
+{
+
+ /** . */
+ final NavigationalStateContext navigationalStateContext;
+
+ /** . */
+ final StructuralStateContext structuralStateContext;
+
+ public UIModelImpl(NavigationalStateContext navigationalStateContext,
StructuralStateContext structuralStateContext)
+ {
+ this.navigationalStateContext = navigationalStateContext;
+ this.structuralStateContext = structuralStateContext;
+ }
+
+ public NavigationalStateContext getNavigationalStateContext()
+ {
+ return navigationalStateContext;
+ }
+
+ public StructuralStateContext getStructuralStateContext()
+ {
+ return structuralStateContext;
+ }
+
+ public String getRootId()
+ {
+ return structuralStateContext.getRootId();
+ }
+
+ public ViewPort createViewPort(ViewPortContext context, ViewPortScope scope)
+ {
+ return new ViewPortImpl(this, context, scope);
+ }
+}
\ No newline at end of file
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/UIObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/UIObjectImpl.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/UIObjectImpl.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,103 @@
+/******************************************************************************
+ * 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.model2.refresh;
+
+import org.jboss.portal.presentation.model2.UIObject;
+import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UIObjectImpl implements UIObject
+{
+
+ /** . */
+ public final StructuralObject structuralObject;
+
+ /** We keep track of what was loaded by the scope. */
+ public Map<String, UIObjectRef> childRefs;
+
+ public UIObjectImpl(StructuralObject structuralObject)
+ {
+ this.structuralObject = structuralObject;
+ }
+
+ public String getId()
+ {
+ return structuralObject.getId();
+ }
+
+ public String getName()
+ {
+ return structuralObject.getState().getName();
+ }
+
+ public <T> T getProperty(String propertyName, Class<T> propertyType)
throws IllegalArgumentException, StateException
+ {
+ return safeCast(getProperty(propertyName), propertyType);
+ }
+
+ public Object getProperty(String propertyName) throws IllegalArgumentException,
StateException
+ {
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ return structuralObject.getState().getProperties().get(propertyName);
+ }
+
+ /**
+ * Attempt to cast the value argument to the provided type argument. If the value
argument type is assignable
+ * to the provided type, the value is returned, otherwise if it is not or the value is
null, null is returned.
+ *
+ * @param value the value to cast
+ * @param type the type to downcast
+ * @return the casted value or null
+ */
+ private <T> T safeCast(Object value, Class<T> type)
+ {
+ if (type == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (value == null)
+ {
+ return null;
+ }
+ else
+ {
+ if (type.isAssignableFrom(value.getClass()))
+ {
+ return type.cast(value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+}
\ No newline at end of file
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/UIObjectRef.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/UIObjectRef.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/UIObjectRef.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * 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.model2.refresh;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UIObjectRef
+{
+
+ /** The child id. */
+ final String id;
+
+ /** Whether or not the child is loaded. */
+ public boolean loaded;
+
+ public UIObjectRef(String id, boolean loaded)
+ {
+ this.id = id;
+ this.loaded = loaded;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/ViewPortImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/ViewPortImpl.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/ViewPortImpl.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,88 @@
+/******************************************************************************
+ * 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.model2.refresh;
+
+import org.jboss.portal.presentation.model2.ViewPort;
+import org.jboss.portal.presentation.model2.ViewPortContext;
+import org.jboss.portal.presentation.model2.ViewPortScope;
+import org.jboss.portal.presentation.impl.model2.refresh.diff.CreateDiffPhase;
+import org.jboss.portal.presentation.impl.model2.refresh.diff.ObjectVisit;
+import org.jboss.portal.presentation.impl.model2.refresh.update.CreateUpdatePhase;
+import org.jboss.portal.presentation.impl.model2.refresh.update.ObjectUpdate;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ViewPortImpl implements ViewPort
+{
+
+ /** . */
+ final UIModelImpl model;
+
+ /** . */
+ final ViewPortContext context;
+
+ /** . */
+ final ViewPortScope scope;
+
+ public ViewPortImpl(UIModelImpl model, ViewPortContext context, ViewPortScope scope)
+ {
+ this.model = model;
+ this.context = context;
+ this.scope = scope;
+ }
+
+ public void refresh()
+ {
+ CreateDiffPhase createDiffPhase = new CreateDiffPhase(context, scope,
model.structuralStateContext);
+
+ //
+ createDiffPhase.perform();
+
+ //
+ ObjectVisit rootVisit = createDiffPhase.getRootVisit();
+
+ //
+ CreateUpdatePhase createUpdatePhase = new CreateUpdatePhase(context, rootVisit);
+
+ //
+ createUpdatePhase.perform();
+
+ //
+ ObjectUpdate rootUpdate = createUpdatePhase.getRootUpdate();
+
+ //
+ rootUpdate.execute(context);
+ }
+
+ public ViewPortContext getContext()
+ {
+ return context;
+ }
+
+ public ViewPortScope getScope()
+ {
+ return scope;
+ }
+}
\ No newline at end of file
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/diff/ChildrenVisit.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/diff/ChildrenVisit.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/diff/ChildrenVisit.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,70 @@
+/******************************************************************************
+ * 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.model2.refresh.diff;
+
+import java.util.Collection;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ChildrenVisit
+{
+
+ /** . */
+ final Collection<ObjectVisit> addedObjects = new
ArrayList<ObjectVisit>();
+
+ /** . */
+ final Collection<ObjectVisit> validObjects = new
ArrayList<ObjectVisit>();
+
+ /** . */
+ final Collection<ObjectVisit> staleObjects = new
ArrayList<ObjectVisit>();
+
+ /** . */
+ final Collection<String> removedObjects = new ArrayList<String>();
+
+ ChildrenVisit()
+ {
+ }
+
+ public Collection<ObjectVisit> getAddedObjects()
+ {
+ return addedObjects;
+ }
+
+ public Collection<String> getRemovedObjects()
+ {
+ return removedObjects;
+ }
+
+ public Collection<ObjectVisit> getValidObjects()
+ {
+ return validObjects;
+ }
+
+ public Collection<ObjectVisit> getStaleObjects()
+ {
+ return staleObjects;
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/diff/CreateDiffPhase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/diff/CreateDiffPhase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/diff/CreateDiffPhase.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,188 @@
+/******************************************************************************
+ * 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.model2.refresh.diff;
+
+import org.jboss.portal.presentation.model2.ViewPortScope;
+import org.jboss.portal.presentation.model2.ViewPortContext;
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+import org.jboss.portal.presentation.impl.model2.refresh.UIObjectImpl;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class CreateDiffPhase
+{
+
+ /** . */
+ private final ViewPortContext context;
+
+ /** . */
+ private final ViewPortScope scope;
+
+ /** . */
+ private final StructuralStateContext structuralStateContext;
+
+ /** . */
+ private ObjectVisit rootVisit;
+
+ public CreateDiffPhase(
+ ViewPortContext context,
+ ViewPortScope scope,
+ StructuralStateContext structuralStateContext)
+ {
+ this.context = context;
+ this.scope = scope;
+ this.structuralStateContext = structuralStateContext;
+ }
+
+ public void perform()
+ {
+ rootVisit = diff(scope.getRootId());
+ }
+
+ public ObjectVisit getRootVisit()
+ {
+ return rootVisit;
+ }
+
+ private ObjectVisit 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 ObjectVisit diff(UIObjectImpl object)
+ {
+ ObjectTraversalType traversalType = scope.enterObject(object);
+
+ //
+ try
+ {
+ switch (traversalType)
+ {
+ case SKIP:
+ return new ObjectVisit(object, false);
+ case SINGLE:
+ return new ObjectVisit(object, true);
+ case RECURSIVE:
+ StructuralObject.Refresh refresh =
structuralStateContext.refresh(object.structuralObject);
+ ChildrenVisit childrenVisit = new ChildrenVisit();
+
+ //
+ for (StructuralObject addedStructuralChild : refresh.getAddedChildren())
+ {
+ ObjectVisit childVisit = load(addedStructuralChild);
+ childrenVisit.addedObjects.add(childVisit);
+ }
+
+ //
+ for (StructuralObject staleStructuralChild :
refresh.getStaleChildren().values())
+ {
+ ObjectVisit childVisit = diff(staleStructuralChild.getId());
+ childrenVisit.staleObjects.add(childVisit);
+ }
+
+ //
+ for (String validChildId : refresh.getValidChildren())
+ {
+ ObjectVisit childVisit = diff(validChildId);
+ childrenVisit.validObjects.add(childVisit);
+ }
+
+ //
+ childrenVisit.removedObjects.addAll(refresh.getRemovedChildren());
+
+ //
+ return new ObjectVisit(object, childrenVisit);
+ default:
+ throw new AssertionError();
+ }
+ }
+ finally
+ {
+ scope.leaveObject(object);
+ }
+ }
+
+ private ObjectVisit load(StructuralObject structuralObject)
+ {
+ UIObjectImpl object = new UIObjectImpl(structuralObject);
+
+ //
+ ObjectTraversalType traversalType = scope.enterObject(object);
+
+ //
+ try
+ {
+ ObjectVisit visit;
+ switch (traversalType)
+ {
+ case SKIP:
+ visit = new ObjectVisit(object, false);
+ break;
+ case SINGLE:
+ visit = new ObjectVisit(object, true);
+ break;
+ case RECURSIVE:
+ ChildrenVisit 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 visit;
+ }
+ finally
+ {
+ scope.leaveObject(object);
+ }
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/diff/ObjectVisit.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/diff/ObjectVisit.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/diff/ObjectVisit.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,76 @@
+/******************************************************************************
+ * 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.model2.refresh.diff;
+
+import org.jboss.portal.presentation.impl.model2.refresh.UIObjectImpl;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ObjectVisit
+{
+
+ /** . */
+ private final UIObjectImpl object;
+
+ /** . */
+ private final boolean loaded;
+
+ /** . */
+ private final ChildrenVisit children;
+
+ ObjectVisit(UIObjectImpl object, ChildrenVisit children)
+ {
+ this.object = object;
+ this.loaded = true;
+ this.children = children;
+ }
+
+ ObjectVisit(UIObjectImpl object, boolean loaded)
+ {
+ this.object = object;
+ this.loaded = loaded;
+ this.children = null;
+ }
+
+ public String getObjectId()
+ {
+ return object.getId();
+ }
+
+ public UIObjectImpl getObject()
+ {
+ return object;
+ }
+
+ public boolean getLoaded()
+ {
+ return loaded;
+ }
+
+ public ChildrenVisit getChildrenVisit()
+ {
+ return children;
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/update/CreateUpdatePhase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/update/CreateUpdatePhase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/update/CreateUpdatePhase.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,304 @@
+/******************************************************************************
+ * 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.model2.refresh.update;
+
+import org.jboss.portal.presentation.model2.ViewPortContext;
+import org.jboss.portal.presentation.impl.model2.refresh.diff.ObjectVisit;
+import org.jboss.portal.presentation.impl.model2.refresh.diff.ChildrenVisit;
+import org.jboss.portal.presentation.impl.model2.refresh.UIObjectImpl;
+import org.jboss.portal.presentation.impl.model2.refresh.UIObjectRef;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class CreateUpdatePhase
+{
+
+ /** . */
+ private final ViewPortContext context;
+
+ /** . */
+ private ObjectVisit rootVisit;
+
+ /** . */
+ private ObjectUpdate rootUpdate;
+
+ /** . */
+ private Map<String, ObjectUpdate.AddChild> deferredAddChildUpdates;
+
+ /** . */
+ private Set<String> removedChildren;
+
+ public CreateUpdatePhase(ViewPortContext context, ObjectVisit rootVisit)
+ {
+ this.context = context;
+ this.rootVisit = rootVisit;
+ }
+
+ public ObjectUpdate getRootUpdate()
+ {
+ return rootUpdate;
+ }
+
+ public void perform()
+ {
+ deferredAddChildUpdates = new HashMap<String, ObjectUpdate.AddChild>();
+ removedChildren = new HashSet<String>();
+
+ //
+ rootUpdate = createUpdate(rootVisit);
+
+ //
+ if (deferredAddChildUpdates.size() > 0)
+ {
+ throw new IllegalStateException("Was expecting the deferred update to be
empty");
+ }
+ }
+
+ private ObjectUpdate createUpdate(ObjectVisit objectVisit)
+ {
+ UIObjectImpl object = (UIObjectImpl)context.getObject(objectVisit.getObjectId());
+
+ if (objectVisit.getLoaded())
+ {
+ ChildrenVisit childrenVisit = objectVisit.getChildrenVisit();
+
+ //
+ if (object != null)
+ {
+ if (object != objectVisit.getObject())
+ {
+ // The object is stale, we need to update the state maybe
+ }
+ }
+
+ //
+ if (childrenVisit != null)
+ {
+ 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 (ObjectVisit addedObjectVisit : childrenVisit.getAddedObjects())
+ {
+ ObjectUpdate childUpdate = createUpdate(addedObjectVisit);
+
+ //
+ if (childUpdate instanceof ObjectUpdate.AddObject)
+ {
+ addedChildrenUpdates.add(new
ObjectUpdate.AddChild(objectVisit.getObjectId(), (ObjectUpdate.AddObject)childUpdate));
+ childrenStatus.put(addedObjectVisit.getObjectId(), true);
+ }
+ else if (childUpdate == null)
+ {
+ childrenStatus.put(addedObjectVisit.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(
+ addedObjectVisit.getObject(),
+ updateChildUpdate.childrenStatus,
+ updateChildUpdate.addedChildrenUpdates,
+ updateChildUpdate.removedChildrenUpdates,
+ updateChildUpdate.updateChildrenUpdates);
+
+ //
+ ObjectUpdate.AddChild addChildUpdate = new
ObjectUpdate.AddChild(objectVisit.getObjectId(), addObjectUpdate);
+
+ //
+ if (removedChildren.contains(addedObjectVisit.getObjectId()))
+ {
+ addedChildrenUpdates.add(addChildUpdate);
+ }
+ else
+ {
+ deferredAddChildUpdates.put(addedObjectVisit.getObjectId(),
addChildUpdate);
+ }
+
+ //
+ childrenStatus.put(addedObjectVisit.getObjectId(), true);
+ }
+ else
+ {
+ throw new UnsupportedOperationException("Was not expecting update
of type " + childUpdate.getClass().getSimpleName());
+ }
+ }
+
+ //
+ for (String removeObjectId : childrenVisit.getRemovedObjects())
+ {
+ UIObjectImpl child = (UIObjectImpl)context.getObject(removeObjectId);
+ removedChildrenUpdates.add(new
ObjectUpdate.RemoveChild(objectVisit.getObjectId(), createRemove(child)));
+ }
+
+ List<ObjectVisit> existingObjectVisits = new
ArrayList<ObjectVisit>();
+ existingObjectVisits.addAll(childrenVisit.getValidObjects());
+ existingObjectVisits.addAll(childrenVisit.getStaleObjects());
+
+ //
+ for (ObjectVisit validObjectVisit : existingObjectVisits)
+ {
+ ObjectUpdate childUpdate = createUpdate(validObjectVisit);
+
+ //
+ if (childUpdate == null)
+ {
+ childrenStatus.put(validObjectVisit.getObjectId(), false);
+ }
+ else if (childUpdate instanceof ObjectUpdate.UpdateObject)
+ {
+ updateChildrenUpdates.add((ObjectUpdate.UpdateObject)childUpdate);
+ childrenStatus.put(validObjectVisit.getObjectId(), true);
+ }
+ else if (childUpdate instanceof ObjectUpdate.RemoveObject)
+ {
+ removedChildrenUpdates.add(new
ObjectUpdate.RemoveChild(objectVisit.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));
+ childrenStatus.put(validObjectVisit.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.getId(),
+ childrenStatus,
+ addedChildrenUpdates,
+ removedChildrenUpdates,
+ updateChildrenUpdates);
+ }
+ else
+ {
+ return new ObjectUpdate.AddObject(
+ objectVisit.getObject(),
+ childrenStatus,
+ addedChildrenUpdates,
+ removedChildrenUpdates,
+ updateChildrenUpdates);
+ }
+ }
+ else
+ {
+ if (object != null)
+ {
+ List<ObjectUpdate.RemoveChild> removedChildrenUpdates = new
ArrayList<ObjectUpdate.RemoveChild>();
+
+ //
+ if (object.childRefs != null)
+ {
+ for (UIObjectRef removedChildRef : object.childRefs.values())
+ {
+ if (removedChildRef.loaded)
+ {
+ UIObjectImpl child =
(UIObjectImpl)context.getObject(removedChildRef.getId());
+
+ //
+ removedChildrenUpdates.add(new
ObjectUpdate.RemoveChild(objectVisit.getObjectId(), createRemove(child)));
+ }
+ }
+ }
+
+ //
+ for (ObjectUpdate.RemoveChild removeChildUpdate : removedChildrenUpdates)
+ {
+ removedChildren.add(removeChildUpdate.removedObjectUpdate.objectId);
+ }
+
+ //
+ return new ObjectUpdate.UpdateObject(object.getId(),
removedChildrenUpdates);
+ }
+ else
+ {
+ return new ObjectUpdate.AddObject(objectVisit.getObject());
+ }
+ }
+ }
+ else
+ {
+ if (object != null)
+ {
+ return createRemove(object);
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+
+ private ObjectUpdate.RemoveObject createRemove(UIObjectImpl object)
+ {
+ List<ObjectUpdate.RemoveObject> removedChildrenUpdates = new
ArrayList<ObjectUpdate.RemoveObject>();
+
+ //
+ if (object.childRefs != null)
+ {
+ for (UIObjectRef removedChildRef : object.childRefs.values())
+ {
+ if (removedChildRef.loaded)
+ {
+ UIObjectImpl removedChild =
(UIObjectImpl)context.getObject(removedChildRef.getId());
+
+ //
+ removedChildrenUpdates.add(createRemove(removedChild));
+ }
+ }
+ }
+
+ //
+ ObjectUpdate.AddChild addChildUpdate =
deferredAddChildUpdates.remove(object.getId());
+
+ //
+ return new ObjectUpdate.RemoveObject(object.getId(), removedChildrenUpdates,
addChildUpdate);
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/update/ObjectUpdate.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/update/ObjectUpdate.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/refresh/update/ObjectUpdate.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,352 @@
+/******************************************************************************
+ * 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.model2.refresh.update;
+
+import org.jboss.portal.presentation.impl.model2.refresh.UIObjectImpl;
+import org.jboss.portal.presentation.impl.model2.refresh.UIObjectRef;
+import org.jboss.portal.presentation.model2.ViewPortContext;
+
+import java.util.List;
+import java.util.HashMap;
+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 String objectId;
+
+ /** . */
+ final Map<String, Boolean> childrenStatus;
+
+ /** . */
+ final List<AddChild> addedChildrenUpdates;
+
+ /** . */
+ final List<RemoveChild> removedChildrenUpdates;
+
+ /** . */
+ final List<UpdateObject> updateChildrenUpdates;
+
+ public UpdateObject(String objectId, List<RemoveChild>
removeChildrenUpdates)
+ {
+ if (objectId == null)
+ {
+ throw new IllegalArgumentException("No null object id accepted");
+ }
+ if (removeChildrenUpdates == null)
+ {
+ throw new IllegalArgumentException("No null removed children
accepted");
+ }
+
+ //
+ this.objectId = objectId;
+ this.childrenStatus = null;
+ this.addedChildrenUpdates = null;
+ this.removedChildrenUpdates = removeChildrenUpdates;
+ this.updateChildrenUpdates = null;
+ }
+
+ public UpdateObject(
+ String objectId,
+ Map<String, Boolean> childrenStatus,
+ List<AddChild> addedChildrenUpdates,
+ List<RemoveChild> removedChildrenUpdates,
+ List<UpdateObject> updateChildrenUpdates)
+ {
+ if (objectId == 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.objectId = objectId;
+ this.childrenStatus = childrenStatus;
+ this.addedChildrenUpdates = addedChildrenUpdates;
+ this.removedChildrenUpdates = removedChildrenUpdates;
+ this.updateChildrenUpdates = updateChildrenUpdates;
+ }
+
+ public void execute(ViewPortContext context)
+ {
+ UIObjectImpl object = (UIObjectImpl)context.getObject(objectId);
+
+ // 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);
+ }
+
+ //
+ if (childrenStatus != null)
+ {
+ if (object.childRefs == null)
+ {
+ object.childRefs = new HashMap<String, UIObjectRef>();
+ for (Map.Entry<String, Boolean> childRefEntry :
childrenStatus.entrySet())
+ {
+ object.childRefs.put(childRefEntry.getKey(), new
UIObjectRef(childRefEntry.getKey(), childRefEntry.getValue()));
+ }
+
+ //
+ context.createChildren(objectId);
+ }
+
+ //
+ for (AddChild addedChildUpdate : addedChildrenUpdates)
+ {
+ addedChildUpdate.execute(context);
+ }
+
+ //
+ for (UpdateObject updateChildUpdate : updateChildrenUpdates)
+ {
+ updateChildUpdate.execute(context);
+ }
+ }
+ else
+ {
+ if (object.childRefs != null)
+ {
+ context.destroyChildren(objectId);
+ }
+ }
+ }
+ }
+
+ 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)
+ {
+ object.childRefs = new HashMap<String, UIObjectRef>();
+ for (Map.Entry<String, Boolean> childRefEntry :
childrenStatus.entrySet())
+ {
+ object.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);
+ }
+ }
+}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java 2008-03-28
17:53:50 UTC (rev 10402)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -37,6 +37,9 @@
StructuralState getState();
+ /**
+ * todo : replace by equals probably.
+ */
boolean compareTo(StructuralObject other);
/**
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ObjectTraversalType.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ObjectTraversalType.java 2008-03-28
17:53:50 UTC (rev 10402)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ObjectTraversalType.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -32,18 +32,18 @@
{
/**
- * The object should not be visited.
+ * The object should be visited and its children.
*/
- SKIP,
+ RECURSIVE,
/**
* The object should be visited but not its children.
*/
SINGLE,
+
/**
- * The object should be visited and its children.
+ * The object should not be visited.
*/
- RECURSIVE
-
+ SKIP
}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/AbstractModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/AbstractModelTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/AbstractModelTestCase.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * 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.test.model3;
+
+import org.jboss.portal.presentation.model2.UIModel;
+import org.jboss.portal.presentation.test.model.state.structural.MockModel;
+import org.jboss.portal.presentation.test.model.state.structural.MockModelImpl;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.impl.model2.refresh.UIModelImpl;
+import
org.jboss.portal.presentation.impl.model.state.navigational.NavigationalStateContextImpl;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class AbstractModelTestCase extends TestCase
+{
+
+ /** . */
+ protected UIModel model;
+
+ /** . */
+ protected MockModel mockModel;
+
+ /** . */
+ protected StructuralStateContext structuralStateContext;
+
+ protected void setUp() throws Exception
+ {
+ mockModel = new MockModelImpl();
+ structuralStateContext = mockModel.getStructuralStateContext();
+ model = new UIModelImpl(new NavigationalStateContextImpl(),
structuralStateContext);
+ }
+}
\ No newline at end of file
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/AddChildTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/AddChildTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/AddChildTestCase.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,71 @@
+/******************************************************************************
+ * 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.test.model3;
+
+import org.jboss.portal.presentation.model2.ViewPortScope;
+import org.jboss.portal.presentation.model2.ViewPort;
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+import org.jboss.portal.presentation.test.model.state.structural.MockObject;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class AddChildTestCase extends TraversalModelTestCase
+{
+
+ public void testAddChild()
+ {
+ test(1, null);
+ }
+
+ protected void test(ObjectTraversalType[] before, ObjectTraversalType[] after, Object
handback)
+ {
+ NodeDef rootDef = NodeDef.create();
+ NodeDef fooDef = rootDef.addChild("foo");
+ fooDef.setTraversal(before[0]);
+
+ //
+ rootDef.populate(mockModel);
+
+ //
+ ViewPortScope scope = new CustomScope(model, rootDef);
+ UIObjectTree context = new UIObjectTree();
+ ViewPort viewPort = model.createViewPort(context, scope);
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ context.assertConsistency(model.getRootId());
+
+ //
+ mockModel.getRoot().getChild("foo").addChild("juu",
MockObject.Type.PORTAL);
+ fooDef.addChild("juu");
+ fooDef.setTraversal(after[0]);
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ context.assertConsistency(model.getRootId());
+ }
+}
\ No newline at end of file
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/CustomScope.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/CustomScope.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/CustomScope.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,99 @@
+/******************************************************************************
+ * 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.test.model3;
+
+import org.jboss.portal.presentation.model2.ViewPortScope;
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+import org.jboss.portal.presentation.model2.UIObject;
+import org.jboss.portal.presentation.model2.UIModel;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class CustomScope implements ViewPortScope
+{
+
+ /** . */
+ private final UIModel model;
+
+ /** . */
+ private final NodeDef root;
+
+ /** . */
+ private NodeDef current;
+
+ public CustomScope(UIModel model, NodeDef root)
+ {
+ if (root == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.model = model;
+ this.root = root;
+ this.current = null;
+ }
+
+ public String getRootId()
+ {
+ return model.getRootId();
+ }
+
+ public ObjectTraversalType enterObject(UIObject object)
+ {
+ if (current == null)
+ {
+ // It must be the root
+ if (!model.getRootId().equals(object.getId()))
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ current = root;
+ }
+ else
+ {
+ NodeDef child = current.getChild(object.getName());
+
+ //
+ if (child == null)
+ {
+ throw new IllegalStateException("No such child " +
object.getName());
+ }
+
+ //
+ current = child;
+ }
+
+ //
+ return current.getTraversal();
+ }
+
+ public void leaveObject(UIObject object)
+ {
+ current = current.getParent();
+ }
+}
\ No newline at end of file
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/ModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/ModelTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/ModelTestCase.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,84 @@
+/******************************************************************************
+ * 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.test.model3;
+
+import org.jboss.portal.presentation.model2.ViewPortScope;
+import org.jboss.portal.presentation.model2.ViewPort;
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ModelTestCase extends TraversalModelTestCase
+{
+
+ public void testRefresh1() throws Exception
+ {
+ test(4, null);
+ }
+
+ protected void test(ObjectTraversalType[] before, ObjectTraversalType[] after, Object
handback)
+ {
+ NodeDef rootDef = NodeDef.create();
+ NodeDef fooDef = rootDef.addChild("foo");
+ NodeDef barDef = rootDef.addChild("bar");
+ NodeDef juuDef = fooDef.addChild("juu");
+ NodeDef daaDef = fooDef.addChild("daa");
+
+ //
+ fooDef.setTraversal(before[0]);
+ barDef.setTraversal(before[1]);
+ juuDef.setTraversal(before[2]);
+ daaDef.setTraversal(before[3]);
+
+ //
+ rootDef.populate(mockModel);
+
+ //
+ ViewPortScope scope = new CustomScope(model, rootDef);
+ UIObjectTree context = new UIObjectTree();
+ ViewPort viewPort = model.createViewPort(context, scope);
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ context.assertConsistency(model.getRootId());
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ context.assertConsistency(model.getRootId());
+
+ //
+ fooDef.setTraversal(after[0]);
+ barDef.setTraversal(after[1]);
+ juuDef.setTraversal(after[2]);
+ daaDef.setTraversal(after[3]);
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ context.assertConsistency(model.getRootId());
+ }
+}
\ No newline at end of file
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/MoveChildTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/MoveChildTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/MoveChildTestCase.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,155 @@
+/******************************************************************************
+ * 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.test.model3;
+
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+import org.jboss.portal.presentation.model2.ViewPortScope;
+import org.jboss.portal.presentation.model2.ViewPort;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class MoveChildTestCase extends TraversalModelTestCase
+{
+
+ public void testMoveChild1()
+ {
+ test(0, new Runnable()
+ {
+ public void run()
+ {
+ NodeDef rootDef = NodeDef.create();
+ NodeDef fooDef = rootDef.addChild("foo");
+ NodeDef juuDef = fooDef.addChild("juu");
+ NodeDef barDef = rootDef.addChild("bar");
+
+ //
+ rootDef.populate(mockModel);
+
+ //
+ ViewPortScope scope = new CustomScope(model, rootDef);
+ UIObjectTree context = new UIObjectTree();
+ ViewPort viewPort = model.createViewPort(context, scope);
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ context.assertConsistency(model.getRootId());
+
+ //
+
mockModel.getRoot().getChild("foo").getChild("juu").move(mockModel.getRoot().getChild("bar"));
+ fooDef.removeChild("juu");
+ barDef.addChild("juu");
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ context.assertConsistency(model.getRootId());
+ }
+ });
+ }
+
+ public void testMoveChild2()
+ {
+ test(0, new Runnable()
+ {
+ public void run()
+ {
+ NodeDef rootDef = NodeDef.create();
+ NodeDef fooDef = rootDef.addChild("foo");
+ NodeDef barDef = rootDef.addChild("bar");
+ NodeDef juuDef = barDef.addChild("juu");
+
+ //
+ rootDef.populate(mockModel);
+
+ //
+ ViewPortScope scope = new CustomScope(model, rootDef);
+ UIObjectTree context = new UIObjectTree();
+ ViewPort viewPort = model.createViewPort(context, scope);
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ context.assertConsistency(model.getRootId());
+
+ //
+
mockModel.getRoot().getChild("bar").getChild("juu").move(mockModel.getRoot().getChild("foo"));
+ barDef.removeChild("juu");
+ fooDef.addChild("juu");
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ context.assertConsistency(model.getRootId());
+ }
+ });
+ }
+
+ public void testMoveChild3()
+ {
+ test(0, new Runnable()
+ {
+ public void run()
+ {
+ NodeDef rootDef = NodeDef.create();
+ NodeDef fooDef = rootDef.addChild("foo");
+ NodeDef juuDef = fooDef.addChild("juu");
+ NodeDef barDef = rootDef.addChild("bar");
+ NodeDef daaDef = barDef.addChild("daa");
+
+ //
+ rootDef.populate(mockModel);
+
+ //
+ ViewPortScope scope = new CustomScope(model, rootDef);
+ UIObjectTree context = new UIObjectTree();
+ ViewPort viewPort = model.createViewPort(context, scope);
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ context.assertConsistency(model.getRootId());
+
+ //
+
mockModel.getRoot().getChild("foo").getChild("juu").move(mockModel.getRoot().getChild("bar"));
+
mockModel.getRoot().getChild("bar").getChild("daa").move(mockModel.getRoot().getChild("foo"));
+ fooDef.removeChild("juu");
+ barDef.addChild("juu");
+ barDef.removeChild("daa");
+ fooDef.addChild("daa");
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ context.assertConsistency(model.getRootId());
+ }
+ });
+ }
+
+ protected void test(ObjectTraversalType[] before, ObjectTraversalType[] after, Object
handback)
+ {
+ ((Runnable)handback).run();
+ }
+}
\ No newline at end of file
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/NodeDef.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/NodeDef.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/NodeDef.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,174 @@
+/******************************************************************************
+ * 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.test.model3;
+
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+import org.jboss.portal.presentation.test.model.state.structural.MockObject;
+import org.jboss.portal.presentation.test.model.state.structural.MockModel;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+
+import junit.framework.Assert;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class NodeDef
+{
+
+ public static NodeDef create()
+ {
+ return new NodeDef("");
+ }
+
+ /** . */
+ private final String name;
+
+ /** . */
+ private final Map<String, NodeDef> children;
+
+ /** . */
+ private ObjectTraversalType traversal;
+
+ /** . */
+ private NodeDef parent;
+
+ private NodeDef(String name)
+ {
+ this.name = name;
+ this.children = new HashMap<String, NodeDef>();
+ this.traversal = ObjectTraversalType.RECURSIVE;
+ this.parent = null;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public NodeDef getChild(String name)
+ {
+ return children.get(name);
+ }
+
+ public NodeDef getParent()
+ {
+ return parent;
+ }
+
+ public ObjectTraversalType getTraversal()
+ {
+ return traversal;
+ }
+
+ public void setTraversal(ObjectTraversalType traversal)
+ {
+ this.traversal = traversal;
+ }
+
+ public NodeDef addChild(String name)
+ {
+ if (children.containsKey(name))
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ NodeDef child = new NodeDef(name);
+
+ //
+ children.put(name, child);
+ child.parent = this;
+
+ //
+ return child;
+ }
+
+ public void removeChild(String name)
+ {
+ NodeDef child = children.remove(name);
+
+ //
+ if (child == null)
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ child.parent = null;
+ }
+
+ public void populate(MockModel model)
+ {
+ populate(model.getRoot());
+ }
+
+ public void populate(MockObject object)
+ {
+ for (Map.Entry<String, NodeDef> childNodeEntry : children.entrySet())
+ {
+ MockObject child = object.addChild(childNodeEntry.getKey(),
MockObject.Type.PORTAL);
+ childNodeEntry.getValue().populate(child);
+ }
+ }
+
+ public void assertEquals(UIObjectNode objectNode)
+ {
+ Assert.assertEquals(name, objectNode.getObject().getName());
+
+ //
+ switch (traversal)
+ {
+ case SKIP:
+ Assert.fail();
+ break;
+ case SINGLE:
+ Assert.assertNull(objectNode.getChildren());
+ break;
+ case RECURSIVE:
+ Set<String> expectedChildrenNames = new HashSet<String>();
+ for (Map.Entry<String, NodeDef> entry : children.entrySet())
+ {
+ if (entry.getValue().getTraversal() != ObjectTraversalType.SKIP)
+ {
+ expectedChildrenNames.add(entry.getKey());
+ }
+ }
+
+ //
+ Assert.assertEquals(expectedChildrenNames,
objectNode.getChildren().keySet());
+
+ //
+ for (UIObjectNode childObjectNode : objectNode.getChildren().values())
+ {
+ NodeDef child = children.get(childObjectNode.getObject().getName());
+ child.assertEquals(childObjectNode);
+ }
+ break;
+ }
+ }
+}
\ No newline at end of file
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/RemoveChildTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/RemoveChildTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/RemoveChildTestCase.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,69 @@
+/******************************************************************************
+ * 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.test.model3;
+
+import org.jboss.portal.presentation.model2.ViewPortScope;
+import org.jboss.portal.presentation.model2.ViewPort;
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class RemoveChildTestCase extends TraversalModelTestCase
+{
+
+ public void testRemoveChild()
+ {
+ test(1, null);
+ }
+
+ protected void test(ObjectTraversalType[] before, ObjectTraversalType[] after, Object
handback)
+ {
+ NodeDef rootDef = NodeDef.create();
+ NodeDef fooDef = rootDef.addChild("foo");
+ NodeDef barDef = fooDef.addChild("bar");
+ NodeDef juuDef = fooDef.addChild("juu");
+
+ //
+ rootDef.populate(mockModel);
+
+ //
+ ViewPortScope scope = new CustomScope(model, rootDef);
+ UIObjectTree context = new UIObjectTree();
+ ViewPort viewPort = model.createViewPort(context, scope);
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+
+ //
+
mockModel.destroy(mockModel.getRoot().getChild("foo").getChild("juu"));
+ fooDef.removeChild("juu");
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ context.assertConsistency(model.getRootId());
+ }
+}
\ No newline at end of file
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/TraversalModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/TraversalModelTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/TraversalModelTestCase.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,128 @@
+/******************************************************************************
+ * 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.test.model3;
+
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+import org.jboss.portal.presentation.model2.UIModel;
+import org.jboss.portal.presentation.test.model.state.structural.MockModel;
+import org.jboss.portal.presentation.test.model.state.structural.MockModelImpl;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.impl.model2.refresh.UIModelImpl;
+import
org.jboss.portal.presentation.impl.model.state.navigational.NavigationalStateContextImpl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class TraversalModelTestCase extends TestCase
+{
+
+ /** . */
+ protected UIModel model;
+
+ /** . */
+ protected MockModel mockModel;
+
+ /** . */
+ protected StructuralStateContext structuralStateContext;
+
+ public void test(int size, Object handback)
+ {
+ ObjectTraversalType[] before = new ObjectTraversalType[size];
+ ObjectTraversalType[] after = new ObjectTraversalType[size];
+ Collection<ObjectTraversalType[]> enumeration = generate(before.length +
after.length);
+
+ //
+ for (ObjectTraversalType[] element : enumeration)
+ {
+ mockModel = new MockModelImpl();
+ structuralStateContext = mockModel.getStructuralStateContext();
+ model = new UIModelImpl(new NavigationalStateContextImpl(),
structuralStateContext);
+
+ //
+ Assert.assertEquals(before.length + after.length, element.length);
+ System.arraycopy(element, 0, before, 0, before.length);
+ System.arraycopy(element, before.length, after, 0, after.length);
+ boolean failed = true;
+ try
+ {
+ test(before, after, handback);
+ failed = false;
+ }
+ finally
+ {
+ if (failed)
+ {
+ System.out.println("Arrays.asList(before) = " +
Arrays.asList(before));
+ System.out.println("Arrays.asList(after) = " +
Arrays.asList(after));
+ }
+
+ //
+ mockModel = null;
+ structuralStateContext = null;
+ model = null;
+ }
+ }
+ }
+
+ protected abstract void test(ObjectTraversalType[] before, ObjectTraversalType[]
after, Object handback);
+
+ public static Collection<ObjectTraversalType[]> generate(int size)
+ {
+ if (size == 0)
+ {
+ return Collections.singleton(new ObjectTraversalType[0]);
+ }
+ else
+ {
+ Collection<ObjectTraversalType[]> enumeration = generate(size - 1);
+
+ //
+ ArrayList<ObjectTraversalType[]> augmentedEnumeration = new
ArrayList<ObjectTraversalType[]>(enumeration.size() * 3);
+
+ //
+ for (ObjectTraversalType type : ObjectTraversalType.values())
+ {
+ for (ObjectTraversalType[] element : enumeration)
+ {
+ ObjectTraversalType[] augmentedElement = new ObjectTraversalType[1 +
element.length];
+ System.arraycopy(element, 0, augmentedElement, 1, element.length);
+ augmentedElement[0] = type;
+ augmentedEnumeration.add(augmentedElement);
+ }
+ }
+
+ //
+ return augmentedEnumeration;
+ }
+ }
+
+}
\ No newline at end of file
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectNode.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectNode.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectNode.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,125 @@
+/******************************************************************************
+ * 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.test.model3;
+
+import org.jboss.portal.presentation.model2.UIObject;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UIObjectNode
+{
+
+ /** . */
+ private final UIObject object;
+
+ /** . */
+ private Map<String, UIObjectNode> children;
+
+ public UIObjectNode(UIObject object)
+ {
+ if (object == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.object = object;
+ }
+
+ public UIObject getObject()
+ {
+ return object;
+ }
+
+ public Map<String, UIObjectNode> getChildren()
+ {
+ return children;
+ }
+
+ public void addChild(UIObjectNode child)
+ {
+ if (children == null)
+ {
+ throw new IllegalStateException("Children not initialized");
+ }
+
+ //
+ String key = child.getObject().getName();
+
+ //
+ if (children.containsKey(key))
+ {
+ throw new IllegalStateException("Duplicate name " + key + " among
" + children.keySet());
+ }
+
+ //
+ children.put(key, child);
+ }
+
+ public void removeChild(UIObjectNode child)
+ {
+ if (children == null)
+ {
+ throw new IllegalStateException("Children not initialized");
+ }
+
+ //
+ String key = child.getObject().getName();
+
+ //
+ if (!children.containsKey(key))
+ {
+ throw new IllegalStateException("No such child with name " + key +
" among " + children.keySet());
+ }
+
+ //
+ children.remove(key);
+ }
+
+ public void createChildren()
+ {
+ if (children != null)
+ {
+ throw new IllegalStateException("Children already initialized");
+ }
+
+ //
+ children = new HashMap<String, UIObjectNode>();
+ }
+
+ public void destroyChildren()
+ {
+ if (children == null)
+ {
+ throw new IllegalStateException("Children never initialized");
+ }
+
+ //
+ children = null;
+ }
+}
\ No newline at end of file
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectTree.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectTree.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model3/UIObjectTree.java 2008-03-28
19:49:52 UTC (rev 10403)
@@ -0,0 +1,163 @@
+/******************************************************************************
+ * 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.test.model3;
+
+import org.jboss.portal.presentation.model2.ViewPortContext;
+import org.jboss.portal.presentation.model2.UIObject;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.HashSet;
+
+import junit.framework.Assert;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UIObjectTree implements ViewPortContext
+{
+
+ /** . */
+ private final Map<String, UIObjectNode> nodes = new HashMap<String,
UIObjectNode>();
+
+ public void assertConsistency(String rootId)
+ {
+ UIObjectNode root = nodes.get(rootId);
+ Assert.assertNotNull(root);
+ ArrayList<String> allIds = new ArrayList<String>();
+ collect(root, allIds);
+ Assert.assertEquals(new HashSet<String>(allIds).size(), allIds.size());
+ Assert.assertEquals(new HashSet<String>(allIds), nodes.keySet());
+ }
+
+ private void collect(UIObjectNode node, ArrayList<String> ids)
+ {
+ ids.add(node.getObject().getId());
+ if (node.getChildren() != null)
+ {
+ for (UIObjectNode child : node.getChildren().values())
+ {
+ collect(child, ids);
+ }
+ }
+ }
+
+ public UIObjectNode getNode(String objectId)
+ {
+ return nodes.get(objectId);
+ }
+
+ public UIObject getObject(String objectId)
+ {
+ UIObjectNode node = nodes.get(objectId);
+
+ //
+ return node != null ? node.getObject() : null;
+ }
+
+ public void removeObject(String objectId)
+ {
+ if (nodes.remove(objectId) == null)
+ {
+ throw new IllegalStateException("No such object " + objectId);
+ }
+ }
+
+ public void addObject(UIObject object)
+ {
+ String id = object.getId();
+
+ //
+ if (nodes.containsKey(id))
+ {
+ throw new IllegalStateException("Object with id " + id + " is
already loaded");
+ }
+
+ //
+ nodes.put(id, new UIObjectNode(object));
+ }
+
+ public void addChild(String parentId, String childId)
+ {
+ UIObjectNode parent = nodes.get(parentId);
+ if (parent == null)
+ {
+ throw new IllegalStateException("No such object " + parentId);
+ }
+
+ //
+ UIObjectNode child = nodes.get(childId);
+ if (child == null)
+ {
+ throw new IllegalStateException("No such object " + childId);
+ }
+
+ //
+ parent.addChild(child);
+ }
+
+ public void removeChild(String parentId, String childId)
+ {
+ UIObjectNode parent = nodes.get(parentId);
+ if (parent == null)
+ {
+ throw new IllegalStateException("No such object " + parentId);
+ }
+
+ //
+ UIObjectNode child = nodes.get(childId);
+ if (child == null)
+ {
+ throw new IllegalStateException("No such object " + childId);
+ }
+
+ //
+ parent.removeChild(child);
+ }
+
+ public void createChildren(String parentId)
+ {
+ UIObjectNode parent = nodes.get(parentId);
+ if (parent == null)
+ {
+ throw new IllegalStateException("No such object " + parentId);
+ }
+
+ //
+ parent.createChildren();
+ }
+
+ public void destroyChildren(String parentId)
+ {
+ UIObjectNode parent =nodes.get(parentId);
+ if (parent == null)
+ {
+ throw new IllegalStateException("No such object " + parentId);
+ }
+
+ //
+ parent.destroyChildren();
+ }
+}
\ No newline at end of file