Author: chris.laprun(a)jboss.com
Date: 2009-11-23 09:43:45 -0500 (Mon, 23 Nov 2009)
New Revision: 763
Modified:
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/consumer/mapping/EndpointInfoMapping.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationInfoMapping.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/main/java/org/gatein/portal/wsrp/state/mapping/RegistrationPropertyDescriptionMapping.java
Log:
- Let mapping classes deal with conversion to and from model objects for better
encapsulation.
Modified:
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/consumer/JCRConsumerRegistry.java 2009-11-23
14:32:21 UTC (rev 762)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java 2009-11-23
14:43:45 UTC (rev 763)
@@ -24,7 +24,6 @@
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;
@@ -36,15 +35,9 @@
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;
@@ -174,95 +167,11 @@
pim = session.insert(ProducerInfoMapping.class, getPathFor(producerInfo));
}
- pim.setActive(producerInfo.isActive());
- pim.setExpirationCacheSeconds(producerInfo.getExpirationCacheSeconds());
- pim.setId(producerInfo.getId());
+ pim.initFrom(producerInfo);
- 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;
@@ -279,7 +188,7 @@
public ProducerInfo next()
{
- return toProducerInfo(mappings.next());
+ return mappings.next().toProducerInfo();
}
public void remove()
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/EndpointInfoMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/EndpointInfoMapping.java 2009-11-23
14:32:21 UTC (rev 762)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/EndpointInfoMapping.java 2009-11-23
14:43:45 UTC (rev 763)
@@ -25,6 +25,7 @@
import org.chromattic.api.annotations.NodeMapping;
import org.chromattic.api.annotations.Property;
+import org.gatein.wsrp.consumer.EndpointConfigurationInfo;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -39,4 +40,16 @@
public abstract String getWSDLURL();
public abstract void setWSDLURL(String wsdlURL);
+
+ public void initFrom(EndpointConfigurationInfo info)
+ {
+ setWSDLURL(info.getWsdlDefinitionURL());
+ }
+
+ public EndpointConfigurationInfo toEndpointConfigurationInfo()
+ {
+ EndpointConfigurationInfo info = new EndpointConfigurationInfo();
+ info.setWsdlDefinitionURL(getWSDLURL());
+ return info;
+ }
}
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java 2009-11-23
14:32:21 UTC (rev 762)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java 2009-11-23
14:43:45 UTC (rev 763)
@@ -28,6 +28,9 @@
import org.chromattic.api.annotations.OneToOne;
import org.chromattic.api.annotations.Property;
import org.chromattic.api.annotations.RelatedMappedBy;
+import org.gatein.wsrp.consumer.EndpointConfigurationInfo;
+import org.gatein.wsrp.consumer.ProducerInfo;
+import org.gatein.wsrp.consumer.RegistrationInfo;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -68,4 +71,40 @@
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 toProducerInfo()
+ {
+ // 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.setEndpointConfigurationInfo(endInfo);
+
+ // registration
+ RegistrationInfo regInfo = getRegistrationInfo().toRegistrationInfo();
+ info.setRegistrationInfo(regInfo);
+
+ return info;
+ }
}
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationInfoMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationInfoMapping.java 2009-11-23
14:32:21 UTC (rev 762)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationInfoMapping.java 2009-11-23
14:43:45 UTC (rev 763)
@@ -27,7 +27,13 @@
import org.chromattic.api.annotations.NodeMapping;
import org.chromattic.api.annotations.OneToMany;
import org.chromattic.api.annotations.Property;
+import org.exoplatform.commons.utils.Safe;
+import org.gatein.portal.wsrp.state.mapping.RegistrationPropertyDescriptionMapping;
+import org.gatein.wsrp.consumer.RegistrationInfo;
+import org.gatein.wsrp.consumer.RegistrationProperty;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;
@@ -60,4 +66,56 @@
@Create
public abstract RegistrationPropertyMapping create();
+
+ 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 = create();
+
+ // initialize
+ rpm.initFrom(property);
+
+ // add newly created RegistrationPropertyMapping to parent
+ rpms.add(rpm);
+ }
+ }
+
+ public RegistrationInfo toRegistrationInfo()
+ {
+ RegistrationInfo regInfo = new RegistrationInfo();
+
+ regInfo.setConsumerName(getConsumerName());
+ regInfo.setRegistrationHandle(getRegistrationHandle());
+ regInfo.setRegistrationState(Safe.getBytes(getRegistrationState()));
+
+ // registration properties
+ for (RegistrationPropertyMapping rpm : getRegistrationProperties())
+ {
+ RegistrationPropertyDescriptionMapping rpdm = rpm.getDescription();
+ String name = rpdm.getName();
+
+ RegistrationProperty prop = regInfo.setRegistrationPropertyValue(name,
rpm.getValue());
+
+ RegistrationPropertyDescription desc =
rpdm.toRegistrationPropertyDescription();
+ prop.setDescription(desc);
+
+ prop.setStatus(RegistrationProperty.Status.valueOf(rpm.getStatus()));
+ }
+
+ return regInfo;
+ }
}
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-23
14:32:21 UTC (rev 762)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyMapping.java 2009-11-23
14:43:45 UTC (rev 763)
@@ -28,6 +28,8 @@
import org.chromattic.api.annotations.Property;
import org.chromattic.api.annotations.RelatedMappedBy;
import org.gatein.portal.wsrp.state.mapping.RegistrationPropertyDescriptionMapping;
+import org.gatein.wsrp.consumer.RegistrationProperty;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -53,4 +55,16 @@
public abstract String getStatus();
public abstract void setStatus(String status);
+
+ public void initFrom(RegistrationProperty property)
+ {
+ // set properties
+ setStatus(property.getStatus().name());
+ setValue(property.getValue());
+
+ // description
+ RegistrationPropertyDescriptionMapping rpdm = getDescription();
+ RegistrationPropertyDescription desc = property.getDescription();
+ rpdm.initFrom(desc);
+ }
}
Modified:
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/mapping/RegistrationPropertyDescriptionMapping.java 2009-11-23
14:32:21 UTC (rev 762)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/mapping/RegistrationPropertyDescriptionMapping.java 2009-11-23
14:43:45 UTC (rev 763)
@@ -25,7 +25,11 @@
import org.chromattic.api.annotations.NodeMapping;
import org.chromattic.api.annotations.Property;
+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$
@@ -35,39 +39,50 @@
{
public static final String NODE_NAME =
"wsrp:registrationpropertydescription";
- // todo: this should really be a QName
-
@Property(name = "name")
- public abstract String getName();
+ public abstract String getName(); // todo: this should really be a QName
public abstract void setName(String name);
- // todo: this should really be a QName
@Property(name = "type")
- public abstract String getType();
+ public abstract String getType(); // todo: this should really be a QName
public abstract void setType(String type);
-
- // todo: this should really be a LocalizedString
-
@Property(name = "description")
- public abstract String getDescription();
+ public abstract String getDescription(); // todo: this should really be a
LocalizedString
public abstract void setDescription(String description);
- // todo: this should really be a LocalizedString
-
@Property(name = "hint")
- public abstract String getHint();
+ public abstract String getHint(); // todo: this should really be a LocalizedString
public abstract void setHint(String hint);
- // todo: this should really be a LocalizedString
-
@Property(name = "label")
- public abstract String getLabel();
+ public abstract String getLabel(); // todo: this should really be a LocalizedString
public abstract void setLabel(String label);
+
+ public void initFrom(RegistrationPropertyDescription desc)
+ {
+ setDescription(desc.getDescription().getValue());
+ setHint(desc.getHint().getValue());
+ setLabel(desc.getLabel().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.setDefaultDescription(getDescription());
+ desc.setHint(new LocalizedString(getHint()));
+ desc.setLabel(new LocalizedString(getLabel()));
+
+ return desc;
+ }
}
Show replies by date