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();
+ }
+ }
+}