Author: chris.laprun(a)jboss.com
Date: 2010-02-25 18:10:54 -0500 (Thu, 25 Feb 2010)
New Revision: 1870
Added:
components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/state/producer/AbstractPortletStatePersistenceManager.java
Modified:
components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/impl/state/producer/PortletStatePersistenceManagerService.java
Log:
- Extracted non-persistence-specific code from PortletStatePersistenceManagerService into
AbstractPortletStatePersistenceManager as a
base for reuse in other implementations.
Modified:
components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/impl/state/producer/PortletStatePersistenceManagerService.java
===================================================================
---
components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/impl/state/producer/PortletStatePersistenceManagerService.java 2010-02-25
23:04:21 UTC (rev 1869)
+++
components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/impl/state/producer/PortletStatePersistenceManagerService.java 2010-02-25
23:10:54 UTC (rev 1870)
@@ -1,34 +1,32 @@
-/******************************************************************************
- * 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. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, 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.gatein.pc.portlet.impl.state.producer;
-import org.gatein.pc.portlet.state.InvalidStateIdException;
-import org.gatein.pc.portlet.state.NoSuchStateException;
import org.gatein.pc.api.state.PropertyMap;
+import org.gatein.pc.portlet.state.InvalidStateIdException;
import org.gatein.pc.portlet.state.SimplePropertyMap;
-import org.gatein.pc.portlet.state.producer.PortletStatePersistenceManager;
+import org.gatein.pc.portlet.state.producer.AbstractPortletStatePersistenceManager;
import org.gatein.pc.portlet.state.producer.PortletStateContext;
-import org.gatein.pc.portlet.state.producer.PortletState;
import java.util.HashMap;
import java.util.Map;
@@ -39,7 +37,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 7215 $
*/
-public class PortletStatePersistenceManagerService implements
PortletStatePersistenceManager
+public class PortletStatePersistenceManagerService extends
AbstractPortletStatePersistenceManager
{
/** . */
@@ -48,83 +46,33 @@
/** . */
private int counter = 0;
- public synchronized PortletStateContext loadState(String stateId) throws
IllegalArgumentException, NoSuchStateException, InvalidStateIdException
+ @Override
+ protected synchronized PortletStateContext getStateContext(String stateId) throws
InvalidStateIdException
{
- if (stateId == null)
- {
- throw new IllegalArgumentException("No null state id accepted");
- }
- try
- {
- Integer.parseInt(stateId);
- }
- catch (NumberFormatException e)
- {
- throw new InvalidStateIdException(e, stateId);
- }
- PortletStateContext context = store.get(stateId);
- if (context == null)
- {
- throw new NoSuchStateException(stateId);
- }
- return context;
- }
+ checkId(stateId);
- private synchronized PortletState getState(String stateId) throws
NoSuchStateException, InvalidStateIdException
- {
- PortletStateContext context = loadState(stateId);
- return context.getState();
+ return store.get(stateId);
}
- public synchronized String createState(String portletId, PropertyMap propertyMap)
+ @Override
+ protected synchronized String createStateContext(String portletId, PropertyMap
propertyMap)
{
- if (portletId == null)
- {
- throw new IllegalArgumentException("No null portlet id accepted");
- }
- if (propertyMap == null)
- {
- throw new IllegalArgumentException("No null value map accepted");
- }
String id = Integer.toString(counter++);
PortletStateContext state = new PortletStateContextImpl(id, portletId, new
SimplePropertyMap(propertyMap));
store.put(id, state);
return id;
}
- public synchronized String cloneState(String stateId, PropertyMap propertyMap) throws
NoSuchStateException, InvalidStateIdException
+ @Override
+ protected synchronized PortletStateContext destroyStateContext(String stateId) throws
InvalidStateIdException
{
- if (propertyMap == null)
- {
- throw new IllegalArgumentException();
- }
- PortletState stateContext = getState(stateId);
- return createState(stateContext.getPortletId(), propertyMap);
- }
+ checkId(stateId);
- public String cloneState(String stateId) throws IllegalArgumentException,
NoSuchStateException, InvalidStateIdException
- {
- PortletState state = getState(stateId);
- return createState(state.getPortletId(), new
SimplePropertyMap(state.getProperties()));
+ return store.remove(stateId);
}
- public synchronized void updateState(String stateId, PropertyMap propertyMap) throws
NoSuchStateException, InvalidStateIdException
+ private void checkId(String stateId) throws InvalidStateIdException
{
- if (propertyMap == null)
- {
- throw new IllegalArgumentException("No null value map");
- }
- PortletState ctx = getState(stateId);
- ctx.getProperties().clear();
- ctx.getProperties().putAll(propertyMap);
- }
-
- public synchronized void destroyState(String stateId) throws InvalidStateIdException,
NoSuchStateException
- {
- if (stateId == null)
- {
- throw new IllegalArgumentException();
- }
try
{
Integer.parseInt(stateId);
@@ -133,12 +81,14 @@
{
throw new InvalidStateIdException(e, stateId);
}
- if (store.remove(stateId) == null)
- {
- throw new NoSuchStateException(stateId);
- }
}
+ @Override
+ protected void updateStateContext(PortletStateContext stateContext)
+ {
+ // nothing to do here
+ }
+
public synchronized int getSize()
{
return store.size();
Added:
components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/state/producer/AbstractPortletStatePersistenceManager.java
===================================================================
---
components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/state/producer/AbstractPortletStatePersistenceManager.java
(rev 0)
+++
components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/state/producer/AbstractPortletStatePersistenceManager.java 2010-02-25
23:10:54 UTC (rev 1870)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, 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.gatein.pc.portlet.state.producer;
+
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.state.PropertyMap;
+import org.gatein.pc.portlet.state.InvalidStateIdException;
+import org.gatein.pc.portlet.state.NoSuchStateException;
+import org.gatein.pc.portlet.state.SimplePropertyMap;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public abstract class AbstractPortletStatePersistenceManager implements
PortletStatePersistenceManager
+{
+ public PortletStateContext loadState(String stateId) throws IllegalArgumentException,
NoSuchStateException, InvalidStateIdException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(stateId, "state
id", null);
+
+ PortletStateContext context = getStateContext(stateId);
+ if (context == null)
+ {
+ throw new NoSuchStateException(stateId);
+ }
+ return context;
+ }
+
+ protected PortletState getState(String stateId) throws NoSuchStateException,
InvalidStateIdException
+ {
+ PortletStateContext context = loadState(stateId);
+ return context.getState();
+ }
+
+ public String createState(String portletId, PropertyMap propertyMap)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(portletId, "portlet
id", null);
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyMap, "property
map");
+
+ return createStateContext(portletId, propertyMap);
+ }
+
+ public String cloneState(String stateId, PropertyMap propertyMap) throws
NoSuchStateException, InvalidStateIdException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyMap, "property
map");
+
+ PortletState stateContext = getState(stateId);
+ return createState(stateContext.getPortletId(), propertyMap);
+ }
+
+ public String cloneState(String stateId) throws IllegalArgumentException,
NoSuchStateException, InvalidStateIdException
+ {
+ PortletState state = getState(stateId);
+ return createState(state.getPortletId(), new
SimplePropertyMap(state.getProperties()));
+ }
+
+ public void updateState(String stateId, PropertyMap propertyMap) throws
NoSuchStateException, InvalidStateIdException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyMap, "property
map");
+
+ PortletStateContext ctx = loadState(stateId);
+ PortletState state = ctx.getState();
+ PropertyMap props = state.getProperties();
+ props.clear();
+ props.putAll(propertyMap);
+ updateStateContext(ctx);
+ }
+
+ public void destroyState(String stateId) throws InvalidStateIdException,
NoSuchStateException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(stateId, "state
id", null);
+
+ if (destroyStateContext(stateId) == null)
+ {
+ throw new NoSuchStateException(stateId);
+ }
+ }
+
+ protected abstract PortletStateContext getStateContext(String stateId) throws
InvalidStateIdException;
+
+ protected abstract String createStateContext(String portletId, PropertyMap
propertyMap);
+
+ protected abstract PortletStateContext destroyStateContext(String stateId) throws
InvalidStateIdException;
+
+ protected abstract void updateStateContext(PortletStateContext stateContext);
+}