Author: julien(a)jboss.com
Date: 2007-12-03 17:09:21 -0500 (Mon, 03 Dec 2007)
New Revision: 9256
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/MockObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectImpl.java
Log:
better state encapsulation of MockeObjectImpl
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-03
21:56:04 UTC (rev 9255)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2007-12-03
22:09:21 UTC (rev 9256)
@@ -64,21 +64,8 @@
{
MockObjectImpl object = universe.remove(objectId);
- // Remove children recursively
- for (String childId : new ArrayList<String>(object.children.keySet()))
- {
- destroy(childId);
- }
-
- // Detach from parent
- if (object.parent != null)
- {
- object.parent.children.remove(object.id);
- object.parent = null;
- }
-
- // We cannot use it anymore
- object.valid = false;
+ //
+ object.destroy();
}
MockObjectImpl createObject(MockObject.Type type, String name)
@@ -117,7 +104,7 @@
for (Map.Entry<String, String> entry : changes.entrySet())
{
String propertyName = entry.getKey();
- MockObject.UpdateBehavior behavior =
object.propertyBehaviors.get(propertyName);
+ MockObject.UpdateBehavior behavior =
object.getPropertyBehavior(propertyName);
if (behavior instanceof MockObject.Veto)
{
throw new StateChangeVetoException("Cannot modify non behavior
property");
@@ -131,15 +118,7 @@
}
else
{
- String propertyValue = entry.getValue();
- if (propertyValue != null)
- {
- object.propertyValues.put(propertyName, propertyValue);
- }
- else
- {
- object.propertyValues.remove(propertyName);
- }
+ object.setPropertyValue(propertyName, entry.getValue());
}
}
}
@@ -149,7 +128,7 @@
StructuralObjectImpl mockStructuralObject = (StructuralObjectImpl)object;
MockObjectImpl mockObject = universe.get(mockStructuralObject.getId());
List<StructuralObject> tmp = new ArrayList<StructuralObject>();
- for (MockObjectImpl mockChild : mockObject.children.values())
+ for (MockObject mockChild : mockObject.getChildren())
{
tmp.add(mockChild.takeSnapshot());
}
@@ -160,7 +139,7 @@
{
StructuralObjectImpl mockStructuralObject = (StructuralObjectImpl)object;
MockObjectImpl mockObject = universe.get(mockStructuralObject.getId());
- return mockObject.parent.takeSnapshot();
+ return mockObject.getParent().takeSnapshot();
}
};
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java 2007-12-03
21:56:04 UTC (rev 9255)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java 2007-12-03
22:09:21 UTC (rev 9256)
@@ -29,6 +29,7 @@
import org.jboss.portal.presentation.model.UIWindow;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import java.util.List;
import java.util.Set;
/**
@@ -109,6 +110,12 @@
Set<String> getPropertyNames();
MockObject addChild(String name, Type type);
+
+ MockObject getParent();
+
+ List<MockObject> getChildren();
boolean isValid();
+
+ StructuralObject takeSnapshot();
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2007-12-03
21:56:04 UTC (rev 9255)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2007-12-03
22:09:21 UTC (rev 9256)
@@ -24,9 +24,12 @@
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
-import java.util.LinkedHashMap;
-import java.util.HashMap;
import java.util.Set;
/**
@@ -37,32 +40,35 @@
{
/** . */
- final MockObject.Type type;
+ private final MockObject.Type type;
/** . */
- final String name;
+ private final String name;
/** . */
- final String id;
+ private final String id;
/** . */
- final Map<String, String> propertyValues;
+ private final Map<String, String> propertyValues;
/** . */
- final Map<String, UpdateBehavior> propertyBehaviors;
+ private final Map<String, UpdateBehavior> propertyBehaviors;
/** . */
- final Map<String, MockObjectImpl> children;
+ private final LinkedHashMap<String, MockObjectImpl> children;
/** . */
- final MockModel model;
+ private final MockModel model;
/** . */
- MockObjectImpl parent;
+ private MockObjectImpl parent;
/** . */
- boolean valid;
+ private boolean valid;
+ /** The version id. */
+ int version;
+
MockObjectImpl(MockModel model, String name, MockObject.Type type, String id)
{
this.model = model;
@@ -73,6 +79,7 @@
this.propertyBehaviors = new HashMap<String, UpdateBehavior>();
this.id = id;
this.valid = true;
+ this.version = 0;
}
public MockObject.Type getType()
@@ -100,6 +107,16 @@
return propertyValues.get(propertyName);
}
+ public MockObject getParent()
+ {
+ return parent;
+ }
+
+ public List<MockObject> getChildren()
+ {
+ return Collections.unmodifiableList(new
ArrayList<MockObject>(children.values()));
+ }
+
public MockObject addChild(String name, MockObject.Type type)
{
if (name == null)
@@ -164,10 +181,33 @@
{
propertyValues.remove(propertyName);
}
+
+ //
+ this.version++;
}
- StructuralObject takeSnapshot()
+ public StructuralObject takeSnapshot()
{
- return new StructuralObjectImpl(id, new StructuralStateImpl(type.clazz, name, new
HashMap<String, String>(propertyValues)));
+ return new StructuralObjectImpl(id, version, new StructuralStateImpl(type.clazz,
name, new HashMap<String, String>(propertyValues)));
}
+
+ void destroy()
+ {
+ // Remove children recursively
+ for (String childId : new ArrayList<String>(children.keySet()))
+ {
+ model.destroy(childId);
+ }
+
+ // Detach from parent
+ if (parent != null)
+ {
+ parent.children.remove(id);
+ parent = null;
+ }
+
+ // We cannot use it anymore
+ valid = false;
+ }
+
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectImpl.java 2007-12-03
21:56:04 UTC (rev 9255)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectImpl.java 2007-12-03
22:09:21 UTC (rev 9256)
@@ -33,14 +33,18 @@
{
/** . */
- private final String id;
+ final String id;
/** . */
+ final int version;
+
+ /** . */
private final StructuralStateImpl state;
- public StructuralObjectImpl(String id, StructuralStateImpl state)
+ public StructuralObjectImpl(String id, int version, StructuralStateImpl state)
{
this.id = id;
+ this.version = version;
this.state = state;
}