Author: julien(a)jboss.com
Date: 2007-12-19 19:11:07 -0500 (Wed, 19 Dec 2007)
New Revision: 9374
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
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/UIObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
Log:
starting the refresh implementation
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-19
14:12:30 UTC (rev 9373)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-20
00:11:07 UTC (rev 9374)
@@ -38,6 +38,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.BitSet;
/**
* Implement base fonctionnality of the <code>UIObject</code> interface.
@@ -75,7 +76,7 @@
// UIObject interface
implementation-----------------------------------------------------------------------------------------------------------------------------
- public String getId()
+ public final String getId()
{
return context.structuralObject.getId();
}
@@ -109,39 +110,36 @@
}
}
- public Status getStatus()
+ public final Status getStatus()
{
return context.status;
}
- public void validate()
+ protected final boolean isModifiable()
{
- try
- {
- context.container.structuralStateContext.validate(context.structuralObject);
- }
- catch (StateException e)
- {
- context.updateStatus(e);
- }
+ return true;
}
- public void refresh()
+ public void validate(Visitor scope)
{
- switch (context.status)
- {
- case STALE:
- // Todo :-)
- throw new NotYetImplemented();
- case INVALID:
- // Cannot be resolved
- throw new IllegalStateException();
- case VALID:
- // Nothing to do
- break;
- }
+ context.container.validate(this, scope);
}
+ public final void validate()
+ {
+ refresh(SINGLE_NODE_VISITOR);
+ }
+
+ public void refresh(Visitor scope)
+ {
+ context.container.refresh(this, scope);
+ }
+
+ public final void refresh()
+ {
+ refresh(SINGLE_NODE_VISITOR);
+ }
+
public <T> T getProperty(StateType stateType, String propertyName,
Class<T> propertyType)
{
if (!context.isValid())
@@ -175,12 +173,12 @@
return safeCast(value, propertyType);
}
- public Object getProperty(StateType stateType, String propertyName)
+ public final Object getProperty(StateType stateType, String propertyName)
{
return getProperty(stateType, propertyName, Object.class);
}
- public <T> void setProperty(StateType stateType, String propertyName, T
propertyValue) throws StateChangeVetoException
+ public final <T> void setProperty(StateType stateType, String propertyName, T
propertyValue) throws StateChangeVetoException
{
if (!context.isValid())
{
@@ -194,6 +192,10 @@
{
throw new IllegalArgumentException();
}
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
//
String id = getId();
@@ -254,7 +256,7 @@
}
}
- public AbstractUIObject getChild(String name)
+ public final AbstractUIObject getChild(String name)
{
if (!context.isValid())
{
@@ -278,7 +280,7 @@
return null;
}
- public String getName()
+ public final String getName()
{
if (!context.isValid())
{
@@ -318,12 +320,16 @@
return children;
}
- public <T extends UIObject> T createChild(String name, Class<T> type)
throws IllegalArgumentException
+ public final <T extends UIObject> T createChild(String name, Class<T>
type) throws IllegalArgumentException
{
if (!context.isValid())
{
throw new IllegalStateException();
}
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
//
StructuralObject.Creation creation;
@@ -355,7 +361,7 @@
return type.cast(context.getObject(child.getId()));
}
- public void destroyChild(String name) throws IllegalArgumentException, StateException
+ public final void destroyChild(String name) throws IllegalArgumentException,
StateException
{
if (!context.isValid())
{
@@ -365,6 +371,10 @@
{
throw new IllegalArgumentException();
}
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
// Get the named child
AbstractUIObject namedChild = getChild(name);
@@ -382,12 +392,16 @@
context.container.update(destruction);
}
- public void move(UIObject destination) throws IllegalArgumentException,
StateException
+ public final void move(UIObject destination) throws IllegalArgumentException,
StateException
{
if (destination == null)
{
throw new IllegalArgumentException("No null object accepted");
}
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
//
if (destination instanceof AbstractUIObject)
@@ -409,4 +423,24 @@
protected abstract <T extends UIObject> boolean isAllowedAsChild(Class<T>
type);
+ /**
+ * Visitor that visits a single node only.
+ */
+ private static final Visitor SINGLE_NODE_VISITOR = new Visitor()
+ {
+ public boolean enterObject(UIObject object)
+ {
+ return true;
+ }
+
+ public void leaveObject(UIObject object)
+ {
+ }
+
+ public boolean enterChildren(UIObject object)
+ {
+ 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-19
14:12:30 UTC (rev 9373)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-20
00:11:07 UTC (rev 9374)
@@ -33,6 +33,8 @@
import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
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.StateException;
+import org.jboss.portal.presentation.model.state.NoSuchStateException;
import org.jboss.portal.presentation.impl.model.UIPortalImpl;
import org.jboss.portal.presentation.impl.model.UIPageImpl;
import org.jboss.portal.presentation.impl.model.UIContainerImpl;
@@ -257,6 +259,83 @@
}
}
+ void validate(AbstractUIObject 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.children)
+ {
+ validate(child, scope);
+ }
+ }
+ }
+
+ //
+ scope.leaveObject(object);
+ }
+ }
+
+ void refresh(AbstractUIObject object, UIObject.Visitor scope)
+ {
+
+
+ if (scope.enterObject(object))
+ {
+ switch (object.context.status)
+ {
+ case VALID:
+ case STALE:
+ try
+ {
+ StructuralObject.Refresh refresh =
structuralStateContext.refresh(object.context.structuralObject);
+
+ // Update the structural state
+ object.context.structuralObject = refresh.getObject();
+
+ // Notify removals
+ refresh.getRemovedChildren();
+
+ // Notify additions
+ refresh.getAddedChildren();
+
+ //
+ refresh.getValidChildren();
+
+ // Notify refresh
+ refresh.getStaleChildren();
+ }
+ catch (NoSuchStateException e)
+ {
+ object.context.status = UIObject.Status.INVALID;
+ }
+
+ //
+ break;
+ case INVALID:
+ throw new IllegalStateException();
+ }
+
+ //
+
+ //
+ scope.leaveObject(object);
+ }
+ }
+
// Private
**********************************************************************************************************
/**
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-19
14:12:30 UTC (rev 9373)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-20
00:11:07 UTC (rev 9374)
@@ -115,10 +115,4 @@
throw new AssertionError(e);
}
}
-
- void invalidate()
- {
- status = UIObject.Status.INVALID;
- }
-
}
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-19
14:12:30 UTC (rev 9373)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-20
00:11:07 UTC (rev 9374)
@@ -55,11 +55,24 @@
STALE
}
+ public interface Visitor
+ {
+
+ boolean enterObject(UIObject object);
+
+ void leaveObject(UIObject object);
+
+ boolean enterChildren(UIObject object);
+
+ }
+
/**
* Updates the status of the object by comparing validating it against the structural
state context.
*/
void validate();
+ void validate(Visitor scope);
+
/**
* Attempt a resolution of the current conflict. The behavior of the method will
change according to the
* current status of the object:
@@ -72,6 +85,8 @@
*/
void refresh();
+ void refresh(Visitor scope);
+
/**
* Return the current status.
*
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-12-19
14:12:30 UTC (rev 9373)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-20
00:11:07 UTC (rev 9374)
@@ -25,6 +25,7 @@
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.List;
import java.util.Map;
@@ -85,6 +86,15 @@
*/
void validate(StructuralObject object) throws IllegalArgumentException,
StateException;
+ /**
+ * Attempt to return an object that contains the difference between the provided
object
+ * and the up to date object.
+ *
+ * @param object the object to refresh
+ * @return the refresh
+ * @throws IllegalArgumentException if the object argument is null
+ * @throws StateException if the object cannot be refreshed
+ */
StructuralObject.Refresh refresh(StructuralObject object) throws
IllegalArgumentException, StateException;
/**