Author: julien(a)jboss.com
Date: 2007-12-27 12:00:47 -0500 (Thu, 27 Dec 2007)
New Revision: 9391
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIContainerObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIObjectFactory.java
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
Log:
refactor to cleanup a bit
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-27
13:25:10 UTC (rev 9390)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-27
17:00:47 UTC (rev 9391)
@@ -24,11 +24,10 @@
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.StateType;
-import org.jboss.portal.presentation.model.ModelListener;
import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
-import org.jboss.portal.presentation.impl.model.container.UIContainerObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
+import org.jboss.portal.presentation.impl.model.container.spi.UIContainerObject;
+import org.jboss.portal.presentation.impl.model.container.spi.UIObjectContext;
import java.util.List;
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2007-12-27
17:00:47 UTC (rev 9391)
@@ -0,0 +1,200 @@
+/******************************************************************************
+ * 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.impl.model.container.spi.UIContainerObject;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.model.UIObject;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.AbstractList;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class AssociationContext
+{
+
+ ObjectContext owner;
+
+ final ManyToOne parent = new ManyToOne();
+
+ final OneToMany children = new OneToMany();
+
+
+ class ManyToOne
+ {
+
+ /** . */
+ boolean loaded;
+
+ /** . */
+ UIContainerObject related;
+
+ private ManyToOne()
+ {
+ }
+
+ UIContainerObject get()
+ {
+ if (!loaded)
+ {
+ StructuralObject parentSO =
owner.container.structuralStateContext.loadParent(owner.structuralObject);
+
+ // If null it is the root so nothing is done
+ if (parentSO != null)
+ {
+ UIContainerObject parent = owner.container.get(parentSO);
+
+ //
+ if (parent != null)
+ {
+ related = parent;
+
+ //
+ ObjectContext parentContext = (ObjectContext)parent.getContext();
+
+ //
+ if (!parentSO.compareTo(parentContext.structuralObject))
+ {
+ parentContext.status = UIObject.Status.STALE;
+ }
+ }
+ else
+ {
+ parent = owner.container.create(parentSO);
+
+ //
+ owner.container.put(parent);
+
+ //
+ related = parent;
+ }
+ }
+ }
+
+ // Try to resolve the relationship
+
+
+ //
+ return related;
+ }
+ }
+
+ class OneToMany
+ {
+
+ /** . */
+ final ProxyList list;
+
+ /** . */
+ List<UIContainerObject> relateds;
+
+ private OneToMany()
+ {
+ this.list = new ProxyList();
+ this.relateds = null;
+ }
+
+ List<UIContainerObject> get()
+ {
+ return list;
+ }
+
+ private List<UIContainerObject> getChildren(StructuralObject
structuralObject)
+ {
+ ArrayList<UIContainerObject> children = new
ArrayList<UIContainerObject>();
+
+ //
+ for (StructuralObject childSO :
owner.container.structuralStateContext.loadChildren(structuralObject))
+ {
+ UIContainerObject child = owner.container.get(childSO);
+
+ //
+ if (child != null)
+ {
+ ObjectContext childContext = (ObjectContext)child.getContext();
+
+ //
+ if (!childContext.structuralObject.compareTo(childSO))
+ {
+ childContext.status = UIObject.Status.STALE;
+ }
+ }
+ else
+ {
+ child = owner.container.create(childSO);
+
+ //
+ owner.container.put(child);
+ }
+
+ //
+ children.add(child);
+ }
+
+ //
+ return children;
+ }
+
+ private class ProxyList extends AbstractList<UIContainerObject>
+ {
+ public UIContainerObject get(int i)
+ {
+ if (!owner.isValid())
+ {
+ throw new IllegalStateException("Relationship not valid");
+ }
+
+ // Load the entire relationship
+ if (relateds == null)
+ {
+ relateds = getChildren(owner.structuralObject);
+ }
+
+ //
+ return relateds.get(i);
+ }
+
+ public int size()
+ {
+ if (!owner.isValid())
+ {
+ throw new IllegalStateException("Relationship cannot be used because
the owner " + owner + " is not valid");
+ }
+ if (relateds == null)
+ {
+ relateds = getChildren(owner.structuralObject);
+ }
+ return relateds.size();
+ }
+
+ public String toString()
+ {
+ return "ProxyList[" + owner + "]";
+ }
+ }
+ }
+}
Copied:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
(from rev 9388,
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java)
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-27
17:00:47 UTC (rev 9391)
@@ -0,0 +1,426 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.impl.model.container;
+
+import org.jboss.portal.presentation.model.StateType;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.event.state.StateChange;
+import org.jboss.portal.presentation.model.event.state.StateChangeEvent;
+import
org.jboss.portal.presentation.model.event.state.navigational.NavigationalStateModification;
+import
org.jboss.portal.presentation.model.event.state.structural.StructuralStateModification;
+import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.impl.model.container.spi.UIContainerObject;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Implement base fonctionnality of the <code>UIObject</code> interface.
+ *
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ */
+public class ManagedObject implements UIObject
+{
+
+ /** . */
+ private static final Map<String, String> EMPTY_STATE = Collections.emptyMap();
+
+ /** The context. */
+ protected final ObjectContext context;
+
+ public ManagedObject(ObjectContext context)
+ {
+ if (context == null)
+ {
+ throw new IllegalArgumentException("No null context accepted");
+ }
+
+ //
+ this.context = context;
+ }
+
+ // UIObject interface implementation
--------------------------------------------------------------------------------
+
+ public final String getId()
+ {
+ return context.structuralObject.getId();
+ }
+
+ /**
+ * Attempt to cast the value argument to the provided type argument. If the value
argument type is assignable
+ * to the provided type, the value is returned, otherwise if it is not or the value is
null, null is returned.
+ *
+ * todo: Move that to common package.
+ *
+ * @param value the value to cast
+ * @param type the type to downcast
+ * @return the casted value or null
+ */
+ private <T> T safeCast(Object value, Class<T> type)
+ {
+ if (value == null)
+ {
+ return null;
+ }
+ else
+ {
+ if (type.isAssignableFrom(value.getClass()))
+ {
+ return type.cast(value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+
+ public final Status getStatus()
+ {
+ return context.status;
+ }
+
+ protected final boolean isModifiable()
+ {
+ return true;
+ }
+
+ public void validate(Visitor scope)
+ {
+ context.container.validate(this, scope);
+ }
+
+ public final void validate()
+ {
+ refresh(SINGLE_NODE_VISITOR);
+ }
+
+ public void refresh(Visitor scope)
+ {
+ context.container.refresh(this, scope);
+ }
+
+ public final void refresh()
+ {
+ refresh(SINGLE_NODE_VISITOR);
+ }
+
+ public <T> T getProperty(StateType stateType, String propertyName,
Class<T> propertyType)
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (stateType == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertyType == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ Object value;
+ switch (stateType)
+ {
+ case NAVIGATIONAL:
+ value = context.container.navigationalStateContext.get(getId(),
propertyName);
+ break;
+ case STRUCTURAL:
+ value =
context.structuralObject.getState().getProperties().get(propertyName);
+ break;
+ default:
+ throw new AssertionError();
+ }
+ return safeCast(value, propertyType);
+ }
+
+ public final Object getProperty(StateType stateType, String propertyName)
+ {
+ return getProperty(stateType, propertyName, Object.class);
+ }
+
+ public final <T> void setProperty(StateType stateType, String propertyName, T
propertyValue) throws StateChangeVetoException
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (stateType == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
+
+ //
+ String id = getId();
+
+ //
+ switch (stateType)
+ {
+ case NAVIGATIONAL:
+ {
+ // Have context process the change
+ context.container.navigationalStateContext.set(id, propertyName,
propertyValue);
+
+ // Broadcast event
+ NavigationalStateModification mod = new
NavigationalStateModification(propertyName, propertyValue);
+ StateChange<NavigationalStateModification> change = new
StateChange<NavigationalStateModification>(id, mod);
+ StateChangeEvent event = new StateChangeEvent(change);
+ context.container.fireEvent(event);
+ break;
+ }
+ case STRUCTURAL:
+ {
+ if (propertyValue instanceof String)
+ {
+ Map<String, String> changes = new HashMap<String, String>();
+ changes.put(propertyName, (String)propertyValue);
+
+ // Have context process change
+ StructuralObject.Update update;
+ try
+ {
+ update =
context.container.structuralStateContext.update(context.structuralObject, changes);
+ }
+ catch (StateException e)
+ {
+ validate();
+
+ //
+ throw e;
+ }
+
+ //
+ context.container.update(update);
+
+ // Broadcast event
+ StructuralStateModification mod = new
StructuralStateModification.Update(changes);
+ StateChange<StructuralStateModification> change = new
StateChange<StructuralStateModification>(id, mod);
+ StateChangeEvent event = new StateChangeEvent(change);
+ context.container.fireEvent(event);
+ }
+ else
+ {
+ throw new StateChangeVetoException("Structural property value must be
string value");
+ }
+ break;
+ }
+ default:
+ throw new AssertionError();
+ }
+ }
+
+ public final UIContainerObject getChild(String name)
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (name == null)
+ {
+ throw new IllegalArgumentException("No null name accepted");
+ }
+
+ //
+ for (UIContainerObject child : getChildren())
+ {
+ if (child.getName().equals(name))
+ {
+ return child;
+ }
+ }
+
+ //
+ return null;
+ }
+
+ public final String getName()
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ return context.structuralObject.getState().getName();
+ }
+
+ public final UIObject getParent()
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ return context.associationContext.parent.get();
+ }
+
+ public final List<UIContainerObject> getChildren()
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ return context.associationContext.children.get();
+ }
+
+ public final <T extends UIObject> T createChild(String name, Class<T>
type) throws IllegalArgumentException
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
+
+ //
+ StructuralObject.Creation creation;
+ try
+ {
+ creation =
context.container.structuralStateContext.create(context.structuralObject, type, name,
EMPTY_STATE);
+ }
+ catch (StateException e)
+ {
+ context.updateStatus(e);
+
+ //
+ throw e;
+ }
+
+ //
+ context.container.update(creation);
+
+ //
+ StructuralObject child = creation.getChild();
+
+ // Eventing
+ StructuralStateModification mod = new StructuralStateModification.Creation(type,
name, EMPTY_STATE);
+ StateChange<StructuralStateModification> change = new
StateChange<StructuralStateModification>(child.getId(), mod);
+ StateChangeEvent event = new StateChangeEvent(change);
+ context.container.fireEvent(event);
+
+ //
+ return type.cast(context.getObject(child.getId()));
+ }
+
+ public final void destroyChild(String name) throws IllegalArgumentException,
StateException
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
+
+ // Get the named child
+ UIContainerObject namedChild = getChild(name);
+
+ //
+ if (namedChild == null)
+ {
+ throw new IllegalArgumentException("No such child with name " +
name);
+ }
+
+ // Destroy the child
+ StructuralObject.Destruction destruction =
context.container.structuralStateContext.destroy(((ObjectContext)namedChild.getContext()).structuralObject);
+
+ //
+ context.container.update(destruction);
+ }
+
+ public final void move(UIObject destination) throws IllegalArgumentException,
StateException
+ {
+ if (destination == null)
+ {
+ throw new IllegalArgumentException("No null object accepted");
+ }
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
+
+ //
+ if (destination instanceof UIContainerObject)
+ {
+ //
+ UIContainerObject tmp = (UIContainerObject)destination;
+
+ // Perform the move operation
+ StructuralObject.Move move =
context.container.structuralStateContext.move(context.structuralObject,
((ObjectContext)tmp.getContext()).structuralObject);
+
+ //
+ context.container.update(move);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Object not of right type");
+ }
+ }
+
+ /**
+ * Visitor that visits a single node only.
+ */
+ private static final Visitor SINGLE_NODE_VISITOR = new Visitor()
+ {
+ public boolean enterObject(UIObject object)
+ {
+ return true;
+ }
+
+ public void leaveObject(UIObject object)
+ {
+ }
+
+ public boolean enterChildren(UIObject object, boolean loaded)
+ {
+ return false;
+ }
+ };
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ObjectContext.java 2007-12-27
17:00:47 UTC (rev 9391)
@@ -0,0 +1,138 @@
+/******************************************************************************
+ * 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.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;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.UIContext;
+import org.jboss.portal.presentation.model.ModelListener;
+import org.jboss.portal.presentation.impl.model.container.spi.UIObjectContext;
+
+/**
+ * Encapsulate internal of an object.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public final class ObjectContext implements UIObjectContext
+{
+
+ /** . */
+ final UIObjectContainer container;
+
+ /** . */
+ final ManagedObject managedObject;
+
+ /** . */
+ AssociationContext associationContext;
+
+ /** . */
+ StructuralObject structuralObject;
+
+ /** . */
+ UIObject.Status status;
+
+ public ObjectContext(UIObjectContainer container, StructuralObject structuralObject)
+ {
+ if (container == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (structuralObject == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.container = container;
+ this.structuralObject = structuralObject;
+ this.status = UIObject.Status.VALID;
+ this.managedObject = new ManagedObject(this);
+ }
+
+ // Public
***********************************************************************************************************
+
+ public UIObject getManagedObject()
+ {
+ return managedObject;
+ }
+
+ public UIObject getObject(String id)
+ {
+ return container.getObject(id);
+ }
+
+ public void addModelListener(ModelListener listener)
+ {
+ container.addModelListener(listener);
+ }
+
+ //
+
+ StructuralState getState()
+ {
+ return structuralObject.getState();
+ }
+
+ UIContext getRoot()
+ {
+ return container.root;
+ }
+
+ UIObject.Status getStatus()
+ {
+ return status;
+ }
+
+ boolean isValid()
+ {
+ return status == UIObject.Status.VALID;
+ }
+
+ // Package protected
************************************************************************************************
+
+ void updateStatus(StateException e)
+ {
+ if (e instanceof NoSuchStateException)
+ {
+ status = UIObject.Status.INVALID;
+ }
+ else if (e instanceof StaleStateException)
+ {
+ status = UIObject.Status.STALE;
+ }
+ else
+ {
+ throw new AssertionError(e);
+ }
+ }
+
+ public String toString()
+ {
+ return "UIObjectContext[" + structuralObject.getId() + "]";
+ }
+}
\ No newline at end of file
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java 2007-12-27
13:25:10 UTC (rev 9390)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java 2007-12-27
17:00:47 UTC (rev 9391)
@@ -1,38 +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;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public interface UIContainerObject extends UIObject
-{
-
- UIObjectContext getContext();
-
- void setContext(UIObjectContext context);
-
-}
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java 2007-12-27
13:25:10 UTC (rev 9390)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java 2007-12-27
17:00:47 UTC (rev 9391)
@@ -1,425 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.presentation.impl.model.container;
-
-import org.jboss.portal.presentation.model.StateType;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.event.state.StateChange;
-import org.jboss.portal.presentation.model.event.state.StateChangeEvent;
-import
org.jboss.portal.presentation.model.event.state.navigational.NavigationalStateModification;
-import
org.jboss.portal.presentation.model.event.state.structural.StructuralStateModification;
-import org.jboss.portal.presentation.model.state.StateChangeVetoException;
-import org.jboss.portal.presentation.model.state.StateException;
-import org.jboss.portal.presentation.model.state.structural.StructuralObject;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Implement base fonctionnality of the <code>UIObject</code> interface.
- *
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- */
-public class UIManagedObject implements UIObject
-{
-
- /** . */
- private static final Map<String, String> EMPTY_STATE = Collections.emptyMap();
-
- /** The context. */
- protected final UIObjectContext context;
-
- public UIManagedObject(UIObjectContext context)
- {
- if (context == null)
- {
- throw new IllegalArgumentException("No null context accepted");
- }
-
- //
- this.context = context;
- }
-
- // UIObject interface implementation
--------------------------------------------------------------------------------
-
- public final String getId()
- {
- return context.structuralObject.getId();
- }
-
- /**
- * Attempt to cast the value argument to the provided type argument. If the value
argument type is assignable
- * to the provided type, the value is returned, otherwise if it is not or the value is
null, null is returned.
- *
- * todo: Move that to common package.
- *
- * @param value the value to cast
- * @param type the type to downcast
- * @return the casted value or null
- */
- private <T> T safeCast(Object value, Class<T> type)
- {
- if (value == null)
- {
- return null;
- }
- else
- {
- if (type.isAssignableFrom(value.getClass()))
- {
- return type.cast(value);
- }
- else
- {
- return null;
- }
- }
- }
-
- public final Status getStatus()
- {
- return context.status;
- }
-
- protected final boolean isModifiable()
- {
- return true;
- }
-
- public void validate(Visitor scope)
- {
- context.container.validate(this, scope);
- }
-
- public final void validate()
- {
- refresh(SINGLE_NODE_VISITOR);
- }
-
- public void refresh(Visitor scope)
- {
- context.container.refresh(this, scope);
- }
-
- public final void refresh()
- {
- refresh(SINGLE_NODE_VISITOR);
- }
-
- public <T> T getProperty(StateType stateType, String propertyName,
Class<T> propertyType)
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
- if (stateType == null)
- {
- throw new IllegalArgumentException();
- }
- if (propertyName == null)
- {
- throw new IllegalArgumentException();
- }
- if (propertyType == null)
- {
- throw new IllegalArgumentException();
- }
- Object value;
- switch (stateType)
- {
- case NAVIGATIONAL:
- value = context.container.navigationalStateContext.get(getId(),
propertyName);
- break;
- case STRUCTURAL:
- value =
context.structuralObject.getState().getProperties().get(propertyName);
- break;
- default:
- throw new AssertionError();
- }
- return safeCast(value, propertyType);
- }
-
- public final Object getProperty(StateType stateType, String propertyName)
- {
- return getProperty(stateType, propertyName, Object.class);
- }
-
- public final <T> void setProperty(StateType stateType, String propertyName, T
propertyValue) throws StateChangeVetoException
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
- if (stateType == null)
- {
- throw new IllegalArgumentException();
- }
- if (propertyName == null)
- {
- throw new IllegalArgumentException();
- }
- if (!isModifiable())
- {
- throw new IllegalStateException("Cannot change state");
- }
-
- //
- String id = getId();
-
- //
- switch (stateType)
- {
- case NAVIGATIONAL:
- {
- // Have context process the change
- context.container.navigationalStateContext.set(id, propertyName,
propertyValue);
-
- // Broadcast event
- NavigationalStateModification mod = new
NavigationalStateModification(propertyName, propertyValue);
- StateChange<NavigationalStateModification> change = new
StateChange<NavigationalStateModification>(id, mod);
- StateChangeEvent event = new StateChangeEvent(change);
- context.container.fireEvent(event);
- break;
- }
- case STRUCTURAL:
- {
- if (propertyValue instanceof String)
- {
- Map<String, String> changes = new HashMap<String, String>();
- changes.put(propertyName, (String)propertyValue);
-
- // Have context process change
- StructuralObject.Update update;
- try
- {
- update =
context.container.structuralStateContext.update(context.structuralObject, changes);
- }
- catch (StateException e)
- {
- validate();
-
- //
- throw e;
- }
-
- //
- context.container.update(update);
-
- // Broadcast event
- StructuralStateModification mod = new
StructuralStateModification.Update(changes);
- StateChange<StructuralStateModification> change = new
StateChange<StructuralStateModification>(id, mod);
- StateChangeEvent event = new StateChangeEvent(change);
- context.container.fireEvent(event);
- }
- else
- {
- throw new StateChangeVetoException("Structural property value must be
string value");
- }
- break;
- }
- default:
- throw new AssertionError();
- }
- }
-
- public final UIContainerObject getChild(String name)
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
- if (name == null)
- {
- throw new IllegalArgumentException("No null name accepted");
- }
-
- //
- for (UIContainerObject child : getChildren())
- {
- if (child.getName().equals(name))
- {
- return child;
- }
- }
-
- //
- return null;
- }
-
- public final String getName()
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
-
- //
- return context.structuralObject.getState().getName();
- }
-
- public final UIObject getParent()
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
-
- //
- return context.parent.get();
- }
-
- public final List<UIContainerObject> getChildren()
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
-
- //
- return context.children.get();
- }
-
- public final <T extends UIObject> T createChild(String name, Class<T>
type) throws IllegalArgumentException
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
- if (!isModifiable())
- {
- throw new IllegalStateException("Cannot change state");
- }
-
- //
- StructuralObject.Creation creation;
- try
- {
- creation =
context.container.structuralStateContext.create(context.structuralObject, type, name,
EMPTY_STATE);
- }
- catch (StateException e)
- {
- context.updateStatus(e);
-
- //
- throw e;
- }
-
- //
- context.container.update(creation);
-
- //
- StructuralObject child = creation.getChild();
-
- // Eventing
- StructuralStateModification mod = new StructuralStateModification.Creation(type,
name, EMPTY_STATE);
- StateChange<StructuralStateModification> change = new
StateChange<StructuralStateModification>(child.getId(), mod);
- StateChangeEvent event = new StateChangeEvent(change);
- context.container.fireEvent(event);
-
- //
- return type.cast(context.getObject(child.getId()));
- }
-
- public final void destroyChild(String name) throws IllegalArgumentException,
StateException
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
- if (name == null)
- {
- throw new IllegalArgumentException();
- }
- if (!isModifiable())
- {
- throw new IllegalStateException("Cannot change state");
- }
-
- // Get the named child
- UIContainerObject namedChild = getChild(name);
-
- //
- if (namedChild == null)
- {
- throw new IllegalArgumentException("No such child with name " +
name);
- }
-
- // Destroy the child
- StructuralObject.Destruction destruction =
context.container.structuralStateContext.destroy(namedChild.getContext().structuralObject);
-
- //
- context.container.update(destruction);
- }
-
- public final void move(UIObject destination) throws IllegalArgumentException,
StateException
- {
- if (destination == null)
- {
- throw new IllegalArgumentException("No null object accepted");
- }
- if (!isModifiable())
- {
- throw new IllegalStateException("Cannot change state");
- }
-
- //
- if (destination instanceof UIContainerObject)
- {
- //
- UIContainerObject tmp = (UIContainerObject)destination;
-
- // Perform the move operation
- StructuralObject.Move move =
context.container.structuralStateContext.move(context.structuralObject,
tmp.getContext().structuralObject);
-
- //
- context.container.update(move);
- }
- else
- {
- throw new IllegalArgumentException("Object not of right type");
- }
- }
-
- /**
- * Visitor that visits a single node only.
- */
- private static final Visitor SINGLE_NODE_VISITOR = new Visitor()
- {
- public boolean enterObject(UIObject object)
- {
- return true;
- }
-
- public void leaveObject(UIObject object)
- {
- }
-
- public boolean enterChildren(UIObject object, boolean loaded)
- {
- return false;
- }
- };
-}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-27
13:25:10 UTC (rev 9390)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-27
17:00:47 UTC (rev 9391)
@@ -31,13 +31,14 @@
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.impl.model.container.spi.UIContainerObject;
+import org.jboss.portal.presentation.impl.model.container.spi.UIObjectFactory;
import org.jboss.portal.common.NotYetImplemented;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.AbstractList;
import java.util.Iterator;
/**
@@ -82,17 +83,23 @@
put(root);
}
- private UIContainerObject create(StructuralObject structuralObject)
+ UIContainerObject create(StructuralObject structuralObject)
{
// Create context
- UIObjectContext context = new UIObjectContext(this, structuralObject);
+ ObjectContext objectContext = new ObjectContext(this, structuralObject);
+ AssociationContext associationContext = new AssociationContext();
+ // Wire
+ objectContext.associationContext = associationContext;
+ associationContext.owner = objectContext;
+
// Create container object
UIContainerObject object =
factory.createObject(structuralObject.getState().getType());
// Contextualize
- object.setContext(context);
+ object.setContext(objectContext);
+ //
return object;
}
@@ -126,7 +133,7 @@
}
//
- UIObjectContext context = object.getContext();
+ ObjectContext context = (ObjectContext)object.getContext();
context.structuralObject = update.getObject();
}
else if (change instanceof StructuralObject.Creation)
@@ -143,13 +150,13 @@
}
//
- UIObjectContext parentContext = parent.getContext();
+ ObjectContext parentContext = (ObjectContext)parent.getContext();
//
parentContext.structuralObject = creation.getParent();
//
- if (parentContext.children.relateds != null)
+ if (parentContext.associationContext.children.relateds != null)
{
UIContainerObject child = create(creation.getChild());
@@ -157,7 +164,7 @@
put(child);
//
- parentContext.children.relateds.add(child);
+ parentContext.associationContext.children.relateds.add(child);
}
}
else if (change instanceof StructuralObject.Destruction)
@@ -170,15 +177,15 @@
//
if (parent != null)
{
- UIObjectContext parentContext = parent.getContext();
+ ObjectContext parentContext = (ObjectContext)parent.getContext();
//
parentContext.structuralObject = destruction.getParent();
//
- if (parentContext.children.relateds != null)
+ if (parentContext.associationContext.children.relateds != null)
{
- for (Iterator<UIContainerObject> i =
parentContext.children.relateds.iterator();i.hasNext();)
+ for (Iterator<UIContainerObject> i =
parentContext.associationContext.children.relateds.iterator();i.hasNext();)
{
UIContainerObject child = i.next();
@@ -195,12 +202,13 @@
//
for (String id : destruction.getIds())
{
- UIContainerObject o = universe.remove(id);
+ UIContainerObject destroyed = universe.remove(id);
//
- if (o != null)
+ if (destroyed != null)
{
- o.getContext().status = UIObject.Status.INVALID;
+ ObjectContext destroyedContext = (ObjectContext)destroyed.getContext();
+ destroyedContext.status = UIObject.Status.INVALID;
}
}
}
@@ -216,15 +224,15 @@
// Update parent
if (parent != null)
{
- UIObjectContext parentContext = parent.getContext();
+ ObjectContext parentContext = (ObjectContext)parent.getContext();
// Update so
parentContext.structuralObject = move.getParent();
// Remove the child if the relationship is loaded on this side
- if (parentContext.children.relateds != null)
+ if (parentContext.associationContext.children.relateds != null)
{
- for (Iterator<UIContainerObject> i =
parentContext.children.relateds.iterator();i.hasNext();)
+ for (Iterator<UIContainerObject> i =
parentContext.associationContext.children.relateds.iterator();i.hasNext();)
{
UIContainerObject child = i.next();
@@ -241,13 +249,13 @@
//
if (destination != null)
{
- UIObjectContext destinationContext = destination.getContext();
+ ObjectContext destinationContext = (ObjectContext)destination.getContext();
//
destinationContext.structuralObject = move.getDestination();
//
- if (destinationContext.children.relateds != null)
+ if (destinationContext.associationContext.children.relateds != null)
{
// Now we really need to add the source as we load collections entirely
if (source == null)
@@ -259,29 +267,29 @@
}
//
- destinationContext.children.relateds.add(source);
+ destinationContext.associationContext.children.relateds.add(source);
}
}
// Update source
if (source != null)
{
- UIObjectContext sourceContext = source.getContext();
+ ObjectContext sourceContext = (ObjectContext)source.getContext();
// Update so
sourceContext.structuralObject = move.getSource();
//
- if (sourceContext.parent.loaded)
+ if (sourceContext.associationContext.parent.loaded)
{
if (destination != null)
{
- sourceContext.parent.related = destination;
+ sourceContext.associationContext.parent.related = destination;
}
else
{
- sourceContext.parent.related = null;
- sourceContext.parent.loaded = false;
+ sourceContext.associationContext.parent.related = null;
+ sourceContext.associationContext.parent.loaded = false;
}
}
}
@@ -359,11 +367,11 @@
}
}
- void validate(UIManagedObject object, UIObject.Visitor scope)
+ void validate(ManagedObject object, UIObject.Visitor scope)
{
if (scope.enterObject(object))
{
- UIObjectContext context = object.context;
+ ObjectContext context = object.context;
// We do it only if it is not yet invalid
if (context.isValid())
@@ -381,15 +389,18 @@
// Continue only if it is valid
if (context.isValid())
{
- boolean loaded = context.children.relateds != null;
+ boolean loaded = context.associationContext.children.relateds != null;
// Loading children will never make the current object invalid
// but it could make some already loaded children invalid
if (scope.enterChildren(object, loaded))
{
- for (UIContainerObject child : context.children.get())
+ for (UIContainerObject child :
context.associationContext.children.get())
{
- validate(child.getContext().managedObject, scope);
+ ObjectContext childContext = (ObjectContext)child.getContext();
+
+ //
+ validate(childContext.managedObject, scope);
}
}
}
@@ -400,11 +411,11 @@
}
}
- void refresh(UIManagedObject object, UIObject.Visitor scope)
+ void refresh(ManagedObject object, UIObject.Visitor scope)
{
if (scope.enterObject(object))
{
- UIObjectContext context = object.context;
+ ObjectContext context = object.context;
//
switch (context.status)
@@ -418,7 +429,7 @@
// Update the structural state
if (!context.structuralObject.compareTo(refresh.getObject()))
{
- boolean loaded = context.children.relateds != null;
+ boolean loaded = context.associationContext.children.relateds !=
null;
//
if (loaded)
@@ -436,18 +447,18 @@
//
if (added != null)
{
- UIObjectContext addedContext = added.getContext();
+ ObjectContext addedContext =
(ObjectContext)added.getContext();
// Set the parent as stale if needed
- if (addedContext.parent.loaded)
+ if (addedContext.associationContext.parent.loaded)
{
- UIObjectContext addedParentContext =
addedContext.parent.related.getContext();
+ ObjectContext addedParentContext =
(ObjectContext)addedContext.associationContext.parent.related.getContext();
// Mark the parent as stale
addedParentContext.status = UIObject.Status.STALE;
//
- addedParentContext.parent.related =
get(context.structuralObject.getId());
+ addedParentContext.associationContext.parent.related =
get(context.structuralObject.getId());
}
}
else
@@ -477,8 +488,11 @@
{
UIContainerObject stale = get(staleSO);
+ //
+ ObjectContext staleContext =
(ObjectContext)stale.getContext();
+
// Mark as stale
- stale.getContext().status = UIObject.Status.STALE;
+ staleContext.status = UIObject.Status.STALE;
//
children.add(stale);
@@ -501,7 +515,7 @@
// Update state
context.structuralObject = refresh.getObject();
context.status = UIObject.Status.VALID;
- context.children.relateds = children;
+ context.associationContext.children.relateds = children;
}
}
}
@@ -522,228 +536,18 @@
}
}
- ManyToOne createManyToOne(UIObjectContext context)
+ void put(UIContainerObject object)
{
- return new ManyToOne(context);
- }
-
- OneToMany createOneToMany(UIObjectContext context)
- {
- return new OneToMany(context);
- }
-
- // Private
**********************************************************************************************************
-
-// /**
-// * Update the state of an object if it is present. It will also reset the parent and
children
-// * relationships in order to force a implicit refresh.
-// *
-// * @param structuralObject the structural object to update
-// * @return the object API implementation
-// */
-// private UIContainerObject update(StructuralObject structuralObject, boolean
compareWithExisting)
-// {
-// UIContainerObject containerObject = universe.get(structuralObject.getId());
-//
-// //
-// if (containerObject == null)
-// {
-// containerObject = new
UIObjectFactory().createObject(structuralObject.getState().getType());
-//
-// //
-// containerObject.setContext(new UIObjectContext(this, structuralObject));
-//
-// //
-// universe.put(structuralObject.getId(), containerObject);
-// }
-// else
-// {
-// UIObjectContext context = containerObject.getContext();
-//
-// //
-// context.structuralObject = structuralObject;
-// context.parent.clear();
-// context.children.clear();
-// }
-//
-// //
-// return containerObject;
-// }
-
- private void put(UIContainerObject object)
- {
universe.put(object.getId(), object);
}
- private UIContainerObject get(String id)
+ UIContainerObject get(String id)
{
return universe.get(id);
}
- private UIContainerObject get(StructuralObject so)
+ UIContainerObject get(StructuralObject so)
{
return universe.get(so.getId());
}
-
- class ManyToOne
- {
-
- /** . */
- private final UIObjectContext owner;
-
- /** . */
- private boolean loaded;
-
- /** . */
- private UIContainerObject related;
-
- private ManyToOne(UIObjectContext owner)
- {
- this.owner = owner;
- }
-
- UIContainerObject get()
- {
- if (!loaded)
- {
- StructuralObject parentSO =
structuralStateContext.loadParent(owner.structuralObject);
-
- // If null it is the root so nothing is done
- if (parentSO != null)
- {
- UIContainerObject parent = UIObjectContainer.this.get(parentSO);
-
- //
- if (parent != null)
- {
- related = parent;
-
- //
- UIObjectContext parentContext = parent.getContext();
-
- //
- if (!parentSO.compareTo(parentContext.structuralObject))
- {
- parentContext.status = UIObject.Status.STALE;
- }
- }
- else
- {
- parent = create(parentSO);
-
- //
- put(parent);
-
- //
- related = parent;
- }
- }
- }
-
- // Try to resolve the relationship
-
-
- //
- return related;
- }
- }
-
- class OneToMany
- {
-
- /** . */
- private final ProxyList list;
-
- /** . */
- private final UIObjectContext owner;
-
- /** . */
- private List<UIContainerObject> relateds;
-
- private OneToMany(UIObjectContext object)
- {
- this.owner = object;
- this.list = new ProxyList();
- this.relateds = null;
- }
-
- List<UIContainerObject> get()
- {
- return list;
- }
-
- private List<UIContainerObject> getChildren(StructuralObject
structuralObject)
- {
- ArrayList<UIContainerObject> children = new
ArrayList<UIContainerObject>();
-
- //
- for (StructuralObject childSO :
structuralStateContext.loadChildren(structuralObject))
- {
- UIContainerObject child = UIObjectContainer.this.get(childSO);
-
- //
- if (child != null)
- {
- UIObjectContext childContext = child.getContext();
-
- //
- if (!childContext.structuralObject.compareTo(childSO))
- {
- childContext.status = UIObject.Status.STALE;
- }
- }
- else
- {
- child = create(childSO);
-
- //
- put(child);
- }
-
- //
- children.add(child);
- }
-
- //
- return children;
- }
-
- private class ProxyList extends AbstractList<UIContainerObject>
- {
- public UIContainerObject get(int i)
- {
- if (!owner.isValid())
- {
- throw new IllegalStateException("Relationship not valid");
- }
-
- // Load the entire relationship
- if (relateds == null)
- {
- relateds = getChildren(owner.structuralObject);
- }
-
- //
- return relateds.get(i);
- }
-
- public int size()
- {
- if (!owner.isValid())
- {
- throw new IllegalStateException("Relationship cannot be used because
the owner " + owner + " is not valid");
- }
- if (relateds == null)
- {
- relateds = getChildren(owner.structuralObject);
- }
- return relateds.size();
- }
-
- public String toString()
- {
- return "ProxyList[" + owner + "]";
- }
- }
- }
}
Deleted:
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-27
13:25:10 UTC (rev 9390)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-27
17:00:47 UTC (rev 9391)
@@ -1,142 +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.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;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.UIContext;
-import org.jboss.portal.presentation.model.ModelListener;
-
-/**
- * Encapsulate internal of an object.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public final class UIObjectContext
-{
-
- /** . */
- final UIObjectContainer container;
-
- /** . */
- final UIManagedObject managedObject;
-
- /** . */
- final UIObjectContainer.OneToMany children;
-
- /** . */
- final UIObjectContainer.ManyToOne parent;
-
- /** . */
- StructuralObject structuralObject;
-
- /** . */
- UIObject.Status status;
-
- public UIObjectContext(UIObjectContainer container, StructuralObject
structuralObject)
- {
- if (container == null)
- {
- throw new IllegalArgumentException();
- }
- if (structuralObject == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- this.container = container;
- this.structuralObject = structuralObject;
- this.status = UIObject.Status.VALID;
- this.managedObject = new UIManagedObject(this);
- this.children = container.createOneToMany(this);
- this.parent = container.createManyToOne(this);
- }
-
- // Public
***********************************************************************************************************
-
- public UIObject getManagedObject()
- {
- return managedObject;
- }
-
- public UIObject getObject(String id)
- {
- return container.getObject(id);
- }
-
- public void addModelListener(ModelListener listener)
- {
- container.addModelListener(listener);
- }
-
- //
-
- StructuralState getState()
- {
- return structuralObject.getState();
- }
-
- UIContext getRoot()
- {
- return container.root;
- }
-
- UIObject.Status getStatus()
- {
- return status;
- }
-
- boolean isValid()
- {
- return status == UIObject.Status.VALID;
- }
-
- // Package protected
************************************************************************************************
-
- void updateStatus(StateException e)
- {
- if (e instanceof NoSuchStateException)
- {
- status = UIObject.Status.INVALID;
- }
- else if (e instanceof StaleStateException)
- {
- status = UIObject.Status.STALE;
- }
- else
- {
- throw new AssertionError(e);
- }
- }
-
- public String toString()
- {
- return "UIObjectContext[" + structuralObject.getId() + "]";
- }
-}
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java 2007-12-27
13:25:10 UTC (rev 9390)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java 2007-12-27
17:00:47 UTC (rev 9391)
@@ -1,99 +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.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.model.UIObject;
-import org.jboss.portal.presentation.impl.model.UIContextImpl;
-import org.jboss.portal.presentation.impl.model.UIPortalImpl;
-import org.jboss.portal.presentation.impl.model.UIPageImpl;
-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 UIContainerObject createObject(Class<? extends UIObject> type)
- {
- if(type == UIContext.class)
- {
- return new UIContextImpl();
- }
- else if(type == UIPortal.class)
- {
- return new UIPortalImpl();
- }
- else if(type == UIPage.class)
- {
- return new UIPageImpl();
- }
- else if(type == UIContainer.class)
- {
- return new UIContainerImpl();
- }
- else if(type == UIWindow.class)
- {
- return new UIWindowImpl();
- }
- else
- {
- throw new AssertionError();
- }
- }
-
-// public <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
-// {
-// if(type == UIContext.class)
-// {
-// return type == UIPortal.class;
-// }
-// else if (type == UIPortal.class)
-// {
-// return type == UIPage.class;
-// }
-// else if (type == UIPage.class)
-// {
-// return type == UIPage.class || type == UIContainer.class || type ==
UIWindow.class;
-// }
-// else if (type == UIContainer.class)
-// {
-// return type == UIWindow.class;
-// }
-// else if (type == UIWindow.class)
-// {
-// return false;
-// }
-// else
-// {
-// throw new AssertionError();
-// }
-// }
-}
Copied:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIContainerObject.java
(from rev 9382,
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java)
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIContainerObject.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIContainerObject.java 2007-12-27
17:00:47 UTC (rev 9391)
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * 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.spi;
+
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.impl.model.container.spi.UIObjectContext;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface UIContainerObject extends UIObject
+{
+
+ UIObjectContext getContext();
+
+ void setContext(UIObjectContext context);
+
+}
Copied:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIObjectContext.java
(from rev 9386,
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/spi/UIObjectContext.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIObjectContext.java 2007-12-27
17:00:47 UTC (rev 9391)
@@ -0,0 +1,43 @@
+/******************************************************************************
+ * 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.spi;
+
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.ModelListener;
+
+/**
+ * Encapsulate internal of an object.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface UIObjectContext
+{
+
+ UIObject getManagedObject();
+
+ UIObject getObject(String id);
+
+ void addModelListener(ModelListener listener);
+
+}
Copied:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIObjectFactory.java
(from rev 9382,
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/spi/UIObjectFactory.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/spi/UIObjectFactory.java 2007-12-27
17:00:47 UTC (rev 9391)
@@ -0,0 +1,99 @@
+/******************************************************************************
+ * 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.spi;
+
+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.model.UIObject;
+import org.jboss.portal.presentation.impl.model.UIContextImpl;
+import org.jboss.portal.presentation.impl.model.UIPortalImpl;
+import org.jboss.portal.presentation.impl.model.UIPageImpl;
+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 UIContainerObject createObject(Class<? extends UIObject> type)
+ {
+ if(type == UIContext.class)
+ {
+ return new UIContextImpl();
+ }
+ else if(type == UIPortal.class)
+ {
+ return new UIPortalImpl();
+ }
+ else if(type == UIPage.class)
+ {
+ return new UIPageImpl();
+ }
+ else if(type == UIContainer.class)
+ {
+ return new UIContainerImpl();
+ }
+ else if(type == UIWindow.class)
+ {
+ return new UIWindowImpl();
+ }
+ else
+ {
+ throw new AssertionError();
+ }
+ }
+
+// public <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
+// {
+// if(type == UIContext.class)
+// {
+// return type == UIPortal.class;
+// }
+// else if (type == UIPortal.class)
+// {
+// return type == UIPage.class;
+// }
+// else if (type == UIPage.class)
+// {
+// return type == UIPage.class || type == UIContainer.class || type ==
UIWindow.class;
+// }
+// else if (type == UIContainer.class)
+// {
+// return type == UIWindow.class;
+// }
+// else if (type == UIWindow.class)
+// {
+// return false;
+// }
+// else
+// {
+// throw new AssertionError();
+// }
+// }
+}