Author: chris.laprun(a)jboss.com
Date: 2010-02-27 13:56:53 -0500 (Sat, 27 Feb 2010)
New Revision: 1898
Added:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/mapping/MappedMap.java
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/JCRPortletStatePersistenceManager.java
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/mapping/
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/mapping/PortletStateContextMapping.java
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/mapping/PortletStateContextsMapping.java
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/mapping/PortletStateMapping.java
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/wsrp/producer-portlet-states-nodetypes.xml
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/wsrp/WSRPContentProvider.java
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java
portal/trunk/pom.xml
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/jcr/jcr-configuration.xml
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/jcr/repository-configuration.xml
Log:
- Updated to use PC 2.1.0-CR05 and WSRP 1.0.0-Beta09.
- GTNPORTAL-737:
+ Implemented a JCR-backed implementation of PortletStatePersistenceManager and
configure the WSRP producer to use it.
+ Implemented WSRPContentProvider.combine as it is now called when the producer returns
a state.
+ Added PortletNameFormatter to deal with / in WSRP portlet names that would cause an
issue with JCR persistence.
+ Added portlet-states-system JCR workspace and producer-portlet-states-nodetypes.xml.
+ Added MappedMap to facilitate using @Properties in JCR by dealing with blacklisted
properties and internal vs. external values.
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/wsrp/WSRPContentProvider.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/wsrp/WSRPContentProvider.java 2010-02-27
14:29:19 UTC (rev 1897)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/spi/wsrp/WSRPContentProvider.java 2010-02-27
18:56:53 UTC (rev 1898)
@@ -20,6 +20,7 @@
package org.exoplatform.portal.pom.spi.wsrp;
import org.exoplatform.commons.utils.Safe;
+import org.gatein.common.util.ParameterValidation;
import org.gatein.mop.spi.content.ContentProvider;
import org.gatein.mop.spi.content.StateContainer;
@@ -35,7 +36,19 @@
public WSRP combine(List<WSRP> wsrpStates)
{
- throw new UnsupportedOperationException("todo");
+ WSRP result = null;
+ if(ParameterValidation.existsAndIsNotEmpty(wsrpStates))
+ {
+ for (WSRP state : wsrpStates)
+ {
+ result = state;
+ if(state.isCloned())
+ {
+ return state;
+ }
+ }
+ }
+ return result;
}
public void setState(StateContainer<WSRPState> container, WSRP state)
Modified:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java
===================================================================
---
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java 2010-02-27
14:29:19 UTC (rev 1897)
+++
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java 2010-02-27
18:56:53 UTC (rev 1898)
@@ -37,10 +37,12 @@
import org.gatein.pc.portlet.impl.state.StateManagementPolicyService;
import org.gatein.pc.portlet.impl.state.producer.PortletStatePersistenceManagerService;
import org.gatein.pc.portlet.state.StateConverter;
+import org.gatein.pc.portlet.state.producer.PortletStatePersistenceManager;
import org.gatein.pc.portlet.state.producer.ProducerPortletInvoker;
import org.gatein.portal.wsrp.state.consumer.JCRConsumerRegistry;
import
org.gatein.portal.wsrp.state.producer.configuration.JCRProducerConfigurationService;
import
org.gatein.portal.wsrp.state.producer.registrations.JCRRegistrationPersistenceManager;
+import org.gatein.portal.wsrp.state.producer.state.JCRPortletStatePersistenceManager;
import org.gatein.registration.RegistrationManager;
import org.gatein.registration.RegistrationPersistenceManager;
import org.gatein.registration.impl.RegistrationManagerImpl;
@@ -175,7 +177,15 @@
(ContainerPortletInvoker)container.getComponentInstanceOfType(ContainerPortletInvoker.class);
// The producer persistence manager
- PortletStatePersistenceManagerService producerPersistenceManager = new
PortletStatePersistenceManagerService();
+ PortletStatePersistenceManager producerPersistenceManager;
+ try
+ {
+ producerPersistenceManager = new JCRPortletStatePersistenceManager(container);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Couldn't instantiate
PortletStatePersistenceManager", e);
+ }
// The producer state management policy
StateManagementPolicyService producerStateManagementPolicy = new
StateManagementPolicyService();
@@ -274,7 +284,6 @@
switch (lifeCycleEvent.getType())
{
case WebAppLifeCycleEvent.ADDED:
-
context.setAttribute("ConsumerRegistry", consumerRegistry);
context.setAttribute("ProducerConfigurationService",
producer.getConfigurationService());
break;
Modified:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java
===================================================================
---
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java 2010-02-27
14:29:19 UTC (rev 1897)
+++
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java 2010-02-27
18:56:53 UTC (rev 1898)
@@ -139,6 +139,9 @@
private static final String OPEN_BRACE_REPLACEMENT = "-__";
private static final String CLOSE_BRACE_REPLACEMENT = "__-";
private static final String COLON_REPLACEMENT = "_-_";
+ private static final String CLOSE_BRACE = "}";
+ private static final String OPEN_BRACE = "{";
+ private static final String COLON = ":";
public String decodeNodeName(FormatterContext formatterContext, String s)
{
@@ -162,12 +165,33 @@
private String decode(String s)
{
- return s.replace(CLOSE_BRACE_REPLACEMENT,
"}").replace(OPEN_BRACE_REPLACEMENT, "{").replace(COLON_REPLACEMENT,
":");
+ return s.replace(CLOSE_BRACE_REPLACEMENT,
CLOSE_BRACE).replace(OPEN_BRACE_REPLACEMENT, OPEN_BRACE).replace(COLON_REPLACEMENT,
COLON);
}
private String encode(String s)
{
- return s.replace("{", OPEN_BRACE_REPLACEMENT).replace("}",
CLOSE_BRACE_REPLACEMENT).replace(":", COLON_REPLACEMENT);
+ return s.replace(OPEN_BRACE, OPEN_BRACE_REPLACEMENT).replace(CLOSE_BRACE,
CLOSE_BRACE_REPLACEMENT).replace(COLON, COLON_REPLACEMENT);
}
}
+
+ public static class PortletNameFormatter implements ObjectFormatter
+ {
+ public static final String SLASH_REPLACEMENT = "___";
+ private static final String SLASH = "/";
+
+ public String decodeNodeName(FormatterContext formatterContext, String s)
+ {
+ return s.replace(SLASH_REPLACEMENT, SLASH);
+ }
+
+ public String encodeNodeName(FormatterContext formatterContext, String s) throws
IllegalArgumentException, NullPointerException
+ {
+ return encode(s);
+ }
+
+ public static String encode(String s)
+ {
+ return s.replace(SLASH, SLASH_REPLACEMENT);
+ }
+ }
}
Added:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/mapping/MappedMap.java
===================================================================
---
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/mapping/MappedMap.java
(rev 0)
+++
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/mapping/MappedMap.java 2010-02-27
18:56:53 UTC (rev 1898)
@@ -0,0 +1,118 @@
+/*
+ * 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.portal.wsrp.state.mapping;
+
+import org.exoplatform.commons.utils.Tools;
+import org.gatein.common.util.AbstractTypedMap;
+import org.gatein.common.util.ParameterValidation;
+
+import javax.xml.namespace.QName;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class MappedMap<Key, Value>
+{
+ /** Need to ignore JCR properties for now until scoping mechanism exists on
@Properties */
+ private static final Set<String> jcrBlacklistedPropertyKeys =
Tools.set("jcr:uuid", "jcr:primaryType");
+ private Set<String> blacklistedPropertyKeys;
+ private Converter<String, Key> keyConverter;
+ private Converter<Object, Value> valueConverter;
+
+ public static final Converter<String, String> IDENTITY_KEY_CONVERTER = new
Converter<String, String>()
+ {
+
+ public String fromInternal(String s)
+ {
+ return s;
+ }
+
+ public String toInternal(String s)
+ {
+ return s;
+ }
+ };
+
+ public MappedMap(Converter<String, Key> keyConverter, Converter<Object,
Value> valueConverter, String... blacklistedPropertyNames)
+ {
+ this.keyConverter = keyConverter;
+ this.valueConverter = valueConverter;
+
+ int blacklistedNumber = blacklistedPropertyNames.length;
+ if(blacklistedNumber > 0)
+ {
+ blacklistedPropertyKeys = new
HashSet<String>(jcrBlacklistedPropertyKeys);
+ blacklistedPropertyKeys.addAll(Arrays.asList(blacklistedPropertyNames));
+ }
+ }
+
+ public Map<Key, Value> toExternalMap(Map<String, Object> internalMap)
+ {
+ if (!internalMap.isEmpty())
+ {
+ Map<Key, Value> externalMap = new HashMap<Key,
Value>(internalMap.size());
+ for (Map.Entry<String, Object> entry : internalMap.entrySet())
+ {
+ String key = entry.getKey();
+
+ // ignore blacklisted properties
+ if (!blacklistedPropertyKeys.contains(key))
+ {
+ externalMap.put(keyConverter.fromInternal(key),
valueConverter.fromInternal(entry.getValue()));
+ }
+ }
+
+ return externalMap;
+ }
+ else
+ {
+ return Collections.emptyMap();
+ }
+ }
+
+ public void initFrom(Map<Key, Value> externalMap, Map<String, Object>
internalMap)
+ {
+ if (ParameterValidation.existsAndIsNotEmpty(externalMap))
+ {
+ for (Map.Entry<Key, Value> entry : externalMap.entrySet())
+ {
+ internalMap.put(keyConverter.toInternal(entry.getKey()),
valueConverter.toInternal(entry.getValue()));
+ }
+ }
+ }
+
+ public static interface Converter<Internal, External>
+ {
+ External fromInternal(Internal internal);
+ Internal toInternal(External external);
+ }
+}
Added:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/JCRPortletStatePersistenceManager.java
===================================================================
---
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/JCRPortletStatePersistenceManager.java
(rev 0)
+++
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/JCRPortletStatePersistenceManager.java 2010-02-27
18:56:53 UTC (rev 1898)
@@ -0,0 +1,167 @@
+/*
+ * 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.portal.wsrp.state.producer.state;
+
+import org.chromattic.api.ChromatticSession;
+import org.exoplatform.container.ExoContainer;
+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.producer.AbstractPortletStatePersistenceManager;
+import org.gatein.pc.portlet.state.producer.PortletStateContext;
+import org.gatein.portal.wsrp.state.JCRPersister;
+import org.gatein.portal.wsrp.state.producer.state.mapping.PortletStateContextMapping;
+import org.gatein.portal.wsrp.state.producer.state.mapping.PortletStateContextsMapping;
+import org.gatein.portal.wsrp.state.producer.state.mapping.PortletStateMapping;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class JCRPortletStatePersistenceManager extends
AbstractPortletStatePersistenceManager
+{
+ private JCRPersister persister;
+ private static final String PATH = PortletStateContextsMapping.NODE_NAME +
"/";
+
+ public JCRPortletStatePersistenceManager(ExoContainer container) throws Exception
+ {
+ persister = new JCRPersister(container);
+
+ List<Class> mappingClasses = new ArrayList<Class>(6);
+ Collections.addAll(mappingClasses, PortletStateContextsMapping.class,
PortletStateContextMapping.class, PortletStateMapping.class);
+
+ persister.initializeBuilderFor(mappingClasses);
+
+// persister = NewJCRPersister.getInstance(container);
+ }
+
+ private PortletStateContextsMapping getContexts(ChromatticSession session)
+ {
+ PortletStateContextsMapping portletStateContexts =
session.findByPath(PortletStateContextsMapping.class,
PortletStateContextsMapping.NODE_NAME);
+ if (portletStateContexts == null)
+ {
+ portletStateContexts = session.insert(PortletStateContextsMapping.class,
PortletStateContextsMapping.NODE_NAME);
+ }
+ return portletStateContexts;
+ }
+
+ @Override
+ public void updateState(String stateId, PropertyMap propertyMap) throws
NoSuchStateException, InvalidStateIdException
+ {
+ // more optimized version of updateState
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyMap, "property
map");
+
+ ChromatticSession session = persister.getSession();
+
+ PortletStateContextMapping pscm = getPortletStateContextMapping(session, stateId);
+ PortletStateMapping psm = pscm.getState();
+ psm.setProperties(propertyMap);
+
+ persister.closeSession(session, false);
+ }
+
+
+ @Override
+ protected PortletStateContext getStateContext(String stateId)
+ {
+ ChromatticSession session = persister.getSession();
+
+ PortletStateContextMapping pscm = getPortletStateContextMapping(session, stateId);
+ PortletStateContext context;
+ if(pscm == null)
+ {
+ context = null;
+ }
+ else
+ {
+ context = pscm.toPortletStateContext();
+ }
+
+ persister.closeSession(session, false);
+
+ return context;
+ }
+
+ @Override
+ protected String createStateContext(String portletId, PropertyMap propertyMap)
+ {
+ ChromatticSession session = persister.getSession();
+
+ String encodedForPath = JCRPersister.PortletNameFormatter.encode(portletId);
+
+ PortletStateContextMapping pscm =
session.findByPath(PortletStateContextMapping.class, PATH + encodedForPath);
+ if(pscm == null)
+ {
+ PortletStateContextsMapping portletStateContexts = getContexts(session);
+ pscm = portletStateContexts.createPortletStateContext(portletId);
+ portletStateContexts.getPortletStateContexts().add(pscm);
+ }
+
+ PortletStateMapping psm = pscm.getState();
+ psm.setPortletID(pscm.getPortletId());
+ psm.setProperties(propertyMap);
+
+ persister.closeSession(session, true);
+
+ return pscm.getPersistentKey();
+ }
+
+ @Override
+ protected PortletStateContext destroyStateContext(String stateId)
+ {
+ ChromatticSession session = persister.getSession();
+
+ PortletStateContextMapping pscm = getPortletStateContextMapping(session, stateId);
+ PortletStateContext result;
+ if (pscm == null)
+ {
+ result = null;
+ }
+ else
+ {
+ getContexts(session).getPortletStateContexts().remove(pscm);
+ session.remove(pscm);
+ result = pscm.toPortletStateContext();
+ }
+
+ persister.closeSession(session, true);
+ return result;
+ }
+
+ @Override
+ protected void updateStateContext(PortletStateContext stateContext)
+ {
+ throw new UnsupportedOperationException("Shouldn't be called as
updateState method is overriden!");
+ }
+
+ private PortletStateContextMapping getPortletStateContextMapping(ChromatticSession
session, String stateId)
+ {
+ return getContexts(session).findPortletStateContextById(stateId);
+ }
+}
Added:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/mapping/PortletStateContextMapping.java
===================================================================
---
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/mapping/PortletStateContextMapping.java
(rev 0)
+++
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/mapping/PortletStateContextMapping.java 2010-02-27
18:56:53 UTC (rev 1898)
@@ -0,0 +1,70 @@
+/*
+ * 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.portal.wsrp.state.producer.state.mapping;
+
+import org.chromattic.api.annotations.Id;
+import org.chromattic.api.annotations.MappedBy;
+import org.chromattic.api.annotations.Name;
+import org.chromattic.api.annotations.OneToOne;
+import org.chromattic.api.annotations.PrimaryType;
+import org.gatein.pc.portlet.impl.state.producer.PortletStateContextImpl;
+import org.gatein.pc.portlet.state.producer.PortletStateContext;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = PortletStateContextMapping.NODE_NAME)
+public abstract class PortletStateContextMapping
+{
+ public static final String NODE_NAME = "portlet:statecontext";
+
+ @Id
+ public abstract String getPersistentKey();
+
+ @Name
+ public abstract String getPortletId();
+
+ @OneToOne
+ @MappedBy("state")
+ public abstract PortletStateMapping getState();
+
+ public PortletStateContext toPortletStateContext()
+ {
+ PortletStateMapping psm = getState();
+ String portletId = psm.getPortletID();
+
+ if(getPortletId().equals(portletId))
+ {
+ PortletStateContextImpl context = new
PortletStateContextImpl(getPersistentKey(), portletId, psm.getPropertiesAsPropertyMap());
+ context.getState().setTerminationTime(psm.getTerminationTime());
+ return context;
+ }
+ else
+ {
+ throw new IllegalStateException("PortletStateContext's portlet id is
'" + getPortletId()
+ + "' but PortletState has '" + portletId +
"'");
+ }
+ }
+}
Added:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/mapping/PortletStateContextsMapping.java
===================================================================
---
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/mapping/PortletStateContextsMapping.java
(rev 0)
+++
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/mapping/PortletStateContextsMapping.java 2010-02-27
18:56:53 UTC (rev 1898)
@@ -0,0 +1,53 @@
+/*
+ * 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.portal.wsrp.state.producer.state.mapping;
+
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.FindById;
+import org.chromattic.api.annotations.FormattedBy;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.PrimaryType;
+import org.gatein.portal.wsrp.state.JCRPersister;
+
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = PortletStateContextsMapping.NODE_NAME)
+(a)FormattedBy(JCRPersister.PortletNameFormatter.class)
+public abstract class PortletStateContextsMapping
+{
+ public static final String NODE_NAME = "portlet:producerstates";
+
+ @OneToMany
+ public abstract Collection<PortletStateContextMapping>
getPortletStateContexts();
+
+ @Create
+ public abstract PortletStateContextMapping createPortletStateContext(String id);
+
+ @FindById
+ public abstract PortletStateContextMapping findPortletStateContextById(String id);
+}
Added:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/mapping/PortletStateMapping.java
===================================================================
---
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/mapping/PortletStateMapping.java
(rev 0)
+++
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/state/mapping/PortletStateMapping.java 2010-02-27
18:56:53 UTC (rev 1898)
@@ -0,0 +1,160 @@
+/*
+ * 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.portal.wsrp.state.producer.state.mapping;
+
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Properties;
+import org.chromattic.api.annotations.Property;
+import org.exoplatform.commons.utils.Tools;
+import org.gatein.common.util.AbstractTypedMap;
+import org.gatein.pc.api.state.PropertyMap;
+import org.gatein.pc.portlet.state.AbstractPropertyMap;
+import org.gatein.pc.portlet.state.SimplePropertyMap;
+import org.gatein.portal.wsrp.state.mapping.MappedMap;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = PortletStateMapping.NODE_NAME)
+public abstract class PortletStateMapping
+{
+ public static final String NODE_NAME = "portlet:state";
+
+ private static final String PORTLET_ID = "portlet:portletid";
+ private static final String TERMINATION_TIME = "portlet:terminationtime";
+
+ private static final ObjectToStringListConverter VALUE_CONVERTER = new
ObjectToStringListConverter();
+ private static final MappedMap<String, List<String>> mappedMap =
+ new MappedMap<String, List<String>>(MappedMap.IDENTITY_KEY_CONVERTER,
VALUE_CONVERTER, PORTLET_ID, TERMINATION_TIME);
+
+ @Property(name = PORTLET_ID)
+ public abstract String getPortletID();
+
+ public abstract void setPortletID(String portletId);
+
+ @Properties
+ public abstract Map<String, Object> getProperties();
+
+ @Property(name = TERMINATION_TIME)
+ public abstract Date getTerminationTime();
+
+ public abstract void setTerminationTime(Date terminationTime);
+
+ public PropertyMap getPropertiesAsPropertyMap()
+ {
+ Map<String, Object> map = getProperties();
+
+ if (!map.isEmpty())
+ {
+ return new SimplePropertyMap(mappedMap.toExternalMap(map));
+ }
+ else
+ {
+ return new SimplePropertyMap();
+ }
+ }
+
+ public void setProperties(PropertyMap props)
+ {
+ mappedMap.initFrom(props, getProperties());
+ }
+
+ /**
+ * todo: copied from org.exoplatform.portal.pom.config.Utils class that should really
be moved to common module...
+ * @param separator
+ * @param strings
+ * @return
+ */
+ public static String join(String separator, List<String> strings)
+ {
+ if (strings == null)
+ {
+ return null;
+ }
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < strings.size(); i++)
+ {
+ Object o = strings.get(i);
+ if (i > 0)
+ {
+ sb.append(separator);
+ }
+ sb.append(o);
+ }
+ return sb.toString();
+ }
+
+ /**
+ * todo: move to common module
+ * @param separator
+ * @param s
+ * @return
+ */
+ public static String[] split(String separator, String s)
+ {
+ if (s == null)
+ {
+ return null;
+ }
+ return split(s, 0, 0, separator);
+ }
+
+ private static String[] split(String s, int fromIndex, int index, String separator)
+ {
+ int toIndex = s.indexOf(separator, fromIndex);
+ String[] chunks;
+ if (toIndex == -1)
+ {
+ chunks = new String[index + 1];
+ toIndex = s.length();
+ }
+ else
+ {
+ chunks = split(s, toIndex + separator.length(), index + 1, separator);
+ }
+ chunks[index] = s.substring(fromIndex, toIndex);
+ return chunks;
+ }
+
+ private static class ObjectToStringListConverter implements
MappedMap.Converter<Object, List<String>>
+ {
+
+ public List<String> fromInternal(Object o)
+ {
+ return Arrays.asList(split(",", (String)o));
+ }
+
+ public String toInternal(List<String> strings)
+ {
+ return join(",", strings);
+ }
+ }
+}
Modified: portal/trunk/pom.xml
===================================================================
--- portal/trunk/pom.xml 2010-02-27 14:29:19 UTC (rev 1897)
+++ portal/trunk/pom.xml 2010-02-27 18:56:53 UTC (rev 1898)
@@ -45,9 +45,9 @@
<org.shindig.version>SNAPSHOT-r790473</org.shindig.version>
<org.gatein.common.version>2.0.0-CR03</org.gatein.common.version>
<org.gatein.wci.version>2.0.0-CR02</org.gatein.wci.version>
- <org.gatein.pc.version>2.1.0-CR04</org.gatein.pc.version>
+ <org.gatein.pc.version>2.1.0-CR05</org.gatein.pc.version>
<org.picketlink.idm>1.1.0.Beta5</org.picketlink.idm>
- <org.gatein.wsrp.version>1.0.0-Beta08</org.gatein.wsrp.version>
+ <org.gatein.wsrp.version>1.0.0-Beta09</org.gatein.wsrp.version>
<org.gatein.mop.version>1.0.0-CR03</org.gatein.mop.version>
<org.slf4j.version>1.5.6</org.slf4j.version>
<rhino.version>1.6R5</rhino.version>
Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/jcr/jcr-configuration.xml
===================================================================
---
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/jcr/jcr-configuration.xml 2010-02-27
14:29:19 UTC (rev 1897)
+++
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/jcr/jcr-configuration.xml 2010-02-27
18:56:53 UTC (rev 1898)
@@ -100,6 +100,7 @@
<property name="app"
value="http://www.gatein.org/jcr/application-registry/1.0/"/>
<property name="lgn"
value="http://www.gatein.org/jcr/autologin/1.0/"/>
<property name="wsrp"
value="http://www.gatein.org/jcr/wsrp/1.0/"/>
+ <property name="portlet"
value="http://www.gatein.org/jcr/portlet/1.0/"/>
</properties-param>
</init-params>
</component-plugin>
@@ -121,6 +122,7 @@
<value>war:/conf/wsrp/consumers-configuration-nodetypes.xml</value>
<value>war:/conf/wsrp/producer-configuration-nodetypes.xml</value>
<value>war:/conf/wsrp/producer-registrations-nodetypes.xml</value>
+
<value>war:/conf/wsrp/producer-portlet-states-nodetypes.xml</value>
</values-param>
</init-params>
</component-plugin>
Modified:
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/jcr/repository-configuration.xml
===================================================================
---
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/jcr/repository-configuration.xml 2010-02-27
14:29:19 UTC (rev 1897)
+++
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/jcr/repository-configuration.xml 2010-02-27
18:56:53 UTC (rev 1898)
@@ -26,7 +26,7 @@
<access-control>optional</access-control>
<authentication-policy>org.exoplatform.services.jcr.impl.core.access.JAASAuthenticator</authentication-policy>
- <!-- System -->
+ <!-- System -->
<workspaces>
<workspace name="system">
<container
class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
@@ -292,6 +292,79 @@
</lock-manager>
</workspace>
+ <!-- Producer portlet states -->
+ <workspace name="portlet-states-system">
+ <container
class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
+ <properties>
+ <property name="source-name"
value="${gatein.jcr.datasource.name}${container.name.suffix}"/>
+ <property name="dialect"
value="${gatein.jcr.datasource.dialect}"/>
+ <property name="multi-db" value="false"/>
+ <property name="update-storage"
value="true"/>
+ <property name="max-buffer-size"
value="204800"/>
+ <property name="swap-directory"
value="${gatein.jcr.data.dir}/swap/portlet-states${container.name.suffix}"/>
+ </properties>
+ <value-storages>
+ <value-storage id="gadgets"
+
class="org.exoplatform.services.jcr.impl.storage.value.fs.TreeFileValueStorage">
+ <properties>
+ <property name="path"
value="${gatein.jcr.storage.data.dir}/portlet-states${container.name.suffix}"/>
+ </properties>
+ <filters>
+ <filter property-type="Binary"/>
+ </filters>
+ </value-storage>
+ </value-storages>
+ </container>
+ <initializer
class="org.exoplatform.services.jcr.impl.core.ScratchWorkspaceInitializer">
+ <properties>
+ <property name="root-nodetype"
value="nt:unstructured"/>
+ <property name="root-permissions"
+ value="any read;*:/platform/administrators
read;*:/platform/administrators add_node;*:/platform/administrators
set_property;*:/platform/administrators remove"/>
+ </properties>
+ </initializer>
+ <cache enabled="true"
+
class="org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.JBossCacheWorkspaceStorageCache">
+ <properties>
+ <property name="jbosscache-configuration"
+
value="conf/jcr/jbosscache/${gatein.jcr.config.type}/config.xml"/>
+ <property name="jgroups-configuration"
value="jar:/conf/jcr/jbosscache/cluster/udp-mux.xml"/>
+ <property name="jgroups-multiplexer-stack"
value="true"/>
+ <property name="jbosscache-cluster-name"
value="jcr-${container.name.suffix}-portlet-states-system"/>
+ </properties>
+ </cache>
+ <query-handler
class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
+ <properties>
+ <property name="index-dir"
value="${gatein.jcr.index.data.dir}/portlet-states-system${container.name.suffix}"/>
+ <property name="changesfilter-class"
value="${gatein.jcr.index.changefilterclass}"/>
+ <property name="jbosscache-configuration"
value="conf/jcr/jbosscache/cluster/indexer-config.xml"/>
+ <property name="jgroups-configuration"
value="jar:/conf/jcr/jbosscache/cluster/udp-mux.xml"/>
+ <property name="jgroups-multiplexer-stack"
value="true"/>
+ <property name="jbosscache-cluster-name"
value="jcrindexer-${container.name.suffix}-portlet-states-system"/>
+ <property name="max-volatile-time"
value="60"/>
+ </properties>
+ </query-handler>
+ <lock-manager
class="org.exoplatform.services.jcr.impl.core.lock.jbosscache.CacheableLockManagerImpl">
+ <properties>
+ <property name="time-out" value="15m"/>
+ <property name="jbosscache-configuration"
+
value="conf/jcr/jbosscache/${gatein.jcr.config.type}/lock-config.xml"/>
+ <property name="jgroups-configuration"
value="jar:/conf/jcr/jbosscache/cluster/udp-mux.xml"/>
+ <property name="jgroups-multiplexer-stack"
value="true"/>
+ <property
name="jbosscache-cluster-namejbosscache-cluster-name"
+
value="jcrlock-${container.name.suffix}-system"/>
+ <property name="jbosscache-cl-cache.jdbc.table.name"
value="jcrlock_portlet_states_system"/>
+ <property name="jbosscache-cl-cache.jdbc.table.create"
value="true"/>
+ <property name="jbosscache-cl-cache.jdbc.table.drop"
value="false"/>
+ <property name="jbosscache-cl-cache.jdbc.table.primarykey"
value="pk"/>
+ <property name="jbosscache-cl-cache.jdbc.fqn.column"
value="fqn"/>
+ <property name="jbosscache-cl-cache.jdbc.node.column"
value="node"/>
+ <property name="jbosscache-cl-cache.jdbc.parent.column"
value="parent"/>
+ <property name="jbosscache-cl-cache.jdbc.datasource"
+
value="${gatein.jcr.datasource.name}${container.name.suffix}"/>
+ </properties>
+ </lock-manager>
+ </workspace>
+
</workspaces>
</repository>
</repositories>
Added:
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/wsrp/producer-portlet-states-nodetypes.xml
===================================================================
---
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/wsrp/producer-portlet-states-nodetypes.xml
(rev 0)
+++
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/wsrp/producer-portlet-states-nodetypes.xml 2010-02-27
18:56:53 UTC (rev 1898)
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<nodeTypes
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
+
xmlns:jcr="http://www.jcp.org/jcr/1.0">
+ <nodeType name="portlet:producerstates" isMixin="false"
hasOrderableChildNodes="false">
+ <supertypes>
+ <supertype>nt:base</supertype>
+ <supertype>mix:referenceable</supertype>
+ </supertypes>
+ <propertyDefinitions/>
+ <childNodeDefinitions>
+ <childNodeDefinition name="*" defaultPrimaryType=""
autoCreated="false" mandatory="false"
+ onParentVersion="COPY"
protected="false" sameNameSiblings="false">
+ <requiredPrimaryTypes>
+
<requiredPrimaryType>portlet:statecontext</requiredPrimaryType>
+ </requiredPrimaryTypes>
+ </childNodeDefinition>
+ </childNodeDefinitions>
+ </nodeType>
+
+ <nodeType name="portlet:statecontext" isMixin="false"
hasOrderableChildNodes="false">
+ <supertypes>
+ <supertype>nt:base</supertype>
+ <supertype>mix:referenceable</supertype>
+ </supertypes>
+ <propertyDefinitions>
+ <propertyDefinition name="id" requiredType="String"
autoCreated="false" mandatory="false"
+ onParentVersion="COPY" protected="false"
multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ </propertyDefinitions>
+ <childNodeDefinitions>
+ <childNodeDefinition name="state"
defaultPrimaryType="portlet:state" autoCreated="true"
mandatory="false"
+ onParentVersion="COPY"
protected="false" sameNameSiblings="false">
+ <requiredPrimaryTypes>
+ <requiredPrimaryType>portlet:state</requiredPrimaryType>
+ </requiredPrimaryTypes>
+ </childNodeDefinition>
+ </childNodeDefinitions>
+ </nodeType>
+
+ <nodeType name="portlet:state" isMixin="false"
hasOrderableChildNodes="false">
+ <supertypes>
+ <supertype>nt:base</supertype>
+ <supertype>mix:referenceable</supertype>
+ </supertypes>
+ <propertyDefinitions>
+ <propertyDefinition name="portlet:portletid"
requiredType="String" autoCreated="false" mandatory="false"
+ onParentVersion="COPY" protected="false"
multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="portlet:terminationtime"
requiredType="Date" autoCreated="false" mandatory="false"
+ onParentVersion="COPY" protected="false"
multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="*" requiredType="undefined"
autoCreated="false" mandatory="false"
+ onParentVersion="COPY" protected="false"
multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ </propertyDefinitions>
+ <childNodeDefinitions/>
+ </nodeType>
+
+</nodeTypes>