Author: julien(a)jboss.com
Date: 2007-12-21 16:28:29 -0500 (Fri, 21 Dec 2007)
New Revision: 9379
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectAssociation.java
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java
Log:
decouple the notion of managed/container object
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java 2007-12-21
18:34:54 UTC (rev 9378)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java 2007-12-21
21:28:29 UTC (rev 9379)
@@ -23,32 +23,11 @@
package org.jboss.portal.presentation.impl.model;
import org.jboss.portal.presentation.model.UIContainer;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public class UIContainerImpl extends AbstractUIObject implements UIContainer
+public class UIContainerImpl extends UIObjectImpl implements UIContainer
{
-
- public UIContainerImpl(UIObjectContext context)
- {
- super(context);
- }
-
- protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
- {
- boolean isAllowedAsChild = false;
-
- if(type == UIWindow.class)
- {
- isAllowedAsChild = true;
- }
-
- return isAllowedAsChild;
- }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-21
18:34:54 UTC (rev 9378)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-21
21:28:29 UTC (rev 9379)
@@ -22,10 +22,7 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.model;
-import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.UIPortal;
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.ModelListener;
@@ -33,19 +30,13 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-public class UIContextImpl extends AbstractUIObject implements UIContext
+public class UIContextImpl extends UIObjectImpl implements UIContext
{
- public UIContextImpl(UIObjectContext context)
+ public UIContextImpl()
{
- super(context);
}
- protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
- {
- return type == UIPortal.class;
- }
-
public UIObject getObject(String id)
{
return context.getObject(id);
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-21
21:28:29 UTC (rev 9379)
@@ -0,0 +1,137 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.impl.model;
+
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.StateType;
+import org.jboss.portal.presentation.model.ModelListener;
+import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.impl.model.container.UIContainerObject;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class UIObjectImpl implements UIContainerObject
+{
+
+ /** . */
+ protected UIObjectContext context;
+
+ //
+ public UIObjectContext getContext()
+ {
+ return context;
+ }
+
+ public void setContext(UIObjectContext context)
+ {
+ this.context = context;
+ }
+
+ //
+
+ public String getId()
+ {
+ return context.getManagedObject().getId();
+ }
+
+ public Status getStatus()
+ {
+ return context.getManagedObject().getStatus();
+ }
+
+ public void validate(Visitor scope)
+ {
+ context.getManagedObject().validate(scope);
+ }
+
+ public void validate()
+ {
+ context.getManagedObject().validate();
+ }
+
+ public void refresh(Visitor scope)
+ {
+ context.getManagedObject().refresh(scope);
+ }
+
+ public void refresh()
+ {
+ context.getManagedObject().refresh();
+ }
+
+ public <T> T getProperty(StateType stateType, String propertyName,
Class<T> propertyType)
+ {
+ return context.getManagedObject().getProperty(stateType, propertyName,
propertyType);
+ }
+
+ public Object getProperty(StateType stateType, String propertyName)
+ {
+ return context.getManagedObject().getProperty(stateType, propertyName);
+ }
+
+ public <T> void setProperty(StateType stateType, String propertyName, T
propertyValue) throws StateChangeVetoException
+ {
+ context.getManagedObject().setProperty(stateType, propertyName, propertyValue);
+ }
+
+ public UIObject getChild(String name)
+ {
+ return context.getManagedObject().getChild(name);
+ }
+
+ public String getName()
+ {
+ return context.getManagedObject().getName();
+ }
+
+ public UIObject getParent()
+ {
+ return context.getManagedObject().getParent();
+ }
+
+ public List<? extends UIObject> getChildren()
+ {
+ return context.getManagedObject().getChildren();
+ }
+
+ public <T extends UIObject> T createChild(String name, Class<T> type)
throws IllegalArgumentException
+ {
+ return context.getManagedObject().createChild(name, type);
+ }
+
+ public void destroyChild(String name) throws IllegalArgumentException, StateException
+ {
+ context.getManagedObject().destroyChild(name);
+ }
+
+ public void move(UIObject destination) throws IllegalArgumentException,
StateException
+ {
+ context.getManagedObject().move(destination);
+ }
+}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java 2007-12-21
18:34:54 UTC (rev 9378)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java 2007-12-21
21:28:29 UTC (rev 9379)
@@ -22,27 +22,12 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.model;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.UIContainer;
import org.jboss.portal.presentation.model.UIPage;
-import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public class UIPageImpl extends AbstractUIObject implements UIPage
+public class UIPageImpl extends UIObjectImpl implements UIPage
{
-
- public UIPageImpl(UIObjectContext context)
- {
- super(context);
- }
-
- protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
- {
- return type == UIPage.class || type == UIContainer.class || type == UIWindow.class;
- }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java 2007-12-21
18:34:54 UTC (rev 9378)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java 2007-12-21
21:28:29 UTC (rev 9379)
@@ -22,26 +22,12 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.model;
-import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIPortal;
-import org.jboss.portal.presentation.model.UIPage;
-import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public class UIPortalImpl extends AbstractUIObject implements UIPortal
+public class UIPortalImpl extends UIObjectImpl implements UIPortal
{
-
- public UIPortalImpl(UIObjectContext context)
- {
- super(context);
- }
-
- protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
- {
- return type == UIPage.class;
- }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java 2007-12-21
18:34:54 UTC (rev 9378)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java 2007-12-21
21:28:29 UTC (rev 9379)
@@ -25,23 +25,15 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
import org.jboss.portal.presentation.model.StateType;
-import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public class UIWindowImpl extends AbstractUIObject implements UIWindow
+public class UIWindowImpl extends UIObjectImpl implements UIWindow
{
- public UIWindowImpl(UIObjectContext context)
- {
- super(context);
- }
-
/**
*
*/
@@ -73,9 +65,4 @@
{
setProperty(StateType.NAVIGATIONAL, "windowstate", windowState);
}
-
- protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
- {
- return false;
- }
}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIContainerObject.java 2007-12-21
21:28:29 UTC (rev 9379)
@@ -0,0 +1,38 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.impl.model.container;
+
+import org.jboss.portal.presentation.model.UIObject;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface UIContainerObject extends UIObject
+{
+
+ UIObjectContext getContext();
+
+ void setContext(UIObjectContext context);
+
+}
Copied:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java
(from rev 9378,
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java)
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIManagedObject.java 2007-12-21
21:28:29 UTC (rev 9379)
@@ -0,0 +1,434 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.impl.model.container;
+
+import org.jboss.portal.presentation.model.StateType;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.event.state.StateChange;
+import org.jboss.portal.presentation.model.event.state.StateChangeEvent;
+import
org.jboss.portal.presentation.model.event.state.navigational.NavigationalStateModification;
+import
org.jboss.portal.presentation.model.event.state.structural.StructuralStateModification;
+import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Implement base fonctionnality of the <code>UIObject</code> interface.
+ *
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ */
+public class UIManagedObject implements UIObject
+{
+
+ /** . */
+ private static final Map<String, String> EMPTY_STATE = Collections.emptyMap();
+
+ /** The context. */
+ protected final UIObjectContext context;
+
+ /** . */
+ final UIObjectOneToMany childrenRelationship;
+
+ /** . */
+ final UIObjectManyToOne parentRelationship;
+
+ public UIManagedObject(UIObjectContext context)
+ {
+ if (context == null)
+ {
+ throw new IllegalArgumentException("No null context accepted");
+ }
+
+ //
+ this.context = context;
+ this.childrenRelationship = new UIObjectOneToMany(context);
+ this.parentRelationship = new UIObjectManyToOne(context);
+ }
+
+ // UIObject interface implementation
--------------------------------------------------------------------------------
+
+ public final String getId()
+ {
+ return context.structuralObject.getId();
+ }
+
+ /**
+ * Attempt to cast the value argument to the provided type argument. If the value
argument type is assignable
+ * to the provided type, the value is returned, otherwise if it is not or the value is
null, null is returned.
+ *
+ * todo: Move that to common package.
+ *
+ * @param value the value to cast
+ * @param type the type to downcast
+ * @return the casted value or null
+ */
+ private <T> T safeCast(Object value, Class<T> type)
+ {
+ if (value == null)
+ {
+ return null;
+ }
+ else
+ {
+ if (type.isAssignableFrom(value.getClass()))
+ {
+ return type.cast(value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+
+ public final Status getStatus()
+ {
+ return context.status;
+ }
+
+ protected final boolean isModifiable()
+ {
+ return true;
+ }
+
+ public void validate(Visitor scope)
+ {
+ context.container.validate(this, scope);
+ }
+
+ public final void validate()
+ {
+ refresh(SINGLE_NODE_VISITOR);
+ }
+
+ public void refresh(Visitor scope)
+ {
+ context.container.refresh(this, scope);
+ }
+
+ public final void refresh()
+ {
+ refresh(SINGLE_NODE_VISITOR);
+ }
+
+ public <T> T getProperty(StateType stateType, String propertyName,
Class<T> propertyType)
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (stateType == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertyType == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ Object value;
+ switch (stateType)
+ {
+ case NAVIGATIONAL:
+ value = context.container.navigationalStateContext.get(getId(),
propertyName);
+ break;
+ case STRUCTURAL:
+ value =
context.structuralObject.getState().getProperties().get(propertyName);
+ break;
+ default:
+ throw new AssertionError();
+ }
+ return safeCast(value, propertyType);
+ }
+
+ public final Object getProperty(StateType stateType, String propertyName)
+ {
+ return getProperty(stateType, propertyName, Object.class);
+ }
+
+ public final <T> void setProperty(StateType stateType, String propertyName, T
propertyValue) throws StateChangeVetoException
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (stateType == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
+
+ //
+ String id = getId();
+
+ //
+ switch (stateType)
+ {
+ case NAVIGATIONAL:
+ {
+ // Have context process the change
+ context.container.navigationalStateContext.set(id, propertyName,
propertyValue);
+
+ // Broadcast event
+ NavigationalStateModification mod = new
NavigationalStateModification(propertyName, propertyValue);
+ StateChange<NavigationalStateModification> change = new
StateChange<NavigationalStateModification>(id, mod);
+ StateChangeEvent event = new StateChangeEvent(change);
+ context.container.fireEvent(event);
+ break;
+ }
+ case STRUCTURAL:
+ {
+ if (propertyValue instanceof String)
+ {
+ Map<String, String> changes = new HashMap<String, String>();
+ changes.put(propertyName, (String)propertyValue);
+
+ // Have context process change
+ StructuralObject.Update update;
+ try
+ {
+ update =
context.container.structuralStateContext.update(context.structuralObject, changes);
+ }
+ catch (StateException e)
+ {
+ validate();
+
+ //
+ throw e;
+ }
+
+ //
+ context.container.update(update);
+
+ // Broadcast event
+ StructuralStateModification mod = new
StructuralStateModification.Update(changes);
+ StateChange<StructuralStateModification> change = new
StateChange<StructuralStateModification>(id, mod);
+ StateChangeEvent event = new StateChangeEvent(change);
+ context.container.fireEvent(event);
+ }
+ else
+ {
+ throw new StateChangeVetoException("Structural property value must be
string value");
+ }
+ break;
+ }
+ default:
+ throw new AssertionError();
+ }
+ }
+
+ public final UIContainerObject getChild(String name)
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (name == null)
+ {
+ throw new IllegalArgumentException("No null name accepted");
+ }
+
+ //
+ for (UIContainerObject child : getChildren())
+ {
+ if (child.getName().equals(name))
+ {
+ return child;
+ }
+ }
+
+ //
+ return null;
+ }
+
+ public final String getName()
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ return context.structuralObject.getState().getName();
+ }
+
+ public final UIObject getParent()
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ return parentRelationship.get();
+ }
+
+ public final List<UIContainerObject> getChildren()
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ return childrenRelationship.get();
+ }
+
+ public final <T extends UIObject> T createChild(String name, Class<T>
type) throws IllegalArgumentException
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
+
+ //
+ StructuralObject.Creation creation;
+ try
+ {
+ creation =
context.container.structuralStateContext.create(context.structuralObject, type, name,
EMPTY_STATE);
+ }
+ catch (StateException e)
+ {
+ context.updateStatus(e);
+
+ //
+ throw e;
+ }
+
+ //
+ context.container.update(creation);
+
+ //
+ StructuralObject child = creation.getChild();
+
+ // Eventing
+ StructuralStateModification mod = new StructuralStateModification.Creation(type,
name, EMPTY_STATE);
+ StateChange<StructuralStateModification> change = new
StateChange<StructuralStateModification>(child.getId(), mod);
+ StateChangeEvent event = new StateChangeEvent(change);
+ context.container.fireEvent(event);
+
+ //
+ return type.cast(context.getObject(child.getId()));
+ }
+
+ public final void destroyChild(String name) throws IllegalArgumentException,
StateException
+ {
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
+
+ // Get the named child
+ UIContainerObject namedChild = getChild(name);
+
+ //
+ if (namedChild == null)
+ {
+ throw new IllegalArgumentException("No such child with name " +
name);
+ }
+
+ // Destroy the child
+ StructuralObject.Destruction destruction =
context.container.structuralStateContext.destroy(namedChild.getContext().structuralObject);
+
+ //
+ context.container.update(destruction);
+ }
+
+ public final void move(UIObject destination) throws IllegalArgumentException,
StateException
+ {
+ if (destination == null)
+ {
+ throw new IllegalArgumentException("No null object accepted");
+ }
+ if (!isModifiable())
+ {
+ throw new IllegalStateException("Cannot change state");
+ }
+
+ //
+ if (destination instanceof UIContainerObject)
+ {
+ //
+ UIContainerObject tmp = (UIContainerObject)destination;
+
+ // Perform the move operation
+ StructuralObject.Move move =
context.container.structuralStateContext.move(context.structuralObject,
tmp.getContext().structuralObject);
+
+ //
+ context.container.update(move);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Object not of right type");
+ }
+ }
+
+ /**
+ * Visitor that visits a single node only.
+ */
+ private static final Visitor SINGLE_NODE_VISITOR = new Visitor()
+ {
+ public boolean enterObject(UIObject object)
+ {
+ return true;
+ }
+
+ public void leaveObject(UIObject object)
+ {
+ }
+
+ public boolean enterChildren(UIObject object)
+ {
+ return false;
+ }
+ };
+
+}
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectAssociation.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectAssociation.java 2007-12-21
18:34:54 UTC (rev 9378)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectAssociation.java 2007-12-21
21:28:29 UTC (rev 9379)
@@ -1,79 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.presentation.impl.model.container;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-abstract class UIObjectAssociation<T>
-{
-
- /** . */
- private static final int NOT_LOADED = 0;
-
- /** . */
- private static final int LOADED = 1;
-
- /** . */
- private int status;
-
- /** . */
- private T t;
-
- public void clear()
- {
- if (status == LOADED)
- {
- T tmp = t;
-
- //
- t = null;
- status = NOT_LOADED;
-
- //
- doEvict(tmp);
- }
- }
-
- public T get()
- {
- if (status == NOT_LOADED)
- {
- t = doLoad();
- status = LOADED;
- }
-
- //
- return t;
- }
-
- protected final int getStatus()
- {
- return status;
- }
-
- protected abstract T doLoad();
-
- protected abstract void doEvict(T t);
-}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-21
18:34:54 UTC (rev 9378)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-21
21:28:29 UTC (rev 9379)
@@ -45,7 +45,7 @@
{
/** . */
- private final Map<String, AbstractUIObject> universe = new HashMap<String,
AbstractUIObject>();
+ private final Map<String, UIContainerObject> universe = new HashMap<String,
UIContainerObject>();
/** . */
private final List<ModelListener> listeners;
@@ -116,12 +116,12 @@
//
for (String id : destruction.getIds())
{
- AbstractUIObject o = universe.remove(id);
+ UIContainerObject o = universe.remove(id);
//
if (o != null)
{
- o.context.status = UIObject.Status.INVALID;
+ o.getContext().status = UIObject.Status.INVALID;
}
}
}
@@ -144,7 +144,7 @@
}
}
- AbstractUIObject getParent(StructuralObject structuralObject)
+ UIContainerObject getParent(StructuralObject structuralObject)
{
StructuralObject parentStructuralState =
structuralStateContext.loadParent(structuralObject);
@@ -158,14 +158,14 @@
return update(parentStructuralState);
}
- List<AbstractUIObject> getChildren(StructuralObject structuralObject)
+ List<UIContainerObject> getChildren(StructuralObject structuralObject)
{
- ArrayList<AbstractUIObject> children = new
ArrayList<AbstractUIObject>();
+ ArrayList<UIContainerObject> children = new
ArrayList<UIContainerObject>();
//
for (StructuralObject structuralChild :
structuralStateContext.loadChildren(structuralObject))
{
- AbstractUIObject child = update(structuralChild);
+ UIContainerObject child = update(structuralChild);
children.add(child);
}
@@ -182,11 +182,11 @@
* @param loadIfAbsent load the object from the structural state context if it is not
present
* @return the loaded object
*/
- AbstractUIObject getObject(String id, boolean loadIfAbsent)
+ UIContainerObject getObject(String id, boolean loadIfAbsent)
{
try
{
- AbstractUIObject context = universe.get(id);
+ UIContainerObject context = universe.get(id);
//
if (context != null)
@@ -250,7 +250,7 @@
}
}
- void validate(AbstractUIObject object, UIObject.Visitor scope)
+ void validate(UIManagedObject object, UIObject.Visitor scope)
{
// if (scope.enterObject(object))
// {
@@ -280,7 +280,7 @@
// }
}
- void refresh(AbstractUIObject object, UIObject.Visitor scope)
+ void refresh(UIManagedObject object, UIObject.Visitor scope)
{
@@ -336,31 +336,33 @@
* @param structuralObject the structural object to update
* @return the object API implementation
*/
- private AbstractUIObject update(StructuralObject structuralObject)
+ private UIContainerObject update(StructuralObject structuralObject)
{
- AbstractUIObject object = universe.get(structuralObject.getId());
+ UIContainerObject containerObject = universe.get(structuralObject.getId());
//
- if (object == null)
+ if (containerObject == null)
{
- //
- UIObjectContext context = new UIObjectContext(this, structuralObject);
+ containerObject = new
UIObjectFactory().createObject(structuralObject.getState().getType());
//
- object = new UIObjectFactory().createObject(context);
+ containerObject.setContext(new UIObjectContext(this, structuralObject));
//
- universe.put(structuralObject.getId(), object);
+ universe.put(structuralObject.getId(), containerObject);
}
else
{
- object.context.structuralObject = structuralObject;
- object.parentRelationship.clear();
- object.childrenRelationship.clear();
+ UIObjectContext context = containerObject.getContext();
+
+ //
+ context.structuralObject = structuralObject;
+ context.managedObject.parentRelationship.clear();
+ context.managedObject.childrenRelationship.clear();
}
//
- return object;
+ return containerObject;
}
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-21
18:34:54 UTC (rev 9378)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-21
21:28:29 UTC (rev 9379)
@@ -49,6 +49,9 @@
/** . */
UIObject.Status status;
+ /** . */
+ UIManagedObject managedObject;
+
public UIObjectContext(UIObjectContainer container, StructuralObject
structuralObject)
{
if (container == null)
@@ -64,20 +67,16 @@
this.container = container;
this.structuralObject = structuralObject;
this.status = UIObject.Status.VALID;
+ this.managedObject = new UIManagedObject(this);
}
// Public
***********************************************************************************************************
- public StructuralState getState()
+ public UIObject getManagedObject()
{
- return structuralObject.getState();
+ return managedObject;
}
- public UIContext getRoot()
- {
- return container.root;
- }
-
public UIObject getObject(String id)
{
return container.getObject(id, true);
@@ -88,12 +87,24 @@
container.addModelListener(listener);
}
- public UIObject.Status getStatus()
+ //
+
+ StructuralState getState()
{
+ return structuralObject.getState();
+ }
+
+ UIContext getRoot()
+ {
+ return container.root;
+ }
+
+ UIObject.Status getStatus()
+ {
return status;
}
- public boolean isValid()
+ boolean isValid()
{
return status == UIObject.Status.VALID;
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java 2007-12-21
18:34:54 UTC (rev 9378)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectFactory.java 2007-12-21
21:28:29 UTC (rev 9379)
@@ -27,6 +27,7 @@
import org.jboss.portal.presentation.model.UIPage;
import org.jboss.portal.presentation.model.UIContainer;
import org.jboss.portal.presentation.model.UIWindow;
+import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.impl.model.UIContextImpl;
import org.jboss.portal.presentation.impl.model.UIPortalImpl;
import org.jboss.portal.presentation.impl.model.UIPageImpl;
@@ -40,34 +41,59 @@
public class UIObjectFactory
{
- public AbstractUIObject createObject(UIObjectContext context)
+ public UIContainerObject createObject(Class<? extends UIObject> type)
{
- Class type = context.getState().getType();
-
- //
if(type == UIContext.class)
{
- return new UIContextImpl(context);
+ return new UIContextImpl();
}
else if(type == UIPortal.class)
{
- return new UIPortalImpl(context);
+ return new UIPortalImpl();
}
else if(type == UIPage.class)
{
- return new UIPageImpl(context);
+ return new UIPageImpl();
}
else if(type == UIContainer.class)
{
- return new UIContainerImpl(context);
+ return new UIContainerImpl();
}
else if(type == UIWindow.class)
{
- return new UIWindowImpl(context);
+ return new UIWindowImpl();
}
else
{
throw new AssertionError();
}
}
+
+// public <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
+// {
+// if(type == UIContext.class)
+// {
+// return type == UIPortal.class;
+// }
+// else if (type == UIPortal.class)
+// {
+// return type == UIPage.class;
+// }
+// else if (type == UIPage.class)
+// {
+// return type == UIPage.class || type == UIContainer.class || type ==
UIWindow.class;
+// }
+// else if (type == UIContainer.class)
+// {
+// return type == UIWindow.class;
+// }
+// else if (type == UIWindow.class)
+// {
+// return false;
+// }
+// else
+// {
+// throw new AssertionError();
+// }
+// }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java 2007-12-21
18:34:54 UTC (rev 9378)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectManyToOne.java 2007-12-21
21:28:29 UTC (rev 9379)
@@ -28,7 +28,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-final class UIObjectManyToOne extends UIObjectRelationship<AbstractUIObject>
+final class UIObjectManyToOne extends UIObjectRelationship<UIContainerObject>
{
/** . */
@@ -39,12 +39,12 @@
this.owner = owner;
}
- protected AbstractUIObject doLoad()
+ protected UIContainerObject doLoad()
{
return owner.container.getParent(owner.structuralObject);
}
- protected void doEvict(AbstractUIObject abstractUIObject)
+ protected void doEvict(UIContainerObject abstractUIObject)
{
}
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java 2007-12-21
18:34:54 UTC (rev 9378)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectOneToMany.java 2007-12-21
21:28:29 UTC (rev 9379)
@@ -29,7 +29,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-final class UIObjectOneToMany extends
UIObjectRelationship<List<AbstractUIObject>>
+final class UIObjectOneToMany extends
UIObjectRelationship<List<UIContainerObject>>
{
/** . */
@@ -39,7 +39,7 @@
private final UIObjectContext owner;
/** . */
- private List<AbstractUIObject> content;
+ private List<UIContainerObject> content;
UIObjectOneToMany(UIObjectContext object)
{
@@ -47,19 +47,19 @@
this.list = new ProxyList();
}
- protected List<AbstractUIObject> doLoad()
+ protected List<UIContainerObject> doLoad()
{
return list;
}
- protected void doEvict(List<AbstractUIObject> abstractUIObjects)
+ protected void doEvict(List<UIContainerObject> abstractUIObjects)
{
content = null;
}
- private class ProxyList extends AbstractList<AbstractUIObject>
+ private class ProxyList extends AbstractList<UIContainerObject>
{
- public AbstractUIObject get(int i)
+ public UIContainerObject get(int i)
{
if (!owner.isValid())
{