Author: chris.laprun(a)jboss.com
Date: 2011-04-07 13:25:59 -0400 (Thu, 07 Apr 2011)
New Revision: 6176
Modified:
components/pc/trunk/api/src/main/java/org/gatein/pc/api/PortletContext.java
components/pc/trunk/api/src/test/java/org/gatein/pc/api/PortletContextTestCase.java
components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/state/consumer/ConsumerPortletInvoker.java
components/pc/trunk/portlet/src/test/java/org/gatein/pc/test/portlet/state/AbstractStatefulPortletInvokerTestCase.java
components/pc/trunk/portlet/src/test/java/org/gatein/pc/test/portlet/state/ProducerStatefulPortletInvokerTestCase.java
Log:
- GTNPC-58: Added support for consumer clones.
Modified: components/pc/trunk/api/src/main/java/org/gatein/pc/api/PortletContext.java
===================================================================
--- components/pc/trunk/api/src/main/java/org/gatein/pc/api/PortletContext.java 2011-04-07
15:45:49 UTC (rev 6175)
+++ components/pc/trunk/api/src/main/java/org/gatein/pc/api/PortletContext.java 2011-04-07
17:25:59 UTC (rev 6176)
@@ -1,25 +1,25 @@
-/******************************************************************************
- * 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 2011, 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.api;
import org.gatein.common.util.ParameterValidation;
@@ -39,8 +39,14 @@
private static final char SEPARATOR = '.';
public static final String PRODUCER_CLONE_ID_PREFIX = "_";
+ public static final int PRODUCER_CLONE_PREFIX_LENGTH =
PRODUCER_CLONE_ID_PREFIX.length();
+
+ public static final String CONSUMER_CLONE_ID_PREFIX = "@";
+ public static final int CONSUMER_CLONE_PREFIX_LENGTH =
CONSUMER_CLONE_ID_PREFIX.length();
+
public static final String CONSUMER_CLONE_DUMMY_STATE_ID = "dumbvalue";
public static final String CONSUMER_CLONE_ID = PRODUCER_CLONE_ID_PREFIX +
CONSUMER_CLONE_DUMMY_STATE_ID;
+
public final static PortletContext LOCAL_CONSUMER_CLONE =
PortletContext.createPortletContext(PortletInvoker.LOCAL_PORTLET_INVOKER_ID + SEPARATOR +
CONSUMER_CLONE_ID);
protected final String id;
@@ -79,12 +85,12 @@
isSimpleAppPortlet = separator != -1 && appName.length() > 0
&& portletName.length() > 0;
if (isSimpleAppPortlet)
{
- components = new PortletContextComponents(null, appName, portletName,
false);
+ components = new PortletContextComponents(null, appName, portletName,
null);
}
}
else
{
- if (!trimmedId.startsWith(PRODUCER_CLONE_ID_PREFIX))
+ if (!(trimmedId.startsWith(PRODUCER_CLONE_ID_PREFIX) ||
trimmedId.startsWith(CONSUMER_CLONE_ID_PREFIX)))
{
int invoker = trimmedId.indexOf(SEPARATOR);
int prefix = trimmedId.indexOf(PREFIX);
@@ -106,7 +112,7 @@
isCompoundAppPortlet = invokerId.length() > 0 &&
applicationName.length() > 0 && portletName.length() > 0;
if (isCompoundAppPortlet)
{
- components = new PortletContextComponents(invokerId,
applicationName, portletName, false);
+ components = new PortletContextComponents(invokerId,
applicationName, portletName, null);
}
}
}
@@ -123,15 +129,22 @@
if (portletNameOrStateId.length() > 0)
{
- if
(portletNameOrStateId.startsWith(PRODUCER_CLONE_ID_PREFIX))
+ boolean isProducerClone =
portletNameOrStateId.startsWith(PRODUCER_CLONE_ID_PREFIX);
+ boolean isConsumerClone =
portletNameOrStateId.startsWith(CONSUMER_CLONE_ID_PREFIX);
+ if (isProducerClone || isConsumerClone)
{
- isCloned = true;
- components = new PortletContextComponents(invokerId, null,
portletNameOrStateId.substring(PRODUCER_CLONE_ID_PREFIX.length()).trim(), true);
+ int prefixLength = isProducerClone ?
PRODUCER_CLONE_PREFIX_LENGTH : CONSUMER_CLONE_PREFIX_LENGTH;
+ portletNameOrStateId =
portletNameOrStateId.substring(prefixLength).trim();
+ if (portletNameOrStateId.length() > 0)
+ {
+ isCloned = true;
+ components = new PortletContextComponents(invokerId,
null, portletNameOrStateId, isProducerClone);
+ }
}
else
{
isOpaquePortlet = true;
- components = new PortletContextComponents(invokerId, null,
portletNameOrStateId, false);
+ components = new PortletContextComponents(invokerId, null,
portletNameOrStateId, null);
}
}
}
@@ -139,11 +152,17 @@
}
else
{
- String stateId =
trimmedId.substring(PRODUCER_CLONE_ID_PREFIX.length()).trim();
- isCloned = stateId.length() > 0;
- if (isCloned)
+ boolean isProducerClone =
trimmedId.startsWith(PRODUCER_CLONE_ID_PREFIX);
+ boolean isConsumerClone =
trimmedId.startsWith(CONSUMER_CLONE_ID_PREFIX);
+ if (isProducerClone || isConsumerClone)
{
- components = new PortletContextComponents(null, null, stateId,
true);
+ int prefixLength = isProducerClone ? PRODUCER_CLONE_PREFIX_LENGTH :
CONSUMER_CLONE_PREFIX_LENGTH;
+ trimmedId = trimmedId.substring(prefixLength).trim();
+ if (trimmedId.length() > 0)
+ {
+ isCloned = true;
+ components = new PortletContextComponents(null, null, trimmedId,
isProducerClone);
+ }
}
}
}
@@ -269,7 +288,7 @@
applicationName = applicationName.substring(1);
}
- return new PortletContext(new PortletContextComponents(null, applicationName,
portletName, false));
+ return new PortletContext(new PortletContextComponents(null, applicationName,
portletName, null));
}
public PortletContextComponents getComponents()
@@ -282,11 +301,13 @@
private final String applicationName;
private final String portletName;
private final String invokerName;
- private final boolean cloned;
+ private final Boolean producerCloned;
- public PortletContextComponents(String invokerName, String applicationName, String
portletNameOrStateId, boolean cloned)
+ public PortletContextComponents(String invokerName, String applicationName, String
portletNameOrStateId, Boolean producerCloned)
{
- if (cloned && !ParameterValidation.isNullOrEmpty(applicationName))
+ this.producerCloned = producerCloned;
+
+ if (isCloned() && !ParameterValidation.isNullOrEmpty(applicationName))
{
throw new IllegalArgumentException("Cannot be a clone if applicationName
is provided");
}
@@ -294,7 +315,6 @@
this.applicationName = applicationName;
this.portletName = portletNameOrStateId;
this.invokerName = invokerName;
- this.cloned = cloned;
}
public String getApplicationName()
@@ -314,9 +334,19 @@
public boolean isCloned()
{
- return cloned;
+ return producerCloned != null;
}
+ public boolean isProducerCloned()
+ {
+ return isCloned() && producerCloned;
+ }
+
+ public boolean isConsumerCloned()
+ {
+ return isCloned() && !producerCloned;
+ }
+
public String getStateId()
{
return isCloned() ? portletName : null;
@@ -326,7 +356,7 @@
{
return (invokerName == null ? "" : invokerName + SEPARATOR)
+ (applicationName == null ? "" : PREFIX + applicationName +
SEPARATOR)
- + (portletName == null ? "" : (cloned ? PRODUCER_CLONE_ID_PREFIX :
"") + portletName);
+ + (portletName == null ? "" : (producerCloned != null ?
(producerCloned ? PRODUCER_CLONE_ID_PREFIX : CONSUMER_CLONE_ID_PREFIX) : "") +
portletName);
}
}
}
Modified:
components/pc/trunk/api/src/test/java/org/gatein/pc/api/PortletContextTestCase.java
===================================================================
---
components/pc/trunk/api/src/test/java/org/gatein/pc/api/PortletContextTestCase.java 2011-04-07
15:45:49 UTC (rev 6175)
+++
components/pc/trunk/api/src/test/java/org/gatein/pc/api/PortletContextTestCase.java 2011-04-07
17:25:59 UTC (rev 6176)
@@ -1,24 +1,25 @@
/*
-* 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.
-*/
+ * JBoss, a division of Red Hat
+ * Copyright 2011, 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.api;
@@ -185,30 +186,40 @@
assertEquals("foo", context.getId());
}
- public void testAcceptClones()
+ public void testAcceptProducerClones()
{
- PortletContext context = PortletContext.createPortletContext("_clone");
- assertEquals("_clone", context.getId());
- PortletContext.PortletContextComponents components = context.getComponents();
+ PortletContext context;
+ PortletContext.PortletContextComponents components;
+
+ checkClones(PortletContext.PRODUCER_CLONE_ID_PREFIX);
+
+ context = PortletContext.createPortletContext("foo." +
PortletContext.CONSUMER_CLONE_ID);
+ assertEquals("foo." + PortletContext.CONSUMER_CLONE_ID,
context.getId());
+ components = context.getComponents();
assertNotNull(components);
- assertNull(components.getInvokerName());
+ assertEquals("foo", components.getInvokerName());
assertNull(components.getApplicationName());
assertNull(components.getPortletName());
assertTrue(components.isCloned());
- assertEquals("clone", components.getStateId());
+ assertEquals(PortletContext.CONSUMER_CLONE_DUMMY_STATE_ID,
components.getStateId());
+ }
- context = PortletContext.createPortletContext("foo._clone");
- assertEquals("foo._clone", context.getId());
+ private void checkClones(String clonePrefix)
+ {
+ PortletContext context;
+ PortletContext.PortletContextComponents components;
+ context = PortletContext.createPortletContext(clonePrefix + "clone");
+ assertEquals(clonePrefix + "clone", context.getId());
components = context.getComponents();
assertNotNull(components);
- assertEquals("foo", components.getInvokerName());
+ assertNull(components.getInvokerName());
assertNull(components.getApplicationName());
assertNull(components.getPortletName());
assertTrue(components.isCloned());
assertEquals("clone", components.getStateId());
- context = PortletContext.createPortletContext("foo \t \n. _
\t\nclone");
- assertEquals("foo._clone", context.getId());
+ context = PortletContext.createPortletContext("foo." + clonePrefix +
"clone");
+ assertEquals("foo." + clonePrefix + "clone", context.getId());
components = context.getComponents();
assertNotNull(components);
assertEquals("foo", components.getInvokerName());
@@ -217,19 +228,24 @@
assertTrue(components.isCloned());
assertEquals("clone", components.getStateId());
- context = PortletContext.createPortletContext("foo." +
PortletContext.CONSUMER_CLONE_ID);
- assertEquals("foo." + PortletContext.CONSUMER_CLONE_ID,
context.getId());
+ context = PortletContext.createPortletContext("foo \t \n. " +
clonePrefix + " \t\nclone");
+ assertEquals("foo." + clonePrefix + "clone", context.getId());
components = context.getComponents();
assertNotNull(components);
assertEquals("foo", components.getInvokerName());
assertNull(components.getApplicationName());
assertNull(components.getPortletName());
assertTrue(components.isCloned());
- assertEquals(PortletContext.CONSUMER_CLONE_DUMMY_STATE_ID,
components.getStateId());
+ assertEquals("clone", components.getStateId());
}
- public void testAcceptConsumerClone()
+ public void testAcceptConsumerClones()
{
+ checkClones(PortletContext.CONSUMER_CLONE_ID_PREFIX);
+ }
+
+ public void testAcceptLocalConsumerClone()
+ {
PortletContext.PortletContextComponents components =
PortletContext.LOCAL_CONSUMER_CLONE.getComponents();
assertNotNull(components);
assertEquals(PortletInvoker.LOCAL_PORTLET_INVOKER_ID,
components.getInvokerName());
Modified:
components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/state/consumer/ConsumerPortletInvoker.java
===================================================================
---
components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/state/consumer/ConsumerPortletInvoker.java 2011-04-07
15:45:49 UTC (rev 6175)
+++
components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/state/consumer/ConsumerPortletInvoker.java 2011-04-07
17:25:59 UTC (rev 6176)
@@ -1,25 +1,25 @@
-/******************************************************************************
- * 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 2011, 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.consumer;
import org.gatein.common.NotYetImplemented;
@@ -55,9 +55,6 @@
{
/** . */
- private static final String CLONE_ID_PREFIX = "@";
-
- /** . */
private ConsumerPersistenceManager persistenceManager;
public PortletContext unwrapCCP(String wrappedCCP) throws InvalidPortletIdException
@@ -66,11 +63,11 @@
{
throw new IllegalArgumentException();
}
- if (!wrappedCCP.startsWith(CLONE_ID_PREFIX))
+ if (!wrappedCCP.startsWith(PortletContext.CONSUMER_CLONE_ID_PREFIX))
{
throw new InvalidPortletIdException(wrappedCCP);
}
- return
PortletContext.createPortletContext(wrappedCCP.substring(CLONE_ID_PREFIX.length()));
+ return
PortletContext.createPortletContext(wrappedCCP.substring(PortletContext.CONSUMER_CLONE_ID_PREFIX.length()));
}
public PortletContext unwrapPOP(String wrappedPOPId) throws InvalidPortletIdException
@@ -88,7 +85,7 @@
{
throw new IllegalArgumentException();
}
- return CLONE_ID_PREFIX + ccpCtx.getId();
+ return PortletContext.CONSUMER_CLONE_ID_PREFIX + ccpCtx.getId();
}
public String wrapPOP(PortletContext popCtx) throws InvalidPortletIdException
@@ -97,9 +94,9 @@
{
throw new IllegalArgumentException();
}
- if (popCtx.getId().startsWith(CLONE_ID_PREFIX))
+ if (popCtx.getId().startsWith(PortletContext.CONSUMER_CLONE_ID_PREFIX))
{
- throw new IllegalArgumentException("Must not start with " +
CLONE_ID_PREFIX);
+ throw new IllegalArgumentException("Must not start with " +
PortletContext.CONSUMER_CLONE_ID_PREFIX);
}
return popCtx.getId();
}
@@ -157,7 +154,7 @@
// Save the clone state
ConsumerState consumerState = new
ConsumerState<Serializable>(clonedContext.getId(), stateType, state);
String stateId = persistenceManager.createState(consumerState);
- String clonedId = CLONE_ID_PREFIX + stateId;
+ String clonedId = PortletContext.CONSUMER_CLONE_ID_PREFIX + stateId;
StateEvent event = new
StateEvent(PortletContext.createPortletContext(clonedId),
StateEvent.Type.PORTLET_CLONED_EVENT);
cictx.onStateEvent(event);
}
@@ -217,7 +214,7 @@
StatefulPortletContext statefulClonedContext =
(StatefulPortletContext)clonedContext;
ConsumerState consumerState = new
ConsumerState<Serializable>(clonedContext.getId(), statefulClonedContext.getType(),
statefulClonedContext.getState());
String id = persistenceManager.createState(consumerState);
- return PortletContext.createPortletContext(CLONE_ID_PREFIX + id);
+ return
PortletContext.createPortletContext(PortletContext.CONSUMER_CLONE_ID_PREFIX + id);
}
else
{
@@ -237,7 +234,7 @@
StatefulPortletContext statefulimportContext =
(StatefulPortletContext)importContext;
ConsumerState consumerState = new
ConsumerState<Serializable>(importContext.getId(), statefulimportContext.getType(),
statefulimportContext.getState());
String id = persistenceManager.createState(consumerState);
- return PortletContext.createPortletContext(CLONE_ID_PREFIX + id);
+ return
PortletContext.createPortletContext(PortletContext.CONSUMER_CLONE_ID_PREFIX + id);
}
else
{
@@ -413,9 +410,9 @@
String portletId = portletContext.getId();
//
- if (portletId.startsWith(CLONE_ID_PREFIX))
+ if (portletId.startsWith(PortletContext.CONSUMER_CLONE_ID_PREFIX))
{
- String stateId = portletId.substring(CLONE_ID_PREFIX.length());
+ String stateId =
portletId.substring(PortletContext.CONSUMER_CLONE_ID_PREFIX.length());
try
{
ConsumerStateContext stateCtx = persistenceManager.loadState(stateId);
Modified:
components/pc/trunk/portlet/src/test/java/org/gatein/pc/test/portlet/state/AbstractStatefulPortletInvokerTestCase.java
===================================================================
---
components/pc/trunk/portlet/src/test/java/org/gatein/pc/test/portlet/state/AbstractStatefulPortletInvokerTestCase.java 2011-04-07
15:45:49 UTC (rev 6175)
+++
components/pc/trunk/portlet/src/test/java/org/gatein/pc/test/portlet/state/AbstractStatefulPortletInvokerTestCase.java 2011-04-07
17:25:59 UTC (rev 6176)
@@ -1100,8 +1100,9 @@
PortletContext portletContext = importedPortlet.getContext();
//make sure the expected portlet context and the one we get back from the import
are the same
- assertEquals(originalPortletContext.getComponents().getApplicationName(),
portletContext.getComponents().getApplicationName());
- assertEquals(originalPortletContext.getComponents().getPortletName(),
portletContext.getComponents().getPortletName());
+// assertEquals(originalPortletContext.getComponents().getApplicationName(),
portletContext.getComponents().getApplicationName());
+// assertEquals(originalPortletContext.getComponents().getPortletName(),
portletContext.getComponents().getPortletName());
+ assertEquals(originalPortletContext, portletContext);
if (originalPortletContext instanceof StatefulPortletContext)
{
Modified:
components/pc/trunk/portlet/src/test/java/org/gatein/pc/test/portlet/state/ProducerStatefulPortletInvokerTestCase.java
===================================================================
---
components/pc/trunk/portlet/src/test/java/org/gatein/pc/test/portlet/state/ProducerStatefulPortletInvokerTestCase.java 2011-04-07
15:45:49 UTC (rev 6175)
+++
components/pc/trunk/portlet/src/test/java/org/gatein/pc/test/portlet/state/ProducerStatefulPortletInvokerTestCase.java 2011-04-07
17:25:59 UTC (rev 6176)
@@ -271,6 +271,6 @@
assertEquals(PortletStatus.MANAGED, producer.getStatus(ccp2Ctx));
// inexistent portlet
-
assertNull(producer.getStatus(PortletContext.createPortletContext("foo")));
+
assertNull(producer.getStatus(PortletContext.createPortletContext("/foo.bar")));
}
}