[portal-commits] JBoss Portal SVN: r9194 - in branches/presentation: presentation/src/main/org/jboss/portal/presentation/impl/model and 4 other directories.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Thu Nov 29 08:16:38 EST 2007


Author: julien at jboss.com
Date: 2007-11-29 08:16:38 -0500 (Thu, 29 Nov 2007)
New Revision: 9194

Added:
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/ModelEvent.java
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/ModelListener.java
   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/structural/StructuralStateModification.java
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java
Removed:
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateManager.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/UIContext.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/MockModel.java
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
added model event feature that will allow to track complex changes during an interaction which will allow the client to react accordingly to perform the necessary state updates

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-11-29 12:30:00 UTC (rev 9193)
+++ branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -35,7 +35,9 @@
 import org.jboss.portal.presentation.model.UIWindow;
 import org.jboss.portal.presentation.model.state.structural.StructuralState;
 import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateModification;
 import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.state.StateChange;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -73,7 +75,6 @@
       this.portalObjectContainer = portalObjectContainer;
    }
 
-
    public String getRootId()
    {
       return portalObjectContainer.getContext().getId().toString();
@@ -177,6 +178,16 @@
       throw new StateChangeVetoException();
    }
 
+   public void update(List<StateChange<StructuralStateModification>> modifications)
+   {
+      throw new StateChangeVetoException();
+   }
+
+   public void update(StateChange<StructuralStateModification> modification)
+   {
+      throw new StateChangeVetoException();
+   }
+
    /**
     * 
     *

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-11-29 12:30:00 UTC (rev 9193)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -22,6 +22,8 @@
  ******************************************************************************/
 package org.jboss.portal.presentation.impl.model;
 
+import org.jboss.portal.presentation.model.ModelEvent;
+import org.jboss.portal.presentation.model.ModelListener;
 import org.jboss.portal.presentation.model.UIContainer;
 import org.jboss.portal.presentation.model.UIContext;
 import org.jboss.portal.presentation.model.UIObject;
@@ -33,7 +35,9 @@
 import org.jboss.portal.presentation.model.state.structural.StructuralState;
 import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -55,6 +59,9 @@
    /** . */
    protected final ContentStateContext contentStateContext;
 
+   /** . */
+   protected final List<ModelListener> listeners;
+
    private static String getRootId(StructuralStateContext loader)
    {
       return loader.getRootId();
@@ -76,6 +83,7 @@
       this.structuralStateContext = structuralStateContext;
       this.navigationalStateContext = navigationalStateContext;
       this.contentStateContext = contentStateContext;
+      this.listeners = new ArrayList<ModelListener>();
 
       // Put our self in the object cache
       objects.put(getId(), this);
@@ -104,6 +112,20 @@
       }
    }
 
+   public void addModelListener(ModelListener listener)
+   {
+      if (listener == null)
+      {
+         throw new IllegalArgumentException();
+      }
+
+      //
+      if (!listeners.contains(listener))
+      {
+         listeners.add(listener);
+      }
+   }
+
    /**
     * @return
     */
@@ -157,4 +179,19 @@
       
       return isAllowedAsChild;
    }
+
+   protected void fireEvent(ModelEvent event)
+   {
+      for (ModelListener listener : listeners)
+      {
+         try
+         {
+            listener.onEvent(event);
+         }
+         catch (Exception ignore)
+         {
+            System.out.println("ignore = " + ignore);
+         }
+      }
+   }
 }

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-11-29 12:30:00 UTC (rev 9193)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -24,8 +24,11 @@
 
 import org.jboss.portal.presentation.model.StateScopeType;
 import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.state.StateChange;
+import org.jboss.portal.presentation.model.state.StateChangeEvent;
 import org.jboss.portal.presentation.model.state.StateChangeVetoException;
 import org.jboss.portal.presentation.model.state.structural.StructuralState;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateModification;
 
 import java.io.Serializable;
 import java.util.HashMap;
