Author: julien(a)jboss.com
Date: 2008-01-06 12:11:15 -0500 (Sun, 06 Jan 2008)
New Revision: 9441
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/LifeCycleEvent.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/ObjectAddedEvent.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/ObjectLifeCycleEvent.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/ObjectRemovedEvent.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/RelationshipAddedEvent.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/RelationshipLifeCycleEvent.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/RelationshipRemovedEvent.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventTestCase.java
Modified:
branches/presentation/presentation/build.xml
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/ManagedObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
more stuff related to eventing
Modified: branches/presentation/presentation/build.xml
===================================================================
--- branches/presentation/presentation/build.xml 2008-01-06 15:42:26 UTC (rev 9440)
+++ branches/presentation/presentation/build.xml 2008-01-06 17:11:15 UTC (rev 9441)
@@ -307,8 +307,9 @@
-->
</x-sysproperty>
<x-test>
+ <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.MockModelTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.ModelTestCase"/>
- <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.MockModelTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.presentation.test.model.EventTestCase"/>
</x-test>
<x-classpath>
<path refid="jboss.portal/modules/common.classpath"/>
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2008-01-06
15:42:26 UTC (rev 9440)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -133,4 +133,9 @@
{
context.getManagedObject().move(destination);
}
+
+ public String toString()
+ {
+ return context.getManagedObject().toString();
+ }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2008-01-06
15:42:26 UTC (rev 9440)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -30,12 +30,15 @@
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.model.state.structural.StructuralState;
import org.jboss.portal.presentation.impl.model.container.spi.UIContainerObject;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Collection;
+import java.io.StringWriter;
+import java.io.PrintWriter;
/**
* Implement base fonctionnality of the <code>UIObject</code> interface.
@@ -398,4 +401,11 @@
return false;
}
};
+
+ public String toString()
+ {
+ StructuralObject so = context.structuralObject;
+ StructuralState st = so.getState();
+ return "UIObject[id=" + so.getId() + ",name=" + st.getName() +
",type=" + st.getType().getSimpleName() + ",id=" + hashCode() +
"]";
+ }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java 2008-01-06
15:42:26 UTC (rev 9440)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/RelationshipContext.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -26,6 +26,8 @@
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.event.lifecycle.RelationshipAddedEvent;
+import org.jboss.portal.presentation.model.event.lifecycle.RelationshipRemovedEvent;
import java.util.Iterator;
import java.util.Set;
@@ -33,7 +35,7 @@
import java.util.Collection;
import java.util.AbstractSet;
import java.util.ArrayList;
-import java.util.Collections;
+import java.util.LinkedHashSet;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -89,24 +91,15 @@
private UIContainerObject related;
/** The context pointing at us via a OneToMany. */
- private Set<ObjectContext> refs;
+ private final Set<ObjectContext> refs;
- /** The refs field exposed in a non modifiable manner. */
- private Set<ObjectContext> readOnlyRefs;
-
private ManyToOne()
{
this.loaded = false;
this.related = null;
this.refs = new HashSet<ObjectContext>();
- this.readOnlyRefs = Collections.unmodifiableSet(refs);
}
- Set<ObjectContext> getReferences()
- {
- return readOnlyRefs;
- }
-
/**
* Returns true if the relationship is loaded
*
@@ -171,7 +164,7 @@
throw new IllegalStateException("Cannot clear parent of non loaded
association");
}
- // Downgrade realted
+ // Downgrade related
detach();
}
@@ -246,6 +239,14 @@
oneToMany.refs.add(owner);
this.related = related;
this.loaded = true;
+
+ // We need to broadcast an event maybe
+ ObjectContext relatedContext = oneToMany.getOwner();
+ if (!refs.contains(relatedContext))
+ {
+ RelationshipAddedEvent event = new
RelationshipAddedEvent(relatedContext.structuralObject.getId(),
owner.structuralObject.getId());
+ owner.container.fireEvent(event);
+ }
}
private void detach()
@@ -269,6 +270,14 @@
oneToMany.refs.remove(owner);
this.related = null;
this.loaded = false;
+
+ // We need to broadcast an event maybe
+ ObjectContext relatedContext = oneToMany.getOwner();
+ if (!refs.contains(relatedContext))
+ {
+ RelationshipRemovedEvent event = new
RelationshipRemovedEvent(relatedContext.structuralObject.getId(),
owner.structuralObject.getId());
+ owner.container.fireEvent(event);
+ }
}
/**
@@ -335,22 +344,18 @@
/** Indicates if the relationship is loaded. */
private boolean loaded;
- /** The related object. */
+ /** The related objects. */
private Set<UIContainerObject> relateds;
/** The contexts pointing at us via a ManyToOne. */
private Set<ObjectContext> refs;
- /** The refs field exposed in a non modifiable manner. */
- private Set<ObjectContext> readOnlyRefs;
-
private OneToMany()
{
this.set = new LazySet();
this.loaded = false;
- this.relateds = new HashSet<UIContainerObject>();
+ this.relateds = new LinkedHashSet<UIContainerObject>();
this.refs = new HashSet<ObjectContext>();
- this.readOnlyRefs = Collections.unmodifiableSet(refs);
}
boolean isLoaded()
@@ -432,9 +437,18 @@
return set;
}
- Set<ObjectContext> getReferences()
+ void clear()
{
- return readOnlyRefs;
+ if (!loaded)
+ {
+ throw new IllegalStateException("Cannot clear parent of non loaded
association");
+ }
+
+ // Detach relateds
+ for (UIContainerObject related : new
HashSet<UIContainerObject>(relateds))
+ {
+ detach(related);
+ }
}
/**
@@ -465,6 +479,14 @@
//
manyToOne.refs.remove(owner);
relateds.remove(related);
+
+ //
+ ObjectContext relatedContext = manyToOne.getOwner();
+ if (!refs.contains(relatedContext))
+ {
+ RelationshipRemovedEvent event = new
RelationshipRemovedEvent(owner.structuralObject.getId(),
relatedContext.structuralObject.getId());
+ owner.container.fireEvent(event);
+ }
}
private void attach(UIContainerObject related)
@@ -483,6 +505,14 @@
//
manyToOne.refs.add(owner);
relateds.add(related);
+
+ //
+ ObjectContext relatedContext = manyToOne.getOwner();
+ if (!refs.contains(relatedContext))
+ {
+ RelationshipAddedEvent event = new
RelationshipAddedEvent(owner.structuralObject.getId(),
relatedContext.structuralObject.getId());
+ owner.container.fireEvent(event);
+ }
}
private void load()
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 2008-01-06
15:42:26 UTC (rev 9440)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -214,13 +214,12 @@
//
for (String id : destruction.getIds())
{
- UIContainerObject destroyed = universe.remove(id);
+ UIContainerObject toDestroy = universe.get(id);
//
- if (destroyed != null)
+ if (toDestroy != null)
{
- ObjectContext destroyedContext = (ObjectContext)destroyed.getContext();
- destroyedContext.status = UIObject.Status.INVALID;
+ detach(toDestroy, false);
// Eventing
StateChange<StructuralStateModification> stateChange = new
StateChange<StructuralStateModification>(id, DESTRUCTION);
@@ -436,6 +435,9 @@
}
//
+ System.err.println("<" + context.getState().getName() +
">");
+
+ //
StructuralObject.Refresh refresh = null;
try
{
@@ -466,11 +468,11 @@
{
ObjectContext addedContext = (ObjectContext)added.getContext();
- // Find parent pointing at us and set as dirty
- for (ObjectContext addedParentContext :
addedContext.relationshipContext.parent.getReferences())
- {
- addedParentContext.status = UIObject.Status.STALE;
- }
+// // Find parent pointing at us and set as dirty
+// for (ObjectContext addedParentContext :
addedContext.relationshipContext.parent.getReferences())
+// {
+// addedParentContext.status = UIObject.Status.STALE;
+// }
// Update parent if it was loaded
if (addedContext.relationshipContext.parent.isLoaded())
@@ -486,6 +488,8 @@
attach(added);
}
+ System.err.println("added " + added.getName());
+
//
context.relationshipContext.children.addLoadedRelated(added);
}
@@ -508,7 +512,17 @@
UIContainerObject removed =
context.relationshipContext.children.removeLoadedRelated(removedId);
//
- detach(removed);
+ ObjectContext removedContext = (ObjectContext)removed.getContext();
+
+ //
+ System.err.println("want to remove " + removed.getName());
+
+ // We remove only if it's pointing at us
+ if (removedContext.relationshipContext.parent.isLoaded() &&
removedContext.relationshipContext.parent.getRelated() == object)
+ {
+ System.err.println("removed " + removed.getName());
+ detach(removed, true);
+ }
}
// Update state
@@ -526,29 +540,73 @@
}
}
+ System.err.println("</" + context.getState().getName() +
">");
+
//
scope.leaveObject(object);
}
}
+// void refresh(UIContainerObject object, UIObject.Visitor scope)
+// {
+// // First pass
+//
+//
+//
+// }
+
void attach(UIContainerObject object)
{
- universe.put(object.getId(), object);
+ String id = object.getId();
+
+ //
+ if (universe.containsKey(id))
+ {
+ throw new AssertionError("Duplicate put for id" + id);
+ }
+
+ //
+ universe.put(id, object);
+
+ //
+// ObjectContext context = (ObjectContext)object.getContext();
+// StructuralObject so = context.structuralObject;
+// StructuralState st = so.getState();
+// ObjectAddedEvent event = new ObjectAddedEvent(so.getId(), st.getName(),
st.getType(), st.getProperties());
+// fireEvent(event);
}
- void detach(UIContainerObject object)
+ void detach(UIContainerObject object, boolean cascade)
{
ObjectContext context = (ObjectContext)object.getContext();
//
- for (UIContainerObject child : context.relationshipContext.children.getRelateds())
+ if (cascade)
{
- detach(child);
+ for (UIContainerObject child :
context.relationshipContext.children.getRelateds())
+ {
+ detach(child, true);
+ }
}
//
+ if (context.relationshipContext.parent.isLoaded())
+ {
+ context.relationshipContext.parent.clear();
+ }
+ if (context.relationshipContext.children.isLoaded())
+ {
+ context.relationshipContext.children.clear();
+ }
+
+ //
context.status = UIObject.Status.INVALID;
universe.remove(object.getId());
+
+ //
+// StructuralObject so = context.structuralObject;
+// ObjectRemovedEvent event = new ObjectRemovedEvent(so.getId());
+// fireEvent(event);
}
UIContainerObject get(String id)
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/LifeCycleEvent.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/LifeCycleEvent.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/LifeCycleEvent.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -0,0 +1,33 @@
+/******************************************************************************
+ * 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.model.event.lifecycle;
+
+import org.jboss.portal.presentation.model.ModelEvent;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class LifeCycleEvent extends ModelEvent
+{
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/ObjectAddedEvent.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/ObjectAddedEvent.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/ObjectAddedEvent.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -0,0 +1,83 @@
+/******************************************************************************
+ * 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.model.event.lifecycle;
+
+import org.jboss.portal.presentation.model.UIObject;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ObjectAddedEvent extends ObjectLifeCycleEvent
+{
+
+ /** . */
+ private final String name;
+
+ /** . */
+ private final Class<? extends UIObject> type;
+
+ /** . */
+ private final Map<String, String> properties;
+
+ public ObjectAddedEvent(String objectId, String name, Class<? extends UIObject>
type, Map<String, String> properties)
+ {
+ super(objectId);
+
+ //
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (type == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (properties == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.name = name;
+ this.type = type;
+ this.properties = properties;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Class<? extends UIObject> getType()
+ {
+ return type;
+ }
+
+ public Map<String, String> getProperties()
+ {
+ return properties;
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/ObjectLifeCycleEvent.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/ObjectLifeCycleEvent.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/ObjectLifeCycleEvent.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -0,0 +1,50 @@
+/******************************************************************************
+ * 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.model.event.lifecycle;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class ObjectLifeCycleEvent extends LifeCycleEvent
+{
+
+ /** . */
+ private final String objectId;
+
+ public ObjectLifeCycleEvent(String objectId)
+ {
+ if (objectId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.objectId = objectId;
+ }
+
+ public String getObjectId()
+ {
+ return objectId;
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/ObjectRemovedEvent.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/ObjectRemovedEvent.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/ObjectRemovedEvent.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * 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.model.event.lifecycle;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ObjectRemovedEvent extends ObjectLifeCycleEvent
+{
+ public ObjectRemovedEvent(String objectId)
+ {
+ super(objectId);
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/RelationshipAddedEvent.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/RelationshipAddedEvent.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/RelationshipAddedEvent.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * 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.model.event.lifecycle;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class RelationshipAddedEvent extends RelationshipLifeCycleEvent
+{
+ public RelationshipAddedEvent(String parentId, String childId)
+ {
+ super(parentId, childId);
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/RelationshipLifeCycleEvent.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/RelationshipLifeCycleEvent.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/RelationshipLifeCycleEvent.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -0,0 +1,63 @@
+/******************************************************************************
+ * 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.model.event.lifecycle;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class RelationshipLifeCycleEvent extends LifeCycleEvent
+{
+
+ /** . */
+ private final String parentId;
+
+ /** . */
+ private final String childId;
+
+ public RelationshipLifeCycleEvent(String parentId, String childId)
+ {
+ if (parentId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (childId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.parentId = parentId;
+ this.childId = childId;
+ }
+
+ public String getParentId()
+ {
+ return parentId;
+ }
+
+ public String getChildId()
+ {
+ return childId;
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/RelationshipRemovedEvent.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/RelationshipRemovedEvent.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/lifecycle/RelationshipRemovedEvent.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * 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.model.event.lifecycle;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class RelationshipRemovedEvent extends RelationshipLifeCycleEvent
+{
+ public RelationshipRemovedEvent(String parentId, String childId)
+ {
+ super(parentId, childId);
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/AbstractModelTestCase.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -0,0 +1,88 @@
+/******************************************************************************
+ * 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.test.model;
+
+import org.jboss.portal.presentation.test.model.state.structural.MockModel;
+import org.jboss.portal.presentation.test.model.state.structural.MockModelImpl;
+import org.jboss.portal.presentation.model.UIContext;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
+import
org.jboss.portal.presentation.impl.model.state.navigational.NavigationalStateContextImpl;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class AbstractModelTestCase extends TestCase
+{
+
+ /** . */
+ protected MockModel model;
+
+ public AbstractModelTestCase()
+ {
+ }
+
+ public AbstractModelTestCase(String testName)
+ {
+ super(testName);
+ }
+
+ protected void setUp() throws Exception
+ {
+ this.model = new MockModelImpl();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ this.model = null;
+ }
+
+ protected final UIContext createContext()
+ {
+ return new UIObjectContainer(model.getStructuralStateContext(), new
NavigationalStateContextImpl()).getRoot();
+ }
+
+ protected final void resetModel()
+ {
+ this.model = new MockModelImpl();
+ }
+
+ protected static final UIObject.Visitor CRAWLER = new UIObject.Visitor()
+ {
+ public boolean enterObject(UIObject object)
+ {
+ return true;
+ }
+
+ public void leaveObject(UIObject object)
+ {
+ }
+
+ public boolean enterChildren(UIObject object, boolean loaded)
+ {
+ return loaded;
+ }
+ };
+}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java 2008-01-06
15:42:26 UTC (rev 9440)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -80,6 +80,14 @@
Assert.assertEquals(sp.getProperties(), mod.getProperties());
}
+ public void next(String targetId, StructuralStateModification.Destruction sp)
+ {
+ StateChangeEvent ste = next(StateChangeEvent.class);
+ StateChange change = ste.getChange();
+ Assert.assertEquals(targetId, change.getTargetId());
+ StructuralStateModification.Destruction mod =
(StructuralStateModification.Destruction)change.getModification();
+ }
+
public void next(String targetId, NavigationalStateModification ns)
{
StateChangeEvent ste = next(StateChangeEvent.class);
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventTestCase.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventTestCase.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -0,0 +1,79 @@
+/******************************************************************************
+ * 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.test.model;
+
+import org.jboss.portal.presentation.model.UIContext;
+import org.jboss.portal.presentation.model.UIPortal;
+import org.jboss.portal.presentation.model.UIObject;
+import
org.jboss.portal.presentation.model.event.state.structural.StructuralStateModification;
+import org.jboss.portal.presentation.model.event.lifecycle.RelationshipAddedEvent;
+import org.jboss.portal.presentation.model.event.lifecycle.RelationshipRemovedEvent;
+
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class EventTestCase extends AbstractModelTestCase
+{
+
+ public EventTestCase()
+ {
+ }
+
+ public void testCreateChildEvents()
+ {
+ UIContext context = createContext();
+ context.getChildren().size();
+
+ EventAssert eventAssert = new EventAssert();
+ context.addModelListener(eventAssert);
+
+ //
+ UIObject foo = context.createChild("foo", UIPortal.class);
+ String fooId = foo.getId();
+
+ //
+ eventAssert.next(RelationshipAddedEvent.class);
+ eventAssert.next(fooId, new StructuralStateModification.Creation(UIPortal.class,
"foo", new HashMap<String, String>()));
+ }
+
+ public void testDestroyChildEvents()
+ {
+ UIContext context = createContext();
+ UIObject foo = context.createChild("foo", UIPortal.class);
+ String fooId = foo.getId();
+ context.getChildren().size();
+
+ EventAssert eventAssert = new EventAssert();
+ context.addModelListener(eventAssert);
+
+ //
+ context.destroyChild("foo");
+
+ //
+ eventAssert.next(RelationshipRemovedEvent.class);
+ eventAssert.next(fooId, new StructuralStateModification.Destruction());
+ }
+}
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 2008-01-06
15:42:26 UTC (rev 9440)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2008-01-06
17:11:15 UTC (rev 9441)
@@ -23,22 +23,18 @@
package org.jboss.portal.presentation.test.model;
import junit.framework.Assert;
-import junit.framework.TestCase;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
-import
org.jboss.portal.presentation.impl.model.state.navigational.NavigationalStateContextImpl;
import org.jboss.portal.presentation.model.StateType;
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIPage;
import org.jboss.portal.presentation.model.UIPortal;
import
org.jboss.portal.presentation.model.event.state.structural.StructuralStateModification;
+import org.jboss.portal.presentation.model.event.lifecycle.RelationshipAddedEvent;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
import org.jboss.portal.presentation.model.state.StaleStateException;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
-import org.jboss.portal.presentation.test.model.state.structural.MockModel;
import org.jboss.portal.presentation.test.model.state.structural.MockObject;
import org.jboss.portal.presentation.test.model.state.structural.MockException;
-import org.jboss.portal.presentation.test.model.state.structural.MockModelImpl;
import org.jboss.portal.common.util.Tools;
import java.util.Collections;
@@ -49,39 +45,11 @@
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
*/
-public class ModelTestCase extends TestCase
+public class ModelTestCase extends AbstractModelTestCase
{
- /** . */
- private MockModel model;
-
- public ModelTestCase()
- {
- }
-
- public ModelTestCase(String testName)
- {
- super(testName);
- }
-
- /**
- *
- */
- protected void setUp() throws Exception
- {
- this.model = new MockModelImpl();
- }
-
- /**
- *
- */
- protected void tearDown() throws Exception
- {
- this.model = null;
- }
-
public void testUIContextParentIsNull()
{
UIContext context = createContext();
@@ -113,11 +81,6 @@
}
}
- private UIContext createContext()
- {
- return new UIObjectContainer(model.getStructuralStateContext(), new
NavigationalStateContextImpl()).getRoot();
- }
-
public void testGetPropertyThrowsIAE()
{
UIContext context = createContext();
@@ -794,11 +757,29 @@
public void testPartialRefreshAfterConcurrentMove() throws Exception
{
MockObject mockRoot = model.getRoot();
-
MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
MockObject mockBar = mockRoot.addChild("bar", MockObject.Type.PORTAL);
MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+ //
+ doTestPartialRefreshAfterConcurrentMove(true);
+
+ //
+ resetModel();
+
+ //
+ mockRoot = model.getRoot();
+ mockBar = mockRoot.addChild("bar", MockObject.Type.PORTAL);
+ mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+
+ //
+ doTestPartialRefreshAfterConcurrentMove(false);
+ }
+
+ public void doTestPartialRefreshAfterConcurrentMove(boolean bilto) throws Exception
+ {
+
// Load fully the context 1
UIContext context1 = createContext();
loadSubTree(context1);
@@ -820,33 +801,52 @@
UIObject juu3 = foo3.getChild("juu");
UIObject bar3 = context3.getChild("bar");
+ // Load fully the context 4
+ UIContext context4 = createContext();
+ loadSubTree(context4);
+ UIObject foo4 = context4.getChild("foo");
+ UIObject juu4 = foo4.getChild("juu");
+ UIObject bar4 = context4.getChild("bar");
+ String juu4id = juu4.getId();
+
// Concurrent move
UIContext context = createContext();
context.getChild("foo").getChild("juu").move(context.getChild("bar"));
//
+ System.err.println("-------------");
foo1.refresh(CRAWLER);
assertEquals(UIObject.Status.VALID, foo1.getStatus());
assertEquals(0, foo1.getChildren().size());
//
bar2.refresh(CRAWLER);
- assertEquals(UIObject.Status.STALE, foo2.getStatus());
+ assertEquals(UIObject.Status.VALID, foo2.getStatus());
assertEquals(UIObject.Status.VALID, bar2.getStatus());
assertEquals(Tools.toSet(juu2), new HashSet<UIObject>(bar2.getChildren()));
assertEquals(bar2, juu2.getParent());
//
+ System.err.println("bilto = " + bilto);
context3.refresh(CRAWLER);
assertEquals(UIObject.Status.VALID, foo3.getStatus());
assertEquals(UIObject.Status.VALID, bar3.getStatus());
+ if (bilto)
+ {
+ assertEquals(UIObject.Status.INVALID, juu3.getStatus());
+ juu3 = context3.getObject(juu4id);
+ }
+ assertEquals(UIObject.Status.VALID, juu3.getStatus());
assertEquals(Tools.toSet(juu3), new HashSet<UIObject>(bar3.getChildren()));
+
+ //
}
private void loadSubTree(UIObject object)
{
for (UIObject child : object.getChildren())
{
+ child.getParent();
loadSubTree(child);
}
}
@@ -884,21 +884,20 @@
assertEquals(Tools.toSet(barDaa, fooJuu), new
HashSet<UIObject>(barChildren));
}
- private static final UIObject.Visitor CRAWLER = new UIObject.Visitor()
+ public void testBlah() throws Exception
{
- public boolean enterObject(UIObject object)
- {
- return true;
- }
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockBar = mockRoot.addChild("bar", MockObject.Type.PORTAL);
- public void leaveObject(UIObject object)
- {
- }
+ EventAssert blah = new EventAssert();
- public boolean enterChildren(UIObject object, boolean loaded)
- {
- return loaded;
- }
- };
+ UIContext context = createContext();
+ context.addModelListener(blah);
+ UIObject foo = context.getObject(mockFoo.getId());
+ blah.assertEmpty();
+ foo.getParent();
+ blah.next(RelationshipAddedEvent.class);
+ }
}