Author: julien(a)jboss.com
Date: 2007-11-28 08:46:43 -0500 (Wed, 28 Nov 2007)
New Revision: 9164
Added:
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/content/ContentStateContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
Modified:
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/server/PresentationServerImpl.java
branches/presentation/core-presentation/src/resources/presentation-sar/META-INF/jboss-service.xml
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/PresentationContextImpl.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/UIObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/server/PresentationServer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java
Log:
- delegate storage of navigational and content state to dedicated context which allow a
better control of the state life cycle of the overral model
Copied:
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java
(from rev 9141,
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateManagerImpl.java)
===================================================================
---
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java
(rev 0)
+++
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/model/StructuralStateContextImpl.java 2007-11-28
13:46:43 UTC (rev 9164)
@@ -0,0 +1,197 @@
+/******************************************************************************
+ * 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.core.presentation.model;
+
+import org.jboss.portal.core.model.portal.Page;
+import org.jboss.portal.core.model.portal.Portal;
+import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.model.portal.PortalObjectContainer;
+import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.model.portal.PortalObjectPath;
+import org.jboss.portal.core.model.portal.Window;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.UIPage;
+import org.jboss.portal.presentation.model.UIPortal;
+import org.jboss.portal.presentation.model.UIWindow;
+import org.jboss.portal.presentation.model.state.structural.StructuralState;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class StructuralStateContextImpl implements StructuralStateContext
+{
+ /**
+ *
+ */
+ private PortalObjectContainer portalObjectContainer = null;
+
+ /**
+ *
+ * @return
+ */
+ public PortalObjectContainer getPortalObjectContainer()
+ {
+ return portalObjectContainer;
+ }
+
+ /**
+ *
+ * @param portalObjectContainer
+ */
+ public void setPortalObjectContainer(
+ PortalObjectContainer portalObjectContainer)
+ {
+ this.portalObjectContainer = portalObjectContainer;
+ }
+
+
+ public String getRootId()
+ {
+ return portalObjectContainer.getContext().getId().toString();
+ }
+
+ /**
+ *
+ */
+ public StructuralState load(String objectId) throws IllegalArgumentException
+ {
+ StructuralState structuralState = null;
+
+ // Get the PortalObject corresponding to this objectId from the
PortalObjectContainer
+ PortalObject portalObject =
this.portalObjectContainer.getObject(PortalObjectId.parse(objectId,
+ PortalObjectPath.CANONICAL_FORMAT));
+
+ if(portalObject == null)
+ {
+ // Object by this id was not found in the Portal
+ return null;
+ }
+
+ // Type
+ Class<? extends UIObject> type = this.getType(portalObject);
+
+ // Name
+ String name = portalObject.getName();
+
+ // Properties
+ Map<String, String> properties = portalObject.getDeclaredProperties();
+
+ // Parent Id
+ String parentId = null;
+ if(portalObject.getParent() != null)
+ {
+ parentId = portalObject.getParent().getId().toString();
+ }
+
+ //Children Ids
+ List<String> childrenIds = new ArrayList<String>();
+ Collection children = portalObject.getChildren();
+ for(Iterator itr=children.iterator(); itr.hasNext();)
+ {
+ PortalObject child = (PortalObject)itr.next();
+ childrenIds.add(child.getId().toString());
+ }
+
+ structuralState = new StructuralState(
+ type, //type
+ name,
+ properties, //properties
+ parentId,
+ childrenIds // childrenIds
+ );
+
+ return structuralState;
+ }
+
+ /**
+ *
+ * @param portalObject
+ * @return
+ */
+ private Class<? extends UIObject> getType(PortalObject portalObject)
+ {
+ Class<? extends UIObject> type = null;
+
+ if(portalObject instanceof Portal)
+ {
+ type = UIPortal.class;
+ }
+ else if(portalObject instanceof Page)
+ {
+ type = UIPage.class;
+ }
+ else if(portalObject instanceof Window)
+ {
+ type = UIWindow.class;
+ }
+
+ return type;
+ }
+
+ public StructuralState create(String parentId, Class<? extends UIObject> type,
String name, Map<String, String> properties) throws StateChangeVetoException
+ {
+ throw new StateChangeVetoException();
+ }
+
+ public void destroy(String objectId) throws StateChangeVetoException
+ {
+ throw new StateChangeVetoException();
+ }
+
+ public void move(String objectId, String parentId) throws StateChangeVetoException
+ {
+ throw new StateChangeVetoException();
+ }
+
+ public void update(String objectId, Map<String, String> changes) throws
StateChangeVetoException
+ {
+ throw new StateChangeVetoException();
+ }
+
+ /**
+ *
+ *
+ */
+ public void start()
+ {
+
+ }
+
+ /**
+ *
+ *
+ */
+ public void stop()
+ {
+
+ }
+}
Modified:
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/server/PresentationServerImpl.java
===================================================================
---
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/server/PresentationServerImpl.java 2007-11-28
12:19:35 UTC (rev 9163)
+++
branches/presentation/core-presentation/src/main/org/jboss/portal/core/presentation/server/PresentationServerImpl.java 2007-11-28
13:46:43 UTC (rev 9164)
@@ -27,7 +27,7 @@
import org.jboss.portal.presentation.server.PresentationServer;
import org.jboss.portal.presentation.model.UIWindow;
import org.jboss.portal.presentation.model.state.content.WindowContent;
-import org.jboss.portal.presentation.model.state.structural.StructuralStateManager;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import org.jboss.portal.core.controller.ControllerResponse;
import org.jboss.portal.core.model.portal.command.response.MarkupResponse;
import org.jboss.portal.core.model.portal.PortalObjectId;
@@ -56,7 +56,7 @@
/**
*
*/
- private StructuralStateManager structuralStateManager;
+ private StructuralStateContext structuralStateContext;
/**
*
@@ -98,18 +98,18 @@
/**
*
*/
- public StructuralStateManager getStructuralStateManager()
+ public StructuralStateContext getStructuralStateManager()
{
- return structuralStateManager;
+ return structuralStateContext;
}
/**
*
- * @param structuralStateManager
+ * @param structuralStateContext
*/
- public void setModelLoader(StructuralStateManager structuralStateManager)
+ public void setModelLoader(StructuralStateContext structuralStateContext)
{
- this.structuralStateManager = structuralStateManager;
+ this.structuralStateContext = structuralStateContext;
}
/**
Modified:
branches/presentation/core-presentation/src/resources/presentation-sar/META-INF/jboss-service.xml
===================================================================
---
branches/presentation/core-presentation/src/resources/presentation-sar/META-INF/jboss-service.xml 2007-11-28
12:19:35 UTC (rev 9163)
+++
branches/presentation/core-presentation/src/resources/presentation-sar/META-INF/jboss-service.xml 2007-11-28
13:46:43 UTC (rev 9164)
@@ -82,7 +82,7 @@
<depends optional-attribute-name="CustomizationManager"
proxy-type="attribute">portal:service=CustomizationManager</depends>
</mbean>
<mbean
-
code="org.jboss.portal.core.presentation.model.StructuralStateManagerImpl"
+
code="org.jboss.portal.core.presentation.model.StructuralStateContextImpl"
name="portal:container=ModelLoader"
xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/PresentationContextImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/PresentationContextImpl.java 2007-11-28
12:19:35 UTC (rev 9163)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/PresentationContextImpl.java 2007-11-28
13:46:43 UTC (rev 9164)
@@ -24,6 +24,8 @@
import org.jboss.portal.presentation.client.PresentationContext;
import org.jboss.portal.presentation.impl.model.UIContextImpl;
+import org.jboss.portal.presentation.impl.model.state.content.ContentStateContextImpl;
+import
org.jboss.portal.presentation.impl.model.state.navigational.NavigationalStateContextImpl;
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.protocol.LinkActivation;
@@ -71,14 +73,14 @@
public UIContext getUIContext()
{
HttpSession session =
this.invocation.getServerContext().getClientRequest().getSession();
-
+
+
UIContext uiContext = (UIContext)session.getAttribute("uicontext");
+
+
if(uiContext == null)
{
- /**
- * TODO: decouple the implementation via factory pattern
- */
- uiContext = new
UIContextImpl(this.presentationServer.getStructuralStateManager());
+ uiContext = new
UIContextImpl(this.presentationServer.getStructuralStateManager(), new
NavigationalStateContextImpl(), new ContentStateContextImpl());
session.setAttribute("uicontext", uiContext);
}
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-11-28
12:19:35 UTC (rev 9163)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-11-28
13:46:43 UTC (rev 9164)
@@ -22,18 +22,20 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.model;
-import java.util.Map;
-import java.util.HashMap;
-
+import org.jboss.portal.presentation.model.UIContainer;
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.UIPage;
import org.jboss.portal.presentation.model.UIPortal;
-import org.jboss.portal.presentation.model.UIPage;
-import org.jboss.portal.presentation.model.UIContainer;
import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.model.state.structural.StructuralStateManager;
+import org.jboss.portal.presentation.model.state.content.ContentStateContext;
+import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
import org.jboss.portal.presentation.model.state.structural.StructuralState;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
@@ -44,27 +46,36 @@
/** . */
Map<String, UIObject> objects = new HashMap<String, UIObject>();
- /**
- *
- */
- private StructuralStateManager structuralStateManager = null;
+ /** . */
+ protected final StructuralStateContext structuralStateContext;
- private static String getRootId(StructuralStateManager loader)
+ /** . */
+ protected final NavigationalStateContext navigationalStateContext;
+
+ /** . */
+ protected final ContentStateContext contentStateContext;
+
+ private static String getRootId(StructuralStateContext loader)
{
return loader.getRootId();
}
- private static StructuralState getRootState(StructuralStateManager loader)
+ private static StructuralState getRootState(StructuralStateContext loader)
{
return loader.load(loader.getRootId());
}
- public UIContextImpl(StructuralStateManager structuralStateManager)
+ public UIContextImpl(
+ StructuralStateContext structuralStateContext,
+ NavigationalStateContext navigationalStateContext,
+ ContentStateContext contentStateContext)
{
- super(getRootId(structuralStateManager), getRootState(structuralStateManager));
+ super(getRootId(structuralStateContext), getRootState(structuralStateContext));
//
- this.structuralStateManager = structuralStateManager;
+ this.structuralStateContext = structuralStateContext;
+ this.navigationalStateContext = navigationalStateContext;
+ this.contentStateContext = contentStateContext;
// Put our self in the object cache
objects.put(getId(), this);
@@ -81,7 +92,7 @@
if (object == null)
{
//Fetch the state of the UIObject in question
- StructuralState structuralState = this.structuralStateManager.load(id);
+ StructuralState structuralState = this.structuralStateContext.load(id);
object = getImplementation(id, structuralState);
objects.put(id, object);
}
@@ -124,9 +135,9 @@
/**
*
*/
- public StructuralStateManager getModelLoader()
+ public StructuralStateContext getModelLoader()
{
- return this.structuralStateManager;
+ return this.structuralStateContext;
}
/**
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-11-28
12:19:35 UTC (rev 9163)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-11-28
13:46:43 UTC (rev 9164)
@@ -24,8 +24,8 @@
import org.jboss.portal.presentation.model.StateScopeType;
import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.state.structural.StructuralState;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.state.structural.StructuralState;
import java.io.Serializable;
import java.util.HashMap;
@@ -39,44 +39,24 @@
public abstract class UIObjectImpl implements UIObject, Serializable
{
- /**
- *
- */
+ /** . */
protected final UIContextImpl context;
- /**
- *
- */
+ /** . */
protected final String id;
- /**
- *
- */
+ /** . */
protected final UIObjectList children;
- /**
- * This is used to assist with data needed during lazy loading, other state related
data etc
- */
+ /** This is used to assist with data needed during lazy loading, other state related
data etc... */
private StructuralState state;
- /**
- *
- */
- private final Map<String, Object> transientState;
-
- /**
- *
- */
- private final Map<String, Object> navigationalState;
-
public UIObjectImpl(UIContextImpl context, String id, StructuralState state)
{
this.id = id;
this.state = state;
this.context = context;
this.children = new UIObjectList(this.context, state.getChildrenIds());
- this.transientState = new HashMap<String, Object>();
- this.navigationalState = new HashMap<String, Object>();
}
public UIObjectImpl(String id, StructuralState state)
@@ -85,8 +65,6 @@
this.state = state;
this.context = (UIContextImpl)this;
this.children = new UIObjectList(this.context, state.getChildrenIds());
- this.transientState = new HashMap<String, Object>();
- this.navigationalState = new HashMap<String, Object>();
}
//UIObject interface
implementation-----------------------------------------------------------------------------------------------------------------------------
@@ -142,21 +120,22 @@
throw new IllegalArgumentException();
}
Map map;
+ Object value;
switch (scopeType)
{
case CONTENT:
- map = transientState;
+ value = context.contentStateContext.get(propertyName);
break;
case NAVIGATIONAL:
- map = navigationalState;
+ value = context.navigationalStateContext.get(propertyName);
break;
case STRUCTURAL:
- map = state.getProperties();
+ value = state.getProperties().get(propertyName);
break;
default:
throw new AssertionError();
}
- return safeCast(map.get(propertyName), propertyType);
+ return safeCast(value, propertyType);
}
public Object getProperty(StateScopeType scopeType, String propertyName)
@@ -177,10 +156,10 @@
switch (scopeType)
{
case CONTENT:
- updateProperty(transientState, propertyName, propertyValue);
+ context.contentStateContext.set(propertyName, propertyValue);
break;
case NAVIGATIONAL:
- updateProperty(navigationalState, propertyName, propertyValue);
+ context.navigationalStateContext.set(propertyName, propertyValue);
break;
case STRUCTURAL:
if (propertyValue instanceof String)
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIContext.java 2007-11-28
12:19:35 UTC (rev 9163)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIContext.java 2007-11-28
13:46:43 UTC (rev 9164)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.presentation.model;
-import org.jboss.portal.presentation.model.state.structural.StructuralStateManager;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -41,5 +41,5 @@
*
* @return
*/
- StructuralStateManager getModelLoader();
+ StructuralStateContext getModelLoader();
}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/content/ContentStateContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/content/ContentStateContext.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/content/ContentStateContext.java 2007-11-28
13:46:43 UTC (rev 9164)
@@ -0,0 +1,33 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.model.state.content;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface ContentStateContext
+{
+ void set(String key, Object contentState);
+ Object get(String key);
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateContext.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateContext.java 2007-11-28
13:46:43 UTC (rev 9164)
@@ -0,0 +1,33 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.model.state.navigational;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface NavigationalStateContext
+{
+ void set(String key, Object navigationalState);
+ Object get(String key);
+}
Copied:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
(from rev 9141,
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateManager.java)
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-11-28
13:46:43 UTC (rev 9164)
@@ -0,0 +1,111 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.model.state.structural;
+
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.NoSuchStateException;
+
+import java.util.Map;
+
+/**
+ * The structural state manager.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface StructuralStateContext
+{
+
+ /**
+ * Load the state of a specified object.
+ *
+ * @param objectId the object id
+ * @return the state of the object or null if such state does not exist
+ * @throws IllegalArgumentException if the object id argument is null
+ */
+ StructuralState load(String objectId) throws IllegalArgumentException;
+
+ /**
+ * Returns the id of the root object.
+ *
+ * @return the id of the root object.
+ */
+ String getRootId();
+
+ /**
+ * Create an object.
+ *
+ * @param parentId the id of the parent object
+ * @param type the type of the child
+ * @param name the name of the child
+ * @param properties the initial properties of the child
+ * @return the structural state of the child
+ * @throws StateChangeVetoException if the creation is vetoed
+ * @throws StateException a generic state exception
+ * @throws NoSuchStateException if the parent id does not point a valid state
+ * @throws IllegalArgumentException if an argument is null or not valid
+ */
+ StructuralState create(String parentId, Class<? extends UIObject> type, String
name, Map<String, String> properties) throws StateChangeVetoException,
StateException, IllegalArgumentException;
+
+ /**
+ * Destroy a specified object.
+ *
+ * @param objectId the object id to destroy
+ * @throws StateChangeVetoException if the creation is vetoed
+ * @throws StateException a generic state exception
+ * @throws NoSuchStateException if the object id does not point a valid state
+ * @throws IllegalArgumentException if an argument is null or not valid
+ */
+ void destroy(String objectId) throws StateChangeVetoException, StateException,
IllegalArgumentException;
+
+ /**
+ * Move an object to a new parent.
+ *
+ * @param objectId the object id to move
+ * @param parentId the id of the new parent
+ * @throws StateChangeVetoException if the creation is vetoed
+ * @throws StateException a generic state exception
+ * @throws NoSuchStateException if the object id does not point a valid state
+ * @throws IllegalArgumentException if an argument is null or not valid
+ */
+ void move(String objectId, String parentId) throws StateChangeVetoException,
StateException, IllegalArgumentException;
+
+ /**
+ * Update the state of a specified object. The <code>Map</code> values are
interpreted as follow:
+ * <ul>
+ * <li>Each non null value will replace an existing value of create a new
one</li>
+ * <li>Each null value will destroy an existing value</li>
+ * </ul>
+ *
+ * @param objectId the id of the object to udpate
+ * @param changes the changes
+ * @throws StateChangeVetoException if the creation is vetoed
+ * @throws StateException a generic state exception
+ * @throws NoSuchStateException if the object id does not point a valid state
+ * @throws IllegalArgumentException if an argument is null or not valid
+ */
+ void update(String objectId, Map<String, String> changes) throws
StateChangeVetoException, StateException, IllegalArgumentException;
+
+}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/server/PresentationServer.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/server/PresentationServer.java 2007-11-28
12:19:35 UTC (rev 9163)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/server/PresentationServer.java 2007-11-28
13:46:43 UTC (rev 9164)
@@ -25,7 +25,7 @@
import org.jboss.portal.presentation.client.PresentationContext;
import org.jboss.portal.presentation.model.UIWindow;
import org.jboss.portal.presentation.model.state.content.WindowContent;
-import org.jboss.portal.presentation.model.state.structural.StructuralStateManager;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -53,5 +53,5 @@
*
* @return
*/
- StructuralStateManager getStructuralStateManager();
+ StructuralStateContext getStructuralStateManager();
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java 2007-11-28
12:19:35 UTC (rev 9163)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModel.java 2007-11-28
13:46:43 UTC (rev 9164)
@@ -27,7 +27,7 @@
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.structural.StructuralState;
-import org.jboss.portal.presentation.model.state.structural.StructuralStateManager;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import java.util.ArrayList;
import java.util.HashMap;
@@ -49,9 +49,9 @@
private final Map<String, MockObjectImpl> universe = new HashMap<String,
MockObjectImpl>();
/** . */
- private final MockObjectImpl context = new MockObjectImpl();
+ private final MockObjectImpl root = new MockObjectImpl();
- private final StructuralStateManager manager = new StructuralStateManager()
+ private final StructuralStateContext structuralStateContext = new
StructuralStateContext()
{
public StructuralState load(String objectId) throws IllegalArgumentException
{
@@ -65,7 +65,7 @@
public String getRootId()
{
- return context.id;
+ return root.id;
}
public StructuralState create(String parentId, Class<? extends UIObject>
type, String name, Map<String, String> properties) throws StateChangeVetoException
@@ -133,14 +133,14 @@
}
};
- public StructuralStateManager getManager()
+ public StructuralStateContext getStructuralStateContext()
{
- return manager;
+ return structuralStateContext;
}
- public MockObject getContext()
+ public MockObject getRoot()
{
- return context;
+ return root;
}
public void destroy(String objectId)
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-11-28
12:19:35 UTC (rev 9163)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-11-28
13:46:43 UTC (rev 9164)
@@ -26,6 +26,8 @@
import junit.framework.TestCase;
import org.apache.log4j.Logger;
import org.jboss.portal.presentation.impl.model.UIContextImpl;
+import org.jboss.portal.presentation.impl.model.state.content.ContentStateContextImpl;
+import
org.jboss.portal.presentation.impl.model.state.navigational.NavigationalStateContextImpl;
import org.jboss.portal.presentation.model.StateScopeType;
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.UIObject;
@@ -142,7 +144,7 @@
public void testSetPropertyThrowsIAE()
{
- UIContext context = new UIContextImpl(model.getManager());
+ UIContext context = createContext();
//
try
@@ -164,10 +166,15 @@
{
}
}
-
+
+ private UIContext createContext()
+ {
+ return new UIContextImpl(model.getStructuralStateContext(), new
NavigationalStateContextImpl(), new ContentStateContextImpl());
+ }
+
public void testGetPropertyThrowsIAE()
{
- UIContext context = new UIContextImpl(model.getManager());
+ UIContext context = createContext();
//
try
@@ -192,9 +199,9 @@
public void testLoadChildren() throws Exception
{
- MockObject mockDefaultPortal =
model.getContext().addChild("defaultPortal", MockObject.Type.PORTAL);
- MockObject mockSomeOtherPortal =
model.getContext().addChild("someOtherPortal", MockObject.Type.PORTAL);
- UIContext context = new UIContextImpl(model.getManager());
+ MockObject mockDefaultPortal = model.getRoot().addChild("defaultPortal",
MockObject.Type.PORTAL);
+ MockObject mockSomeOtherPortal =
model.getRoot().addChild("someOtherPortal", MockObject.Type.PORTAL);
+ UIContext context = createContext();
//
List<UIObject> children = context.getChildren();
@@ -222,9 +229,9 @@
public void testLoadParent() throws Exception
{
- MockObject mockDefaultPortal =
model.getContext().addChild("defaultPortal", MockObject.Type.PORTAL);
+ MockObject mockDefaultPortal = model.getRoot().addChild("defaultPortal",
MockObject.Type.PORTAL);
MockObject mockDefaultPage = mockDefaultPortal.addChild("defaultPage",
MockObject.Type.PAGE);
- UIContext context = new UIContextImpl(model.getManager());
+ UIContext context = createContext();
//
UIPage defaultPage = (UIPage)context.getObject(mockDefaultPage.getId());
@@ -278,8 +285,8 @@
public void testUpdatePropertyNonExistingObject()
{
- UIContext context = new UIContextImpl(model.getManager());
- MockObject mockFoo = model.getContext().addChild("foo",
MockObject.Type.PORTAL);
+ UIContext context = createContext();
+ MockObject mockFoo = model.getRoot().addChild("foo",
MockObject.Type.PORTAL);
UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
model.destroy(mockFoo.getId());
@@ -296,9 +303,9 @@
public void testUpdateExistingMutableStructuralProperty()
{
- MockObject mockFoo = model.getContext().addChild("foo",
MockObject.Type.PORTAL);
+ MockObject mockFoo = model.getRoot().addChild("foo",
MockObject.Type.PORTAL);
mockFoo.setPropertyValue("foo", "foo_value");
- UIContext context = new UIContextImpl(model.getManager());
+ UIContext context = createContext();
// Check initial state
UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
@@ -323,10 +330,10 @@
public void testUpdateExistingNonMutableStructuralProperty()
{
- MockObject mockFoo = model.getContext().addChild("foo",
MockObject.Type.PORTAL);
+ MockObject mockFoo = model.getRoot().addChild("foo",
MockObject.Type.PORTAL);
mockFoo.setPropertyValue("foo", "foo_value");
mockFoo.setPropertyBehavior("foo", MockObject.Failure.veto());
- UIContext context = new UIContextImpl(model.getManager());
+ UIContext context = createContext();
// Check initial state
UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
@@ -358,8 +365,8 @@
public void testUpdateNonExistingMutableStructuralProperty()
{
- MockObject mockFoo = model.getContext().addChild("foo",
MockObject.Type.PORTAL);
- UIContext context = new UIContextImpl(model.getManager());
+ MockObject mockFoo = model.getRoot().addChild("foo",
MockObject.Type.PORTAL);
+ UIContext context = createContext();
// Check initial state
UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
@@ -384,9 +391,9 @@
public void testUpdateNonExistingNonMutableStructuralProperty()
{
- MockObject mockFoo = model.getContext().addChild("foo",
MockObject.Type.PORTAL);
+ MockObject mockFoo = model.getRoot().addChild("foo",
MockObject.Type.PORTAL);
mockFoo.setPropertyBehavior("foo", MockObject.Failure.veto());
- UIContext context = new UIContextImpl(model.getManager());
+ UIContext context = createContext();
// Check initial state
UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
@@ -418,8 +425,8 @@
public void testUpdateContentProperty()
{
- MockObject mockFoo = model.getContext().addChild("foo",
MockObject.Type.PORTAL);
- UIContext context = new UIContextImpl(model.getManager());
+ MockObject mockFoo = model.getRoot().addChild("foo",
MockObject.Type.PORTAL);
+ UIContext context = createContext();
// Check initial state
UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
@@ -437,8 +444,8 @@
public void testUpdateNavigationalProperty()
{
- MockObject mockFoo = model.getContext().addChild("foo",
MockObject.Type.PORTAL);
- UIContext context = new UIContextImpl(model.getManager());
+ MockObject mockFoo = model.getRoot().addChild("foo",
MockObject.Type.PORTAL);
+ UIContext context = createContext();
// Check initial state
UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java 2007-11-28
12:19:35 UTC (rev 9163)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java 2007-11-28
13:46:43 UTC (rev 9164)
@@ -24,9 +24,10 @@
import junit.framework.TestCase;
import org.apache.log4j.Logger;
-
-import org.jboss.portal.presentation.model.*;
import org.jboss.portal.presentation.impl.model.UIContextImpl;
+import org.jboss.portal.presentation.impl.model.state.content.ContentStateContextImpl;
+import
org.jboss.portal.presentation.impl.model.state.navigational.NavigationalStateContextImpl;
+import org.jboss.portal.presentation.model.UIContext;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -42,7 +43,7 @@
*/
protected void setUp() throws Exception
{
- this.uiContext = new UIContextImpl(new MockModel().getManager());
+ this.uiContext = new UIContextImpl(new MockModel().getStructuralStateContext(), new
NavigationalStateContextImpl(), new ContentStateContextImpl());
}
/**