@@ -167,10 +170,20 @@
             {
                Map<String, String> changes = new HashMap<String, String>();
                changes.put(propertyName, (String)propertyValue);
-               context.getModelLoader().update(id, changes);
+
+               // Have loader process state
+               StructuralStateModification mod = new StructuralStateModification.SetProperties(changes);
+               StateChange<StructuralStateModification> change = new StateChange<StructuralStateModification>(id, mod);
+               context.getModelLoader().update(change);
+
+               // Update state locally
                Map<String, String> updatedProperties = new HashMap<String, String>(state.getProperties());
                updateProperty(updatedProperties, propertyName, (String)propertyValue);
                state = new StructuralState(state.getType(), state.getName(), updatedProperties, state.getParentId(), state.getChildrenIds());
+
+               // Broadcast event
+               StateChangeEvent event = new StateChangeEvent(change);
+               context.fireEvent(event);
             }
             else
             {

Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/ModelEvent.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/ModelEvent.java	                        (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/ModelEvent.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -0,0 +1,31 @@
+/******************************************************************************
+ * 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;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class ModelEvent
+{
+}

Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/ModelListener.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/ModelListener.java	                        (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/ModelListener.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -0,0 +1,32 @@
+/******************************************************************************
+ * 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;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface ModelListener
+{
+   void onEvent(ModelEvent event);
+}

Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIContext.java	2007-11-29 12:30:00 UTC (rev 9193)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIContext.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -28,18 +28,24 @@
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
  * @version $Revision: 1.1 $
  */
-public interface UIContext extends UIObject 
+public interface UIContext extends UIObject
 {
    /**
     * 
-    * @param id
-    * @return
+    * @param id the object id
+    * @return the object for the specified id or null if it cannot be found
     */
    UIObject getObject(String id);
    
    /**
     * 
-    * @return
+    * @return the model loader
     */
    StructuralStateContext getModelLoader();
+
+   /**
+    *
+    * @param listener the listener
+    */
+   void addModelListener(ModelListener listener);
 }

Added: 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	                        (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChange.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -0,0 +1,63 @@
+/******************************************************************************
+ * 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;
+
+/**
+ * @author <a href="mailto:julien at 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;
+   }
+
+   public String getTargetId()
+   {
+      return targetId;
+   }
+
+   public M getModification()
+   {
+      return modification;
+   }
+}

Added: 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	                        (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChangeEvent.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -0,0 +1,52 @@
+/******************************************************************************
+ * 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;
+
+/**
+ * @author <a href="mailto:julien at 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;
+   }
+
+   public StateChange getChange()
+   {
+      return change;
+   }
+}

Added: 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	                        (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateModification.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -0,0 +1,31 @@
+/******************************************************************************
+ * 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;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class StateModification
+{
+}

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-11-29 12:30:00 UTC (rev 9193)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -23,10 +23,12 @@
 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.StateChange;
 import org.jboss.portal.presentation.model.state.StateChangeVetoException;
 import org.jboss.portal.presentation.model.state.StateException;
-import org.jboss.portal.presentation.model.state.NoSuchStateException;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -54,6 +56,10 @@
     */
    String getRootId();
 
+   void update(List<StateChange<StructuralStateModification>> modifications);
+
+   void update(StateChange<StructuralStateModification> modification);
+
    /**
     * Create an object.
     *

Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateManager.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateManager.java	2007-11-29 12:30:00 UTC (rev 9193)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateManager.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -1,111 +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.UIObject;
-import org.jboss.portal.presentation.model.state.StateChangeVetoException;
-import org.jboss.portal.presentation.model.state.StateException;
-import org.jboss.portal.presentation.model.state.NoSuchStateException;
-
-import java.util.Map;
-
-/**
- * The structural state manager.
- * 
- * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public interface StructuralStateManager
-{
-
-   /**
-    * Load the state of a 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
-    */
-   StructuralState load(String objectId) throws IllegalArgumentException;
-
-   /**
-    * Returns the id of the root object.
-    *
-    * @return the id of the root object.
-    */
-   String getRootId();
-
-   /**
-    * Create an object.
-    *
-    * @param parentId the id of the parent object
-    * @param type the type of the child
-    * @param name the name of the child
-    * @param properties the initial properties of the child
-    * @return the structural state of the child
-    * @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
-    * @throws IllegalArgumentException if an argument is null or not valid
-    */
-   StructuralState create(String parentId, Class<? extends UIObject> type, String name, Map<String, String> properties) throws StateChangeVetoException, StateException, IllegalArgumentException;
-
-   /**
-    * Destroy a specified object.
-    *
-    * @param objectId the object id 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
-    */
-   void destroy(String objectId) throws StateChangeVetoException, StateException, IllegalArgumentException;
-
-   /**
-    * Move an object to a new parent.
-    *
-    * @param objectId the object id to move
-    * @param parentId the id of the new parent
-    * @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 move(String objectId, String parentId) throws StateChangeVetoException, StateException, IllegalArgumentException;
-
-   /**
-    * Update the state of a specified object. 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>
-    *  
-    * @param objectId the id of 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
-    * @throws IllegalArgumentException if an argument is null or not valid
-    */
-   void update(String objectId, Map<String, String> changes) throws StateChangeVetoException, StateException, IllegalArgumentException;
-
-}

Added: 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	                        (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -0,0 +1,58 @@
+/******************************************************************************
+ * 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 java.util.Map;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class StructuralStateModification extends StateModification
+{
+
+   public static class SetProperties extends StructuralStateModification
+   {
+
+      /** . */
+      private final Map<String, String> changes;
+
+      public SetProperties(Map<String, String> changes)
+      {
+         if (changes == null)
+         {
+            throw new IllegalArgumentException();
+         }
+
+         //
+         this.changes = changes;
+      }
+
+      public Map<String, String> getChanges()
+      {
+         return changes;
+      }
+   }
+}

Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java	                        (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -0,0 +1,76 @@
+/******************************************************************************
+ * 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;
+
+import junit.framework.Assert;
+import org.jboss.portal.presentation.model.ModelEvent;
+import org.jboss.portal.presentation.model.ModelListener;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateModification;
+import org.jboss.portal.presentation.model.state.StateChangeEvent;
+import org.jboss.portal.presentation.model.state.StateChange;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class EventAssert implements ModelListener
+{
+
+   /** . */
+   private final List<ModelEvent> events = new ArrayList<ModelEvent>();
+
+   /** . */
+   private int index = 0;
+
+   public void onEvent(ModelEvent event)
+   {
+      events.add(event);
+   }
+
+   public <T> T next(Class<T> clazz)
+   {
+      Assert.assertTrue(index < events.size());
+      ModelEvent event = events.get(index++);
+      Assert.assertNotNull(event);
+      Assert.assertTrue(clazz.isInstance(event));
+      return clazz.cast(event);
+   }
+
+   public void next(String targetId, StructuralStateModification.SetProperties sp)
+   {
+      StateChangeEvent ste = next(StateChangeEvent.class);
+      StateChange change = ste.getChange();
+      Assert.assertEquals(targetId, change.getTargetId());
+      StructuralStateModification.SetProperties mod = (StructuralStateModification.SetProperties)change.getModification();
+      Assert.assertEquals(sp.getChanges(), mod.getChanges());
+   }
+
+   public void assertEmpty()
+   {
+      Assert.assertEquals(events.size(), index);
+   }
+}

Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java	2007-11-29 12:30:00 UTC (rev 9193)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -26,14 +26,17 @@
 import org.jboss.portal.presentation.model.state.NoSuchStateException;
 import org.jboss.portal.presentation.model.state.StateChangeVetoException;
 import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.StateChange;
 import org.jboss.portal.presentation.model.state.structural.StructuralState;
 import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateModification;
 
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
+import java.util.List;
 
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
@@ -63,46 +66,27 @@
          return object != null ? object.takeSnapshot() : null;
       }
 
