JBoss Portal SVN: r9378 - 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 13:34:54 -0500 (Fri, 21 Dec 2007)
New Revision: 9378
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/UIObjectList.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRef.java
Modified:
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/UIObjectContainer.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:
rename association -> relationship
Modified: 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 18:20:47 UTC (rev 9377)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-21 18:34:54 UTC (rev 9378)
@@ -54,10 +54,10 @@
protected final UIObjectContext context;
/** . */
- final UIObjectOneToMany childrenAssociation;
+ final UIObjectOneToMany childrenRelationship;
/** . */
- final UIObjectManyToOne parentAssociation;
+ final UIObjectManyToOne parentRelationship;
public AbstractUIObject(UIObjectContext context)
{
@@ -68,8 +68,8 @@
//
this.context = context;
- this.childrenAssociation = new UIObjectOneToMany(context);
- this.parentAssociation = new UIObjectManyToOne(context);
+ this.childrenRelationship = new UIObjectOneToMany(context);
+ this.parentRelationship = new UIObjectManyToOne(context);
}
// UIObject interface implementation-----------------------------------------------------------------------------------------------------------------------------
@@ -297,7 +297,7 @@
}
//
- return parentAssociation.get();
+ return parentRelationship.get();
}
public final List<AbstractUIObject> getChildren()
@@ -308,7 +308,7 @@
}
//
- return childrenAssociation.get();
+ return childrenRelationship.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 18:20:47 UTC (rev 9377)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-21 18:34:54 UTC (rev 9378)
@@ -29,7 +29,6 @@
import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
-import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
import org.jboss.portal.presentation.impl.model.UIContextImpl;
@@ -356,8 +355,8 @@
else
{
object.context.structuralObject = structuralObject;
- object.parentAssociation.clear();
- object.childrenAssociation.clear();
+ object.parentRelationship.clear();
+ object.childrenRelationship.clear();
}
//
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java 2007-12-21 18:20:47 UTC (rev 9377)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java 2007-12-21 18:34:54 UTC (rev 9378)
@@ -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;
-
-import org.jboss.portal.presentation.model.UIObject;
-
-import java.util.AbstractList;
-import java.util.List;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-final class UIObjectList extends AbstractList<AbstractUIObject>
-{
-
- /** . */
- private List<AbstractUIObject> content;
-
- /** . */
- private final AbstractUIObject object;
-
- UIObjectList(AbstractUIObject object)
- {
- this.object = object;
- this.content = null;
- }
-
- public AbstractUIObject get(int i)
- {
- if (!object.context.isValid())
- {
- throw new IllegalStateException("Relationship not valid");
- }
- if (content == null)
- {
- content = object.context.container.getChildren(object.context.structuralObject);
- }
- return content.get(i);
- }
-
- public int size()
- {
- if (!object.context.isValid())
- {
- throw new IllegalStateException("Relationship not valid");
- }
- if (content == null)
- {
- content = object.context.container.getChildren(object.context.structuralObject);
- }
- return content.size();
- }
-
- void reset()
- {
- content = null;
- }
-}
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:20:47 UTC (rev 9377)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java 2007-12-21 18:34:54 UTC (rev 9378)
@@ -28,7 +28,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-final class UIObjectManyToOne extends UIObjectAssociation<AbstractUIObject>
+final class UIObjectManyToOne extends UIObjectRelationship<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:20:47 UTC (rev 9377)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java 2007-12-21 18:34:54 UTC (rev 9378)
@@ -29,7 +29,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-final class UIObjectOneToMany extends UIObjectAssociation<List<AbstractUIObject>>
+final class UIObjectOneToMany extends UIObjectRelationship<List<AbstractUIObject>>
{
/** . */
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRef.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRef.java 2007-12-21 18:20:47 UTC (rev 9377)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRef.java 2007-12-21 18:34:54 UTC (rev 9378)
@@ -1,51 +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 UIObjectRef
-{
-
- /** . */
- AbstractUIObject object;
-
- /** . */
- boolean loaded;
-
- UIObjectRef()
- {
- object = null;
- loaded = false;
- }
-
- void reset()
- {
- loaded = false;
- object = null;
- }
-}
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java (from rev 9377, 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/UIObjectRelationship.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java 2007-12-21 18:34:54 UTC (rev 9378)
@@ -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.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);
+}
16 years, 4 months
JBoss Portal SVN: r9377 - 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 13:20:47 -0500 (Fri, 21 Dec 2007)
New Revision: 9377
Added:
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/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/AbstractUIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
Log:
encapsulate state management of relationship into the object
Modified: 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 17:29:47 UTC (rev 9376)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-21 18:20:47 UTC (rev 9377)
@@ -22,7 +22,6 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.model.container;
-import org.jboss.portal.common.NotYetImplemented;
import org.jboss.portal.presentation.model.StateType;
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.event.state.StateChange;
@@ -38,7 +37,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.BitSet;
/**
* Implement base fonctionnality of the <code>UIObject</code> interface.
@@ -56,10 +54,10 @@
protected final UIObjectContext context;
/** . */
- final UIObjectList children;
+ final UIObjectOneToMany childrenAssociation;
/** . */
- final UIObjectRef parent;
+ final UIObjectManyToOne parentAssociation;
public AbstractUIObject(UIObjectContext context)
{
@@ -70,8 +68,8 @@
//
this.context = context;
- this.children = new UIObjectList(this);
- this.parent = new UIObjectRef();
+ this.childrenAssociation = new UIObjectOneToMany(context);
+ this.parentAssociation = new UIObjectManyToOne(context);
}
// UIObject interface implementation-----------------------------------------------------------------------------------------------------------------------------
@@ -299,14 +297,7 @@
}
//
- if (!parent.loaded)
- {
- parent.object = context.container.getParent(context.structuralObject);
- parent.loaded = true;
- }
-
- //
- return parent.object;
+ return parentAssociation.get();
}
public final List<AbstractUIObject> getChildren()
@@ -317,7 +308,7 @@
}
//
- return children;
+ return childrenAssociation.get();
}
public final <T extends UIObject> T createChild(String name, Class<T> type) throws IllegalArgumentException
Added: 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 (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectAssociation.java 2007-12-21 18:20:47 UTC (rev 9377)
@@ -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.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 17:29:47 UTC (rev 9376)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-21 18:20:47 UTC (rev 9377)
@@ -24,21 +24,13 @@
import org.jboss.portal.presentation.model.ModelEvent;
import org.jboss.portal.presentation.model.ModelListener;
-import org.jboss.portal.presentation.model.UIContainer;
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.UIWindow;
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
-import org.jboss.portal.presentation.impl.model.UIPortalImpl;
-import org.jboss.portal.presentation.impl.model.UIPageImpl;
-import org.jboss.portal.presentation.impl.model.UIContainerImpl;
-import org.jboss.portal.presentation.impl.model.UIWindowImpl;
import org.jboss.portal.presentation.impl.model.UIContextImpl;
import java.util.ArrayList;
@@ -261,32 +253,32 @@
void validate(AbstractUIObject 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.children)
- {
- validate(child, scope);
- }
- }
- }
-
- //
- scope.leaveObject(object);
- }
+// 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);
+// }
}
void refresh(AbstractUIObject object, UIObject.Visitor scope)
@@ -364,8 +356,8 @@
else
{
object.context.structuralObject = structuralObject;
- object.parent.reset();
- object.children.reset();
+ object.parentAssociation.clear();
+ object.childrenAssociation.clear();
}
//
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java (from rev 9366, branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRef.java)
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java 2007-12-21 18:20:47 UTC (rev 9377)
@@ -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.impl.model.container;
+
+/**
+ * A lazy reference.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+final class UIObjectManyToOne extends UIObjectAssociation<AbstractUIObject>
+{
+
+ /** . */
+ private final UIObjectContext owner;
+
+ UIObjectManyToOne(UIObjectContext owner)
+ {
+ this.owner = owner;
+ }
+
+ protected AbstractUIObject doLoad()
+ {
+ return owner.container.getParent(owner.structuralObject);
+ }
+
+ protected void doEvict(AbstractUIObject abstractUIObject)
+ {
+ }
+}
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java (from rev 9366, branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java)
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java 2007-12-21 18:20:47 UTC (rev 9377)
@@ -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.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 extends UIObjectAssociation<List<AbstractUIObject>>
+{
+
+ /** . */
+ private final ProxyList list;
+
+ /** . */
+ private final UIObjectContext owner;
+
+ /** . */
+ private List<AbstractUIObject> content;
+
+ UIObjectOneToMany(UIObjectContext object)
+ {
+ this.owner = object;
+ this.list = new ProxyList();
+ }
+
+ protected List<AbstractUIObject> doLoad()
+ {
+ return list;
+ }
+
+ protected void doEvict(List<AbstractUIObject> abstractUIObjects)
+ {
+ content = null;
+ }
+
+ private class ProxyList extends AbstractList<AbstractUIObject>
+ {
+ public AbstractUIObject get(int i)
+ {
+ if (!owner.isValid())
+ {
+ throw new IllegalStateException("Relationship not valid");
+ }
+ if (content == null)
+ {
+ content = owner.container.getChildren(owner.structuralObject);
+ }
+ return content.get(i);
+ }
+
+ public int size()
+ {
+ if (!owner.isValid())
+ {
+ throw new IllegalStateException("Relationship not valid");
+ }
+ if (content == null)
+ {
+ content = owner.container.getChildren(owner.structuralObject);
+ }
+ return content.size();
+ }
+ }
+}
16 years, 4 months
JBoss Portal SVN: r9376 - branches/presentation/presentation/src/main/org/jboss/portal/presentation/model.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-21 12:29:47 -0500 (Fri, 21 Dec 2007)
New Revision: 9376
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/StateScopeType.java
Log:
remove non removed class
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/StateScopeType.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/StateScopeType.java 2007-12-21 16:35:15 UTC (rev 9375)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/StateScopeType.java 2007-12-21 17:29:47 UTC (rev 9376)
@@ -1,42 +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.model;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public enum StateScopeType
-{
- /**
- * The navigational scope type. The navigational scope describe the a kind of change done at runtime by the user when it
- * interacts with the model (i.e not all interactions with the model are automatically navigational state changes).
- */
- NAVIGATIONAL,
-
- /**
- * The structural scope type. The structural scope describe the structure of the model, i.e it defines an enduring
- * state managed by the presentation server.
- */
- STRUCTURAL
-}
16 years, 4 months
JBoss Portal SVN: r9374 - 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-19 19:11:07 -0500 (Wed, 19 Dec 2007)
New Revision: 9374
Modified:
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/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/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
Log:
starting the refresh implementation
Modified: 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-19 14:12:30 UTC (rev 9373)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-20 00:11:07 UTC (rev 9374)
@@ -38,6 +38,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.BitSet;
/**
* Implement base fonctionnality of the <code>UIObject</code> interface.
@@ -75,7 +76,7 @@
// UIObject interface implementation-----------------------------------------------------------------------------------------------------------------------------
- public String getId()
+ public final String getId()
{
return context.structuralObject.getId();
}
@@ -109,39 +110,36 @@
}
}
- public Status getStatus()
+ public final Status getStatus()
{
return context.status;
}
- public void validate()
+ protected final boolean isModifiable()
{
- try
- {
- context.container.structuralStateContext.validate(context.structuralObject);
- }
- catch (StateException e)
- {
- context.updateStatus(e);
- }
+ return true;
}
- public void refresh()
+ public void validate(Visitor scope)
{
- switch (context.status)
- {
- case STALE:
- // Todo :-)
- throw new NotYetImplemented();
- case INVALID:
- // Cannot be resolved
- throw new IllegalStateException();
- case VALID:
- // Nothing to do
- break;
- }
+ 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())
@@ -175,12 +173,12 @@
return safeCast(value, propertyType);
}
- public Object getProperty(StateType stateType, String propertyName)
+ public final Object getProperty(StateType stateType, String propertyName)
{
return getProperty(stateType, propertyName, Object.class);
}
- public <T> void setProperty(StateType stateType, String propertyName, T propertyValue) throws StateChangeVetoException
+ public final <T> void setProperty(StateType stateType, String propertyName, T propertyValue) throws StateChangeVetoException
{
if (!context.isValid())
{
@@ -194,6 +192,10 @@
{
throw new IllegalArgumentException();
}
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
//
String id = getId();
@@ -254,7 +256,7 @@
}
}
- public AbstractUIObject getChild(String name)
+ public final AbstractUIObject getChild(String name)
{
if (!context.isValid())
{
@@ -278,7 +280,7 @@
return null;
}
- public String getName()
+ public final String getName()
{
if (!context.isValid())
{
@@ -318,12 +320,16 @@
return children;
}
- public <T extends UIObject> T createChild(String name, Class<T> type) throws IllegalArgumentException
+ 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;
@@ -355,7 +361,7 @@
return type.cast(context.getObject(child.getId()));
}
- public void destroyChild(String name) throws IllegalArgumentException, StateException
+ public final void destroyChild(String name) throws IllegalArgumentException, StateException
{
if (!context.isValid())
{
@@ -365,6 +371,10 @@
{
throw new IllegalArgumentException();
}
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
// Get the named child
AbstractUIObject namedChild = getChild(name);
@@ -382,12 +392,16 @@
context.container.update(destruction);
}
- public void move(UIObject destination) throws IllegalArgumentException, StateException
+ 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)
@@ -409,4 +423,24 @@
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-19 14:12:30 UTC (rev 9373)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-20 00:11:07 UTC (rev 9374)
@@ -33,6 +33,8 @@
import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.NoSuchStateException;
import org.jboss.portal.presentation.impl.model.UIPortalImpl;
import org.jboss.portal.presentation.impl.model.UIPageImpl;
import org.jboss.portal.presentation.impl.model.UIContainerImpl;
@@ -257,6 +259,83 @@
}
}
+ void validate(AbstractUIObject 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.children)
+ {
+ validate(child, scope);
+ }
+ }
+ }
+
+ //
+ scope.leaveObject(object);
+ }
+ }
+
+ void refresh(AbstractUIObject object, UIObject.Visitor scope)
+ {
+
+
+ if (scope.enterObject(object))
+ {
+ switch (object.context.status)
+ {
+ case VALID:
+ case STALE:
+ try
+ {
+ StructuralObject.Refresh refresh = structuralStateContext.refresh(object.context.structuralObject);
+
+ // Update the structural state
+ object.context.structuralObject = refresh.getObject();
+
+ // Notify removals
+ refresh.getRemovedChildren();
+
+ // Notify additions
+ refresh.getAddedChildren();
+
+ //
+ refresh.getValidChildren();
+
+ // Notify refresh
+ refresh.getStaleChildren();
+ }
+ catch (NoSuchStateException e)
+ {
+ object.context.status = UIObject.Status.INVALID;
+ }
+
+ //
+ break;
+ case INVALID:
+ throw new IllegalStateException();
+ }
+
+ //
+
+ //
+ scope.leaveObject(object);
+ }
+ }
+
// Private **********************************************************************************************************
/**
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-19 14:12:30 UTC (rev 9373)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-20 00:11:07 UTC (rev 9374)
@@ -115,10 +115,4 @@
throw new AssertionError(e);
}
}
-
- void invalidate()
- {
- status = UIObject.Status.INVALID;
- }
-
}
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-19 14:12:30 UTC (rev 9373)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-20 00:11:07 UTC (rev 9374)
@@ -55,11 +55,24 @@
STALE
}
+ public interface Visitor
+ {
+
+ boolean enterObject(UIObject object);
+
+ void leaveObject(UIObject object);
+
+ boolean enterChildren(UIObject object);
+
+ }
+
/**
* Updates the status of the object by comparing validating it against the structural state context.
*/
void validate();
+ void validate(Visitor scope);
+
/**
* Attempt a resolution of the current conflict. The behavior of the method will change according to the
* current status of the object:
@@ -72,6 +85,8 @@
*/
void refresh();
+ void refresh(Visitor scope);
+
/**
* Return the current status.
*
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-19 14:12:30 UTC (rev 9373)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-20 00:11:07 UTC (rev 9374)
@@ -25,6 +25,7 @@
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.NoSuchStateException;
import java.util.List;
import java.util.Map;
@@ -85,6 +86,15 @@
*/
void validate(StructuralObject object) throws IllegalArgumentException, StateException;
+ /**
+ * Attempt to return an object that contains the difference between the provided object
+ * and the up to date object.
+ *
+ * @param object the object to refresh
+ * @return the refresh
+ * @throws IllegalArgumentException if the object argument is null
+ * @throws StateException if the object cannot be refreshed
+ */
StructuralObject.Refresh refresh(StructuralObject object) throws IllegalArgumentException, StateException;
/**
16 years, 4 months
JBoss Portal SVN: r9373 - 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-19 09:12:30 -0500 (Wed, 19 Dec 2007)
New Revision: 9373
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
Log:
introduce factory for getting implementation of model classes
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-19 12:49:13 UTC (rev 9372)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-19 14:12:30 UTC (rev 9373)
@@ -273,9 +273,13 @@
//
if (object == null)
{
- object = createObject(structuralObject);
+ //
+ UIObjectContext context = new UIObjectContext(this, structuralObject);
//
+ object = new UIObjectFactory().createObject(context);
+
+ //
universe.put(structuralObject.getId(), object);
}
else
@@ -289,37 +293,4 @@
return object;
}
- private AbstractUIObject createObject(StructuralObject state)
- {
- Class type = state.getState().getType();
-
- //
- UIObjectContext context = new UIObjectContext(this, state);
-
- //
- if(type == UIContext.class)
- {
- return new UIContextImpl(context);
- }
- else if(type == UIPortal.class)
- {
- return new UIPortalImpl(context);
- }
- else if(type == UIPage.class)
- {
- return new UIPageImpl(context);
- }
- else if(type == UIContainer.class)
- {
- return new UIContainerImpl(context);
- }
- else if(type == UIWindow.class)
- {
- return new UIWindowImpl(context);
- }
- else
- {
- throw new AssertionError();
- }
- }
}
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-19 12:49:13 UTC (rev 9372)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-19 14:12:30 UTC (rev 9373)
@@ -23,6 +23,7 @@
package org.jboss.portal.presentation.impl.model.container;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.model.state.structural.StructuralState;
import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
import org.jboss.portal.presentation.model.state.StaleStateException;
@@ -67,6 +68,11 @@
// Public ***********************************************************************************************************
+ public StructuralState getState()
+ {
+ return structuralObject.getState();
+ }
+
public UIContext getRoot()
{
return container.root;
Added: 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 (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java 2007-12-19 14:12:30 UTC (rev 9373)
@@ -0,0 +1,73 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.impl.model.container;
+
+import org.jboss.portal.presentation.model.UIContext;
+import org.jboss.portal.presentation.model.UIPortal;
+import org.jboss.portal.presentation.model.UIPage;
+import org.jboss.portal.presentation.model.UIContainer;
+import org.jboss.portal.presentation.model.UIWindow;
+import org.jboss.portal.presentation.impl.model.UIContextImpl;
+import org.jboss.portal.presentation.impl.model.UIPortalImpl;
+import org.jboss.portal.presentation.impl.model.UIPageImpl;
+import org.jboss.portal.presentation.impl.model.UIContainerImpl;
+import org.jboss.portal.presentation.impl.model.UIWindowImpl;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UIObjectFactory
+{
+
+ public AbstractUIObject createObject(UIObjectContext context)
+ {
+ Class type = context.getState().getType();
+
+ //
+ if(type == UIContext.class)
+ {
+ return new UIContextImpl(context);
+ }
+ else if(type == UIPortal.class)
+ {
+ return new UIPortalImpl(context);
+ }
+ else if(type == UIPage.class)
+ {
+ return new UIPageImpl(context);
+ }
+ else if(type == UIContainer.class)
+ {
+ return new UIContainerImpl(context);
+ }
+ else if(type == UIWindow.class)
+ {
+ return new UIWindowImpl(context);
+ }
+ else
+ {
+ throw new AssertionError();
+ }
+ }
+}
16 years, 4 months
JBoss Portal SVN: r9372 - in branches/presentation: core-presentation/src/main/org/jboss/portal/core/presentation/server and 6 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-19 07:49:13 -0500 (Wed, 19 Dec 2007)
New Revision: 9372
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/StateType.java
Modified:
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/server/MainProcessor.java
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/server/content/PresentationContentRendererContext.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/AbstractUIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
NYI implementation of refresh operation in the portal object structural state context impl that was preventing compilation
Modified: branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java
===================================================================
--- branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java 2007-12-19 12:41:36 UTC (rev 9371)
+++ branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java 2007-12-19 12:49:13 UTC (rev 9372)
@@ -30,6 +30,7 @@
import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.structural.AbstractStructuralStateContext;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.common.NotYetImplemented;
import java.util.ArrayList;
import java.util.Collection;
@@ -90,6 +91,11 @@
}
}
+ public StructuralObject.Refresh refresh(StructuralObject object) throws IllegalArgumentException, StateException
+ {
+ throw new NotYetImplemented();
+ }
+
/**
*
*/
Modified: branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/server/MainProcessor.java
===================================================================
--- branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/server/MainProcessor.java 2007-12-19 12:41:36 UTC (rev 9371)
+++ branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/server/MainProcessor.java 2007-12-19 12:49:13 UTC (rev 9372)
@@ -45,7 +45,7 @@
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
import org.jboss.portal.portlet.invocation.response.RenderResponse;
import org.jboss.portal.presentation.client.PresentationContext;
-import org.jboss.portal.presentation.model.StateScopeType;
+import org.jboss.portal.presentation.model.StateType;
import org.jboss.portal.presentation.model.UIWindow;
import org.jboss.portal.presentation.protocol.ErrorResponse;
import org.jboss.portal.presentation.protocol.LinkActivation;
@@ -254,7 +254,7 @@
{
uiWindow.setMode(mode);
}
- uiWindow.setProperty(StateScopeType.NAVIGATIONAL, "content", contentState);
+ uiWindow.setProperty(StateType.NAVIGATIONAL, "content", contentState);
response = new ShowUIObjectResponse(window.getPage().getId().toString(PortalObjectPath.CANONICAL_FORMAT));
}
}
Modified: branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/server/content/PresentationContentRendererContext.java
===================================================================
--- branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/server/content/PresentationContentRendererContext.java 2007-12-19 12:41:36 UTC (rev 9371)
+++ branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/server/content/PresentationContentRendererContext.java 2007-12-19 12:49:13 UTC (rev 9372)
@@ -37,7 +37,7 @@
import org.jboss.portal.portlet.impl.spi.AbstractUserContext;
import org.jboss.portal.portlet.invocation.RenderInvocation;
import org.jboss.portal.presentation.client.PresentationContext;
-import org.jboss.portal.presentation.model.StateScopeType;
+import org.jboss.portal.presentation.model.StateType;
import org.jboss.portal.presentation.model.UIWindow;
/**
@@ -83,7 +83,7 @@
windowState = WindowState.NORMAL;
}
- StateString contentState = (StateString)uiwindow.getProperty(StateScopeType.NAVIGATIONAL, "content");
+ StateString contentState = (StateString)uiwindow.getProperty(StateType.NAVIGATIONAL, "content");
//
return new WindowNavigationalState(windowState, mode, contentState);
@@ -93,7 +93,7 @@
{
uiwindow.setWindowState(navigationalState.getWindowState());
uiwindow.setMode(navigationalState.getMode());
- uiwindow.setProperty(StateScopeType.NAVIGATIONAL, "content", navigationalState.getContentState());
+ uiwindow.setProperty(StateType.NAVIGATIONAL, "content", navigationalState.getContentState());
}
public User getUser()
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-19 12:41:36 UTC (rev 9371)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java 2007-12-19 12:49:13 UTC (rev 9372)
@@ -24,7 +24,7 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
-import org.jboss.portal.presentation.model.StateScopeType;
+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;
@@ -47,7 +47,7 @@
*/
public Mode getMode()
{
- return getProperty(StateScopeType.NAVIGATIONAL, "mode", Mode.class);
+ return getProperty(StateType.NAVIGATIONAL, "mode", Mode.class);
}
/**
@@ -55,7 +55,7 @@
*/
public WindowState getWindowState()
{
- return getProperty(StateScopeType.NAVIGATIONAL, "windowstate", WindowState.class);
+ return getProperty(StateType.NAVIGATIONAL, "windowstate", WindowState.class);
}
/**
@@ -63,7 +63,7 @@
*/
public void setMode(Mode mode)
{
- setProperty(StateScopeType.NAVIGATIONAL, "mode", mode);
+ setProperty(StateType.NAVIGATIONAL, "mode", mode);
}
/**
@@ -71,7 +71,7 @@
*/
public void setWindowState(WindowState windowState)
{
- setProperty(StateScopeType.NAVIGATIONAL, "windowstate", windowState);
+ setProperty(StateType.NAVIGATIONAL, "windowstate", windowState);
}
protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
Modified: 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-19 12:41:36 UTC (rev 9371)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-19 12:49:13 UTC (rev 9372)
@@ -23,7 +23,7 @@
package org.jboss.portal.presentation.impl.model.container;
import org.jboss.portal.common.NotYetImplemented;
-import org.jboss.portal.presentation.model.StateScopeType;
+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;
@@ -142,13 +142,13 @@
}
}
- public <T> T getProperty(StateScopeType scopeType, String propertyName, Class<T> propertyType)
+ public <T> T getProperty(StateType stateType, String propertyName, Class<T> propertyType)
{
if (!context.isValid())
{
throw new IllegalStateException();
}
- if (scopeType == null)
+ if (stateType == null)
{
throw new IllegalArgumentException();
}
@@ -161,7 +161,7 @@
throw new IllegalArgumentException();
}
Object value;
- switch (scopeType)
+ switch (stateType)
{
case NAVIGATIONAL:
value = context.container.navigationalStateContext.get(getId(), propertyName);
@@ -175,18 +175,18 @@
return safeCast(value, propertyType);
}
- public Object getProperty(StateScopeType scopeType, String propertyName)
+ public Object getProperty(StateType stateType, String propertyName)
{
- return getProperty(scopeType, propertyName, Object.class);
+ return getProperty(stateType, propertyName, Object.class);
}
- public <T> void setProperty(StateScopeType scopeType, String propertyName, T propertyValue) throws StateChangeVetoException
+ public <T> void setProperty(StateType stateType, String propertyName, T propertyValue) throws StateChangeVetoException
{
if (!context.isValid())
{
throw new IllegalStateException();
}
- if (scopeType == null)
+ if (stateType == null)
{
throw new IllegalArgumentException();
}
@@ -199,7 +199,7 @@
String id = getId();
//
- switch (scopeType)
+ switch (stateType)
{
case NAVIGATIONAL:
{
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/StateType.java (from rev 9366, branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/StateScopeType.java)
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/StateType.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/StateType.java 2007-12-19 12:49:13 UTC (rev 9372)
@@ -0,0 +1,42 @@
+/******************************************************************************
+ * 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;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public enum StateType
+{
+ /**
+ * The navigational state type. The navigational state type describe sthe a kind of change done at runtime by the user when it
+ * interacts with the model (i.e not all interactions with the model are automatically navigational state changes).
+ */
+ NAVIGATIONAL,
+
+ /**
+ * The structural state type. The structural state type describes the structure of the model, i.e it defines an enduring
+ * state managed by the presentation server.
+ */
+ STRUCTURAL
+}
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-19 12:41:36 UTC (rev 9371)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-19 12:49:13 UTC (rev 9372)
@@ -111,28 +111,28 @@
/**
* Returns a property value or null if it does not exist.
*
- * @param scopeType the scope where to get the value from
+ * @param stateType the scope where to get the value from
* @param propertyName the property name
* @param propertyType the expected property type
* @return the property value
* @throws IllegalArgumentException if any argument is null or not valid
* @throws StateException any state exception
*/
- <T> T getProperty(StateScopeType scopeType, String propertyName, Class<T> propertyType) throws IllegalArgumentException, StateException;
+ <T> T getProperty(StateType stateType, String propertyName, Class<T> propertyType) throws IllegalArgumentException, StateException;
/**
* Equivalent to call <code>getPropertyValue(StateScopeType,String,Class)</code> with the <code>Object.class</code>
* literal.
*
- * @param scopeType the scope where to get the value from
+ * @param stateType the scope where to get the value from
* @param propertyName the property name
* @return the property value
* @throws IllegalArgumentException if any argument is null or not valid
* @throws StateException any state exception
*/
- Object getProperty(StateScopeType scopeType, String propertyName) throws IllegalArgumentException, StateException;
+ Object getProperty(StateType stateType, String propertyName) throws IllegalArgumentException, StateException;
- <T> void setProperty(StateScopeType scopeType, String propertyName, T propertyValue) throws IllegalArgumentException, StateException;
+ <T> void setProperty(StateType stateType, String propertyName, T propertyValue) throws IllegalArgumentException, StateException;
/**
* Create a named child with a specified type.
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java 2007-12-19 12:41:36 UTC (rev 9371)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java 2007-12-19 12:49:13 UTC (rev 9372)
@@ -40,17 +40,17 @@
throw new StateChangeVetoException();
}
- public StructuralObject.Destruction destroy(StructuralObject object) throws StateChangeVetoException, StateException, IllegalArgumentException
+ public StructuralObject.Destruction destroy(StructuralObject object) throws StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
- public StructuralObject.Move move(StructuralObject source, StructuralObject destination) throws StateChangeVetoException, StateException, IllegalArgumentException
+ public StructuralObject.Move move(StructuralObject source, StructuralObject destination) throws StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
- public StructuralObject.Update update(StructuralObject object, Map<String, String> changes) throws StateChangeVetoException, StateException, IllegalArgumentException
+ public StructuralObject.Update update(StructuralObject object, Map<String, String> changes) throws StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
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-19 12:41:36 UTC (rev 9371)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-19 12:49:13 UTC (rev 9372)
@@ -26,7 +26,7 @@
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.StateScopeType;
+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;
@@ -104,7 +104,7 @@
//
try
{
- context.setProperty(StateScopeType.STRUCTURAL, null, "foo_value");
+ context.setProperty(StateType.STRUCTURAL, null, "foo_value");
fail();
}
catch (IllegalArgumentException ignore)
@@ -134,7 +134,7 @@
//
try
{
- context.getProperty(StateScopeType.STRUCTURAL, null);
+ context.getProperty(StateType.STRUCTURAL, null);
fail();
}
catch (IllegalArgumentException ignore)
@@ -207,20 +207,20 @@
void assertStructuralEquals(String propertyName, String propertyValue)
{
- assertEquals(StateScopeType.STRUCTURAL, propertyName, propertyValue, String.class);
+ assertEquals(StateType.STRUCTURAL, propertyName, propertyValue, String.class);
}
<T> void assertNavigationalEquals(String propertyName, T propertyValue, Class<T> propertyClass)
{
- assertEquals(StateScopeType.NAVIGATIONAL, propertyName, propertyValue, propertyClass);
+ assertEquals(StateType.NAVIGATIONAL, propertyName, propertyValue, propertyClass);
}
- <T> void assertEquals(StateScopeType scopeType, String propertyName, T propertyValue, Class<T> propertyClass)
+ <T> void assertEquals(StateType stateType, String propertyName, T propertyValue, Class<T> propertyClass)
{
- Assert.assertEquals(propertyValue, object.getProperty(scopeType, propertyName, propertyClass));
- Assert.assertEquals(propertyValue, object.getProperty(scopeType, propertyName, Object.class));
- Assert.assertEquals(propertyValue, object.getProperty(scopeType, propertyName));
- Assert.assertEquals(null, object.getProperty(scopeType, propertyName, Blah.class)); }
+ Assert.assertEquals(propertyValue, object.getProperty(stateType, propertyName, propertyClass));
+ Assert.assertEquals(propertyValue, object.getProperty(stateType, propertyName, Object.class));
+ Assert.assertEquals(propertyValue, object.getProperty(stateType, propertyName));
+ Assert.assertEquals(null, object.getProperty(stateType, propertyName, Blah.class)); }
}
public void testUpdatePropertyNonExistingObject() throws MockException
@@ -233,7 +233,7 @@
//
try
{
- foo.setProperty(StateScopeType.STRUCTURAL, "foo", "foo_value");
+ foo.setProperty(StateType.STRUCTURAL, "foo", "foo_value");
fail();
}
catch (NoSuchStateException e)
@@ -256,14 +256,14 @@
fooAssert.assertStructuralEquals("foo", "foo_value");
// Update structural property
- foo.setProperty(StateScopeType.STRUCTURAL, "foo", "foo_new_value");
+ foo.setProperty(StateType.STRUCTURAL, "foo", "foo_new_value");
fooAssert.assertStructuralEquals("foo", "foo_new_value");
eventAssert.next(fooId, new StructuralStateModification.Update(Collections.singletonMap("foo", "foo_new_value")));
// Try a non string type
try
{
- foo.setProperty(StateScopeType.STRUCTURAL, "foo", 2);
+ foo.setProperty(StateType.STRUCTURAL, "foo", 2);
fail("Property update should have been vetoed");
}
catch (StateChangeVetoException ignore)
@@ -290,7 +290,7 @@
// Try an update
try
{
- foo.setProperty(StateScopeType.STRUCTURAL, "foo", "foo_new_value");
+ foo.setProperty(StateType.STRUCTURAL, "foo", "foo_new_value");
fail("Property update should have been vetoed");
}
catch (StateChangeVetoException ignore)
@@ -302,7 +302,7 @@
// Try a non string type
try
{
- foo.setProperty(StateScopeType.STRUCTURAL, "foo", 2);
+ foo.setProperty(StateType.STRUCTURAL, "foo", 2);
fail("Property update should have been vetoed");
}
catch (StateChangeVetoException ignore)
@@ -326,14 +326,14 @@
fooAssert.assertStructuralEquals("foo", null);
// Update structural property
- foo.setProperty(StateScopeType.STRUCTURAL, "foo", "foo_new_value");
+ foo.setProperty(StateType.STRUCTURAL, "foo", "foo_new_value");
fooAssert.assertStructuralEquals("foo", "foo_new_value");
eventAssert.next(fooId, new StructuralStateModification.Update(Collections.singletonMap("foo", "foo_new_value")));
// Try a non string type
try
{
- foo.setProperty(StateScopeType.STRUCTURAL, "foo", 2);
+ foo.setProperty(StateType.STRUCTURAL, "foo", 2);
fail("Property update should have been vetoed");
}
catch (StateChangeVetoException ignore)
@@ -359,7 +359,7 @@
// Try an update
try
{
- foo.setProperty(StateScopeType.STRUCTURAL, "foo", "foo_new_value");
+ foo.setProperty(StateType.STRUCTURAL, "foo", "foo_new_value");
fail("Property update should have been vetoed");
}
catch (StateChangeVetoException ignore)
@@ -371,7 +371,7 @@
// Try a non string type
try
{
- foo.setProperty(StateScopeType.STRUCTURAL, "foo", 2);
+ foo.setProperty(StateType.STRUCTURAL, "foo", 2);
fail("Property update should have been vetoed");
}
catch (StateChangeVetoException ignore)
@@ -394,11 +394,11 @@
fooAssert.assertNavigationalEquals("foo", null, String.class);
// Update navigational state
- foo.setProperty(StateScopeType.NAVIGATIONAL, "foo", "foo_new_value");
+ foo.setProperty(StateType.NAVIGATIONAL, "foo", "foo_new_value");
fooAssert.assertNavigationalEquals("foo", "foo_new_value", String.class);
// Update navigational state
- foo.setProperty(StateScopeType.NAVIGATIONAL, "foo", 2);
+ foo.setProperty(StateType.NAVIGATIONAL, "foo", 2);
fooAssert.assertNavigationalEquals("foo", 2, Integer.class);
}
@@ -407,8 +407,8 @@
UIContext context = createContext();
//
- context.setProperty(StateScopeType.STRUCTURAL, "foo", "bar");
- context.setProperty(StateScopeType.STRUCTURAL, "foo", "bar2");
+ context.setProperty(StateType.STRUCTURAL, "foo", "bar");
+ context.setProperty(StateType.STRUCTURAL, "foo", "bar2");
}
public void testConcurrentStructuralPropertyDetection() throws MockException
@@ -416,7 +416,7 @@
UIContext context = createContext();
//
- context.setProperty(StateScopeType.STRUCTURAL, "foo", "bar");
+ context.setProperty(StateType.STRUCTURAL, "foo", "bar");
// The concurrent update
model.getRoot().setPropertyValue("foo", "bar2");
@@ -424,7 +424,7 @@
//
try
{
- context.setProperty(StateScopeType.STRUCTURAL, "foo", "bar3");
+ context.setProperty(StateType.STRUCTURAL, "foo", "bar3");
fail("Was expecting an stale state exception");
}
catch (StaleStateException ignore)
16 years, 4 months
JBoss Portal SVN: r9371 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: model and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-19 07:41:36 -0500 (Wed, 19 Dec 2007)
New Revision: 9371
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
Log:
minor
Modified: 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-19 01:17:55 UTC (rev 9370)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-19 12:41:36 UTC (rev 9371)
@@ -388,6 +388,8 @@
{
throw new IllegalArgumentException("No null object accepted");
}
+
+ //
if (destination instanceof AbstractUIObject)
{
//
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-19 01:17:55 UTC (rev 9370)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-19 12:41:36 UTC (rev 9371)
@@ -22,8 +22,8 @@
******************************************************************************/
package org.jboss.portal.presentation.model;
-import org.jboss.portal.presentation.model.state.StateChangeVetoException;
import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.ConstraintViolationException;
import java.util.List;
@@ -161,7 +161,15 @@
*/
void destroyChild(String name) throws IllegalArgumentException, StateException;
-
+ /**
+ * Move the specified object to a new parent. A constraint violation will be detected if the destination
+ * is a descendant of the current object.
+ *
+ * @param destination the new parent
+ * @throws IllegalArgumentException if the destination is null
+ * @throws StateException any state exception
+ * @throws ConstraintViolationException if the destination is not valid
+ */
void move(UIObject destination) throws IllegalArgumentException, StateException;
}
16 years, 4 months
JBoss Portal SVN: r9370 - branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-18 20:17:55 -0500 (Tue, 18 Dec 2007)
New Revision: 9370
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
Log:
start refresh test case
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-19 01:01:18 UTC (rev 9369)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-19 01:17:55 UTC (rev 9370)
@@ -40,6 +40,8 @@
import java.util.Collections;
import java.util.List;
import java.util.HashMap;
+import java.util.Set;
+import java.util.Map;
/**
* Test that the mock model we are using behaves in an expected manner
@@ -499,6 +501,54 @@
assertValidity(juu, StaleStateException.class);
}
+ public void testRefresh() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+ String rootId = mockRoot.getId();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ String fooId = mockFoo.getId();
+ MockObject mockJuu = mockRoot.addChild("juu", MockObject.Type.PORTAL);
+ String juuId = mockJuu.getId();
+ MockObject mockFaa = mockRoot.addChild("faa", MockObject.Type.PORTAL);
+ String faaId = mockFaa.getId();
+ StructuralObject rootV0 = ssc.load(rootId);
+
+ //
+ MockObject mockBar = mockRoot.addChild("bar", MockObject.Type.PORTAL);
+ String barId = mockBar.getId();
+ model.destroy(mockFoo);
+ mockJuu.setPropertyValue("blah", "blah");
+
+ //
+ StructuralObject.Refresh comparison = ssc.refresh(rootV0);
+ assertNotNull(comparison);
+ Set<String> removed = comparison.getRemovedChildren();
+ assertNotNull(removed);
+ assertEquals(1, removed.size());
+ assertEquals(fooId, removed.iterator().next());
+
+ //
+ Set<StructuralObject> added = comparison.getAddedChildren();
+ assertNotNull(added);
+ assertEquals(1, added.size());
+ assertEquals(barId, added.iterator().next().getId());
+
+ //
+ Map<String, StructuralObject> stale = comparison.getStaleChildren();
+ assertNotNull(stale);
+ assertEquals(1, stale.size());
+ StructuralObject juu = stale.values().iterator().next();
+ assertNotNull(juu);
+ assertEquals(juuId, juu.getId());
+ assertEquals("blah", juu.getState().getProperties().get("blah"));
+
+ //
+ Set<String> valid = comparison.getValidChildren();
+ assertNotNull(valid);
+ assertEquals(1, valid.size());
+ assertEquals(faaId, valid.iterator().next());
+ }
+
private void assertValidity(StructuralObject object, Class<? extends StateException> expected) throws MockException
{
//
16 years, 4 months
JBoss Portal SVN: r9369 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: test/model/state/structural and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-18 20:01:18 -0500 (Tue, 18 Dec 2007)
New Revision: 9369
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectHandle.java
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/StructuralStateContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectImpl.java
Log:
start to implement refresh of a structural state context
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-19 00:35:40 UTC (rev 9368)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java 2007-12-19 01:01:18 UTC (rev 9369)
@@ -23,6 +23,8 @@
package org.jboss.portal.presentation.model.state.structural;
import java.util.List;
+import java.util.Set;
+import java.util.Map;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -35,6 +37,107 @@
StructuralState getState();
+ /**
+ * A comparison between two structural objects.
+ */
+ public static class Refresh
+ {
+
+ /** . */
+ private final StructuralObject parent;
+
+ /** . */
+ private final StructuralObject object;
+
+ /** . */
+ private final Set<StructuralObject> addedChildren;
+
+ /** . */
+ private final Set<String> removedChildren;
+
+ /** . */
+// private final Set<String> destroyedChildren;
+
+ /** . */
+ private final Map<String, StructuralObject> staleChildren;
+
+ /** . */
+ private final Set<String> validChildren;
+
+ public Refresh(
+ StructuralObject parent,
+ StructuralObject object,
+ Set<StructuralObject> addedChildren,
+ Set<String> removedChildren,
+ Map<String, StructuralObject> staleChildren,
+ Set<String> validChildren/*,
+ Set<String> destroyedChildren*/)
+ {
+ if (addedChildren == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (validChildren == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (staleChildren == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (removedChildren == null)
+ {
+ throw new IllegalArgumentException();
+ }
+// if (destroyedChildren == null)
+// {
+// throw new IllegalArgumentException();
+// }
+ this.parent = parent;
+ this.object = object;
+ this.addedChildren = addedChildren;
+ this.validChildren = validChildren;
+ this.staleChildren = staleChildren;
+ this.removedChildren = removedChildren;
+// this.destroyedChildren = destroyedChildren;
+ }
+
+ public StructuralObject getParent()
+ {
+ return parent;
+ }
+
+ public StructuralObject getObject()
+ {
+ return object;
+ }
+
+// public Set<String> getDestroyedChildren()
+// {
+// return destroyedChildren;
+// }
+
+ public Set<StructuralObject> getAddedChildren()
+ {
+ return addedChildren;
+ }
+
+ public Map<String, StructuralObject> getStaleChildren()
+ {
+ return staleChildren;
+ }
+
+ public Set<String> getValidChildren()
+ {
+ return validChildren;
+ }
+
+ public Set<String> getRemovedChildren()
+ {
+ return removedChildren;
+ }
+ }
+
public static class Change
{
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-19 00:35:40 UTC (rev 9368)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-19 01:01:18 UTC (rev 9369)
@@ -85,6 +85,8 @@
*/
void validate(StructuralObject object) throws IllegalArgumentException, StateException;
+ StructuralObject.Refresh refresh(StructuralObject object) throws IllegalArgumentException, StateException;
+
/**
* Create an object.
*
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-19 00:35:40 UTC (rev 9368)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-19 01:01:18 UTC (rev 9369)
@@ -40,6 +40,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.HashSet;
+import java.util.Set;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -134,6 +136,92 @@
getValidMockObject(object);
}
+ public StructuralObject.Refresh refresh(StructuralObject object) throws IllegalArgumentException, StateException
+ {
+ MockObjectImpl mockObject = getMockObject(object, false);
+
+ //
+ StructuralObjectImpl previous = (StructuralObjectImpl)object;
+ StructuralObjectImpl current = mockObject.takeSnapshot();
+
+ //
+ StructuralObject parent = null;
+ if (previous.parentHandle != null)
+ {
+ if (!current.parentHandle.equals(previous.handle))
+ {
+ parent = getMockObject(current.parentHandle, true).takeSnapshot();
+ }
+ }
+
+ //
+ Map<String, StructuralObjectHandle> previousChildren = new HashMap<String, StructuralObjectHandle>();
+ for (StructuralObjectHandle childHandle : previous.childrenHandles)
+ {
+ previousChildren.put(childHandle.id, childHandle);
+ }
+
+ //
+ Map<String, StructuralObjectHandle> currentChildren = new HashMap<String, StructuralObjectHandle>();
+ for (StructuralObjectHandle childHandle : current.childrenHandles)
+ {
+ currentChildren.put(childHandle.id, childHandle);
+ }
+
+ //
+ Map<String, StructuralObjectHandle> addedChildrenHandleMap = new HashMap<String, StructuralObjectHandle>(currentChildren);
+ addedChildrenHandleMap.keySet().removeAll(previousChildren.keySet());
+ Set<StructuralObject> addedChildren = new HashSet<StructuralObject>();
+ for (StructuralObjectHandle handle : addedChildrenHandleMap.values())
+ {
+ StructuralObject snapshot = getMockObject(handle, true).takeSnapshot();
+ addedChildren.add(snapshot);
+ }
+
+ //
+ Map<String, StructuralObjectHandle> removedChildrenHandleMap = new HashMap<String, StructuralObjectHandle>(previousChildren);
+ removedChildrenHandleMap.keySet().removeAll(currentChildren.keySet());
+ Set<String> removedChildren = new HashSet<String>();
+ for (StructuralObjectHandle handle : removedChildrenHandleMap.values())
+ {
+ removedChildren.add(handle.id);
+ }
+
+ //
+ Map<String, StructuralObjectHandle> commonCurrentChildrenHandleMap = new HashMap<String, StructuralObjectHandle>(currentChildren);
+ commonCurrentChildrenHandleMap.keySet().retainAll(previousChildren.keySet());
+
+ //
+ Map<String, StructuralObjectHandle> commonPreviousChildrenHandleMap = new HashMap<String, StructuralObjectHandle>(previousChildren);
+ commonPreviousChildrenHandleMap.keySet().retainAll(currentChildren.keySet());
+
+ //
+ Set<StructuralObjectHandle> validChildrenHandleSet = new HashSet<StructuralObjectHandle>(commonPreviousChildrenHandleMap.values());
+ validChildrenHandleSet.retainAll(commonCurrentChildrenHandleMap.values());
+ Set<String> validChildren = new HashSet<String>();
+ for (StructuralObjectHandle handle : validChildrenHandleSet)
+ {
+ validChildren.add(handle.id);
+ }
+
+ //
+ Set<StructuralObjectHandle> staleChildrenHandleSet = new HashSet<StructuralObjectHandle>(commonPreviousChildrenHandleMap.values());
+ staleChildrenHandleSet.removeAll(commonCurrentChildrenHandleMap.values());
+
+ //
+ Map<String, StructuralObject> staleChildrenHandleMap = new HashMap<String, StructuralObject>();
+ for (StructuralObjectHandle previousHandle : staleChildrenHandleSet)
+ {
+ String id = previousHandle.id;
+ StructuralObjectHandle handle = commonCurrentChildrenHandleMap.get(id);
+ StructuralObject snapshot = getMockObject(handle, true).takeSnapshot();
+ staleChildrenHandleMap.put(id, snapshot);
+ }
+
+ //
+ return new StructuralObject.Refresh(parent, current, addedChildren, removedChildren, staleChildrenHandleMap, validChildren);
+ }
+
public StructuralObject.Update update(StructuralObject object, Map<String, String> changes) throws StateChangeVetoException
{
MockObject mockObject = getValidMockObject(object);
@@ -271,6 +359,11 @@
private MockObjectImpl getValidMockObject(StructuralObject object) throws StateException
{
+ return getMockObject(object, true);
+ }
+
+ private MockObjectImpl getMockObject(StructuralObject object, boolean validateVersion)
+ {
if (object == null)
{
throw new IllegalArgumentException("No null object accepted");
@@ -280,24 +373,35 @@
StructuralObjectImpl structuralObject = (StructuralObjectImpl)object;
//
- MockObjectImpl mockObject = universe.get(structuralObject.getId());
+ return getMockObject(structuralObject.handle, validateVersion);
+ }
+
+ private MockObjectImpl getMockObject(StructuralObjectHandle handle, boolean validateVersion)
+ {
+ if (handle == null)
+ {
+ throw new IllegalArgumentException("No null object accepted");
+ }
//
+ MockObjectImpl mockObject = universe.get(handle.id);
+
+ //
if (mockObject == null)
{
throw new NoSuchStateException();
}
- // An invalid mock object should not be in the universe
+ //
if (!mockObject.isValid())
{
- throw new AssertionError();
+ throw new StaleStateException();
}
//
- if (mockObject.getVersion() != structuralObject.version)
+ if (validateVersion && (mockObject.getVersion() != handle.version))
{
- throw new StaleStateException("Version has changed obtained=" + mockObject.getVersion() + " wanted=" + structuralObject.version);
+ throw new StaleStateException("Version has changed obtained=" + mockObject.getVersion() + " wanted=" + handle.version);
}
//
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2007-12-19 00:35:40 UTC (rev 9368)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2007-12-19 01:01:18 UTC (rev 9369)
@@ -22,9 +22,6 @@
******************************************************************************/
package org.jboss.portal.presentation.test.model.state.structural;
-import org.jboss.portal.presentation.model.state.structural.StructuralObject;
-import org.jboss.portal.presentation.model.state.ConstraintViolationException;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -50,9 +47,6 @@
private final String name;
/** . */
- private final String id;
-
- /** . */
private final Map<String, String> propertyValues;
/** . */
@@ -71,7 +65,7 @@
private boolean valid;
/** The version id. */
- int version;
+ private StructuralObjectHandle handle;
MockObjectImpl(MockModelImpl model, String name, MockObject.Type type, String id)
{
@@ -81,9 +75,8 @@
this.children = new LinkedHashMap<String, MockObjectImpl>();
this.propertyValues = new HashMap<String, String>();
this.propertyBehaviors = new HashMap<String, UpdateBehavior>();
- this.id = id;
this.valid = true;
- this.version = 0;
+ this.handle = new StructuralObjectHandle(id, 0);
}
public MockObject.Type getType()
@@ -103,7 +96,7 @@
public String getId()
{
- return id;
+ return handle.id;
}
public String getPropertyValue(String propertyName)
@@ -165,8 +158,8 @@
//
child.parent = this;
- children.put(child.id, child);
- version++;
+ children.put(child.handle.id, child);
+ handle = handle.nextHandle();
//
return child;
@@ -217,17 +210,30 @@
}
//
- this.version++;
+ handle = handle.nextHandle();
}
public int getVersion()
{
- return version;
+ return handle.version;
}
- public StructuralObject takeSnapshot()
+ public StructuralObjectImpl takeSnapshot()
{
- return new StructuralObjectImpl(id, version, new StructuralStateImpl(type.clazz, name, new HashMap<String, String>(propertyValues)));
+ StructuralObjectHandle parentHandle = parent == null ? null : parent.handle;
+
+ //
+ List<StructuralObjectHandle> childrenHandles = new ArrayList<StructuralObjectHandle>();
+ for (MockObjectImpl child : children.values())
+ {
+ childrenHandles.add(child.handle);
+ }
+
+ //
+ StructuralStateImpl state = new StructuralStateImpl(type.clazz, name, new HashMap<String, String>(propertyValues));
+
+ //
+ return new StructuralObjectImpl(handle, parentHandle, childrenHandles, state);
}
public void move(MockObject destination) throws IllegalStateException, MockException
@@ -265,16 +271,16 @@
}
//
- parent.children.remove(id);
- parent.version++;
+ parent.children.remove(handle.id);
+ parent.handle = parent.handle.nextHandle();
//
- destination.children.put(id, this);
- destination.version++;
+ destination.children.put(handle.id, this);
+ destination.handle = destination.handle.nextHandle();
//
parent = destination;
- version++;
+ handle = handle.nextHandle();
}
public void destroy() throws MockException
@@ -287,8 +293,8 @@
// Detach from parent
if (parent != null)
{
- parent.children.remove(id);
- parent.version++;
+ parent.children.remove(handle.id);
+ parent.handle = parent.handle.nextHandle();
parent = null;
}
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectHandle.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectHandle.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectHandle.java 2007-12-19 01:01:18 UTC (rev 9369)
@@ -0,0 +1,81 @@
+/******************************************************************************
+ * 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.state.structural;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+class StructuralObjectHandle
+{
+
+ /** . */
+ final String id;
+
+ /** . */
+ final int version;
+
+ StructuralObjectHandle(String id, int version)
+ {
+ if (id == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.id = id;
+ this.version = version;
+ }
+
+ public int hashCode()
+ {
+ return id.hashCode() * version;
+ }
+
+ public boolean equals(Object o)
+ {
+ if (o == this)
+ {
+ return true;
+ }
+ if (o instanceof StructuralObjectHandle)
+ {
+ StructuralObjectHandle that = (StructuralObjectHandle)o;
+
+ //
+ return id.equals(that.id) && version == that.version;
+ }
+ return false;
+ }
+
+ StructuralObjectHandle nextHandle()
+ {
+ return new StructuralObjectHandle(id, version + 1);
+ }
+
+ public String toString()
+ {
+ return "StructuralObjectHandle[id=" + id + ",version=" + version + "]";
+ }
+
+}
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-19 00:35:40 UTC (rev 9368)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/StructuralObjectImpl.java 2007-12-19 01:01:18 UTC (rev 9369)
@@ -25,6 +25,8 @@
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralState;
+import java.util.List;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
@@ -33,24 +35,32 @@
{
/** . */
- final String id;
+ final StructuralObjectHandle handle;
/** . */
- final int version;
+ final StructuralObjectHandle parentHandle;
/** . */
+ final List<StructuralObjectHandle> childrenHandles;
+
+ /** . */
private final StructuralStateImpl state;
- public StructuralObjectImpl(String id, int version, StructuralStateImpl state)
+ public StructuralObjectImpl(
+ StructuralObjectHandle handle,
+ StructuralObjectHandle parentHandle,
+ List<StructuralObjectHandle> childrenHandles,
+ StructuralStateImpl state)
{
- this.id = id;
- this.version = version;
+ this.handle = handle;
+ this.parentHandle = parentHandle;
+ this.childrenHandles = childrenHandles;
this.state = state;
}
public String getId()
{
- return id;
+ return handle.id;
}
public StructuralState getState()
@@ -67,7 +77,7 @@
if (o instanceof StructuralObjectImpl)
{
StructuralObjectImpl that = (StructuralObjectImpl)o;
- return id.equals(that.id) && version == that.version;
+ return handle.equals(that.handle);
}
return false;
}
16 years, 4 months
JBoss Portal SVN: r9368 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: model/state/structural and 2 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-18 19:35:40 -0500 (Tue, 18 Dec 2007)
New Revision: 9368
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
Log:
more testing of mock 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-18 22:57:38 UTC (rev 9367)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-19 00:35:40 UTC (rev 9368)
@@ -89,6 +89,11 @@
// Package protected ************************************************************************************************
+ /**
+ * Process a change.
+ *
+ * @param change the change to process
+ */
void update(StructuralObject.Change change)
{
if (change instanceof StructuralObject.Update)
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-18 22:57:38 UTC (rev 9367)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-19 00:35:40 UTC (rev 9368)
@@ -39,17 +39,6 @@
{
/**
- * Validate the state of the provided object. The operation is idempotent and does not modify any state.
- * If validation is succesfull the method returns otherwise it throws an exception that indicates
- * the nature of the non validation failure.
- *
- * @param object the object to check
- * @throws IllegalArgumentException if the provided object is null
- * @throws StateException any useful exception that would make the object non valid
- */
- void validate(StructuralObject object) throws IllegalArgumentException, StateException;
-
- /**
* Load the state of the specified object.
*
* @param objectId the object id
@@ -86,6 +75,17 @@
String getRootId();
/**
+ * Validate the state of the provided object. The operation is idempotent and does not modify any state.
+ * If validation is succesfull the method returns otherwise it throws an exception that indicates
+ * the nature of the non validation failure.
+ *
+ * @param object the object to check
+ * @throws IllegalArgumentException if the provided object is null
+ * @throws StateException any useful exception that would make the object non valid
+ */
+ void validate(StructuralObject object) throws IllegalArgumentException, StateException;
+
+ /**
* Create an object.
*
* @param parent the parent
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-18 22:57:38 UTC (rev 9367)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-19 00:35:40 UTC (rev 9368)
@@ -25,8 +25,10 @@
import junit.framework.TestCase;
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.UIPortal;
+import org.jboss.portal.presentation.model.UIPage;
import org.jboss.portal.presentation.model.state.StaleStateException;
import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.NoSuchStateException;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralState;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
@@ -37,6 +39,7 @@
import java.util.Collections;
import java.util.List;
+import java.util.HashMap;
/**
* Test that the mock model we are using behaves in an expected manner
@@ -403,6 +406,180 @@
}
}
+ public void testInvalidatedByDestruction() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+
+ //
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+ MockObject mockBar = mockRoot.addChild("bar", MockObject.Type.PAGE);
+
+ //
+ StructuralObject foo = mockFoo.takeSnapshot();
+
+ //
+ model.destroy(mockFoo);
+
+ //
+ assertValidity(foo, NoSuchStateException.class);
+ }
+
+ public void testInvalidatedByPropertyUpdate() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+
+ //
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+
+ //
+ StructuralObject foo = mockFoo.takeSnapshot();
+
+ //
+ mockFoo.setPropertyValue("a", "b");
+
+ //
+ assertValidity(foo, StaleStateException.class);
+ }
+
+ public void testInvalidatedByChildCreation() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+
+ //
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+
+ //
+ StructuralObject foo = mockFoo.takeSnapshot();
+
+ //
+ mockFoo.addChild("juu", MockObject.Type.PAGE);
+
+ //
+ assertValidity(foo, StaleStateException.class);
+ }
+
+ public void testInvalidatedByChildDestruction() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+
+ //
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+
+ //
+ StructuralObject foo = mockFoo.takeSnapshot();
+
+ //
+ model.destroy(mockJuu);
+
+ //
+ assertValidity(foo, StaleStateException.class);
+ }
+
+ public void testInvalidatedByMove() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+
+ //
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+ MockObject mockBar = mockFoo.addChild("bar", MockObject.Type.PAGE);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+
+ //
+ StructuralObject foo = mockFoo.takeSnapshot();
+ StructuralObject bar = mockBar.takeSnapshot();
+ StructuralObject juu = mockJuu.takeSnapshot();
+
+ //
+ mockBar.move(mockJuu);
+
+ //
+ assertValidity(foo, StaleStateException.class);
+ assertValidity(bar, StaleStateException.class);
+ assertValidity(juu, StaleStateException.class);
+ }
+
+ private void assertValidity(StructuralObject object, Class<? extends StateException> expected) throws MockException
+ {
+ //
+ try
+ {
+ ssc.validate(object);
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ //
+ try
+ {
+ ssc.loadChildren(object);
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ //
+ try
+ {
+ ssc.loadParent(object);
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ //
+ try
+ {
+ StructuralObject bar = model.getRoot().addChild("bar", MockObject.Type.PAGE).takeSnapshot();
+ ssc.move(object, bar);
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ //
+ try
+ {
+ ssc.create(object, UIPage.class, "juu", new HashMap<String, String>());
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ //
+ try
+ {
+ ssc.destroy(object);
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+
+ //
+ try
+ {
+ ssc.update(object, new HashMap<String, String>());
+ fail();
+ }
+ catch (StateException e)
+ {
+ assertTrue(expected.isInstance(e));
+ }
+ }
+
private void assertStale(StructuralObject object)
{
try
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-18 22:57:38 UTC (rev 9367)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-19 00:35:40 UTC (rev 9368)
@@ -288,10 +288,10 @@
throw new NoSuchStateException();
}
- //
+ // An invalid mock object should not be in the universe
if (!mockObject.isValid())
{
- throw new StaleStateException();
+ throw new AssertionError();
}
//
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2007-12-18 22:57:38 UTC (rev 9367)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2007-12-19 00:35:40 UTC (rev 9368)
@@ -266,10 +266,15 @@
//
parent.children.remove(id);
+ parent.version++;
+
+ //
destination.children.put(id, this);
+ destination.version++;
+
+ //
parent = destination;
version++;
- destination.version++;
}
public void destroy() throws MockException
16 years, 4 months