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();
}
}
}
Show replies by date