-      public String getRootId()
+      public void update(List<StateChange<StructuralStateModification>> changes)
       {
-         return root.id;
+         for (StateChange<StructuralStateModification> change : changes)
+         {
+            update(change);
+         }
       }
 
-      public StructuralState create(String parentId, Class<? extends UIObject> type, String name, Map<String, String> properties) throws StateChangeVetoException
+      public void update(StateChange<StructuralStateModification> change)
       {
-         throw new StateChangeVetoException();
-      }
+         StructuralStateModification.SetProperties sp = (StructuralStateModification.SetProperties)change.getModification();
 
-      public void destroy(String objectId) throws StateChangeVetoException
-      {
-         throw new StateChangeVetoException();
-      }
-
-      public void move(String objectId, String parentId) throws StateChangeVetoException
-      {
-         throw new StateChangeVetoException();
-      }
-
-      public void update(String objectId, Map<String, String> changes) throws StateChangeVetoException
-      {
-         if (objectId == null)
-         {
-            throw new IllegalArgumentException();
-         }
-         if (changes == null)
-         {
-            throw new IllegalArgumentException();
-         }
-
          //
-         MockObjectImpl object = universe.get(objectId);
+         MockObjectImpl object = universe.get(change.getTargetId());
          if (object == null)
          {
             throw new NoSuchStateException();
          }
 
          //
-         for (Map.Entry<String, String> entry : changes.entrySet())
+         for (Map.Entry<String, String> entry : sp.getChanges().entrySet())
          {
             String propertyName = entry.getKey();
             MockObject.UpdateBehavior behavior = object.propertyBehaviors.get(propertyName);
@@ -131,6 +115,31 @@
             }
          }
       }
+
+      public String getRootId()
+      {
+         return root.id;
+      }
+
+      public StructuralState create(String parentId, Class<? extends UIObject> type, String name, Map<String, String> properties) throws StateChangeVetoException
+      {
+         throw new StateChangeVetoException();
+      }
+
+      public void destroy(String objectId) throws StateChangeVetoException
+      {
+         throw new StateChangeVetoException();
+      }
+
+      public void move(String objectId, String parentId) throws StateChangeVetoException
+      {
+         throw new StateChangeVetoException();
+      }
+
+      public void update(String objectId, Map<String, String> changes) throws StateChangeVetoException
+      {
+         update(new StateChange<StructuralStateModification>(objectId, new StructuralStateModification.SetProperties(changes)));
+      }
    };
 
    public StructuralStateContext getStructuralStateContext()

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-11-29 12:30:00 UTC (rev 9193)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java	2007-11-29 13:16:38 UTC (rev 9194)
@@ -34,7 +34,10 @@
 import org.jboss.portal.presentation.model.UIPage;
 import org.jboss.portal.presentation.model.UIPortal;
 import org.jboss.portal.presentation.model.state.NoSuchStateException;
