JBoss Portal SVN: r9398 - branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-27 17:00:40 -0500 (Thu, 27 Dec 2007)
New Revision: 9398
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
Log:
abstrac the owner from the one2many and many2one associations
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 21:51:58 UTC (rev 9397)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 22:00:40 UTC (rev 9398)
@@ -49,6 +49,10 @@
{
return owner.container.structuralStateContext.loadParent(owner.structuralObject);
}
+ protected ObjectContext getOwner()
+ {
+ return owner;
+ }
};
/** . */
@@ -58,9 +62,13 @@
{
return owner.container.structuralStateContext.loadChildren(owner.structuralObject);
}
+ protected ObjectContext getOwner()
+ {
+ return owner;
+ }
};
- abstract class ManyToOne
+ static abstract class ManyToOne
{
/** . */
@@ -88,6 +96,14 @@
{
throw new IllegalStateException("Cannot set parent of non loaded association");
}
+
+ // Update the related side
+ if (related != null)
+ {
+
+ }
+
+ //
if (newParent != null)
{
related = newParent;
@@ -126,6 +142,8 @@
*/
protected abstract StructuralObject doLoad() throws StateException;
+ protected abstract ObjectContext getOwner();
+
/**
* Attempt for loading the related side. If a failure occurs during while loading the related side
* the load operation is aborted and the status of the association owner is updated accordingly. If the loading
@@ -133,6 +151,9 @@
*/
private void load()
{
+ ObjectContext owner = getOwner();
+
+ //
try
{
StructuralObject relatedSO = doLoad();
@@ -179,6 +200,9 @@
UIContainerObject getRelated()
{
+ ObjectContext owner = getOwner();
+
+ //
owner.checkAccess();
//
@@ -195,7 +219,7 @@
}
}
- abstract class OneToMany
+ static abstract class OneToMany
{
/** . */
@@ -284,8 +308,13 @@
*/
protected abstract List<StructuralObject> doLoad() throws StateException;
+ protected abstract ObjectContext getOwner();
+
private void load()
{
+ ObjectContext owner = getOwner();
+
+ //
try
{
ArrayList<UIContainerObject> relateds = new ArrayList<UIContainerObject>();
@@ -332,6 +361,9 @@
{
public UIContainerObject get(int i)
{
+ ObjectContext owner = getOwner();
+
+ //
owner.checkAccess();
// Load the entire relationship
@@ -349,6 +381,9 @@
public int size()
{
+ ObjectContext owner = getOwner();
+
+ //
owner.checkAccess();
//
@@ -366,7 +401,7 @@
public String toString()
{
- return "ProxyList[" + owner + "]";
+ return "ProxyList[" + getOwner() + "]";
}
}
}
16 years, 4 months
JBoss Portal SVN: r9397 - branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-27 16:51:58 -0500 (Thu, 27 Dec 2007)
New Revision: 9397
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
Log:
minor refactorings
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 21:35:22 UTC (rev 9396)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 21:51:58 UTC (rev 9397)
@@ -161,7 +161,7 @@
related = owner.container.create(relatedSO);
//
- owner.container.put(related);
+ owner.container.attach(related);
//
this.related = related;
@@ -311,7 +311,7 @@
related = owner.container.create(relatedSO);
//
- owner.container.put(related);
+ owner.container.attach(related);
}
//
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-27 21:35:22 UTC (rev 9396)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-27 21:51:58 UTC (rev 9397)
@@ -112,7 +112,7 @@
public void validate(Visitor scope)
{
- context.container.validate(this, scope);
+ context.container.validate(context.containerObject, scope);
}
public final void validate()
@@ -122,7 +122,7 @@
public void refresh(Visitor scope)
{
- context.container.refresh(this, scope);
+ context.container.refresh(context.containerObject, scope);
}
public final void refresh()
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java 2007-12-27 21:35:22 UTC (rev 9396)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java 2007-12-27 21:51:58 UTC (rev 9397)
@@ -31,6 +31,7 @@
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.ModelListener;
import org.jboss.portal.presentation.impl.model.container.spi.UIObjectContext;
+import org.jboss.portal.presentation.impl.model.container.spi.UIContainerObject;
/**
* The internal state of an object.
@@ -45,6 +46,9 @@
final UIObjectContainer container;
/** The managed object. */
+ final UIContainerObject containerObject;
+
+ /** . */
final ManagedObject managedObject;
/** The associations. */
@@ -56,7 +60,10 @@
/** The status related to the structural object value. */
UIObject.Status status;
- ObjectContext(UIObjectContainer container, StructuralObject structuralObject)
+ ObjectContext(
+ UIObjectContainer container,
+ UIContainerObject containerObject,
+ StructuralObject structuralObject)
{
if (container == null)
{
@@ -69,6 +76,7 @@
//
this.container = container;
+ this.containerObject = containerObject;
this.structuralObject = structuralObject;
this.status = UIObject.Status.VALID;
this.managedObject = new ManagedObject(this);
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-27 21:35:22 UTC (rev 9396)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-27 21:51:58 UTC (rev 9397)
@@ -79,22 +79,22 @@
this.root = (UIContext)root;
// Update universe
- put(root);
+ attach(root);
}
UIContainerObject create(StructuralObject structuralObject)
{
+ // Create container object
+ UIContainerObject object = factory.createObject(structuralObject.getState().getType());
+
// Create context
- ObjectContext objectContext = new ObjectContext(this, structuralObject);
+ ObjectContext objectContext = new ObjectContext(this, object, structuralObject);
AssociationContext associationContext = new AssociationContext();
// Wire
objectContext.associationContext = associationContext;
associationContext.owner = objectContext;
- // Create container object
- UIContainerObject object = factory.createObject(structuralObject.getState().getType());
-
// Contextualize
object.setContext(objectContext);
@@ -160,7 +160,7 @@
UIContainerObject child = create(creation.getChild());
//
- put(child);
+ attach(child);
//
parentContext.associationContext.children.addLoadedRelated(child);
@@ -246,7 +246,7 @@
source = create(move.getSource());
//
- put(source);
+ attach(source);
}
//
@@ -309,7 +309,7 @@
object = create(structuralObject);
//
- put(object);
+ attach(object);
//
return object;
@@ -349,11 +349,11 @@
}
}
- void validate(ManagedObject object, UIObject.Visitor scope)
+ void validate(UIContainerObject object, UIObject.Visitor scope)
{
if (scope.enterObject(object))
{
- ObjectContext context = object.context;
+ ObjectContext context = (ObjectContext)object.getContext();
// We do it only if it is not yet invalid
if (context.isValid())
@@ -382,7 +382,7 @@
ObjectContext childContext = (ObjectContext)child.getContext();
//
- validate(childContext.managedObject, scope);
+ validate(childContext.containerObject, scope);
}
}
}
@@ -393,11 +393,11 @@
}
}
- void refresh(ManagedObject object, UIObject.Visitor scope)
+ void refresh(UIContainerObject object, UIObject.Visitor scope)
{
if (scope.enterObject(object))
{
- ObjectContext context = object.context;
+ ObjectContext context = (ObjectContext)object.getContext();
//
switch (context.status)
@@ -440,7 +440,7 @@
addedParentContext.status = UIObject.Status.STALE;
//
- addedParentContext.associationContext.parent.setLoadedRelated(get(context.structuralObject.getId()));
+ addedParentContext.associationContext.parent.setLoadedRelated(get(context.structuralObject));
}
}
else
@@ -448,7 +448,7 @@
added = create(addedSO);
//
- put(added);
+ attach(added);
}
//
@@ -518,11 +518,16 @@
}
}
- void put(UIContainerObject object)
+ void attach(UIContainerObject object)
{
universe.put(object.getId(), object);
}
+// void detach(UIContainerObject object)
+// {
+// universe.remove(object.getId());
+// }
+
UIContainerObject get(String id)
{
return universe.get(id);
16 years, 4 months
JBoss Portal SVN: r9396 - branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-27 16:35:22 -0500 (Thu, 27 Dec 2007)
New Revision: 9396
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java
Log:
- minor javadoc
- improve scope of various internal classes (package protected + final)
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 21:30:57 UTC (rev 9395)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 21:35:22 UTC (rev 9396)
@@ -36,7 +36,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-public class AssociationContext
+final class AssociationContext
{
/** . */
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-27 21:30:57 UTC (rev 9395)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-27 21:35:22 UTC (rev 9396)
@@ -44,7 +44,7 @@
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
*/
-public class ManagedObject implements UIObject
+final class ManagedObject implements UIObject
{
/** . */
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java 2007-12-27 21:30:57 UTC (rev 9395)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java 2007-12-27 21:35:22 UTC (rev 9396)
@@ -33,30 +33,30 @@
import org.jboss.portal.presentation.impl.model.container.spi.UIObjectContext;
/**
- * Encapsulate internal of an object.
+ * The internal state of an object.
*
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-public final class ObjectContext implements UIObjectContext
+final class ObjectContext implements UIObjectContext
{
- /** . */
+ /** We keep a ref to the container. */
final UIObjectContainer container;
- /** . */
+ /** The managed object. */
final ManagedObject managedObject;
- /** . */
+ /** The associations. */
AssociationContext associationContext;
- /** . */
+ /** What we know from the structural context. */
StructuralObject structuralObject;
- /** . */
+ /** The status related to the structural object value. */
UIObject.Status status;
- public ObjectContext(UIObjectContainer container, StructuralObject structuralObject)
+ ObjectContext(UIObjectContainer container, StructuralObject structuralObject)
{
if (container == null)
{
16 years, 4 months
JBoss Portal SVN: r9395 - branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-27 16:30:57 -0500 (Thu, 27 Dec 2007)
New Revision: 9395
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
Log:
minor javadoc
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 21:22:27 UTC (rev 9394)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 21:30:57 UTC (rev 9395)
@@ -118,8 +118,19 @@
loaded = false;
}
- protected abstract StructuralObject doLoad();
+ /**
+ * Loads the related side.
+ *
+ * @return the loaded structural object
+ * @throws StateException if the load operation cannot be achieved
+ */
+ protected abstract StructuralObject doLoad() throws StateException;
+ /**
+ * Attempt for loading the related side. If a failure occurs during while loading the related side
+ * the load operation is aborted and the status of the association owner is updated accordingly. If the loading
+ * of the related side is succesful the association is updated.
+ */
private void load()
{
try
@@ -157,7 +168,7 @@
}
}
- //
+ // Set as loaded
this.loaded = true;
}
catch (StateException e)
@@ -265,7 +276,13 @@
return list;
}
- protected abstract List<StructuralObject> doLoad();
+ /**
+ * Load the related side.
+ *
+ * @return the list of structural objects
+ * @throws StateException if the load operation cannot be achieved
+ */
+ protected abstract List<StructuralObject> doLoad() throws StateException;
private void load()
{
16 years, 4 months
JBoss Portal SVN: r9394 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: test/model and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-27 16:22:27 -0500 (Thu, 27 Dec 2007)
New Revision: 9394
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
implement StateException handling during parent/children loading
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 20:16:20 UTC (rev 9393)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 21:22:27 UTC (rev 9394)
@@ -24,6 +24,7 @@
import org.jboss.portal.presentation.impl.model.container.spi.UIContainerObject;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.UIObject;
import java.util.List;
@@ -121,51 +122,64 @@
private void load()
{
- StructuralObject relatedSO = doLoad();
-
- // If null it is the root so nothing is done
- if (relatedSO != null)
+ try
{
- UIContainerObject related = owner.container.get(relatedSO);
+ StructuralObject relatedSO = doLoad();
- //
- if (related != null)
+ // If null it is the root so nothing is done
+ if (relatedSO != null)
{
- this.related = related;
+ UIContainerObject related = owner.container.get(relatedSO);
//
- ObjectContext parentContext = (ObjectContext)related.getContext();
+ if (related != null)
+ {
+ this.related = related;
- //
- if (!relatedSO.compareTo(parentContext.structuralObject))
+ //
+ ObjectContext parentContext = (ObjectContext)related.getContext();
+
+ //
+ if (!relatedSO.compareTo(parentContext.structuralObject))
+ {
+ parentContext.status = UIObject.Status.STALE;
+ }
+ }
+ else
{
- parentContext.status = UIObject.Status.STALE;
+ related = owner.container.create(relatedSO);
+
+ //
+ owner.container.put(related);
+
+ //
+ this.related = related;
}
}
- else
- {
- related = owner.container.create(relatedSO);
- //
- owner.container.put(related);
-
- //
- this.related = related;
- }
+ //
+ this.loaded = true;
}
-
- //
- this.loaded = true;
+ catch (StateException e)
+ {
+ owner.updateStatus(e);
+ }
}
UIContainerObject getRelated()
{
+ owner.checkAccess();
+
+ //
if (!loaded)
{
load();
}
//
+ owner.checkAccess();
+
+ //
return related;
}
}
@@ -255,49 +269,53 @@
private void load()
{
- ArrayList<UIContainerObject> relateds = new ArrayList<UIContainerObject>();
-
- //
- for (StructuralObject relatedSO : doLoad())
+ try
{
- UIContainerObject related = owner.container.get(relatedSO);
+ ArrayList<UIContainerObject> relateds = new ArrayList<UIContainerObject>();
//
- if (related != null)
+ for (StructuralObject relatedSO : doLoad())
{
- ObjectContext relatedContext = (ObjectContext)related.getContext();
+ UIContainerObject related = owner.container.get(relatedSO);
//
- if (!relatedContext.structuralObject.compareTo(relatedSO))
+ if (related != null)
{
- relatedContext.status = UIObject.Status.STALE;
+ ObjectContext relatedContext = (ObjectContext)related.getContext();
+
+ //
+ if (!relatedContext.structuralObject.compareTo(relatedSO))
+ {
+ relatedContext.status = UIObject.Status.STALE;
+ }
}
- }
- else
- {
- related = owner.container.create(relatedSO);
+ else
+ {
+ related = owner.container.create(relatedSO);
+ //
+ owner.container.put(related);
+ }
+
//
- owner.container.put(related);
+ relateds.add(related);
}
//
- relateds.add(related);
+ this.relateds = relateds;
+ this.loaded = true;
}
-
- //
- this.relateds = relateds;
- this.loaded = true;
+ catch (StateException e)
+ {
+ owner.updateStatus(e);
+ }
}
private class ProxyList extends AbstractList<UIContainerObject>
{
public UIContainerObject get(int i)
{
- if (!owner.isValid())
- {
- throw new IllegalStateException("Relationship not valid");
- }
+ owner.checkAccess();
// Load the entire relationship
if (!isLoaded())
@@ -306,19 +324,26 @@
}
//
+ owner.checkAccess();
+
+ //
return relateds.get(i);
}
public int size()
{
- if (!owner.isValid())
- {
- throw new IllegalStateException("Relationship cannot be used because the owner " + owner + " is not valid");
- }
+ owner.checkAccess();
+
+ //
if (!isLoaded())
{
load();
}
+
+ //
+ owner.checkAccess();
+
+ //
return relateds.size();
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-27 20:16:20 UTC (rev 9393)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-27 21:22:27 UTC (rev 9394)
@@ -132,10 +132,9 @@
public <T> T getProperty(StateType stateType, String propertyName, Class<T> propertyType)
{
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
+ context.checkAccess();
+
+ //
if (stateType == null)
{
throw new IllegalArgumentException();
@@ -170,10 +169,9 @@
public final <T> void setProperty(StateType stateType, String propertyName, T propertyValue) throws StateChangeVetoException
{
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
+ context.checkAccess();
+
+ //
if (stateType == null)
{
throw new IllegalArgumentException();
@@ -248,10 +246,9 @@
public final UIContainerObject getChild(String name)
{
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
+ context.checkAccess();
+
+ //
if (name == null)
{
throw new IllegalArgumentException("No null name accepted");
@@ -272,10 +269,7 @@
public final String getName()
{
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
+ context.checkAccess();
//
return context.structuralObject.getState().getName();
@@ -283,10 +277,7 @@
public final UIObject getParent()
{
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
+ context.checkAccess();
//
return context.associationContext.parent.getRelated();
@@ -294,10 +285,7 @@
public final List<UIContainerObject> getChildren()
{
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
+ context.checkAccess();
//
return context.associationContext.children.getRelateds();
@@ -305,10 +293,9 @@
public final <T extends UIObject> T createChild(String name, Class<T> type) throws IllegalArgumentException
{
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
+ context.checkAccess();
+
+ //
if (!isModifiable())
{
throw new IllegalStateException("Cannot change state");
@@ -346,10 +333,9 @@
public final void destroyChild(String name) throws IllegalArgumentException, StateException
{
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
+ context.checkAccess();
+
+ //
if (name == null)
{
throw new IllegalArgumentException();
@@ -377,6 +363,9 @@
public final void move(UIObject destination) throws IllegalArgumentException, StateException
{
+ context.checkAccess();
+
+ //
if (destination == null)
{
throw new IllegalArgumentException("No null object accepted");
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java 2007-12-27 20:16:20 UTC (rev 9393)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java 2007-12-27 21:22:27 UTC (rev 9394)
@@ -93,6 +93,19 @@
//
+ void checkAccess() throws NoSuchStateException, StaleStateException
+ {
+ switch (status)
+ {
+ case VALID:
+ break;
+ case INVALID:
+ throw new NoSuchStateException();
+ case STALE:
+ throw new StaleStateException();
+ }
+ }
+
StructuralState getState()
{
return structuralObject.getState();
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-27 20:16:20 UTC (rev 9393)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-27 21:22:27 UTC (rev 9394)
@@ -46,6 +46,7 @@
import java.util.List;
import java.util.HashSet;
import java.util.Map;
+import java.util.ArrayList;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -172,7 +173,117 @@
assertSame(context, someOtherPortal.getParent());
assertEquals(Collections.EMPTY_LIST, defaultPortal.getChildren());
}
-
+
+ public void testLoadChildrenFromStale() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockBar = mockFoo.addChild("bar", MockObject.Type.PORTAL);
+
+ // Load the context object
+ UIObject foo = createContext().getObject(mockFoo.getId());
+
+ // Make a concurrent modification of the children
+ model.destroy(mockBar);
+
+ // Access children
+ try
+ {
+ List<? extends UIObject> children = foo.getChildren();
+ for (UIObject child : children)
+ {
+ }
+ fail();
+ }
+ catch (StaleStateException expected)
+ {
+ }
+
+ // Now state should be stale
+ assertEquals(UIObject.Status.STALE, foo.getStatus());
+ }
+
+ public void testLoadParentFromStale() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockBar = mockFoo.addChild("bar", MockObject.Type.PORTAL);
+
+ // Load the context object
+ UIObject foo = createContext().getObject(mockFoo.getId());
+
+ // Make a concurrent modification of the children
+ model.destroy(mockBar);
+
+ // Access children
+ try
+ {
+ foo.getParent();
+ fail();
+ }
+ catch (StaleStateException expected)
+ {
+ }
+
+ // Now state should be stale
+ assertEquals(UIObject.Status.STALE, foo.getStatus());
+ }
+
+ public void loadChildrenFromDestroyed() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockBar = mockFoo.addChild("bar", MockObject.Type.PORTAL);
+
+ // Load the context object
+ UIObject foo = createContext().getObject(mockFoo.getId());
+
+ // Make a concurrent modification of the children
+ model.destroy(mockFoo);
+
+ // Access children
+ try
+ {
+ List<? extends UIObject> children = foo.getChildren();
+ for (UIObject child : children)
+ {
+ }
+ fail();
+ }
+ catch (NoSuchStateException expected)
+ {
+ }
+
+ // Now state should be invalid
+ assertEquals(UIObject.Status.INVALID, foo.getStatus());
+ }
+
+ public void loadParentFromDestroyed() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockBar = mockFoo.addChild("bar", MockObject.Type.PORTAL);
+
+ // Load the context object
+ UIObject foo = createContext().getObject(mockFoo.getId());
+
+ // Make a concurrent modification of the children
+ model.destroy(mockFoo);
+
+ // Access children
+ try
+ {
+ foo.getParent();
+ fail();
+ }
+ catch (NoSuchStateException expected)
+ {
+ }
+
+ // Now state should be invalid
+ assertEquals(UIObject.Status.INVALID, foo.getStatus());
+ }
+
public void testLoadParent() throws Exception
{
MockObject mockDefaultPortal = model.getRoot().addChild("defaultPortal", MockObject.Type.PORTAL);
@@ -483,7 +594,7 @@
daaChildren.size();
fail();
}
- catch (IllegalStateException ignore)
+ catch (NoSuchStateException ignore)
{
}
}
@@ -520,7 +631,7 @@
juuChildren.size();
fail();
}
- catch (IllegalStateException ignore)
+ catch (NoSuchStateException ignore)
{
}
try
@@ -528,7 +639,7 @@
daaChildren.size();
fail();
}
- catch (IllegalStateException ignore)
+ catch (NoSuchStateException ignore)
{
}
assertEquals(0, fooChildren.size());
16 years, 4 months
JBoss Portal SVN: r9393 - branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-27 15:16:20 -0500 (Thu, 27 Dec 2007)
New Revision: 9393
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
Log:
improved state management of association context
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 17:39:08 UTC (rev 9392)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 20:16:20 UTC (rev 9393)
@@ -42,12 +42,24 @@
ObjectContext owner;
/** . */
- final ManyToOne parent = new ManyToOne();
+ final ManyToOne parent = new ManyToOne()
+ {
+ protected StructuralObject doLoad()
+ {
+ return owner.container.structuralStateContext.loadParent(owner.structuralObject);
+ }
+ };
/** . */
- final OneToMany children = new OneToMany();
+ final OneToMany children = new OneToMany()
+ {
+ protected List<StructuralObject> doLoad()
+ {
+ return owner.container.structuralStateContext.loadChildren(owner.structuralObject);
+ }
+ };
- class ManyToOne
+ abstract class ManyToOne
{
/** . */
@@ -105,75 +117,86 @@
loaded = false;
}
- UIContainerObject getRelated()
+ protected abstract StructuralObject doLoad();
+
+ private void load()
{
- if (!loaded)
+ StructuralObject relatedSO = doLoad();
+
+ // If null it is the root so nothing is done
+ if (relatedSO != null)
{
- StructuralObject parentSO = owner.container.structuralStateContext.loadParent(owner.structuralObject);
+ UIContainerObject related = owner.container.get(relatedSO);
- // If null it is the root so nothing is done
- if (parentSO != null)
+ //
+ if (related != null)
{
- UIContainerObject parent = owner.container.get(parentSO);
+ this.related = related;
//
- if (parent != null)
+ ObjectContext parentContext = (ObjectContext)related.getContext();
+
+ //
+ if (!relatedSO.compareTo(parentContext.structuralObject))
{
- related = parent;
-
- //
- ObjectContext parentContext = (ObjectContext)parent.getContext();
-
- //
- if (!parentSO.compareTo(parentContext.structuralObject))
- {
- parentContext.status = UIObject.Status.STALE;
- }
+ parentContext.status = UIObject.Status.STALE;
}
- else
- {
- parent = owner.container.create(parentSO);
+ }
+ else
+ {
+ related = owner.container.create(relatedSO);
- //
- owner.container.put(parent);
+ //
+ owner.container.put(related);
- //
- related = parent;
- }
+ //
+ this.related = related;
}
}
- // Try to resolve the relationship
+ //
+ this.loaded = true;
+ }
+ UIContainerObject getRelated()
+ {
+ if (!loaded)
+ {
+ load();
+ }
//
return related;
}
}
- class OneToMany
+ abstract class OneToMany
{
/** . */
private final ProxyList list;
/** . */
+ private boolean loaded;
+
+ /** . */
private List<UIContainerObject> relateds;
private OneToMany()
{
this.list = new ProxyList();
- this.relateds = null;
+ this.loaded = false;
+ this.relateds = new ArrayList<UIContainerObject>();
}
boolean isLoaded()
{
- return relateds != null;
+ return loaded;
}
void addLoadedRelated(UIContainerObject related)
{
- if (relateds == null)
+ if (!isLoaded())
{
throw new IllegalStateException("Not loaded");
}
@@ -193,15 +216,16 @@
void setLoadedRelateds(List<UIContainerObject> relateds)
{
- if (relateds == null)
+ if (!isLoaded())
{
throw new IllegalStateException("Not loaded");
}
+ this.relateds = relateds;
}
void removeLoadedRelated(String relatedId)
{
- if (relateds == null)
+ if (!isLoaded())
{
throw new IllegalStateException("Not loaded");
}
@@ -227,40 +251,43 @@
return list;
}
- private List<UIContainerObject> getChildren(StructuralObject structuralObject)
+ protected abstract List<StructuralObject> doLoad();
+
+ private void load()
{
- ArrayList<UIContainerObject> children = new ArrayList<UIContainerObject>();
+ ArrayList<UIContainerObject> relateds = new ArrayList<UIContainerObject>();
//
- for (StructuralObject childSO : owner.container.structuralStateContext.loadChildren(structuralObject))
+ for (StructuralObject relatedSO : doLoad())
{
- UIContainerObject child = owner.container.get(childSO);
+ UIContainerObject related = owner.container.get(relatedSO);
//
- if (child != null)
+ if (related != null)
{
- ObjectContext childContext = (ObjectContext)child.getContext();
+ ObjectContext relatedContext = (ObjectContext)related.getContext();
//
- if (!childContext.structuralObject.compareTo(childSO))
+ if (!relatedContext.structuralObject.compareTo(relatedSO))
{
- childContext.status = UIObject.Status.STALE;
+ relatedContext.status = UIObject.Status.STALE;
}
}
else
{
- child = owner.container.create(childSO);
+ related = owner.container.create(relatedSO);
//
- owner.container.put(child);
+ owner.container.put(related);
}
//
- children.add(child);
+ relateds.add(related);
}
//
- return children;
+ this.relateds = relateds;
+ this.loaded = true;
}
private class ProxyList extends AbstractList<UIContainerObject>
@@ -273,9 +300,9 @@
}
// Load the entire relationship
- if (relateds == null)
+ if (!isLoaded())
{
- relateds = getChildren(owner.structuralObject);
+ load();
}
//
@@ -288,9 +315,9 @@
{
throw new IllegalStateException("Relationship cannot be used because the owner " + owner + " is not valid");
}
- if (relateds == null)
+ if (!isLoaded())
{
- relateds = getChildren(owner.structuralObject);
+ load();
}
return relateds.size();
}
16 years, 4 months
JBoss Portal SVN: r9392 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: test/model and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-27 12:39:08 -0500 (Thu, 27 Dec 2007)
New Revision: 9392
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
encapsulate more code in the AssociationContext class
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 17:00:47 UTC (rev 9391)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 17:39:08 UTC (rev 9392)
@@ -29,6 +29,7 @@
import java.util.List;
import java.util.ArrayList;
import java.util.AbstractList;
+import java.util.Iterator;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -37,30 +38,77 @@
public class AssociationContext
{
+ /** . */
ObjectContext owner;
+ /** . */
final ManyToOne parent = new ManyToOne();
+ /** . */
final OneToMany children = new OneToMany();
-
class ManyToOne
{
/** . */
- boolean loaded;
+ private boolean loaded;
/** . */
- UIContainerObject related;
+ private UIContainerObject related;
private ManyToOne()
{
}
- UIContainerObject get()
+ boolean isLoaded()
{
+ return loaded;
+ }
+
+ void setLoadedRelated(UIContainerObject newParent)
+ {
+ if (newParent == null)
+ {
+ throw new IllegalArgumentException();
+ }
if (!loaded)
{
+ throw new IllegalStateException("Cannot set parent of non loaded association");
+ }
+ if (newParent != null)
+ {
+ related = newParent;
+ }
+ else
+ {
+ related = null;
+ loaded = false;
+ }
+ }
+
+ UIContainerObject getLoadedRelated()
+ {
+ if (!loaded)
+ {
+ throw new IllegalStateException("Cannot set parent of non loaded association");
+ }
+ return related;
+ }
+
+ void clearLoadedRelated()
+ {
+ if (!loaded)
+ {
+ throw new IllegalStateException("Cannot clear parent of non loaded association");
+ }
+ related = null;
+ loaded = false;
+ }
+
+ UIContainerObject getRelated()
+ {
+ if (!loaded)
+ {
StructuralObject parentSO = owner.container.structuralStateContext.loadParent(owner.structuralObject);
// If null it is the root so nothing is done
@@ -107,10 +155,10 @@
{
/** . */
- final ProxyList list;
+ private final ProxyList list;
/** . */
- List<UIContainerObject> relateds;
+ private List<UIContainerObject> relateds;
private OneToMany()
{
@@ -118,8 +166,64 @@
this.relateds = null;
}
- List<UIContainerObject> get()
+ boolean isLoaded()
{
+ return relateds != null;
+ }
+
+ void addLoadedRelated(UIContainerObject related)
+ {
+ if (relateds == null)
+ {
+ throw new IllegalStateException("Not loaded");
+ }
+ if (related == null)
+ {
+ throw new IllegalArgumentException("No null child accepted");
+ }
+ for (UIContainerObject r : relateds)
+ {
+ if (related.getId().equals(r.getId()))
+ {
+ throw new IllegalStateException("Cannot add duplicate");
+ }
+ }
+ relateds.add(related);
+ }
+
+ void setLoadedRelateds(List<UIContainerObject> relateds)
+ {
+ if (relateds == null)
+ {
+ throw new IllegalStateException("Not loaded");
+ }
+ }
+
+ void removeLoadedRelated(String relatedId)
+ {
+ if (relateds == null)
+ {
+ throw new IllegalStateException("Not loaded");
+ }
+ if (relatedId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ for (Iterator<UIContainerObject> i = relateds.iterator();i.hasNext();)
+ {
+ UIContainerObject child = i.next();
+
+ //
+ if (relatedId.equals(child.getId()))
+ {
+ i.remove();
+ break;
+ }
+ }
+ }
+
+ List<UIContainerObject> getRelateds()
+ {
return list;
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-27 17:00:47 UTC (rev 9391)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-27 17:39:08 UTC (rev 9392)
@@ -289,7 +289,7 @@
}
//
- return context.associationContext.parent.get();
+ return context.associationContext.parent.getRelated();
}
public final List<UIContainerObject> getChildren()
@@ -300,7 +300,7 @@
}
//
- return context.associationContext.children.get();
+ return context.associationContext.children.getRelateds();
}
public final <T extends UIObject> T createChild(String name, Class<T> type) throws IllegalArgumentException
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-27 17:00:47 UTC (rev 9391)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-27 17:39:08 UTC (rev 9392)
@@ -39,7 +39,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Iterator;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -156,7 +155,7 @@
parentContext.structuralObject = creation.getParent();
//
- if (parentContext.associationContext.children.relateds != null)
+ if (parentContext.associationContext.children.isLoaded())
{
UIContainerObject child = create(creation.getChild());
@@ -164,7 +163,7 @@
put(child);
//
- parentContext.associationContext.children.relateds.add(child);
+ parentContext.associationContext.children.addLoadedRelated(child);
}
}
else if (change instanceof StructuralObject.Destruction)
@@ -183,19 +182,13 @@
parentContext.structuralObject = destruction.getParent();
//
- if (parentContext.associationContext.children.relateds != null)
+ if (parentContext.associationContext.children.isLoaded())
{
- for (Iterator<UIContainerObject> i = parentContext.associationContext.children.relateds.iterator();i.hasNext();)
- {
- UIContainerObject child = i.next();
+ // Get the id which is the destroyed object
+ String destroyedId = destruction.getIds().get(destruction.getIds().size() - 1);
- //
- if (destruction.getIds().contains(child.getId()))
- {
- i.remove();
- break;
- }
- }
+ //
+ parentContext.associationContext.children.removeLoadedRelated(destroyedId);
}
}
@@ -230,19 +223,9 @@
parentContext.structuralObject = move.getParent();
// Remove the child if the relationship is loaded on this side
- if (parentContext.associationContext.children.relateds != null)
+ if (parentContext.associationContext.children.isLoaded())
{
- for (Iterator<UIContainerObject> i = parentContext.associationContext.children.relateds.iterator();i.hasNext();)
- {
- UIContainerObject child = i.next();
-
- //
- if (child.getId().equals(move.getSource().getId()))
- {
- i.remove();
- break;
- }
- }
+ parentContext.associationContext.children.removeLoadedRelated(move.getSource().getId());
}
}
@@ -255,7 +238,7 @@
destinationContext.structuralObject = move.getDestination();
//
- if (destinationContext.associationContext.children.relateds != null)
+ if (destinationContext.associationContext.children.isLoaded())
{
// Now we really need to add the source as we load collections entirely
if (source == null)
@@ -267,7 +250,7 @@
}
//
- destinationContext.associationContext.children.relateds.add(source);
+ destinationContext.associationContext.children.addLoadedRelated(source);
}
}
@@ -280,16 +263,15 @@
sourceContext.structuralObject = move.getSource();
//
- if (sourceContext.associationContext.parent.loaded)
+ if (sourceContext.associationContext.parent.isLoaded())
{
if (destination != null)
{
- sourceContext.associationContext.parent.related = destination;
+ sourceContext.associationContext.parent.setLoadedRelated(destination);
}
else
{
- sourceContext.associationContext.parent.related = null;
- sourceContext.associationContext.parent.loaded = false;
+ sourceContext.associationContext.parent.clearLoadedRelated();
}
}
}
@@ -389,13 +371,13 @@
// Continue only if it is valid
if (context.isValid())
{
- boolean loaded = context.associationContext.children.relateds != null;
+ boolean loaded = context.associationContext.children.isLoaded();
// 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.associationContext.children.get())
+ for (UIContainerObject child : context.associationContext.children.getRelateds())
{
ObjectContext childContext = (ObjectContext)child.getContext();
@@ -429,7 +411,7 @@
// Update the structural state
if (!context.structuralObject.compareTo(refresh.getObject()))
{
- boolean loaded = context.associationContext.children.relateds != null;
+ boolean loaded = context.associationContext.children.isLoaded();
//
if (loaded)
@@ -450,15 +432,15 @@
ObjectContext addedContext = (ObjectContext)added.getContext();
// Set the parent as stale if needed
- if (addedContext.associationContext.parent.loaded)
+ if (addedContext.associationContext.parent.isLoaded())
{
- ObjectContext addedParentContext = (ObjectContext)addedContext.associationContext.parent.related.getContext();
+ ObjectContext addedParentContext = (ObjectContext)addedContext.associationContext.parent.getLoadedRelated().getContext();
// Mark the parent as stale
addedParentContext.status = UIObject.Status.STALE;
//
- addedParentContext.associationContext.parent.related = get(context.structuralObject.getId());
+ addedParentContext.associationContext.parent.setLoadedRelated(get(context.structuralObject.getId()));
}
}
else
@@ -515,7 +497,7 @@
// Update state
context.structuralObject = refresh.getObject();
context.status = UIObject.Status.VALID;
- context.associationContext.children.relateds = children;
+ context.associationContext.children.setLoadedRelateds(children);
}
}
}
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-27 17:00:47 UTC (rev 9391)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-27 17:39:08 UTC (rev 9392)
@@ -45,7 +45,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.HashSet;
-import java.util.Set;
import java.util.Map;
/**
16 years, 4 months
JBoss Portal SVN: r9391 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model: container and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-27 12:00:47 -0500 (Thu, 27 Dec 2007)
New Revision: 9391
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIContainerObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIObjectFactory.java
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java
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/UIObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.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/container/UIObjectContainer.java
Log:
refactor to cleanup a bit
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-27 13:25:10 UTC (rev 9390)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-27 17:00:47 UTC (rev 9391)
@@ -24,11 +24,10 @@
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.StateType;
-import org.jboss.portal.presentation.model.ModelListener;
import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
-import org.jboss.portal.presentation.impl.model.container.UIContainerObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
+import org.jboss.portal.presentation.impl.model.container.spi.UIContainerObject;
+import org.jboss.portal.presentation.impl.model.container.spi.UIObjectContext;
import java.util.List;
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27 17:00:47 UTC (rev 9391)
@@ -0,0 +1,200 @@
+/******************************************************************************
+ * 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.impl.model.container;
+
+import org.jboss.portal.presentation.impl.model.container.spi.UIContainerObject;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.model.UIObject;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.AbstractList;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class AssociationContext
+{
+
+ ObjectContext owner;
+
+ final ManyToOne parent = new ManyToOne();
+
+ final OneToMany children = new OneToMany();
+
+
+ class ManyToOne
+ {
+
+ /** . */
+ boolean loaded;
+
+ /** . */
+ UIContainerObject related;
+
+ private ManyToOne()
+ {
+ }
+
+ UIContainerObject get()
+ {
+ if (!loaded)
+ {
+ StructuralObject parentSO = owner.container.structuralStateContext.loadParent(owner.structuralObject);
+
+ // If null it is the root so nothing is done
+ if (parentSO != null)
+ {
+ UIContainerObject parent = owner.container.get(parentSO);
+
+ //
+ if (parent != null)
+ {
+ related = parent;
+
+ //
+ ObjectContext parentContext = (ObjectContext)parent.getContext();
+
+ //
+ if (!parentSO.compareTo(parentContext.structuralObject))
+ {
+ parentContext.status = UIObject.Status.STALE;
+ }
+ }
+ else
+ {
+ parent = owner.container.create(parentSO);
+
+ //
+ owner.container.put(parent);
+
+ //
+ related = parent;
+ }
+ }
+ }
+
+ // Try to resolve the relationship
+
+
+ //
+ return related;
+ }
+ }
+
+ class OneToMany
+ {
+
+ /** . */
+ final ProxyList list;
+
+ /** . */
+ List<UIContainerObject> relateds;
+
+ private OneToMany()
+ {
+ this.list = new ProxyList();
+ this.relateds = null;
+ }
+
+ List<UIContainerObject> get()
+ {
+ return list;
+ }
+
+ private List<UIContainerObject> getChildren(StructuralObject structuralObject)
+ {
+ ArrayList<UIContainerObject> children = new ArrayList<UIContainerObject>();
+
+ //
+ for (StructuralObject childSO : owner.container.structuralStateContext.loadChildren(structuralObject))
+ {
+ UIContainerObject child = owner.container.get(childSO);
+
+ //
+ if (child != null)
+ {
+ ObjectContext childContext = (ObjectContext)child.getContext();
+
+ //
+ if (!childContext.structuralObject.compareTo(childSO))
+ {
+ childContext.status = UIObject.Status.STALE;
+ }
+ }
+ else
+ {
+ child = owner.container.create(childSO);
+
+ //
+ owner.container.put(child);
+ }
+
+ //
+ children.add(child);
+ }
+
+ //
+ return children;
+ }
+
+ private class ProxyList extends AbstractList<UIContainerObject>
+ {
+ public UIContainerObject get(int i)
+ {
+ if (!owner.isValid())
+ {
+ throw new IllegalStateException("Relationship not valid");
+ }
+
+ // Load the entire relationship
+ if (relateds == null)
+ {
+ relateds = getChildren(owner.structuralObject);
+ }
+
+ //
+ return relateds.get(i);
+ }
+
+ public int size()
+ {
+ if (!owner.isValid())
+ {
+ throw new IllegalStateException("Relationship cannot be used because the owner " + owner + " is not valid");
+ }
+ if (relateds == null)
+ {
+ relateds = getChildren(owner.structuralObject);
+ }
+ return relateds.size();
+ }
+
+ public String toString()
+ {
+ return "ProxyList[" + owner + "]";
+ }
+ }
+ }
+}
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java (from rev 9388, 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/ManagedObject.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-27 17:00:47 UTC (rev 9391)
@@ -0,0 +1,426 @@
+/******************************************************************************
+ * 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.impl.model.container;
+
+import org.jboss.portal.presentation.model.StateType;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.event.state.StateChange;
+import org.jboss.portal.presentation.model.event.state.StateChangeEvent;
+import org.jboss.portal.presentation.model.event.state.navigational.NavigationalStateModification;
+import org.jboss.portal.presentation.model.event.state.structural.StructuralStateModification;
+import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.impl.model.container.spi.UIContainerObject;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Implement base fonctionnality of the <code>UIObject</code> interface.
+ *
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ */
+public class ManagedObject implements UIObject
+{
+
+ /** . */
+ private static final Map<String, String> EMPTY_STATE = Collections.emptyMap();
+
+ /** The context. */
+ protected final ObjectContext context;
+
+ public ManagedObject(ObjectContext context)
+ {
+ if (context == null)
+ {
+ throw new IllegalArgumentException("No null context accepted");
+ }
+
+ //
+ this.context = context;
+ }
+
+ // UIObject interface implementation --------------------------------------------------------------------------------
+
+ public final String getId()
+ {
+ return context.structuralObject.getId();
+ }
+
+ /**
+ * Attempt to cast the value argument to the provided type argument. If the value argument type is assignable
+ * to the provided type, the value is returned, otherwise if it is not or the value is null, null is returned.
+ *
+ * todo: Move that to common package.
+ *
+ * @param value the value to cast
+ * @param type the type to downcast
+ * @return the casted value or null
+ */
+ private <T> T safeCast(Object value, Class<T> type)
+ {
+ if (value == null)
+ {
+ return null;
+ }
+ else
+ {
+ if (type.isAssignableFrom(value.getClass()))
+ {
+ return type.cast(value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+
+ public final Status getStatus()
+ {
+ return context.status;
+ }
+
+ protected final boolean isModifiable()
+ {
+ return true;
+ }
+
+ public void validate(Visitor scope)
+ {
+ 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())
+ {
+ throw new IllegalStateException();
+ }
+ if (stateType == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertyType == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ Object value;
+ switch (stateType)
+ {
+ case NAVIGATIONAL:
+ value = context.container.navigationalStateContext.get(getId(), propertyName);
+ break;
+ case STRUCTURAL:
+ value = context.structuralObject.getState().getProperties().get(propertyName);
+ break;
+ default:
+ throw new AssertionError();
+ }
+ return safeCast(value, propertyType);
+ }
+
+ public final Object getProperty(StateType stateType, String propertyName)
+ {
+ return getProperty(stateType, propertyName, Object.class);
+ }
+
+ public final <T> void setProperty(StateType stateType, String propertyName, T propertyValue) throws StateChangeVetoException
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (stateType == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
+
+ //
+ String id = getId();
+
+ //
+ switch (stateType)
+ {
+ case NAVIGATIONAL:
+ {
+ // Have context process the change
+ context.container.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.container.fireEvent(event);
+ break;
+ }
+ case STRUCTURAL:
+ {
+ if (propertyValue instanceof String)
+ {
+ Map<String, String> changes = new HashMap<String, String>();
+ changes.put(propertyName, (String)propertyValue);
+
+ // Have context process change
+ StructuralObject.Update update;
+ try
+ {
+ update = context.container.structuralStateContext.update(context.structuralObject, changes);
+ }
+ catch (StateException e)
+ {
+ validate();
+
+ //
+ throw e;
+ }
+
+ //
+ context.container.update(update);
+
+ // Broadcast event
+ StructuralStateModification mod = new StructuralStateModification.Update(changes);
+ StateChange<StructuralStateModification> change = new StateChange<StructuralStateModification>(id, mod);
+ StateChangeEvent event = new StateChangeEvent(change);
+ context.container.fireEvent(event);
+ }
+ else
+ {
+ throw new StateChangeVetoException("Structural property value must be string value");
+ }
+ break;
+ }
+ default:
+ throw new AssertionError();
+ }
+ }
+
+ public final UIContainerObject getChild(String name)
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (name == null)
+ {
+ throw new IllegalArgumentException("No null name accepted");
+ }
+
+ //
+ for (UIContainerObject child : getChildren())
+ {
+ if (child.getName().equals(name))
+ {
+ return child;
+ }
+ }
+
+ //
+ return null;
+ }
+
+ public final String getName()
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ return context.structuralObject.getState().getName();
+ }
+
+ public final UIObject getParent()
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ return context.associationContext.parent.get();
+ }
+
+ public final List<UIContainerObject> getChildren()
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ return context.associationContext.children.get();
+ }
+
+ 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;
+ try
+ {
+ creation = context.container.structuralStateContext.create(context.structuralObject, type, name, EMPTY_STATE);
+ }
+ catch (StateException e)
+ {
+ context.updateStatus(e);
+
+ //
+ throw e;
+ }
+
+ //
+ context.container.update(creation);
+
+ //
+ StructuralObject child = creation.getChild();
+
+ // Eventing
+ StructuralStateModification mod = new StructuralStateModification.Creation(type, name, EMPTY_STATE);
+ StateChange<StructuralStateModification> change = new StateChange<StructuralStateModification>(child.getId(), mod);
+ StateChangeEvent event = new StateChangeEvent(change);
+ context.container.fireEvent(event);
+
+ //
+ return type.cast(context.getObject(child.getId()));
+ }
+
+ public final void destroyChild(String name) throws IllegalArgumentException, StateException
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
+
+ // Get the named child
+ UIContainerObject namedChild = getChild(name);
+
+ //
+ if (namedChild == null)
+ {
+ throw new IllegalArgumentException("No such child with name " + name);
+ }
+
+ // Destroy the child
+ StructuralObject.Destruction destruction = context.container.structuralStateContext.destroy(((ObjectContext)namedChild.getContext()).structuralObject);
+
+ //
+ context.container.update(destruction);
+ }
+
+ 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 UIContainerObject)
+ {
+ //
+ UIContainerObject tmp = (UIContainerObject)destination;
+
+ // Perform the move operation
+ StructuralObject.Move move = context.container.structuralStateContext.move(context.structuralObject, ((ObjectContext)tmp.getContext()).structuralObject);
+
+ //
+ context.container.update(move);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Object not of right 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, boolean loaded)
+ {
+ return false;
+ }
+ };
+}
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java 2007-12-27 17:00:47 UTC (rev 9391)
@@ -0,0 +1,138 @@
+/******************************************************************************
+ * 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.impl.model.container;
+
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.model.state.structural.StructuralState;
+import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.NoSuchStateException;
+import org.jboss.portal.presentation.model.state.StaleStateException;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.UIContext;
+import org.jboss.portal.presentation.model.ModelListener;
+import org.jboss.portal.presentation.impl.model.container.spi.UIObjectContext;
+
+/**
+ * Encapsulate internal of an object.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public final class ObjectContext implements UIObjectContext
+{
+
+ /** . */
+ final UIObjectContainer container;
+
+ /** . */
+ final ManagedObject managedObject;
+
+ /** . */
+ AssociationContext associationContext;
+
+ /** . */
+ StructuralObject structuralObject;
+
+ /** . */
+ UIObject.Status status;
+
+ public ObjectContext(UIObjectContainer container, StructuralObject structuralObject)
+ {
+ if (container == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (structuralObject == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.container = container;
+ this.structuralObject = structuralObject;
+ this.status = UIObject.Status.VALID;
+ this.managedObject = new ManagedObject(this);
+ }
+
+ // Public ***********************************************************************************************************
+
+ public UIObject getManagedObject()
+ {
+ return managedObject;
+ }
+
+ public UIObject getObject(String id)
+ {
+ return container.getObject(id);
+ }
+
+ public void addModelListener(ModelListener listener)
+ {
+ container.addModelListener(listener);
+ }
+
+ //
+
+ StructuralState getState()
+ {
+ return structuralObject.getState();
+ }
+
+ UIContext getRoot()
+ {
+ return container.root;
+ }
+
+ UIObject.Status getStatus()
+ {
+ return status;
+ }
+
+ boolean isValid()
+ {
+ return status == UIObject.Status.VALID;
+ }
+
+ // Package protected ************************************************************************************************
+
+ void updateStatus(StateException e)
+ {
+ if (e instanceof NoSuchStateException)
+ {
+ status = UIObject.Status.INVALID;
+ }
+ else if (e instanceof StaleStateException)
+ {
+ status = UIObject.Status.STALE;
+ }
+ else
+ {
+ throw new AssertionError(e);
+ }
+ }
+
+ public String toString()
+ {
+ return "UIObjectContext[" + structuralObject.getId() + "]";
+ }
+}
\ No newline at end of file
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java 2007-12-27 13:25:10 UTC (rev 9390)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java 2007-12-27 17:00:47 UTC (rev 9391)
@@ -1,38 +0,0 @@
-/******************************************************************************
- * 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.impl.model.container;
-
-import org.jboss.portal.presentation.model.UIObject;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public interface UIContainerObject extends UIObject
-{
-
- UIObjectContext getContext();
-
- void setContext(UIObjectContext context);
-
-}
Deleted: 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-27 13:25:10 UTC (rev 9390)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java 2007-12-27 17:00:47 UTC (rev 9391)
@@ -1,425 +0,0 @@
-/******************************************************************************
- * 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.impl.model.container;
-
-import org.jboss.portal.presentation.model.StateType;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.event.state.StateChange;
-import org.jboss.portal.presentation.model.event.state.StateChangeEvent;
-import org.jboss.portal.presentation.model.event.state.navigational.NavigationalStateModification;
-import org.jboss.portal.presentation.model.event.state.structural.StructuralStateModification;
-import org.jboss.portal.presentation.model.state.StateChangeVetoException;
-import org.jboss.portal.presentation.model.state.StateException;
-import org.jboss.portal.presentation.model.state.structural.StructuralObject;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Implement base fonctionnality of the <code>UIObject</code> interface.
- *
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- */
-public class UIManagedObject implements UIObject
-{
-
- /** . */
- private static final Map<String, String> EMPTY_STATE = Collections.emptyMap();
-
- /** The context. */
- protected final UIObjectContext context;
-
- public UIManagedObject(UIObjectContext context)
- {
- if (context == null)
- {
- throw new IllegalArgumentException("No null context accepted");
- }
-
- //
- this.context = context;
- }
-
- // UIObject interface implementation --------------------------------------------------------------------------------
-
- public final String getId()
- {
- return context.structuralObject.getId();
- }
-
- /**
- * Attempt to cast the value argument to the provided type argument. If the value argument type is assignable
- * to the provided type, the value is returned, otherwise if it is not or the value is null, null is returned.
- *
- * todo: Move that to common package.
- *
- * @param value the value to cast
- * @param type the type to downcast
- * @return the casted value or null
- */
- private <T> T safeCast(Object value, Class<T> type)
- {
- if (value == null)
- {
- return null;
- }
- else
- {
- if (type.isAssignableFrom(value.getClass()))
- {
- return type.cast(value);
- }
- else
- {
- return null;
- }
- }
- }
-
- public final Status getStatus()
- {
- return context.status;
- }
-
- protected final boolean isModifiable()
- {
- return true;
- }
-
- public void validate(Visitor scope)
- {
- 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())
- {
- throw new IllegalStateException();
- }
- if (stateType == null)
- {
- throw new IllegalArgumentException();
- }
- if (propertyName == null)
- {
- throw new IllegalArgumentException();
- }
- if (propertyType == null)
- {
- throw new IllegalArgumentException();
- }
- Object value;
- switch (stateType)
- {
- case NAVIGATIONAL:
- value = context.container.navigationalStateContext.get(getId(), propertyName);
- break;
- case STRUCTURAL:
- value = context.structuralObject.getState().getProperties().get(propertyName);
- break;
- default:
- throw new AssertionError();
- }
- return safeCast(value, propertyType);
- }
-
- public final Object getProperty(StateType stateType, String propertyName)
- {
- return getProperty(stateType, propertyName, Object.class);
- }
-
- public final <T> void setProperty(StateType stateType, String propertyName, T propertyValue) throws StateChangeVetoException
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
- if (stateType == null)
- {
- throw new IllegalArgumentException();
- }
- if (propertyName == null)
- {
- throw new IllegalArgumentException();
- }
- if (!isModifiable())
- {
- throw new IllegalStateException("Cannot change state");
- }
-
- //
- String id = getId();
-
- //
- switch (stateType)
- {
- case NAVIGATIONAL:
- {
- // Have context process the change
- context.container.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.container.fireEvent(event);
- break;
- }
- case STRUCTURAL:
- {
- if (propertyValue instanceof String)
- {
- Map<String, String> changes = new HashMap<String, String>();
- changes.put(propertyName, (String)propertyValue);
-
- // Have context process change
- StructuralObject.Update update;
- try
- {
- update = context.container.structuralStateContext.update(context.structuralObject, changes);
- }
- catch (StateException e)
- {
- validate();
-
- //
- throw e;
- }
-
- //
- context.container.update(update);
-
- // Broadcast event
- StructuralStateModification mod = new StructuralStateModification.Update(changes);
- StateChange<StructuralStateModification> change = new StateChange<StructuralStateModification>(id, mod);
- StateChangeEvent event = new StateChangeEvent(change);
- context.container.fireEvent(event);
- }
- else
- {
- throw new StateChangeVetoException("Structural property value must be string value");
- }
- break;
- }
- default:
- throw new AssertionError();
- }
- }
-
- public final UIContainerObject getChild(String name)
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
- if (name == null)
- {
- throw new IllegalArgumentException("No null name accepted");
- }
-
- //
- for (UIContainerObject child : getChildren())
- {
- if (child.getName().equals(name))
- {
- return child;
- }
- }
-
- //
- return null;
- }
-
- public final String getName()
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
-
- //
- return context.structuralObject.getState().getName();
- }
-
- public final UIObject getParent()
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
-
- //
- return context.parent.get();
- }
-
- public final List<UIContainerObject> getChildren()
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
-
- //
- return context.children.get();
- }
-
- 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;
- try
- {
- creation = context.container.structuralStateContext.create(context.structuralObject, type, name, EMPTY_STATE);
- }
- catch (StateException e)
- {
- context.updateStatus(e);
-
- //
- throw e;
- }
-
- //
- context.container.update(creation);
-
- //
- StructuralObject child = creation.getChild();
-
- // Eventing
- StructuralStateModification mod = new StructuralStateModification.Creation(type, name, EMPTY_STATE);
- StateChange<StructuralStateModification> change = new StateChange<StructuralStateModification>(child.getId(), mod);
- StateChangeEvent event = new StateChangeEvent(change);
- context.container.fireEvent(event);
-
- //
- return type.cast(context.getObject(child.getId()));
- }
-
- public final void destroyChild(String name) throws IllegalArgumentException, StateException
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
- if (name == null)
- {
- throw new IllegalArgumentException();
- }
- if (!isModifiable())
- {
- throw new IllegalStateException("Cannot change state");
- }
-
- // Get the named child
- UIContainerObject namedChild = getChild(name);
-
- //
- if (namedChild == null)
- {
- throw new IllegalArgumentException("No such child with name " + name);
- }
-
- // Destroy the child
- StructuralObject.Destruction destruction = context.container.structuralStateContext.destroy(namedChild.getContext().structuralObject);
-
- //
- context.container.update(destruction);
- }
-
- 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 UIContainerObject)
- {
- //
- UIContainerObject tmp = (UIContainerObject)destination;
-
- // Perform the move operation
- StructuralObject.Move move = context.container.structuralStateContext.move(context.structuralObject, tmp.getContext().structuralObject);
-
- //
- context.container.update(move);
- }
- else
- {
- throw new IllegalArgumentException("Object not of right 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, 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-27 13:25:10 UTC (rev 9390)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-27 17:00:47 UTC (rev 9391)
@@ -31,13 +31,14 @@
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 org.jboss.portal.presentation.impl.model.container.spi.UIContainerObject;
+import org.jboss.portal.presentation.impl.model.container.spi.UIObjectFactory;
import org.jboss.portal.common.NotYetImplemented;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.AbstractList;
import java.util.Iterator;
/**
@@ -82,17 +83,23 @@
put(root);
}
- private UIContainerObject create(StructuralObject structuralObject)
+ UIContainerObject create(StructuralObject structuralObject)
{
// Create context
- UIObjectContext context = new UIObjectContext(this, structuralObject);
+ ObjectContext objectContext = new ObjectContext(this, structuralObject);
+ AssociationContext associationContext = new AssociationContext();
+ // Wire
+ objectContext.associationContext = associationContext;
+ associationContext.owner = objectContext;
+
// Create container object
UIContainerObject object = factory.createObject(structuralObject.getState().getType());
// Contextualize
- object.setContext(context);
+ object.setContext(objectContext);
+ //
return object;
}
@@ -126,7 +133,7 @@
}
//
- UIObjectContext context = object.getContext();
+ ObjectContext context = (ObjectContext)object.getContext();
context.structuralObject = update.getObject();
}
else if (change instanceof StructuralObject.Creation)
@@ -143,13 +150,13 @@
}
//
- UIObjectContext parentContext = parent.getContext();
+ ObjectContext parentContext = (ObjectContext)parent.getContext();
//
parentContext.structuralObject = creation.getParent();
//
- if (parentContext.children.relateds != null)
+ if (parentContext.associationContext.children.relateds != null)
{
UIContainerObject child = create(creation.getChild());
@@ -157,7 +164,7 @@
put(child);
//
- parentContext.children.relateds.add(child);
+ parentContext.associationContext.children.relateds.add(child);
}
}
else if (change instanceof StructuralObject.Destruction)
@@ -170,15 +177,15 @@
//
if (parent != null)
{
- UIObjectContext parentContext = parent.getContext();
+ ObjectContext parentContext = (ObjectContext)parent.getContext();
//
parentContext.structuralObject = destruction.getParent();
//
- if (parentContext.children.relateds != null)
+ if (parentContext.associationContext.children.relateds != null)
{
- for (Iterator<UIContainerObject> i = parentContext.children.relateds.iterator();i.hasNext();)
+ for (Iterator<UIContainerObject> i = parentContext.associationContext.children.relateds.iterator();i.hasNext();)
{
UIContainerObject child = i.next();
@@ -195,12 +202,13 @@
//
for (String id : destruction.getIds())
{
- UIContainerObject o = universe.remove(id);
+ UIContainerObject destroyed = universe.remove(id);
//
- if (o != null)
+ if (destroyed != null)
{
- o.getContext().status = UIObject.Status.INVALID;
+ ObjectContext destroyedContext = (ObjectContext)destroyed.getContext();
+ destroyedContext.status = UIObject.Status.INVALID;
}
}
}
@@ -216,15 +224,15 @@
// Update parent
if (parent != null)
{
- UIObjectContext parentContext = parent.getContext();
+ ObjectContext parentContext = (ObjectContext)parent.getContext();
// Update so
parentContext.structuralObject = move.getParent();
// Remove the child if the relationship is loaded on this side
- if (parentContext.children.relateds != null)
+ if (parentContext.associationContext.children.relateds != null)
{
- for (Iterator<UIContainerObject> i = parentContext.children.relateds.iterator();i.hasNext();)
+ for (Iterator<UIContainerObject> i = parentContext.associationContext.children.relateds.iterator();i.hasNext();)
{
UIContainerObject child = i.next();
@@ -241,13 +249,13 @@
//
if (destination != null)
{
- UIObjectContext destinationContext = destination.getContext();
+ ObjectContext destinationContext = (ObjectContext)destination.getContext();
//
destinationContext.structuralObject = move.getDestination();
//
- if (destinationContext.children.relateds != null)
+ if (destinationContext.associationContext.children.relateds != null)
{
// Now we really need to add the source as we load collections entirely
if (source == null)
@@ -259,29 +267,29 @@
}
//
- destinationContext.children.relateds.add(source);
+ destinationContext.associationContext.children.relateds.add(source);
}
}
// Update source
if (source != null)
{
- UIObjectContext sourceContext = source.getContext();
+ ObjectContext sourceContext = (ObjectContext)source.getContext();
// Update so
sourceContext.structuralObject = move.getSource();
//
- if (sourceContext.parent.loaded)
+ if (sourceContext.associationContext.parent.loaded)
{
if (destination != null)
{
- sourceContext.parent.related = destination;
+ sourceContext.associationContext.parent.related = destination;
}
else
{
- sourceContext.parent.related = null;
- sourceContext.parent.loaded = false;
+ sourceContext.associationContext.parent.related = null;
+ sourceContext.associationContext.parent.loaded = false;
}
}
}
@@ -359,11 +367,11 @@
}
}
- void validate(UIManagedObject object, UIObject.Visitor scope)
+ void validate(ManagedObject object, UIObject.Visitor scope)
{
if (scope.enterObject(object))
{
- UIObjectContext context = object.context;
+ ObjectContext context = object.context;
// We do it only if it is not yet invalid
if (context.isValid())
@@ -381,15 +389,18 @@
// Continue only if it is valid
if (context.isValid())
{
- boolean loaded = context.children.relateds != null;
+ boolean loaded = context.associationContext.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())
+ for (UIContainerObject child : context.associationContext.children.get())
{
- validate(child.getContext().managedObject, scope);
+ ObjectContext childContext = (ObjectContext)child.getContext();
+
+ //
+ validate(childContext.managedObject, scope);
}
}
}
@@ -400,11 +411,11 @@
}
}
- void refresh(UIManagedObject object, UIObject.Visitor scope)
+ void refresh(ManagedObject object, UIObject.Visitor scope)
{
if (scope.enterObject(object))
{
- UIObjectContext context = object.context;
+ ObjectContext context = object.context;
//
switch (context.status)
@@ -418,7 +429,7 @@
// Update the structural state
if (!context.structuralObject.compareTo(refresh.getObject()))
{
- boolean loaded = context.children.relateds != null;
+ boolean loaded = context.associationContext.children.relateds != null;
//
if (loaded)
@@ -436,18 +447,18 @@
//
if (added != null)
{
- UIObjectContext addedContext = added.getContext();
+ ObjectContext addedContext = (ObjectContext)added.getContext();
// Set the parent as stale if needed
- if (addedContext.parent.loaded)
+ if (addedContext.associationContext.parent.loaded)
{
- UIObjectContext addedParentContext = addedContext.parent.related.getContext();
+ ObjectContext addedParentContext = (ObjectContext)addedContext.associationContext.parent.related.getContext();
// Mark the parent as stale
addedParentContext.status = UIObject.Status.STALE;
//
- addedParentContext.parent.related = get(context.structuralObject.getId());
+ addedParentContext.associationContext.parent.related = get(context.structuralObject.getId());
}
}
else
@@ -477,8 +488,11 @@
{
UIContainerObject stale = get(staleSO);
+ //
+ ObjectContext staleContext = (ObjectContext)stale.getContext();
+
// Mark as stale
- stale.getContext().status = UIObject.Status.STALE;
+ staleContext.status = UIObject.Status.STALE;
//
children.add(stale);
@@ -501,7 +515,7 @@
// Update state
context.structuralObject = refresh.getObject();
context.status = UIObject.Status.VALID;
- context.children.relateds = children;
+ context.associationContext.children.relateds = children;
}
}
}
@@ -522,228 +536,18 @@
}
}
- ManyToOne createManyToOne(UIObjectContext context)
+ void put(UIContainerObject object)
{
- return new ManyToOne(context);
- }
-
- OneToMany createOneToMany(UIObjectContext context)
- {
- return new OneToMany(context);
- }
-
- // Private **********************************************************************************************************
-
-// /**
-// * Update the state of an object if it is present. It will also reset the parent and children
-// * relationships in order to force a implicit refresh.
-// *
-// * @param structuralObject the structural object to update
-// * @return the object API implementation
-// */
-// private UIContainerObject update(StructuralObject structuralObject, boolean compareWithExisting)
-// {
-// UIContainerObject containerObject = universe.get(structuralObject.getId());
-//
-// //
-// if (containerObject == null)
-// {
-// containerObject = new UIObjectFactory().createObject(structuralObject.getState().getType());
-//
-// //
-// containerObject.setContext(new UIObjectContext(this, structuralObject));
-//
-// //
-// universe.put(structuralObject.getId(), containerObject);
-// }
-// else
-// {
-// UIObjectContext context = containerObject.getContext();
-//
-// //
-// context.structuralObject = structuralObject;
-// context.parent.clear();
-// context.children.clear();
-// }
-//
-// //
-// return containerObject;
-// }
-
- private void put(UIContainerObject object)
- {
universe.put(object.getId(), object);
}
- private UIContainerObject get(String id)
+ UIContainerObject get(String id)
{
return universe.get(id);
}
- private UIContainerObject get(StructuralObject so)
+ UIContainerObject get(StructuralObject so)
{
return universe.get(so.getId());
}
-
- class ManyToOne
- {
-
- /** . */
- private final UIObjectContext owner;
-
- /** . */
- private boolean loaded;
-
- /** . */
- private UIContainerObject related;
-
- private ManyToOne(UIObjectContext owner)
- {
- this.owner = owner;
- }
-
- UIContainerObject get()
- {
- if (!loaded)
- {
- StructuralObject parentSO = structuralStateContext.loadParent(owner.structuralObject);
-
- // If null it is the root so nothing is done
- if (parentSO != null)
- {
- UIContainerObject parent = UIObjectContainer.this.get(parentSO);
-
- //
- if (parent != null)
- {
- related = parent;
-
- //
- UIObjectContext parentContext = parent.getContext();
-
- //
- if (!parentSO.compareTo(parentContext.structuralObject))
- {
- parentContext.status = UIObject.Status.STALE;
- }
- }
- else
- {
- parent = create(parentSO);
-
- //
- put(parent);
-
- //
- related = parent;
- }
- }
- }
-
- // Try to resolve the relationship
-
-
- //
- return related;
- }
- }
-
- class OneToMany
- {
-
- /** . */
- private final ProxyList list;
-
- /** . */
- private final UIObjectContext owner;
-
- /** . */
- private List<UIContainerObject> relateds;
-
- private OneToMany(UIObjectContext object)
- {
- this.owner = object;
- this.list = new ProxyList();
- this.relateds = null;
- }
-
- List<UIContainerObject> get()
- {
- return list;
- }
-
- private List<UIContainerObject> getChildren(StructuralObject structuralObject)
- {
- ArrayList<UIContainerObject> children = new ArrayList<UIContainerObject>();
-
- //
- for (StructuralObject childSO : structuralStateContext.loadChildren(structuralObject))
- {
- UIContainerObject child = UIObjectContainer.this.get(childSO);
-
- //
- if (child != null)
- {
- UIObjectContext childContext = child.getContext();
-
- //
- if (!childContext.structuralObject.compareTo(childSO))
- {
- childContext.status = UIObject.Status.STALE;
- }
- }
- else
- {
- child = create(childSO);
-
- //
- put(child);
- }
-
- //
- children.add(child);
- }
-
- //
- return children;
- }
-
- private class ProxyList extends AbstractList<UIContainerObject>
- {
- public UIContainerObject get(int i)
- {
- if (!owner.isValid())
- {
- throw new IllegalStateException("Relationship not valid");
- }
-
- // Load the entire relationship
- if (relateds == null)
- {
- relateds = getChildren(owner.structuralObject);
- }
-
- //
- return relateds.get(i);
- }
-
- public int size()
- {
- if (!owner.isValid())
- {
- throw new IllegalStateException("Relationship cannot be used because the owner " + owner + " is not valid");
- }
- if (relateds == null)
- {
- relateds = getChildren(owner.structuralObject);
- }
- return relateds.size();
- }
-
- public String toString()
- {
- return "ProxyList[" + owner + "]";
- }
- }
- }
}
Deleted: 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-27 13:25:10 UTC (rev 9390)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-27 17:00:47 UTC (rev 9391)
@@ -1,142 +0,0 @@
-/******************************************************************************
- * 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.impl.model.container;
-
-import org.jboss.portal.presentation.model.state.structural.StructuralObject;
-import org.jboss.portal.presentation.model.state.structural.StructuralState;
-import org.jboss.portal.presentation.model.state.StateException;
-import org.jboss.portal.presentation.model.state.NoSuchStateException;
-import org.jboss.portal.presentation.model.state.StaleStateException;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.UIContext;
-import org.jboss.portal.presentation.model.ModelListener;
-
-/**
- * Encapsulate internal of an object.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public final class UIObjectContext
-{
-
- /** . */
- final UIObjectContainer container;
-
- /** . */
- final UIManagedObject managedObject;
-
- /** . */
- final UIObjectContainer.OneToMany children;
-
- /** . */
- final UIObjectContainer.ManyToOne parent;
-
- /** . */
- StructuralObject structuralObject;
-
- /** . */
- UIObject.Status status;
-
- public UIObjectContext(UIObjectContainer container, StructuralObject structuralObject)
- {
- if (container == null)
- {
- throw new IllegalArgumentException();
- }
- if (structuralObject == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- this.container = container;
- this.structuralObject = structuralObject;
- this.status = UIObject.Status.VALID;
- this.managedObject = new UIManagedObject(this);
- this.children = container.createOneToMany(this);
- this.parent = container.createManyToOne(this);
- }
-
- // Public ***********************************************************************************************************
-
- public UIObject getManagedObject()
- {
- return managedObject;
- }
-
- public UIObject getObject(String id)
- {
- return container.getObject(id);
- }
-
- public void addModelListener(ModelListener listener)
- {
- container.addModelListener(listener);
- }
-
- //
-
- StructuralState getState()
- {
- return structuralObject.getState();
- }
-
- UIContext getRoot()
- {
- return container.root;
- }
-
- UIObject.Status getStatus()
- {
- return status;
- }
-
- boolean isValid()
- {
- return status == UIObject.Status.VALID;
- }
-
- // Package protected ************************************************************************************************
-
- void updateStatus(StateException e)
- {
- if (e instanceof NoSuchStateException)
- {
- status = UIObject.Status.INVALID;
- }
- else if (e instanceof StaleStateException)
- {
- status = UIObject.Status.STALE;
- }
- else
- {
- throw new AssertionError(e);
- }
- }
-
- public String toString()
- {
- return "UIObjectContext[" + structuralObject.getId() + "]";
- }
-}
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java 2007-12-27 13:25:10 UTC (rev 9390)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java 2007-12-27 17:00:47 UTC (rev 9391)
@@ -1,99 +0,0 @@
-/******************************************************************************
- * 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.impl.model.container;
-
-import org.jboss.portal.presentation.model.UIContext;
-import org.jboss.portal.presentation.model.UIPortal;
-import org.jboss.portal.presentation.model.UIPage;
-import org.jboss.portal.presentation.model.UIContainer;
-import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.impl.model.UIContextImpl;
-import org.jboss.portal.presentation.impl.model.UIPortalImpl;
-import org.jboss.portal.presentation.impl.model.UIPageImpl;
-import org.jboss.portal.presentation.impl.model.UIContainerImpl;
-import org.jboss.portal.presentation.impl.model.UIWindowImpl;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class UIObjectFactory
-{
-
- public UIContainerObject createObject(Class<? extends UIObject> type)
- {
- if(type == UIContext.class)
- {
- return new UIContextImpl();
- }
- else if(type == UIPortal.class)
- {
- return new UIPortalImpl();
- }
- else if(type == UIPage.class)
- {
- return new UIPageImpl();
- }
- else if(type == UIContainer.class)
- {
- return new UIContainerImpl();
- }
- else if(type == UIWindow.class)
- {
- return new UIWindowImpl();
- }
- else
- {
- throw new AssertionError();
- }
- }
-
-// public <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
-// {
-// if(type == UIContext.class)
-// {
-// return type == UIPortal.class;
-// }
-// else if (type == UIPortal.class)
-// {
-// return type == UIPage.class;
-// }
-// else if (type == UIPage.class)
-// {
-// return type == UIPage.class || type == UIContainer.class || type == UIWindow.class;
-// }
-// else if (type == UIContainer.class)
-// {
-// return type == UIWindow.class;
-// }
-// else if (type == UIWindow.class)
-// {
-// return false;
-// }
-// else
-// {
-// throw new AssertionError();
-// }
-// }
-}
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIContainerObject.java (from rev 9382, branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java)
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIContainerObject.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIContainerObject.java 2007-12-27 17:00:47 UTC (rev 9391)
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * 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.impl.model.container.spi;
+
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.impl.model.container.spi.UIObjectContext;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface UIContainerObject extends UIObject
+{
+
+ UIObjectContext getContext();
+
+ void setContext(UIObjectContext context);
+
+}
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIObjectContext.java (from rev 9386, 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/spi/UIObjectContext.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIObjectContext.java 2007-12-27 17:00:47 UTC (rev 9391)
@@ -0,0 +1,43 @@
+/******************************************************************************
+ * 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.impl.model.container.spi;
+
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.ModelListener;
+
+/**
+ * Encapsulate internal of an object.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface UIObjectContext
+{
+
+ UIObject getManagedObject();
+
+ UIObject getObject(String id);
+
+ void addModelListener(ModelListener listener);
+
+}
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIObjectFactory.java (from rev 9382, branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java)
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIObjectFactory.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIObjectFactory.java 2007-12-27 17:00:47 UTC (rev 9391)
@@ -0,0 +1,99 @@
+/******************************************************************************
+ * 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.impl.model.container.spi;
+
+import org.jboss.portal.presentation.model.UIContext;
+import org.jboss.portal.presentation.model.UIPortal;
+import org.jboss.portal.presentation.model.UIPage;
+import org.jboss.portal.presentation.model.UIContainer;
+import org.jboss.portal.presentation.model.UIWindow;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.impl.model.UIContextImpl;
+import org.jboss.portal.presentation.impl.model.UIPortalImpl;
+import org.jboss.portal.presentation.impl.model.UIPageImpl;
+import org.jboss.portal.presentation.impl.model.UIContainerImpl;
+import org.jboss.portal.presentation.impl.model.UIWindowImpl;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UIObjectFactory
+{
+
+ public UIContainerObject createObject(Class<? extends UIObject> type)
+ {
+ if(type == UIContext.class)
+ {
+ return new UIContextImpl();
+ }
+ else if(type == UIPortal.class)
+ {
+ return new UIPortalImpl();
+ }
+ else if(type == UIPage.class)
+ {
+ return new UIPageImpl();
+ }
+ else if(type == UIContainer.class)
+ {
+ return new UIContainerImpl();
+ }
+ else if(type == UIWindow.class)
+ {
+ return new UIWindowImpl();
+ }
+ else
+ {
+ throw new AssertionError();
+ }
+ }
+
+// public <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
+// {
+// if(type == UIContext.class)
+// {
+// return type == UIPortal.class;
+// }
+// else if (type == UIPortal.class)
+// {
+// return type == UIPage.class;
+// }
+// else if (type == UIPage.class)
+// {
+// return type == UIPage.class || type == UIContainer.class || type == UIWindow.class;
+// }
+// else if (type == UIContainer.class)
+// {
+// return type == UIWindow.class;
+// }
+// else if (type == UIWindow.class)
+// {
+// return false;
+// }
+// else
+// {
+// throw new AssertionError();
+// }
+// }
+}
16 years, 4 months
JBoss Portal SVN: r9390 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: test/model and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-27 08:25:10 -0500 (Thu, 27 Dec 2007)
New Revision: 9390
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
more implementation of refresh operation
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-27 12:09:04 UTC (rev 9389)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-27 13:25:10 UTC (rev 9390)
@@ -31,6 +31,7 @@
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 org.jboss.portal.common.NotYetImplemented;
import java.util.ArrayList;
import java.util.HashMap;
@@ -38,8 +39,6 @@
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>
@@ -419,50 +418,91 @@
// Update the structural state
if (!context.structuralObject.compareTo(refresh.getObject()))
{
- context.structuralObject = refresh.getObject();
- }
+ boolean loaded = context.children.relateds != null;
- //
- boolean loaded = context.children.relateds != null;
+ //
+ if (loaded)
+ {
+ boolean refreshChildren = scope.enterChildren(object, loaded);
- //
- if (loaded)
- {
- boolean refreshChildren = scope.enterChildren(object, loaded);
+ // The new list of children
+ List<UIContainerObject> children = new ArrayList<UIContainerObject>();
- // Removals
- for (String removedId : refresh.getRemovedChildren())
- {
- }
+ // Take care of the added children
+ for (StructuralObject addedSO : refresh.getAddedChildren())
+ {
+ UIContainerObject added = get(addedSO);
+ //
+ if (added != null)
+ {
+ UIObjectContext addedContext = added.getContext();
- // Compute set of added ids
-// Set<String> addedIds = new HashSet<String>();
-// for (StructuralObject addedSO : refresh.getAddedChildren())
-// {
-// addedIds.add(addedSO.getId());
-// }
+ // Set the parent as stale if needed
+ if (addedContext.parent.loaded)
+ {
+ UIObjectContext addedParentContext = addedContext.parent.related.getContext();
- List<UIContainerObject> children = new ArrayList<UIContainerObject>();
+ // Mark the parent as stale
+ addedParentContext.status = UIObject.Status.STALE;
- //
- for (StructuralObject addedSO : refresh.getAddedChildren())
- {
- }
+ //
+ addedParentContext.parent.related = get(context.structuralObject.getId());
+ }
+ }
+ else
+ {
+ added = create(addedSO);
- //
- for (String validId : refresh.getValidChildren())
- {
- }
+ //
+ put(added);
+ }
+ //
+ children.add(added);
+ }
- //
- for (StructuralObject staleSO : refresh.getStaleChildren().values())
- {
+ //
+ for (String validId : refresh.getValidChildren())
+ {
+ UIContainerObject valid = get(validId);
+
+ // It must be here...
+ children.add(valid);
+ }
+
+
+ //
+ for (StructuralObject staleSO : refresh.getStaleChildren().values())
+ {
+ UIContainerObject stale = get(staleSO);
+
+ // Mark as stale
+ stale.getContext().status = UIObject.Status.STALE;
+
+ //
+ children.add(stale);
+ }
+
+ // Removals
+ for (String removedId : refresh.getRemovedChildren())
+ {
+ UIContainerObject removed = get(removedId);
+
+ //
+ if (removed != null)
+ {
+ // We should try to now if it is somehow referenced by someone that is not us
+ // i.e it has been already be moved somewhere else
+ throw new NotYetImplemented();
+ }
+ }
+
+ // Update state
+ context.structuralObject = refresh.getObject();
+ context.status = UIObject.Status.VALID;
+ context.children.relateds = children;
}
-
- // Update to valid
- context.status = UIObject.Status.VALID;
}
}
catch (NoSuchStateException e)
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-27 12:09:04 UTC (rev 9389)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-27 13:25:10 UTC (rev 9390)
@@ -647,7 +647,38 @@
assertSame(context.getObject(daaId), daa);
}
+ public void testRefreshAfterConcurrentMove() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockBar = mockRoot.addChild("bar", MockObject.Type.PORTAL);
+
+ MockObject mockFooJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+ MockObject mockFooDaa = mockFoo.addChild("daa", MockObject.Type.PAGE);
+
+ MockObject mockBarDaa = mockBar.addChild("daa", MockObject.Type.PAGE);
+
+ // Load fully the context 1
+ UIContext context1 = createContext();
+ loadDescendants(context1);
+
+ // Concurrent move
+ UIContext context2 = createContext();
+ context2.getChild("foo").getChild("juu").move(context2.getChild("bar"));
+
+ //
+ context1.getChild("bar").refresh();
+ }
+
+ private void loadDescendants(UIObject object)
+ {
+ for (UIObject child : object.getChildren())
+ {
+ loadDescendants(child);
+ }
+ }
+
public void testMove() throws Exception
{
MockObject mockRoot = model.getRoot();
16 years, 4 months
JBoss Portal SVN: r9389 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: test/model and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-27 07:09:04 -0500 (Thu, 27 Dec 2007)
New Revision: 9389
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
Log:
- reimplemented move operation on the model
- fixed a bug in the move operation in the structural state context
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-27 11:16:19 UTC (rev 9388)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-27 12:09:04 UTC (rev 9389)
@@ -205,19 +205,88 @@
}
}
}
-// else if (change instanceof StructuralObject.Move)
-// {
-// StructuralObject.Move move = (StructuralObject.Move)change;
-//
-// //
-// update(move.getParent());
-//
-// //
-// update(move.getSource());
-//
-// //
-// update(move.getDestination());
-// }
+ else if (change instanceof StructuralObject.Move)
+ {
+ StructuralObject.Move move = (StructuralObject.Move)change;
+
+ // Get the container object (some may not be loaded)
+ UIContainerObject parent = get(move.getParent());
+ UIContainerObject destination = get(move.getDestination());
+ UIContainerObject source = get(move.getSource());
+
+ // Update parent
+ if (parent != null)
+ {
+ UIObjectContext parentContext = parent.getContext();
+
+ // Update so
+ parentContext.structuralObject = move.getParent();
+
+ // Remove the child if the relationship is loaded on this side
+ if (parentContext.children.relateds != null)
+ {
+ for (Iterator<UIContainerObject> i = parentContext.children.relateds.iterator();i.hasNext();)
+ {
+ UIContainerObject child = i.next();
+
+ //
+ if (child.getId().equals(move.getSource().getId()))
+ {
+ i.remove();
+ break;
+ }
+ }
+ }
+ }
+
+ //
+ if (destination != null)
+ {
+ UIObjectContext destinationContext = destination.getContext();
+
+ //
+ destinationContext.structuralObject = move.getDestination();
+
+ //
+ if (destinationContext.children.relateds != null)
+ {
+ // Now we really need to add the source as we load collections entirely
+ if (source == null)
+ {
+ source = create(move.getSource());
+
+ //
+ put(source);
+ }
+
+ //
+ destinationContext.children.relateds.add(source);
+ }
+ }
+
+ // Update source
+ if (source != null)
+ {
+ UIObjectContext sourceContext = source.getContext();
+
+ // Update so
+ sourceContext.structuralObject = move.getSource();
+
+ //
+ if (sourceContext.parent.loaded)
+ {
+ if (destination != null)
+ {
+ sourceContext.parent.related = destination;
+ }
+ else
+ {
+ sourceContext.parent.related = null;
+ sourceContext.parent.loaded = false;
+ }
+ }
+ }
+ }
else
{
throw new AssertionError();
@@ -225,9 +294,8 @@
}
/**
- * Get an object from the universe. If the parameter <code>loadIfAbsent</code> has the value <code>false</code>
- * and the object is not in the universe it will throw an <code>AssertionError</code> otherwise it will return
- * the object.
+ * Returns an object an object specified by the id that is referenced by this context or load
+ * it if it is not present.
*
* @param id the id of the object to obtain
* @return the loaded object
@@ -538,12 +606,6 @@
//
return related;
}
-
- void clear()
- {
- related = null;
- loaded = false;
- }
}
class OneToMany
@@ -570,11 +632,6 @@
return list;
}
- void clear()
- {
- relateds = null;
- }
-
private List<UIContainerObject> getChildren(StructuralObject structuralObject)
{
ArrayList<UIContainerObject> children = new ArrayList<UIContainerObject>();
@@ -634,7 +691,7 @@
{
if (!owner.isValid())
{
- throw new IllegalStateException("Relationship not valid");
+ throw new IllegalStateException("Relationship cannot be used because the owner " + owner + " is not valid");
}
if (relateds == null)
{
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-27 11:16:19 UTC (rev 9388)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-27 12:09:04 UTC (rev 9389)
@@ -359,6 +359,49 @@
assertEquals(Collections.singletonList(mockBar), mockRoot.getChildren());
}
+ public void testMove2() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+ MockObject mockBar = mockRoot.addChild("bar", MockObject.Type.PAGE);
+
+ //
+ String fooId = mockFoo.getId();
+ String barId = mockBar.getId();
+ String rootId = mockRoot.getId();
+
+ //
+ StructuralObject fooSO = ssc.load(fooId);
+ StructuralObject barSO = ssc.load(barId);
+ StructuralObject rootSO = ssc.load(rootId);
+
+ //
+ StructuralObject.Move move = ssc.move(fooSO, barSO);
+
+ //
+ assertNotNull(move);
+
+ //
+ StructuralObject newFooSO = move.getSource();
+ StructuralObject newBarSO = move.getDestination();
+ StructuralObject newRootSO = move.getParent();
+
+ //
+ assertEquals(rootId, newRootSO.getId());
+ assertEquals(fooId, newFooSO.getId());
+ assertEquals(barId, newBarSO.getId());
+
+ //
+ assertStale(fooSO);
+ assertStale(barSO);
+ assertStale(rootSO);
+
+ //
+ assertNotStale(newRootSO);
+ assertNotStale(newBarSO);
+ assertNotStale(newFooSO);
+ }
+
public void testMoveViolatesConstraint() throws MockException
{
MockObject mockRoot = model.getRoot();
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-27 11:16:19 UTC (rev 9388)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-27 12:09:04 UTC (rev 9389)
@@ -648,7 +648,7 @@
}
- public void _testMove() throws Exception
+ public void testMove() throws Exception
{
MockObject mockRoot = model.getRoot();
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-27 11:16:19 UTC (rev 9388)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-27 12:09:04 UTC (rev 9389)
@@ -323,7 +323,7 @@
mockSource.move(mockDestination);
//
- return new StructuralObject.Move(mockParent.takeSnapshot(), mockSource.takeSnapshot(), mockSource.takeSnapshot());
+ return new StructuralObject.Move(mockParent.takeSnapshot(), mockSource.takeSnapshot(), mockDestination.takeSnapshot());
}
catch (MockException e)
{
16 years, 4 months