Author: chris.laprun(a)jboss.com
Date: 2009-11-30 12:02:54 -0500 (Mon, 30 Nov 2009)
New Revision: 872
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/Consumer.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerGroupImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationPersistenceManagerImpl.java
Log:
- Encapsulated use of internal structure in RegistrationPersistenceManagerImpl to make it
easier to extend it.
- Use generics.
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/Consumer.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/Consumer.java 2009-11-30
16:51:05 UTC (rev 871)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/Consumer.java 2009-11-30
17:02:54 UTC (rev 872)
@@ -63,7 +63,7 @@
* @return the consumer registrations
* @throws RegistrationException
*/
- Collection getRegistrations() throws RegistrationException;
+ Collection<? extends Registration> getRegistrations() throws
RegistrationException;
/**
* Returns the group that this consumer belongs to.
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java 2009-11-30
16:51:05 UTC (rev 871)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java 2009-11-30
17:02:54 UTC (rev 872)
@@ -77,13 +77,13 @@
Registration addRegistrationFor(String consumerId, Map registrationProperties) throws
RegistrationException;
- Collection getConsumerGroups();
+ Collection<? extends ConsumerGroup> getConsumerGroups();
Registration getRegistration(String registrationId);
Consumer addConsumerToGroupNamed(String consumerId, String groupName) throws
RegistrationException;
- Collection getConsumers();
+ Collection<? extends Consumer> getConsumers();
- Collection getRegistrations();
+ Collection<? extends Registration> getRegistrations();
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerGroupImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerGroupImpl.java 2009-11-30
16:51:05 UTC (rev 871)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerGroupImpl.java 2009-11-30
17:02:54 UTC (rev 872)
@@ -42,7 +42,7 @@
{
private String name;
- private Map consumers;
+ private Map<String, Consumer> consumers;
private RegistrationStatus status;
@@ -59,7 +59,7 @@
private void init()
{
- this.consumers = new HashMap();
+ this.consumers = new HashMap<String, Consumer>();
status = RegistrationStatus.PENDING;
}
@@ -109,7 +109,7 @@
public Consumer getConsumer(String consumerId) throws IllegalArgumentException,
RegistrationException
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerId,
"Consumer name", null);
- return (Consumer)consumers.get(consumerId);
+ return consumers.get(consumerId);
}
public boolean isEmpty()
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerImpl.java 2009-11-30
16:51:05 UTC (rev 871)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerImpl.java 2009-11-30
17:02:54 UTC (rev 872)
@@ -48,7 +48,7 @@
private String name;
private String identity;
private String consumerAgent;
- private Set registrations;
+ private Set<Registration> registrations;
private RegistrationStatus status;
private ConsumerGroup group;
private ConsumerCapabilities capabilities;
@@ -71,7 +71,7 @@
private void init()
{
- registrations = new HashSet(7);
+ registrations = new HashSet<Registration>(7);
status = RegistrationStatus.PENDING;
capabilities = new ConsumerCapabilitiesImpl();
}
@@ -144,7 +144,7 @@
this.status = status;
}
- public Collection getRegistrations() throws RegistrationException
+ public Collection<Registration> getRegistrations() throws RegistrationException
{
return Collections.unmodifiableSet(registrations);
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationImpl.java 2009-11-30
16:51:05 UTC (rev 871)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationImpl.java 2009-11-30
17:02:54 UTC (rev 872)
@@ -31,7 +31,6 @@
import javax.xml.namespace.QName;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
/**
@@ -45,7 +44,7 @@
private final String id;
private ConsumerImpl consumer;
private RegistrationStatus status;
- private Map properties;
+ private Map<QName, Object> properties;
private String registrationHandle;
@@ -54,7 +53,7 @@
this.id = id;
this.consumer = consumer;
this.status = status;
- this.properties = new HashMap(properties);
+ this.properties = new HashMap<QName, Object>(properties);
}
public String getId()
@@ -150,12 +149,10 @@
}
// check properties
- for (Iterator props = properties.entrySet().iterator(); props.hasNext();)
+ for (Map.Entry<QName, Object> entry : properties.entrySet())
{
- Map.Entry entry = (Map.Entry)props.next();
-
// we should have a 1-1 match between name/value pair
- QName name = (QName)entry.getKey();
+ QName name = entry.getKey();
if (!entry.getValue().equals(registrationProperties.get(name)))
{
return false;
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationPersistenceManagerImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationPersistenceManagerImpl.java 2009-11-30
16:51:05 UTC (rev 871)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationPersistenceManagerImpl.java 2009-11-30
17:02:54 UTC (rev 872)
@@ -46,9 +46,9 @@
public class RegistrationPersistenceManagerImpl implements
RegistrationPersistenceManager
{
private long lastRegistrationId;
- private Map consumers = new HashMap();
- private Map groups = new HashMap();
- private Map registrations = new HashMap();
+ private Map<String, Consumer> consumers = new HashMap<String,
Consumer>();
+ private Map<String, ConsumerGroup> groups = new HashMap<String,
ConsumerGroup>();
+ private Map<String, Registration> registrations = new HashMap<String,
Registration>();
public Consumer createConsumer(String consumerId, String consumerName) throws
RegistrationException
{
@@ -57,7 +57,7 @@
ConsumerImpl consumer = new ConsumerImpl(consumerId, consumerName);
consumer.setStatus(RegistrationStatus.PENDING);
- consumers.put(consumerId, consumer);
+ internalAddConsumer(consumer);
return consumer;
}
@@ -66,7 +66,7 @@
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "ConsumerGroup
name", null);
- return (ConsumerGroup)groups.get(name);
+ return groups.get(name);
}
public ConsumerGroup createConsumerGroup(String name) throws RegistrationException
@@ -79,7 +79,7 @@
else
{
group = new ConsumerGroupImpl(name);
- groups.put(name, group);
+ internalAddConsumerGroup(group);
return group;
}
}
@@ -87,7 +87,7 @@
public void removeConsumerGroup(String name) throws RegistrationException
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "ConsumerGroup
name", null);
- if (groups.remove(name) == null)
+ if (internalRemoveConsumerGroup(name) == null)
{
throw new NoSuchRegistrationException("There is no ConsumerGroup named
'" + name + "'.");
}
@@ -96,7 +96,7 @@
public void removeConsumer(String consumerId) throws RegistrationException
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerId,
"Consumer identity", null);
- if (consumers.remove(consumerId) == null)
+ if (internalRemoveConsumer(consumerId) == null)
{
throw new RegistrationException("There is no Consumer with identity
'" + consumerId + "'.");
}
@@ -106,7 +106,7 @@
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(registrationId,
"Registration identity", null);
- RegistrationImpl registration =
(RegistrationImpl)registrations.get(registrationId);
+ Registration registration = internalRemoveRegistration(registrationId);
if (registration == null)
{
throw new NoSuchRegistrationException("There is no Registration with id
'" + registrationId + "'");
@@ -114,14 +114,13 @@
ConsumerImpl consumer = (ConsumerImpl)registration.getConsumer();
consumer.removeRegistration(registration);
- registrations.remove(registrationId);
}
public Consumer getConsumerById(String consumerId) throws RegistrationException
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerId,
"Consumer identity", null);
- return (Consumer)consumers.get(consumerId);
+ return consumers.get(consumerId);
}
public Registration addRegistrationFor(String consumerId, Map registrationProperties)
throws RegistrationException
@@ -140,7 +139,7 @@
RegistrationStatus.PENDING, registrationProperties);
consumer.addRegistration(registration);
- registrations.put(registration.getId(), registration);
+ internalAddRegistration(registration);
return registration;
}
@@ -169,17 +168,17 @@
return consumer;
}
- public Collection getConsumers()
+ public Collection<? extends Consumer> getConsumers()
{
return Collections.unmodifiableCollection(consumers.values());
}
- public Collection getRegistrations()
+ public Collection<? extends Registration> getRegistrations()
{
return Collections.unmodifiableCollection(registrations.values());
}
- public Collection getConsumerGroups()
+ public Collection<? extends ConsumerGroup> getConsumerGroups()
{
return Collections.unmodifiableCollection(groups.values());
}
@@ -188,6 +187,38 @@
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(registrationId,
"Registration id", null);
- return (Registration)registrations.get(registrationId);
+ return registrations.get(registrationId);
}
+
+ // internal methods: extension points for subclasses
+
+ protected void internalAddRegistration(RegistrationImpl registration)
+ {
+ registrations.put(registration.getId(), registration);
+ }
+
+ protected Registration internalRemoveRegistration(String registrationId)
+ {
+ return registrations.remove(registrationId);
+ }
+
+ protected void internalAddConsumer(Consumer consumer)
+ {
+ consumers.put(consumer.getId(), consumer);
+ }
+
+ protected Consumer internalRemoveConsumer(String consumerId)
+ {
+ return consumers.remove(consumerId);
+ }
+
+ protected void internalAddConsumerGroup(ConsumerGroup group)
+ {
+ groups.put(group.getName(), group);
+ }
+
+ protected ConsumerGroup internalRemoveConsumerGroup(String name)
+ {
+ return groups.remove(name);
+ }
}