Author: julien(a)jboss.com
Date: 2007-12-05 17:11:49 -0500 (Wed, 05 Dec 2007)
New Revision: 9304
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChange.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChangeEvent.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateModification.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateModification.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/state/structural/MockModelTestCase.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/UIObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateException.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java
Log:
some more stuff in PF
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-05
22:11:35 UTC (rev 9303)
+++
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java 2007-12-05
22:11:49 UTC (rev 9304)
@@ -26,6 +26,8 @@
import org.jboss.portal.core.model.portal.PortalObjectContainer;
import org.jboss.portal.core.model.portal.PortalObjectId;
import org.jboss.portal.core.model.portal.PortalObjectPath;
+import org.jboss.portal.presentation.model.state.NoSuchStateException;
+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;
@@ -69,6 +71,26 @@
}
/**
+ * The implementation only validate that an object is present.
+ */
+ public void validate(StructuralObject object) throws IllegalArgumentException,
StateException
+ {
+ if (object == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ PortalObject portalObject =
this.portalObjectContainer.getObject(PortalObjectId.parse(object.getId(),
PortalObjectPath.CANONICAL_FORMAT));
+
+ //
+ if (portalObject == null)
+ {
+ throw new NoSuchStateException();
+ }
+ }
+
+ /**
*
*/
public StructuralObject load(String objectId) throws IllegalArgumentException
@@ -87,10 +109,10 @@
}
- public List<StructuralObject> loadChildren(StructuralObject object)
+ public List<StructuralObject> loadChildren(StructuralObject parent)
{
// Get the PortalObject corresponding to this objectId from the
PortalObjectContainer
- PortalObject portalObject =
this.portalObjectContainer.getObject(PortalObjectId.parse(object.getId(),
PortalObjectPath.CANONICAL_FORMAT));
+ PortalObject portalObject =
this.portalObjectContainer.getObject(PortalObjectId.parse(parent.getId(),
PortalObjectPath.CANONICAL_FORMAT));
//
ArrayList<StructuralObject> children = new
ArrayList<StructuralObject>();
@@ -103,10 +125,10 @@
return children;
}
- public StructuralObject loadParent(StructuralObject object)
+ public StructuralObject loadParent(StructuralObject child)
{
// Get the PortalObject corresponding to this objectId from the
PortalObjectContainer
- PortalObject portalObject =
this.portalObjectContainer.getObject(PortalObjectId.parse(object.getId(),
PortalObjectPath.CANONICAL_FORMAT));
+ PortalObject portalObject =
this.portalObjectContainer.getObject(PortalObjectId.parse(child.getId(),
PortalObjectPath.CANONICAL_FORMAT));
//
PortalObject parent = portalObject.getParent();
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-05
22:11:35 UTC (rev 9303)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-05
22:11:49 UTC (rev 9304)
@@ -22,14 +22,18 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.model;
+import org.jboss.portal.common.NotYetImplemented;
import org.jboss.portal.presentation.model.StateScopeType;
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.event.StateChange;
import org.jboss.portal.presentation.model.event.StateChangeEvent;
import
org.jboss.portal.presentation.model.event.navigational.NavigationalStateModification;
+import org.jboss.portal.presentation.model.event.structural.StructuralStateModification;
+import org.jboss.portal.presentation.model.state.NoSuchStateException;
+import org.jboss.portal.presentation.model.state.StaleStateException;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
-import org.jboss.portal.presentation.model.event.structural.StructuralStateModification;
import java.io.Serializable;
import java.util.Collections;
@@ -60,12 +64,16 @@
/** This is used to assist with data needed during lazy loading, other state related
data etc... */
private StructuralObject structuralObject;
+ /** . */
+ private Status status;
+
public UIObjectImpl(UIContextImpl context, StructuralObject object)
{
this.structuralObject = object;
this.context = context;
this.children = null;
this.parent = null;
+ this.status = Status.VALID;
}
public UIObjectImpl(StructuralObject object)
@@ -74,6 +82,7 @@
this.context = (UIContextImpl)this;
this.children = null;
this.parent = null;
+ this.status = Status.VALID;
}
protected final StructuralObject getStructuralObject()
@@ -120,6 +129,55 @@
}
}
+ public Status getStatus()
+ {
+ return status;
+ }
+
+ void updateStatus(StateException e)
+ {
+ if (e instanceof NoSuchStateException)
+ {
+ status = Status.INVALID;
+ }
+ else if (e instanceof StaleStateException)
+ {
+ status = Status.STALE;
+ }
+ else
+ {
+ throw new AssertionError(e);
+ }
+ }
+
+ public void validate()
+ {
+ try
+ {
+ context.structuralStateContext.validate(structuralObject);
+ }
+ catch (StateException e)
+ {
+ updateStatus(e);
+ }
+ }
+
+ public void resolveConflicts()
+ {
+ switch (status)
+ {
+ case STALE:
+ // Todo :-)
+ throw new NotYetImplemented();
+ case INVALID:
+ // Cannot be resolved
+ throw new IllegalStateException();
+ case VALID:
+ // Nothing to do
+ break;
+ }
+ }
+
public <T> T getProperty(StateScopeType scopeType, String propertyName,
Class<T> propertyType)
{
if (scopeType == null)
@@ -191,8 +249,19 @@
changes.put(propertyName, (String)propertyValue);
// Have context process change
- StructuralObject.Update update =
context.structuralStateContext.update(structuralObject, changes);
+ StructuralObject.Update update;
+ try
+ {
+ update = context.structuralStateContext.update(structuralObject,
changes);
+ }
+ catch (StateException e)
+ {
+ validate();
+ //
+ throw e;
+ }
+
//
context.update(update);
@@ -267,8 +336,19 @@
public <T extends UIObject> T createChild(String name, Class<T> type)
throws IllegalArgumentException
{
- StructuralObject.Creation creation =
context.structuralStateContext.create(structuralObject, type, name, EMPTY_STATE);
+ StructuralObject.Creation creation;
+ try
+ {
+ creation = context.structuralStateContext.create(structuralObject, type, name,
EMPTY_STATE);
+ }
+ catch (StateException e)
+ {
+ updateStatus(e);
+ //
+ throw e;
+ }
+
//
context.update(creation);
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-05
22:11:35 UTC (rev 9303)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-05
22:11:49 UTC (rev 9304)
@@ -33,60 +33,133 @@
*/
public interface UIObject
{
+
/**
- *
- * @return
+ * The status of a user interface object.
*/
+ public enum Status
+ {
+ /**
+ * It can be used.
+ */
+ VALID,
+
+ /**
+ * It cannot be used.
+ */
+ INVALID,
+
+ /**
+ * It cannot be used as is but a recovery is possible to either become valid or
invalid.
+ */
+ STALE
+ }
+
+ /**
+ * Updates the status of the object by comparing validating it against the structural
state context.
+ */
+ void validate();
+
+ /**
+ * Attempt a resolution of the current conflict. The behavior of the method will
change according to the
+ * current status of the object:
+ * <ul>
+ * <li><code>STALE</code> status leads to resolve the conflict to a
new status with <code>INVALID</code> or <code>VALID</code>
+ * as possible values</li>
+ * <li><code>VALID</code> status leads to a non
operation</li>
+ * <li><code>INVALID</code> status leads to throw an
<code>IllegalStateException</code></li>
+ * </ul>
+ */
+ void resolveConflicts();
+
+ /**
+ * Return the current status.
+ *
+ * @return the status
+ */
+ Status getStatus();
+
+ /**
+ * Returns the id.
+ *
+ * @return the id
+ */
String getId();
/**
+ * Returns the name.
*
- * @return
+ * @return the name
*/
String getName();
/**
+ * Returns the parent or null if the object does not have a parent.
*
- * @return
+ * @return the parent
*/
UIObject getParent();
+ /**
+ * Returns a named child or null if it does not exist.
+ *
+ * @param name the name of the child
+ * @return the named child
+ */
UIObject getChild(String name);
- <T> T getProperty(StateScopeType scopeType, String propertyName, Class<T>
propertyType);
+ /**
+ * Returns a property value or null if it does not exist.
+ *
+ * @param scopeType the scope where to get the value from
+ * @param propertyName the property name
+ * @param propertyType the expected property type
+ * @return the property value
+ * @throws IllegalArgumentException if any argument is null or not valid
+ * @throws StateException any state exception
+ */
+ <T> T getProperty(StateScopeType scopeType, String propertyName, Class<T>
propertyType) throws IllegalArgumentException, StateException;
/**
* Equivalent to call
<code>getPropertyValue(StateScopeType,String,Class)</code> with the
<code>Object.class</code>
* literal.
+ *
+ * @param scopeType the scope where to get the value from
+ * @param propertyName the property name
+ * @return the property value
+ * @throws IllegalArgumentException if any argument is null or not valid
+ * @throws StateException any state exception
*/
- Object getProperty(StateScopeType scopeType, String propertyName) throws
IllegalArgumentException, StateException, StateChangeVetoException;
+ Object getProperty(StateScopeType scopeType, String propertyName) throws
IllegalArgumentException, StateException;
- <T> void setProperty(StateScopeType scopeType, String propertyName, T
propertyValue) throws IllegalArgumentException, StateException, StateChangeVetoException;
+ <T> void setProperty(StateScopeType scopeType, String propertyName, T
propertyValue) throws IllegalArgumentException, StateException;
/**
- * Create a child with a specified type.
+ * Create a named child with a specified type.
*
* @param name the child name
* @param type the child type
* @return the newly created child
* @throws IllegalArgumentException if the name is null, already exists or this kind
of object does not accept children of the specified type
+ * @throws StateException any state exception
*/
- public <T extends UIObject> T createChild(String name, Class<T> type)
throws IllegalArgumentException;
+ public <T extends UIObject> T createChild(String name, Class<T> type)
throws IllegalArgumentException, StateException;
/**
- *
- * @param name
+ * Returns the children of this object.
+ *
+ * @return the list of children
*/
-// public void removeChild(String name);
+ List<UIObject> getChildren();
/**
- *
- * @return
+ *
+ * @param name
*/
- List<UIObject> getChildren();
+// public void removeChild(String name);
/**
- *
+ *
* @param <T>
* @param type
* @return
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChange.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChange.java 2007-12-05
22:11:35 UTC (rev 9303)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChange.java 2007-12-05
22:11:49 UTC (rev 9304)
@@ -1,77 +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;
-
-/**
- * A change in the state of the model. The change is the association of a target id and a
modification.
- * The target id refers to an object in the structural state context and the modification
is a modification
- * of its state. Note that the modification could also modify the state of other
objects.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public final class StateChange<M extends StateModification>
-{
-
- /** . */
- private final String targetId;
-
- /** . */
- private final M modification;
-
- public StateChange(String targetId, M modification)
- {
- if (targetId == null)
- {
- throw new IllegalArgumentException();
- }
- if (modification == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- this.targetId = targetId;
- this.modification = modification;
- }
-
- /**
- * Returns the target id of the change.
- *
- * @return the target id
- */
- public String getTargetId()
- {
- return targetId;
- }
-
- /**
- * Returns the modification operated on the target id.
- *
- * @return the modification
- */
- public M getModification()
- {
- return modification;
- }
-}
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChangeEvent.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChangeEvent.java 2007-12-05
22:11:35 UTC (rev 9303)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChangeEvent.java 2007-12-05
22:11:49 UTC (rev 9304)
@@ -1,59 +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;
-
-import org.jboss.portal.presentation.model.ModelEvent;
-
-/**
- * Signals a state change occured.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public final class StateChangeEvent extends ModelEvent
-{
-
- /** . */
- private final StateChange change;
-
- public StateChangeEvent(StateChange change)
- {
- if (change == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- this.change = change;
- }
-
- /**
- * Returns the state change that occured.
- *
- * @return the state change
- */
- public StateChange getChange()
- {
- return change;
- }
-}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateException.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateException.java 2007-12-05
22:11:35 UTC (rev 9303)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateException.java 2007-12-05
22:11:49 UTC (rev 9304)
@@ -26,7 +26,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-public class StateException extends RuntimeException
+public abstract class StateException extends RuntimeException
{
public StateException()
{
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateModification.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateModification.java 2007-12-05
22:11:35 UTC (rev 9303)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateModification.java 2007-12-05
22:11:49 UTC (rev 9304)
@@ -1,33 +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;
-
-/**
- * An abstract class for the modification of state.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public abstract class StateModification
-{
-}
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateModification.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateModification.java 2007-12-05
22:11:35 UTC (rev 9303)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateModification.java 2007-12-05
22:11:49 UTC (rev 9304)
@@ -1,61 +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.navigational;
-
-import org.jboss.portal.presentation.model.state.StateModification;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public final class NavigationalStateModification extends StateModification
-{
-
- /** . */
- private final String key;
-
- /** . */
- private final Object navigationalState;
-
- public NavigationalStateModification(String key, Object navigationalState)
- {
- if (key == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- this.key = key;
- this.navigationalState = navigationalState;
- }
-
- public String getKey()
- {
- return key;
- }
-
- public Object getNavigationalState()
- {
- return navigationalState;
- }
-}
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-05
22:11:35 UTC (rev 9303)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-05
22:11:49 UTC (rev 9304)
@@ -23,7 +23,6 @@
package org.jboss.portal.presentation.model.state.structural;
import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.state.NoSuchStateException;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
import org.jboss.portal.presentation.model.state.StateException;
@@ -31,7 +30,7 @@
import java.util.Map;
/**
- * The structural state manager.
+ * The structural state context.
*
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
@@ -40,17 +39,44 @@
{
/**
- * Load the state of a specified object.
+ * Validate the state of the provided object. The operation is idempotent and does not
modify any state.
+ * If validation is succesfull the method returns otherwise it throws an exception
that indicates
+ * the nature of the non validation failure.
*
+ * @param object the object to check
+ * @throws IllegalArgumentException if the provided object is null
+ * @throws StateException any useful exception that would make the object non valid
+ */
+ void validate(StructuralObject object) throws IllegalArgumentException,
StateException;
+
+ /**
+ * Load the state of the specified object.
+ *
* @param objectId the object id
* @return the state of the object or null if such state does not exist
* @throws IllegalArgumentException if the object id argument is null
*/
StructuralObject load(String objectId) throws IllegalArgumentException;
- List<StructuralObject> loadChildren(StructuralObject object);
+ /**
+ * Load the children of the provided object.
+ *
+ * @param parent the parent
+ * @return the list of children as structural objects
+ * @throws IllegalArgumentException if the provided object is null
+ * @throws StateException any useful exception that would make the object non valid
+ */
+ List<StructuralObject> loadChildren(StructuralObject parent) throws
IllegalArgumentException, StateException;
- StructuralObject loadParent(StructuralObject object);
+ /**
+ * Load the parent of the specified object.
+ *
+ * @param child the child
+ * @return the parent or null if it does not exist
+ * @throws IllegalArgumentException if the provided object is null
+ * @throws StateException any useful exception that would make the object non valid
+ */
+ StructuralObject loadParent(StructuralObject child) throws IllegalArgumentException,
StateException;
/**
* Returns the id of the root object.
@@ -66,36 +92,32 @@
* @param type the type of the child
* @param name the name of the child
* @param properties the initial properties of the child @return the id of the newly
created structural state
- * @return the state id
- * @throws StateChangeVetoException if the creation is vetoed
- * @throws StateException a generic state exception
- * @throws NoSuchStateException if the parent id does not point a valid state
+ * @return the creation object
* @throws IllegalArgumentException if an argument is null or not valid
+ * @throws StateException if the provided state prevents the operation to be done
*/
- StructuralObject.Creation create(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
StateException, IllegalArgumentException;
/**
* Destroy a specified object.
*
* @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
+ * @return the destruction object
* @throws IllegalArgumentException if an argument is null or not valid
- * @throws StateChangeVetoException
+ * @throws StateException if the provided state prevents the operation to be done
*/
- StructuralObject.Destruction destroy(StructuralObject object) throws StateException,
IllegalArgumentException;
+ StructuralObject.Destruction destroy(StructuralObject object) throws
IllegalArgumentException, StateException;
/**
* Move an object to a new parent.
*
- * @param source
- * @param destination
- * @throws StateException a generic state exception
- * @throws NoSuchStateException if the object id does not point a valid state
+ * @param source the source object
+ * @param destination the destination object
+ * @return the move object
* @throws IllegalArgumentException if an argument is null or not valid
+ * @throws StateException if the provided state prevents the operation to be done
*/
- StructuralObject.Move move(StructuralObject source, StructuralObject destination)
throws StateException, IllegalArgumentException;
+ StructuralObject.Move move(StructuralObject source, StructuralObject destination)
throws IllegalArgumentException, StateException;
/**
* Update the state of a specified object.
@@ -103,21 +125,9 @@
* @param object the object to udpate
* @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
+ * @return the update object
* @throws IllegalArgumentException if an argument is null or not valid
+ * @throws StateException if the provided state prevents the operation to be done
*/
- 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);
-
+ StructuralObject.Update update(StructuralObject object, Map<String, String>
changes) throws IllegalArgumentException, StateException;
}
Deleted:
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-05
22:11:35 UTC (rev 9303)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java 2007-12-05
22:11:49 UTC (rev 9304)
@@ -1,136 +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;
-
-import org.jboss.portal.presentation.model.state.StateModification;
-import org.jboss.portal.presentation.model.UIObject;
-
-import java.util.Map;
-
-/**
- * Specification of state modification for structural state.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public abstract class StructuralStateModification extends StateModification
-{
-
- protected StructuralStateModification()
- {
- }
-
- /**
- * Destruction of an object.
- */
- public final static class Destruction extends StructuralStateModification
- {
- }
-
- public final static class Creation extends StructuralStateModification
- {
-
- /** . */
- private final Class<? extends UIObject> type;
-
- /** . */
- private final String name;
-
- /** . */
- private final Map<String, String> properties;
-
- public Creation(Class<? extends UIObject> type, String name, Map<String,
String> properties)
- {
- this.type = type;
- this.name = name;
- this.properties = properties;
- }
-
- public Class<? extends UIObject> getType()
- {
- return type;
- }
-
- public String getName()
- {
- return name;
- }
-
- public Map<String, String> getProperties()
- {
- return properties;
- }
- }
-
- public final static class Move extends StructuralStateModification
- {
-
- /** . */
- private final String destinationId;
-
- public Move(String parentId)
- {
- this.destinationId = parentId;
- }
-
- public String getDestinationId()
- {
- return destinationId;
- }
- }
-
-
- /**
- * Update the properties portion of the state. The <code>Map</code> values
are interpreted as follow:
- * <ul>
- * <li>Each non null value will replace an existing value of create a new
one</li>
- * <li>Each null value will destroy an existing value</li>
- * </ul>
- */
- public final static class Update extends StructuralStateModification
- {
-
- /** . */
- private final Map<String, String> changes;
-
- public Update(Map<String, String> changes)
- {
- if (changes == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- this.changes = changes;
- }
-
- /**
- *
- * @return
- */
- public Map<String, String> getChanges()
- {
- return changes;
- }
- }
-}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-05
22:11:35 UTC (rev 9303)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-05
22:11:49 UTC (rev 9304)
@@ -515,4 +515,11 @@
eventAssert.next(portal.getId(), new
StructuralStateModification.Creation(UIPortal.class, "foo", new
HashMap<String, String>()));
}
+
+ public void testBlah()
+ {
+
+
+
+ }
}
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-05
22:11:35 UTC (rev 9303)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2007-12-05
22:11:49 UTC (rev 9304)
@@ -110,6 +110,11 @@
return root.getId();
}
+ public void validate(StructuralObject object) throws StateException
+ {
+ getValidMockObject(object);
+ }
+
public StructuralObject.Update update(StructuralObject object, Map<String,
String> changes) throws StateChangeVetoException
{
MockObject mockObject = getValidMockObject(object);
@@ -140,7 +145,7 @@
return new StructuralObject.Update(mockObject.takeSnapshot());
}
- public StructuralObject.Creation create(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
StateException, IllegalArgumentException
{
MockObject mockParent = getValidMockObject(parent);
@@ -154,23 +159,23 @@
return new StructuralObject.Creation(mockParent.takeSnapshot(),
mockChild.takeSnapshot());
}
- public List<StructuralObject> loadChildren(StructuralObject object)
+ public List<StructuralObject> loadChildren(StructuralObject parent)
{
- MockObject mockObject = getValidMockObject(object);
+ MockObject mockParent = getValidMockObject(parent);
//
List<StructuralObject> tmp = new ArrayList<StructuralObject>();
- for (MockObject mockChild : mockObject.getChildren())
+ for (MockObject mockChild : mockParent.getChildren())
{
tmp.add(mockChild.takeSnapshot());
}
return tmp;
}
- public StructuralObject loadParent(StructuralObject object)
+ public StructuralObject loadParent(StructuralObject child)
{
- MockObject mockObject = getValidMockObject(object);
- MockObject mockParent = mockObject.getParent();
+ MockObject mockchild = getValidMockObject(child);
+ MockObject mockParent = mockchild.getParent();
return mockParent != null ? mockParent.takeSnapshot() : null;
}
@@ -208,33 +213,5 @@
//
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;
- }
- }
};
}
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelTestCase.java 2007-12-05
22:11:35 UTC (rev 9303)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelTestCase.java 2007-12-05
22:11:49 UTC (rev 9304)
@@ -1,278 +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.test.model.state.structural;
-
-import junit.framework.TestCase;
-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 java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Test that the mock model we are using behaves in an expected manner
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class MockModelTestCase extends TestCase
-{
-
- /** . */
- private MockModel model;
-
- /** . */
- 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()
- {
- MockObject mockRoot = model.getRoot();
- assertNotNull(mockRoot);
- assertEquals(Collections.EMPTY_SET, mockRoot.getPropertyNames());
- assertNull(mockRoot.getParent());
- assertEquals(Collections.EMPTY_LIST, mockRoot.getChildren());
- assertEquals(MockObject.Type.CONTEXT, mockRoot.getType());
- assertEquals("", mockRoot.getName());
- assertEquals(true, mockRoot.isValid());
-
- //
- String rootId = ssc.getRootId();
- assertNotNull(rootId);
- StructuralObject root = ssc.load(rootId);
- assertNotNull(root);
- assertEquals(rootId, root.getId());
- StructuralState state = root.getState();
- assertEquals(UIContext.class, state.getType());
- assertEquals("", state.getName());
- assertEquals(Collections.EMPTY_MAP, state.getProperties());
- }
-
- public void testSetProperty()
- {
- MockObject mockRoot = model.getRoot();
- String rootId = mockRoot.getId();
- int rootV0 = mockRoot.getVersion();
-
- //
- StructuralObject root0 = ssc.load(rootId);
- StructuralState rootState0 = root0.getState();
- assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
-
- // Set
- ssc.update(listener, root0, Collections.singletonMap("foo",
"bar"));
-
- //
- int rootV1 = mockRoot.getVersion();
- assertTrue(rootV1 > rootV0);
- assertEquals(Collections.singleton("foo"), mockRoot.getPropertyNames());
- assertEquals("bar", mockRoot.getPropertyValue("foo"));
- assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
- assertStale(root0);
- StructuralObject root1_0 = universe.get(rootId);
- assertNotNull(root1_0);
- assertNotStale(root1_0);
- StructuralState rootState1_0 = root1_0.getState();
- assertEquals(Collections.singletonMap("foo", "bar"),
rootState1_0.getProperties());
- StructuralObject root1_1 = ssc.load(rootId);
- assertNotNull(root1_1);
- assertNotStale(root1_1);
- StructuralState rootState1_1 = root1_1.getState();
- assertEquals(Collections.singletonMap("foo", "bar"),
rootState1_1.getProperties());
- }
-
- public void testUpdateProperty()
- {
- MockObject mockRoot = model.getRoot();
- String rootId = mockRoot.getId();
- int rootV0 = mockRoot.getVersion();
-
- //
- StructuralObject root0 = ssc.load(rootId);
- StructuralState rootState0 = root0.getState();
- assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
-
- // Set
- mockRoot.setPropertyValue("foo", "bar");
-
- //
- int rootV1 = mockRoot.getVersion();
- assertTrue(rootV1 > rootV0);
- assertEquals(Collections.singleton("foo"), mockRoot.getPropertyNames());
- assertEquals("bar", mockRoot.getPropertyValue("foo"));
- assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
- assertStale(root0);
- StructuralObject root1 = ssc.load(rootId);
- assertNotNull(root1);
- assertNotStale(root1);
- StructuralState rootState1 = root1.getState();
- assertEquals(Collections.singletonMap("foo", "bar"),
rootState1.getProperties());
-
- // Update
- ssc.update(listener, root1, Collections.singletonMap("foo",
"bar2"));
-
- //
- int rootV2 = mockRoot.getVersion();
- assertTrue(rootV2 > rootV1);
- assertEquals(Collections.singleton("foo"), mockRoot.getPropertyNames());
- assertEquals("bar2", mockRoot.getPropertyValue("foo"));
- assertEquals(Collections.EMPTY_MAP, rootState0.getProperties());
- assertStale(root0);
- assertStale(root1);
-
- //
- StructuralObject root2_0 = universe.get(rootId);
- assertNotNull(root2_0);
- assertNotStale(root2_0);
- StructuralState rootState2_0 = root2_0.getState();
- assertEquals(Collections.singletonMap("foo", "bar2"),
rootState2_0.getProperties());
- StructuralObject root2_1 = ssc.load(rootId);
- assertNotNull(root2_1);
- assertNotStale(root2_1);
- StructuralState rootState2_1 = root2_1.getState();
- assertEquals(Collections.singletonMap("foo", "bar2"),
rootState2_1.getProperties());
- }
-
- private void assertStale(StructuralObject object)
- {
- try
- {
- ssc.loadParent(object);
- fail();
- }
- catch (StaleStateException ignore)
- {
- }
- try
- {
- ssc.loadChildren(object);
- fail();
- }
- catch (StaleStateException ignore)
- {
- }
- }
-
- private void assertNotStale(StructuralObject object)
- {
- ssc.loadParent(object);
- ssc.loadChildren(object);
- }
-
- public void testAddChild()
- {
- MockObject mockRoot = model.getRoot();
- int rootV0 = mockRoot.getVersion();
-
- //
- String rootId = mockRoot.getId();
- StructuralObject root = ssc.load(rootId);
-
- //
- MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
- assertNotNull(mockFoo);
- String fooId = mockFoo.getId();
-
- //
- assertNotNull(fooId);
- assertEquals("foo", mockFoo.getName());
- assertEquals(MockObject.Type.PORTAL, mockFoo.getType());
- assertSame(mockRoot, mockFoo.getParent());
- assertEquals(Collections.singletonList(mockFoo), mockRoot.getChildren());
- assertEquals(Collections.EMPTY_SET, mockFoo.getPropertyNames());
- assertTrue(mockRoot.getVersion() > rootV0);
-
- //
- try
- {
- ssc.loadParent(root);
- fail();
- }
- catch (StaleStateException ignore)
- {
- }
- try
- {
- ssc.loadChildren(root);
- fail();
- }
- catch (StaleStateException ignore)
- {
- }
-
- //
- root = ssc.load(rootId);
- assertNotNull(root);
- assertEquals(rootId, root.getId());
-
- //
- List<StructuralObject> children = ssc.loadChildren(root);
- assertNotNull(children);
- assertEquals(1, children.size());
- StructuralObject foo = children.get(0);
- assertNotNull(foo);
- assertEquals(fooId, foo.getId());
- StructuralState fooState = foo.getState();
- assertNotNull(fooState);
- assertEquals("foo", fooState.getName());
- assertEquals(Collections.EMPTY_MAP, fooState.getProperties());
- assertEquals(UIPortal.class, fooState.getType());
- root = ssc.loadParent(foo);
- assertNotNull(root);
- assertEquals(rootId, root.getId());
- }
-
-}