Author: chris.laprun(a)jboss.com
Date: 2009-11-23 10:50:38 -0500 (Mon, 23 Nov 2009)
New Revision: 764
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/producer/configuration/JCRProducerConfigurationService.java
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
Log:
- First pass at producer configuration 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-23
14:43:45 UTC (rev 763)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java 2009-11-23
15:50:38 UTC (rev 764)
@@ -32,6 +32,7 @@
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.portal.wsrp.state.producer.configuration.JCRProducerConfigurationService;
import org.gatein.registration.RegistrationManager;
import org.gatein.registration.RegistrationPersistenceManager;
import org.gatein.registration.impl.RegistrationManagerImpl;
@@ -44,8 +45,6 @@
import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
import org.gatein.wsrp.producer.ProducerHolder;
import org.gatein.wsrp.producer.WSRPProducer;
-import org.gatein.wsrp.producer.config.ProducerConfigurationService;
-import org.gatein.wsrp.producer.config.impl.xml.SimpleXMLProducerConfigurationService;
import org.picocontainer.Startable;
import java.io.InputStream;
@@ -96,7 +95,8 @@
private void startProducer(ExoContainer container)
{
- ProducerConfigurationService producerConfigurationService = new
SimpleXMLProducerConfigurationService(configurationIS);
+ JCRProducerConfigurationService producerConfigurationService = new
JCRProducerConfigurationService();
+ producerConfigurationService.setDefaultConfigurationIS(configurationIS);
try
{
producerConfigurationService.reloadConfiguration();
Modified:
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 2009-11-23
14:43:45 UTC (rev 763)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/JCRProducerConfigurationService.java 2009-11-23
15:50:38 UTC (rev 764)
@@ -24,8 +24,14 @@
import org.chromattic.api.ChromatticSession;
import org.gatein.portal.wsrp.state.JCRPersister;
+import org.gatein.portal.wsrp.state.mapping.RegistrationPropertyDescriptionMapping;
+import
org.gatein.portal.wsrp.state.producer.configuration.mapping.ProducerConfigurationMapping;
+import
org.gatein.portal.wsrp.state.producer.configuration.mapping.RegistrationRequirementsMapping;
+import org.gatein.wsrp.producer.config.ProducerConfigurationService;
import org.gatein.wsrp.producer.config.impl.AbstractProducerConfigurationService;
+import org.gatein.wsrp.producer.config.impl.xml.SimpleXMLProducerConfigurationService;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -39,21 +45,69 @@
private JCRPersister persister;
private static String PRODUCER_CONFIGURATION_PATH = JCRPersister.WSRP_SERVICES_PATH +
"producerconfiguration";
+ private InputStream defaultConfigurationIS;
+
public JCRProducerConfigurationService()
{
- List<Class> mappingClasses = new ArrayList<Class>();
- Collections.addAll(mappingClasses, null);
+ List<Class> mappingClasses = new ArrayList<Class>(3);
+ Collections.addAll(mappingClasses, ProducerConfigurationMapping.class,
RegistrationRequirementsMapping.class,
+ RegistrationPropertyDescriptionMapping.class);
}
+ /**
+ * 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);
- //todo
+ // if we don't have a configuration persisted in JCR already, force a reload
from XML and save the resulting configuration
+ pcm = saveConfiguration(session, pcm, true);
+
+ configuration = pcm.toProducerConfiguration();
+
}
public void saveConfiguration() throws Exception
{
- //todo
+ ChromatticSession session = persister.getSession();
+
+ saveConfiguration(session, session.findByPath(ProducerConfigurationMapping.class,
PRODUCER_CONFIGURATION_PATH), false);
}
+
+ private ProducerConfigurationMapping saveConfiguration(ChromatticSession session,
ProducerConfigurationMapping pcm, boolean forceReloadFromXML) throws Exception
+ {
+ if (pcm == null)
+ {
+ pcm = session.insert(ProducerConfigurationMapping.class,
PRODUCER_CONFIGURATION_PATH);
+ }
+
+ if (configuration == null)
+ {
+ // if we don't already have a configuration, check if we want to reload it
from XML
+ if (forceReloadFromXML)
+ {
+ ProducerConfigurationService service = new
SimpleXMLProducerConfigurationService(defaultConfigurationIS);
+
+ service.reloadConfiguration();
+ configuration = service.getConfiguration();
+ }
+
+ pcm.initFrom(configuration);
+
+ session.persist(pcm);
+ }
+
+ return pcm;
+ }
}
Modified:
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 2009-11-23
14:43:45 UTC (rev 763)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/ProducerConfigurationMapping.java 2009-11-23
15:50:38 UTC (rev 764)
@@ -26,6 +26,9 @@
import org.chromattic.api.annotations.OneToOne;
import org.chromattic.api.annotations.Property;
import org.chromattic.api.annotations.RelatedMappedBy;
+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>
@@ -44,4 +47,24 @@
@OneToOne
@RelatedMappedBy("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;
+ }
}
Modified:
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 2009-11-23
14:43:45 UTC (rev 763)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/RegistrationRequirementsMapping.java 2009-11-23
15:50:38 UTC (rev 764)
@@ -27,6 +27,9 @@
import org.chromattic.api.annotations.OneToMany;
import org.chromattic.api.annotations.Property;
import org.gatein.portal.wsrp.state.mapping.RegistrationPropertyDescriptionMapping;
+import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
+import org.gatein.wsrp.producer.config.impl.ProducerRegistrationRequirementsImpl;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
import java.util.List;
@@ -54,4 +57,35 @@
@Create
public abstract RegistrationPropertyDescriptionMapping create();
+
+ public void initFrom(ProducerRegistrationRequirements registrationRequirements)
+ {
+ setRegistrationRequired(registrationRequirements.isRegistrationRequired());
+
setRegistrationRequiredForFullDescription(registrationRequirements.isRegistrationRequiredForFullDescription());
+
+ List<RegistrationPropertyDescriptionMapping> rpdms =
getRegistrationPropertyDescriptions();
+ for (RegistrationPropertyDescription desc :
registrationRequirements.getRegistrationProperties().values())
+ {
+ RegistrationPropertyDescriptionMapping rpdm = create();
+
+ rpdm.initFrom(desc);
+
+ rpdms.add(rpdm);
+ }
+ }
+
+ public ProducerRegistrationRequirements toProducerRegistrationRequirements()
+ {
+ ProducerRegistrationRequirements req = new ProducerRegistrationRequirementsImpl();
+
+ req.setRegistrationRequired(getRegistrationRequired());
+
req.setRegistrationRequiredForFullDescription(getRegistrationRequiredForFullDescription());
+
+ for (RegistrationPropertyDescriptionMapping rpdm :
getRegistrationPropertyDescriptions())
+ {
+ req.addRegistrationProperty(rpdm.toRegistrationPropertyDescription());
+ }
+
+ return req;
+ }
}
Show replies by date