Author: julien(a)jboss.com
Date: 2007-12-04 10:45:20 -0500 (Tue, 04 Dec 2007)
New Revision: 9283
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChange.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChangeEvent.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateModification.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/navigational/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/navigational/NavigationalStateModification.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/structural/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/structural/StructuralStateModification.java
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/state/navigational/NavigationalStateContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateContext.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/ModelTestCase.java
Log:
move model event related stuff in an model.event package
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-04
15:32:16 UTC (rev 9282)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-04
15:45:20 UTC (rev 9283)
@@ -24,12 +24,12 @@
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.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.state.StateChangeVetoException;
-import
org.jboss.portal.presentation.model.state.navigational.NavigationalStateModification;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
-import org.jboss.portal.presentation.model.state.structural.StructuralStateModification;
+import org.jboss.portal.presentation.model.event.structural.StructuralStateModification;
import java.io.Serializable;
import java.util.Collections;
@@ -134,7 +134,6 @@
{
throw new IllegalArgumentException();
}
- Map map;
Object value;
switch (scopeType)
{
@@ -165,17 +164,21 @@
{
throw new IllegalArgumentException();
}
+
+ //
+ String id = getId();
+
+ //
switch (scopeType)
{
case NAVIGATIONAL:
{
- NavigationalStateModification mod = new
NavigationalStateModification(propertyName, propertyValue);
- StateChange<NavigationalStateModification> change = new
StateChange<NavigationalStateModification>(getId(), mod);
-
// Have context process the change
- context.navigationalStateContext.update(change);
+ context.navigationalStateContext.set(id, propertyName, propertyValue);
// Broadcast event
+ NavigationalStateModification mod = new
NavigationalStateModification(propertyName, propertyValue);
+ StateChange<NavigationalStateModification> change = new
StateChange<NavigationalStateModification>(id, mod);
StateChangeEvent event = new StateChangeEvent(change);
context.fireEvent(event);
break;
@@ -195,7 +198,7 @@
// Broadcast event
StructuralStateModification mod = new
StructuralStateModification.Update(changes);
- StateChange<StructuralStateModification> change = new
StateChange<StructuralStateModification>(getId(), mod);
+ StateChange<StructuralStateModification> change = new
StateChange<StructuralStateModification>(id, mod);
StateChangeEvent event = new StateChangeEvent(change);
context.fireEvent(event);
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/state/navigational/NavigationalStateContextImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/state/navigational/NavigationalStateContextImpl.java 2007-12-04
15:32:16 UTC (rev 9282)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/state/navigational/NavigationalStateContextImpl.java 2007-12-04
15:45:20 UTC (rev 9283)
@@ -23,14 +23,11 @@
package org.jboss.portal.presentation.impl.model.state.navigational;
import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
-import
org.jboss.portal.presentation.model.state.navigational.NavigationalStateModification;
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 java.util.Map;
import java.util.HashMap;
-import java.util.List;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -52,35 +49,21 @@
this(new HashMap<Key, Object>());
}
- public void update(List<StateChange<NavigationalStateModification>>
changes)
+ public void set(String objectId, String key, Object navigationalState) throws
StateChangeVetoException, StateException, IllegalArgumentException
{
- for (StateChange<NavigationalStateModification> change : changes)
- {
- update(change);
- }
- }
+ Key key2 = new Key(objectId, key);
- public void update(StateChange<NavigationalStateModification> change)
- {
- Key key = new Key(change.getTargetId(), change.getModification().getKey());
- Object navigationalState = change.getModification().getNavigationalState();
-
//
if (navigationalState != null)
{
- map.put(key, navigationalState);
+ map.put(key2, navigationalState);
}
else
{
- map.remove(key);
+ map.remove(key2);
}
}
- public void set(String objectId, String key, Object navigationalState) throws
StateChangeVetoException, StateException, IllegalArgumentException
- {
- update(new StateChange<NavigationalStateModification>(objectId, new
NavigationalStateModification(key, navigationalState)));
- }
-
public Object get(String objectId, String key) throws IllegalArgumentException
{
return map.get(new Key(objectId, key));
Copied:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChange.java
(from rev 9227,
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChange.java)
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChange.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChange.java 2007-12-04
15:45:20 UTC (rev 9283)
@@ -0,0 +1,79 @@
+/******************************************************************************
+ * 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.event;
+
+import org.jboss.portal.presentation.model.event.StateModification;
+
+/**
+ * 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;
+ }
+}
Copied:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChangeEvent.java
(from rev 9227,
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateChangeEvent.java)
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChangeEvent.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChangeEvent.java 2007-12-04
15:45:20 UTC (rev 9283)
@@ -0,0 +1,60 @@
+/******************************************************************************
+ * 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.event;
+
+import org.jboss.portal.presentation.model.ModelEvent;
+import org.jboss.portal.presentation.model.event.StateChange;
+
+/**
+ * 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;
+ }
+}
Copied:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateModification.java
(from rev 9227,
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateModification.java)
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateModification.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateModification.java 2007-12-04
15:45:20 UTC (rev 9283)
@@ -0,0 +1,33 @@
+/******************************************************************************
+ * 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.event;
+
+/**
+ * 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
+{
+}
Copied:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/navigational/NavigationalStateModification.java
(from rev 9227,
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateModification.java)
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/navigational/NavigationalStateModification.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/navigational/NavigationalStateModification.java 2007-12-04
15:45:20 UTC (rev 9283)
@@ -0,0 +1,61 @@
+/******************************************************************************
+ * 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.event.navigational;
+
+import org.jboss.portal.presentation.model.event.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;
+ }
+}
Copied:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/structural/StructuralStateModification.java
(from rev 9281,
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java)
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/structural/StructuralStateModification.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/structural/StructuralStateModification.java 2007-12-04
15:45:20 UTC (rev 9283)
@@ -0,0 +1,136 @@
+/******************************************************************************
+ * 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.event.structural;
+
+import org.jboss.portal.presentation.model.event.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/model/state/navigational/NavigationalStateContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateContext.java 2007-12-04
15:32:16 UTC (rev 9282)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateContext.java 2007-12-04
15:45:20 UTC (rev 9283)
@@ -22,12 +22,8 @@
******************************************************************************/
package org.jboss.portal.presentation.model.state.navigational;
-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 java.util.List;
-
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
@@ -36,9 +32,6 @@
{
Object get(String objectId, String key) throws IllegalArgumentException;
- void set(String objectId, String key, Object navigationalState) throws
StateChangeVetoException, StateException, IllegalArgumentException;
+ void set(String objectId, String key, Object navigationalState) throws StateException,
IllegalArgumentException;
- void update(List<StateChange<NavigationalStateModification>>
modifications);
-
- void update(StateChange<NavigationalStateModification> modification);
}
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-12-04
15:32:16 UTC (rev 9282)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java 2007-12-04
15:45:20 UTC (rev 9283)
@@ -25,10 +25,10 @@
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.StateChange;
-import org.jboss.portal.presentation.model.state.StateChangeEvent;
-import
org.jboss.portal.presentation.model.state.navigational.NavigationalStateModification;
-import org.jboss.portal.presentation.model.state.structural.StructuralStateModification;
+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 java.util.ArrayList;
import java.util.List;
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-04
15:32:16 UTC (rev 9282)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-04
15:45:20 UTC (rev 9283)
@@ -32,11 +32,10 @@
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIPage;
import org.jboss.portal.presentation.model.UIPortal;
+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.StructuralStateModification;
import org.jboss.portal.presentation.test.model.state.structural.MockModel;
import org.jboss.portal.presentation.test.model.state.structural.MockObject;