+import org.jboss.portal.presentation.model.state.StateChange;
+import org.jboss.portal.presentation.model.state.StateChangeEvent;
 import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateModification;
 
 import java.util.Collections;
 import java.util.List;
@@ -304,17 +307,21 @@
    public void testUpdateExistingMutableStructuralProperty()
    {
       MockObject mockFoo = model.getRoot().addChild("foo", MockObject.Type.PORTAL);
+      String fooId = mockFoo.getId();
       mockFoo.setPropertyValue("foo", "foo_value");
       UIContext context = createContext();
+      EventAssert eventAssert = new EventAssert();
+      context.addModelListener(eventAssert);
 
       // Check initial state
-      UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
+      UIPortal foo = (UIPortal)context.getObject(fooId);
       PropertyAssert fooAssert = new PropertyAssert(foo);
       fooAssert.assertStructuralEquals("foo", "foo_value");
 
       // Update structural property
       foo.setProperty(StateScopeType.STRUCTURAL, "foo", "foo_new_value");
       fooAssert.assertStructuralEquals("foo", "foo_new_value");
+      eventAssert.next(fooId, new StructuralStateModification.SetProperties(Collections.singletonMap("foo", "foo_new_value")));
 
       // Try a non string type
       try
@@ -326,17 +333,20 @@
       {
       }
       fooAssert.assertStructuralEquals("foo", "foo_new_value");
+      eventAssert.assertEmpty();
    }
 
    public void testUpdateExistingNonMutableStructuralProperty()
    {
       MockObject mockFoo = model.getRoot().addChild("foo", MockObject.Type.PORTAL);
+      String fooId = mockFoo.getId();
       mockFoo.setPropertyValue("foo", "foo_value");
       mockFoo.setPropertyBehavior("foo", MockObject.Failure.veto());
       UIContext context = createContext();
+      EventAssert eventAssert = new EventAssert();
 
       // Check initial state
-      UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
+      UIPortal foo = (UIPortal)context.getObject(fooId);
       PropertyAssert fooAssert = new PropertyAssert(foo);
       fooAssert.assertStructuralEquals("foo", "foo_value");
 
@@ -350,6 +360,7 @@
       {
       }
       fooAssert.assertStructuralEquals("foo", "foo_value");
+      eventAssert.assertEmpty();
 
       // Try a non string type
       try
@@ -361,21 +372,26 @@
       {
       }
       fooAssert.assertStructuralEquals("foo", "foo_value");
+      eventAssert.assertEmpty();
    }
 
    public void testUpdateNonExistingMutableStructuralProperty()
    {
       MockObject mockFoo = model.getRoot().addChild("foo", MockObject.Type.PORTAL);
+      String fooId = mockFoo.getId();
       UIContext context = createContext();
+      EventAssert eventAssert = new EventAssert();
+      context.addModelListener(eventAssert);
 
       // Check initial state
-      UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
+      UIPortal foo = (UIPortal)context.getObject(fooId);
       PropertyAssert fooAssert = new PropertyAssert(foo);
       fooAssert.assertStructuralEquals("foo", null);
 
       // Update structural property
       foo.setProperty(StateScopeType.STRUCTURAL, "foo", "foo_new_value");
       fooAssert.assertStructuralEquals("foo", "foo_new_value");
+      eventAssert.next(fooId, new StructuralStateModification.SetProperties(Collections.singletonMap("foo", "foo_new_value")));
 
       // Try a non string type
       try
@@ -387,6 +403,7 @@
       {
       }
       fooAssert.assertStructuralEquals("foo", "foo_new_value");
+      eventAssert.assertEmpty();
    }
 
    public void testUpdateNonExistingNonMutableStructuralProperty()
@@ -394,6 +411,8 @@
       MockObject mockFoo = model.getRoot().addChild("foo", MockObject.Type.PORTAL);
       mockFoo.setPropertyBehavior("foo", MockObject.Failure.veto());
       UIContext context = createContext();
+      EventAssert eventAssert = new EventAssert();
+      context.addModelListener(eventAssert);
 
       // Check initial state
       UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
@@ -410,6 +429,7 @@
       {
       }
       fooAssert.assertStructuralEquals("foo", null);
+      eventAssert.assertEmpty();
 
       // Try a non string type
       try
@@ -421,6 +441,7 @@
       {
       }
       fooAssert.assertStructuralEquals("foo", null);
+      eventAssert.assertEmpty();
    }
 
    public void testUpdateContentProperty()




More information about the portal-commits mailing list