Author: julien(a)jboss.com
Date: 2007-12-27 06:16:19 -0500 (Thu, 27 Dec 2007)
New Revision: 9388
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
better implementation of model validation
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java 2007-12-26
17:08:59 UTC (rev 9387)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java 2007-12-27
11:16:19 UTC (rev 9388)
@@ -417,10 +417,9 @@
{
}
- public boolean enterChildren(UIObject object)
+ public boolean enterChildren(UIObject object, boolean loaded)
{
return false;
}
};
-
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-26
17:08:59 UTC (rev 9387)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-27
11:16:19 UTC (rev 9388)
@@ -30,6 +30,7 @@
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
+import org.jboss.portal.presentation.model.state.StateException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -37,6 +38,8 @@
import java.util.Map;
import java.util.AbstractList;
import java.util.Iterator;
+import java.util.Set;
+import java.util.HashSet;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -291,72 +294,117 @@
void validate(UIManagedObject object, UIObject.Visitor scope)
{
-// if (scope.enterObject(object))
-// {
-// try
-// {
-// structuralStateContext.validate(object.context.structuralObject);
-// }
-// catch (StateException e)
-// {
-// object.context.updateStatus(e);
-// }
-//
-// //
-// if (object.context.isValid())
-// {
-// if (scope.enterChildren(object))
-// {
-// for (AbstractUIObject child : object.childrenAssociation)
-// {
-// validate(child, scope);
-// }
-// }
-// }
-//
-// //
-// scope.leaveObject(object);
-// }
+ if (scope.enterObject(object))
+ {
+ UIObjectContext context = object.context;
+
+ // We do it only if it is not yet invalid
+ if (context.isValid())
+ {
+ // Validate
+ try
+ {
+ structuralStateContext.validate(context.structuralObject);
+ }
+ catch (StateException e)
+ {
+ context.updateStatus(e);
+ }
+
+ // Continue only if it is valid
+ if (context.isValid())
+ {
+ boolean loaded = context.children.relateds != null;
+
+ // Loading children will never make the current object invalid
+ // but it could make some already loaded children invalid
+ if (scope.enterChildren(object, loaded))
+ {
+ for (UIContainerObject child : context.children.get())
+ {
+ validate(child.getContext().managedObject, scope);
+ }
+ }
+ }
+
+ //
+ scope.leaveObject(object);
+ }
+ }
}
void refresh(UIManagedObject object, UIObject.Visitor scope)
{
-
-
if (scope.enterObject(object))
{
- switch (object.context.status)
+ UIObjectContext context = object.context;
+
+ //
+ switch (context.status)
{
case VALID:
case STALE:
try
{
- StructuralObject.Refresh refresh =
structuralStateContext.refresh(object.context.structuralObject);
+ StructuralObject.Refresh refresh =
structuralStateContext.refresh(context.structuralObject);
// Update the structural state
- object.context.structuralObject = refresh.getObject();
+ if (!context.structuralObject.compareTo(refresh.getObject()))
+ {
+ context.structuralObject = refresh.getObject();
+ }
- // Notify removals
- refresh.getRemovedChildren();
+ //
+ boolean loaded = context.children.relateds != null;
- // Notify additions
- refresh.getAddedChildren();
-
//
- refresh.getValidChildren();
+ if (loaded)
+ {
+ boolean refreshChildren = scope.enterChildren(object, loaded);
- // Notify refresh
- refresh.getStaleChildren();
+ // Removals
+ for (String removedId : refresh.getRemovedChildren())
+ {
+ }
+
+
+ // Compute set of added ids
+// Set<String> addedIds = new HashSet<String>();
+// for (StructuralObject addedSO : refresh.getAddedChildren())
+// {
+// addedIds.add(addedSO.getId());
+// }
+
+ List<UIContainerObject> children = new
ArrayList<UIContainerObject>();
+
+ //
+ for (StructuralObject addedSO : refresh.getAddedChildren())
+ {
+ }
+
+ //
+ for (String validId : refresh.getValidChildren())
+ {
+ }
+
+
+ //
+ for (StructuralObject staleSO :
refresh.getStaleChildren().values())
+ {
+ }
+
+ // Update to valid
+ context.status = UIObject.Status.VALID;
+ }
}
catch (NoSuchStateException e)
{
- object.context.status = UIObject.Status.INVALID;
+ context.status = UIObject.Status.INVALID;
}
//
break;
case INVALID:
- throw new IllegalStateException();
}
//
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-26
17:08:59 UTC (rev 9387)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-27
11:16:19 UTC (rev 9388)
@@ -58,11 +58,29 @@
public interface Visitor
{
+ /**
+ * Returns true if the provided object should be visited.
+ *
+ * @param object the object
+ * @return true if it should be visited
+ */
boolean enterObject(UIObject object);
+ /**
+ * Callback to signal that an object visit is terminated
+ *
+ * @param object the object
+ */
void leaveObject(UIObject object);
- boolean enterChildren(UIObject object);
+ /**
+ * Returns true if the children should be visited
+ *
+ * @param object the parent of the children
+ * @param loaded if the relationship is already loaded
+ * @return true if the children should be visited
+ */
+ boolean enterChildren(UIObject object, boolean loaded);
}
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-26
17:08:59 UTC (rev 9387)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-27
11:16:19 UTC (rev 9388)
@@ -647,6 +647,7 @@
assertSame(context.getObject(daaId), daa);
}
+
public void _testMove() throws Exception
{
MockObject mockRoot = model.getRoot();