Author: chris.laprun(a)jboss.com
Date: 2008-04-10 20:20:05 -0400 (Thu, 10 Apr 2008)
New Revision: 10528
Added:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/state/AbstractPageNavigationalState.java
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/state/PageNavigationalStateImpl.java
Log:
- Added AbstractPageNavigationalState to make PageNavigationalState implementations
easier.
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/state/PageNavigationalStateImpl.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/state/PageNavigationalStateImpl.java 2008-04-10
23:32:30 UTC (rev 10527)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/state/PageNavigationalStateImpl.java 2008-04-11
00:20:05 UTC (rev 10528)
@@ -22,13 +22,10 @@
******************************************************************************/
package org.jboss.portal.portlet.controller.impl.state;
-import org.jboss.portal.common.util.ParameterMap;
-import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+import org.jboss.portal.portlet.controller.state.AbstractPageNavigationalState;
import org.jboss.portal.portlet.controller.state.WindowNavigationalState;
-import org.jboss.portal.portlet.info.ParameterInfo;
import org.jboss.portal.portlet.info.PortletInfo;
-import javax.xml.namespace.QName;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
@@ -38,35 +35,26 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class PageNavigationalStateImpl implements PageNavigationalState, Serializable
+public class PageNavigationalStateImpl extends AbstractPageNavigationalState implements
Serializable
{
-
/** . */
protected final StateControllerContextImpl context;
/** . */
protected final Map<String, WindowNavigationalState> windows;
- /** . */
- protected final Map<QName, String[]> page;
-
- /** . */
- private final boolean modifiable;
-
protected PageNavigationalStateImpl(StateControllerContextImpl context, boolean
modifiable)
{
+ super(modifiable);
this.context = context;
this.windows = new HashMap<String, WindowNavigationalState>();
- this.page = new HashMap<QName, String[]>();
- this.modifiable = modifiable;
}
public PageNavigationalStateImpl(PageNavigationalStateImpl original, boolean
modifiable)
{
+ super(modifiable, original.page);
this.context = original.context;
this.windows = new HashMap<String,
WindowNavigationalState>(original.windows);
- this.page = new HashMap<QName, String[]>(original.page);
- this.modifiable = modifiable;
}
public Set<String> getWindowIds()
@@ -79,47 +67,6 @@
return windows.get(windowId);
}
- public ParameterMap getPublicNavigationalState(String windowId)
- {
- PortletInfo info = context.portletControllerContext.getPortletInfo(windowId);
-
- //
- if (info != null)
- {
- ParameterMap publicNavigationalState = new ParameterMap();
- for (ParameterInfo parameterInfo : info.getNavigation().getPublicParameters())
- {
- String[] parameterValue = page.get(parameterInfo.getName());
-
- //
- if (parameterValue != null)
- {
- String parameterId = parameterInfo.getId();
-
- // We clone the value here so we keep the internal state not potentially
changed
- publicNavigationalState.put(parameterId, parameterValue.clone());
- }
- }
-
- //
- return publicNavigationalState;
- }
-
- //
- return null;
- }
-
- public Set<QName> getPublicNames()
- {
- return page.keySet();
- }
-
- public String[] getPublicNavigationalState(QName name)
- {
- String[] values = page.get(name);
- return values != null ? values.clone() : null;
- }
-
public void setWindowNavigationalState(String windowId, WindowNavigationalState
windowState)
{
if (!modifiable)
@@ -131,25 +78,8 @@
windows.put(windowId, windowState);
}
- public void setPublicNavigationalState(QName name, String[] value)
+ protected PortletInfo getPortletInfo(String windowId)
{
- if (!modifiable)
- {
- throw new IllegalStateException("The page navigational state is not
modifiable");
- }
-
- // We clone the value in order to keep the state not mutated by a side effect
- page.put(name, value.clone());
+ return context.portletControllerContext.getPortletInfo(windowId);
}
-
- public void removePublicNavigationalState(QName name)
- {
- if (!modifiable)
- {
- throw new IllegalStateException("The page navigational state is not
modifiable");
- }
-
- //
- page.remove(name);
- }
}
\ No newline at end of file
Added:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/state/AbstractPageNavigationalState.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/state/AbstractPageNavigationalState.java
(rev 0)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/state/AbstractPageNavigationalState.java 2008-04-11
00:20:05 UTC (rev 10528)
@@ -0,0 +1,120 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.portlet.controller.state;
+
+import org.jboss.portal.common.util.ParameterMap;
+import org.jboss.portal.portlet.info.ParameterInfo;
+import org.jboss.portal.portlet.info.PortletInfo;
+
+import javax.xml.namespace.QName;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public abstract class AbstractPageNavigationalState implements PageNavigationalState
+{
+ /** . */
+ protected final Map<QName, String[]> page;
+ /** . */
+ protected final boolean modifiable;
+
+ protected AbstractPageNavigationalState(boolean modifiable)
+ {
+ this(modifiable, new HashMap<QName, String[]>());
+ }
+
+ protected AbstractPageNavigationalState(boolean modifiable, Map<QName, String[]>
page)
+ {
+ this.modifiable = modifiable;
+ this.page = page;
+ }
+
+ public ParameterMap getPublicNavigationalState(String windowId)
+ {
+ PortletInfo info = getPortletInfo(windowId);
+
+ //
+ if (info != null)
+ {
+ ParameterMap publicNavigationalState = new ParameterMap();
+ for (ParameterInfo parameterInfo : info.getNavigation().getPublicParameters())
+ {
+ String[] parameterValue = page.get(parameterInfo.getName());
+
+ //
+ if (parameterValue != null)
+ {
+ String parameterId = parameterInfo.getId();
+
+ // We clone the value here so we keep the internal state not potentially
changed
+ publicNavigationalState.put(parameterId, parameterValue.clone());
+ }
+ }
+
+ //
+ return publicNavigationalState;
+ }
+
+ //
+ return null;
+ }
+
+ protected abstract PortletInfo getPortletInfo(String windowId);
+
+ public Set<QName> getPublicNames()
+ {
+ return page.keySet();
+ }
+
+ public String[] getPublicNavigationalState(QName name)
+ {
+ String[] values = page.get(name);
+ return values != null ? values.clone() : null;
+ }
+
+ public void setPublicNavigationalState(QName name, String[] value)
+ {
+ if (!modifiable)
+ {
+ throw new IllegalStateException("The page navigational state is not
modifiable");
+ }
+
+ // We clone the value in order to keep the state not mutated by a side effect
+ page.put(name, value.clone());
+ }
+
+ public void removePublicNavigationalState(QName name)
+ {
+ if (!modifiable)
+ {
+ throw new IllegalStateException("The page navigational state is not
modifiable");
+ }
+
+ //
+ page.remove(name);
+ }
+}