Author: chris.laprun(a)jboss.com
Date: 2011-01-21 04:35:09 -0500 (Fri, 21 Jan 2011)
New Revision: 5805
Added:
components/wsrp/trunk/jcr-impl/
components/wsrp/trunk/jcr-impl/pom.xml
components/wsrp/trunk/jcr-impl/src/
components/wsrp/trunk/jcr-impl/src/main/
components/wsrp/trunk/jcr-impl/src/main/java/
components/wsrp/trunk/jcr-impl/src/main/java/org/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/JCRMigrationService.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportErrorMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfoMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfosMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportedStateMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/EndpointInfoMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfoMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfosMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/RegistrationInfoMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/RegistrationPropertyMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/ChromatticPersister.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/StoresByPathManager.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/BaseMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/MappedMap.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/Utils.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationService.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/ProducerConfigurationMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/RegistrationRequirementsMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/JCRPortletStatePersistenceManager.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/mapping/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/mapping/PortletStateContextMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/mapping/PortletStateContextsMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/mapping/PortletStateMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerCapabilitiesMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerGroupMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumersAndGroupsMapping.java
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/RegistrationPropertiesMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationPropertyDescriptionMapping.java
components/wsrp/trunk/jcr-impl/src/test/
components/wsrp/trunk/jcr-impl/src/test/java/
components/wsrp/trunk/jcr-impl/src/test/java/org/
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/jcr/
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/jcr/mapping/
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/jcr/mapping/MappedMapTestCase.java
Modified:
components/wsrp/trunk/pom.xml
Log:
- GTNWSRP-196: First commit of migrated code in jcr-impl module.
+ Introduced ChromatticPersister interface to allow for JCR-implementation specific
versions.
+ Re-organized packages to be more consistent with WSRP code organization.
+ Not code-complete or tested integration-wise yet.
Added: components/wsrp/trunk/jcr-impl/pom.xml
===================================================================
--- components/wsrp/trunk/jcr-impl/pom.xml (rev 0)
+++ components/wsrp/trunk/jcr-impl/pom.xml 2011-01-21 09:35:09 UTC (rev 5805)
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>wsrp-parent</artifactId>
+ <groupId>org.gatein.wsrp</groupId>
+ <version>2.1.0-Alpha01-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>jcr-impl</artifactId>
+ <name>GateIn WSRP JCR-based persistence implementation</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.gatein.wsrp</groupId>
+ <artifactId>wsrp-consumer</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.gatein.wsrp</groupId>
+ <artifactId>wsrp-producer-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.gatein.wsrp</groupId>
+ <artifactId>wsrp-integration-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.chromattic</groupId>
+ <artifactId>chromattic.api</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.gatein.common</groupId>
+ <artifactId>common-common</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/JCRMigrationService.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/JCRMigrationService.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/JCRMigrationService.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,196 @@
+/*
+ * 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.consumer.migration;
+
+import org.chromattic.api.ChromatticSession;
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.wsrp.api.context.ConsumerStructureProvider;
+import org.gatein.wsrp.consumer.migration.mapping.ExportErrorMapping;
+import org.gatein.wsrp.consumer.migration.mapping.ExportInfoMapping;
+import org.gatein.wsrp.consumer.migration.mapping.ExportInfosMapping;
+import org.gatein.wsrp.consumer.migration.mapping.ExportedStateMapping;
+import org.gatein.wsrp.jcr.ChromatticPersister;
+import org.gatein.wsrp.jcr.StoresByPathManager;
+
+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 JCRMigrationService implements MigrationService,
StoresByPathManager<ExportInfo>
+{
+ private ConsumerStructureProvider structureProvider;
+ private ChromatticPersister persister;
+ private static final String EXPORT_INFOS_PATH = ExportInfosMapping.NODE_NAME;
+ private int exportInfosCount = -1;
+
+ public static final List<Class> mappingClasses = new ArrayList<Class>(4);
+
+ static
+ {
+ Collections.addAll(mappingClasses, ExportInfosMapping.class,
ExportInfoMapping.class, ExportedStateMapping.class,
+ ExportErrorMapping.class);
+ }
+
+
+ public JCRMigrationService(ChromatticPersister persister) throws Exception
+ {
+ this.persister = persister;
+ }
+
+ public ConsumerStructureProvider getStructureProvider()
+ {
+ return structureProvider;
+ }
+
+ public void setStructureProvider(ConsumerStructureProvider structureProvider)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(structureProvider,
"PortalStructureProvider");
+ this.structureProvider = structureProvider;
+ }
+
+ public List<ExportInfo> getAvailableExportInfos()
+ {
+ ChromatticSession session = persister.getSession();
+
+ ExportInfosMapping exportInfosMapping = getExportInfosMapping(session);
+
+ List<ExportInfoMapping> exportInfoMappings =
exportInfosMapping.getExportInfos();
+ List<ExportInfo> exportInfos = new
ArrayList<ExportInfo>(exportInfoMappings.size());
+ for (ExportInfoMapping eim : exportInfoMappings)
+ {
+ exportInfos.add(eim.toModel(null));
+ }
+
+ persister.closeSession(false);
+
+ exportInfosCount = exportInfos.size();
+
+ return exportInfos;
+ }
+
+ private ExportInfosMapping getExportInfosMapping(ChromatticSession session)
+ {
+ ExportInfosMapping exportInfosMapping =
session.findByPath(ExportInfosMapping.class, ExportInfosMapping.NODE_NAME);
+ if (exportInfosMapping == null)
+ {
+ exportInfosMapping = session.insert(ExportInfosMapping.class,
ExportInfosMapping.NODE_NAME);
+ exportInfosCount = 0;
+ }
+
+ return exportInfosMapping;
+ }
+
+ public ExportInfo getExportInfo(long exportTime)
+ {
+ ChromatticSession session = persister.getSession();
+
+ ExportInfoMapping eim = session.findByPath(ExportInfoMapping.class,
getPathFor(exportTime));
+
+ try
+ {
+ if (eim != null)
+ {
+ return eim.toModel(null);
+ }
+ else
+ {
+ return null;
+ }
+ }
+ finally
+ {
+ persister.closeSession(false);
+ }
+ }
+
+ public void add(ExportInfo info)
+ {
+ ChromatticSession session = persister.getSession();
+
+ ExportInfoMapping eim = session.findByPath(ExportInfoMapping.class,
getChildPath(info));
+ long exportTime = info.getExportTime();
+ if (eim != null)
+ {
+ persister.closeSession(false);
+ throw new IllegalArgumentException("An ExportInfo with export time "
+ + exportTime + " already exists!");
+ }
+ else
+ {
+ ExportInfosMapping exportInfosMapping = getExportInfosMapping(session);
+ String exportTimeAsString = "" + exportTime;
+ ExportInfoMapping exportInfo =
exportInfosMapping.createExportInfo(exportTimeAsString);
+ session.persist(exportInfosMapping, exportInfo, exportTimeAsString);
+ exportInfo.initFrom(info);
+
+ persister.closeSession(true);
+ exportInfosCount++;
+ }
+ }
+
+ public ExportInfo remove(ExportInfo info)
+ {
+ if (persister.delete(info, this))
+ {
+ exportInfosCount--;
+ return info;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public boolean isAvailableExportInfosEmpty()
+ {
+ if (exportInfosCount == -1)
+ {
+ ChromatticSession session = persister.getSession();
+ ExportInfosMapping mappings = getExportInfosMapping(session);
+ exportInfosCount = mappings.getExportInfos().size();
+ persister.closeSession(false);
+ }
+
+ return exportInfosCount == 0;
+ }
+
+ public String getParentPath()
+ {
+ return EXPORT_INFOS_PATH;
+ }
+
+ public String getChildPath(ExportInfo exportInfo)
+ {
+ return getPathFor(exportInfo.getExportTime());
+ }
+
+ private String getPathFor(final long exportTime)
+ {
+ return getParentPath() + "/" + exportTime;
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportErrorMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportErrorMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportErrorMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,84 @@
+/*
+ * 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.consumer.migration.mapping;
+
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+import org.gatein.common.util.ParameterValidation;
+
+import javax.xml.namespace.QName;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = ExportErrorMapping.NODE_NAME)
+public abstract class ExportErrorMapping
+{
+ public static final String NODE_NAME = "wsrp:exporterror";
+ private static final String COMMA = ",";
+
+ @Property(name = "errorcode")
+ public abstract String getCode();
+
+ public abstract void setCode(String code);
+
+ @Property(name = "handles")
+ public abstract String getHandles();
+
+ public abstract void setHandles(String handles);
+
+ public QName getErrorCode()
+ {
+ return QName.valueOf(getCode());
+ }
+
+ public List<String> getPortletHandles()
+ {
+ return Arrays.asList(getHandles().split(COMMA));
+ }
+
+ public void initFrom(QName errorCode, List<String> handles)
+ {
+ setCode(errorCode.toString());
+
+ if (ParameterValidation.existsAndIsNotEmpty(handles))
+ {
+ StringBuilder sb = new StringBuilder();
+ int size = handles.size();
+ int index = 0;
+ for (String handle : handles)
+ {
+ sb.append(handle);
+ if (index++ < size)
+ {
+ sb.append(COMMA);
+ }
+ }
+ setHandles(sb.toString());
+ }
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfoMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfoMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfoMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,143 @@
+/*
+ * 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.consumer.migration.mapping;
+
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+import org.gatein.wsrp.consumer.migration.ExportInfo;
+import org.gatein.wsrp.jcr.ChromatticPersister;
+import org.gatein.wsrp.jcr.mapping.BaseMapping;
+import org.gatein.wsrp.jcr.mapping.Utils;
+
+import javax.xml.namespace.QName;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = ExportInfoMapping.NODE_NAME)
+public abstract class ExportInfoMapping implements BaseMapping<ExportInfo>
+{
+ public static final String NODE_NAME = "wsrp:exportinfo";
+
+ @Property(name = "exporttime")
+ public abstract long getExportTime();
+
+ public abstract void setExportTime(long exportTime);
+
+ @Property(name = "expirationtime")
+ public abstract long getExpirationTime();
+
+ public abstract void setExpirationTime(long expirationTime);
+
+ @Property(name = "exportcontext")
+ public abstract InputStream getExportContext();
+
+ public abstract void setExportContext(InputStream exportContext);
+
+ @OneToMany
+ public abstract List<ExportedStateMapping> getExportedStates();
+
+ @Create
+ public abstract ExportedStateMapping internalCreateExportedState(String
portletHandle);
+
+ public ExportedStateMapping createExportedState(String portletHandle)
+ {
+ return
internalCreateExportedState(ChromatticPersister.PortletNameFormatter.encode(portletHandle));
+ }
+
+ @OneToMany
+ protected abstract List<ExportErrorMapping> getErrors();
+
+ @Create
+ public abstract ExportErrorMapping internalCreateError(String errorCode);
+
+ public ExportErrorMapping createError(String errorCode)
+ {
+ return internalCreateError(ChromatticPersister.QNameFormatter.encode(errorCode));
+ }
+
+ public void initFrom(ExportInfo exportInfo)
+ {
+ setExportTime(exportInfo.getExportTime());
+ setExpirationTime(exportInfo.getExpirationTime());
+
+ byte[] exportContext = exportInfo.getExportContext();
+ if (exportContext != null && exportContext.length > 0)
+ {
+ ByteArrayInputStream is = new ByteArrayInputStream(exportContext);
+ setExportContext(is);
+ }
+
+ List<ExportedStateMapping> exportedStates = getExportedStates();
+ exportedStates.clear();
+ for (String handle : exportInfo.getExportedPortletHandles())
+ {
+ ExportedStateMapping exportedState = createExportedState(handle);
+
+ // add then init idiom
+ exportedStates.add(exportedState);
+ exportedState.initFrom(handle, exportInfo.getPortletStateFor(handle));
+ }
+
+ List<ExportErrorMapping> errors = getErrors();
+ errors.clear();
+ for (Map.Entry<QName, List<String>> entry :
exportInfo.getErrorCodesToFailedPortletHandlesMapping().entrySet())
+ {
+ QName errorCode = entry.getKey();
+ ExportErrorMapping error = createError(errorCode.toString());
+
+ // add then init idiom
+ errors.add(error);
+ error.initFrom(errorCode, entry.getValue());
+ }
+ }
+
+ public ExportInfo toModel(ExportInfo initial)
+ {
+ List<ExportedStateMapping> exportedStates = getExportedStates();
+ SortedMap<String, byte[]> states = new TreeMap<String, byte[]>();
+ for (ExportedStateMapping exportedState : exportedStates)
+ {
+
states.put(ChromatticPersister.PortletNameFormatter.decode(exportedState.getHandle()),
Utils.safeGetBytes(exportedState.getState()));
+ }
+
+ List<ExportErrorMapping> errors = getErrors();
+ SortedMap<QName, List<String>> errorCodesToHandles = new
TreeMap<QName, List<String>>();
+ for (ExportErrorMapping error : errors)
+ {
+ errorCodesToHandles.put(error.getErrorCode(), error.getPortletHandles());
+ }
+
+ return new ExportInfo(getExportTime(), errorCodesToHandles, states,
Utils.safeGetBytes(getExportContext()));
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfosMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfosMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfosMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,47 @@
+/*
+ * 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.consumer.migration.mapping;
+
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.PrimaryType;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = ExportInfosMapping.NODE_NAME)
+public abstract class ExportInfosMapping
+{
+
+ public static final String NODE_NAME = "wsrp:exportinfos";
+
+ @OneToMany
+ public abstract List<ExportInfoMapping> getExportInfos();
+
+ @Create
+ public abstract ExportInfoMapping createExportInfo(String exportTimeAsString);
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportedStateMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportedStateMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportedStateMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -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.consumer.migration.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 = ExportedStateMapping.NODE_NAME)
+public abstract class ExportedStateMapping
+{
+ public static final String NODE_NAME = "wsrp:exportedstate";
+
+ @Property(name = "handle")
+ public abstract String getHandle();
+
+ public abstract void setHandle(String handle);
+
+ @Property(name = "state")
+ public abstract InputStream getState();
+
+ public abstract void setState(InputStream state);
+
+ public void initFrom(String handle, byte[] state)
+ {
+ setHandle(handle);
+
+ if (state != null && state.length > 0)
+ {
+ ByteArrayInputStream is = new ByteArrayInputStream(state);
+ setState(is);
+ }
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,238 @@
+/*
+ * 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.consumer.registry;
+
+import org.chromattic.api.ChromatticSession;
+import org.gatein.wsrp.WSRPConsumer;
+import org.gatein.wsrp.consumer.ConsumerException;
+import org.gatein.wsrp.consumer.ProducerInfo;
+import org.gatein.wsrp.consumer.registry.mapping.EndpointInfoMapping;
+import org.gatein.wsrp.consumer.registry.mapping.ProducerInfoMapping;
+import org.gatein.wsrp.consumer.registry.mapping.ProducerInfosMapping;
+import org.gatein.wsrp.consumer.registry.mapping.RegistrationInfoMapping;
+import org.gatein.wsrp.consumer.registry.mapping.RegistrationPropertyMapping;
+import org.gatein.wsrp.consumer.registry.xml.XMLConsumerRegistry;
+import org.gatein.wsrp.jcr.ChromatticPersister;
+import org.gatein.wsrp.jcr.StoresByPathManager;
+import org.gatein.wsrp.registration.mapping.RegistrationPropertyDescriptionMapping;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class JCRConsumerRegistry extends AbstractConsumerRegistry implements
StoresByPathManager<ProducerInfo>
+{
+ private ChromatticPersister persister;
+ private static final String PRODUCER_INFOS_PATH = ProducerInfosMapping.NODE_NAME;
+
+ public static final List<Class> mappingClasses = new ArrayList<Class>(6);
+
+ static
+ {
+ Collections.addAll(mappingClasses, ProducerInfosMapping.class,
ProducerInfoMapping.class,
+ EndpointInfoMapping.class, RegistrationInfoMapping.class,
RegistrationPropertyMapping.class,
+ RegistrationPropertyDescriptionMapping.class);
+ }
+
+ public JCRConsumerRegistry(ChromatticPersister persister) throws Exception
+ {
+ this.persister = persister;
+ }
+
+ @Override
+ protected void save(ProducerInfo info, String messageOnError)
+ {
+
+ try
+ {
+ ChromatticSession session = persister.getSession();
+
+ ProducerInfosMapping pims = getProducerInfosMapping(session);
+ ProducerInfoMapping pim = pims.createProducerInfo(info.getId());
+ String key = session.persist(pims, pim, info.getId());
+ info.setKey(key);
+ pim.initFrom(info);
+
+ persister.closeSession(true);
+ }
+ catch (Exception e)
+ {
+ persister.closeSession(false);
+ throw new ConsumerException(messageOnError, e);
+ }
+ }
+
+ @Override
+ protected void delete(ProducerInfo info)
+ {
+ if (!persister.delete(info, this))
+ {
+ throw new ConsumerException("Couldn't delete ProducerInfo " +
info);
+ }
+ }
+
+ @Override
+ protected String update(ProducerInfo producerInfo)
+ {
+ String key = producerInfo.getKey();
+ if (key == null)
+ {
+ throw new IllegalArgumentException("ProducerInfo '" +
producerInfo.getId()
+ + "' hasn't been persisted and thus cannot be updated.");
+ }
+
+ String oldId;
+ String newId;
+ boolean idUnchanged;
+
+ ChromatticSession session = persister.getSession();
+
+ synchronized (this)
+ {
+ ProducerInfoMapping pim = session.findById(ProducerInfoMapping.class, key);
+ if (pim == null)
+ {
+ throw new IllegalArgumentException("Couldn't find
ProducerInfoMapping associated with key " + key);
+ }
+ oldId = pim.getId();
+ newId = producerInfo.getId();
+ pim.initFrom(producerInfo);
+
+ idUnchanged = oldId.equals(newId);
+
+ if (!idUnchanged)
+ {
+ ProducerInfosMapping pims = getProducerInfosMapping(session);
+ Map<String, ProducerInfoMapping> nameToProducerInfoMap =
pims.getNameToProducerInfoMap();
+ nameToProducerInfoMap.put(pim.getId(), pim);
+ }
+
+ persister.closeSession(true);
+ }
+
+ // if the consumer's id has changed, return the old one so that state can be
updated
+ return idUnchanged ? null : oldId;
+ }
+
+ @Override
+ protected Iterator<ProducerInfo> getProducerInfosFromStorage()
+ {
+ ChromatticSession session = persister.getSession();
+ ProducerInfosMapping producerInfosMapping = getProducerInfosMapping(session);
+
+ List<ProducerInfoMapping> mappings =
producerInfosMapping.getProducerInfos();
+
+ persister.closeSession(true);
+
+ return new MappingToProducerInfoIterator(mappings.iterator());
+ }
+
+ private ProducerInfosMapping getProducerInfosMapping(ChromatticSession session)
+ {
+ ProducerInfosMapping producerInfosMapping =
session.findByPath(ProducerInfosMapping.class, PRODUCER_INFOS_PATH);
+
+ // if we don't have info from JCR, load from XML and populate JCR
+ if (producerInfosMapping == null)
+ {
+ producerInfosMapping = session.insert(ProducerInfosMapping.class,
ProducerInfosMapping.NODE_NAME);
+
+ List<ProducerInfoMapping> infos =
producerInfosMapping.getProducerInfos();
+
+ // Load from XML
+ XMLConsumerRegistry fromXML = new XMLConsumerRegistry();
+ fromXML.reloadConsumers();
+
+ // Save to JCR
+ List<WSRPConsumer> consumers = fromXML.getConfiguredConsumers();
+ for (WSRPConsumer consumer : consumers)
+ {
+ ProducerInfo info = consumer.getProducerInfo();
+
+ ProducerInfoMapping pim =
producerInfosMapping.createProducerInfo(info.getId());
+
+ // need to add to parent first to attach newly created ProducerInfoMapping
+ infos.add(pim);
+
+ // init it from ProducerInfo
+ pim.initFrom(info);
+ }
+ }
+
+ return producerInfosMapping;
+ }
+
+ public String getChildPath(ProducerInfo needsComputedPath)
+ {
+ return getPathFor(needsComputedPath);
+ }
+
+ private static String getPathFor(ProducerInfo info)
+ {
+ return PRODUCER_INFOS_PATH + "/" + info.getId();
+ }
+
+ private static ProducerInfoMapping toProducerInfoMapping(ProducerInfo producerInfo,
ChromatticSession session)
+ {
+ ProducerInfoMapping pim = session.findById(ProducerInfoMapping.class,
producerInfo.getKey());
+ if (pim == null)
+ {
+ pim = session.insert(ProducerInfoMapping.class, getPathFor(producerInfo));
+ }
+
+ pim.initFrom(producerInfo);
+
+ return pim;
+ }
+
+ private static class MappingToProducerInfoIterator implements
Iterator<ProducerInfo>
+ {
+ private Iterator<ProducerInfoMapping> mappings;
+
+ public MappingToProducerInfoIterator(Iterator<ProducerInfoMapping>
infoMappingIterator)
+ {
+ this.mappings = infoMappingIterator;
+ }
+
+ public boolean hasNext()
+ {
+ return mappings.hasNext();
+ }
+
+ public ProducerInfo next()
+ {
+ return mappings.next().toModel(null);
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException("Remove not supported!");
+ }
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/EndpointInfoMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/EndpointInfoMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/EndpointInfoMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -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.consumer.registry.mapping;
+
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+import org.gatein.wsrp.consumer.EndpointConfigurationInfo;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = EndpointInfoMapping.NODE_NAME)
+public abstract class EndpointInfoMapping
+{
+ public static final String NODE_NAME = "wsrp:endpointinfo";
+
+ @Property(name = "wsdlurl")
+ public abstract String getWSDLURL();
+
+ public abstract void setWSDLURL(String wsdlURL);
+
+ @Property(name = "timeout")
+ public abstract Integer getWSTimeoutMilliseconds();
+
+ public abstract void setWSTimeoutMilliseconds(Integer expiration);
+
+ public void initFrom(EndpointConfigurationInfo info)
+ {
+ setWSDLURL(info.getWsdlDefinitionURL());
+ setWSTimeoutMilliseconds(info.getWSOperationTimeOut());
+ }
+
+ EndpointConfigurationInfo toEndpointConfigurationInfo(EndpointConfigurationInfo
initial)
+ {
+ initial.setWsdlDefinitionURL(getWSDLURL());
+ initial.setWSOperationTimeOut(getWSTimeoutMilliseconds());
+ return initial;
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfoMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfoMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfoMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,114 @@
+/*
+ * 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.consumer.registry.mapping;
+
+import org.chromattic.api.annotations.Id;
+import org.chromattic.api.annotations.MappedBy;
+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.wsrp.consumer.EndpointConfigurationInfo;
+import org.gatein.wsrp.consumer.ProducerInfo;
+import org.gatein.wsrp.consumer.RegistrationInfo;
+import org.gatein.wsrp.jcr.mapping.BaseMapping;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = ProducerInfoMapping.NODE_NAME)
+public abstract class ProducerInfoMapping implements BaseMapping<ProducerInfo>
+{
+ public static final String NODE_NAME = "wsrp:producerinfo";
+
+ @OneToOne
+ @Owner
+ @MappedBy("endpoint")
+ public abstract EndpointInfoMapping getEndpointInfo();
+
+ @OneToOne
+ @Owner
+ @MappedBy("registration")
+ public abstract RegistrationInfoMapping getRegistrationInfo();
+
+ @Property(name = "producerid")
+ public abstract String getId();
+
+ public abstract void setId(String id);
+
+ @Property(name = "cache")
+ public abstract Integer getExpirationCacheSeconds();
+
+ public abstract void setExpirationCacheSeconds(Integer expiration);
+
+ @Property(name = "active", defaultValue = "false")
+ public abstract boolean getActive();
+
+ public abstract void setActive(boolean active);
+
+ @Id
+ public abstract String getKey();
+
+ /* @Property(name = "available")
+public abstract boolean getAvailable();
+
+public abstract void setAvailable(boolean available);*/
+
+ public void initFrom(ProducerInfo producerInfo)
+ {
+ setActive(producerInfo.isActive());
+ setExpirationCacheSeconds(producerInfo.getExpirationCacheSeconds());
+ setId(producerInfo.getId());
+
+ EndpointInfoMapping eim = getEndpointInfo();
+ eim.initFrom(producerInfo.getEndpointConfigurationInfo());
+
+ RegistrationInfoMapping rim = getRegistrationInfo();
+ RegistrationInfo regInfo = producerInfo.getRegistrationInfo();
+ rim.initFrom(regInfo);
+ }
+
+ public ProducerInfo toModel(ProducerInfo initial)
+ {
+ // todo: should probably use a ProducerInfo implementation backed by mapping at
some point
+ ProducerInfo info = new ProducerInfo();
+
+ // basic properties
+ info.setKey(getKey());
+ info.setId(getId());
+ info.setActive(getActive());
+ info.setExpirationCacheSeconds(getExpirationCacheSeconds());
+
+ // endpoint
+ EndpointConfigurationInfo endInfo =
getEndpointInfo().toEndpointConfigurationInfo(info.getEndpointConfigurationInfo());
+ info.setEndpointConfigurationInfo(endInfo);
+
+ // registration
+ RegistrationInfo regInfo =
getRegistrationInfo().toRegistrationInfo(info.getRegistrationInfo());
+ info.setRegistrationInfo(regInfo);
+
+ return info;
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfosMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfosMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfosMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,50 @@
+/*
+ * 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.consumer.registry.mapping;
+
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.PrimaryType;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = ProducerInfosMapping.NODE_NAME)
+public abstract class ProducerInfosMapping
+{
+ public static final String NODE_NAME = "wsrp:producerinfos";
+
+ @OneToMany
+ public abstract List<ProducerInfoMapping> getProducerInfos();
+
+ @OneToMany
+ public abstract Map<String, ProducerInfoMapping> getNameToProducerInfoMap();
+
+ @Create
+ public abstract ProducerInfoMapping createProducerInfo(String producerId);
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/RegistrationInfoMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/RegistrationInfoMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/RegistrationInfoMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,124 @@
+/*
+ * 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.consumer.registry.mapping;
+
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.FormattedBy;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+import org.gatein.wsrp.consumer.RegistrationInfo;
+import org.gatein.wsrp.consumer.RegistrationProperty;
+import org.gatein.wsrp.jcr.ChromatticPersister;
+import org.gatein.wsrp.jcr.mapping.Utils;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+import org.gatein.wsrp.registration.mapping.RegistrationPropertyDescriptionMapping;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = RegistrationInfoMapping.NODE_NAME)
+(a)FormattedBy(ChromatticPersister.QNameFormatter.class)
+public abstract class RegistrationInfoMapping
+{
+ public static final String NODE_NAME = "wsrp:registrationinfo";
+
+ @Property(name = "consumername")
+ public abstract String getConsumerName();
+
+ public abstract void setConsumerName(String name);
+
+ @Property(name = "handle")
+ public abstract String getRegistrationHandle();
+
+ public abstract void setRegistrationHandle(String handle);
+
+ @Property(name = "state")
+ public abstract InputStream getRegistrationState();
+
+ public abstract void setRegistrationState(InputStream state);
+
+ @OneToMany
+ public abstract List<RegistrationPropertyMapping> getRegistrationProperties();
+
+ @Create
+ public abstract RegistrationPropertyMapping createRegistrationProperty(String
propertyName);
+
+ public void initFrom(RegistrationInfo regInfo)
+ {
+ setConsumerName(regInfo.getConsumerName());
+ setRegistrationHandle(regInfo.getRegistrationHandle());
+ byte[] bytes = regInfo.getRegistrationState();
+ if (bytes != null && bytes.length > 0)
+ {
+ ByteArrayInputStream is = new ByteArrayInputStream(bytes);
+ setRegistrationState(is);
+ }
+
+ // clear and recreate registration properties
+ List<RegistrationPropertyMapping> rpms = getRegistrationProperties();
+ rpms.clear();
+ for (RegistrationProperty property : regInfo.getRegistrationProperties().values())
+ {
+ // create new RegistrationPropertyMapping for this RegistrationInfoMapping
+ RegistrationPropertyMapping rpm =
createRegistrationProperty(property.getName().toString());
+
+ // add newly created RegistrationPropertyMapping to parent then initialize for
JCR
+ rpms.add(rpm);
+ rpm.initFrom(property);
+ }
+ }
+
+ RegistrationInfo toRegistrationInfo(RegistrationInfo initial)
+ {
+ initial.setConsumerName(getConsumerName());
+ initial.setRegistrationHandle(getRegistrationHandle());
+ initial.setRegistrationState(Utils.safeGetBytes(getRegistrationState()));
+
+ // registration properties
+ for (RegistrationPropertyMapping rpm : getRegistrationProperties())
+ {
+ RegistrationProperty prop = initial.setRegistrationPropertyValue(rpm.getName(),
rpm.getValue());
+
+ RegistrationPropertyDescriptionMapping rpdm = rpm.getDescription();
+ if (rpdm != null)
+ {
+ RegistrationPropertyDescription desc =
rpdm.toRegistrationPropertyDescription();
+ prop.setDescription(desc);
+ }
+
+ prop.setStatus(rpm.getStatus());
+
+ // set RegistrationInfo as listener of property changes
+ prop.setListener(initial);
+ }
+
+ return initial;
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/RegistrationPropertyMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/RegistrationPropertyMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/RegistrationPropertyMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,86 @@
+/*
+ * 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.consumer.registry.mapping;
+
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.MappedBy;
+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.wsrp.consumer.RegistrationProperty;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+import org.gatein.wsrp.registration.mapping.RegistrationPropertyDescriptionMapping;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = RegistrationPropertyMapping.NODE_NAME)
+public abstract class RegistrationPropertyMapping
+{
+ public static final String NODE_NAME = "wsrp:registrationproperty";
+
+ @Property(name = "name")
+ public abstract String getName();
+
+ public abstract void setName(String name);
+
+ @Property(name = "value")
+ public abstract String getValue();
+
+ public abstract void setValue(String value);
+
+ @OneToOne
+ @Owner
+ @MappedBy("description")
+ public abstract RegistrationPropertyDescriptionMapping getDescription();
+
+ public abstract void setDescription(RegistrationPropertyDescriptionMapping rpdm);
+
+ @Create
+ public abstract RegistrationPropertyDescriptionMapping createDescription();
+
+ @Property(name = "status")
+ public abstract RegistrationProperty.Status getStatus();
+
+ public abstract void setStatus(RegistrationProperty.Status status);
+
+ public void initFrom(RegistrationProperty property)
+ {
+ // set properties
+ setName(property.getName().toString());
+ setStatus(property.getStatus());
+ setValue(property.getValue());
+
+ // description
+ RegistrationPropertyDescription desc = property.getDescription();
+ if (desc != null)
+ {
+ RegistrationPropertyDescriptionMapping rpdm = createDescription();
+ setDescription(rpdm);
+ rpdm.initFrom(desc);
+ }
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/ChromatticPersister.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/ChromatticPersister.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/ChromatticPersister.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,109 @@
+/*
+ * 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.jcr;
+
+import org.chromattic.api.ChromatticSession;
+import org.chromattic.api.format.FormatterContext;
+import org.chromattic.api.format.ObjectFormatter;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public interface ChromatticPersister
+{
+ ChromatticSession getSession();
+
+ void closeSession(boolean save);
+
+ void save();
+
+ <T> boolean delete(T toDelete, StoresByPathManager<T> manager);
+
+ public static class QNameFormatter implements ObjectFormatter
+ {
+ 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)
+ {
+ return decode(s);
+ }
+
+ public String encodeNodeName(FormatterContext formatterContext, String s)
+ {
+ return encode(s);
+ }
+
+ public String decodePropertyName(FormatterContext formatterContext, String s)
+ {
+ return decode(s);
+ }
+
+ public String encodePropertyName(FormatterContext formatterContext, String s)
+ {
+ return encode(s);
+ }
+
+ public static String decode(String s)
+ {
+ return s.replace(CLOSE_BRACE_REPLACEMENT,
CLOSE_BRACE).replace(OPEN_BRACE_REPLACEMENT, OPEN_BRACE).replace(COLON_REPLACEMENT,
COLON);
+ }
+
+ public static String encode(String s)
+ {
+ 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 decode(s);
+ }
+
+ public static String decode(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:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/StoresByPathManager.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/StoresByPathManager.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/StoresByPathManager.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,33 @@
+/*
+ * 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.jcr;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public interface StoresByPathManager<C>
+{
+ String getChildPath(C needsComputedPath);
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/BaseMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/BaseMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/BaseMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,35 @@
+/*
+ * 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.jcr.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);
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/MappedMap.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/MappedMap.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/MappedMap.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,127 @@
+/*
+ * 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.jcr.mapping;
+
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.common.util.Tools;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+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.toSet("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))
+ {
+ // remove existing values (apart from blacklisted ones that we shouldn't
touch)
+ Set<String> keys = new HashSet<String>(internalMap.keySet());
+ for (String key : keys)
+ {
+ if (!blacklistedPropertyKeys.contains(key))
+ {
+ internalMap.remove(key);
+ }
+ }
+
+ // put the new values in
+ 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:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/Utils.java
===================================================================
--- components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/Utils.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/Utils.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,62 @@
+/*
+ * 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.jcr.mapping;
+
+import org.gatein.common.io.IOTools;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ * @deprecated Remove when we can use common 2.0.4
+ */
+public class Utils
+{
+ public static byte[] safeGetBytes(InputStream is)
+ {
+ byte[] bytes;
+
+ if (is == null)
+ {
+ return null;
+ }
+
+ try
+ {
+ bytes = IOTools.getBytes(is);
+ return bytes;
+ }
+ catch (IOException ignore)
+ {
+ // todo: should log
+ return null;
+ }
+ finally
+ {
+ IOTools.safeClose(is);
+ }
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationService.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationService.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationService.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,115 @@
+/*
+ * 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.producer.config;
+
+import org.chromattic.api.ChromatticSession;
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.wsrp.jcr.ChromatticPersister;
+import org.gatein.wsrp.producer.config.impl.AbstractProducerConfigurationService;
+import org.gatein.wsrp.producer.config.impl.xml.SimpleXMLProducerConfigurationService;
+import org.gatein.wsrp.producer.config.mapping.ProducerConfigurationMapping;
+import org.gatein.wsrp.producer.config.mapping.RegistrationRequirementsMapping;
+import org.gatein.wsrp.registration.mapping.RegistrationPropertyDescriptionMapping;
+
+import java.io.InputStream;
+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 JCRProducerConfigurationService extends
AbstractProducerConfigurationService
+{
+ private static String PRODUCER_CONFIGURATION_PATH =
ProducerConfigurationMapping.NODE_NAME;
+
+ private InputStream defaultConfigurationIS;
+ private ChromatticPersister persister;
+
+ public static final List<Class> mappingClasses = new ArrayList<Class>(3);
+
+ static
+ {
+ Collections.addAll(mappingClasses, ProducerConfigurationMapping.class,
RegistrationRequirementsMapping.class,
+ RegistrationPropertyDescriptionMapping.class);
+ }
+
+ public JCRProducerConfigurationService(ChromatticPersister persister) throws
Exception
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(persister,
"ChromatticPersister");
+ this.persister = persister;
+ }
+
+ /**
+ * todo: remove
+ *
+ * @param is
+ * @deprecated this should be removed when a better initialization of default is
setup
+ */
+ public void setDefaultConfigurationIS(InputStream is)
+ {
+ this.defaultConfigurationIS = is;
+ }
+
+ protected void loadConfiguration() throws Exception
+ {
+ // Try loading configuration from JCR first
+ ChromatticSession session = persister.getSession();
+ ProducerConfigurationMapping pcm =
session.findByPath(ProducerConfigurationMapping.class, PRODUCER_CONFIGURATION_PATH);
+
+ // if we don't have a configuration persisted in JCR already, force a reload
from XML and save the resulting configuration
+ if (pcm == null)
+ {
+ pcm = session.insert(ProducerConfigurationMapping.class,
PRODUCER_CONFIGURATION_PATH);
+
+ ProducerConfigurationService service = new
SimpleXMLProducerConfigurationService(defaultConfigurationIS);
+
+ service.reloadConfiguration();
+ configuration = service.getConfiguration();
+ pcm.initFrom(configuration);
+ }
+ else
+ {
+ configuration = pcm.toProducerConfiguration();
+ }
+
+
+ persister.closeSession(true);
+ }
+
+ public void saveConfiguration() throws Exception
+ {
+ ChromatticSession session = persister.getSession();
+
+ ProducerConfigurationMapping pcm =
session.findByPath(ProducerConfigurationMapping.class, PRODUCER_CONFIGURATION_PATH);
+ if (pcm == null)
+ {
+ pcm = session.insert(ProducerConfigurationMapping.class,
PRODUCER_CONFIGURATION_PATH);
+ }
+ pcm.initFrom(configuration);
+
+ persister.closeSession(true);
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/ProducerConfigurationMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/ProducerConfigurationMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/ProducerConfigurationMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,73 @@
+/*
+ * 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.producer.config.mapping;
+
+import org.chromattic.api.annotations.MappedBy;
+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.wsrp.producer.config.ProducerConfiguration;
+import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
+import org.gatein.wsrp.producer.config.impl.ProducerConfigurationImpl;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = ProducerConfigurationMapping.NODE_NAME)
+public abstract class ProducerConfigurationMapping
+{
+ public static final String NODE_NAME = "wsrp:producerconfiguration";
+
+ @Property(name = "strictmode")
+ public abstract boolean getUsingStrictMode();
+
+ public abstract void setUsingStrictMode(boolean strict);
+
+ @OneToOne
+ @Owner
+ @MappedBy("registrationrequirements")
+ public abstract RegistrationRequirementsMapping getRegistrationRequirements();
+
+ public void initFrom(ProducerConfiguration configuration)
+ {
+ setUsingStrictMode(configuration.isUsingStrictMode());
+
+ RegistrationRequirementsMapping rrm = getRegistrationRequirements();
+ rrm.initFrom(configuration.getRegistrationRequirements());
+ }
+
+ public ProducerConfiguration toProducerConfiguration()
+ {
+ ProducerConfigurationImpl configuration = new ProducerConfigurationImpl();
+
+ configuration.setUsingStrictMode(getUsingStrictMode());
+
+ ProducerRegistrationRequirements req =
getRegistrationRequirements().toProducerRegistrationRequirements();
+ configuration.setRegistrationRequirements(req);
+
+ return configuration;
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/RegistrationRequirementsMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/RegistrationRequirementsMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/RegistrationRequirementsMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,120 @@
+/*
+ * 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.producer.config.mapping;
+
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.FindById;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+import org.gatein.registration.RegistrationPolicy;
+import org.gatein.registration.policies.DefaultRegistrationPolicy;
+import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
+import org.gatein.wsrp.producer.config.impl.ProducerRegistrationRequirementsImpl;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+import org.gatein.wsrp.registration.mapping.RegistrationPropertyDescriptionMapping;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = RegistrationRequirementsMapping.NODE_NAME)
+public abstract class RegistrationRequirementsMapping
+{
+ public static final String NODE_NAME = "wsrp:registrationrequirements";
+
+ @Property(name = "registrationrequired")
+ public abstract boolean getRegistrationRequired();
+
+ public abstract void setRegistrationRequired(boolean requiresRegistration);
+
+ @Property(name = "registrationrequiredforfulldescription")
+ public abstract boolean getRegistrationRequiredForFullDescription();
+
+ public abstract void setRegistrationRequiredForFullDescription(boolean
fullServiceDescriptionRequiresRegistration);
+
+ @Property(name = "policyclassname")
+ public abstract String getPolicyClassName();
+
+ public abstract void setPolicyClassName(String policyClassName);
+
+ @Property(name = "validatorclassname")
+ public abstract String getValidatorClassName();
+
+ public abstract void setValidatorClassName(String validatorClassName);
+
+ @OneToMany
+ public abstract List<RegistrationPropertyDescriptionMapping>
getRegistrationPropertyDescriptions();
+
+ @Create
+ public abstract RegistrationPropertyDescriptionMapping
createRegistrationPropertyDescription(String propertyName);
+
+ @FindById
+ public abstract RegistrationPropertyDescriptionMapping
findRegistrationPropertyDescriptionById(String id);
+
+ public void initFrom(ProducerRegistrationRequirements registrationRequirements)
+ {
+ setRegistrationRequired(registrationRequirements.isRegistrationRequired());
+
setRegistrationRequiredForFullDescription(registrationRequirements.isRegistrationRequiredForFullDescription());
+ RegistrationPolicy policy = registrationRequirements.getPolicy();
+ setPolicyClassName(policy.getClass().getName());
+ if (policy instanceof DefaultRegistrationPolicy)
+ {
+ DefaultRegistrationPolicy drp = (DefaultRegistrationPolicy)policy;
+ setValidatorClassName(drp.getValidator().getClass().getName());
+ }
+
+ // first clear persisted properties
+ List<RegistrationPropertyDescriptionMapping> rpdms =
getRegistrationPropertyDescriptions();
+ rpdms.clear();
+
+ // then add the new ones if any
+ for (RegistrationPropertyDescription desc :
registrationRequirements.getRegistrationProperties().values())
+ {
+ RegistrationPropertyDescriptionMapping rpdm =
createRegistrationPropertyDescription(desc.getNameAsString());
+
+ // attach first to parent, then init
+ rpdms.add(rpdm);
+ rpdm.initFrom(desc);
+ }
+ }
+
+ public ProducerRegistrationRequirements toProducerRegistrationRequirements()
+ {
+ ProducerRegistrationRequirements req = new ProducerRegistrationRequirementsImpl();
+
+ req.setRegistrationRequired(getRegistrationRequired());
+
req.setRegistrationRequiredForFullDescription(getRegistrationRequiredForFullDescription());
+ req.reloadPolicyFrom(getPolicyClassName(), getValidatorClassName());
+
+ for (RegistrationPropertyDescriptionMapping rpdm :
getRegistrationPropertyDescriptions())
+ {
+ req.addRegistrationProperty(rpdm.toRegistrationPropertyDescription());
+ }
+
+ return req;
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/JCRPortletStatePersistenceManager.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/JCRPortletStatePersistenceManager.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/JCRPortletStatePersistenceManager.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,167 @@
+/*
+ * 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.producer.state;
+
+import org.chromattic.api.ChromatticSession;
+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.wsrp.jcr.ChromatticPersister;
+import org.gatein.wsrp.producer.state.mapping.PortletStateContextMapping;
+import org.gatein.wsrp.producer.state.mapping.PortletStateContextsMapping;
+import org.gatein.wsrp.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 ChromatticPersister persister;
+ private static final String PATH = PortletStateContextsMapping.NODE_NAME +
"/";
+
+ public static final List<Class> mappingClasses = new ArrayList<Class>(3);
+
+ static
+ {
+ Collections.addAll(mappingClasses, PortletStateContextsMapping.class,
PortletStateContextMapping.class, PortletStateMapping.class);
+ }
+
+ public JCRPortletStatePersistenceManager(ChromatticPersister persister) throws
Exception
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(persister,
"ChromatticPersister");
+ this.persister = persister;
+ }
+
+ 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(true);
+ }
+
+
+ @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(false);
+
+ return context;
+ }
+
+ @Override
+ protected String createStateContext(String portletId, PropertyMap propertyMap)
+ {
+ ChromatticSession session = persister.getSession();
+
+ String encodedForPath =
ChromatticPersister.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(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(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:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/mapping/PortletStateContextMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/mapping/PortletStateContextMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/mapping/PortletStateContextMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,72 @@
+/*
+ * 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.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.Owner;
+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 = "pc:statecontext";
+
+ @Id
+ public abstract String getPersistentKey();
+
+ @Name
+ public abstract String getPortletId();
+
+ @OneToOne
+ @Owner
+ @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:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/mapping/PortletStateContextsMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/mapping/PortletStateContextsMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/mapping/PortletStateContextsMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,53 @@
+/*
+ * 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.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.wsrp.jcr.ChromatticPersister;
+
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = PortletStateContextsMapping.NODE_NAME)
+(a)FormattedBy(ChromatticPersister.PortletNameFormatter.class)
+public abstract class PortletStateContextsMapping
+{
+ public static final String NODE_NAME = "pc:producerstates";
+
+ @OneToMany
+ public abstract Collection<PortletStateContextMapping>
getPortletStateContexts();
+
+ @Create
+ public abstract PortletStateContextMapping createPortletStateContext(String id);
+
+ @FindById
+ public abstract PortletStateContextMapping findPortletStateContextById(String id);
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/mapping/PortletStateMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/mapping/PortletStateMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/state/mapping/PortletStateMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,158 @@
+/*
+ * 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.producer.state.mapping;
+
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Properties;
+import org.chromattic.api.annotations.Property;
+import org.gatein.pc.api.state.PropertyMap;
+import org.gatein.pc.portlet.state.SimplePropertyMap;
+import org.gatein.wsrp.jcr.mapping.MappedMap;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @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 = "pc:state";
+
+ private static final String PORTLET_ID = "pc:portletid";
+ private static final String TERMINATION_TIME = "pc: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);
+ }
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,249 @@
+/*
+ * 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;
+
+import org.chromattic.api.ChromatticSession;
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.registration.Consumer;
+import org.gatein.registration.ConsumerGroup;
+import org.gatein.registration.Registration;
+import org.gatein.registration.RegistrationException;
+import org.gatein.registration.impl.RegistrationPersistenceManagerImpl;
+import org.gatein.registration.spi.ConsumerGroupSPI;
+import org.gatein.registration.spi.ConsumerSPI;
+import org.gatein.registration.spi.RegistrationSPI;
+import org.gatein.wsrp.jcr.ChromatticPersister;
+import org.gatein.wsrp.registration.mapping.ConsumerCapabilitiesMapping;
+import org.gatein.wsrp.registration.mapping.ConsumerGroupMapping;
+import org.gatein.wsrp.registration.mapping.ConsumerMapping;
+import org.gatein.wsrp.registration.mapping.ConsumersAndGroupsMapping;
+import org.gatein.wsrp.registration.mapping.RegistrationMapping;
+import org.gatein.wsrp.registration.mapping.RegistrationPropertiesMapping;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class JCRRegistrationPersistenceManager extends
RegistrationPersistenceManagerImpl
+{
+ private ChromatticPersister persister;
+ private ConsumersAndGroupsMapping mappings;
+
+ public static final List<Class> mappingClasses = new ArrayList<Class>(6);
+
+ static
+ {
+ Collections.addAll(mappingClasses, ConsumersAndGroupsMapping.class,
ConsumerMapping.class, ConsumerGroupMapping.class,
+ RegistrationMapping.class, ConsumerCapabilitiesMapping.class,
RegistrationPropertiesMapping.class);
+ }
+
+
+ public JCRRegistrationPersistenceManager(ChromatticPersister persister) throws
Exception
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(persister,
"ChromatticPersister");
+ this.persister = persister;
+
+ ChromatticSession session = persister.getSession();
+ mappings = session.findByPath(ConsumersAndGroupsMapping.class,
ConsumersAndGroupsMapping.NODE_NAME);
+ if (mappings == null)
+ {
+ mappings = session.insert(ConsumersAndGroupsMapping.class,
ConsumersAndGroupsMapping.NODE_NAME);
+ }
+ persister.save(); // needed right now as the session must still be open to iterate
over nodes
+
+ for (ConsumerGroupMapping cgm : mappings.getConsumerGroups())
+ {
+ internalAddConsumerGroup(cgm.toConsumerGroup(this));
+ }
+
+ for (ConsumerMapping cm : mappings.getConsumers())
+ {
+ ConsumerSPI consumer = cm.toConsumer(this);
+ internalAddConsumer(consumer);
+
+ // get the registrations and add them to local map.
+ for (Registration registration : consumer.getRegistrations())
+ {
+ internalAddRegistration((RegistrationSPI)registration);
+ }
+ }
+
+ persister.closeSession(false);
+ }
+
+ @Override
+ protected RegistrationSPI internalRemoveRegistration(String registrationId)
+ {
+ Registration registration = getRegistration(registrationId);
+ remove(registration.getPersistentKey(), RegistrationMapping.class);
+
+ return super.internalRemoveRegistration(registrationId);
+ }
+
+ @Override
+ protected RegistrationSPI internalCreateRegistration(ConsumerSPI consumer, Map
registrationProperties)
+ {
+ ChromatticSession session = persister.getSession();
+ RegistrationSPI registration = null;
+ try
+ {
+ ConsumerMapping cm = session.findById(ConsumerMapping.class,
consumer.getPersistentKey());
+ RegistrationMapping rm = cm.createAndAddRegistrationMappingFrom(null);
+ registration = newRegistrationSPI(consumer, registrationProperties,
rm.getPersistentKey());
+ rm.initFrom(registration);
+ persister.closeSession(true);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(); // todo fix me
+ persister.closeSession(false);
+ }
+
+ return registration;
+ }
+
+ @Override
+ protected ConsumerSPI internalRemoveConsumer(String consumerId)
+ {
+ remove(consumerId, ConsumerMapping.class);
+
+ return super.internalRemoveConsumer(consumerId);
+ }
+
+ private void remove(String id, Class clazz)
+ {
+ ChromatticSession session = persister.getSession();
+ session.remove(session.findById(clazz, id));
+ persister.closeSession(true);
+ }
+
+ @Override
+ protected ConsumerSPI internalCreateConsumer(String consumerId, String consumerName)
+ {
+ ConsumerSPI consumer = super.internalCreateConsumer(consumerId, consumerName);
+
+ ChromatticSession session = persister.getSession();
+ mappings = session.findByPath(ConsumersAndGroupsMapping.class,
ConsumersAndGroupsMapping.NODE_NAME); // todo: needed?
+ try
+ {
+ ConsumerMapping cm = mappings.createConsumer(consumerId);
+ mappings.getConsumers().add(cm);
+ cm.initFrom(consumer);
+ consumer.setPersistentKey(cm.getPersistentKey());
+ persister.closeSession(true);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(); // todo: fix me
+ persister.closeSession(false);
+ }
+
+ return consumer;
+ }
+
+ @Override
+ protected ConsumerSPI internalSaveChangesTo(Consumer consumer)
+ {
+ ConsumerSPI consumerSPI = super.internalSaveChangesTo(consumer);
+
+ ChromatticSession session = persister.getSession();
+ try
+ {
+ ConsumerMapping cm = session.findById(ConsumerMapping.class,
consumer.getPersistentKey());
+ cm.initFrom(consumer);
+ persister.closeSession(true);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(); // todo: fix me
+ persister.closeSession(false);
+ }
+
+ return consumerSPI;
+ }
+
+ protected RegistrationSPI internalSaveChangesTo(Registration registration)
+ {
+ RegistrationSPI registrationSPI = super.internalSaveChangesTo(registration);
+
+ ChromatticSession session = persister.getSession();
+ try
+ {
+ RegistrationMapping cm = session.findById(RegistrationMapping.class,
registration.getPersistentKey());
+ cm.initFrom(registration);
+ persister.closeSession(true);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(); //todo: fix me
+ persister.closeSession(false);
+ }
+
+ return registrationSPI;
+ }
+
+ @Override
+ protected ConsumerGroupSPI internalRemoveConsumerGroup(String name)
+ {
+ try
+ {
+ ConsumerGroup group = getConsumerGroup(name);
+ remove(group.getPersistentKey(), ConsumerGroupMapping.class);
+ }
+ catch (RegistrationException e)
+ {
+ throw new IllegalArgumentException("Couldn't remove ConsumerGroup
'" + name + "'", e);
+ }
+
+ return super.internalRemoveConsumerGroup(name);
+ }
+
+ @Override
+ protected ConsumerGroupSPI internalCreateConsumerGroup(String name)
+ {
+ ConsumerGroupSPI group = super.internalCreateConsumerGroup(name);
+
+ ChromatticSession session = persister.getSession();
+ try
+ {
+ ConsumerGroupMapping cgm = mappings.createConsumerGroup(name);
+ mappings.getConsumerGroups().add(cgm);
+ group.setPersistentKey(cgm.getPersistentKey());
+ cgm.initFrom(group);
+ persister.closeSession(true);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(); // todo: fix me
+ persister.closeSession(false);
+ }
+
+ return group;
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerCapabilitiesMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerCapabilitiesMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerCapabilitiesMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,155 @@
+/*
+ * 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 org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.Mode;
+import org.gatein.pc.api.WindowState;
+import org.gatein.registration.ConsumerCapabilities;
+import org.gatein.registration.impl.ConsumerCapabilitiesImpl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = ConsumerCapabilitiesMapping.NODE_NAME)
+public abstract class ConsumerCapabilitiesMapping
+{
+ public static final String NODE_NAME = "wsrp:consumercapabilities";
+
+ @Property(name = "supportsgetmethod")
+ public abstract boolean getSupportsGetMethod();
+
+ public abstract void setSupportsGetMethod(boolean supportsGetMethod);
+
+ @Property(name = "modes")
+ public abstract List<String> getSupportedModes();
+
+ public abstract void setSupportedModes(List<String> modes);
+
+ @Property(name = "windowstates")
+ public abstract List<String> getSupportedWindowStates();
+
+ public abstract void setSupportedWindowStates(List<String> windowStates);
+
+ @Property(name = "userscopes")
+ public abstract List<String> getSupportedUserScopes();
+
+ public abstract void setSupportedUserScopes(List<String> userScopes);
+
+ @Property(name = "userprofiledata")
+ public abstract List<String> getSupportedUserProfileData();
+
+ public abstract void setSupportedUserProfileData(List<String> userProfileData);
+
+
+ public void initFrom(ConsumerCapabilities capabilities)
+ {
+ setSupportsGetMethod(capabilities.supportsGetMethod());
+
+ List<String> modes = convertToStringList(capabilities.getSupportedModes());
+ if (modes != null)
+ {
+ setSupportedModes(modes);
+ }
+ List<String> states =
convertToStringList(capabilities.getSupportedWindowStates());
+ if (states != null)
+ {
+ setSupportedWindowStates(states);
+ }
+ List<String> scopes = capabilities.getSupportedUserScopes();
+ if (ParameterValidation.existsAndIsNotEmpty(scopes))
+ {
+ setSupportedUserScopes(scopes);
+ }
+ List<String> userProfileData = capabilities.getSupportedUserProfileData();
+ if (ParameterValidation.existsAndIsNotEmpty(userProfileData))
+ {
+ setSupportedUserProfileData(userProfileData);
+ }
+ }
+
+ private List<String> convertToStringList(List list)
+ {
+ if (ParameterValidation.existsAndIsNotEmpty(list))
+ {
+ List<String> result = new ArrayList<String>(list.size());
+ for (Object object : list)
+ {
+ result.add(object.toString());
+ }
+ return result;
+ }
+
+ return null;
+ }
+
+ public ConsumerCapabilities toConsumerCapabilities()
+ {
+ ConsumerCapabilitiesImpl consumerCapabilities = new ConsumerCapabilitiesImpl();
+
+ consumerCapabilities.setSupportsGetMethod(getSupportsGetMethod());
+
+ List<String> modeStrings = getSupportedModes();
+ if (ParameterValidation.existsAndIsNotEmpty(modeStrings))
+ {
+ List<Mode> modes = new ArrayList<Mode>(modeStrings.size());
+ for (String modeString : modeStrings)
+ {
+ modes.add(Mode.create(modeString));
+ }
+ consumerCapabilities.setSupportedModes(modes);
+ }
+
+ List<String> windowStateStrings = getSupportedWindowStates();
+ if (ParameterValidation.existsAndIsNotEmpty(windowStateStrings))
+ {
+ List<WindowState> windowStates = new
ArrayList<WindowState>(windowStateStrings.size());
+ for (String windowStateString : windowStateStrings)
+ {
+ windowStates.add(WindowState.create(windowStateString));
+ }
+ consumerCapabilities.setSupportedWindowStates(windowStates);
+ }
+
+ List<String> userProfileData = getSupportedUserProfileData();
+ if (ParameterValidation.existsAndIsNotEmpty(userProfileData))
+ {
+ consumerCapabilities.setSupportedUserProfileData(userProfileData);
+ }
+
+ List<String> userScopes = getSupportedUserScopes();
+ if (ParameterValidation.existsAndIsNotEmpty(userScopes))
+ {
+ consumerCapabilities.setSupportedUserScopes(userScopes);
+ }
+
+ return consumerCapabilities;
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerGroupMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerGroupMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerGroupMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,116 @@
+/*
+ * 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.RelationshipType;
+import org.chromattic.api.annotations.FindById;
+import org.chromattic.api.annotations.Id;
+import org.chromattic.api.annotations.MappedBy;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.registration.Consumer;
+import org.gatein.registration.ConsumerGroup;
+import org.gatein.registration.RegistrationException;
+import org.gatein.registration.RegistrationStatus;
+import org.gatein.registration.spi.ConsumerGroupSPI;
+import org.gatein.wsrp.registration.JCRRegistrationPersistenceManager;
+
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = ConsumerGroupMapping.NODE_NAME)
+public abstract class ConsumerGroupMapping
+{
+ public static final String NODE_NAME = "wsrp:consumergroup";
+
+ @OneToMany(type = RelationshipType.PATH)
+ @MappedBy("group")
+ public abstract Collection<ConsumerMapping> getConsumers();
+
+ @Property(name = "name")
+ public abstract String getName();
+
+ public abstract void setName(String name);
+
+ @Property(name = "status")
+ public abstract RegistrationStatus getStatus();
+
+ public abstract void setStatus(RegistrationStatus status);
+
+ @Id
+ public abstract String getPersistentKey();
+
+ @FindById
+ public abstract ConsumerMapping findConsumerById(String id);
+
+ public void initFrom(ConsumerGroup group)
+ {
+ setName(group.getName());
+ setStatus(group.getStatus());
+
+ try
+ {
+ for (Consumer consumer : group.getConsumers())
+ {
+ String id = consumer.getPersistentKey();
+ ConsumerMapping cm = findConsumerById(id);
+ ParameterValidation.throwIllegalArgExceptionIfNull(cm, "ConsumerMapping
(no such mapping with id: " + id + ")");
+ getConsumers().add(cm);
+ cm.initFrom(consumer);
+ }
+ }
+ catch (RegistrationException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public ConsumerGroupSPI toConsumerGroup(JCRRegistrationPersistenceManager
persistenceManager) throws RegistrationException
+ {
+ ConsumerGroupSPI group = persistenceManager.newConsumerGroupSPI(getName());
+ RegistrationStatus status = getStatus();
+ if (status == null)
+ {
+ status = RegistrationStatus.PENDING;
+ }
+ group.setStatus(status);
+
+ for (ConsumerMapping cm : getConsumers())
+ {
+ Consumer consumer = persistenceManager.getConsumerById(cm.getPersistentKey());
+ if (consumer == null)
+ {
+ consumer = cm.toConsumer(persistenceManager);
+ }
+
+ group.addConsumer(consumer);
+ }
+ return group;
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,177 @@
+/*
+ * 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.RelationshipType;
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.FindById;
+import org.chromattic.api.annotations.Id;
+import org.chromattic.api.annotations.ManyToOne;
+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.registration.Consumer;
+import org.gatein.registration.ConsumerGroup;
+import org.gatein.registration.Registration;
+import org.gatein.registration.RegistrationException;
+import org.gatein.registration.spi.ConsumerSPI;
+import org.gatein.wsrp.registration.JCRRegistrationPersistenceManager;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = ConsumerMapping.NODE_NAME)
+public abstract class ConsumerMapping
+{
+ public static final String NODE_NAME = "wsrp:consumer";
+
+ @Id
+ public abstract String getPersistentKey();
+
+ @Property(name = "name")
+ public abstract String getName();
+
+ public abstract void setName(String name);
+
+ @Property(name = "id")
+ public abstract String getId();
+
+ public abstract void setId(String id);
+
+ @Property(name = "consumeragent")
+ public abstract String getConsumerAgent();
+
+ public abstract void setConsumerAgent(String consumerAgent);
+
+ @OneToMany
+ public abstract List<RegistrationMapping> getRegistrations();
+
+ @Create
+ public abstract RegistrationMapping createRegistration(String path);
+
+ @ManyToOne(type = RelationshipType.PATH)
+ @MappedBy("group")
+ public abstract ConsumerGroupMapping getGroup();
+
+ public abstract void setGroup(ConsumerGroupMapping group);
+
+ @OneToOne
+ @Owner
+ @MappedBy("capabilities")
+ public abstract ConsumerCapabilitiesMapping getCapabilities();
+
+ @FindById
+ public abstract ConsumerGroupMapping findGroupById(String id);
+
+ @FindById
+ public abstract RegistrationMapping findRegistrationById(String id);
+
+ public RegistrationMapping createAndAddRegistrationMappingFrom(Registration
registration)
+ {
+ RegistrationMapping rm;
+ if (registration != null)
+ {
+ // check if the registration has already been persisted and it should already be
associated to this ConsumerMapping
+ String key = registration.getPersistentKey();
+ if (key != null)
+ {
+ rm = findRegistrationById(key);
+ }
+ else
+ {
+ // else create the registration, add to parent
+ rm = createRegistration("" + System.nanoTime());
+ getRegistrations().add(rm);
+ }
+
+ // then init
+ rm.initFrom(registration);
+ }
+ else
+ {
+ // only create the registration and add to parent
+ rm = createRegistration("" + System.nanoTime());
+ getRegistrations().add(rm);
+ }
+
+ return rm;
+ }
+
+ public void initFrom(Consumer consumer)
+ {
+ setName(consumer.getName());
+ setId(consumer.getId());
+ setConsumerAgent(consumer.getConsumerAgent());
+
+ ConsumerGroup group = consumer.getGroup();
+ if (group != null)
+ {
+ ConsumerGroupMapping cgm = findGroupById(group.getPersistentKey());
+ setGroup(cgm);
+ }
+
+ ConsumerCapabilitiesMapping ccm = getCapabilities();
+ ccm.initFrom(consumer.getCapabilities());
+
+ try
+ {
+ for (Registration reg : consumer.getRegistrations())
+ {
+ createAndAddRegistrationMappingFrom(reg);
+ }
+ }
+ catch (RegistrationException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public ConsumerSPI toConsumer(JCRRegistrationPersistenceManager persistenceManager)
throws RegistrationException
+ {
+ ConsumerSPI consumer = persistenceManager.newConsumerSPI(getId(), getName());
+ consumer.setConsumerAgent(getConsumerAgent());
+ consumer.setPersistentKey(getPersistentKey());
+
+ consumer.setCapabilities(getCapabilities().toConsumerCapabilities());
+
+ ConsumerGroupMapping cgm = getGroup();
+ if (cgm != null)
+ {
+ consumer.setGroup(persistenceManager.getConsumerGroup(cgm.getName()));
+ }
+
+ for (RegistrationMapping rm : getRegistrations())
+ {
+ consumer.addRegistration(rm.toRegistration(persistenceManager, consumer));
+ }
+
+ return consumer;
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumersAndGroupsMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumersAndGroupsMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumersAndGroupsMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,52 @@
+/*
+ * 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.Create;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.PrimaryType;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = ConsumersAndGroupsMapping.NODE_NAME)
+public abstract class ConsumersAndGroupsMapping
+{
+ public static final String NODE_NAME = "wsrp:consumersandgroups";
+
+ @OneToMany
+ public abstract List<ConsumerMapping> getConsumers();
+
+ @OneToMany
+ public abstract List<ConsumerGroupMapping> getConsumerGroups();
+
+ @Create
+ public abstract ConsumerMapping createConsumer(String id);
+
+ @Create
+ public abstract ConsumerGroupMapping createConsumerGroup(String name);
+}
Added:
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
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,124 @@
+/*
+ * 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.Create;
+import org.chromattic.api.annotations.Id;
+import org.chromattic.api.annotations.MappedBy;
+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.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.registration.JCRRegistrationPersistenceManager;
+
+import javax.xml.namespace.QName;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = RegistrationMapping.NODE_NAME)
+public abstract class RegistrationMapping
+{
+ public static final String NODE_NAME = "wsrp:registration";
+
+ @Id
+ public abstract String getPersistentKey();
+
+ @Property(name = "status")
+ public abstract RegistrationStatus getStatus();
+
+ public abstract void setStatus(RegistrationStatus status);
+
+ @Property(name = "registrationhandle")
+ public abstract String getRegistrationHandle();
+
+ public abstract void setRegistrationHandle(String handle);
+
+ /*
+TODO: convert to use PortletContexts instead of just handles
+@Property(name="portlethandles")
+public abstract List<String> getPortletHandles();
+
+public abstract void setPortletHandles(List<String> portletHandles);*/
+
+ @OneToOne
+ @Owner
+ @MappedBy("properties")
+ public abstract RegistrationPropertiesMapping getProperties();
+
+ public abstract void setProperties(RegistrationPropertiesMapping rpm);
+
+ @Create
+ public abstract RegistrationPropertiesMapping createProperties();
+
+ /**
+ * At this point, this RegistrationMapping should already have been added to its
parent
+ *
+ * @param registration
+ */
+ public void initFrom(Registration registration)
+ {
+ setStatus(registration.getStatus());
+ setRegistrationHandle(registration.getRegistrationHandle());
+// setPortletHandles(registration.getPortletHandles()); // TODO
+
+ Map<QName, Object> properties = registration.getProperties();
+ if (ParameterValidation.existsAndIsNotEmpty(properties))
+ {
+ RegistrationPropertiesMapping rpm = getProperties();
+ if (rpm == null)
+ {
+ rpm = createProperties();
+ setProperties(rpm);
+ }
+ rpm.initFrom(properties);
+ }
+ }
+
+ public RegistrationSPI toRegistration(JCRRegistrationPersistenceManager
persistenceManager, ConsumerSPI consumer) throws RegistrationException
+ {
+ RegistrationPropertiesMapping rpm = getProperties();
+ Map<QName, Object> props = Collections.emptyMap();
+ if (rpm != null)
+ {
+ props = rpm.toPropMap();
+ }
+
+ RegistrationSPI reg = persistenceManager.newRegistrationSPI(consumer, props,
getPersistentKey());
+ reg.setStatus(getStatus());
+ reg.setRegistrationHandle(getRegistrationHandle());
+// reg.getPortletHandles().addAll(getPortletHandles()); // TODO
+
+ return reg;
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationPropertiesMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationPropertiesMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationPropertiesMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,87 @@
+/*
+ * 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.Properties;
+import org.gatein.common.util.Tools;
+
+import javax.xml.namespace.QName;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = RegistrationPropertiesMapping.NODE_NAME)
+public abstract class RegistrationPropertiesMapping
+{
+ public static final String NODE_NAME = "wsrp:registrationproperties";
+
+ /** Need to ignore JCR properties for now until scoping mechanism exists on
@Properties */
+ private static final Set<String> propertiesBlackList =
Tools.toSet("jcr:uuid", "jcr:primaryType");
+
+ @Properties
+ public abstract Map<String, String> getProperties();
+
+ public Map<QName, Object> toPropMap()
+ {
+ Map<String, String> propMap = getProperties();
+ if (!propMap.isEmpty())
+ {
+ Map<QName, Object> properties = new HashMap<QName,
Object>(propMap.size());
+ for (Map.Entry<String, String> entry : propMap.entrySet())
+ {
+ String key = entry.getKey();
+ // ignore JCR-specific properties
+ if (!propertiesBlackList.contains(key))
+ {
+ properties.put(QName.valueOf(key), entry.getValue());
+ }
+ }
+
+ return properties;
+ }
+ else
+ {
+ return Collections.emptyMap();
+ }
+ }
+
+ public void initFrom(Map<QName, Object> properties)
+ {
+ if (properties != null)
+ {
+ Map<String, String> map = getProperties();
+
+ for (Map.Entry<QName, Object> entry : properties.entrySet())
+ {
+ map.put(entry.getKey().toString(), entry.getValue().toString());
+ }
+ }
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationPropertyDescriptionMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationPropertyDescriptionMapping.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationPropertyDescriptionMapping.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,119 @@
+/*
+ * 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.Id;
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.wsrp.registration.LocalizedString;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = RegistrationPropertyDescriptionMapping.NODE_NAME)
+public abstract class RegistrationPropertyDescriptionMapping
+{
+ public static final String NODE_NAME =
"wsrp:registrationpropertydescription";
+
+ @Id
+ public abstract String getPersistentKey();
+
+ @Property(name = "name")
+ public abstract String getName(); // todo: this should really be a QName
+
+ public abstract void setName(String name);
+
+
+ @Property(name = "type")
+ public abstract String getType(); // todo: this should really be a QName
+
+ public abstract void setType(String type);
+
+ @Property(name = "description")
+ public abstract String getDescription(); // todo: this should really be a
LocalizedString
+
+ public abstract void setDescription(String description);
+
+ @Property(name = "hint")
+ public abstract String getHint(); // todo: this should really be a LocalizedString
+
+ public abstract void setHint(String hint);
+
+ @Property(name = "label")
+ public abstract String getLabel(); // todo: this should really be a LocalizedString
+
+ public abstract void setLabel(String label);
+
+ public void initFrom(RegistrationPropertyDescription desc)
+ {
+ LocalizedString description = desc.getDescription();
+ if (description != null)
+ {
+ setDescription(description.getValue());
+ }
+ LocalizedString hint = desc.getHint();
+ if (hint != null)
+ {
+ setHint(hint.getValue());
+ }
+ LocalizedString label = desc.getLabel();
+ if (label != null)
+ {
+ setLabel(label.getValue());
+ }
+
+ // convert QNames to Strings
+ setName(desc.getName().toString());
+ setType(desc.getType().toString());
+ }
+
+ public RegistrationPropertyDescription toRegistrationPropertyDescription()
+ {
+ RegistrationPropertyDescription desc = new
RegistrationPropertyDescription(getName(), QName.valueOf(getType()));
+ desc.setPersistentKey(getPersistentKey());
+
+ String description = getDescription();
+ if (!ParameterValidation.isNullOrEmpty(description))
+ {
+ desc.setDefaultDescription(description);
+ }
+ String hint = getHint();
+ if (!ParameterValidation.isNullOrEmpty(hint))
+ {
+ desc.setHint(new LocalizedString(hint));
+ }
+ String label = getLabel();
+ if (!ParameterValidation.isNullOrEmpty(label))
+ {
+ desc.setLabel(new LocalizedString(label));
+ }
+
+ return desc;
+ }
+}
Added:
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/jcr/mapping/MappedMapTestCase.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/jcr/mapping/MappedMapTestCase.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/jcr/mapping/MappedMapTestCase.java 2011-01-21
09:35:09 UTC (rev 5805)
@@ -0,0 +1,95 @@
+/*
+ * 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.jcr.mapping;
+
+import junit.framework.TestCase;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class MappedMapTestCase extends TestCase
+{
+ private MappedMap<String, String> mapped;
+
+ public void testInitFrom()
+ {
+ Map<String, String> external = new HashMap<String, String>();
+ external.put("bar", "barvalue");
+
+ Map<String, Object> internal = new HashMap<String, Object>();
+ internal.put("foo", "foovalue");
+ internal.put("baz", "bazvalue");
+
+ mapped.initFrom(external, internal);
+
+ assertEquals("foovalue", internal.get("foo"));
+ assertEquals("barvalue", internal.get("bar"));
+ assertNull("baz isn't in the external map we initialize from so it
shouldn't be present anymore after", internal.get("baz"));
+ }
+
+ public void testToExternalMap()
+ {
+ Map<String, Object> internal = new HashMap<String, Object>();
+ internal.put("foo", "foovalue");
+ internal.put("baz", "bazvalue");
+
+ Map<String, String> external = mapped.toExternalMap(internal);
+
+ assertNull(external.get("foo"));
+ assertEquals("bazvalue", external.get("baz"));
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ mapped = new MappedMap<String, String>(new MappedMap.Converter<String,
String>()
+ {
+
+ public String fromInternal(String s)
+ {
+ return s;
+ }
+
+ public String toInternal(String s)
+ {
+ return s;
+ }
+ }, new MappedMap.Converter<Object, String>()
+ {
+ public String fromInternal(Object o)
+ {
+ return o.toString();
+ }
+
+ public Object toInternal(String s)
+ {
+ return s;
+ }
+ }, "foo");
+ }
+}
Modified: components/wsrp/trunk/pom.xml
===================================================================
--- components/wsrp/trunk/pom.xml 2011-01-20 21:33:36 UTC (rev 5804)
+++ components/wsrp/trunk/pom.xml 2011-01-21 09:35:09 UTC (rev 5805)
@@ -183,6 +183,7 @@
<module>admin-gui</module>
<module>wsrp-producer-war</module>
<module>hibernate-impl</module>
+ <module>jcr-impl</module>
</modules>
<repositories>