Author: chris.laprun(a)jboss.com
Date: 2009-12-07 13:05:05 -0500 (Mon, 07 Dec 2009)
New Revision: 964
Added:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/JCRRegistrationPersistenceManager.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerCapabilitiesMapping.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerGroupMapping.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerMapping.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumersAndGroupsMapping.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/RegistrationMapping.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/RegistrationPropertiesMapping.java
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyMapping.java
Log:
- First pass implementation of consumer registrations on the producer side should be done
but not tested.
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-12-07
15:44:44 UTC (rev 963)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyMapping.java 2009-12-07
18:05:05 UTC (rev 964)
@@ -23,6 +23,7 @@
package org.gatein.portal.wsrp.state.consumer.mapping;
+import org.chromattic.api.annotations.MappedBy;
import org.chromattic.api.annotations.NodeMapping;
import org.chromattic.api.annotations.OneToOne;
import org.chromattic.api.annotations.Property;
@@ -51,7 +52,7 @@
public abstract void setValue(String value);
@OneToOne
- @RelatedMappedBy("description")
+ @MappedBy("description")
public abstract RegistrationPropertyDescriptionMapping getDescription();
// todo: this should really be an enum�
Added:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/JCRRegistrationPersistenceManager.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/JCRRegistrationPersistenceManager.java
(rev 0)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/JCRRegistrationPersistenceManager.java 2009-12-07
18:05:05 UTC (rev 964)
@@ -0,0 +1,163 @@
+/*
+* 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.registrations;
+
+import org.chromattic.api.ChromatticSession;
+import org.exoplatform.container.ExoContainer;
+import org.gatein.portal.wsrp.state.JCRPersister;
+import
org.gatein.portal.wsrp.state.producer.registrations.mapping.ConsumerCapabilitiesMapping;
+import org.gatein.portal.wsrp.state.producer.registrations.mapping.ConsumerGroupMapping;
+import org.gatein.portal.wsrp.state.producer.registrations.mapping.ConsumerMapping;
+import
org.gatein.portal.wsrp.state.producer.registrations.mapping.ConsumersAndGroupsMapping;
+import org.gatein.portal.wsrp.state.producer.registrations.mapping.RegistrationMapping;
+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 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 JCRPersister persister;
+ private ConsumersAndGroupsMapping mappings;
+
+ public JCRRegistrationPersistenceManager(ExoContainer container, String workspaceName,
String repositoryName) throws Exception
+ {
+ persister = new JCRPersister(container, workspaceName, repositoryName);
+
+ List<Class> mappingClasses = new ArrayList<Class>(5);
+ Collections.addAll(mappingClasses, ConsumersAndGroupsMapping.class,
ConsumerMapping.class, ConsumerGroupMapping.class,
+ RegistrationMapping.class, ConsumerCapabilitiesMapping.class);
+
+ persister.initializeBuilderFor(mappingClasses);
+
+ ChromatticSession session = persister.getSession();
+ mappings = session.findByPath(ConsumersAndGroupsMapping.class,
ConsumersAndGroupsMapping.NODE_NAME);
+ if(mappings == null)
+ {
+ session.insert(ConsumersAndGroupsMapping.class,
ConsumersAndGroupsMapping.NODE_NAME);
+ }
+ persister.closeSession(session);
+
+ for (ConsumerGroupMapping cgm : mappings.getConsumerGroups().values())
+ {
+ internalAddConsumerGroup(cgm.toConsumerGroup(this));
+ }
+
+ for (ConsumerMapping cm : mappings.getConsumers().values())
+ {
+ internalAddConsumer(cm.toConsumer(this));
+ }
+ }
+
+ @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();
+ ConsumerMapping cm = session.findById(ConsumerMapping.class,
consumer.getPersistentKey());
+ RegistrationMapping rm = cm.createRegistration();
+ RegistrationSPI registration = newRegistrationSPI(consumer, registrationProperties,
rm.getPersistentKey());
+ rm.initFrom(registration);
+ persister.closeSession(session);
+
+ 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(session);
+ }
+
+ @Override
+ protected ConsumerSPI internalCreateConsumer(String consumerId, String consumerName)
+ {
+ ConsumerSPI consumer = super.internalCreateConsumer(consumerId, consumerName);
+
+ ChromatticSession session = persister.getSession();
+ ConsumerMapping cm = mappings.createConsumer(consumerId);
+ cm.initFrom(consumer);
+ persister.closeSession(session);
+
+ return consumer;
+ }
+
+ @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();
+ ConsumerGroupMapping cgm = mappings.createConsumerGroup(name);
+ group.setPersistentKey(cgm.getPersistentKey());
+ cgm.initFrom(group);
+ persister.closeSession(session);
+
+ return group;
+ }
+}
Added:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerCapabilitiesMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerCapabilitiesMapping.java
(rev 0)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerCapabilitiesMapping.java 2009-12-07
18:05:05 UTC (rev 964)
@@ -0,0 +1,46 @@
+/*
+* 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.registrations.mapping;
+
+import org.chromattic.api.annotations.NodeMapping;
+import org.gatein.registration.ConsumerCapabilities;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@NodeMapping(name = ConsumerCapabilitiesMapping.NODE_NAME)
+public class ConsumerCapabilitiesMapping
+{
+ public static final String NODE_NAME = "wsrp:consumercapabilities";
+
+ public void initFrom(ConsumerCapabilities capabilities)
+ {
+
+ }
+
+ public ConsumerCapabilities toConsumerCapabilities()
+ {
+ return null; // todo: implement
+ }
+}
Added:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerGroupMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerGroupMapping.java
(rev 0)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerGroupMapping.java 2009-12-07
18:05:05 UTC (rev 964)
@@ -0,0 +1,110 @@
+/*
+* 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.registrations.mapping;
+
+import org.chromattic.api.RelationshipType;
+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.NodeMapping;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.Property;
+import org.chromattic.api.annotations.RelatedMappedBy;
+import org.gatein.common.util.ParameterValidation;
+import
org.gatein.portal.wsrp.state.producer.registrations.JCRRegistrationPersistenceManager;
+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 java.util.Collection;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@NodeMapping(name = ConsumerGroupMapping.NODE_NAME)
+public abstract class ConsumerGroupMapping
+{
+ public static final String NODE_NAME = "wsrp:consumergroup";
+
+ @OneToMany(type = RelationshipType.PATH)
+ @RelatedMappedBy("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 + ")");
+ cm.initFrom(consumer);
+ getConsumers().add(cm);
+ }
+ }
+ catch (RegistrationException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public ConsumerGroupSPI toConsumerGroup(JCRRegistrationPersistenceManager
persistenceManager) throws RegistrationException
+ {
+ ConsumerGroupSPI group = persistenceManager.newConsumerGroupSPI(getName());
+ group.setStatus(getStatus());
+
+ for (ConsumerMapping cm : getConsumers())
+ {
+ Consumer consumer = persistenceManager.getConsumerById(cm.getPersistentKey());
+ if(consumer == null)
+ {
+ consumer = cm.toConsumer(persistenceManager);
+ }
+
+ group.addConsumer(consumer);
+ }
+ return group;
+ }
+}
Added:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerMapping.java
(rev 0)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerMapping.java 2009-12-07
18:05:05 UTC (rev 964)
@@ -0,0 +1,152 @@
+/*
+* 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.registrations.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.NodeMapping;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.OneToOne;
+import org.chromattic.api.annotations.Property;
+import org.chromattic.api.annotations.RelatedMappedBy;
+import
org.gatein.portal.wsrp.state.producer.registrations.JCRRegistrationPersistenceManager;
+import org.gatein.registration.Consumer;
+import org.gatein.registration.ConsumerGroup;
+import org.gatein.registration.Registration;
+import org.gatein.registration.RegistrationException;
+import org.gatein.registration.RegistrationStatus;
+import org.gatein.registration.spi.ConsumerSPI;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@NodeMapping(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);
+
+ @Property(name = "status")
+ public abstract RegistrationStatus getStatus();
+
+ public abstract void setStatus(RegistrationStatus status);
+
+ @OneToMany(type = RelationshipType.PATH)
+ @RelatedMappedBy("consumer")
+ public abstract Map<String, RegistrationMapping> getRegistrations();
+
+ @Create
+ public abstract RegistrationMapping createRegistration();
+
+ @ManyToOne(type = RelationshipType.PATH)
+ @MappedBy("group")
+ public abstract ConsumerGroupMapping getGroup();
+
+ public abstract void setGroup(ConsumerGroupMapping group);
+
+ @OneToOne
+ @MappedBy("capabilities")
+ public abstract ConsumerCapabilitiesMapping getCapabilities();
+
+ @FindById
+ public abstract ConsumerGroupMapping findGroupById(String id);
+
+ public void initFrom(Consumer consumer)
+ {
+ setName(consumer.getName());
+ setConsumerAgent(consumer.getConsumerAgent());
+ setStatus(consumer.getStatus());
+
+ ConsumerGroup group = consumer.getGroup();
+ if (group != null)
+ {
+ ConsumerGroupMapping cgm = findGroupById(group.getPersistentKey());
+ setGroup(cgm);
+ }
+
+ ConsumerCapabilitiesMapping ccm = getCapabilities();
+ ccm.initFrom(consumer.getCapabilities());
+
+ try
+ {
+ Map<String, RegistrationMapping> rms = getRegistrations();
+ for (Registration reg : consumer.getRegistrations())
+ {
+ RegistrationMapping rm = createRegistration();
+ rm.initFrom(reg);
+ rms.put(reg.getRegistrationHandle(), rm);
+ }
+ }
+ catch (RegistrationException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public ConsumerSPI toConsumer(JCRRegistrationPersistenceManager persistenceManager)
throws RegistrationException
+ {
+ ConsumerSPI consumer = persistenceManager.newConsumerSPI(getId(), getName());
+ consumer.setConsumerAgent(getConsumerAgent());
+ consumer.setStatus(getStatus());
+ consumer.setPersistentKey(getPersistentKey());
+
+ consumer.setCapabilities(getCapabilities().toConsumerCapabilities());
+
+ ConsumerGroupMapping cgm = getGroup();
+ if (cgm != null)
+ {
+ consumer.setGroup(persistenceManager.getConsumerGroup(cgm.getName()));
+ }
+
+ for (RegistrationMapping rm : getRegistrations().values())
+ {
+ consumer.addRegistration(rm.toRegistration(persistenceManager, consumer));
+ }
+
+ return consumer;
+ }
+}
Added:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumersAndGroupsMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumersAndGroupsMapping.java
(rev 0)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumersAndGroupsMapping.java 2009-12-07
18:05:05 UTC (rev 964)
@@ -0,0 +1,51 @@
+/*
+* 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.registrations.mapping;
+
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.NodeMapping;
+import org.chromattic.api.annotations.OneToMany;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@NodeMapping(name = ConsumersAndGroupsMapping.NODE_NAME)
+public abstract class ConsumersAndGroupsMapping
+{
+ public static final String NODE_NAME = "wsrp:consumersandgroups";
+
+ @OneToMany
+ public abstract Map<String, ConsumerMapping> getConsumers();
+
+ @OneToMany
+ public abstract Map<String, ConsumerGroupMapping> getConsumerGroups();
+
+ @Create
+ public abstract ConsumerMapping createConsumer(String id);
+
+ @Create
+ public abstract ConsumerGroupMapping createConsumerGroup(String name);
+}
Added:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/RegistrationMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/RegistrationMapping.java
(rev 0)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/RegistrationMapping.java 2009-12-07
18:05:05 UTC (rev 964)
@@ -0,0 +1,96 @@
+/*
+* 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.registrations.mapping;
+
+import org.chromattic.api.RelationshipType;
+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.NodeMapping;
+import org.chromattic.api.annotations.OneToOne;
+import org.chromattic.api.annotations.Property;
+import
org.gatein.portal.wsrp.state.producer.registrations.JCRRegistrationPersistenceManager;
+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 javax.xml.namespace.QName;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@NodeMapping(name = RegistrationMapping.NODE_NAME)
+public abstract class RegistrationMapping
+{
+ public static final String NODE_NAME = "wsrp:registration";
+
+ @Id
+ public abstract String getPersistentKey();
+
+ @ManyToOne(type = RelationshipType.PATH)
+ @MappedBy("consumer")
+ public abstract ConsumerMapping getConsumer();
+
+ @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);
+
+ @OneToOne
+ @MappedBy("properties")
+ public abstract RegistrationPropertiesMapping getProperties();
+
+ @FindById
+ public abstract ConsumerMapping findConsumerById(String id);
+
+ public void initFrom(Registration registration)
+ {
+ setStatus(registration.getStatus());
+ setRegistrationHandle(registration.getRegistrationHandle());
+
+ getProperties().initFrom(registration.getProperties());
+
+ ConsumerMapping cm = findConsumerById(registration.getConsumer().getId());
+ cm.getRegistrations().put(registration.getPersistentKey(), this);
+ }
+
+ public RegistrationSPI toRegistration(JCRRegistrationPersistenceManager
persistenceManager, ConsumerSPI consumer) throws RegistrationException
+ {
+ ConsumerMapping cm = getConsumer();
+
+ RegistrationSPI reg = persistenceManager.newRegistrationSPI(consumer,
getProperties().toPropMap(), getPersistentKey());
+ reg.setStatus(getStatus());
+ reg.setRegistrationHandle(getRegistrationHandle());
+ return reg;
+ }
+}
Added:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/RegistrationPropertiesMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/RegistrationPropertiesMapping.java
(rev 0)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/RegistrationPropertiesMapping.java 2009-12-07
18:05:05 UTC (rev 964)
@@ -0,0 +1,73 @@
+/*
+* 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.registrations.mapping;
+
+import org.chromattic.api.annotations.NodeMapping;
+import org.chromattic.api.annotations.Properties;
+
+import javax.xml.namespace.QName;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+@NodeMapping(name = RegistrationPropertiesMapping.NODE_NAME)
+public abstract class RegistrationPropertiesMapping
+{
+ public static final String NODE_NAME = "wsrp:registrationproperties";
+
+ @Properties
+ public abstract Map<String, String> getProperties();
+
+ public Map<QName, Object> toPropMap()
+ {
+ Map<QName, Object> properties = Collections.emptyMap();
+ Map<String, String> propMap = getProperties();
+ if (!propMap.isEmpty())
+ {
+ properties = new HashMap<QName, Object>(propMap.size());
+ for (Map.Entry<String, String> entry : propMap.entrySet())
+ {
+ properties.put(QName.valueOf(entry.getKey()), entry.getValue());
+ }
+ }
+
+ return properties;
+ }
+
+ 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());
+ }
+ }
+ }
+}