Author: chris.laprun(a)jboss.com
Date: 2009-11-22 20:08:00 -0500 (Sun, 22 Nov 2009)
New Revision: 751
Added:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/mapping/
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/mapping/RegistrationPropertyDescriptionMapping.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/JCRProducerConfigurationService.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/ProducerConfigurationMapping.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/RegistrationRequirementsMapping.java
Removed:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/ConsumerRegistry.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyDescriptionMapping.java
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyMapping.java
portal/branches/wsrp-integration/component/wsrp/src/test/java/org/gatein/portal/wsrp/state/consumer/ConsumerRegistryTestCase.java
Log:
- Started adding producer configuration persistence.
- Adapted ExoKernelIntegration to API changes and hooked JCRConsumerRegistry up (needs
testing).
- Started extracting common behavior into JCRPersister helper class.
- Renamed ConsumerRegistry to JCRConsumerRegistry.
- Moved RegistrationPropertyDescriptionMapping to new higher level package as it is now
shared between producer and consumer
persistence.
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java 2009-11-22
23:43:40 UTC (rev 750)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java 2009-11-23
01:08:00 UTC (rev 751)
@@ -31,6 +31,7 @@
import org.gatein.pc.portlet.impl.state.producer.PortletStatePersistenceManagerService;
import org.gatein.pc.portlet.state.StateConverter;
import org.gatein.pc.portlet.state.producer.ProducerPortletInvoker;
+import org.gatein.portal.wsrp.state.consumer.JCRConsumerRegistry;
import org.gatein.registration.RegistrationManager;
import org.gatein.registration.RegistrationPersistenceManager;
import org.gatein.registration.impl.RegistrationManagerImpl;
@@ -41,7 +42,6 @@
import org.gatein.wsrp.api.SessionEventBroadcaster;
import org.gatein.wsrp.api.SessionEventListener;
import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
-import org.gatein.wsrp.consumer.registry.xml.XMLConsumerRegistry;
import org.gatein.wsrp.producer.ProducerHolder;
import org.gatein.wsrp.producer.WSRPProducer;
import org.gatein.wsrp.producer.config.ProducerConfigurationService;
@@ -96,10 +96,10 @@
private void startProducer(ExoContainer container)
{
- ProducerConfigurationService producerConfigurationService = new
SimpleXMLProducerConfigurationService();
+ ProducerConfigurationService producerConfigurationService = new
SimpleXMLProducerConfigurationService(configurationIS);
try
{
- producerConfigurationService.loadConfigurationFrom(configurationIS);
+ producerConfigurationService.reloadConfiguration();
}
catch (Exception e)
{
@@ -152,12 +152,11 @@
FederatingPortletInvoker federatingPortletInvoker =
(FederatingPortletInvoker)container.getComponentInstanceOfType(PortletInvoker.class);
- consumerRegistry = new XMLConsumerRegistry();
- consumerRegistry.setFederatingPortletInvoker(federatingPortletInvoker);
- consumerRegistry.setSessionEventBroadcaster(new SimpleSessionEventBroadcaster());
-
try
{
+ consumerRegistry = new JCRConsumerRegistry();
+ consumerRegistry.setFederatingPortletInvoker(federatingPortletInvoker);
+ consumerRegistry.setSessionEventBroadcaster(new
SimpleSessionEventBroadcaster());
consumerRegistry.start();
}
catch (Exception e)
Added:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java
(rev 0)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java 2009-11-23
01:08:00 UTC (rev 751)
@@ -0,0 +1,58 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.gatein.portal.wsrp.state;
+
+import org.chromattic.api.Chromattic;
+import org.chromattic.api.ChromatticBuilder;
+import org.chromattic.api.ChromatticSession;
+import org.exoplatform.services.jcr.ext.registry.RegistryService;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class JCRPersister
+{
+ private Chromattic chrome;
+ public static final String WSRP_SERVICES_PATH = RegistryService.EXO_SERVICES +
"/wsrp/";
+
+ public void initializeBuilderFor(List<Class> mappingClasses) throws Exception
+ {
+ ChromatticBuilder builder = ChromatticBuilder.create();
+ builder.setOption(ChromatticBuilder.INSTRUMENTOR_CLASSNAME,
"org.chromattic.apt.InstrumentorImpl");
+
+ for (Class mappingClass : mappingClasses)
+ {
+ builder.add(mappingClass);
+ }
+
+ chrome = builder.build();
+ }
+
+ public ChromatticSession getSession()
+ {
+ return chrome.openSession();
+ }
+}
Deleted:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/ConsumerRegistry.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/ConsumerRegistry.java 2009-11-22
23:43:40 UTC (rev 750)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/ConsumerRegistry.java 2009-11-23
01:08:00 UTC (rev 751)
@@ -1,295 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2009, Red Hat Middleware, LLC, and individual
- * contributors as indicated by the @authors tag. See the
- * copyright.txt in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.gatein.portal.wsrp.state.consumer;
-
-import org.chromattic.api.Chromattic;
-import org.chromattic.api.ChromatticBuilder;
-import org.chromattic.api.ChromatticSession;
-import org.exoplatform.commons.utils.Safe;
-import org.exoplatform.container.xml.InitParams;
-import org.exoplatform.services.jcr.ext.registry.RegistryService;
-import org.gatein.portal.wsrp.state.consumer.mapping.EndpointInfoMapping;
-import org.gatein.portal.wsrp.state.consumer.mapping.ProducerInfoMapping;
-import org.gatein.portal.wsrp.state.consumer.mapping.ProducerInfosMapping;
-import org.gatein.portal.wsrp.state.consumer.mapping.RegistrationInfoMapping;
-import
org.gatein.portal.wsrp.state.consumer.mapping.RegistrationPropertyDescriptionMapping;
-import org.gatein.portal.wsrp.state.consumer.mapping.RegistrationPropertyMapping;
-import org.gatein.wsrp.WSRPConsumer;
-import org.gatein.wsrp.consumer.ProducerInfo;
-import org.gatein.wsrp.consumer.RegistrationInfo;
-import org.gatein.wsrp.consumer.RegistrationProperty;
-import org.gatein.wsrp.consumer.registry.AbstractConsumerRegistry;
-import org.gatein.wsrp.consumer.registry.xml.XMLConsumerRegistry;
-import org.gatein.wsrp.registration.LocalizedString;
-import org.gatein.wsrp.registration.RegistrationPropertyDescription;
-
-import javax.xml.namespace.QName;
-import java.io.ByteArrayInputStream;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision$
- */
-public class ConsumerRegistry extends AbstractConsumerRegistry
-{
- private Chromattic chrome;
- private static final String WSRP_SERVICES_PATH = RegistryService.EXO_SERVICES +
"/wsrp/";
- private static final String PRODUCER_INFOS_PATH = WSRP_SERVICES_PATH +
"producerinfos";
-
- public ConsumerRegistry() throws Exception
- {
- ChromatticBuilder builder = ChromatticBuilder.create();
- builder.setOption(ChromatticBuilder.INSTRUMENTOR_CLASSNAME,
"org.chromattic.apt.InstrumentorImpl");
-
- builder.add(ProducerInfosMapping.class);
- builder.add(ProducerInfoMapping.class);
- builder.add(EndpointInfoMapping.class);
- builder.add(RegistrationInfoMapping.class);
- builder.add(RegistrationPropertyMapping.class);
- builder.add(RegistrationPropertyDescriptionMapping.class);
-
- chrome = builder.build();
- }
-
- public ConsumerRegistry(InitParams params, RegistryService jcrRegistry) throws
Exception
- {
- this();
- }
-
- @Override
- protected void save(ProducerInfo info, String messageOnError)
- {
- String path = getPathFor(info);
- ChromatticSession session = chrome.openSession();
-
- String key = session.persist(toProducerInfoMapping(info, session), path);
- info.setKey(key);
-
- session.close();
- }
-
- @Override
- protected void delete(ProducerInfo info)
- {
- ChromatticSession session = chrome.openSession();
- delete(session, getPathFor(info));
-
- session.close();
- }
-
- @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.");
- }
-
- ChromatticSession session = chrome.openSession();
- session.persist(toProducerInfoMapping(producerInfo, session),
getPathFor(producerInfo));
-
- return null;
- }
-
- @Override
- protected Iterator<ProducerInfo> getProducerInfosFromStorage()
- {
- ChromatticSession session = chrome.openSession();
- ProducerInfosMapping producerInfosMapping =
session.findByPath(ProducerInfosMapping.class, PRODUCER_INFOS_PATH);
-
- Iterator<ProducerInfo> producerInfos;
-
- // if we don't have info from JCR, load from XML and populate JCR
- if (producerInfosMapping == null)
- {
- producerInfosMapping = session.insert(ProducerInfosMapping.class,
PRODUCER_INFOS_PATH);
-
- 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)
- {
- infos.add(toProducerInfoMapping(consumer.getProducerInfo(), session));
- }
- session.persist(infos); // todo: is that sufficient?
-
- producerInfos = new ProducerInfoIterator(consumers.iterator());
- }
- else
- {
- List<ProducerInfoMapping> mappings =
producerInfosMapping.getProducerInfos();
- producerInfos = new MappingToProducerInfoIterator(mappings.iterator());
- }
-
- session.save();
- session.close();
- return producerInfos;
- }
-
- private void delete(ChromatticSession session, String path)
- {
- ProducerInfoMapping old = session.findByPath(ProducerInfoMapping.class, path);
-
- if (old != null)
- {
- session.remove(old);
- }
- }
-
- 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.setActive(producerInfo.isActive());
- pim.setExpirationCacheSeconds(producerInfo.getExpirationCacheSeconds());
- pim.setId(producerInfo.getId());
-
- EndpointInfoMapping eim = pim.getEndpointInfo();
-
eim.setWSDLURL(producerInfo.getEndpointConfigurationInfo().getWsdlDefinitionURL());
-
- RegistrationInfoMapping rim = pim.getRegistrationInfo();
- RegistrationInfo regInfo = producerInfo.getRegistrationInfo();
- rim.setConsumerName(regInfo.getConsumerName());
- rim.setRegistrationHandle(regInfo.getRegistrationHandle());
- byte[] bytes = regInfo.getRegistrationState();
- if (bytes != null && bytes.length > 0)
- {
- ByteArrayInputStream is = new ByteArrayInputStream(bytes);
- rim.setRegistrationState(is);
- }
-
- // clear and recreate registration properties
- List<RegistrationPropertyMapping> rpms = rim.getRegistrationProperties();
- rpms.clear();
- for (RegistrationProperty property : regInfo.getRegistrationProperties().values())
- {
- // create new RegistrationPropertyMapping for this RegistrationInfoMapping
- RegistrationPropertyMapping rpm = rim.create();
-
- // set properties
- rpm.setStatus(property.getStatus().name());
- rpm.setValue(property.getValue());
-
- // description
- RegistrationPropertyDescriptionMapping rpdm = rpm.getDescription();
- RegistrationPropertyDescription desc = property.getDescription();
- rpdm.setDescription(desc.getDescription().getValue()); // todo: should really
persist LocalizedString here...
- rpdm.setHint(desc.getHint().getValue()); // todo: should really persist
LocalizedString here...
- rpdm.setLabel(desc.getLabel().getValue()); // todo: should really persist
LocalizedString here...
-
- // convert QNames to Strings
- rpdm.setName(desc.getName().toString());
- rpdm.setType(desc.getType().toString());
-
- // add newly created RegistrationPropertyMapping to parent
- rpms.add(rpm);
- }
-
- return pim;
- }
-
- private static ProducerInfo toProducerInfo(ProducerInfoMapping mapping)
- {
- // todo: should probably use a ProducerInfo implementation backed by mapping at
some point
- ProducerInfo info = new ProducerInfo();
-
- // basic properties
- info.setKey(mapping.getKey());
- info.setId(mapping.getId());
- info.setActive(mapping.getActive());
- info.setExpirationCacheSeconds(mapping.getExpirationCacheSeconds());
-
- // endpoint
-
info.getEndpointConfigurationInfo().setWsdlDefinitionURL(mapping.getEndpointInfo().getWSDLURL());
-
- // registration
- RegistrationInfo regInfo = info.getRegistrationInfo();
- RegistrationInfoMapping rim = mapping.getRegistrationInfo();
- regInfo.setConsumerName(rim.getConsumerName());
- regInfo.setRegistrationHandle(rim.getRegistrationHandle());
- regInfo.setRegistrationState(Safe.getBytes(rim.getRegistrationState()));
-
- // registration properties
- for (RegistrationPropertyMapping rpm : rim.getRegistrationProperties())
- {
- RegistrationPropertyDescriptionMapping rpdm = rpm.getDescription();
- String name = rpdm.getName();
-
- RegistrationProperty prop = regInfo.setRegistrationPropertyValue(name,
rpm.getValue());
-
- RegistrationPropertyDescription desc = new RegistrationPropertyDescription(name,
QName.valueOf(rpdm.getType()));
- desc.setDefaultDescription(rpdm.getDescription());
- desc.setHint(new LocalizedString(rpdm.getHint()));
- desc.setLabel(new LocalizedString(rpdm.getLabel()));
- prop.setDescription(desc);
-
- prop.setStatus(RegistrationProperty.Status.valueOf(rpm.getStatus()));
- }
-
- return info;
- }
-
- 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 toProducerInfo(mappings.next());
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException("Remove not supported!");
- }
- }
-}
Copied:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java
(from rev 747,
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/ConsumerRegistry.java)
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java
(rev 0)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java 2009-11-23
01:08:00 UTC (rev 751)
@@ -0,0 +1,290 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.portal.wsrp.state.consumer;
+
+import org.chromattic.api.ChromatticSession;
+import org.exoplatform.commons.utils.Safe;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.services.jcr.ext.registry.RegistryService;
+import org.gatein.portal.wsrp.state.JCRPersister;
+import org.gatein.portal.wsrp.state.consumer.mapping.EndpointInfoMapping;
+import org.gatein.portal.wsrp.state.consumer.mapping.ProducerInfoMapping;
+import org.gatein.portal.wsrp.state.consumer.mapping.ProducerInfosMapping;
+import org.gatein.portal.wsrp.state.consumer.mapping.RegistrationInfoMapping;
+import org.gatein.portal.wsrp.state.consumer.mapping.RegistrationPropertyMapping;
+import org.gatein.portal.wsrp.state.mapping.RegistrationPropertyDescriptionMapping;
+import org.gatein.wsrp.WSRPConsumer;
+import org.gatein.wsrp.consumer.ProducerInfo;
+import org.gatein.wsrp.consumer.RegistrationInfo;
+import org.gatein.wsrp.consumer.RegistrationProperty;
+import org.gatein.wsrp.consumer.registry.AbstractConsumerRegistry;
+import org.gatein.wsrp.consumer.registry.xml.XMLConsumerRegistry;
+import org.gatein.wsrp.registration.LocalizedString;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+
+import javax.xml.namespace.QName;
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class JCRConsumerRegistry extends AbstractConsumerRegistry
+{
+ private JCRPersister persister = new JCRPersister();
+ private static final String PRODUCER_INFOS_PATH = JCRPersister.WSRP_SERVICES_PATH +
"producerinfos";
+
+ public JCRConsumerRegistry() throws Exception
+ {
+ List<Class> mappingClasses = new ArrayList<Class>(6);
+ Collections.addAll(mappingClasses, ProducerInfosMapping.class,
ProducerInfoMapping.class,
+ EndpointInfoMapping.class, RegistrationInfoMapping.class,
RegistrationPropertyMapping.class,
+ RegistrationPropertyDescriptionMapping.class);
+
+ persister.initializeBuilderFor(mappingClasses);
+ }
+
+ public JCRConsumerRegistry(InitParams params, RegistryService jcrRegistry) throws
Exception
+ {
+ this();
+ }
+
+ @Override
+ protected void save(ProducerInfo info, String messageOnError)
+ {
+ String path = getPathFor(info);
+ ChromatticSession session = persister.getSession();
+
+ String key = session.persist(toProducerInfoMapping(info, session), path);
+ info.setKey(key);
+
+ session.close();
+ }
+
+ @Override
+ protected void delete(ProducerInfo info)
+ {
+ ChromatticSession session = persister.getSession();
+ delete(session, getPathFor(info));
+
+ session.close();
+ }
+
+ @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.");
+ }
+
+ ChromatticSession session = persister.getSession();
+ session.persist(toProducerInfoMapping(producerInfo, session),
getPathFor(producerInfo));
+
+ return null;
+ }
+
+ @Override
+ protected Iterator<ProducerInfo> getProducerInfosFromStorage()
+ {
+ ChromatticSession session = persister.getSession();
+ ProducerInfosMapping producerInfosMapping =
session.findByPath(ProducerInfosMapping.class, PRODUCER_INFOS_PATH);
+
+ Iterator<ProducerInfo> producerInfos;
+
+ // if we don't have info from JCR, load from XML and populate JCR
+ if (producerInfosMapping == null)
+ {
+ producerInfosMapping = session.insert(ProducerInfosMapping.class,
PRODUCER_INFOS_PATH);
+
+ 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)
+ {
+ infos.add(toProducerInfoMapping(consumer.getProducerInfo(), session));
+ }
+ session.persist(infos); // todo: is that sufficient?
+
+ producerInfos = new ProducerInfoIterator(consumers.iterator());
+ }
+ else
+ {
+ List<ProducerInfoMapping> mappings =
producerInfosMapping.getProducerInfos();
+ producerInfos = new MappingToProducerInfoIterator(mappings.iterator());
+ }
+
+ session.save();
+ session.close();
+ return producerInfos;
+ }
+
+ private void delete(ChromatticSession session, String path)
+ {
+ ProducerInfoMapping old = session.findByPath(ProducerInfoMapping.class, path);
+
+ if (old != null)
+ {
+ session.remove(old);
+ }
+ }
+
+ 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.setActive(producerInfo.isActive());
+ pim.setExpirationCacheSeconds(producerInfo.getExpirationCacheSeconds());
+ pim.setId(producerInfo.getId());
+
+ EndpointInfoMapping eim = pim.getEndpointInfo();
+
eim.setWSDLURL(producerInfo.getEndpointConfigurationInfo().getWsdlDefinitionURL());
+
+ RegistrationInfoMapping rim = pim.getRegistrationInfo();
+ RegistrationInfo regInfo = producerInfo.getRegistrationInfo();
+ rim.setConsumerName(regInfo.getConsumerName());
+ rim.setRegistrationHandle(regInfo.getRegistrationHandle());
+ byte[] bytes = regInfo.getRegistrationState();
+ if (bytes != null && bytes.length > 0)
+ {
+ ByteArrayInputStream is = new ByteArrayInputStream(bytes);
+ rim.setRegistrationState(is);
+ }
+
+ // clear and recreate registration properties
+ List<RegistrationPropertyMapping> rpms = rim.getRegistrationProperties();
+ rpms.clear();
+ for (RegistrationProperty property : regInfo.getRegistrationProperties().values())
+ {
+ // create new RegistrationPropertyMapping for this RegistrationInfoMapping
+ RegistrationPropertyMapping rpm = rim.create();
+
+ // set properties
+ rpm.setStatus(property.getStatus().name());
+ rpm.setValue(property.getValue());
+
+ // description
+ RegistrationPropertyDescriptionMapping rpdm = rpm.getDescription();
+ RegistrationPropertyDescription desc = property.getDescription();
+ rpdm.setDescription(desc.getDescription().getValue()); // todo: should really
persist LocalizedString here...
+ rpdm.setHint(desc.getHint().getValue()); // todo: should really persist
LocalizedString here...
+ rpdm.setLabel(desc.getLabel().getValue()); // todo: should really persist
LocalizedString here...
+
+ // convert QNames to Strings
+ rpdm.setName(desc.getName().toString());
+ rpdm.setType(desc.getType().toString());
+
+ // add newly created RegistrationPropertyMapping to parent
+ rpms.add(rpm);
+ }
+
+ return pim;
+ }
+
+ private static ProducerInfo toProducerInfo(ProducerInfoMapping mapping)
+ {
+ // todo: should probably use a ProducerInfo implementation backed by mapping at
some point
+ ProducerInfo info = new ProducerInfo();
+
+ // basic properties
+ info.setKey(mapping.getKey());
+ info.setId(mapping.getId());
+ info.setActive(mapping.getActive());
+ info.setExpirationCacheSeconds(mapping.getExpirationCacheSeconds());
+
+ // endpoint
+
info.getEndpointConfigurationInfo().setWsdlDefinitionURL(mapping.getEndpointInfo().getWSDLURL());
+
+ // registration
+ RegistrationInfo regInfo = info.getRegistrationInfo();
+ RegistrationInfoMapping rim = mapping.getRegistrationInfo();
+ regInfo.setConsumerName(rim.getConsumerName());
+ regInfo.setRegistrationHandle(rim.getRegistrationHandle());
+ regInfo.setRegistrationState(Safe.getBytes(rim.getRegistrationState()));
+
+ // registration properties
+ for (RegistrationPropertyMapping rpm : rim.getRegistrationProperties())
+ {
+ RegistrationPropertyDescriptionMapping rpdm = rpm.getDescription();
+ String name = rpdm.getName();
+
+ RegistrationProperty prop = regInfo.setRegistrationPropertyValue(name,
rpm.getValue());
+
+ RegistrationPropertyDescription desc = new RegistrationPropertyDescription(name,
QName.valueOf(rpdm.getType()));
+ desc.setDefaultDescription(rpdm.getDescription());
+ desc.setHint(new LocalizedString(rpdm.getHint()));
+ desc.setLabel(new LocalizedString(rpdm.getLabel()));
+ prop.setDescription(desc);
+
+ prop.setStatus(RegistrationProperty.Status.valueOf(rpm.getStatus()));
+ }
+
+ return info;
+ }
+
+ 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 toProducerInfo(mappings.next());
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException("Remove not supported!");
+ }
+ }
+}
Deleted:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyDescriptionMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyDescriptionMapping.java 2009-11-22
23:43:40 UTC (rev 750)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyDescriptionMapping.java 2009-11-23
01:08:00 UTC (rev 751)
@@ -1,68 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2009, Red Hat Middleware, LLC, and individual
- * contributors as indicated by the @authors tag. See the
- * copyright.txt in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.gatein.portal.wsrp.state.consumer.mapping;
-
-import org.chromattic.api.annotations.NodeMapping;
-import org.chromattic.api.annotations.Property;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision$
- */
-@NodeMapping(name = RegistrationPropertyDescriptionMapping.NODE_NAME)
-public abstract class RegistrationPropertyDescriptionMapping
-{
- public static final String NODE_NAME =
"wsrp:registrationpropertydescription";
-
- // todo: this should really be a QName
- @Property(name = "name")
- public abstract String getName();
-
- public abstract void setName(String name);
-
- // todo: this should really be a QName
- @Property(name = "type")
- public abstract String getType();
-
- public abstract void setType(String type);
-
-
- // todo: this should really be a LocalizedString
- @Property(name = "description")
- public abstract String getDescription();
-
- public abstract void setDescription(String description);
-
- // todo: this should really be a LocalizedString
- @Property(name = "hint")
- public abstract String getHint();
-
- public abstract void setHint(String hint);
-
- // todo: this should really be a LocalizedString
- @Property(name = "label")
- public abstract String getLabel();
-
- public abstract void setLabel(String label);
-}
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyMapping.java 2009-11-22
23:43:40 UTC (rev 750)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyMapping.java 2009-11-23
01:08:00 UTC (rev 751)
@@ -27,6 +27,7 @@
import org.chromattic.api.annotations.OneToOne;
import org.chromattic.api.annotations.Property;
import org.chromattic.api.annotations.RelatedMappedBy;
+import org.gatein.portal.wsrp.state.mapping.RegistrationPropertyDescriptionMapping;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -47,6 +48,7 @@
public abstract RegistrationPropertyDescriptionMapping getDescription();
// todo: this should really be an enum�
+
@Property(name = "status")
public abstract String getStatus();
Copied:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/mapping/RegistrationPropertyDescriptionMapping.java
(from rev 748,
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyDescriptionMapping.java)
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/mapping/RegistrationPropertyDescriptionMapping.java
(rev 0)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/mapping/RegistrationPropertyDescriptionMapping.java 2009-11-23
01:08:00 UTC (rev 751)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.portal.wsrp.state.mapping;
+
+import org.chromattic.api.annotations.NodeMapping;
+import org.chromattic.api.annotations.Property;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@NodeMapping(name = RegistrationPropertyDescriptionMapping.NODE_NAME)
+public abstract class RegistrationPropertyDescriptionMapping
+{
+ public static final String NODE_NAME =
"wsrp:registrationpropertydescription";
+
+ // todo: this should really be a QName
+
+ @Property(name = "name")
+ public abstract String getName();
+
+ public abstract void setName(String name);
+
+ // todo: this should really be a QName
+
+ @Property(name = "type")
+ public abstract String getType();
+
+ public abstract void setType(String type);
+
+
+ // todo: this should really be a LocalizedString
+
+ @Property(name = "description")
+ public abstract String getDescription();
+
+ public abstract void setDescription(String description);
+
+ // todo: this should really be a LocalizedString
+
+ @Property(name = "hint")
+ public abstract String getHint();
+
+ public abstract void setHint(String hint);
+
+ // todo: this should really be a LocalizedString
+
+ @Property(name = "label")
+ public abstract String getLabel();
+
+ public abstract void setLabel(String label);
+}
Added:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/JCRProducerConfigurationService.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/JCRProducerConfigurationService.java
(rev 0)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/JCRProducerConfigurationService.java 2009-11-23
01:08:00 UTC (rev 751)
@@ -0,0 +1,59 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.gatein.portal.wsrp.state.producer.configuration;
+
+import org.chromattic.api.ChromatticSession;
+import org.gatein.portal.wsrp.state.JCRPersister;
+import org.gatein.wsrp.producer.config.impl.AbstractProducerConfigurationService;
+
+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 JCRPersister persister;
+ private static String PRODUCER_CONFIGURATION_PATH = JCRPersister.WSRP_SERVICES_PATH +
"producerconfiguration";
+
+ public JCRProducerConfigurationService()
+ {
+ List<Class> mappingClasses = new ArrayList<Class>();
+ Collections.addAll(mappingClasses, null);
+ }
+
+ protected void loadConfiguration() throws Exception
+ {
+ ChromatticSession session = persister.getSession();
+
+ //todo
+ }
+
+ public void saveConfiguration() throws Exception
+ {
+ //todo
+ }
+}
Added:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/ProducerConfigurationMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/ProducerConfigurationMapping.java
(rev 0)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/ProducerConfigurationMapping.java 2009-11-23
01:08:00 UTC (rev 751)
@@ -0,0 +1,47 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.gatein.portal.wsrp.state.producer.configuration.mapping;
+
+import org.chromattic.api.annotations.NodeMapping;
+import org.chromattic.api.annotations.OneToOne;
+import org.chromattic.api.annotations.Property;
+import org.chromattic.api.annotations.RelatedMappedBy;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@NodeMapping(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
+ @RelatedMappedBy("registrationrequirements")
+ public abstract RegistrationRequirementsMapping getRegistrationRequirements();
+}
Added:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/RegistrationRequirementsMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/RegistrationRequirementsMapping.java
(rev 0)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/RegistrationRequirementsMapping.java 2009-11-23
01:08:00 UTC (rev 751)
@@ -0,0 +1,57 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.gatein.portal.wsrp.state.producer.configuration.mapping;
+
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.NodeMapping;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.Property;
+import org.gatein.portal.wsrp.state.mapping.RegistrationPropertyDescriptionMapping;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@NodeMapping(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);
+
+ @OneToMany
+ public abstract List<RegistrationPropertyDescriptionMapping>
getRegistrationPropertyDescriptions();
+
+ @Create
+ public abstract RegistrationPropertyDescriptionMapping create();
+}
Modified:
portal/branches/wsrp-integration/component/wsrp/src/test/java/org/gatein/portal/wsrp/state/consumer/ConsumerRegistryTestCase.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/test/java/org/gatein/portal/wsrp/state/consumer/ConsumerRegistryTestCase.java 2009-11-22
23:43:40 UTC (rev 750)
+++
portal/branches/wsrp-integration/component/wsrp/src/test/java/org/gatein/portal/wsrp/state/consumer/ConsumerRegistryTestCase.java 2009-11-23
01:08:00 UTC (rev 751)
@@ -41,12 +41,12 @@
*/
public class ConsumerRegistryTestCase extends TestCase
{
- private ConsumerRegistry registry;
+ private JCRConsumerRegistry registry;
@Override
protected void setUp() throws Exception
{
- registry = new ConsumerRegistry();
+ registry = new JCRConsumerRegistry();
registry.setFederatingPortletInvoker(new FederatingPortletInvokerService());
}