Author: julien(a)jboss.com
Date: 2008-03-28 15:54:35 -0400 (Fri, 28 Mar 2008)
New Revision: 10404
Removed:
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/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/MoveChildTestCase.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/RemoveChildTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/TraversalModelTestCase.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
Log:
removed previous flawed impl
Deleted:
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 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/Refresh.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,406 +0,0 @@
-/******************************************************************************
- * 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 enum Action
- {
- NO_OP, WANT_REMOVE, WANT_ADD
- }
-
- /** . */
- 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 Status 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) ? Status.LOADED : Status.NOT_LOADED;
- }
- }
-
- private Status refresh(StructuralObject structuralObject)
- {
-
- UIObjectImpl object = (UIObjectImpl)context.getObject(structuralObject.getId());
-
- if (object == null)
- {
- return load(structuralObject) ? Status.LOADED : Status.NOT_LOADED;
- }
- else
- {
- // Update state
-
- //
- return refresh(object);
- }
- }
-
- private enum Status
- {
- LOADED,
- NOT_LOADED,
- WANT_EVICT
- }
-
- private Status refresh(UIObjectImpl object)
- {
- ObjectTraversalType traversalType = scope.enterObject(object);
-
- //
- try
- {
- if (traversalType == ObjectTraversalType.SKIP)
- {
- return Status.WANT_EVICT;
- }
- 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 Status.LOADED;
- }
- else
- {
- boolean hadChildren = object.childrenRefs != null;
- String objectId = object.structuralObject.getId();
-
- //
- if (!hadChildren)
- {
- object.childrenRefs = new HashMap<String, UIObjectImpl.ChildRef>();
- context.createChildren(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))
- {
- Status status = refresh(childEntry.getValue());
-
- switch (status)
- {
- case LOADED:
- if (hadChildren)
- {
- UIObjectImpl.ChildRef childRef =
object.childrenRefs.get(childId);
- if (!childRef.loaded)
- {
- childRef.loaded = true;
- context.addChild(objectId, childId);
- }
- }
- else
- {
- object.childrenRefs.put(childId, new
UIObjectImpl.ChildRef(childId, true));
- context.addChild(objectId, structuralChild.getId());
- }
- break;
- case NOT_LOADED:
- if (hadChildren)
- {
- UIObjectImpl.ChildRef childRef =
object.childrenRefs.get(childId);
- if (childRef.loaded)
- {
- childRef.loaded = false;
- context.removeChild(objectId, childId);
- }
- }
- else
- {
- object.childrenRefs.put(childId, new
UIObjectImpl.ChildRef(childId, false));
- }
- break;
- case WANT_EVICT:
- if (hadChildren)
- {
- UIObjectImpl.ChildRef childRef =
object.childrenRefs.get(childId);
- if (childRef.loaded)
- {
- context.removeChild(objectId, childId);
- childRef.loaded = false;
- UIObjectImpl child =
(UIObjectImpl)context.getObject(childId);
- evict(child);
- }
- }
- break;
- }
- }
- 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())
- {
- if (hadChildren)
- {
- object.childrenRefs.remove(childId);
- context.removeChild(objectId, childId);
- UIObjectImpl removedChild = (UIObjectImpl)context.getObject(childId);
- evict(removedChild);
- }
- }
-
- //
- for (String childId : refresh.getValidChildren())
- {
- Status status = refresh(childId);
-
- switch (status)
- {
- case LOADED:
- if (hadChildren)
- {
- UIObjectImpl.ChildRef childRef =
object.childrenRefs.get(childId);
- if (!childRef.loaded)
- {
- childRef.loaded = true;
- context.addChild(objectId, childId);
- }
- }
- else
- {
- object.childrenRefs.put(childId, new
UIObjectImpl.ChildRef(childId, true));
- context.addChild(objectId, childId);
- }
- break;
- case NOT_LOADED:
- if (hadChildren)
- {
- UIObjectImpl.ChildRef childRef =
object.childrenRefs.get(childId);
- if (childRef.loaded)
- {
- childRef.loaded = false;
- context.removeChild(objectId, childId);
- }
- }
- else
- {
- object.childrenRefs.put(childId, new
UIObjectImpl.ChildRef(childId, false));
- }
- break;
- case WANT_EVICT:
- if (hadChildren)
- {
- UIObjectImpl.ChildRef childRef =
object.childrenRefs.get(childId);
- if (childRef.loaded)
- {
- context.removeChild(objectId, childId);
- childRef.loaded = false;
- UIObjectImpl child =
(UIObjectImpl)context.getObject(childId);
- evict(child);
- }
- }
- break;
- }
- }
-
- //
- return Status.LOADED;
- }
- }
- 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);
-
- //
- context.removeChild(object.structuralObject.getId(),
child.structuralObject.getId());
-
- //
- evict(child);
- }
- }
-
- //
- context.destroyChildren(object.structuralObject.getId());
- }
-
- //
- context.removeObject(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;
- }
- else
- {
- 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.createChildren(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);
- }
- }
-}
Deleted:
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 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/UIModelImpl.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,70 +0,0 @@
-/******************************************************************************
- * 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);
- }
-}
Deleted:
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 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/UIObjectImpl.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,124 +0,0 @@
-/******************************************************************************
- * 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;
- }
- }
-
-}
Deleted:
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 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/ViewPortImpl.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,66 +0,0 @@
-/******************************************************************************
- * 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;
- }
-}
Deleted:
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 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/AbstractModelTestCase.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,107 +0,0 @@
-/******************************************************************************
- * 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);
- }
- }
-}
Deleted:
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 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/AddChildTestCase.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,71 +0,0 @@
-/******************************************************************************
- * 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 TraversalModelTestCase
-{
-
- public void testAddChild()
- {
- test(1);
- }
-
- protected void test(ObjectTraversalType[] before, ObjectTraversalType[] after)
- {
- 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());
- }
-}
Deleted:
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 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/CustomScope.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,99 +0,0 @@
-/******************************************************************************
- * 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();
- }
-}
Deleted:
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 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/FullScope.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,57 +0,0 @@
-/******************************************************************************
- * 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)
- {
- }
-}
Deleted:
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 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/ModelTestCase.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,84 +0,0 @@
-/******************************************************************************
- * 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;
-
-/**
- * @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);
- }
-
- protected void test(ObjectTraversalType[] before, ObjectTraversalType[] after)
- {
- 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());
- }
-}
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/MoveChildTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/MoveChildTestCase.java 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/MoveChildTestCase.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,72 +0,0 @@
-/******************************************************************************
- * 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.model2.ViewPortScope;
-import org.jboss.portal.presentation.model2.ViewPort;
-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 MoveChildTestCase extends TraversalModelTestCase
-{
-
- public void testMoveChild()
- {
- test(0);
- }
-
- protected void test(ObjectTraversalType[] before, ObjectTraversalType[] after)
- {
- 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());
- }
-}
Deleted:
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 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/NodeDef.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,174 +0,0 @@
-/******************************************************************************
- * 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 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;
- }
- }
-}
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/RemoveChildTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/RemoveChildTestCase.java 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/RemoveChildTestCase.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,69 +0,0 @@
-/******************************************************************************
- * 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;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
- * @version $Revision: 630 $
- */
-public class RemoveChildTestCase extends TraversalModelTestCase
-{
-
- public void testRemoveChild()
- {
- test(1);
- }
-
- protected void test(ObjectTraversalType[] before, ObjectTraversalType[] after)
- {
- 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());
- }
-}
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/TraversalModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/TraversalModelTestCase.java 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/TraversalModelTestCase.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,128 +0,0 @@
-/******************************************************************************
- * 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.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.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)
- {
- 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);
- 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);
-
- 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;
- }
- }
-
-}
Deleted:
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 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectNode.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,125 +0,0 @@
-/******************************************************************************
- * 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 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;
- }
-}
Deleted:
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 2008-03-28
19:49:52 UTC (rev 10403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectTree.java 2008-03-28
19:54:35 UTC (rev 10404)
@@ -1,163 +0,0 @@
-/******************************************************************************
- * 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;
-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();
- }
-}