From portal-commits at lists.jboss.org Mon Nov 26 08:59:05 2007 Content-Type: multipart/mixed; boundary="===============5648848267807635933==" MIME-Version: 1.0 From: portal-commits at lists.jboss.org To: portal-commits at lists.jboss.org Subject: [portal-commits] JBoss Portal SVN: r9105 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: model and 1 other directory. Date: Mon, 26 Nov 2007 08:59:04 -0500 Message-ID: --===============5648848267807635933== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/presentatio= n/impl/model/UIObjectImpl.java branches/presentation/presentation/src/main/org/jboss/portal/presentatio= n/impl/model/UIWindowImpl.java branches/presentation/presentation/src/main/org/jboss/portal/presentatio= n/model/StateScopeType.java branches/presentation/presentation/src/main/org/jboss/portal/presentatio= n/model/UIObject.java Log: store content and navigational state of window as scoped properties Modified: branches/presentation/presentation/src/main/org/jboss/portal/pres= entation/impl/model/UIObjectImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/presentation/presentation/src/main/org/jboss/portal/presentati= on/impl/model/UIObjectImpl.java 2007-11-26 12:35:20 UTC (rev 9104) +++ branches/presentation/presentation/src/main/org/jboss/portal/presentati= on/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 Sohil Shah @@ -61,12 +62,12 @@ /** * */ - private final Map transientState; + private final Map transientState; = /** * */ - private final Map navigationalState; + private final Map navigationalState; = public UIObjectImpl(UIContextImpl context, String id, ObjectState state) { @@ -74,8 +75,8 @@ this.state =3D state; this.context =3D context; this.children =3D new UIObjectList(this.context, state.getChildrenId= s()); - this.transientState =3D new HashMap(); - this.navigationalState =3D new HashMap(); + this.transientState =3D new HashMap(); + this.navigationalState =3D new HashMap(); } = public UIObjectImpl(String id, ObjectState state) @@ -84,8 +85,8 @@ this.state =3D state; this.context =3D (UIContextImpl)this; this.children =3D new UIObjectList(this.context, state.getChildrenId= s()); - this.transientState =3D new HashMap(); - this.navigationalState =3D new HashMap(); + this.transientState =3D new HashMap(); + this.navigationalState =3D new HashMap(); } = //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 safeCast(Object value, Class type) { + if (value =3D=3D null) + { + return null; + } + else + { + if (type.isAssignableFrom(value.getClass())) + { + return type.cast(value); + } + else + { + return null; + } + } + } + + public T getProperty(StateScopeType scopeType, String propertyName,= Class propertyType) + { + Map map; switch (scopeType) { case TRANSIENT: - return transientState.get(propertyName); + map =3D transientState; + break; case NAVIGATIONAL: - return navigationalState.get(propertyName); + map =3D navigationalState; + break; case PERSISTENT: - return state.getProperties().get(propertyName); + map =3D state.getProperties(); + break; default: throw new AssertionError(); } + return safeCast(map.get(propertyName), propertyType); } = + public void setProperty(StateScopeType scopeType, String propertyNa= me, T propertyValue) + { + Map map; + switch (scopeType) + { + case TRANSIENT: + map =3D transientState; + break; + case NAVIGATIONAL: + map =3D navigationalState; + break; + case PERSISTENT: + throw new NotYetImplemented(); + default: + throw new AssertionError(); + } + if (propertyValue =3D=3D 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/pres= entation/impl/model/UIWindowImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/presentation/presentation/src/main/org/jboss/portal/presentati= on/impl/model/UIWindowImpl.java 2007-11-26 12:35:20 UTC (rev 9104) +++ branches/presentation/presentation/src/main/org/jboss/portal/presentati= on/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 Sohil Shah @@ -36,39 +37,19 @@ public class UIWindowImpl extends UIObjectImpl implements UIWindow { = - /** . */ - private Mode mode =3D null; - = - /** . */ - private WindowState windowState =3D null; - - /** . */ - private Object contentState =3D null; - - /** . */ - private WindowContent content =3D null; - public UIWindowImpl(UIContextImpl context, String id, ObjectState state) { super(context, id, state); } = - /** - * = - * @return - */ public WindowContent getContent() { - return content; + return getProperty(StateScopeType.TRANSIENT, "content", WindowConten= t.class); } = - /** - * = - * @param content - */ - public void setContent(WindowContent content) + public void setContent(WindowContent windowContent) { - this.content =3D 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", Windo= wState.class); } = /** @@ -92,8 +73,8 @@ */ public void setMode(Mode mode) { - this.mode =3D mode; - this.content =3D null; + setProperty(StateScopeType.NAVIGATIONAL, "mode", mode); + setProperty(StateScopeType.TRANSIENT, "content", null); } = /** @@ -101,19 +82,19 @@ */ public void setWindowState(WindowState windowState) { - this.windowState =3D windowState; - this.content =3D null; + setProperty(StateScopeType.NAVIGATIONAL, "windowstate", windowState); + setProperty(StateScopeType.TRANSIENT, "content", null); } = public Object getContentState() { - return contentState; + return getProperty(StateScopeType.NAVIGATIONAL, "content", Object.cl= ass); } = public void setContentState(Object contentState) { - this.contentState =3D contentState; - this.content =3D null; + setProperty(StateScopeType.NAVIGATIONAL, "content", contentState); + setProperty(StateScopeType.TRANSIENT, "content", null); } = /** Modified: branches/presentation/presentation/src/main/org/jboss/portal/pres= entation/model/StateScopeType.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/presentation/presentation/src/main/org/jboss/portal/presentati= on/model/StateScopeType.java 2007-11-26 12:35:20 UTC (rev 9104) +++ branches/presentation/presentation/src/main/org/jboss/portal/presentati= on/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/pres= entation/model/UIObject.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/presentation/presentation/src/main/org/jboss/portal/presentati= on/model/UIObject.java 2007-11-26 12:35:20 UTC (rev 9104) +++ branches/presentation/presentation/src/main/org/jboss/portal/presentati= on/model/UIObject.java 2007-11-26 13:59:04 UTC (rev 9105) @@ -50,8 +50,9 @@ = UIObject getChild(String name); = + T getProperty(StateScopeType scopeType, String propertyName, Class<= T> propertyType); = - String getProperty(StateScopeType scopeType, String propertyName); + void setProperty(StateScopeType scopeType, String propertyName, T p= ropertyValue); = /** * Create a child with a specified type. --===============5648848267807635933==--