[portal-commits] JBoss Portal SVN: r9200 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: model/state/structural and 1 other directories.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Thu Nov 29 09:19:53 EST 2007


Author: julien at jboss.com
Date: 2007-11-29 09:19:53 -0500 (Thu, 29 Nov 2007)
New Revision: 9200

Added:
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java
Modified:
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.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 other modification for structural state (although not implemented)
- added AbstractStructualStateContext for abstracting stuff that does not depend on the nature of the implementation

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 14:15:23 UTC (rev 9199)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java	2007-11-29 14:19:53 UTC (rev 9200)
@@ -178,7 +178,7 @@
                changes.put(propertyName, (String)propertyValue);
 
                // Create change
-               StructuralStateModification mod = new StructuralStateModification.SetProperties(changes);
+               StructuralStateModification mod = new StructuralStateModification.Update(changes);
                StateChange<StructuralStateModification> change = new StateChange<StructuralStateModification>(id, mod);
 
                // Have context process change

Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java	                        (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java	2007-11-29 14:19:53 UTC (rev 9200)
@@ -0,0 +1,69 @@
+/******************************************************************************
+ * 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.StateChange;
+import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.UIObject;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class AbstractStructuralStateContext implements StructuralStateContext
+{
+
+   public void update(List<StateChange<StructuralStateModification>> changes)
+   {
+      for (StateChange<StructuralStateModification> change : changes)
+      {
+         update(change);
+      }
+   }
+
+   public StructuralState create(String parentId, Class<? extends UIObject> type, String name, Map<String, String> properties) throws StateChangeVetoException
+   {
+      update(new StateChange<StructuralStateModification>(parentId, new StructuralStateModification.Create(type, name, properties)));
+
+      //
+      return load(parentId);
+   }
+
+   public void destroy(String objectId) throws StateChangeVetoException
+   {
+      update(new StateChange<StructuralStateModification>(objectId, new StructuralStateModification.Destroy()));
+   }
+
+   public void move(String objectId, String parentId) throws StateChangeVetoException
+   {
+      update(new StateChange<StructuralStateModification>(objectId, new StructuralStateModification.Move(parentId)));
+   }
+
+   public void update(String objectId, Map<String, String> changes) throws StateChangeVetoException
+   {
+      update(new StateChange<StructuralStateModification>(objectId, new StructuralStateModification.Update(changes)));
+   }
+}

Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java	2007-11-29 14:15:23 UTC (rev 9199)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java	2007-11-29 14:19:53 UTC (rev 9200)
@@ -23,6 +23,7 @@
 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;
 
@@ -40,19 +41,79 @@
    }
 
    /**
+    * Destruction of an object.
+    */
+   public final static class Destroy extends StructuralStateModification
+   {
+   }
+
+   public final static class Create extends StructuralStateModification
+   {
+
+      /** . */
+      private final Class<? extends UIObject> type;
+
+      /** . */
+      private final String name;
+
+      /** . */
+      private final Map<String, String> properties;
+
+      public Create(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 parentId;
+
+      public Move(String parentId)
+      {
+         this.parentId = parentId;
+      }
+
+      public String getParentId()
+      {
+         return parentId;
+      }
+   }
+
+
+   /**
     * 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 SetProperties extends StructuralStateModification
+   public final static class Update extends StructuralStateModification
    {
 
       /** . */
       private final Map<String, String> changes;
 
-      public SetProperties(Map<String, String> changes)
+      public Update(Map<String, String> changes)
       {
          if (changes == null)
          {

Modified: 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	2007-11-29 14:15:23 UTC (rev 9199)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java	2007-11-29 14:19:53 UTC (rev 9200)
@@ -60,12 +60,12 @@
       return clazz.cast(event);
    }
 
-   public void next(String targetId, StructuralStateModification.SetProperties sp)
+   public void next(String targetId, StructuralStateModification.Update sp)
    {
       StateChangeEvent ste = next(StateChangeEvent.class);
       StateChange change = ste.getChange();
       Assert.assertEquals(targetId, change.getTargetId());
-      StructuralStateModification.SetProperties mod = (StructuralStateModification.SetProperties)change.getModification();
+      StructuralStateModification.Update mod = (StructuralStateModification.Update)change.getModification();
       Assert.assertEquals(sp.getChanges(), mod.getChanges());
    }
 

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 14:15:23 UTC (rev 9199)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java	2007-11-29 14:19:53 UTC (rev 9200)
@@ -22,11 +22,11 @@
  ******************************************************************************/
 package org.jboss.portal.presentation.test.model;
 
-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.StateChange;
+import org.jboss.portal.presentation.model.state.structural.AbstractStructuralStateContext;
 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;
@@ -36,7 +36,6 @@
 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>
@@ -54,7 +53,7 @@
    /** . */
    private final MockObjectImpl root = new MockObjectImpl();
 
-   private final StructuralStateContext structuralStateContext = new StructuralStateContext()
+   private final StructuralStateContext structuralStateContext = new AbstractStructuralStateContext()
    {
       public StructuralState load(String objectId) throws IllegalArgumentException
       {
@@ -66,80 +65,59 @@
          return object != null ? object.takeSnapshot() : null;
       }
 
-      public void update(List<StateChange<StructuralStateModification>> changes)
-      {
-         for (StateChange<StructuralStateModification> change : changes)
-         {
-            update(change);
-         }
-      }
-
       public void update(StateChange<StructuralStateModification> change)
       {
-         StructuralStateModification.SetProperties sp = (StructuralStateModification.SetProperties)change.getModification();
-
-         //
-         MockObjectImpl object = universe.get(change.getTargetId());
-         if (object == null)
+         if (change.getModification() instanceof StructuralStateModification.Update)
          {
-            throw new NoSuchStateException();
-         }
+            StructuralStateModification.Update sp = (StructuralStateModification.Update)change.getModification();
 
-         //
-         for (Map.Entry<String, String> entry : sp.getChanges().entrySet())
-         {
-            String propertyName = entry.getKey();
-            MockObject.UpdateBehavior behavior = object.propertyBehaviors.get(propertyName);
-            if (behavior instanceof MockObject.Veto)
+            //
+            MockObjectImpl object = universe.get(change.getTargetId());
+            if (object == null)
             {
-               throw new StateChangeVetoException("Cannot modify non behavior property");
+               throw new NoSuchStateException();
             }
-            else if (behavior instanceof MockObject.Failure)
+
+            //
+            for (Map.Entry<String, String> entry : sp.getChanges().entrySet())
             {
-               MockObject.Failure failure = (MockObject.Failure)behavior;
-               failure.throwAs(IllegalArgumentException.class).
-                       throwAs(StateChangeVetoException.class).
-                       throwAs(StateException.class);
-            }
-            else
-            {
-               String propertyValue = entry.getValue();
-               if (propertyValue != null)
+               String propertyName = entry.getKey();
+               MockObject.UpdateBehavior behavior = object.propertyBehaviors.get(propertyName);
+               if (behavior instanceof MockObject.Veto)
                {
-                  object.propertyValues.put(propertyName, propertyValue);
+                  throw new StateChangeVetoException("Cannot modify non behavior property");
                }
+               else if (behavior instanceof MockObject.Failure)
+               {
+                  MockObject.Failure failure = (MockObject.Failure)behavior;
+                  failure.throwAs(IllegalArgumentException.class).
+                          throwAs(StateChangeVetoException.class).
+                          throwAs(StateException.class);
+               }
                else
                {
-                  object.propertyValues.remove(propertyName);
+                  String propertyValue = entry.getValue();
+                  if (propertyValue != null)
+                  {
+                     object.propertyValues.put(propertyName, propertyValue);
+                  }
+                  else
+                  {
+                     object.propertyValues.remove(propertyName);
+                  }
                }
             }
          }
+         else
+         {
+            throw new StateChangeVetoException();
+         }
       }
 
       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 14:15:23 UTC (rev 9199)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java	2007-11-29 14:19:53 UTC (rev 9200)
@@ -313,7 +313,7 @@
       // 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")));
+      eventAssert.next(fooId, new StructuralStateModification.Update(Collections.singletonMap("foo", "foo_new_value")));
 
       // Try a non string type
       try
@@ -383,7 +383,7 @@
       // 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")));
+      eventAssert.next(fooId, new StructuralStateModification.Update(Collections.singletonMap("foo", "foo_new_value")));
 
       // Try a non string type
       try




More information about the portal-commits mailing list