Author: julien(a)jboss.com
Date: 2007-12-04 10:14:34 -0500 (Tue, 04 Dec 2007)
New Revision: 9280
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateChangeListener.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java
Modified:
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java
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/StructuralStateContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectImpl.java
Log:
- remove the listener mechanism and instead use a more protocolish design
- isolate uicontext objects update in the uicontext class
Modified:
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java
===================================================================
---
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java 2007-12-04
15:08:37 UTC (rev 9279)
+++
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java 2007-12-04
15:14:34 UTC (rev 9280)
@@ -115,6 +115,24 @@
return parent == null ? null : new StructuralObjectImpl(parent);
}
+ public boolean equals(StructuralObject left, StructuralObject right)
+ {
+ if (left == null)
+ {
+ return right == null;
+ }
+ else
+ {
+ if (right == null)
+ {
+ return false;
+ }
+ StructuralObjectImpl lefti = (StructuralObjectImpl)left;
+ StructuralObjectImpl righti = (StructuralObjectImpl)right;
+ return lefti.getId().equals(righti.getId());
+ }
+ }
+
/**
*
*
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-04
15:08:37 UTC (rev 9279)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-04
15:14:34 UTC (rev 9280)
@@ -32,7 +32,6 @@
import org.jboss.portal.presentation.model.UIWindow;
import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
-import
org.jboss.portal.presentation.model.state.structural.StructuralStateChangeListener;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import java.util.ArrayList;
@@ -48,7 +47,7 @@
{
/** . */
- private final Map<String, UIObjectImpl> objects = new HashMap<String,
UIObjectImpl>();
+ private final Map<String, UIObjectImpl> universe = new HashMap<String,
UIObjectImpl>();
/** . */
protected final StructuralStateContext structuralStateContext;
@@ -59,32 +58,6 @@
/** . */
protected final List<ModelListener> listeners;
- protected final StructuralStateChangeListener listener = new
StructuralStateChangeListener()
- {
- public void update(StructuralObject object)
- {
- // Get the corresponding object
- UIObjectImpl tmp = objects.get(object.getId());
-
- // If it is not here, create it
- if (tmp == null)
- {
- tmp = createObject(object);
- objects.put(object.getId(), tmp);
- }
- else
- {
- // Update its structural view
- tmp.update(object);
- }
- }
-
- public void remove(String id)
- {
- objects.remove(id);
- }
- };
-
private static StructuralObject getRootState(StructuralStateContext loader)
{
return loader.load(loader.getRootId());
@@ -99,8 +72,8 @@
this.navigationalStateContext = navigationalStateContext;
this.listeners = new ArrayList<ModelListener>();
- // Put our self in the object cache
- objects.put(getId(), this);
+ // Put our self in the universe
+ universe.put(getId(), this);
}
/**
@@ -108,14 +81,59 @@
*/
public UIObject getObject(String id)
{
- return getFromUniverse(id, true);
+ return getObject(id, true);
}
- UIObject getFromUniverse(String id, boolean loadIfAbsent)
+ void update(StructuralObject.Change change)
{
+ if (change instanceof StructuralObject.Update)
+ {
+ StructuralObject.Update update = (StructuralObject.Update)change;
+ context.updateUniverse(update.getObject());
+ }
+ else if (change instanceof StructuralObject.Creation)
+ {
+ StructuralObject.Creation creation = (StructuralObject.Creation)change;
+ context.updateUniverse(creation.getParent());
+ context.updateUniverse(creation.getChild());
+ }
+ else
+ {
+ throw new AssertionError();
+ }
+ }
+
+ UIObjectImpl getParent(StructuralObject structuralObject)
+ {
+ StructuralObject parentStructuralState =
context.structuralStateContext.loadParent(structuralObject);
+ return context.updateUniverse(parentStructuralState);
+ }
+
+ List<UIObject> getChildren(StructuralObject structuralObject)
+ {
+ ArrayList<UIObject> children = new ArrayList<UIObject>();
+ for (StructuralObject structuralChild :
context.structuralStateContext.loadChildren(structuralObject))
+ {
+ UIObjectImpl child = context.updateUniverse(structuralChild);
+ children.add(child);
+ }
+ return children;
+ }
+
+ /**
+ * Get an object from the universe. If the parameter
<code>loadIfAbsent</code> has the value <code>false</code>
+ * and the object is not in the universe it will throw an
<code>AssertionError</code> otherwise it will return
+ * the object.
+ *
+ * @param id the id of the object to obtain
+ * @param loadIfAbsent load the object from the structural state context if it is not
present
+ * @return the loaded object
+ */
+ private UIObjectImpl getObject(String id, boolean loadIfAbsent)
+ {
try
{
- UIObject object = objects.get(id);
+ UIObjectImpl object = universe.get(id);
//
if (object != null)
@@ -126,7 +144,7 @@
//
if (loadIfAbsent)
{
- //Fetch the state of the UIObject in question
+ // Fetch the state of the UIObject in question
StructuralObject structuralObject = this.structuralStateContext.load(id);
//
@@ -143,9 +161,9 @@
}
}
- protected UIObjectImpl updateUniverse(StructuralObject structuralObject)
+ private UIObjectImpl updateUniverse(StructuralObject structuralObject)
{
- UIObjectImpl object = objects.get(structuralObject.getId());
+ UIObjectImpl object = universe.get(structuralObject.getId());
//
if (object == null)
@@ -153,25 +171,15 @@
object = createObject(structuralObject);
//
- objects.put(structuralObject.getId(), object);
+ universe.put(structuralObject.getId(), object);
}
-
- //
- return object;
- }
-
- public void addModelListener(ModelListener listener)
- {
- if (listener == null)
+ else
{
- throw new IllegalArgumentException();
+ object.update(structuralObject);
}
//
- if (!listeners.contains(listener))
- {
- listeners.add(listener);
- }
+ return object;
}
private UIObjectImpl createObject(StructuralObject state)
@@ -201,6 +209,20 @@
}
}
+ public void addModelListener(ModelListener listener)
+ {
+ if (listener == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ if (!listeners.contains(listener))
+ {
+ listeners.add(listener);
+ }
+ }
+
protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
{
return type == UIPortal.class;
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-04
15:08:37 UTC (rev 9279)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-04
15:14:34 UTC (rev 9280)
@@ -32,7 +32,6 @@
import org.jboss.portal.presentation.model.state.structural.StructuralStateModification;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -47,6 +46,9 @@
{
/** . */
+ private static final Map<String, String> EMPTY_STATE = Collections.emptyMap();
+
+ /** . */
protected final UIContextImpl context;
/** . */
@@ -186,8 +188,11 @@
changes.put(propertyName, (String)propertyValue);
// Have context process change
- context.structuralStateContext.update(context.listener, structuralObject,
changes);
+ StructuralObject.Update update =
context.structuralStateContext.update(structuralObject, changes);
+ //
+ context.update(update);
+
// Broadcast event
StructuralStateModification mod = new
StructuralStateModification.Update(changes);
StateChange<StructuralStateModification> change = new
StateChange<StructuralStateModification>(getId(), mod);
@@ -238,8 +243,7 @@
//
if (parent == null)
{
- StructuralObject parentStructuralState =
context.structuralStateContext.loadParent(structuralObject);
- parent = context.updateUniverse(parentStructuralState);
+ parent = context.getParent(structuralObject);
}
//
@@ -253,25 +257,20 @@
{
if (children == null)
{
- ArrayList<UIObject> tmp = new ArrayList<UIObject>();
- for (StructuralObject structuralChild :
context.structuralStateContext.loadChildren(structuralObject))
- {
- UIObjectImpl child = context.updateUniverse(structuralChild);
- tmp.add(child);
- }
- children = tmp;
+ children = context.getChildren(structuralObject);
}
return children;
}
- private static final Map<String, String> EMPTY_STATE = Collections.emptyMap();
-
public <T extends UIObject> T createChild(String name, Class<T> type)
throws IllegalArgumentException
{
- String id = context.structuralStateContext.create(context.listener,
structuralObject, type, name, EMPTY_STATE);
+ StructuralObject.Creation creation =
context.structuralStateContext.create(structuralObject, type, name, EMPTY_STATE);
//
- return type.cast(context.getFromUniverse(id, false));
+ context.update(creation);
+
+ //
+ return type.cast(context.getObject(creation.getChild().getId()));
}
void update(StructuralObject object)
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateChangeListener.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateChangeListener.java 2007-12-04
15:08:37 UTC (rev 9279)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateChangeListener.java 2007-12-04
15:14:34 UTC (rev 9280)
@@ -1,38 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, 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.model.state.structural;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class AbstractStructuralStateChangeListener implements
StructuralStateChangeListener
-{
- public void update(StructuralObject object)
- {
- }
-
- public void remove(String id)
- {
- }
-}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java 2007-12-04
15:08:37 UTC (rev 9279)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java 2007-12-04
15:14:34 UTC (rev 9280)
@@ -35,22 +35,22 @@
public abstract class AbstractStructuralStateContext implements StructuralStateContext
{
- public String create(StructuralStateChangeListener listener, StructuralObject parent,
Class<? extends UIObject> type, String name, Map<String, String> properties)
throws StateChangeVetoException, StateException, IllegalArgumentException
+ public StructuralObject.Creation create(StructuralObject parent, Class<? extends
UIObject> type, String name, Map<String, String> properties) throws
StateChangeVetoException, StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
- public void destroy(StructuralStateChangeListener listener, StructuralObject object)
throws StateChangeVetoException, StateException, IllegalArgumentException
+ public StructuralObject.Destruction destroy(StructuralObject object) throws
StateChangeVetoException, StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
- public void move(StructuralStateChangeListener listener, StructuralObject object,
StructuralObject parent) throws StateChangeVetoException, StateException,
IllegalArgumentException
+ public StructuralObject.Move move(StructuralObject source, StructuralObject
destination) throws StateChangeVetoException, StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
- public void update(StructuralStateChangeListener listener, StructuralObject object,
Map<String, String> changes) throws StateChangeVetoException, StateException,
IllegalArgumentException
+ public StructuralObject.Update update(StructuralObject object, Map<String,
String> changes) throws StateChangeVetoException, StateException,
IllegalArgumentException
{
throw new StateChangeVetoException();
}
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 2007-12-04
15:08:37 UTC (rev 9279)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java 2007-12-04
15:14:34 UTC (rev 9280)
@@ -22,6 +22,8 @@
******************************************************************************/
package org.jboss.portal.presentation.model.state.structural;
+import java.util.List;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
@@ -33,4 +35,138 @@
StructuralState getState();
+ public static class Change
+ {
+ }
+
+ public static class Update extends Change
+ {
+
+ /** . */
+ private final StructuralObject object;
+
+ public Update(StructuralObject object)
+ {
+ if (object == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.object = object;
+ }
+
+ public StructuralObject getObject()
+ {
+ return object;
+ }
+ }
+
+ public static class Move extends Change
+ {
+
+ /** . */
+ private final StructuralObject source;
+
+ /** . */
+ private final StructuralObject destination;
+
+ public Move(StructuralObject source, StructuralObject destination)
+ {
+ if (source == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (destination == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.source = source;
+ this.destination = destination;
+ }
+
+ public StructuralObject getSource()
+ {
+ return source;
+ }
+
+ public StructuralObject getDestination()
+ {
+ return destination;
+ }
+ }
+
+ public static class Creation extends Change
+ {
+
+ /** . */
+ private final StructuralObject child;
+
+ /** . */
+ private final StructuralObject parent;
+
+ public Creation(StructuralObject parent, StructuralObject child)
+ {
+ if (parent == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (child == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.parent = parent;
+ this.child = child;
+ }
+
+ public StructuralObject getParent()
+ {
+ return parent;
+ }
+
+ public StructuralObject getChild()
+ {
+ return child;
+ }
+ }
+
+ public static class Destruction extends Change
+ {
+
+ /** . */
+ private final StructuralObject parent;
+
+ /** . */
+ private final List<String> ids;
+
+ public Destruction(StructuralObject parent, List<String> ids)
+ {
+ if (parent == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (ids == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.parent = parent;
+ this.ids = ids;
+ }
+
+ public StructuralObject getParent()
+ {
+ return parent;
+ }
+
+ public List<String> getIds()
+ {
+ return ids;
+ }
+ }
}
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java 2007-12-04
15:08:37 UTC (rev 9279)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java 2007-12-04
15:14:34 UTC (rev 9280)
@@ -1,44 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, 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.model.state.structural;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public interface StructuralStateChangeListener
-{
- /**
- * Updates the structural object.
- *
- * @param object the object to update
- */
- void update(StructuralObject object);
-
- /**
- * Removes the structural object with the specified id.
- *
- * @param id the id to remove
- */
- void remove(String id);
-}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-04
15:08:37 UTC (rev 9279)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-04
15:14:34 UTC (rev 9280)
@@ -62,7 +62,6 @@
/**
* Create an object.
*
- * @param listener the listener
* @param parent the parent
* @param type the type of the child
* @param name the name of the child
@@ -73,42 +72,52 @@
* @throws NoSuchStateException if the parent id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
*/
- String create(StructuralStateChangeListener listener, StructuralObject parent,
Class<? extends UIObject> type, String name, Map<String, String> properties)
throws StateChangeVetoException, StateException, IllegalArgumentException;
+ StructuralObject.Creation create(StructuralObject parent, Class<? extends
UIObject> type, String name, Map<String, String> properties) throws
StateChangeVetoException, StateException, IllegalArgumentException;
/**
* Destroy a specified object.
*
- * @param listener the listener
- * @param object the object to destroy @throws StateChangeVetoException if the
creation is vetoed
+ * @param object the object to destroy
+ * @throws StateChangeVetoException if the creation is vetoed
* @throws StateException a generic state exception
* @throws NoSuchStateException if the object id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
* @throws StateChangeVetoException
*/
- void destroy(StructuralStateChangeListener listener, StructuralObject object) throws
StateChangeVetoException, StateException, IllegalArgumentException;
+ StructuralObject.Destruction destroy(StructuralObject object) throws StateException,
IllegalArgumentException;
/**
* Move an object to a new parent.
*
- * @param listener the listener
- * @param object the object to move
- * @param parent the new parent @throws StateChangeVetoException if the creation is
vetoed
+ * @param source
+ * @param destination
* @throws StateException a generic state exception
* @throws NoSuchStateException if the object id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
*/
- void move(StructuralStateChangeListener listener, StructuralObject object,
StructuralObject parent) throws StateChangeVetoException, StateException,
IllegalArgumentException;
+ StructuralObject.Move move(StructuralObject source, StructuralObject destination)
throws StateException, IllegalArgumentException;
/**
* Update the state of a specified object.
*
- * @param listener the listener
* @param object the object to udpate
- * @param changes the changes @throws StateChangeVetoException if the creation is
vetoed
+ * @param changes the changes
+ * @throws StateChangeVetoException if the creation is vetoed
* @throws StateException a generic state exception
* @throws NoSuchStateException if the object id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
*/
- void update(StructuralStateChangeListener listener, StructuralObject object,
Map<String, String> changes) throws StateChangeVetoException, StateException,
IllegalArgumentException;
+ StructuralObject.Update update(StructuralObject object, Map<String, String>
changes) throws StateException, IllegalArgumentException;
+ /**
+ * The structural object equality requires the equality of the id but it may not be a
sufficient condition.
+ * Equality could be based on the state or on a version id. The equality operation can
be considered as safe
+ * with respect to passing null as argument.
+ *
+ * @param left the left
+ * @param right the right
+ * @return if left and right are equals
+ */
+ boolean equals(StructuralObject left, StructuralObject right);
+
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java 2007-12-04
15:08:37 UTC (rev 9279)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java 2007-12-04
15:14:34 UTC (rev 9280)
@@ -86,16 +86,16 @@
{
/** . */
- private final String parentId;
+ private final String destinationId;
public Move(String parentId)
{
- this.parentId = parentId;
+ this.destinationId = parentId;
}
- public String getParentId()
+ public String getDestinationId()
{
- return parentId;
+ return destinationId;
}
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-04
15:08:37 UTC (rev 9279)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-04
15:14:34 UTC (rev 9280)
@@ -26,10 +26,8 @@
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.UIPortal;
import org.jboss.portal.presentation.model.state.StaleStateException;
-import
org.jboss.portal.presentation.model.state.structural.AbstractStructuralStateChangeListener;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralState;
-import
org.jboss.portal.presentation.model.state.structural.StructuralStateChangeListener;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import org.jboss.portal.presentation.test.model.state.structural.MockModel;
import org.jboss.portal.presentation.test.model.state.structural.MockObject;
@@ -54,30 +52,16 @@
/** . */
private StructuralStateContext ssc;
- /** . */
- private Map<String, StructuralObject> universe;
-
- /** . */
- private final StructuralStateChangeListener listener = new
AbstractStructuralStateChangeListener()
- {
- public void update(StructuralObject object)
- {
- universe.put(object.getId(), object);
- }
- };
-
protected void setUp() throws Exception
{
model = new MockModel();
ssc = model.getStructuralStateContext();
- universe = new HashMap<String, StructuralObject>();
}
protected void tearDown() throws Exception
{
model = null;
ssc = null;
- universe = null;
}
public void testRoot()
@@ -115,7 +99,7 @@
assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
// Set
- ssc.update(listener, root0, Collections.singletonMap("foo",
"bar"));
+ StructuralObject.Update update = ssc.update(root0,
Collections.singletonMap("foo", "bar"));
//
int rootV1 = mockRoot.getVersion();
@@ -124,7 +108,7 @@
assertEquals("bar", mockRoot.getPropertyValue("foo"));
assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
assertStale(root0);
- StructuralObject root1_0 = universe.get(rootId);
+ StructuralObject root1_0 = update.getObject();
assertNotNull(root1_0);
assertNotStale(root1_0);
StructuralState rootState1_0 = root1_0.getState();
@@ -164,7 +148,7 @@
assertEquals(Collections.singletonMap("foo", "bar"),
rootState1.getProperties());
// Update
- ssc.update(listener, root1, Collections.singletonMap("foo",
"bar2"));
+ StructuralObject.Update update = ssc.update(root1,
Collections.singletonMap("foo", "bar2"));
//
int rootV2 = mockRoot.getVersion();
@@ -176,7 +160,7 @@
assertStale(root1);
//
- StructuralObject root2_0 = universe.get(rootId);
+ StructuralObject root2_0 = update.getObject();
assertNotNull(root2_0);
assertNotStale(root2_0);
StructuralState rootState2_0 = root2_0.getState();
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2007-12-04
15:08:37 UTC (rev 9279)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2007-12-04
15:14:34 UTC (rev 9280)
@@ -33,7 +33,6 @@
import org.jboss.portal.presentation.model.state.StateException;
import
org.jboss.portal.presentation.model.state.structural.AbstractStructuralStateContext;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
-import
org.jboss.portal.presentation.model.state.structural.StructuralStateChangeListener;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import java.util.ArrayList;
@@ -111,7 +110,7 @@
return root.getId();
}
- public void update(StructuralStateChangeListener listener, StructuralObject object,
Map<String, String> changes) throws StateChangeVetoException
+ public StructuralObject.Update update(StructuralObject object, Map<String,
String> changes) throws StateChangeVetoException
{
MockObject mockObject = getValidMockObject(object);
@@ -138,13 +137,10 @@
}
//
- if (listener != null)
- {
- listener.update(mockObject.takeSnapshot());
- }
+ return new StructuralObject.Update(mockObject.takeSnapshot());
}
- public String create(StructuralStateChangeListener listener, StructuralObject
parent, Class<? extends UIObject> classType, String name, Map<String, String>
properties) throws StateChangeVetoException, StateException, IllegalArgumentException
+ public StructuralObject.Creation create(StructuralObject parent, Class<? extends
UIObject> classType, String name, Map<String, String> properties) throws
StateChangeVetoException, StateException, IllegalArgumentException
{
MockObject mockParent = getValidMockObject(parent);
@@ -155,11 +151,7 @@
MockObject mockChild = mockParent.addChild(name, type, properties);
//
- listener.update(mockParent.takeSnapshot());
- listener.update(mockChild.takeSnapshot());
-
- //
- return mockChild.getId();
+ return new StructuralObject.Creation(mockParent.takeSnapshot(),
mockChild.takeSnapshot());
}
public List<StructuralObject> loadChildren(StructuralObject object)
@@ -217,5 +209,32 @@
return mockObject;
}
+ public boolean equals(StructuralObject left, StructuralObject right)
+ {
+ if (left == null)
+ {
+ return right == null;
+ }
+ else
+ {
+ if (right == null)
+ {
+ return false;
+ }
+
+ //
+ StructuralObjectImpl lefti = (StructuralObjectImpl)left;
+ StructuralObjectImpl righti = (StructuralObjectImpl)left;
+
+ //
+ if (lefti == righti)
+ {
+ return true;
+ }
+
+ //
+ return lefti.id.equals(righti.id) && lefti.version ==
righti.version;
+ }
+ }
};
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectImpl.java 2007-12-04
15:08:37 UTC (rev 9279)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectImpl.java 2007-12-04
15:14:34 UTC (rev 9280)
@@ -57,4 +57,18 @@
{
return state;
}
+
+ public boolean equals(Object o)
+ {
+ if (o == this)
+ {
+ return true;
+ }
+ if (o instanceof StructuralObjectImpl)
+ {
+ StructuralObjectImpl that = (StructuralObjectImpl)o;
+ return id.equals(that.id) && version == that.version;
+ }
+ return false;
+ }
}