Author: julien(a)jboss.com
Date: 2007-11-26 08:59:04 -0500 (Mon, 26 Nov 2007)
New Revision: 9105
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/UIWindowImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/StateScopeType.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
Log:
store content and navigational state of window as scoped properties
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-26
12:35:20 UTC (rev 9104)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-11-26
13:59:04 UTC (rev 9105)
@@ -22,14 +22,15 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.model;
+import org.jboss.portal.common.NotYetImplemented;
import org.jboss.portal.presentation.model.StateScopeType;
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.state.ObjectState;
import java.io.Serializable;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.HashMap;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -61,12 +62,12 @@
/**
*
*/
- private final Map<String, String> transientState;
+ private final Map<String, Object> transientState;
/**
*
*/
- private final Map<String, String> navigationalState;
+ private final Map<String, Object> navigationalState;
public UIObjectImpl(UIContextImpl context, String id, ObjectState state)
{
@@ -74,8 +75,8 @@
this.state = state;
this.context = context;
this.children = new UIObjectList(this.context, state.getChildrenIds());
- this.transientState = new HashMap<String, String>();
- this.navigationalState = new HashMap<String, String>();
+ this.transientState = new HashMap<String, Object>();
+ this.navigationalState = new HashMap<String, Object>();
}
public UIObjectImpl(String id, ObjectState state)
@@ -84,8 +85,8 @@
this.state = state;
this.context = (UIContextImpl)this;
this.children = new UIObjectList(this.context, state.getChildrenIds());
- this.transientState = new HashMap<String, String>();
- this.navigationalState = new HashMap<String, String>();
+ this.transientState = new HashMap<String, Object>();
+ this.navigationalState = new HashMap<String, Object>();
}
//UIObject interface
implementation-----------------------------------------------------------------------------------------------------------------------------
@@ -97,21 +98,81 @@
return this.id;
}
- public String getProperty(StateScopeType scopeType, String propertyName)
+ /**
+ * 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 <T> T getProperty(StateScopeType scopeType, String propertyName,
Class<T> propertyType)
+ {
+ Map map;
switch (scopeType)
{
case TRANSIENT:
- return transientState.get(propertyName);
+ map = transientState;
+ break;
case NAVIGATIONAL:
- return navigationalState.get(propertyName);
+ map = navigationalState;
+ break;
case PERSISTENT:
- return state.getProperties().get(propertyName);
+ map = state.getProperties();
+ break;
default:
throw new AssertionError();
}
+ return safeCast(map.get(propertyName), propertyType);
}
+ public <T> void setProperty(StateScopeType scopeType, String propertyName, T
propertyValue)
+ {
+ Map map;
+ switch (scopeType)
+ {
+ case TRANSIENT:
+ map = transientState;
+ break;
+ case NAVIGATIONAL:
+ map = navigationalState;
+ break;
+ case PERSISTENT:
+ throw new NotYetImplemented();
+ default:
+ throw new AssertionError();
+ }
+ if (propertyValue == null)
+ {
+ map.remove(propertyName);
+ }
+ else
+ {
+ map.put(propertyName, propertyValue);
+ }
+ }
+
public UIObject getChild(String name)
{
for (UIObject child : getChildren())
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-11-26
12:35:20 UTC (rev 9104)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java 2007-11-26
13:59:04 UTC (rev 9105)
@@ -24,10 +24,11 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
+import org.jboss.portal.presentation.model.StateScopeType;
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.model.state.ObjectState;
import org.jboss.portal.presentation.model.content.WindowContent;
+import org.jboss.portal.presentation.model.state.ObjectState;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -36,39 +37,19 @@
public class UIWindowImpl extends UIObjectImpl implements UIWindow
{
- /** . */
- private Mode mode = null;
-
- /** . */
- private WindowState windowState = null;
-
- /** . */
- private Object contentState = null;
-
- /** . */
- private WindowContent content = null;
-
public UIWindowImpl(UIContextImpl context, String id, ObjectState state)
{
super(context, id, state);
}
- /**
- *
- * @return
- */
public WindowContent getContent()
{
- return content;
+ return getProperty(StateScopeType.TRANSIENT, "content",
WindowContent.class);
}
- /**
- *
- * @param content
- */
- public void setContent(WindowContent content)
+ public void setContent(WindowContent windowContent)
{
- this.content = content;
+ setProperty(StateScopeType.TRANSIENT, "content", windowContent);
}
/**
@@ -76,7 +57,7 @@
*/
public Mode getMode()
{
- return this.mode;
+ return getProperty(StateScopeType.NAVIGATIONAL, "mode", Mode.class);
}
/**
@@ -84,7 +65,7 @@
*/
public WindowState getWindowState()
{
- return this.windowState;
+ return getProperty(StateScopeType.NAVIGATIONAL, "windowstate",
WindowState.class);
}
/**
@@ -92,8 +73,8 @@
*/
public void setMode(Mode mode)
{
- this.mode = mode;
- this.content = null;
+ setProperty(StateScopeType.NAVIGATIONAL, "mode", mode);
+ setProperty(StateScopeType.TRANSIENT, "content", null);
}
/**
@@ -101,19 +82,19 @@
*/
public void setWindowState(WindowState windowState)
{
- this.windowState = windowState;
- this.content = null;
+ setProperty(StateScopeType.NAVIGATIONAL, "windowstate", windowState);
+ setProperty(StateScopeType.TRANSIENT, "content", null);
}
public Object getContentState()
{
- return contentState;
+ return getProperty(StateScopeType.NAVIGATIONAL, "content",
Object.class);
}
public void setContentState(Object contentState)
{
- this.contentState = contentState;
- this.content = null;
+ setProperty(StateScopeType.NAVIGATIONAL, "content", contentState);
+ setProperty(StateScopeType.TRANSIENT, "content", null);
}
/**
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/StateScopeType.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/StateScopeType.java 2007-11-26
12:35:20 UTC (rev 9104)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/StateScopeType.java 2007-11-26
13:59:04 UTC (rev 9105)
@@ -29,7 +29,7 @@
public enum StateScopeType
{
/**
- * The transient scope type.
+ * The transient scope type.
*/
TRANSIENT,
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-11-26
12:35:20 UTC (rev 9104)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-11-26
13:59:04 UTC (rev 9105)
@@ -50,8 +50,9 @@
UIObject getChild(String name);
+ <T> T getProperty(StateScopeType scopeType, String propertyName, Class<T>
propertyType);
- String getProperty(StateScopeType scopeType, String propertyName);
+ <T> void setProperty(StateScopeType scopeType, String propertyName, T
propertyValue);
/**
* Create a child with a specified type.