JBoss Portal SVN: r9408 - 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-29 19:47:52 -0500 (Sat, 29 Dec 2007)
New Revision: 9408
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java
Log:
minor
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java 2007-12-30 00:46:39 UTC (rev 9407)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java 2007-12-30 00:47:52 UTC (rev 9408)
@@ -136,10 +136,7 @@
}
// Downgrade the related side
- if (loaded)
- {
- detach();
- }
+ detach();
//
attach(related);
16 years, 3 months
JBoss Portal SVN: r9407 - 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-29 19:46:39 -0500 (Sat, 29 Dec 2007)
New Revision: 9407
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java
Log:
minor
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java 2007-12-30 00:42:23 UTC (rev 9406)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java 2007-12-30 00:46:39 UTC (rev 9407)
@@ -136,7 +136,7 @@
}
// Downgrade the related side
- if (this.related != null)
+ if (loaded)
{
detach();
}
16 years, 3 months
JBoss Portal SVN: r9406 - 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-29 19:42:23 -0500 (Sat, 29 Dec 2007)
New Revision: 9406
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
Log:
added javadoc
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java 2007-12-29 22:56:28 UTC (rev 9405)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java 2007-12-30 00:42:23 UTC (rev 9406)
@@ -33,6 +33,7 @@
import java.util.Collection;
import java.util.AbstractSet;
import java.util.ArrayList;
+import java.util.Collections;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -41,10 +42,10 @@
final class RelationshipContext
{
- /** . */
+ /** The owner of the relationship. */
ObjectContext owner;
- /** . */
+ /** The many to one relationship that make an object reference its parent. */
final ManyToOne parent = new ManyToOne()
{
protected StructuralObject doLoad()
@@ -61,7 +62,7 @@
}
};
- /** . */
+ /** The one to many relationship that makes an object reference its children. */
final OneToMany children = new OneToMany()
{
protected Collection<StructuralObject> doLoad()
@@ -81,71 +82,92 @@
static abstract class ManyToOne
{
- /** . */
+ /** Indicates if the relationship is loaded. */
private boolean loaded;
- /** . */
+ /** The related object. */
private UIContainerObject related;
/** The context pointing at us via a OneToMany. */
private Set<ObjectContext> refs;
+ /** The refs field exposed in a non modifiable manner. */
+ private Set<ObjectContext> readOnlyRefs;
+
private ManyToOne()
{
this.loaded = false;
this.related = null;
this.refs = new HashSet<ObjectContext>();
+ this.readOnlyRefs = Collections.unmodifiableSet(refs);
}
Set<ObjectContext> getReferences()
{
- return refs;
+ return readOnlyRefs;
}
+ /**
+ * Returns true if the relationship is loaded
+ *
+ * @return the loaded status
+ */
boolean isLoaded()
{
return loaded;
}
- void setLoadedRelated(UIContainerObject newParent)
+ /**
+ * Updates the related to a new related object.
+ *
+ * @param related the new related
+ * @throws IllegalArgumentException if the related is null
+ * @throws IllegalStateException if the relationship is not loaded already
+ */
+ void setLoadedRelated(UIContainerObject related) throws IllegalStateException
{
- if (newParent == null)
+ if (!loaded)
{
- throw new IllegalArgumentException();
+ throw new IllegalStateException("Cannot set related of a non loaded association");
}
- if (!loaded)
+ if (related == null)
{
- throw new IllegalStateException("Cannot set parent of non loaded association");
+ throw new IllegalArgumentException();
}
// Downgrade the related side
- if (related != null)
+ if (this.related != null)
{
detach();
}
//
- if (newParent != null)
- {
- attach(newParent);
- }
- else
- {
- related = null;
- loaded = false;
- }
+ attach(related);
}
- UIContainerObject getLoadedRelated()
+ /**
+ * Returns the loaded related.
+ *
+ * @return the loaded related
+ * @throws IllegalStateException if the relationship is not loaded
+ */
+ UIContainerObject getLoadedRelated() throws IllegalStateException
{
if (!loaded)
{
throw new IllegalStateException("Cannot set parent of non loaded association");
}
+
+ //
return related;
}
- void clearLoadedRelated()
+ /**
+ * Clears the reference and unload the relationship.
+ *
+ * @throws IllegalStateException if the relationship is not loaded
+ */
+ void clear() throws IllegalStateException
{
if (!loaded)
{
@@ -154,12 +176,16 @@
// Downgrade realted
detach();
-
- //
- loaded = false;
}
- UIContainerObject getRelated()
+ /**
+ * Returns the related object. If the object is not loaded an attempt to load the state
+ * will be done.
+ *
+ * @return the related object
+ * @throws StateException if the state of the owner prevents to access the related
+ */
+ UIContainerObject getRelated() throws StateException
{
ObjectContext owner = getOwner();
@@ -187,8 +213,19 @@
*/
protected abstract StructuralObject doLoad() throws StateException;
+ /**
+ * The owner of the relationship.
+ *
+ * @return the owner
+ */
protected abstract ObjectContext getOwner();
+ /**
+ * Returns the related one to many relationship obtained from the related object.
+ *
+ * @param related the related
+ * @return the one to many
+ */
protected abstract OneToMany getOneToMany(UIContainerObject related);
private void attach(UIContainerObject related)
@@ -211,6 +248,7 @@
//
oneToMany.refs.add(owner);
this.related = related;
+ this.loaded = true;
}
private void detach()
@@ -233,12 +271,13 @@
//
oneToMany.refs.remove(owner);
this.related = null;
+ this.loaded = false;
}
/**
* 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.
+ * of the related side is successful the association is updated.
*/
private void load()
{
@@ -293,24 +332,28 @@
static abstract class OneToMany
{
- /** . */
- private final LazySet list;
+ /** The lazy read only set. */
+ private final LazySet set;
- /** . */
+ /** Indicates if the relationship is loaded. */
private boolean loaded;
- /** . */
+ /** The related object. */
private Set<UIContainerObject> relateds;
/** The contexts pointing at us via a ManyToOne. */
private Set<ObjectContext> refs;
+ /** The refs field exposed in a non modifiable manner. */
+ private Set<ObjectContext> readOnlyRefs;
+
private OneToMany()
{
- this.list = new LazySet();
+ this.set = new LazySet();
this.loaded = false;
this.relateds = new HashSet<UIContainerObject>();
this.refs = new HashSet<ObjectContext>();
+ this.readOnlyRefs = Collections.unmodifiableSet(refs);
}
boolean isLoaded()
@@ -389,12 +432,12 @@
Collection<UIContainerObject> getRelateds()
{
- return list;
+ return set;
}
Set<ObjectContext> getReferences()
{
- return refs;
+ return readOnlyRefs;
}
/**
@@ -561,7 +604,7 @@
public String toString()
{
- return "ProxyList[" + getOwner() + "]";
+ return "ProxySet[" + getOwner() + "]";
}
}
}
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-29 22:56:28 UTC (rev 9405)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-30 00:42:23 UTC (rev 9406)
@@ -45,7 +45,6 @@
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- *
*/
public final class UIObjectContainer
{
@@ -296,7 +295,7 @@
}
else
{
- sourceContext.relationshipContext.parent.clearLoadedRelated();
+ sourceContext.relationshipContext.parent.clear();
}
}
}
16 years, 3 months
JBoss Portal SVN: r9405 - 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-29 17:56:28 -0500 (Sat, 29 Dec 2007)
New Revision: 9405
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java
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/ObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
Log:
rename Associationcontext to RelationshipContext for more clarity
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-29 22:51:43 UTC (rev 9404)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-29 22:56:28 UTC (rev 9405)
@@ -27,7 +27,6 @@
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;
@@ -35,7 +34,6 @@
import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Collection;
@@ -274,7 +272,7 @@
context.checkAccess();
//
- return context.associationContext.parent.getRelated();
+ return context.relationshipContext.parent.getRelated();
}
public final Collection<UIContainerObject> getChildren()
@@ -282,7 +280,7 @@
context.checkAccess();
//
- return context.associationContext.children.getRelateds();
+ return context.relationshipContext.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/ObjectContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java 2007-12-29 22:51:43 UTC (rev 9404)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java 2007-12-29 22:56:28 UTC (rev 9405)
@@ -52,7 +52,7 @@
final ManagedObject managedObject;
/** The associations. */
- AssociationContext associationContext;
+ RelationshipContext relationshipContext;
/** What we know from the structural context. */
StructuralObject structuralObject;
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java (from rev 9400, 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/RelationshipContext.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java 2007-12-29 22:56:28 UTC (rev 9405)
@@ -0,0 +1,568 @@
+/******************************************************************************
+ * 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.state.StateException;
+import org.jboss.portal.presentation.model.UIObject;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collection;
+import java.util.AbstractSet;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+final class RelationshipContext
+{
+
+ /** . */
+ ObjectContext owner;
+
+ /** . */
+ final ManyToOne parent = new ManyToOne()
+ {
+ protected StructuralObject doLoad()
+ {
+ return owner.container.structuralStateContext.loadParent(owner.structuralObject);
+ }
+ protected ObjectContext getOwner()
+ {
+ return owner;
+ }
+ protected OneToMany getOneToMany(UIContainerObject related)
+ {
+ return ((ObjectContext)related.getContext()).relationshipContext.children;
+ }
+ };
+
+ /** . */
+ final OneToMany children = new OneToMany()
+ {
+ protected Collection<StructuralObject> doLoad()
+ {
+ return owner.container.structuralStateContext.loadChildren(owner.structuralObject);
+ }
+ protected ObjectContext getOwner()
+ {
+ return owner;
+ }
+ protected ManyToOne getManyToOne(UIContainerObject related)
+ {
+ return ((ObjectContext)related.getContext()).relationshipContext.parent;
+ }
+ };
+
+ static abstract class ManyToOne
+ {
+
+ /** . */
+ private boolean loaded;
+
+ /** . */
+ private UIContainerObject related;
+
+ /** The context pointing at us via a OneToMany. */
+ private Set<ObjectContext> refs;
+
+ private ManyToOne()
+ {
+ this.loaded = false;
+ this.related = null;
+ this.refs = new HashSet<ObjectContext>();
+ }
+
+ Set<ObjectContext> getReferences()
+ {
+ return refs;
+ }
+
+ 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");
+ }
+
+ // Downgrade the related side
+ if (related != null)
+ {
+ detach();
+ }
+
+ //
+ if (newParent != null)
+ {
+ attach(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");
+ }
+
+ // Downgrade realted
+ detach();
+
+ //
+ loaded = false;
+ }
+
+ UIContainerObject getRelated()
+ {
+ ObjectContext owner = getOwner();
+
+ //
+ owner.checkAccess();
+
+ //
+ if (!loaded)
+ {
+ load();
+ }
+
+ //
+ owner.checkAccess();
+
+ //
+ return related;
+ }
+
+ /**
+ * Loads the related side.
+ *
+ * @return the loaded structural object
+ * @throws StateException if the load operation cannot be achieved
+ */
+ protected abstract StructuralObject doLoad() throws StateException;
+
+ protected abstract ObjectContext getOwner();
+
+ protected abstract OneToMany getOneToMany(UIContainerObject related);
+
+ private void attach(UIContainerObject related)
+ {
+ if (this.related != null)
+ {
+ throw new AssertionError("BUG");
+ }
+
+ //
+ OneToMany oneToMany = getOneToMany(related);
+ ObjectContext owner = getOwner();
+
+ //
+ if (oneToMany.refs.contains(owner))
+ {
+ throw new AssertionError("BUG");
+ }
+
+ //
+ oneToMany.refs.add(owner);
+ this.related = related;
+ }
+
+ private void detach()
+ {
+ if (related == null)
+ {
+ throw new AssertionError("BUG");
+ }
+
+ //
+ OneToMany oneToMany = getOneToMany(related);
+ ObjectContext owner = getOwner();
+
+ //
+ if (!oneToMany.refs.contains(owner))
+ {
+ throw new AssertionError("BUG");
+ }
+
+ //
+ oneToMany.refs.remove(owner);
+ this.related = null;
+ }
+
+ /**
+ * 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()
+ {
+ ObjectContext owner = getOwner();
+
+ //
+ try
+ {
+ StructuralObject relatedSO = doLoad();
+
+ // If null it is the root so nothing is done
+ if (relatedSO != null)
+ {
+ UIContainerObject related = owner.container.get(relatedSO);
+
+ //
+ if (related != null)
+ {
+ attach(related);
+
+ //
+ ObjectContext parentContext = (ObjectContext)related.getContext();
+
+ //
+ if (!relatedSO.compareTo(parentContext.structuralObject))
+ {
+ parentContext.status = UIObject.Status.STALE;
+ }
+ }
+ else
+ {
+ related = owner.container.create(relatedSO);
+
+ //
+ owner.container.attach(related);
+
+ //
+ attach(related);
+ }
+ }
+
+ // Set as loaded
+ this.loaded = true;
+ }
+ catch (StateException e)
+ {
+ owner.updateStatus(e);
+ }
+ }
+ }
+
+ static abstract class OneToMany
+ {
+
+ /** . */
+ private final LazySet list;
+
+ /** . */
+ private boolean loaded;
+
+ /** . */
+ private Set<UIContainerObject> relateds;
+
+ /** The contexts pointing at us via a ManyToOne. */
+ private Set<ObjectContext> refs;
+
+ private OneToMany()
+ {
+ this.list = new LazySet();
+ this.loaded = false;
+ this.relateds = new HashSet<UIContainerObject>();
+ this.refs = new HashSet<ObjectContext>();
+ }
+
+ boolean isLoaded()
+ {
+ return loaded;
+ }
+
+ void addLoadedRelated(UIContainerObject related)
+ {
+ if (!isLoaded())
+ {
+ 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");
+ }
+ }
+
+ //
+ attach(related);
+ }
+
+ void setLoadedRelateds(Set<UIContainerObject> relateds)
+ {
+ if (!isLoaded())
+ {
+ throw new IllegalStateException("Not loaded");
+ }
+
+ //
+ for (UIContainerObject related : new ArrayList<UIContainerObject>(this.relateds))
+ {
+ detach(related);
+ }
+
+ //
+ for (UIContainerObject related : relateds)
+ {
+ attach(related);
+ }
+ }
+
+ UIContainerObject removeLoadedRelated(String relatedId)
+ {
+ if (!isLoaded())
+ {
+ throw new IllegalStateException("Not loaded");
+ }
+ if (relatedId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ for (UIContainerObject related : relateds)
+ {
+ if (relatedId.equals(related.getId()))
+ {
+ detach(related);
+ return related;
+ }
+ }
+
+ //
+ throw new AssertionError("BUG");
+ }
+
+ Collection<UIContainerObject> getRelateds()
+ {
+ return list;
+ }
+
+ Set<ObjectContext> getReferences()
+ {
+ return refs;
+ }
+
+ /**
+ * Load the related side.
+ *
+ * @return the list of structural objects
+ * @throws StateException if the load operation cannot be achieved
+ */
+ protected abstract Collection<StructuralObject> doLoad() throws StateException;
+
+ protected abstract ObjectContext getOwner();
+
+ protected abstract ManyToOne getManyToOne(UIContainerObject related);
+
+ private void detach(UIContainerObject related)
+ {
+ ManyToOne manyToOne = getManyToOne(related);
+
+ //
+ ObjectContext owner = getOwner();
+
+ //
+ if (!manyToOne.refs.contains(owner))
+ {
+ throw new AssertionError("BUG");
+ }
+
+ //
+ manyToOne.refs.remove(owner);
+ relateds.remove(related);
+ }
+
+ private void attach(UIContainerObject related)
+ {
+ ManyToOne manyToOne = getManyToOne(related);
+
+ //
+ ObjectContext owner = getOwner();
+
+ //
+ if (manyToOne.refs.contains(owner))
+ {
+ throw new AssertionError("Context already referenced by the provided object");
+ }
+
+ //
+ manyToOne.refs.add(owner);
+ relateds.add(related);
+ }
+
+ private void load()
+ {
+ ObjectContext owner = getOwner();
+
+ //
+ try
+ {
+ for (StructuralObject relatedSO : doLoad())
+ {
+ UIContainerObject related = owner.container.get(relatedSO);
+
+ //
+ if (related != null)
+ {
+ ObjectContext relatedContext = (ObjectContext)related.getContext();
+
+ //
+ if (!relatedContext.structuralObject.compareTo(relatedSO))
+ {
+ relatedContext.status = UIObject.Status.STALE;
+ }
+ }
+ else
+ {
+ related = owner.container.create(relatedSO);
+
+ //
+ owner.container.attach(related);
+ }
+
+ //
+ attach(related);
+ }
+
+ //
+ this.loaded = true;
+ }
+ catch (StateException e)
+ {
+ owner.updateStatus(e);
+ }
+ }
+
+ private class LazySet extends AbstractSet<UIContainerObject>
+ {
+
+ public Iterator<UIContainerObject> iterator()
+ {
+ final ObjectContext owner = getOwner();
+
+ //
+ owner.checkAccess();
+
+ // Load the entire relationship
+ if (!isLoaded())
+ {
+ load();
+ }
+
+ //
+ owner.checkAccess();
+
+ //
+ final Iterator<UIContainerObject> iterator = relateds.iterator();
+
+ //
+ return new Iterator<UIContainerObject>()
+ {
+ public boolean hasNext()
+ {
+ owner.checkAccess();
+
+ //
+ return iterator.hasNext();
+ }
+
+ public UIContainerObject next()
+ {
+ owner.checkAccess();
+
+ //
+ return iterator.next();
+ }
+
+ public void remove()
+ {
+ owner.checkAccess();
+
+ //
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ public int size()
+ {
+ ObjectContext owner = getOwner();
+
+ //
+ owner.checkAccess();
+
+ //
+ if (!isLoaded())
+ {
+ load();
+ }
+
+ //
+ owner.checkAccess();
+
+ //
+ return relateds.size();
+ }
+
+ public String toString()
+ {
+ return "ProxyList[" + getOwner() + "]";
+ }
+ }
+ }
+}
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-29 22:51:43 UTC (rev 9404)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-29 22:56:28 UTC (rev 9405)
@@ -37,14 +37,11 @@
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.Set;
-import java.util.HashSet;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -98,11 +95,11 @@
// Create context
ObjectContext objectContext = new ObjectContext(this, object, structuralObject);
- AssociationContext associationContext = new AssociationContext();
+ RelationshipContext relationshipContext = new RelationshipContext();
// Wire
- objectContext.associationContext = associationContext;
- associationContext.owner = objectContext;
+ objectContext.relationshipContext = relationshipContext;
+ relationshipContext.owner = objectContext;
// Contextualize
object.setContext(objectContext);
@@ -170,7 +167,7 @@
parentContext.structuralObject = creation.getParent();
//
- if (parentContext.associationContext.children.isLoaded())
+ if (parentContext.relationshipContext.children.isLoaded())
{
UIContainerObject child = create(creation.getChild());
@@ -178,7 +175,7 @@
attach(child);
//
- parentContext.associationContext.children.addLoadedRelated(child);
+ parentContext.relationshipContext.children.addLoadedRelated(child);
}
// Eventing
@@ -205,13 +202,13 @@
parentContext.structuralObject = destruction.getParent();
//
- if (parentContext.associationContext.children.isLoaded())
+ if (parentContext.relationshipContext.children.isLoaded())
{
// Get the id which is the destroyed object
String destroyedId = destruction.getIds().get(destruction.getIds().size() - 1);
//
- parentContext.associationContext.children.removeLoadedRelated(destroyedId);
+ parentContext.relationshipContext.children.removeLoadedRelated(destroyedId);
}
}
@@ -251,9 +248,9 @@
parentContext.structuralObject = move.getParent();
// Remove the child if the relationship is loaded on this side
- if (parentContext.associationContext.children.isLoaded())
+ if (parentContext.relationshipContext.children.isLoaded())
{
- parentContext.associationContext.children.removeLoadedRelated(move.getSource().getId());
+ parentContext.relationshipContext.children.removeLoadedRelated(move.getSource().getId());
}
}
@@ -266,7 +263,7 @@
destinationContext.structuralObject = move.getDestination();
//
- if (destinationContext.associationContext.children.isLoaded())
+ if (destinationContext.relationshipContext.children.isLoaded())
{
// Now we really need to add the source as we load collections entirely
if (source == null)
@@ -278,7 +275,7 @@
}
//
- destinationContext.associationContext.children.addLoadedRelated(source);
+ destinationContext.relationshipContext.children.addLoadedRelated(source);
}
}
@@ -291,15 +288,15 @@
sourceContext.structuralObject = move.getSource();
//
- if (sourceContext.associationContext.parent.isLoaded())
+ if (sourceContext.relationshipContext.parent.isLoaded())
{
if (destination != null)
{
- sourceContext.associationContext.parent.setLoadedRelated(destination);
+ sourceContext.relationshipContext.parent.setLoadedRelated(destination);
}
else
{
- sourceContext.associationContext.parent.clearLoadedRelated();
+ sourceContext.relationshipContext.parent.clearLoadedRelated();
}
}
}
@@ -405,13 +402,13 @@
// Continue only if it is valid
if (context.isValid())
{
- boolean loaded = context.associationContext.children.isLoaded();
+ boolean loaded = context.relationshipContext.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.getRelateds())
+ for (UIContainerObject child : context.relationshipContext.children.getRelateds())
{
ObjectContext childContext = (ObjectContext)child.getContext();
@@ -452,7 +449,7 @@
}
//
- boolean loaded = context.associationContext.children.isLoaded();
+ boolean loaded = context.relationshipContext.children.isLoaded();
boolean refreshChildren = scope.enterChildren(object, loaded);
// Update the structural state
@@ -471,15 +468,15 @@
ObjectContext addedContext = (ObjectContext)added.getContext();
// Find parent pointing at us and set as dirty
- for (ObjectContext addedParentContext : addedContext.associationContext.parent.getReferences())
+ for (ObjectContext addedParentContext : addedContext.relationshipContext.parent.getReferences())
{
addedParentContext.status = UIObject.Status.STALE;
}
// Update parent if it was loaded
- if (addedContext.associationContext.parent.isLoaded())
+ if (addedContext.relationshipContext.parent.isLoaded())
{
- addedContext.associationContext.parent.setLoadedRelated(object);
+ addedContext.relationshipContext.parent.setLoadedRelated(object);
}
}
else
@@ -491,7 +488,7 @@
}
//
- context.associationContext.children.addLoadedRelated(added);
+ context.relationshipContext.children.addLoadedRelated(added);
}
//
@@ -509,7 +506,7 @@
// Removals
for (String removedId : refresh.getRemovedChildren())
{
- UIContainerObject removed = context.associationContext.children.removeLoadedRelated(removedId);
+ UIContainerObject removed = context.relationshipContext.children.removeLoadedRelated(removedId);
//
detach(removed);
@@ -524,7 +521,7 @@
// Recursively refresh children
if (refreshChildren)
{
- for (UIContainerObject child : context.associationContext.children.getRelateds())
+ for (UIContainerObject child : context.relationshipContext.children.getRelateds())
{
refresh(child, scope);
}
@@ -545,7 +542,7 @@
ObjectContext context = (ObjectContext)object.getContext();
//
- for (UIContainerObject child : context.associationContext.children.getRelateds())
+ for (UIContainerObject child : context.relationshipContext.children.getRelateds())
{
detach(child);
}
16 years, 3 months
JBoss Portal SVN: r9404 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: model/event/state and 3 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-29 17:51:43 -0500 (Sat, 29 Dec 2007)
New Revision: 9404
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/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChange.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/structural/StructuralStateModification.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
Log:
improve a bit existing eventing stuff (need to add test)
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-29 15:14:44 UTC (rev 9403)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-29 22:51:43 UTC (rev 9404)
@@ -212,10 +212,12 @@
changes.put(propertyName, (String)propertyValue);
// Have context process change
- StructuralObject.Update update;
try
{
- update = context.container.structuralStateContext.update(context.structuralObject, changes);
+ StructuralObject.Update update = context.container.structuralStateContext.update(context.structuralObject, changes);
+
+ //
+ context.container.update(update);
}
catch (StateException e)
{
@@ -224,15 +226,6 @@
//
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
{
@@ -322,12 +315,6 @@
//
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()));
}
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-29 15:14:44 UTC (rev 9403)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-29 22:51:43 UTC (rev 9404)
@@ -26,9 +26,13 @@
import org.jboss.portal.presentation.model.ModelListener;
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIContext;
+import org.jboss.portal.presentation.model.event.state.structural.StructuralStateModification;
+import org.jboss.portal.presentation.model.event.state.StateChange;
+import org.jboss.portal.presentation.model.event.state.StateChangeEvent;
import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.model.state.structural.StructuralState;
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;
@@ -50,6 +54,9 @@
{
/** . */
+ private final static StructuralStateModification.Destruction DESTRUCTION = new StructuralStateModification.Destruction();
+
+ /** . */
private final Map<String, UIContainerObject> universe = new HashMap<String, UIContainerObject>();
/** . */
@@ -136,6 +143,12 @@
//
ObjectContext context = (ObjectContext)object.getContext();
context.structuralObject = update.getObject();
+
+ // Eventing
+ StructuralStateModification mod = new StructuralStateModification.Update(update.getChanges());
+ StateChange<StructuralStateModification> stateChange = new StateChange<StructuralStateModification>(update.getObject().getId(), mod);
+ StateChangeEvent event = new StateChangeEvent(stateChange);
+ fireEvent(event);
}
else if (change instanceof StructuralObject.Creation)
{
@@ -167,6 +180,14 @@
//
parentContext.associationContext.children.addLoadedRelated(child);
}
+
+ // Eventing
+ StructuralObject childSO = creation.getChild();
+ StructuralState state = childSO.getState();
+ StructuralStateModification mod = new StructuralStateModification.Creation(state.getType(), state.getName(), state.getProperties());
+ StateChange<StructuralStateModification> stateChange = new StateChange<StructuralStateModification>(childSO.getId(), mod);
+ StateChangeEvent event = new StateChangeEvent(stateChange);
+ fireEvent(event);
}
else if (change instanceof StructuralObject.Destruction)
{
@@ -204,6 +225,11 @@
{
ObjectContext destroyedContext = (ObjectContext)destroyed.getContext();
destroyedContext.status = UIObject.Status.INVALID;
+
+ // Eventing
+ StateChange<StructuralStateModification> stateChange = new StateChange<StructuralStateModification>(id, DESTRUCTION);
+ StateChangeEvent event = new StateChangeEvent(stateChange);
+ fireEvent(event);
}
}
}
@@ -277,6 +303,12 @@
}
}
}
+
+ // Eventing
+ StructuralStateModification.Move mod = new StructuralStateModification.Move(move.getParent().getId(), move.getDestination().getId());
+ StateChange<StructuralStateModification> stateChange = new StateChange<StructuralStateModification>(move.getSource().getId(), mod);
+ StateChangeEvent event = new StateChangeEvent(stateChange);
+ fireEvent(event);
}
else
{
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChange.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChange.java 2007-12-29 15:14:44 UTC (rev 9403)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChange.java 2007-12-29 22:51:43 UTC (rev 9404)
@@ -22,8 +22,6 @@
******************************************************************************/
package org.jboss.portal.presentation.model.event.state;
-import org.jboss.portal.presentation.model.event.state.StateModification;
-
/**
* A change in the state of the model. The change is the association of a target id and a modification.
* The target id refers to an object in the structural state context and the modification is a modification
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/structural/StructuralStateModification.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/structural/StructuralStateModification.java 2007-12-29 15:14:44 UTC (rev 9403)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/structural/StructuralStateModification.java 2007-12-29 22:51:43 UTC (rev 9404)
@@ -86,13 +86,22 @@
{
/** . */
+ private final String parentId;
+
+ /** . */
private final String destinationId;
- public Move(String parentId)
+ public Move(String parentId, String destinationId)
{
- this.destinationId = parentId;
+ this.parentId = parentId;
+ this.destinationId = destinationId;
}
+ public String getParentId()
+ {
+ return parentId;
+ }
+
public String getDestinationId()
{
return destinationId;
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java 2007-12-29 15:14:44 UTC (rev 9403)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java 2007-12-29 22:51:43 UTC (rev 9404)
@@ -150,21 +150,34 @@
/** . */
private final StructuralObject object;
- public Update(StructuralObject object)
+ /** . */
+ private final Map<String, String> changes;
+
+ public Update(StructuralObject object, Map<String, String> changes)
{
if (object == null)
{
throw new IllegalArgumentException();
}
+ if (changes == null)
+ {
+ throw new IllegalArgumentException();
+ }
//
this.object = object;
+ this.changes = changes;
}
public StructuralObject getObject()
{
return object;
}
+
+ public Map<String, String> getChanges()
+ {
+ return changes;
+ }
}
public static class Move extends Change
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-29 15:14:44 UTC (rev 9403)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-29 22:51:43 UTC (rev 9404)
@@ -43,6 +43,7 @@
import java.util.HashSet;
import java.util.Set;
import java.util.Collection;
+import java.util.Collections;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -227,6 +228,9 @@
{
MockObject mockObject = getValidMockObject(object);
+ // Create an non mutable clone (for the event)
+ changes = Collections.unmodifiableMap(new HashMap<String, String>(changes));
+
//
for (Map.Entry<String, String> entry : changes.entrySet())
{
@@ -257,7 +261,7 @@
}
//
- return new StructuralObject.Update(mockObject.takeSnapshot());
+ return new StructuralObject.Update(mockObject.takeSnapshot(), changes);
}
public StructuralObject.Creation create(StructuralObject parent, Class<? extends UIObject> classType, String name, Map<String, String> properties) throws StateException, IllegalArgumentException
16 years, 3 months
JBoss Portal SVN: r9403 - 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-29 10:14:44 -0500 (Sat, 29 Dec 2007)
New Revision: 9403
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
Log:
detach children recursively
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-29 15:11:39 UTC (rev 9402)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-29 15:14:44 UTC (rev 9403)
@@ -510,9 +510,17 @@
void detach(UIContainerObject object)
{
- universe.remove(object.getId());
ObjectContext context = (ObjectContext)object.getContext();
+
+ //
+ for (UIContainerObject child : context.associationContext.children.getRelateds())
+ {
+ detach(child);
+ }
+
+ //
context.status = UIObject.Status.INVALID;
+ universe.remove(object.getId());
}
UIContainerObject get(String id)
16 years, 3 months
JBoss Portal SVN: r9402 - 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-29 10:11:39 -0500 (Sat, 29 Dec 2007)
New Revision: 9402
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
Log:
detach removed objects during a 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-28 22:01:35 UTC (rev 9401)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-29 15:11:39 UTC (rev 9402)
@@ -478,6 +478,9 @@
for (String removedId : refresh.getRemovedChildren())
{
UIContainerObject removed = context.associationContext.children.removeLoadedRelated(removedId);
+
+ //
+ detach(removed);
}
// Update state
@@ -496,8 +499,6 @@
}
//
-
- //
scope.leaveObject(object);
}
}
@@ -507,10 +508,12 @@
universe.put(object.getId(), object);
}
-// void detach(UIContainerObject object)
-// {
-// universe.remove(object.getId());
-// }
+ void detach(UIContainerObject object)
+ {
+ universe.remove(object.getId());
+ ObjectContext context = (ObjectContext)object.getContext();
+ context.status = UIObject.Status.INVALID;
+ }
UIContainerObject get(String id)
{
16 years, 3 months
JBoss Portal SVN: r9401 - branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-28 17:01:35 -0500 (Fri, 28 Dec 2007)
New Revision: 9401
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
- test a bit more the refresh operation and improve its implementation
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-28 21:57:29 UTC (rev 9400)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-28 22:01:35 UTC (rev 9401)
@@ -791,30 +791,6 @@
context1.getChild("bar").refresh();
}
- public void testRefreshAfterConcurrentMove2() 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();
- loadSubTree(context1);
-
- // Concurrent move
- UIContext context2 = createContext();
- context2.getChild("foo").getChild("juu").move(context2.getChild("bar"));
-
- //
- context1.getChild("foo").refresh();
- }
-
public void testPartialRefreshAfterConcurrentMove() throws Exception
{
MockObject mockRoot = model.getRoot();
@@ -858,6 +834,7 @@
assertEquals(UIObject.Status.STALE, foo2.getStatus());
assertEquals(UIObject.Status.VALID, bar2.getStatus());
assertEquals(Tools.toSet(juu2), new HashSet<UIObject>(bar2.getChildren()));
+ assertEquals(bar2, juu2.getParent());
//
context3.refresh(CRAWLER);
16 years, 3 months
JBoss Portal SVN: r9400 - 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-28 16:57:29 -0500 (Fri, 28 Dec 2007)
New Revision: 9400
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/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
- test a bit more the refresh operation and improve its implementation
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-28 00:39:56 UTC (rev 9399)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-28 21:57:29 UTC (rev 9400)
@@ -32,6 +32,7 @@
import java.util.HashSet;
import java.util.Collection;
import java.util.AbstractSet;
+import java.util.ArrayList;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -86,16 +87,21 @@
/** . */
private UIContainerObject related;
- /** . */
- private UIContainerObject ref;
+ /** The context pointing at us via a OneToMany. */
+ private Set<ObjectContext> refs;
private ManyToOne()
{
this.loaded = false;
this.related = null;
- this.ref = null;
+ this.refs = new HashSet<ObjectContext>();
}
+ Set<ObjectContext> getReferences()
+ {
+ return refs;
+ }
+
boolean isLoaded()
{
return loaded;
@@ -296,7 +302,7 @@
/** . */
private Set<UIContainerObject> relateds;
- /** . */
+ /** The contexts pointing at us via a ManyToOne. */
private Set<ObjectContext> refs;
private OneToMany()
@@ -322,6 +328,8 @@
{
throw new IllegalArgumentException("No null child accepted");
}
+
+ //
for (UIContainerObject r : relateds)
{
if (related.getId().equals(r.getId()))
@@ -329,7 +337,9 @@
throw new IllegalStateException("Cannot add duplicate");
}
}
- relateds.add(related);
+
+ //
+ attach(related);
}
void setLoadedRelateds(Set<UIContainerObject> relateds)
@@ -338,10 +348,21 @@
{
throw new IllegalStateException("Not loaded");
}
- this.relateds = relateds;
+
+ //
+ for (UIContainerObject related : new ArrayList<UIContainerObject>(this.relateds))
+ {
+ detach(related);
+ }
+
+ //
+ for (UIContainerObject related : relateds)
+ {
+ attach(related);
+ }
}
- void removeLoadedRelated(String relatedId)
+ UIContainerObject removeLoadedRelated(String relatedId)
{
if (!isLoaded())
{
@@ -351,17 +372,19 @@
{
throw new IllegalArgumentException();
}
- for (Iterator<UIContainerObject> i = relateds.iterator();i.hasNext();)
+
+ //
+ for (UIContainerObject related : relateds)
{
- UIContainerObject child = i.next();
-
- //
- if (relatedId.equals(child.getId()))
+ if (relatedId.equals(related.getId()))
{
- i.remove();
- break;
+ detach(related);
+ return related;
}
}
+
+ //
+ throw new AssertionError("BUG");
}
Collection<UIContainerObject> getRelateds()
@@ -369,6 +392,11 @@
return list;
}
+ Set<ObjectContext> getReferences()
+ {
+ return refs;
+ }
+
/**
* Load the related side.
*
@@ -381,6 +409,42 @@
protected abstract ManyToOne getManyToOne(UIContainerObject related);
+ private void detach(UIContainerObject related)
+ {
+ ManyToOne manyToOne = getManyToOne(related);
+
+ //
+ ObjectContext owner = getOwner();
+
+ //
+ if (!manyToOne.refs.contains(owner))
+ {
+ throw new AssertionError("BUG");
+ }
+
+ //
+ manyToOne.refs.remove(owner);
+ relateds.remove(related);
+ }
+
+ private void attach(UIContainerObject related)
+ {
+ ManyToOne manyToOne = getManyToOne(related);
+
+ //
+ ObjectContext owner = getOwner();
+
+ //
+ if (manyToOne.refs.contains(owner))
+ {
+ throw new AssertionError("Context already referenced by the provided object");
+ }
+
+ //
+ manyToOne.refs.add(owner);
+ relateds.add(related);
+ }
+
private void load()
{
ObjectContext owner = getOwner();
@@ -388,9 +452,6 @@
//
try
{
- Set<UIContainerObject> relateds = new HashSet<UIContainerObject>();
-
- //
for (StructuralObject relatedSO : doLoad())
{
UIContainerObject related = owner.container.get(relatedSO);
@@ -415,11 +476,10 @@
}
//
- relateds.add(related);
+ attach(related);
}
//
- this.relateds = relateds;
this.loaded = true;
}
catch (StateException e)
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-28 00:39:56 UTC (rev 9399)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-28 21:57:29 UTC (rev 9400)
@@ -402,117 +402,99 @@
ObjectContext context = (ObjectContext)object.getContext();
//
- switch (context.status)
+ if (context.status == UIObject.Status.INVALID)
{
- case VALID:
- case STALE:
- try
+ return;
+ }
+
+ //
+ StructuralObject.Refresh refresh = null;
+ try
+ {
+ refresh = structuralStateContext.refresh(context.structuralObject);
+ }
+ catch (NoSuchStateException e)
+ {
+ context.status = UIObject.Status.INVALID;
+ return;
+ }
+
+ //
+ boolean loaded = context.associationContext.children.isLoaded();
+ boolean refreshChildren = scope.enterChildren(object, loaded);
+
+ // Update the structural state
+ if (!context.structuralObject.compareTo(refresh.getObject()))
+ {
+ if (loaded)
+ {
+ // Take care of the added children
+ for (StructuralObject addedSO : refresh.getAddedChildren())
{
- StructuralObject.Refresh refresh = structuralStateContext.refresh(context.structuralObject);
+ UIContainerObject added = get(addedSO);
- // Update the structural state
- if (!context.structuralObject.compareTo(refresh.getObject()))
+ //
+ if (added != null)
{
- boolean loaded = context.associationContext.children.isLoaded();
+ ObjectContext addedContext = (ObjectContext)added.getContext();
- //
- if (loaded)
+ // Find parent pointing at us and set as dirty
+ for (ObjectContext addedParentContext : addedContext.associationContext.parent.getReferences())
{
- boolean refreshChildren = scope.enterChildren(object, loaded);
+ addedParentContext.status = UIObject.Status.STALE;
+ }
- // The new list of children
- Set<UIContainerObject> children = new HashSet<UIContainerObject>();
+ // Update parent if it was loaded
+ if (addedContext.associationContext.parent.isLoaded())
+ {
+ addedContext.associationContext.parent.setLoadedRelated(object);
+ }
+ }
+ else
+ {
+ added = create(addedSO);
- // Take care of the added children
- for (StructuralObject addedSO : refresh.getAddedChildren())
- {
- UIContainerObject added = get(addedSO);
+ //
+ attach(added);
+ }
- //
- if (added != null)
- {
- ObjectContext addedContext = (ObjectContext)added.getContext();
+ //
+ context.associationContext.children.addLoadedRelated(added);
+ }
- // Set the parent as stale if needed
- if (addedContext.associationContext.parent.isLoaded())
- {
- ObjectContext addedParentContext = (ObjectContext)addedContext.associationContext.parent.getLoadedRelated().getContext();
+ //
+ for (StructuralObject staleSO : refresh.getStaleChildren().values())
+ {
+ UIContainerObject stale = get(staleSO);
- // Mark the parent as stale
- addedParentContext.status = UIObject.Status.STALE;
+ // It must be here as it is loaded
+ ObjectContext staleContext = (ObjectContext)stale.getContext();
- //
- addedParentContext.associationContext.parent.setLoadedRelated(get(context.structuralObject));
- }
- }
- else
- {
- added = create(addedSO);
-
- //
- attach(added);
- }
-
- //
- children.add(added);
- }
-
- //
- 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);
-
- //
- ObjectContext staleContext = (ObjectContext)stale.getContext();
-
- // Mark as stale
- staleContext.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.associationContext.children.setLoadedRelateds(children);
- }
- }
+ // Mark as stale
+ staleContext.status = UIObject.Status.STALE;
}
- catch (NoSuchStateException e)
+
+ // Removals
+ for (String removedId : refresh.getRemovedChildren())
{
- context.status = UIObject.Status.INVALID;
+ UIContainerObject removed = context.associationContext.children.removeLoadedRelated(removedId);
}
- //
- break;
- case INVALID:
+ // Update state
+ context.structuralObject = refresh.getObject();
+ context.status = UIObject.Status.VALID;
+ }
}
+ // Recursively refresh children
+ if (refreshChildren)
+ {
+ for (UIContainerObject child : context.associationContext.children.getRelateds())
+ {
+ refresh(child, scope);
+ }
+ }
+
//
//
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-28 00:39:56 UTC (rev 9399)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-28 21:57:29 UTC (rev 9400)
@@ -781,7 +781,7 @@
// Load fully the context 1
UIContext context1 = createContext();
- loadDescendants(context1);
+ loadSubTree(context1);
// Concurrent move
UIContext context2 = createContext();
@@ -791,11 +791,86 @@
context1.getChild("bar").refresh();
}
- private void loadDescendants(UIObject object)
+ public void testRefreshAfterConcurrentMove2() 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();
+ loadSubTree(context1);
+
+ // Concurrent move
+ UIContext context2 = createContext();
+ context2.getChild("foo").getChild("juu").move(context2.getChild("bar"));
+
+ //
+ context1.getChild("foo").refresh();
+ }
+
+ public void testPartialRefreshAfterConcurrentMove() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockBar = mockRoot.addChild("bar", MockObject.Type.PORTAL);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+
+ // Load fully the context 1
+ UIContext context1 = createContext();
+ loadSubTree(context1);
+ UIObject foo1 = context1.getChild("foo");
+ UIObject juu1 = foo1.getChild("juu");
+ UIObject bar1 = context1.getChild("bar");
+
+ // Load fully the context 2
+ UIContext context2 = createContext();
+ loadSubTree(context2);
+ UIObject foo2 = context2.getChild("foo");
+ UIObject juu2 = foo2.getChild("juu");
+ UIObject bar2 = context2.getChild("bar");
+
+ // Load fully the context 3
+ UIContext context3 = createContext();
+ loadSubTree(context3);
+ UIObject foo3 = context3.getChild("foo");
+ UIObject juu3 = foo3.getChild("juu");
+ UIObject bar3 = context3.getChild("bar");
+
+ // Concurrent move
+ UIContext context = createContext();
+ context.getChild("foo").getChild("juu").move(context.getChild("bar"));
+
+ //
+ foo1.refresh(CRAWLER);
+ assertEquals(UIObject.Status.VALID, foo1.getStatus());
+ assertEquals(0, foo1.getChildren().size());
+
+ //
+ bar2.refresh(CRAWLER);
+ assertEquals(UIObject.Status.STALE, foo2.getStatus());
+ assertEquals(UIObject.Status.VALID, bar2.getStatus());
+ assertEquals(Tools.toSet(juu2), new HashSet<UIObject>(bar2.getChildren()));
+
+ //
+ context3.refresh(CRAWLER);
+ assertEquals(UIObject.Status.VALID, foo3.getStatus());
+ assertEquals(UIObject.Status.VALID, bar3.getStatus());
+ assertEquals(Tools.toSet(juu3), new HashSet<UIObject>(bar3.getChildren()));
+ }
+
+ private void loadSubTree(UIObject object)
+ {
for (UIObject child : object.getChildren())
{
- loadDescendants(child);
+ loadSubTree(child);
}
}
@@ -831,4 +906,22 @@
assertEquals(Collections.singleton(fooDaa), new HashSet<UIObject>(fooChildren));
assertEquals(Tools.toSet(barDaa, fooJuu), new HashSet<UIObject>(barChildren));
}
+
+ private static final UIObject.Visitor CRAWLER = new UIObject.Visitor()
+ {
+ public boolean enterObject(UIObject object)
+ {
+ return true;
+ }
+
+ public void leaveObject(UIObject object)
+ {
+ }
+
+ public boolean enterChildren(UIObject object, boolean loaded)
+ {
+ return loaded;
+ }
+ };
+
}
16 years, 3 months
JBoss Portal SVN: r9399 - in branches/presentation: presentation/src/main/org/jboss/portal/presentation/client/controller and 6 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-27 19:39:56 -0500 (Thu, 27 Dec 2007)
New Revision: 9399
Modified:
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/AjaxUIController.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java
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/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/model/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.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:
- replace children list by collection (which provide more flexibility)
- started to add backward references tracking between one2many and many2one associations
Modified: branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java
===================================================================
--- branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java 2007-12-27 22:00:40 UTC (rev 9398)
+++ branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java 2007-12-28 00:39:56 UTC (rev 9399)
@@ -115,7 +115,7 @@
}
- public List<StructuralObject> loadChildren(StructuralObject parent)
+ public Collection<StructuralObject> loadChildren(StructuralObject parent)
{
// Get the PortalObject corresponding to this objectId from the PortalObjectContainer
PortalObject portalObject = this.portalObjectContainer.getObject(PortalObjectId.parse(parent.getId(), PortalObjectPath.CANONICAL_FORMAT));
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/AjaxUIController.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/AjaxUIController.java 2007-12-27 22:00:40 UTC (rev 9398)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/AjaxUIController.java 2007-12-28 00:39:56 UTC (rev 9399)
@@ -48,6 +48,7 @@
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.ArrayList;
+import java.util.Collection;
/**
* The UIServer is responsible for generating the output that is sent back to the client based on the Portal state of a particular Portal Request
@@ -150,11 +151,10 @@
//TODO: set proper status
//TODO: set proper parent reference
- List<? extends UIObject> windows = page.getChildren();
+ Collection<? extends UIObject> windows = page.getChildren();
List clientWindows = new ArrayList();
- for(int i=0; i<windows.size(); i++)
+ for(UIObject cour : windows)
{
- UIObject cour = windows.get(i);
if(cour instanceof UIWindow)
{
UIWindow window = (UIWindow)cour;
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java 2007-12-27 22:00:40 UTC (rev 9398)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java 2007-12-28 00:39:56 UTC (rev 9399)
@@ -48,6 +48,7 @@
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.List;
+import java.util.Collection;
/**
* The UIServer is responsible for generating the output that is sent back to the client based on the Portal state of a particular Portal Request
@@ -336,10 +337,9 @@
if(uiObject instanceof UIPage)
{
UIPage page = (UIPage)uiObject;
- List<? extends UIObject> windows = page.getChildren();
- for(int i=0; i<windows.size(); i++)
+ Collection<? extends UIObject> windows = page.getChildren();
+ for(UIObject cour : windows)
{
- UIObject cour = windows.get(i);
if(cour instanceof UIWindow)
{
UIWindow window = (UIWindow)cour;
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 22:00:40 UTC (rev 9398)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-28 00:39:56 UTC (rev 9399)
@@ -29,7 +29,7 @@
import org.jboss.portal.presentation.impl.model.container.spi.UIContainerObject;
import org.jboss.portal.presentation.impl.model.container.spi.UIObjectContext;
-import java.util.List;
+import java.util.Collection;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -114,7 +114,7 @@
return context.getManagedObject().getParent();
}
- public List<? extends UIObject> getChildren()
+ public Collection<? extends UIObject> getChildren()
{
return context.getManagedObject().getChildren();
}
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 22:00:40 UTC (rev 9398)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-28 00:39:56 UTC (rev 9399)
@@ -27,10 +27,11 @@
import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.UIObject;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.AbstractList;
import java.util.Iterator;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collection;
+import java.util.AbstractSet;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -53,12 +54,16 @@
{
return owner;
}
+ protected OneToMany getOneToMany(UIContainerObject related)
+ {
+ return ((ObjectContext)related.getContext()).associationContext.children;
+ }
};
/** . */
final OneToMany children = new OneToMany()
{
- protected List<StructuralObject> doLoad()
+ protected Collection<StructuralObject> doLoad()
{
return owner.container.structuralStateContext.loadChildren(owner.structuralObject);
}
@@ -66,6 +71,10 @@
{
return owner;
}
+ protected ManyToOne getManyToOne(UIContainerObject related)
+ {
+ return ((ObjectContext)related.getContext()).associationContext.parent;
+ }
};
static abstract class ManyToOne
@@ -77,8 +86,14 @@
/** . */
private UIContainerObject related;
+ /** . */
+ private UIContainerObject ref;
+
private ManyToOne()
{
+ this.loaded = false;
+ this.related = null;
+ this.ref = null;
}
boolean isLoaded()
@@ -97,16 +112,16 @@
throw new IllegalStateException("Cannot set parent of non loaded association");
}
- // Update the related side
+ // Downgrade the related side
if (related != null)
{
-
+ detach();
}
//
if (newParent != null)
{
- related = newParent;
+ attach(newParent);
}
else
{
@@ -130,10 +145,34 @@
{
throw new IllegalStateException("Cannot clear parent of non loaded association");
}
- related = null;
+
+ // Downgrade realted
+ detach();
+
+ //
loaded = false;
}
+ UIContainerObject getRelated()
+ {
+ ObjectContext owner = getOwner();
+
+ //
+ owner.checkAccess();
+
+ //
+ if (!loaded)
+ {
+ load();
+ }
+
+ //
+ owner.checkAccess();
+
+ //
+ return related;
+ }
+
/**
* Loads the related side.
*
@@ -144,6 +183,52 @@
protected abstract ObjectContext getOwner();
+ protected abstract OneToMany getOneToMany(UIContainerObject related);
+
+ private void attach(UIContainerObject related)
+ {
+ if (this.related != null)
+ {
+ throw new AssertionError("BUG");
+ }
+
+ //
+ OneToMany oneToMany = getOneToMany(related);
+ ObjectContext owner = getOwner();
+
+ //
+ if (oneToMany.refs.contains(owner))
+ {
+ throw new AssertionError("BUG");
+ }
+
+ //
+ oneToMany.refs.add(owner);
+ this.related = related;
+ }
+
+ private void detach()
+ {
+ if (related == null)
+ {
+ throw new AssertionError("BUG");
+ }
+
+ //
+ OneToMany oneToMany = getOneToMany(related);
+ ObjectContext owner = getOwner();
+
+ //
+ if (!oneToMany.refs.contains(owner))
+ {
+ throw new AssertionError("BUG");
+ }
+
+ //
+ oneToMany.refs.remove(owner);
+ this.related = null;
+ }
+
/**
* 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
@@ -166,7 +251,7 @@
//
if (related != null)
{
- this.related = related;
+ attach(related);
//
ObjectContext parentContext = (ObjectContext)related.getContext();
@@ -185,7 +270,7 @@
owner.container.attach(related);
//
- this.related = related;
+ attach(related);
}
}
@@ -197,45 +282,29 @@
owner.updateStatus(e);
}
}
-
- UIContainerObject getRelated()
- {
- ObjectContext owner = getOwner();
-
- //
- owner.checkAccess();
-
- //
- if (!loaded)
- {
- load();
- }
-
- //
- owner.checkAccess();
-
- //
- return related;
- }
}
static abstract class OneToMany
{
/** . */
- private final ProxyList list;
+ private final LazySet list;
/** . */
private boolean loaded;
/** . */
- private List<UIContainerObject> relateds;
+ private Set<UIContainerObject> relateds;
+ /** . */
+ private Set<ObjectContext> refs;
+
private OneToMany()
{
- this.list = new ProxyList();
+ this.list = new LazySet();
this.loaded = false;
- this.relateds = new ArrayList<UIContainerObject>();
+ this.relateds = new HashSet<UIContainerObject>();
+ this.refs = new HashSet<ObjectContext>();
}
boolean isLoaded()
@@ -263,7 +332,7 @@
relateds.add(related);
}
- void setLoadedRelateds(List<UIContainerObject> relateds)
+ void setLoadedRelateds(Set<UIContainerObject> relateds)
{
if (!isLoaded())
{
@@ -295,7 +364,7 @@
}
}
- List<UIContainerObject> getRelateds()
+ Collection<UIContainerObject> getRelateds()
{
return list;
}
@@ -306,10 +375,12 @@
* @return the list of structural objects
* @throws StateException if the load operation cannot be achieved
*/
- protected abstract List<StructuralObject> doLoad() throws StateException;
+ protected abstract Collection<StructuralObject> doLoad() throws StateException;
protected abstract ObjectContext getOwner();
+ protected abstract ManyToOne getManyToOne(UIContainerObject related);
+
private void load()
{
ObjectContext owner = getOwner();
@@ -317,7 +388,7 @@
//
try
{
- ArrayList<UIContainerObject> relateds = new ArrayList<UIContainerObject>();
+ Set<UIContainerObject> relateds = new HashSet<UIContainerObject>();
//
for (StructuralObject relatedSO : doLoad())
@@ -357,11 +428,12 @@
}
}
- private class ProxyList extends AbstractList<UIContainerObject>
+ private class LazySet extends AbstractSet<UIContainerObject>
{
- public UIContainerObject get(int i)
+
+ public Iterator<UIContainerObject> iterator()
{
- ObjectContext owner = getOwner();
+ final ObjectContext owner = getOwner();
//
owner.checkAccess();
@@ -376,7 +448,35 @@
owner.checkAccess();
//
- return relateds.get(i);
+ final Iterator<UIContainerObject> iterator = relateds.iterator();
+
+ //
+ return new Iterator<UIContainerObject>()
+ {
+ public boolean hasNext()
+ {
+ owner.checkAccess();
+
+ //
+ return iterator.hasNext();
+ }
+
+ public UIContainerObject next()
+ {
+ owner.checkAccess();
+
+ //
+ return iterator.next();
+ }
+
+ public void remove()
+ {
+ owner.checkAccess();
+
+ //
+ throw new UnsupportedOperationException();
+ }
+ };
}
public int 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 22:00:40 UTC (rev 9398)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-28 00:39:56 UTC (rev 9399)
@@ -37,6 +37,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Collection;
/**
* Implement base fonctionnality of the <code>UIObject</code> interface.
@@ -283,7 +284,7 @@
return context.associationContext.parent.getRelated();
}
- public final List<UIContainerObject> getChildren()
+ public final Collection<UIContainerObject> getChildren()
{
context.checkAccess();
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 22:00:40 UTC (rev 9398)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-28 00:39:56 UTC (rev 9399)
@@ -39,6 +39,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -419,7 +421,7 @@
boolean refreshChildren = scope.enterChildren(object, loaded);
// The new list of children
- List<UIContainerObject> children = new ArrayList<UIContainerObject>();
+ Set<UIContainerObject> children = new HashSet<UIContainerObject>();
// Take care of the added children
for (StructuralObject addedSO : refresh.getAddedChildren())
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-27 22:00:40 UTC (rev 9398)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-28 00:39:56 UTC (rev 9399)
@@ -25,7 +25,7 @@
import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.ConstraintViolationException;
-import java.util.List;
+import java.util.Collection;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -183,7 +183,7 @@
*
* @return the list of children
*/
- List<? extends UIObject> getChildren();
+ Collection<? extends UIObject> getChildren();
/**
* Destroy a named child.
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-27 22:00:40 UTC (rev 9398)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-28 00:39:56 UTC (rev 9399)
@@ -29,6 +29,7 @@
import java.util.List;
import java.util.Map;
+import java.util.Collection;
/**
* The structural state context.
@@ -56,7 +57,7 @@
* @throws IllegalArgumentException if the provided object is null
* @throws StateException any useful exception that would make the object non valid
*/
- List<StructuralObject> loadChildren(StructuralObject parent) throws IllegalArgumentException, StateException;
+ Collection<StructuralObject> loadChildren(StructuralObject parent) throws IllegalArgumentException, StateException;
/**
* Load the parent of the specified object.
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 22:00:40 UTC (rev 9398)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-28 00:39:56 UTC (rev 9399)
@@ -42,6 +42,7 @@
import java.util.HashMap;
import java.util.Set;
import java.util.Map;
+import java.util.Collection;
/**
* Test that the mock model we are using behaves in an expected manner
@@ -225,10 +226,10 @@
assertEquals(rootId, root.getId());
//
- List<StructuralObject> children = ssc.loadChildren(root);
+ Collection<StructuralObject> children = ssc.loadChildren(root);
assertNotNull(children);
assertEquals(1, children.size());
- StructuralObject foo = children.get(0);
+ StructuralObject foo = children.iterator().next();
assertNotNull(foo);
assertEquals(fooId, foo.getId());
StructuralState fooState = foo.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 22:00:40 UTC (rev 9398)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-28 00:39:56 UTC (rev 9399)
@@ -43,10 +43,9 @@
import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.HashSet;
import java.util.Map;
-import java.util.ArrayList;
+import java.util.Collection;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -151,29 +150,40 @@
UIContext context = createContext();
//
- List<? extends UIObject> children = context.getChildren();
+ Collection<? extends UIObject> children = context.getChildren();
assertNotNull(children);
assertEquals(2, children.size());
+ Map childrenMap = toMap(children);
//
- UIPortal defaultPortal = (UIPortal)children.get(0);
+ UIPortal defaultPortal = (UIPortal)childrenMap.get(mockDefaultPortal.getId());
assertNotNull(defaultPortal);
assertSame(defaultPortal, context.getObject(defaultPortal.getId()));
assertEquals("defaultPortal", defaultPortal.getName());
assertEquals(mockDefaultPortal.getId(), defaultPortal.getId());
assertSame(context, defaultPortal.getParent());
- assertEquals(Collections.EMPTY_LIST, defaultPortal.getChildren());
+ assertEquals(0, defaultPortal.getChildren().size());
//
- UIPortal someOtherPortal = (UIPortal)children.get(1);
+ UIPortal someOtherPortal = (UIPortal)childrenMap.get(mockSomeOtherPortal.getId());
assertNotNull(someOtherPortal);
assertSame(someOtherPortal, context.getObject(someOtherPortal.getId()));
assertEquals("someOtherPortal", someOtherPortal.getName());
assertEquals(mockSomeOtherPortal.getId(), someOtherPortal.getId());
assertSame(context, someOtherPortal.getParent());
- assertEquals(Collections.EMPTY_LIST, defaultPortal.getChildren());
+ assertEquals(0, defaultPortal.getChildren().size());
}
+ Map<String, UIObject> toMap(Collection<? extends UIObject> objects)
+ {
+ Map<String, UIObject> map = new HashMap<String, UIObject>();
+ for (UIObject o : objects)
+ {
+ map.put(o.getId(), o);
+ }
+ return map;
+ }
+
public void testLoadChildrenFromStale() throws Exception
{
MockObject mockRoot = model.getRoot();
@@ -189,7 +199,7 @@
// Access children
try
{
- List<? extends UIObject> children = foo.getChildren();
+ Collection<? extends UIObject> children = foo.getChildren();
for (UIObject child : children)
{
}
@@ -244,7 +254,7 @@
// Access children
try
{
- List<? extends UIObject> children = foo.getChildren();
+ Collection<? extends UIObject> children = foo.getChildren();
for (UIObject child : children)
{
}
@@ -551,7 +561,7 @@
context.addModelListener(eventAssert);
//
- List<? extends UIObject> rootChildren = context.getChildren();
+ Collection<? extends UIObject> rootChildren = context.getChildren();
assertNotNull(rootChildren);
assertEquals(0, rootChildren.size());
assertNull(context.getChild("foo"));
@@ -581,7 +591,7 @@
// Load only the descendant
UIObject daa = context.getObject(daaId);
- List<? extends UIObject> daaChildren = daa.getChildren();
+ Collection<? extends UIObject> daaChildren = daa.getChildren();
// Destroy foo
context.destroyChild("foo");
@@ -618,9 +628,9 @@
UIObject foo = context.getChild("foo");
UIObject juu = foo.getChild("juu");
UIObject daa = juu.getChild("daa");
- List<? extends UIObject> fooChildren = foo.getChildren();
- List<? extends UIObject> juuChildren = juu.getChildren();
- List<? extends UIObject> daaChildren = daa.getChildren();
+ Collection<? extends UIObject> fooChildren = foo.getChildren();
+ Collection<? extends UIObject> juuChildren = juu.getChildren();
+ Collection<? extends UIObject> daaChildren = daa.getChildren();
//
foo.destroyChild("juu");
@@ -709,7 +719,7 @@
mockJuu.setPropertyValue("abc", "def");
// Now navigate
- List<? extends UIObject> fooChildren = foo.getChildren();
+ Collection<? extends UIObject> fooChildren = foo.getChildren();
//
assertNotNull(fooChildren);
@@ -739,7 +749,7 @@
UIObject juu = context.getObject(juuId);
// Now navigate
- List<? extends UIObject> fooChildren = foo.getChildren();
+ Collection<? extends UIObject> fooChildren = foo.getChildren();
//
assertNotNull(fooChildren);
@@ -806,12 +816,12 @@
//
UIObject foo = context.getChild("foo");
- List<? extends UIObject> fooChildren = foo.getChildren();
+ Collection<? extends UIObject> fooChildren = foo.getChildren();
UIObject fooJuu = foo.getChild("juu");
UIObject fooDaa = foo.getChild("daa");
UIObject bar = context.getChild("bar");
UIObject barDaa = bar.getChild("daa");
- List<? extends UIObject> barChildren = bar.getChildren();
+ Collection<? extends UIObject> barChildren = bar.getChildren();
//
fooJuu.move(bar);
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 22:00:40 UTC (rev 9398)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-28 00:39:56 UTC (rev 9399)
@@ -42,6 +42,7 @@
import java.util.Map;
import java.util.HashSet;
import java.util.Set;
+import java.util.Collection;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -337,7 +338,7 @@
}
}
- public List<StructuralObject> loadChildren(StructuralObject parent)
+ public Collection<StructuralObject> loadChildren(StructuralObject parent)
{
MockObject mockParent = getValidMockObject(parent);
16 years, 3 months