From do-not-reply at jboss.org Mon Oct 4 17:25:12 2010 Content-Type: multipart/mixed; boundary="===============0280106876633315167==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: gatein-commits at lists.jboss.org Subject: [gatein-commits] gatein SVN: r4484 - in portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state: consumer and 4 other directories. Date: Mon, 04 Oct 2010 17:25:12 -0400 Message-ID: <201010042125.o94LPCVb024953@svn01.web.mwc.hst.phx2.redhat.com> --===============0280106876633315167== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/gatei= n/portal/wsrp/state/mapping/BaseMapping.java Modified: portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatei= n/portal/wsrp/state/JCRPersister.java portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatei= n/portal/wsrp/state/consumer/JCRConsumerRegistry.java portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatei= n/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatei= n/portal/wsrp/state/migration/JCRMigrationService.java portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatei= n/portal/wsrp/state/migration/mapping/ExportInfoMapping.java Log: - GTNPORTAL-1529: Fixed inconsitent parameters in JCRPersister.delete metho= d. - Introduced BaseMapping to gather common behavior and possibly extends JCR= Persister with more generic methods down the road. Modified: portal/branches/wsrp2-integration/component/wsrp/src/main/java/or= g/gatein/portal/wsrp/state/JCRPersister.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gate= in/portal/wsrp/state/JCRPersister.java 2010-10-04 18:51:28 UTC (rev 4483) +++ portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gate= in/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 Chris Laprun @@ -50,6 +57,7 @@ public static final String PORTLET_STATES_WORKSPACE_NAME =3D "pc-system= "; private static final String REPOSITORY_NAME =3D "repository"; private String workspaceName; + private Map> modelToMapping; = public JCRPersister(ExoContainer container, String workspaceName) { @@ -73,8 +81,18 @@ throw new IllegalArgumentException("Unknown workspace name: '" + = workspaceName + "'"); } = + modelToMapping =3D new HashMap>(= mappingClasses.size()); for (Class mappingClass : mappingClasses) { + if (BaseMapping.class.isAssignableFrom(mappingClass)) + { + Type[] interfaces =3D mappingClass.getGenericInterfaces(); + if(ParameterValidation.existsAndIsNotEmpty(interfaces)) + { + Class type =3D (Class)((ParameterizedType)interfaces[0]).ge= tActualTypeArguments()[0]; + modelToMapping.put(type, mappingClass); + } + } builder.add(mappingClass); } = @@ -102,9 +120,16 @@ = public boolean delete(T toDelete, StoresByPathManager manager) { + Class modelClass =3D toDelete.getClass(); + Class baseMappingClass =3D modelToMapping.get= (modelClass); + if(baseMappingClass =3D=3D null) + { + throw new IllegalArgumentException("Cannot find a mapping class f= or " + modelClass.getName()); + } + ChromatticSession session =3D getSession(); = - Object old =3D session.findByPath(toDelete.getClass(), manager.getCh= ildPath(toDelete)); + Object old =3D session.findByPath(baseMappingClass, manager.getChild= Path(toDelete)); = if (old !=3D null) { Modified: portal/branches/wsrp2-integration/component/wsrp/src/main/java/or= g/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gate= in/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/gate= in/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/or= g/gatein/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gate= in/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java 2010-10-04 1= 8:51:28 UTC (rev 4483) +++ portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gate= in/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java 2010-10-04 2= 1: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 =3D ProducerInfoMapping.NODE_NAME) -public abstract class ProducerInfoMapping +public abstract class ProducerInfoMapping implements BaseMapping { public static final String NODE_NAME =3D "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 =3D new ProducerInfo(); Added: portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/g= atein/portal/wsrp/state/mapping/BaseMapping.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gate= in/portal/wsrp/state/mapping/BaseMapping.java (rev = 0) +++ portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gate= in/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 Chris Laprun + * @version $Revision$ + */ +public interface BaseMapping +{ + void initFrom(T model); + + T toModel(T initial); +} Modified: portal/branches/wsrp2-integration/component/wsrp/src/main/java/or= g/gatein/portal/wsrp/state/migration/JCRMigrationService.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gate= in/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/gate= in/portal/wsrp/state/migration/JCRMigrationService.java 2010-10-04 21:25:11= UTC (rev 4484) @@ -82,7 +82,7 @@ List exportInfos =3D new ArrayList(exportInf= oMappings.size()); for (ExportInfoMapping eim : exportInfoMappings) { - exportInfos.add(eim.toExportInfo()); + exportInfos.add(eim.toModel(null)); } = persister.closeSession(session, false); @@ -112,7 +112,7 @@ = if(eim !=3D null) { - return eim.toExportInfo(); + return eim.toModel(null); } else { Modified: portal/branches/wsrp2-integration/component/wsrp/src/main/java/or= g/gatein/portal/wsrp/state/migration/mapping/ExportInfoMapping.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gate= in/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/gate= in/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 =3D ExportInfoMapping.NODE_NAME) -public abstract class ExportInfoMapping +public abstract class ExportInfoMapping implements BaseMapping { public static final String NODE_NAME =3D "wsrp:exportinfo"; = @@ -118,7 +119,7 @@ } } = - public ExportInfo toExportInfo() + public ExportInfo toModel(ExportInfo initial) { List exportedStates =3D getExportedStates(); SortedMap states =3D new TreeMap(); --===============0280106876633315167==--