Author: chris.laprun(a)jboss.com
Date: 2011-01-25 10:50:15 -0500 (Tue, 25 Jan 2011)
New Revision: 5814
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/PortletContextMapping.java
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationMapping.java
Log:
- GTNWSRP-72: Added mapping to save portlet contexts associated with registrations and
related persistence code.
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/PortletContextMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/PortletContextMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/PortletContextMapping.java 2011-01-25
15:50:15 UTC (rev 5814)
@@ -0,0 +1,61 @@
+/*
+ * 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.wsrp.registration.mapping;
+
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = PortletContextMapping.NODE_NAME)
+public abstract class PortletContextMapping
+{
+ public static final String NODE_NAME = "wsrp:portletcontext";
+
+ @Property(name = "id")
+ public abstract String getId();
+
+ public abstract void setId(String id);
+
+ @Property(name = "state")
+ public abstract InputStream getState();
+
+ public abstract void setState(InputStream state);
+
+ public void initFrom(String id, byte[] state)
+ {
+ setId(id);
+
+ if (state != null && state.length > 0)
+ {
+ ByteArrayInputStream is = new ByteArrayInputStream(state);
+ setState(is);
+ }
+ }
+}
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationMapping.java 2011-01-25
14:32:03 UTC (rev 5813)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationMapping.java 2011-01-25
15:50:15 UTC (rev 5814)
@@ -26,19 +26,25 @@
import org.chromattic.api.annotations.Create;
import org.chromattic.api.annotations.Id;
import org.chromattic.api.annotations.MappedBy;
+import org.chromattic.api.annotations.OneToMany;
import org.chromattic.api.annotations.OneToOne;
import org.chromattic.api.annotations.Owner;
import org.chromattic.api.annotations.PrimaryType;
import org.chromattic.api.annotations.Property;
import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.PortletContext;
+import org.gatein.pc.api.PortletStateType;
+import org.gatein.pc.api.StatefulPortletContext;
import org.gatein.registration.Registration;
import org.gatein.registration.RegistrationException;
import org.gatein.registration.RegistrationStatus;
import org.gatein.registration.spi.ConsumerSPI;
import org.gatein.registration.spi.RegistrationSPI;
+import org.gatein.wsrp.jcr.mapping.Utils;
import org.gatein.wsrp.registration.JCRRegistrationPersistenceManager;
import javax.xml.namespace.QName;
+import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@@ -64,12 +70,11 @@
public abstract void setRegistrationHandle(String handle);
- /*
-TODO: convert to use PortletContexts instead of just handles
-@Property(name="portlethandles")
-public abstract List<String> getPortletHandles();
+ @OneToMany
+ public abstract Collection<PortletContextMapping> getPortletContexts();
-public abstract void setPortletHandles(List<String> portletHandles);*/
+ @Create
+ public abstract PortletContextMapping createPortletContext(String id);
@OneToOne
@Owner
@@ -90,8 +95,30 @@
{
setStatus(registration.getStatus());
setRegistrationHandle(registration.getRegistrationHandle());
-// setPortletHandles(registration.getPortletHandles()); // TODO
+ // clear and recreate portlet context mappings
+ Collection<PortletContextMapping> contextMappings = getPortletContexts();
+ contextMappings.clear();
+ for (PortletContext portletContext : registration.getKnownPortletContexts())
+ {
+ String id = portletContext.getId();
+ PortletContextMapping contextMapping = createPortletContext(id);
+ contextMappings.add(contextMapping);
+
+ if (portletContext instanceof StatefulPortletContext)
+ {
+ StatefulPortletContext context = (StatefulPortletContext)portletContext;
+ if (PortletStateType.OPAQUE.equals(context.getType()))
+ {
+ contextMapping.initFrom(id,
((StatefulPortletContext<byte[]>)context).getState());
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot handle PortletContext
state: " + context.getState());
+ }
+ }
+ }
+
Map<QName, Object> properties = registration.getProperties();
if (ParameterValidation.existsAndIsNotEmpty(properties))
{
@@ -117,8 +144,14 @@
RegistrationSPI reg = persistenceManager.newRegistrationSPI(consumer, props,
getPersistentKey());
reg.setStatus(getStatus());
reg.setRegistrationHandle(getRegistrationHandle());
-// reg.getPortletHandles().addAll(getPortletHandles()); // TODO
+ Collection<PortletContextMapping> pcms = getPortletContexts();
+ for (PortletContextMapping pcm : pcms)
+ {
+ PortletContext pc = PortletContext.createPortletContext(pcm.getId(),
Utils.safeGetBytes(pcm.getState()));
+ reg.addPortletContext(pc);
+ }
+
return reg;
}
}