Author: chris.laprun(a)jboss.com
Date: 2010-10-04 17:25:11 -0400 (Mon, 04 Oct 2010)
New Revision: 4484
Added:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/mapping/BaseMapping.java
Modified:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/JCRMigrationService.java
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportInfoMapping.java
Log:
- GTNPORTAL-1529: Fixed inconsitent parameters in JCRPersister.delete method.
- Introduced BaseMapping to gather common behavior and possibly extends JCRPersister with
more generic methods down the road.
Modified:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java 2010-10-04
18:51:28 UTC (rev 4483)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java 2010-10-04
21:25:11 UTC (rev 4484)
@@ -22,6 +22,7 @@
package org.gatein.portal.wsrp.state;
+import EDU.oswego.cs.dl.util.concurrent.FJTask;
import org.chromattic.api.Chromattic;
import org.chromattic.api.ChromatticBuilder;
import org.chromattic.api.ChromatticSession;
@@ -33,11 +34,17 @@
import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.ext.common.SessionProvider;
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.portal.wsrp.state.mapping.BaseMapping;
import javax.jcr.Credentials;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -50,6 +57,7 @@
public static final String PORTLET_STATES_WORKSPACE_NAME = "pc-system";
private static final String REPOSITORY_NAME = "repository";
private String workspaceName;
+ private Map<Class, Class<? extends BaseMapping>> modelToMapping;
public JCRPersister(ExoContainer container, String workspaceName)
{
@@ -73,8 +81,18 @@
throw new IllegalArgumentException("Unknown workspace name: '" +
workspaceName + "'");
}
+ modelToMapping = new HashMap<Class, Class<? extends
BaseMapping>>(mappingClasses.size());
for (Class mappingClass : mappingClasses)
{
+ if (BaseMapping.class.isAssignableFrom(mappingClass))
+ {
+ Type[] interfaces = mappingClass.getGenericInterfaces();
+ if(ParameterValidation.existsAndIsNotEmpty(interfaces))
+ {
+ Class type =
(Class)((ParameterizedType)interfaces[0]).getActualTypeArguments()[0];
+ modelToMapping.put(type, mappingClass);
+ }
+ }
builder.add(mappingClass);
}
@@ -102,9 +120,16 @@
public <T> boolean delete(T toDelete, StoresByPathManager<T> manager)
{
+ Class<? extends Object> modelClass = toDelete.getClass();
+ Class<? extends BaseMapping> baseMappingClass =
modelToMapping.get(modelClass);
+ if(baseMappingClass == null)
+ {
+ throw new IllegalArgumentException("Cannot find a mapping class for "
+ modelClass.getName());
+ }
+
ChromatticSession session = getSession();
- Object old = session.findByPath(toDelete.getClass(),
manager.getChildPath(toDelete));
+ Object old = session.findByPath(baseMappingClass, manager.getChildPath(toDelete));
if (old != null)
{
Modified:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java 2010-10-04
18:51:28 UTC (rev 4483)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java 2010-10-04
21:25:11 UTC (rev 4484)
@@ -205,7 +205,7 @@
public ProducerInfo next()
{
- return mappings.next().toProducerInfo();
+ return mappings.next().toModel(null);
}
public void remove()
Modified:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java 2010-10-04
18:51:28 UTC (rev 4483)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java 2010-10-04
21:25:11 UTC (rev 4484)
@@ -24,6 +24,7 @@
package org.gatein.portal.wsrp.state.consumer.mapping;
import org.chromattic.api.annotations.*;
+import org.gatein.portal.wsrp.state.mapping.BaseMapping;
import org.gatein.wsrp.consumer.EndpointConfigurationInfo;
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.RegistrationInfo;
@@ -33,7 +34,7 @@
* @version $Revision$
*/
@PrimaryType(name = ProducerInfoMapping.NODE_NAME)
-public abstract class ProducerInfoMapping
+public abstract class ProducerInfoMapping implements BaseMapping<ProducerInfo>
{
public static final String NODE_NAME = "wsrp:producerinfo";
@@ -84,7 +85,7 @@
rim.initFrom(regInfo);
}
- public ProducerInfo toProducerInfo()
+ public ProducerInfo toModel(ProducerInfo initial)
{
// todo: should probably use a ProducerInfo implementation backed by mapping at
some point
ProducerInfo info = new ProducerInfo();
Added:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/mapping/BaseMapping.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/mapping/BaseMapping.java
(rev 0)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/mapping/BaseMapping.java 2010-10-04
21:25:11 UTC (rev 4484)
@@ -0,0 +1,34 @@
+/*
+* 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.gatein.portal.wsrp.state.mapping;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public interface BaseMapping<T>
+{
+ void initFrom(T model);
+
+ T toModel(T initial);
+}
Modified:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/JCRMigrationService.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/JCRMigrationService.java 2010-10-04
18:51:28 UTC (rev 4483)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/JCRMigrationService.java 2010-10-04
21:25:11 UTC (rev 4484)
@@ -82,7 +82,7 @@
List<ExportInfo> exportInfos = new
ArrayList<ExportInfo>(exportInfoMappings.size());
for (ExportInfoMapping eim : exportInfoMappings)
{
- exportInfos.add(eim.toExportInfo());
+ exportInfos.add(eim.toModel(null));
}
persister.closeSession(session, false);
@@ -112,7 +112,7 @@
if(eim != null)
{
- return eim.toExportInfo();
+ return eim.toModel(null);
}
else
{
Modified:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportInfoMapping.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportInfoMapping.java 2010-10-04
18:51:28 UTC (rev 4483)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/mapping/ExportInfoMapping.java 2010-10-04
21:25:11 UTC (rev 4484)
@@ -29,6 +29,7 @@
import org.chromattic.api.annotations.Property;
import org.exoplatform.commons.utils.Safe;
import org.gatein.portal.wsrp.state.JCRPersister;
+import org.gatein.portal.wsrp.state.mapping.BaseMapping;
import org.gatein.wsrp.consumer.migration.ExportInfo;
import javax.xml.namespace.QName;
@@ -44,7 +45,7 @@
* @version $Revision$
*/
@PrimaryType(name = ExportInfoMapping.NODE_NAME)
-public abstract class ExportInfoMapping
+public abstract class ExportInfoMapping implements BaseMapping<ExportInfo>
{
public static final String NODE_NAME = "wsrp:exportinfo";
@@ -118,7 +119,7 @@
}
}
- public ExportInfo toExportInfo()
+ public ExportInfo toModel(ExportInfo initial)
{
List<ExportedStateMapping> exportedStates = getExportedStates();
SortedMap<String, byte[]> states = new TreeMap<String,byte[]>();