Author: julien(a)jboss.com
Date: 2008-03-26 17:30:57 -0400 (Wed, 26 Mar 2008)
New Revision: 10381
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/Refresh.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/UIModelImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/UIObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/ViewPortImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ObjectTraversalType.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/UIModel.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPort.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPortContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPortScope.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/AbstractModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/AddChildTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/CustomScope.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/FullScope.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/ModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/NodeDef.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectNode.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/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/test/ajax/JBossUnitSandBox.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockException.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
Log:
initial commit for the model refactor based on the viewport concept
Modified: branches/presentation/presentation/build.xml
===================================================================
--- branches/presentation/presentation/build.xml 2008-03-26 21:25:30 UTC (rev 10380)
+++ branches/presentation/presentation/build.xml 2008-03-26 21:30:57 UTC (rev 10381)
@@ -305,15 +305,17 @@
<execute-tests>
<x-sysproperty>
<sysproperty key="test.root"
value="${build.lib}"/>
- <!--
+<!--
<jvmarg value="-Xdebug"/>
<jvmarg
value="-Xrunjdwp:transport=dt_socket,address=7878,server=y,suspend=y"/>
- -->
+-->
</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.model2.ModelTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model2.AddChildTestCase"/>
</x-test>
<x-classpath>
<path refid="jboss.portal/modules/common.classpath"/>
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/Refresh.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/Refresh.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/Refresh.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -0,0 +1,358 @@
+/******************************************************************************
+ * 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;
+
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.model2.ViewPortContext;
+import org.jboss.portal.presentation.model2.ViewPortScope;
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collection;
+import java.util.ArrayList;
+
+/**
+ * A refresh operation.
+ *
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+class Refresh
+{
+
+ /** . */
+ private final ViewPortContext context;
+
+ /** . */
+ private final ViewPortScope scope;
+
+ /** . */
+ private final StructuralStateContext structuralStateContext;
+
+ /** The objects removed during the refresh operation. */
+ private final Map<String, UIObjectImpl> removedObjects;
+
+
+ Refresh(ViewPortImpl viewPort)
+ {
+ this.context = viewPort.context;
+ this.scope = viewPort.scope;
+ this.structuralStateContext = viewPort.model.structuralStateContext;
+ this.removedObjects = new HashMap<String, UIObjectImpl>();
+ }
+
+ void perform()
+ {
+ String rootId = scope.getRootId();
+
+ //
+ refresh(rootId);
+ }
+
+ private boolean refresh(String objectId)
+ {
+ UIObjectImpl object = (UIObjectImpl)context.getObject(objectId);
+
+ //
+ if (object != null)
+ {
+ return refresh(object);
+ }
+ else
+ {
+ StructuralObject structuralObject = structuralStateContext.load(objectId);
+
+ // It is not present, load it
+ return load(structuralObject);
+ }
+ }
+
+ private boolean refresh(StructuralObject structuralObject)
+ {
+
+ UIObjectImpl object = (UIObjectImpl)context.getObject(structuralObject.getId());
+
+ if (object == null)
+ {
+ return load(structuralObject);
+ }
+ else
+ {
+ // Update state
+
+ //
+ return refresh(object);
+ }
+ }
+
+ private boolean refresh(UIObjectImpl object)
+ {
+ ObjectTraversalType traversalType = scope.enterObject(object);
+
+ //
+ try
+ {
+ if (traversalType == ObjectTraversalType.SKIP)
+ {
+ evict(object);
+
+ //
+ return false;
+ }
+ else if (traversalType == ObjectTraversalType.SINGLE)
+ {
+ if (object.childrenRefs != null)
+ {
+ // Need to evict children if any
+ for (UIObjectImpl.ChildRef childRef : object.childrenRefs.values())
+ {
+ if (childRef.loaded)
+ {
+ UIObjectImpl childObject =
(UIObjectImpl)context.getObject(childRef.id);
+
+ //
+ context.removeChild(object.getId(), childObject.getId());
+
+ //
+ evict(childObject);
+ }
+ }
+
+ //
+ context.destroyChildren(object.getId());
+ }
+
+ //
+ return true;
+ }
+ else
+ {
+ boolean hadChildren = object.childrenRefs != null;
+ String objectId = object.structuralObject.getId();
+
+ //
+ if (!hadChildren)
+ {
+ object.childrenRefs = new HashMap<String, UIObjectImpl.ChildRef>();
+ context.initChildren(objectId);
+ }
+
+ //
+ StructuralObject.Refresh refresh =
structuralStateContext.refresh(object.structuralObject);
+
+ //
+ for (Map.Entry<String, StructuralObject> childEntry :
refresh.getStaleChildren().entrySet())
+ {
+ StructuralObject structuralChild = childEntry.getValue();
+ String childId = structuralChild.getId();
+
+ // Is it the same object with a new state or is it a new child with the
same name ?
+ if (childEntry.getKey().equals(childId))
+ {
+ boolean loaded = refresh(childEntry.getValue());
+
+ //
+ if (hadChildren)
+ {
+ UIObjectImpl.ChildRef childRef = object.childrenRefs.get(childId);
+
+ //
+ childRef.loaded = loaded;
+
+ //
+ if (!loaded)
+ {
+ throw new UnsupportedOperationException("todo");
+ }
+ }
+ else
+ {
+ object.childrenRefs.put(childId, new UIObjectImpl.ChildRef(childId,
loaded));
+
+ //
+ if (loaded)
+ {
+ context.addChild(objectId, structuralChild.getId());
+ }
+ }
+ }
+ else
+ {
+ throw new UnsupportedOperationException("todo");
+ }
+ }
+
+ //
+ for (StructuralObject structuralChild : refresh.getAddedChildren())
+ {
+ boolean loaded = load(structuralChild);
+
+ //
+ object.childrenRefs.put(structuralChild.getId(), new
UIObjectImpl.ChildRef(structuralChild.getId(), loaded));
+
+ //
+ if (loaded)
+ {
+ context.addChild(objectId, structuralChild.getId());
+ }
+ }
+
+ //
+ for (String childId : refresh.getRemovedChildren())
+ {
+ throw new UnsupportedOperationException("todo");
+ }
+
+ //
+ for (String childId : refresh.getValidChildren())
+ {
+ boolean loaded = refresh(childId);
+
+ //
+ if (hadChildren)
+ {
+ UIObjectImpl.ChildRef childRef = object.childrenRefs.get(childId);
+
+ //
+ if (childRef.loaded)
+ {
+ if (!loaded)
+ {
+ childRef.loaded = false;
+ context.removeChild(objectId, childId);
+ }
+ }
+ else
+ {
+ if (loaded)
+ {
+ childRef.loaded = true;
+ context.addChild(objectId, childId);
+ }
+ }
+ }
+ else
+ {
+ object.childrenRefs.put(childId, new UIObjectImpl.ChildRef(childId,
loaded));
+
+ //
+ if (loaded)
+ {
+ context.addChild(objectId, childId);
+ }
+ }
+ }
+
+ //
+ return true;
+ }
+ }
+ finally
+ {
+ scope.leaveObject(object);
+ }
+ }
+
+ private void evict(UIObjectImpl object)
+ {
+ if (object.childrenRefs != null)
+ {
+ for (UIObjectImpl.ChildRef childRef : new
ArrayList<UIObjectImpl.ChildRef>(object.childrenRefs.values()))
+ {
+ if (childRef.loaded)
+ {
+ UIObjectImpl child = (UIObjectImpl)context.getObject(childRef.id);
+
+ //
+ evict(child);
+
+ //
+ context.removeChild(object.structuralObject.getId(),
child.structuralObject.getId());
+ context.removeObject(child.structuralObject.getId());
+ }
+ }
+
+ //
+ context.destroyChildren(object.structuralObject.getId());
+ }
+ }
+
+ private boolean load(StructuralObject structuralObject)
+ {
+ UIObjectImpl object = new UIObjectImpl(structuralObject);
+
+ //
+ ObjectTraversalType tmp = scope.enterObject(object);
+
+ //
+ try
+ {
+ if (tmp == ObjectTraversalType.SKIP)
+ {
+ return false;
+ }
+
+ //
+ context.addObject(object);
+
+ //
+ if (tmp == ObjectTraversalType.RECURSIVE)
+ {
+ Collection<StructuralObject> structuralChildren =
structuralStateContext.loadChildren(object.structuralObject);
+
+ //
+ Map<String, UIObjectImpl.ChildRef> childrenRefs = new
HashMap<String, UIObjectImpl.ChildRef>(structuralChildren.size());
+
+ //
+ context.initChildren(structuralObject.getId());
+
+ //
+ for (StructuralObject structuralChild : structuralChildren)
+ {
+ boolean loaded = load(structuralChild);
+
+ //
+ childrenRefs.put(structuralChild.getId(), new
UIObjectImpl.ChildRef(structuralChild.getId(), loaded));
+
+ //
+ if (loaded)
+ {
+ context.addChild(structuralObject.getId(), structuralChild.getId());
+ }
+ }
+
+ // Update
+ object.childrenRefs = childrenRefs;
+ }
+
+ //
+ return true;
+ }
+ finally
+ {
+ scope.leaveObject(object);
+ }
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/UIModelImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/UIModelImpl.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/UIModelImpl.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -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;
+
+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);
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/UIObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/UIObjectImpl.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/UIObjectImpl.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -0,0 +1,124 @@
+/******************************************************************************
+ * 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;
+
+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.ArrayList;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UIObjectImpl implements UIObject
+{
+
+ /** . */
+ final StructuralObject structuralObject;
+
+ /** We keep track of what was loaded by the scope. */
+ Map<String, ChildRef> childrenRefs;
+
+ 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;
+ }
+ }
+ }
+
+ /**
+ * A reference to a child.
+ */
+ static class ChildRef
+ {
+
+ /** The child id. */
+ final String id;
+
+ /** Whether or not the child is loaded. */
+ boolean loaded;
+
+ ChildRef(String id, boolean loaded)
+ {
+ this.id = id;
+ this.loaded = loaded;
+ }
+ }
+
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/ViewPortImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/ViewPortImpl.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/ViewPortImpl.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -0,0 +1,66 @@
+/******************************************************************************
+ * 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;
+
+import org.jboss.portal.presentation.model2.ViewPort;
+import org.jboss.portal.presentation.model2.ViewPortContext;
+import org.jboss.portal.presentation.model2.ViewPortScope;
+
+/**
+ * @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()
+ {
+ new Refresh(this).perform();
+ }
+
+ public ViewPortContext getContext()
+ {
+ return context;
+ }
+
+ public ViewPortScope getScope()
+ {
+ return scope;
+ }
+}
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-26
21:25:30 UTC (rev 10380)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -51,19 +51,16 @@
/** . */
private final StructuralObject object;
- /** . */
+ /** The children that were added. */
private final Set<StructuralObject> addedChildren;
- /** . */
+ /** The children that were removed. */
private final Set<String> removedChildren;
- /** . */
-// private final Set<String> destroyedChildren;
-
- /** . */
+ /** The children with a stale property state. */
private final Map<String, StructuralObject> staleChildren;
- /** . */
+ /** The children that are valid. */
private final Set<String> validChildren;
public Refresh(
@@ -72,8 +69,7 @@
Set<StructuralObject> addedChildren,
Set<String> removedChildren,
Map<String, StructuralObject> staleChildren,
- Set<String> validChildren/*,
- Set<String> destroyedChildren*/)
+ Set<String> validChildren)
{
if (addedChildren == null)
{
@@ -91,17 +87,12 @@
{
throw new IllegalArgumentException();
}
-// if (destroyedChildren == null)
-// {
-// throw new IllegalArgumentException();
-// }
this.parent = parent;
this.object = object;
this.addedChildren = addedChildren;
this.validChildren = validChildren;
this.staleChildren = staleChildren;
this.removedChildren = removedChildren;
-// this.destroyedChildren = destroyedChildren;
}
public StructuralObject getParent()
@@ -114,11 +105,6 @@
return object;
}
-// public Set<String> getDestroyedChildren()
-// {
-// return destroyedChildren;
-// }
-
public Set<StructuralObject> getAddedChildren()
{
return addedChildren;
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ObjectTraversalType.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ObjectTraversalType.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ObjectTraversalType.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * 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.model2;
+
+/**
+ * A type that describe the different ways to traverse an object.
+ *
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public enum ObjectTraversalType
+{
+
+ /**
+ * The object should not be visited.
+ */
+ SKIP,
+
+ /**
+ * The object should be visited but not its children.
+ */
+ SINGLE,
+
+ /**
+ * The object should be visited and its children.
+ */
+ RECURSIVE
+
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/UIModel.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/UIModel.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/UIModel.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * 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.model2;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface UIModel
+{
+
+ String getRootId();
+
+ ViewPort createViewPort(ViewPortContext context, ViewPortScope scope);
+
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/UIObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/UIObject.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/UIObject.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -0,0 +1,58 @@
+/******************************************************************************
+ * 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.model2;
+
+import org.jboss.portal.presentation.model.state.StateException;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface UIObject
+{
+
+ /**
+ * Returns the id.
+ *
+ * @return the id
+ */
+ String getId();
+
+ /**
+ * Returns the name.
+ *
+ * @return the name
+ */
+ String getName();
+
+ /**
+ * Returns a property value or null if it does not exist.
+ *
+ * @param propertyName the property name
+ * @param propertyType the expected property type
+ * @return the property value
+ * @throws IllegalArgumentException if any argument is null or not valid
+ * @throws org.jboss.portal.presentation.model.state.StateException any state
exception
+ */
+ <T> T getProperty(String propertyName, Class<T> propertyType) throws
IllegalArgumentException, StateException;
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPort.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPort.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPort.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -0,0 +1,51 @@
+/******************************************************************************
+ * 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.model2;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface ViewPort
+{
+
+ /**
+ * Performs a refresh operation.
+ */
+ void refresh();
+
+ /**
+ * Returns the context associated with this viewport.
+ *
+ * @return the context
+ */
+ ViewPortContext getContext();
+
+ /**
+ * Returns the scope associated with this viewport.
+ *
+ * @return the scope
+ */
+ ViewPortScope getScope();
+
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPortContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPortContext.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPortContext.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -0,0 +1,46 @@
+/******************************************************************************
+ * 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.model2;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface ViewPortContext
+{
+
+ UIObject getObject(String objectId);
+
+ void removeObject(String objectId);
+
+ void addObject(UIObject object);
+
+ void initChildren(String parentId);
+
+ void destroyChildren(String parentId);
+
+ void addChild(String parentId, String childId);
+
+ void removeChild(String parentId, String childId);
+
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPortScope.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPortScope.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model2/ViewPortScope.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -0,0 +1,52 @@
+/******************************************************************************
+ * 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.model2;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface ViewPortScope
+{
+ /**
+ * Returns the id of the root of the scope.
+ *
+ * @return the root id
+ */
+ String getRootId();
+
+ /**
+ * Returns how the object should be traversed.
+ *
+ * @param object the object
+ * @return true if it should be visited
+ */
+ ObjectTraversalType enterObject(UIObject object);
+
+ /**
+ * Callback to signal that an object visit is terminated
+ *
+ * @param object the object
+ */
+ void leaveObject(UIObject object);
+}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/ajax/JBossUnitSandBox.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/ajax/JBossUnitSandBox.java 2008-03-26
21:25:30 UTC (rev 10380)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/ajax/JBossUnitSandBox.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -22,8 +22,8 @@
******************************************************************************/
package org.jboss.portal.presentation.test.ajax;
-import org.jboss.unit.api.pojo.annotations.Test;
-import static org.jboss.unit.api.Assert.*;
+//import org.jboss.unit.api.pojo.annotations.Test;
+//import static org.jboss.unit.api.Assert.*;
/**
@@ -32,9 +32,9 @@
*/
public class JBossUnitSandBox
{
- @Test
+// @Test
public void test()
{
- fail("Simple JBossUnit Test in the PresentationFramework successfully
executed....");
+// fail("Simple JBossUnit Test in the PresentationFramework successfully
executed....");
}
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockException.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockException.java 2008-03-26
21:25:30 UTC (rev 10380)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockException.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -26,7 +26,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-public class MockException extends Exception
+public class MockException extends RuntimeException
{
/** . */
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java 2008-03-26
21:25:30 UTC (rev 10380)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -119,6 +119,8 @@
MockObject getParent();
List<? extends MockObject> getChildren();
+
+ MockObject getChild(String name);
boolean isValid();
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2008-03-26
21:25:30 UTC (rev 10380)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -118,6 +118,30 @@
return Collections.unmodifiableList(new
ArrayList<MockObjectImpl>(children.values()));
}
+ public MockObjectImpl getChild(String name)
+ {
+ if (!valid)
+ {
+ throw new MockException(MockException.ErrorCode.INVALID_OBJECT);
+ }
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ for (MockObjectImpl child : children.values())
+ {
+ if (child.name.equals(name))
+ {
+ return child;
+ }
+ }
+
+ //
+ return null;
+ }
+
public MockObjectImpl addChild(String name, MockObject.Type type) throws
MockException
{
return addChild(name, type, EMPTY_STATE);
@@ -138,7 +162,7 @@
{
throw new IllegalArgumentException();
}
- if (children.containsKey(name))
+ if (getChild(name) != null)
{
throw new MockException(MockException.ErrorCode.CONSTRAINT_VIOLATION);
}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/AbstractModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/AbstractModelTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/AbstractModelTestCase.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -0,0 +1,107 @@
+/******************************************************************************
+ * 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.model2;
+
+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.test.model.state.structural.MockObject;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.impl.model2.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);
+ }
+
+ protected abstract static class Population
+ {
+
+ /** . */
+ protected final MockObject root;
+
+ protected Population(MockObject root)
+ {
+ this.root = root;
+ }
+
+ protected Population(MockModel model)
+ {
+ this(model.getRoot());
+ }
+
+ protected abstract void populate();
+
+ protected abstract void check(UIObjectNode root);
+ }
+
+ protected static class Population1 extends Population
+ {
+
+ protected Population1(MockObject root)
+ {
+ super(root);
+ }
+
+ protected Population1(MockModel model)
+ {
+ super(model);
+ }
+
+ protected void populate()
+ {
+ MockObject foo = root.addChild("foo", MockObject.Type.PORTAL);
+ MockObject bar = root.addChild("bar", MockObject.Type.PORTAL);
+ foo.addChild("juu", MockObject.Type.PAGE);
+ foo.addChild("daa", MockObject.Type.PAGE);
+ }
+
+ protected void check(UIObjectNode root)
+ {
+ UIObjectNode foo = root.getChildren().get("foo");
+ UIObjectNode bar = root.getChildren().get("bar");
+ assertNotNull(foo);
+ assertNotNull(bar);
+ }
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/AddChildTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/AddChildTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/AddChildTestCase.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -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.test.model2;
+
+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 AbstractModelTestCase
+{
+
+ private class Test
+ {
+
+ /** . */
+ private ObjectTraversalType traversal1;
+
+ /** . */
+ private ObjectTraversalType traversal2;
+
+ private Test(
+ ObjectTraversalType traversal1,
+ ObjectTraversalType traversal2)
+ {
+ this.traversal1 = traversal1;
+ this.traversal2 = traversal2;
+ }
+
+ public void test()
+ {
+ NodeDef rootDef = NodeDef.create();
+ NodeDef fooDef = rootDef.addChild("foo");
+ fooDef.setTraversal(traversal1);
+
+ //
+ 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.getRoot().getChild("foo").addChild("juu",
MockObject.Type.PORTAL);
+ fooDef.addChild("juu");
+ fooDef.setTraversal(traversal2);
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ }
+
+ }
+
+ public void test1()
+ {
+ new Test(ObjectTraversalType.RECURSIVE, ObjectTraversalType.RECURSIVE).test();
+ }
+
+ public void test2()
+ {
+ new Test(ObjectTraversalType.RECURSIVE, ObjectTraversalType.SINGLE).test();
+ }
+
+ public void test3()
+ {
+ new Test(ObjectTraversalType.SINGLE, ObjectTraversalType.RECURSIVE).test();
+ }
+
+ public void test4()
+ {
+ new Test(ObjectTraversalType.SINGLE, ObjectTraversalType.SINGLE).test();
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/CustomScope.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/CustomScope.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/CustomScope.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -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.model2;
+
+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();
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/FullScope.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/FullScope.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/FullScope.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -0,0 +1,57 @@
+/******************************************************************************
+ * 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.model2;
+
+import org.jboss.portal.presentation.model2.ViewPortScope;
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+import org.jboss.portal.presentation.model2.UIObject;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class FullScope implements ViewPortScope
+{
+
+ /** . */
+ private final String rootId;
+
+ public FullScope(String rootId)
+ {
+ this.rootId = rootId;
+ }
+
+ public String getRootId()
+ {
+ return rootId;
+ }
+
+ public ObjectTraversalType enterObject(UIObject object)
+ {
+ return ObjectTraversalType.RECURSIVE;
+ }
+
+ public void leaveObject(UIObject object)
+ {
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/ModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/ModelTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/ModelTestCase.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -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.model2;
+
+import org.jboss.portal.presentation.model2.ViewPortScope;
+import org.jboss.portal.presentation.model2.ViewPort;
+import org.jboss.portal.presentation.model2.ObjectTraversalType;
+
+import java.util.Collection;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+
+import junit.framework.TestCase;
+import junit.framework.Assert;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ModelTestCase extends TestCase
+{
+
+ private class Test extends AbstractModelTestCase
+ {
+
+ /** . */
+ private ObjectTraversalType[] traversal1;
+
+ /** . */
+ private ObjectTraversalType[] traversal2;
+
+ private Test(ObjectTraversalType[] traversal1, ObjectTraversalType[] traversal2)
+ {
+ this.traversal1 = traversal1;
+ this.traversal2 = traversal2;
+ }
+
+ public void test()
+ {
+ 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(traversal1[0]);
+ barDef.setTraversal(traversal1[1]);
+ juuDef.setTraversal(traversal1[2]);
+ daaDef.setTraversal(traversal1[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()));
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+
+ //
+ fooDef.setTraversal(traversal2[0]);
+ barDef.setTraversal(traversal2[1]);
+ juuDef.setTraversal(traversal2[2]);
+ daaDef.setTraversal(traversal2[3]);
+
+ //
+ viewPort.refresh();
+ rootDef.assertEquals(context.getNode(model.getRootId()));
+ }
+ }
+
+ public void testRefresh1() throws Exception
+ {
+ ObjectTraversalType[] traversal1 = new ObjectTraversalType[4];
+ ObjectTraversalType[] traversal2 = new ObjectTraversalType[4];
+ Collection<ObjectTraversalType[]> enumeration = generate(traversal1.length +
traversal2.length);
+/*
+ Collection<ObjectTraversalType[]> enumeration = Collections.singletonList(
+ new ObjectTraversalType[]{
+ ObjectTraversalType.SKIP,
+ ObjectTraversalType.SKIP,
+ ObjectTraversalType.SKIP,
+ ObjectTraversalType.SKIP,
+ ObjectTraversalType.SKIP,
+ ObjectTraversalType.SINGLE,
+ ObjectTraversalType.SKIP,
+ ObjectTraversalType.SKIP,
+ }
+ );
+*/
+ for (ObjectTraversalType[] element : enumeration)
+ {
+ Assert.assertEquals(traversal1.length + traversal2.length, element.length);
+ System.arraycopy(element, 0, traversal1, 0, traversal1.length);
+ System.arraycopy(element, traversal1.length, traversal2, 0, traversal2.length);
+ Test test = new Test(traversal1, traversal2);
+ test.setUp();
+ boolean failed = true;
+ try
+ {
+ test.test();
+ failed = false;
+ }
+ finally
+ {
+ if (failed)
+ {
+ System.out.println("Arrays.asList(traversal1) = " +
Arrays.asList(traversal1));
+ System.out.println("Arrays.asList(traversal2) = " +
Arrays.asList(traversal2));
+ }
+ }
+ }
+
+ }
+
+ private 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;
+ }
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/NodeDef.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/NodeDef.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/NodeDef.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -0,0 +1,160 @@
+/******************************************************************************
+ * 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.model2;
+
+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 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;
+ }
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectNode.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectNode.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectNode.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -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.model2;
+
+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 createrChildren()
+ {
+ 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;
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectTree.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectTree.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectTree.java 2008-03-26
21:30:57 UTC (rev 10381)
@@ -0,0 +1,89 @@
+/******************************************************************************
+ * 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.model2;
+
+import org.jboss.portal.presentation.model2.ViewPortContext;
+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 UIObjectTree implements ViewPortContext
+{
+
+ /** . */
+ private final Map<String, UIObjectNode> nodes = new HashMap<String,
UIObjectNode>();
+
+ 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)
+ {
+ nodes.remove(objectId);
+ }
+
+ public void addObject(UIObject object)
+ {
+ nodes.put(object.getId(), new UIObjectNode(object));
+ }
+
+ public void addChild(String parentId, String childId)
+ {
+ UIObjectNode parent = nodes.get(parentId);
+ UIObjectNode child = nodes.get(childId);
+ parent.addChild(child);
+ }
+
+ public void removeChild(String parentId, String childId)
+ {
+ UIObjectNode parent = nodes.get(parentId);
+ UIObjectNode child = nodes.get(childId);
+ parent.removeChild(child);
+ }
+
+ public void initChildren(String parentId)
+ {
+ UIObjectNode parent =nodes.get(parentId);
+ parent.createrChildren();
+ }
+
+ public void destroyChildren(String parentId)
+ {
+ UIObjectNode parent =nodes.get(parentId);
+ parent.destroyChildren();
+ }
+}