JBoss Portal SVN: r9388 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: model and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-27 06:16:19 -0500 (Thu, 27 Dec 2007)
New Revision: 9388
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
better implementation of model validation
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java 2007-12-26 17:08:59 UTC (rev 9387)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java 2007-12-27 11:16:19 UTC (rev 9388)
@@ -417,10 +417,9 @@
{
}
- public boolean enterChildren(UIObject object)
+ public boolean enterChildren(UIObject object, boolean loaded)
{
return false;
}
};
-
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-26 17:08:59 UTC (rev 9387)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-27 11:16:19 UTC (rev 9388)
@@ -30,6 +30,7 @@
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
+import org.jboss.portal.presentation.model.state.StateException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -37,6 +38,8 @@
import java.util.Map;
import java.util.AbstractList;
import java.util.Iterator;
+import java.util.Set;
+import java.util.HashSet;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -291,72 +294,117 @@
void validate(UIManagedObject object, UIObject.Visitor scope)
{
-// if (scope.enterObject(object))
-// {
-// try
-// {
-// structuralStateContext.validate(object.context.structuralObject);
-// }
-// catch (StateException e)
-// {
-// object.context.updateStatus(e);
-// }
-//
-// //
-// if (object.context.isValid())
-// {
-// if (scope.enterChildren(object))
-// {
-// for (AbstractUIObject child : object.childrenAssociation)
-// {
-// validate(child, scope);
-// }
-// }
-// }
-//
-// //
-// scope.leaveObject(object);
-// }
+ if (scope.enterObject(object))
+ {
+ UIObjectContext context = object.context;
+
+ // We do it only if it is not yet invalid
+ if (context.isValid())
+ {
+ // Validate
+ try
+ {
+ structuralStateContext.validate(context.structuralObject);
+ }
+ catch (StateException e)
+ {
+ context.updateStatus(e);
+ }
+
+ // Continue only if it is valid
+ if (context.isValid())
+ {
+ boolean loaded = context.children.relateds != null;
+
+ // Loading children will never make the current object invalid
+ // but it could make some already loaded children invalid
+ if (scope.enterChildren(object, loaded))
+ {
+ for (UIContainerObject child : context.children.get())
+ {
+ validate(child.getContext().managedObject, scope);
+ }
+ }
+ }
+
+ //
+ scope.leaveObject(object);
+ }
+ }
}
void refresh(UIManagedObject object, UIObject.Visitor scope)
{
-
-
if (scope.enterObject(object))
{
- switch (object.context.status)
+ UIObjectContext context = object.context;
+
+ //
+ switch (context.status)
{
case VALID:
case STALE:
try
{
- StructuralObject.Refresh refresh = structuralStateContext.refresh(object.context.structuralObject);
+ StructuralObject.Refresh refresh = structuralStateContext.refresh(context.structuralObject);
// Update the structural state
- object.context.structuralObject = refresh.getObject();
+ if (!context.structuralObject.compareTo(refresh.getObject()))
+ {
+ context.structuralObject = refresh.getObject();
+ }
- // Notify removals
- refresh.getRemovedChildren();
+ //
+ boolean loaded = context.children.relateds != null;
- // Notify additions
- refresh.getAddedChildren();
-
//
- refresh.getValidChildren();
+ if (loaded)
+ {
+ boolean refreshChildren = scope.enterChildren(object, loaded);
- // Notify refresh
- refresh.getStaleChildren();
+ // Removals
+ for (String removedId : refresh.getRemovedChildren())
+ {
+ }
+
+
+ // Compute set of added ids
+// Set<String> addedIds = new HashSet<String>();
+// for (StructuralObject addedSO : refresh.getAddedChildren())
+// {
+// addedIds.add(addedSO.getId());
+// }
+
+ List<UIContainerObject> children = new ArrayList<UIContainerObject>();
+
+ //
+ for (StructuralObject addedSO : refresh.getAddedChildren())
+ {
+ }
+
+ //
+ for (String validId : refresh.getValidChildren())
+ {
+ }
+
+
+ //
+ for (StructuralObject staleSO : refresh.getStaleChildren().values())
+ {
+ }
+
+ // Update to valid
+ context.status = UIObject.Status.VALID;
+ }
}
catch (NoSuchStateException e)
{
- object.context.status = UIObject.Status.INVALID;
+ context.status = UIObject.Status.INVALID;
}
//
break;
case INVALID:
- throw new IllegalStateException();
}
//
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-26 17:08:59 UTC (rev 9387)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-27 11:16:19 UTC (rev 9388)
@@ -58,11 +58,29 @@
public interface Visitor
{
+ /**
+ * Returns true if the provided object should be visited.
+ *
+ * @param object the object
+ * @return true if it should be visited
+ */
boolean enterObject(UIObject object);
+ /**
+ * Callback to signal that an object visit is terminated
+ *
+ * @param object the object
+ */
void leaveObject(UIObject object);
- boolean enterChildren(UIObject object);
+ /**
+ * Returns true if the children should be visited
+ *
+ * @param object the parent of the children
+ * @param loaded if the relationship is already loaded
+ * @return true if the children should be visited
+ */
+ boolean enterChildren(UIObject object, boolean loaded);
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-26 17:08:59 UTC (rev 9387)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-27 11:16:19 UTC (rev 9388)
@@ -647,6 +647,7 @@
assertSame(context.getObject(daaId), daa);
}
+
public void _testMove() throws Exception
{
MockObject mockRoot = model.getRoot();
18 years, 4 months
JBoss Portal SVN: r9387 - 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-26 12:08:59 -0500 (Wed, 26 Dec 2007)
New Revision: 9387
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:
implement test cases that test that model navigation can invalidate the model
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-26 16:32:38 UTC (rev 9386)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-26 17:08:59 UTC (rev 9387)
@@ -77,7 +77,7 @@
this.root = (UIContext)root;
// Update universe
- universe.put(rootId, root);
+ put(root);
}
private UIContainerObject create(StructuralObject structuralObject)
@@ -115,7 +115,7 @@
StructuralObject.Update update = (StructuralObject.Update)change;
//
- UIContainerObject object = universe.get(update.getObject().getId());
+ UIContainerObject object = get(update.getObject());
//
if (object == null)
@@ -132,7 +132,7 @@
StructuralObject.Creation creation = (StructuralObject.Creation)change;
//
- UIContainerObject parent = universe.get(creation.getParent().getId());
+ UIContainerObject parent = get(creation.getParent());
//
if (parent == null)
@@ -152,7 +152,7 @@
UIContainerObject child = create(creation.getChild());
//
- universe.put(creation.getChild().getId(), child);
+ put(child);
//
parentContext.children.relateds.add(child);
@@ -163,7 +163,7 @@
StructuralObject.Destruction destruction = (StructuralObject.Destruction)change;
//
- UIContainerObject parent = universe.get(destruction.getParent().getId());
+ UIContainerObject parent = get(destruction.getParent());
//
if (parent != null)
@@ -231,7 +231,7 @@
*/
UIContainerObject getObject(String id)
{
- UIContainerObject object = universe.get(id);
+ UIContainerObject object = get(id);
//
if (object != null)
@@ -249,7 +249,7 @@
object = create(structuralObject);
//
- universe.put(structuralObject.getId(), object);
+ put(object);
//
return object;
@@ -366,6 +366,16 @@
}
}
+ ManyToOne createManyToOne(UIObjectContext context)
+ {
+ return new ManyToOne(context);
+ }
+
+ OneToMany createOneToMany(UIObjectContext context)
+ {
+ return new OneToMany(context);
+ }
+
// Private **********************************************************************************************************
// /**
@@ -404,11 +414,21 @@
// return containerObject;
// }
- public ManyToOne createManyToOne(UIObjectContext context)
+ private void put(UIContainerObject object)
{
- return new ManyToOne(context);
+ universe.put(object.getId(), object);
}
+ private UIContainerObject get(String id)
+ {
+ return universe.get(id);
+ }
+
+ private UIContainerObject get(StructuralObject so)
+ {
+ return universe.get(so.getId());
+ }
+
class ManyToOne
{
@@ -435,7 +455,7 @@
// If null it is the root so nothing is done
if (parentSO != null)
{
- UIContainerObject parent = universe.get(parentSO.getId());
+ UIContainerObject parent = UIObjectContainer.this.get(parentSO);
//
if (parent != null)
@@ -456,7 +476,7 @@
parent = create(parentSO);
//
- universe.put(parentSO.getId(), parent);
+ put(parent);
//
related = parent;
@@ -478,11 +498,6 @@
}
}
- public OneToMany createOneToMany(UIObjectContext context)
- {
- return new OneToMany(context);
- }
-
class OneToMany
{
@@ -519,7 +534,7 @@
//
for (StructuralObject childSO : structuralStateContext.loadChildren(structuralObject))
{
- UIContainerObject child = universe.get(childSO.getId());
+ UIContainerObject child = UIObjectContainer.this.get(childSO);
//
if (child != null)
@@ -537,7 +552,7 @@
child = create(childSO);
//
- universe.put(childSO.getId(), child);
+ put(child);
}
//
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-26 16:32:38 UTC (rev 9386)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-26 17:08:59 UTC (rev 9387)
@@ -45,6 +45,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.HashSet;
+import java.util.Set;
+import java.util.Map;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -539,6 +541,112 @@
assertEquals(null, context.getObject(daaId));
}
+ public void testParentNavigationUpdatesExistingParentStatus() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+
+ //
+ String fooId = mockFoo.getId();
+ String juuId = mockJuu.getId();
+
+ //
+ UIContext context = createContext();
+
+ // Get the object
+ UIObject foo = context.getObject(fooId);
+ UIObject juu = context.getObject(juuId);
+
+ //
+ assertEquals(UIObject.Status.VALID, juu.getStatus());
+ assertEquals(UIObject.Status.VALID, foo.getStatus());
+
+ // Now update foo concurrently
+ mockFoo.setPropertyValue("abc", "def");
+
+ // Now navigate
+ UIObject foo2 = juu.getParent();
+
+ //
+ assertSame(foo, foo2);
+ assertEquals(UIObject.Status.VALID, juu.getStatus());
+ assertEquals(UIObject.Status.STALE, foo.getStatus());
+ }
+
+ public void testChildrenNavigationUpdatesExistingChildStatus() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+
+ //
+ String fooId = mockFoo.getId();
+ String juuId = mockJuu.getId();
+
+ //
+ UIContext context = createContext();
+
+ // Get the object
+ UIObject foo = context.getObject(fooId);
+ UIObject juu = context.getObject(juuId);
+
+ //
+ assertEquals(UIObject.Status.VALID, juu.getStatus());
+ assertEquals(UIObject.Status.VALID, foo.getStatus());
+
+ // Now update juu concurrently
+ mockJuu.setPropertyValue("abc", "def");
+
+ // Now navigate
+ List<? extends UIObject> fooChildren = foo.getChildren();
+
+ //
+ assertNotNull(fooChildren);
+ assertEquals(1, fooChildren.size());
+ assertSame(juu, fooChildren.iterator().next());
+ assertEquals(UIObject.Status.STALE, juu.getStatus());
+ assertEquals(UIObject.Status.VALID, foo.getStatus());
+ }
+
+ public void testChildrenNavigationCombinesExistingChildrenAndLoadAbsentChildren() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+ MockObject mockDaa = mockFoo.addChild("daa", MockObject.Type.PAGE);
+
+ //
+ String fooId = mockFoo.getId();
+ String juuId = mockJuu.getId();
+ String daaId = mockDaa.getId();
+
+ //
+ UIContext context = createContext();
+
+ // Load foo and juu but not daa
+ UIObject foo = context.getObject(fooId);
+ UIObject juu = context.getObject(juuId);
+
+ // Now navigate
+ List<? extends UIObject> fooChildren = foo.getChildren();
+
+ //
+ assertNotNull(fooChildren);
+ Map<String, UIObject> tmp = new HashMap<String, UIObject>();
+ for (UIObject o : fooChildren)
+ {
+ tmp.put(o.getId(), o);
+ }
+
+ //
+ assertEquals(2, tmp.size());
+ assertEquals(Tools.toSet(juuId, daaId), tmp.keySet());
+ assertSame(juu, tmp.get(juuId));
+ UIObject daa = tmp.get(daaId);
+ assertSame(context.getObject(daaId), daa);
+ }
+
public void _testMove() throws Exception
{
MockObject mockRoot = model.getRoot();
18 years, 4 months
JBoss Portal SVN: r9386 - in branches/presentation: presentation/src/main/org/jboss/portal/presentation/impl/model/container and 3 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-26 11:32:38 -0500 (Wed, 26 Dec 2007)
New Revision: 9386
Modified:
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.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/StructuralObjectImpl.java
Log:
better implementation of state management
Modified: branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralObjectImpl.java
===================================================================
--- branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralObjectImpl.java 2007-12-26 13:44:52 UTC (rev 9385)
+++ branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralObjectImpl.java 2007-12-26 16:32:38 UTC (rev 9386)
@@ -25,6 +25,7 @@
import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralState;
+import org.jboss.portal.common.NotYetImplemented;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -54,4 +55,9 @@
{
return state;
}
+
+ public boolean compareTo(StructuralObject other)
+ {
+ throw new NotYetImplemented();
+ }
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-26 13:44:52 UTC (rev 9385)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-26 16:32:38 UTC (rev 9386)
@@ -30,13 +30,13 @@
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
-import org.jboss.portal.presentation.impl.model.UIContextImpl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.AbstractList;
+import java.util.Iterator;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -60,20 +60,40 @@
/** . */
final NavigationalStateContext navigationalStateContext;
+ /** . */
+ private final UIObjectFactory factory = new UIObjectFactory();
+
public UIObjectContainer(StructuralStateContext structuralStateContext, NavigationalStateContext navigationalStateContext)
{
- // Put our self in the universe
+ // Get root so
String rootId = structuralStateContext.getRootId();
- StructuralObject rootObject = structuralStateContext.load(rootId);
- UIContextImpl root = (UIContextImpl)update(rootObject);
+ StructuralObject rootStructuralObject = structuralStateContext.load(rootId);
+ UIContainerObject root = create(rootStructuralObject);
//
this.structuralStateContext = structuralStateContext;
this.navigationalStateContext = navigationalStateContext;
this.listeners = new ArrayList<ModelListener>();
- this.root = root;
+ this.root = (UIContext)root;
+
+ // Update universe
+ universe.put(rootId, root);
}
+ private UIContainerObject create(StructuralObject structuralObject)
+ {
+ // Create context
+ UIObjectContext context = new UIObjectContext(this, structuralObject);
+
+ // Create container object
+ UIContainerObject object = factory.createObject(structuralObject.getState().getType());
+
+ // Contextualize
+ object.setContext(context);
+
+ return object;
+ }
+
// Public ***********************************************************************************************************
public UIContext getRoot()
@@ -95,26 +115,82 @@
StructuralObject.Update update = (StructuralObject.Update)change;
//
- update(update.getObject());
+ UIContainerObject object = universe.get(update.getObject().getId());
+
+ //
+ if (object == null)
+ {
+ throw new AssertionError("It should be here, should we do something ???");
+ }
+
+ //
+ UIObjectContext context = object.getContext();
+ context.structuralObject = update.getObject();
}
else if (change instanceof StructuralObject.Creation)
{
StructuralObject.Creation creation = (StructuralObject.Creation)change;
//
- update(creation.getParent());
+ UIContainerObject parent = universe.get(creation.getParent().getId());
//
- update(creation.getChild());
+ if (parent == null)
+ {
+ throw new AssertionError("It should be here, should we do something ???");
+ }
+
+ //
+ UIObjectContext parentContext = parent.getContext();
+
+ //
+ parentContext.structuralObject = creation.getParent();
+
+ //
+ if (parentContext.children.relateds != null)
+ {
+ UIContainerObject child = create(creation.getChild());
+
+ //
+ universe.put(creation.getChild().getId(), child);
+
+ //
+ parentContext.children.relateds.add(child);
+ }
}
else if (change instanceof StructuralObject.Destruction)
{
StructuralObject.Destruction destruction = (StructuralObject.Destruction)change;
//
- update(destruction.getParent());
+ UIContainerObject parent = universe.get(destruction.getParent().getId());
//
+ if (parent != null)
+ {
+ UIObjectContext parentContext = parent.getContext();
+
+ //
+ parentContext.structuralObject = destruction.getParent();
+
+ //
+ if (parentContext.children.relateds != null)
+ {
+ for (Iterator<UIContainerObject> i = parentContext.children.relateds.iterator();i.hasNext();)
+ {
+ UIContainerObject child = i.next();
+
+ //
+ if (destruction.getIds().contains(child.getId()))
+ {
+ i.remove();
+ break;
+ }
+ }
+ }
+ }
+
+ //
for (String id : destruction.getIds())
{
UIContainerObject o = universe.remove(id);
@@ -126,19 +202,19 @@
}
}
}
- 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;
+//
+// //
+// update(move.getParent());
+//
+// //
+// update(move.getSource());
+//
+// //
+// update(move.getDestination());
+// }
else
{
throw new AssertionError();
@@ -151,45 +227,36 @@
* the object.
*
* @param id the id of the object to obtain
- * @param loadIfAbsent load the object from the structural state context if it is not present
* @return the loaded object
*/
- UIContainerObject getObject(String id, boolean loadIfAbsent)
+ UIContainerObject getObject(String id)
{
- try
+ UIContainerObject object = universe.get(id);
+
+ //
+ if (object != null)
{
- UIContainerObject context = universe.get(id);
+ return object;
+ }
+ //
+ // Fetch the state of the UIObject in question
+ StructuralObject structuralObject = this.structuralStateContext.load(id);
+
+ //
+ if (structuralObject != null)
+ {
+ object = create(structuralObject);
+
//
- if (context != null)
- {
- return context;
- }
+ universe.put(structuralObject.getId(), object);
//
- if (loadIfAbsent)
- {
- // Fetch the state of the UIObject in question
- StructuralObject structuralObject = this.structuralStateContext.load(id);
-
- //
- if (structuralObject != null)
- {
- return update(structuralObject);
- }
- else
- {
- return null;
- }
- }
- else
- {
- throw new AssertionError("Should not be here");
- }
+ return object;
}
- catch (Exception e)
+ else
{
- throw new RuntimeException(e);
+ return null;
}
}
@@ -301,42 +368,42 @@
// 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)
- {
- UIContainerObject containerObject = universe.get(structuralObject.getId());
+// /**
+// * 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;
+// }
- //
- 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;
- }
-
public ManyToOne createManyToOne(UIObjectContext context)
{
return new ManyToOne(context);
@@ -363,7 +430,38 @@
{
if (!loaded)
{
- related = getParent(owner.structuralObject);
+ StructuralObject parentSO = structuralStateContext.loadParent(owner.structuralObject);
+
+ // If null it is the root so nothing is done
+ if (parentSO != null)
+ {
+ UIContainerObject parent = universe.get(parentSO.getId());
+
+ //
+ if (parent != null)
+ {
+ related = parent;
+
+ //
+ UIObjectContext parentContext = parent.getContext();
+
+ //
+ if (!parentSO.compareTo(parentContext.structuralObject))
+ {
+ parentContext.status = UIObject.Status.STALE;
+ }
+ }
+ else
+ {
+ parent = create(parentSO);
+
+ //
+ universe.put(parentSO.getId(), parent);
+
+ //
+ related = parent;
+ }
+ }
}
// Try to resolve the relationship
@@ -378,20 +476,6 @@
related = null;
loaded = false;
}
-
- private UIContainerObject getParent(StructuralObject structuralObject)
- {
- StructuralObject parentStructuralState = structuralStateContext.loadParent(structuralObject);
-
- //
- if (parentStructuralState == null)
- {
- return null;
- }
-
- //
- return update(parentStructuralState);
- }
}
public OneToMany createOneToMany(UIObjectContext context)
@@ -433,9 +517,30 @@
ArrayList<UIContainerObject> children = new ArrayList<UIContainerObject>();
//
- for (StructuralObject structuralChild : structuralStateContext.loadChildren(structuralObject))
+ for (StructuralObject childSO : structuralStateContext.loadChildren(structuralObject))
{
- UIContainerObject child = update(structuralChild);
+ UIContainerObject child = universe.get(childSO.getId());
+
+ //
+ if (child != null)
+ {
+ UIObjectContext childContext = child.getContext();
+
+ //
+ if (!childContext.structuralObject.compareTo(childSO))
+ {
+ childContext.status = UIObject.Status.STALE;
+ }
+ }
+ else
+ {
+ child = create(childSO);
+
+ //
+ universe.put(childSO.getId(), child);
+ }
+
+ //
children.add(child);
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-26 13:44:52 UTC (rev 9385)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-26 16:32:38 UTC (rev 9386)
@@ -87,7 +87,7 @@
public UIObject getObject(String id)
{
- return container.getObject(id, true);
+ return container.getObject(id);
}
public void addModelListener(ModelListener listener)
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-26 13:44:52 UTC (rev 9385)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java 2007-12-26 16:32:38 UTC (rev 9386)
@@ -37,6 +37,8 @@
StructuralState getState();
+ boolean compareTo(StructuralObject other);
+
/**
* A comparison between two structural objects.
*/
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-26 13:44:52 UTC (rev 9385)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-26 16:32:38 UTC (rev 9386)
@@ -539,7 +539,7 @@
assertEquals(null, context.getObject(daaId));
}
- 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/StructuralObjectImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectImpl.java 2007-12-26 13:44:52 UTC (rev 9385)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectImpl.java 2007-12-26 16:32:38 UTC (rev 9386)
@@ -68,15 +68,17 @@
return state;
}
- public boolean equals(Object o)
+ public boolean compareTo(StructuralObject other)
{
- if (o == this)
+ if (other == this)
{
return true;
}
- if (o instanceof StructuralObjectImpl)
+ if (other instanceof StructuralObjectImpl)
{
- StructuralObjectImpl that = (StructuralObjectImpl)o;
+ StructuralObjectImpl that = (StructuralObjectImpl)other;
+
+ //
return handle.equals(that.handle);
}
return false;
18 years, 4 months
JBoss Portal SVN: r9385 - 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-26 08:44:52 -0500 (Wed, 26 Dec 2007)
New Revision: 9385
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
Log:
- move parent/children load methods to more convenient place
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-26 13:40:26 UTC (rev 9384)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-26 13:44:52 UTC (rev 9385)
@@ -145,35 +145,6 @@
}
}
- UIContainerObject getParent(StructuralObject structuralObject)
- {
- StructuralObject parentStructuralState = structuralStateContext.loadParent(structuralObject);
-
- //
- if (parentStructuralState == null)
- {
- return null;
- }
-
- //
- return update(parentStructuralState);
- }
-
- List<UIContainerObject> getChildren(StructuralObject structuralObject)
- {
- ArrayList<UIContainerObject> children = new ArrayList<UIContainerObject>();
-
- //
- for (StructuralObject structuralChild : structuralStateContext.loadChildren(structuralObject))
- {
- UIContainerObject child = update(structuralChild);
- children.add(child);
- }
-
- //
- return children;
- }
-
/**
* 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
@@ -407,6 +378,20 @@
related = null;
loaded = false;
}
+
+ private UIContainerObject getParent(StructuralObject structuralObject)
+ {
+ StructuralObject parentStructuralState = structuralStateContext.loadParent(structuralObject);
+
+ //
+ if (parentStructuralState == null)
+ {
+ return null;
+ }
+
+ //
+ return update(parentStructuralState);
+ }
}
public OneToMany createOneToMany(UIObjectContext context)
@@ -443,6 +428,21 @@
relateds = null;
}
+ private List<UIContainerObject> getChildren(StructuralObject structuralObject)
+ {
+ ArrayList<UIContainerObject> children = new ArrayList<UIContainerObject>();
+
+ //
+ for (StructuralObject structuralChild : structuralStateContext.loadChildren(structuralObject))
+ {
+ UIContainerObject child = update(structuralChild);
+ children.add(child);
+ }
+
+ //
+ return children;
+ }
+
private class ProxyList extends AbstractList<UIContainerObject>
{
public UIContainerObject get(int i)
18 years, 4 months
JBoss Portal SVN: r9384 - 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-26 08:40:26 -0500 (Wed, 26 Dec 2007)
New Revision: 9384
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/UIObjectContext.java
Log:
- implement toString in proxy list that does not fetch the relationship
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-26 13:37:47 UTC (rev 9383)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-26 13:40:26 UTC (rev 9384)
@@ -474,6 +474,11 @@
}
return relateds.size();
}
+
+ public String toString()
+ {
+ return "ProxyList[" + owner + "]";
+ }
}
}
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-26 13:37:47 UTC (rev 9383)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-26 13:40:26 UTC (rev 9384)
@@ -134,4 +134,9 @@
throw new AssertionError(e);
}
}
+
+ public String toString()
+ {
+ return "UIObjectContext[" + structuralObject.getId() + "]";
+ }
}
18 years, 4 months
JBoss Portal SVN: r9383 - 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-26 08:37:47 -0500 (Wed, 26 Dec 2007)
New Revision: 9383
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java
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/UIObjectContext.java
Log:
- removed unused class
- move the relationship inner classes to the UIObjectContainer
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-21 22:17:58 UTC (rev 9382)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-26 13:37:47 UTC (rev 9383)
@@ -1,437 +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.io.Serializable;
-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 abstract class AbstractUIObject implements UIObject, Serializable
-{
-
- /** . */
- private static final Map<String, String> EMPTY_STATE = Collections.emptyMap();
-
- /** The context. */
- protected final UIObjectContext context;
-
- /** . */
- final UIObjectOneToMany childrenRelationship;
-
- /** . */
- final UIObjectManyToOne parentRelationship;
-
- public AbstractUIObject(UIObjectContext context)
- {
- if (context == null)
- {
- throw new IllegalArgumentException("No null context accepted");
- }
-
- //
- this.context = context;
- this.childrenRelationship = new UIObjectOneToMany(context);
- this.parentRelationship = new UIObjectManyToOne(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 AbstractUIObject getChild(String name)
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
- if (name == null)
- {
- throw new IllegalArgumentException("No null name accepted");
- }
-
- //
- for (AbstractUIObject 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 parentRelationship.get();
- }
-
- public final List<AbstractUIObject> getChildren()
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
-
- //
- return childrenRelationship.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
- AbstractUIObject 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.context.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 AbstractUIObject)
- {
- //
- AbstractUIObject tmp = (AbstractUIObject)destination;
-
- // Perform the move operation
- StructuralObject.Move move = context.container.structuralStateContext.move(context.structuralObject, tmp.context.structuralObject);
-
- //
- context.container.update(move);
- }
- else
- {
- throw new IllegalArgumentException("Object not of right type");
- }
- }
-
- protected abstract <T extends UIObject> boolean isAllowedAsChild(Class<T> type);
-
- /**
- * Visitor that visits a single node only.
- */
- private static final Visitor SINGLE_NODE_VISITOR = new Visitor()
- {
- public boolean enterObject(UIObject object)
- {
- return true;
- }
-
- public void leaveObject(UIObject object)
- {
- }
-
- public boolean enterChildren(UIObject object)
- {
- return false;
- }
- };
-
-}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-21 22:17:58 UTC (rev 9382)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-26 13:37:47 UTC (rev 9383)
@@ -36,6 +36,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.AbstractList;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -365,4 +366,114 @@
return containerObject;
}
+ public ManyToOne createManyToOne(UIObjectContext context)
+ {
+ return new ManyToOne(context);
+ }
+
+ class ManyToOne
+ {
+
+ /** . */
+ private final UIObjectContext owner;
+
+ /** . */
+ private boolean loaded;
+
+ /** . */
+ private UIContainerObject related;
+
+ private ManyToOne(UIObjectContext owner)
+ {
+ this.owner = owner;
+ }
+
+ UIContainerObject get()
+ {
+ if (!loaded)
+ {
+ related = getParent(owner.structuralObject);
+ }
+
+ // Try to resolve the relationship
+
+
+ //
+ return related;
+ }
+
+ void clear()
+ {
+ related = null;
+ loaded = false;
+ }
+ }
+
+ public OneToMany createOneToMany(UIObjectContext context)
+ {
+ return new OneToMany(context);
+ }
+
+ 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;
+ }
+
+ void clear()
+ {
+ relateds = null;
+ }
+
+ 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 not valid");
+ }
+ if (relateds == null)
+ {
+ relateds = getChildren(owner.structuralObject);
+ }
+ return relateds.size();
+ }
+ }
+ }
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-21 22:17:58 UTC (rev 9382)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-26 13:37:47 UTC (rev 9383)
@@ -47,10 +47,10 @@
final UIManagedObject managedObject;
/** . */
- final UIObjectRelationship.OneToMany children;
+ final UIObjectContainer.OneToMany children;
/** . */
- final UIObjectRelationship.ManyToOne parent;
+ final UIObjectContainer.ManyToOne parent;
/** . */
StructuralObject structuralObject;
@@ -74,8 +74,8 @@
this.structuralObject = structuralObject;
this.status = UIObject.Status.VALID;
this.managedObject = new UIManagedObject(this);
- this.children = new UIObjectRelationship.OneToMany(this);
- this.parent = new UIObjectRelationship.ManyToOne(this);
+ this.children = container.createOneToMany(this);
+ this.parent = container.createManyToOne(this);
}
// Public ***********************************************************************************************************
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java 2007-12-21 22:17:58 UTC (rev 9382)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java 2007-12-26 13:37:47 UTC (rev 9383)
@@ -1,135 +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 java.util.List;
-import java.util.AbstractList;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class UIObjectRelationship
-{
-
- final static class ManyToOne
- {
-
- /** . */
- private final UIObjectContext owner;
-
- /** . */
- private boolean loaded;
-
- /** . */
- private UIContainerObject related;
-
- ManyToOne(UIObjectContext owner)
- {
- this.owner = owner;
- }
-
- UIContainerObject get()
- {
- if (!loaded)
- {
- related = owner.container.getParent(owner.structuralObject);
- }
-
- // Try to resolve the relationship
-
-
- //
- return related;
- }
-
- void clear()
- {
- related = null;
- loaded = false;
- }
- }
-
- final static class OneToMany
- {
-
- /** . */
- private final ProxyList list;
-
- /** . */
- private final UIObjectContext owner;
-
- /** . */
- private List<UIContainerObject> relateds;
-
- OneToMany(UIObjectContext object)
- {
- this.owner = object;
- this.list = new ProxyList();
- this.relateds = null;
- }
-
- List<UIContainerObject> get()
- {
- return list;
- }
-
- void clear()
- {
- relateds = null;
- }
-
- 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 = owner.container.getChildren(owner.structuralObject);
- }
-
- //
- return relateds.get(i);
- }
-
- public int size()
- {
- if (!owner.isValid())
- {
- throw new IllegalStateException("Relationship not valid");
- }
- if (relateds == null)
- {
- relateds = owner.container.getChildren(owner.structuralObject);
- }
- return relateds.size();
- }
- }
- }
-}
18 years, 4 months
JBoss Portal SVN: r9382 - 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-21 17:17:58 -0500 (Fri, 21 Dec 2007)
New Revision: 9382
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
Log:
move relationship classes to inner static classes as it will be easier to enforce encapsulation of the state for the same package while allowing the 2 classes to access each other state
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-21 21:57:12 UTC (rev 9381)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-21 22:17:58 UTC (rev 9382)
@@ -47,10 +47,10 @@
final UIManagedObject managedObject;
/** . */
- final UIObjectOneToMany children;
+ final UIObjectRelationship.OneToMany children;
/** . */
- final UIObjectManyToOne parent;
+ final UIObjectRelationship.ManyToOne parent;
/** . */
StructuralObject structuralObject;
@@ -74,8 +74,8 @@
this.structuralObject = structuralObject;
this.status = UIObject.Status.VALID;
this.managedObject = new UIManagedObject(this);
- this.children = new UIObjectOneToMany(this);
- this.parent = new UIObjectManyToOne(this);
+ this.children = new UIObjectRelationship.OneToMany(this);
+ this.parent = new UIObjectRelationship.ManyToOne(this);
}
// Public ***********************************************************************************************************
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java 2007-12-21 21:57:12 UTC (rev 9381)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java 2007-12-21 22:17:58 UTC (rev 9382)
@@ -1,64 +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;
-
-/**
- * A lazy reference.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-final class UIObjectManyToOne
-{
-
- /** . */
- private final UIObjectContext owner;
-
- /** . */
- private boolean loaded;
-
- /** . */
- private UIContainerObject related;
-
- UIObjectManyToOne(UIObjectContext owner)
- {
- this.owner = owner;
- }
-
- UIContainerObject get()
- {
- if (!loaded)
- {
- related = owner.container.getParent(owner.structuralObject);
- }
-
- //
- return related;
- }
-
- void clear()
- {
- related = null;
- loaded = false;
- }
-}
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java 2007-12-21 21:57:12 UTC (rev 9381)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java 2007-12-21 22:17:58 UTC (rev 9382)
@@ -1,93 +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 java.util.AbstractList;
-import java.util.List;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-final class UIObjectOneToMany
-{
-
- /** . */
- private final ProxyList list;
-
- /** . */
- private final UIObjectContext owner;
-
- /** . */
- private List<UIContainerObject> relateds;
-
- UIObjectOneToMany(UIObjectContext object)
- {
- this.owner = object;
- this.list = new ProxyList();
- this.relateds = null;
- }
-
- List<UIContainerObject> get()
- {
- return list;
- }
-
- void clear()
- {
- relateds = null;
- }
-
- 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 = owner.container.getChildren(owner.structuralObject);
- }
-
- //
- return relateds.get(i);
- }
-
- public int size()
- {
- if (!owner.isValid())
- {
- throw new IllegalStateException("Relationship not valid");
- }
- if (relateds == null)
- {
- relateds = owner.container.getChildren(owner.structuralObject);
- }
- return relateds.size();
- }
- }
-}
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java 2007-12-21 22:17:58 UTC (rev 9382)
@@ -0,0 +1,135 @@
+/******************************************************************************
+ * 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 java.util.List;
+import java.util.AbstractList;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UIObjectRelationship
+{
+
+ final static class ManyToOne
+ {
+
+ /** . */
+ private final UIObjectContext owner;
+
+ /** . */
+ private boolean loaded;
+
+ /** . */
+ private UIContainerObject related;
+
+ ManyToOne(UIObjectContext owner)
+ {
+ this.owner = owner;
+ }
+
+ UIContainerObject get()
+ {
+ if (!loaded)
+ {
+ related = owner.container.getParent(owner.structuralObject);
+ }
+
+ // Try to resolve the relationship
+
+
+ //
+ return related;
+ }
+
+ void clear()
+ {
+ related = null;
+ loaded = false;
+ }
+ }
+
+ final static class OneToMany
+ {
+
+ /** . */
+ private final ProxyList list;
+
+ /** . */
+ private final UIObjectContext owner;
+
+ /** . */
+ private List<UIContainerObject> relateds;
+
+ OneToMany(UIObjectContext object)
+ {
+ this.owner = object;
+ this.list = new ProxyList();
+ this.relateds = null;
+ }
+
+ List<UIContainerObject> get()
+ {
+ return list;
+ }
+
+ void clear()
+ {
+ relateds = null;
+ }
+
+ 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 = owner.container.getChildren(owner.structuralObject);
+ }
+
+ //
+ return relateds.get(i);
+ }
+
+ public int size()
+ {
+ if (!owner.isValid())
+ {
+ throw new IllegalStateException("Relationship not valid");
+ }
+ if (relateds == null)
+ {
+ relateds = owner.container.getChildren(owner.structuralObject);
+ }
+ return relateds.size();
+ }
+ }
+ }
+}
18 years, 4 months
JBoss Portal SVN: r9381 - 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-21 16:57:12 -0500 (Fri, 21 Dec 2007)
New Revision: 9381
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java
Log:
simplify a bit useless complexity
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java 2007-12-21 21:36:43 UTC (rev 9380)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java 2007-12-21 21:57:12 UTC (rev 9381)
@@ -28,23 +28,37 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-final class UIObjectManyToOne extends UIObjectRelationship<UIContainerObject>
+final class UIObjectManyToOne
{
/** . */
private final UIObjectContext owner;
+ /** . */
+ private boolean loaded;
+
+ /** . */
+ private UIContainerObject related;
+
UIObjectManyToOne(UIObjectContext owner)
{
this.owner = owner;
}
- protected UIContainerObject doLoad()
+ UIContainerObject get()
{
- return owner.container.getParent(owner.structuralObject);
+ if (!loaded)
+ {
+ related = owner.container.getParent(owner.structuralObject);
+ }
+
+ //
+ return related;
}
- protected void doEvict(UIContainerObject abstractUIObject)
+ void clear()
{
+ related = null;
+ loaded = false;
}
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java 2007-12-21 21:36:43 UTC (rev 9380)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java 2007-12-21 21:57:12 UTC (rev 9381)
@@ -29,7 +29,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-final class UIObjectOneToMany extends UIObjectRelationship<List<UIContainerObject>>
+final class UIObjectOneToMany
{
/** . */
@@ -39,22 +39,23 @@
private final UIObjectContext owner;
/** . */
- private List<UIContainerObject> content;
+ private List<UIContainerObject> relateds;
UIObjectOneToMany(UIObjectContext object)
{
this.owner = object;
this.list = new ProxyList();
+ this.relateds = null;
}
- protected List<UIContainerObject> doLoad()
+ List<UIContainerObject> get()
{
return list;
}
- protected void doEvict(List<UIContainerObject> abstractUIObjects)
+ void clear()
{
- content = null;
+ relateds = null;
}
private class ProxyList extends AbstractList<UIContainerObject>
@@ -67,13 +68,13 @@
}
// Load the entire relationship
- if (content == null)
+ if (relateds == null)
{
- content = owner.container.getChildren(owner.structuralObject);
+ relateds = owner.container.getChildren(owner.structuralObject);
}
//
- return content.get(i);
+ return relateds.get(i);
}
public int size()
@@ -82,11 +83,11 @@
{
throw new IllegalStateException("Relationship not valid");
}
- if (content == null)
+ if (relateds == null)
{
- content = owner.container.getChildren(owner.structuralObject);
+ relateds = owner.container.getChildren(owner.structuralObject);
}
- return content.size();
+ return relateds.size();
}
}
}
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java 2007-12-21 21:36:43 UTC (rev 9380)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java 2007-12-21 21:57:12 UTC (rev 9381)
@@ -1,79 +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;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-abstract class UIObjectRelationship<T>
-{
-
- /** . */
- private static final int NOT_LOADED = 0;
-
- /** . */
- private static final int LOADED = 1;
-
- /** . */
- private int status;
-
- /** . */
- private T t;
-
- public void clear()
- {
- if (status == LOADED)
- {
- T tmp = t;
-
- //
- t = null;
- status = NOT_LOADED;
-
- //
- doEvict(tmp);
- }
- }
-
- public T get()
- {
- if (status == NOT_LOADED)
- {
- t = doLoad();
- status = LOADED;
- }
-
- //
- return t;
- }
-
- protected final int getStatus()
- {
- return status;
- }
-
- protected abstract T doLoad();
-
- protected abstract void doEvict(T t);
-}
18 years, 4 months
JBoss Portal SVN: r9380 - 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-21 16:36:43 -0500 (Fri, 21 Dec 2007)
New Revision: 9380
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java
Log:
move the relationship fields from the managed object to its context
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java 2007-12-21 21:28:29 UTC (rev 9379)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java 2007-12-21 21:36:43 UTC (rev 9380)
@@ -52,12 +52,6 @@
/** The context. */
protected final UIObjectContext context;
- /** . */
- final UIObjectOneToMany childrenRelationship;
-
- /** . */
- final UIObjectManyToOne parentRelationship;
-
public UIManagedObject(UIObjectContext context)
{
if (context == null)
@@ -67,8 +61,6 @@
//
this.context = context;
- this.childrenRelationship = new UIObjectOneToMany(context);
- this.parentRelationship = new UIObjectManyToOne(context);
}
// UIObject interface implementation --------------------------------------------------------------------------------
@@ -296,7 +288,7 @@
}
//
- return parentRelationship.get();
+ return context.parent.get();
}
public final List<UIContainerObject> getChildren()
@@ -307,7 +299,7 @@
}
//
- return childrenRelationship.get();
+ return context.children.get();
}
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-21 21:28:29 UTC (rev 9379)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-21 21:36:43 UTC (rev 9380)
@@ -357,8 +357,8 @@
//
context.structuralObject = structuralObject;
- context.managedObject.parentRelationship.clear();
- context.managedObject.childrenRelationship.clear();
+ context.parent.clear();
+ context.children.clear();
}
//
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-21 21:28:29 UTC (rev 9379)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-21 21:36:43 UTC (rev 9380)
@@ -41,17 +41,23 @@
{
/** . */
- UIObjectContainer container;
+ final UIObjectContainer container;
/** . */
+ final UIManagedObject managedObject;
+
+ /** . */
+ final UIObjectOneToMany children;
+
+ /** . */
+ final UIObjectManyToOne parent;
+
+ /** . */
StructuralObject structuralObject;
/** . */
UIObject.Status status;
- /** . */
- UIManagedObject managedObject;
-
public UIObjectContext(UIObjectContainer container, StructuralObject structuralObject)
{
if (container == null)
@@ -68,6 +74,8 @@
this.structuralObject = structuralObject;
this.status = UIObject.Status.VALID;
this.managedObject = new UIManagedObject(this);
+ this.children = new UIObjectOneToMany(this);
+ this.parent = new UIObjectManyToOne(this);
}
// Public ***********************************************************************************************************
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java 2007-12-21 21:28:29 UTC (rev 9379)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java 2007-12-21 21:36:43 UTC (rev 9380)
@@ -65,10 +65,14 @@
{
throw new IllegalStateException("Relationship not valid");
}
+
+ // Load the entire relationship
if (content == null)
{
content = owner.container.getChildren(owner.structuralObject);
}
+
+ //
return content.get(i);
}
18 years, 4 months
JBoss Portal SVN: r9379 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model: container and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-21 16:28:29 -0500 (Fri, 21 Dec 2007)
New Revision: 9379
Added:
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/UIContainerObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectAssociation.java
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java
Log:
decouple the notion of managed/container object
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java 2007-12-21 18:34:54 UTC (rev 9378)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java 2007-12-21 21:28:29 UTC (rev 9379)
@@ -23,32 +23,11 @@
package org.jboss.portal.presentation.impl.model;
import org.jboss.portal.presentation.model.UIContainer;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public class UIContainerImpl extends AbstractUIObject implements UIContainer
+public class UIContainerImpl extends UIObjectImpl implements UIContainer
{
-
- public UIContainerImpl(UIObjectContext context)
- {
- super(context);
- }
-
- protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
- {
- boolean isAllowedAsChild = false;
-
- if(type == UIWindow.class)
- {
- isAllowedAsChild = true;
- }
-
- return isAllowedAsChild;
- }
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-21 18:34:54 UTC (rev 9378)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-21 21:28:29 UTC (rev 9379)
@@ -22,10 +22,7 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.model;
-import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.UIPortal;
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.ModelListener;
@@ -33,19 +30,13 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-public class UIContextImpl extends AbstractUIObject implements UIContext
+public class UIContextImpl extends UIObjectImpl implements UIContext
{
- public UIContextImpl(UIObjectContext context)
+ public UIContextImpl()
{
- super(context);
}
- protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
- {
- return type == UIPortal.class;
- }
-
public UIObject getObject(String id)
{
return context.getObject(id);
Added: 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 (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-21 21:28:29 UTC (rev 9379)
@@ -0,0 +1,137 @@
+/******************************************************************************
+ * 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;
+
+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 java.util.List;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class UIObjectImpl implements UIContainerObject
+{
+
+ /** . */
+ protected UIObjectContext context;
+
+ //
+ public UIObjectContext getContext()
+ {
+ return context;
+ }
+
+ public void setContext(UIObjectContext context)
+ {
+ this.context = context;
+ }
+
+ //
+
+ public String getId()
+ {
+ return context.getManagedObject().getId();
+ }
+
+ public Status getStatus()
+ {
+ return context.getManagedObject().getStatus();
+ }
+
+ public void validate(Visitor scope)
+ {
+ context.getManagedObject().validate(scope);
+ }
+
+ public void validate()
+ {
+ context.getManagedObject().validate();
+ }
+
+ public void refresh(Visitor scope)
+ {
+ context.getManagedObject().refresh(scope);
+ }
+
+ public void refresh()
+ {
+ context.getManagedObject().refresh();
+ }
+
+ public <T> T getProperty(StateType stateType, String propertyName, Class<T> propertyType)
+ {
+ return context.getManagedObject().getProperty(stateType, propertyName, propertyType);
+ }
+
+ public Object getProperty(StateType stateType, String propertyName)
+ {
+ return context.getManagedObject().getProperty(stateType, propertyName);
+ }
+
+ public <T> void setProperty(StateType stateType, String propertyName, T propertyValue) throws StateChangeVetoException
+ {
+ context.getManagedObject().setProperty(stateType, propertyName, propertyValue);
+ }
+
+ public UIObject getChild(String name)
+ {
+ return context.getManagedObject().getChild(name);
+ }
+
+ public String getName()
+ {
+ return context.getManagedObject().getName();
+ }
+
+ public UIObject getParent()
+ {
+ return context.getManagedObject().getParent();
+ }
+
+ public List<? extends UIObject> getChildren()
+ {
+ return context.getManagedObject().getChildren();
+ }
+
+ public <T extends UIObject> T createChild(String name, Class<T> type) throws IllegalArgumentException
+ {
+ return context.getManagedObject().createChild(name, type);
+ }
+
+ public void destroyChild(String name) throws IllegalArgumentException, StateException
+ {
+ context.getManagedObject().destroyChild(name);
+ }
+
+ public void move(UIObject destination) throws IllegalArgumentException, StateException
+ {
+ context.getManagedObject().move(destination);
+ }
+}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java 2007-12-21 18:34:54 UTC (rev 9378)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java 2007-12-21 21:28:29 UTC (rev 9379)
@@ -22,27 +22,12 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.model;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.UIContainer;
import org.jboss.portal.presentation.model.UIPage;
-import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public class UIPageImpl extends AbstractUIObject implements UIPage
+public class UIPageImpl extends UIObjectImpl implements UIPage
{
-
- public UIPageImpl(UIObjectContext context)
- {
- super(context);
- }
-
- protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
- {
- return type == UIPage.class || type == UIContainer.class || type == UIWindow.class;
- }
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java 2007-12-21 18:34:54 UTC (rev 9378)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java 2007-12-21 21:28:29 UTC (rev 9379)
@@ -22,26 +22,12 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.model;
-import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIPortal;
-import org.jboss.portal.presentation.model.UIPage;
-import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public class UIPortalImpl extends AbstractUIObject implements UIPortal
+public class UIPortalImpl extends UIObjectImpl implements UIPortal
{
-
- public UIPortalImpl(UIObjectContext context)
- {
- super(context);
- }
-
- protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
- {
- return type == UIPage.class;
- }
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java 2007-12-21 18:34:54 UTC (rev 9378)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java 2007-12-21 21:28:29 UTC (rev 9379)
@@ -25,23 +25,15 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
import org.jboss.portal.presentation.model.StateType;
-import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public class UIWindowImpl extends AbstractUIObject implements UIWindow
+public class UIWindowImpl extends UIObjectImpl implements UIWindow
{
- public UIWindowImpl(UIObjectContext context)
- {
- super(context);
- }
-
/**
*
*/
@@ -73,9 +65,4 @@
{
setProperty(StateType.NAVIGATIONAL, "windowstate", windowState);
}
-
- protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
- {
- return false;
- }
}
Added: 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 (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java 2007-12-21 21:28:29 UTC (rev 9379)
@@ -0,0 +1,38 @@
+/******************************************************************************
+ * 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);
+
+}
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java (from rev 9378, branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java)
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java 2007-12-21 21:28:29 UTC (rev 9379)
@@ -0,0 +1,434 @@
+/******************************************************************************
+ * 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;
+
+ /** . */
+ final UIObjectOneToMany childrenRelationship;
+
+ /** . */
+ final UIObjectManyToOne parentRelationship;
+
+ public UIManagedObject(UIObjectContext context)
+ {
+ if (context == null)
+ {
+ throw new IllegalArgumentException("No null context accepted");
+ }
+
+ //
+ this.context = context;
+ this.childrenRelationship = new UIObjectOneToMany(context);
+ this.parentRelationship = new UIObjectManyToOne(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 parentRelationship.get();
+ }
+
+ public final List<UIContainerObject> getChildren()
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ return childrenRelationship.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)
+ {
+ return false;
+ }
+ };
+
+}
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectAssociation.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectAssociation.java 2007-12-21 18:34:54 UTC (rev 9378)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectAssociation.java 2007-12-21 21:28:29 UTC (rev 9379)
@@ -1,79 +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;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-abstract class UIObjectAssociation<T>
-{
-
- /** . */
- private static final int NOT_LOADED = 0;
-
- /** . */
- private static final int LOADED = 1;
-
- /** . */
- private int status;
-
- /** . */
- private T t;
-
- public void clear()
- {
- if (status == LOADED)
- {
- T tmp = t;
-
- //
- t = null;
- status = NOT_LOADED;
-
- //
- doEvict(tmp);
- }
- }
-
- public T get()
- {
- if (status == NOT_LOADED)
- {
- t = doLoad();
- status = LOADED;
- }
-
- //
- return t;
- }
-
- protected final int getStatus()
- {
- return status;
- }
-
- protected abstract T doLoad();
-
- protected abstract void doEvict(T t);
-}
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-21 18:34:54 UTC (rev 9378)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-21 21:28:29 UTC (rev 9379)
@@ -45,7 +45,7 @@
{
/** . */
- private final Map<String, AbstractUIObject> universe = new HashMap<String, AbstractUIObject>();
+ private final Map<String, UIContainerObject> universe = new HashMap<String, UIContainerObject>();
/** . */
private final List<ModelListener> listeners;
@@ -116,12 +116,12 @@
//
for (String id : destruction.getIds())
{
- AbstractUIObject o = universe.remove(id);
+ UIContainerObject o = universe.remove(id);
//
if (o != null)
{
- o.context.status = UIObject.Status.INVALID;
+ o.getContext().status = UIObject.Status.INVALID;
}
}
}
@@ -144,7 +144,7 @@
}
}
- AbstractUIObject getParent(StructuralObject structuralObject)
+ UIContainerObject getParent(StructuralObject structuralObject)
{
StructuralObject parentStructuralState = structuralStateContext.loadParent(structuralObject);
@@ -158,14 +158,14 @@
return update(parentStructuralState);
}
- List<AbstractUIObject> getChildren(StructuralObject structuralObject)
+ List<UIContainerObject> getChildren(StructuralObject structuralObject)
{
- ArrayList<AbstractUIObject> children = new ArrayList<AbstractUIObject>();
+ ArrayList<UIContainerObject> children = new ArrayList<UIContainerObject>();
//
for (StructuralObject structuralChild : structuralStateContext.loadChildren(structuralObject))
{
- AbstractUIObject child = update(structuralChild);
+ UIContainerObject child = update(structuralChild);
children.add(child);
}
@@ -182,11 +182,11 @@
* @param loadIfAbsent load the object from the structural state context if it is not present
* @return the loaded object
*/
- AbstractUIObject getObject(String id, boolean loadIfAbsent)
+ UIContainerObject getObject(String id, boolean loadIfAbsent)
{
try
{
- AbstractUIObject context = universe.get(id);
+ UIContainerObject context = universe.get(id);
//
if (context != null)
@@ -250,7 +250,7 @@
}
}
- void validate(AbstractUIObject object, UIObject.Visitor scope)
+ void validate(UIManagedObject object, UIObject.Visitor scope)
{
// if (scope.enterObject(object))
// {
@@ -280,7 +280,7 @@
// }
}
- void refresh(AbstractUIObject object, UIObject.Visitor scope)
+ void refresh(UIManagedObject object, UIObject.Visitor scope)
{
@@ -336,31 +336,33 @@
* @param structuralObject the structural object to update
* @return the object API implementation
*/
- private AbstractUIObject update(StructuralObject structuralObject)
+ private UIContainerObject update(StructuralObject structuralObject)
{
- AbstractUIObject object = universe.get(structuralObject.getId());
+ UIContainerObject containerObject = universe.get(structuralObject.getId());
//
- if (object == null)
+ if (containerObject == null)
{
- //
- UIObjectContext context = new UIObjectContext(this, structuralObject);
+ containerObject = new UIObjectFactory().createObject(structuralObject.getState().getType());
//
- object = new UIObjectFactory().createObject(context);
+ containerObject.setContext(new UIObjectContext(this, structuralObject));
//
- universe.put(structuralObject.getId(), object);
+ universe.put(structuralObject.getId(), containerObject);
}
else
{
- object.context.structuralObject = structuralObject;
- object.parentRelationship.clear();
- object.childrenRelationship.clear();
+ UIObjectContext context = containerObject.getContext();
+
+ //
+ context.structuralObject = structuralObject;
+ context.managedObject.parentRelationship.clear();
+ context.managedObject.childrenRelationship.clear();
}
//
- return object;
+ return containerObject;
}
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-21 18:34:54 UTC (rev 9378)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-21 21:28:29 UTC (rev 9379)
@@ -49,6 +49,9 @@
/** . */
UIObject.Status status;
+ /** . */
+ UIManagedObject managedObject;
+
public UIObjectContext(UIObjectContainer container, StructuralObject structuralObject)
{
if (container == null)
@@ -64,20 +67,16 @@
this.container = container;
this.structuralObject = structuralObject;
this.status = UIObject.Status.VALID;
+ this.managedObject = new UIManagedObject(this);
}
// Public ***********************************************************************************************************
- public StructuralState getState()
+ public UIObject getManagedObject()
{
- return structuralObject.getState();
+ return managedObject;
}
- public UIContext getRoot()
- {
- return container.root;
- }
-
public UIObject getObject(String id)
{
return container.getObject(id, true);
@@ -88,12 +87,24 @@
container.addModelListener(listener);
}
- public UIObject.Status getStatus()
+ //
+
+ StructuralState getState()
{
+ return structuralObject.getState();
+ }
+
+ UIContext getRoot()
+ {
+ return container.root;
+ }
+
+ UIObject.Status getStatus()
+ {
return status;
}
- public boolean isValid()
+ boolean isValid()
{
return status == UIObject.Status.VALID;
}
Modified: 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-21 18:34:54 UTC (rev 9378)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java 2007-12-21 21:28:29 UTC (rev 9379)
@@ -27,6 +27,7 @@
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;
@@ -40,34 +41,59 @@
public class UIObjectFactory
{
- public AbstractUIObject createObject(UIObjectContext context)
+ public UIContainerObject createObject(Class<? extends UIObject> type)
{
- Class type = context.getState().getType();
-
- //
if(type == UIContext.class)
{
- return new UIContextImpl(context);
+ return new UIContextImpl();
}
else if(type == UIPortal.class)
{
- return new UIPortalImpl(context);
+ return new UIPortalImpl();
}
else if(type == UIPage.class)
{
- return new UIPageImpl(context);
+ return new UIPageImpl();
}
else if(type == UIContainer.class)
{
- return new UIContainerImpl(context);
+ return new UIContainerImpl();
}
else if(type == UIWindow.class)
{
- return new UIWindowImpl(context);
+ 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();
+// }
+// }
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java 2007-12-21 18:34:54 UTC (rev 9378)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java 2007-12-21 21:28:29 UTC (rev 9379)
@@ -28,7 +28,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-final class UIObjectManyToOne extends UIObjectRelationship<AbstractUIObject>
+final class UIObjectManyToOne extends UIObjectRelationship<UIContainerObject>
{
/** . */
@@ -39,12 +39,12 @@
this.owner = owner;
}
- protected AbstractUIObject doLoad()
+ protected UIContainerObject doLoad()
{
return owner.container.getParent(owner.structuralObject);
}
- protected void doEvict(AbstractUIObject abstractUIObject)
+ protected void doEvict(UIContainerObject abstractUIObject)
{
}
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java 2007-12-21 18:34:54 UTC (rev 9378)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java 2007-12-21 21:28:29 UTC (rev 9379)
@@ -29,7 +29,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-final class UIObjectOneToMany extends UIObjectRelationship<List<AbstractUIObject>>
+final class UIObjectOneToMany extends UIObjectRelationship<List<UIContainerObject>>
{
/** . */
@@ -39,7 +39,7 @@
private final UIObjectContext owner;
/** . */
- private List<AbstractUIObject> content;
+ private List<UIContainerObject> content;
UIObjectOneToMany(UIObjectContext object)
{
@@ -47,19 +47,19 @@
this.list = new ProxyList();
}
- protected List<AbstractUIObject> doLoad()
+ protected List<UIContainerObject> doLoad()
{
return list;
}
- protected void doEvict(List<AbstractUIObject> abstractUIObjects)
+ protected void doEvict(List<UIContainerObject> abstractUIObjects)
{
content = null;
}
- private class ProxyList extends AbstractList<AbstractUIObject>
+ private class ProxyList extends AbstractList<UIContainerObject>
{
- public AbstractUIObject get(int i)
+ public UIContainerObject get(int i)
{
if (!owner.isValid())
{
18 years, 4 months