Author: chris.laprun(a)jboss.com
Date: 2010-10-17 21:48:48 -0400 (Sun, 17 Oct 2010)
New Revision: 4699
Added:
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirementsTestCase.java
Modified:
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ProducerBean.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/registration/PropertyDescription.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/registration/RegistrationPropertyDescription.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/ProducerConfigurationService.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirements.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/AbstractProducerConfigurationService.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/xml/FileSystemXMLProducerConfigurationService.java
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/DefaultRegistrationPolicyTestCase.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/config/FileSystemXmlProducerConfigWithReload.java
Log:
- GTNWSRP-31: Removed side-effects from Producer configuration screen.
+ Introduced intermediary RegistrationConfiguration object in ProducerBean to store
modifications to producer configuration until either saved (in which case it's
replicated to the real configuration)
or cancelled (in which case, the modifications are discarded).
+ Added copy constructor on ProducerRegistrationRequirementsImpl and
setRegistrationProperties(Map) method to support needs from ProducerBean.
+ addEmptyRegistrationProperty and removeRegistrationProperty methods now return the
new/removed registration property.
+ Made sure that listeners are not triggered when not needed.
- Made PropertyDescription comparable.
- Added reloadConfiguration(boolean triggerListeners) method on
ProducerConfigurationService to be able to decide whether or not listeners should be
triggered (by default, they are not anymore).
- Minor improvements.
Modified:
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ProducerBean.java
===================================================================
---
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ProducerBean.java 2010-10-17
21:58:12 UTC (rev 4698)
+++
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ProducerBean.java 2010-10-18
01:48:48 UTC (rev 4699)
@@ -28,15 +28,15 @@
import org.gatein.wsrp.producer.config.ProducerConfiguration;
import org.gatein.wsrp.producer.config.ProducerConfigurationService;
import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
+import org.gatein.wsrp.producer.config.impl.ProducerRegistrationRequirementsImpl;
import org.gatein.wsrp.registration.RegistrationPropertyDescription;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
-import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -53,6 +53,7 @@
private static final String PROPERTY = "property";
private static final String PRODUCER = "producer";
private String selectedProp;
+ private RegistrationConfiguration registrationConfiguration;
public ProducerConfigurationService getConfigurationService()
{
@@ -74,11 +75,6 @@
return getRegRequirements().isRegistrationRequiredForFullDescription();
}
- private ProducerRegistrationRequirements getRegRequirements()
- {
- return getConfiguration().getRegistrationRequirements();
- }
-
public void setRegistrationRequiredForFullDescription(boolean
requireRegForFullDescription)
{
getRegRequirements().setRegistrationRequiredForFullDescription(requireRegForFullDescription);
@@ -143,18 +139,7 @@
public List<RegistrationPropertyDescription> getRegistrationProperties()
{
- Map descriptions = getRegRequirements().getRegistrationProperties();
- Comparator<RegistrationPropertyDescription> descComparator = new
Comparator<RegistrationPropertyDescription>()
- {
- public int compare(RegistrationPropertyDescription o1,
RegistrationPropertyDescription o2)
- {
- return o1.getName().toString().compareTo(o2.getName().toString());
- }
- };
-
- List<RegistrationPropertyDescription> result = new
ArrayList<RegistrationPropertyDescription>(descriptions.values());
- Collections.sort(result, descComparator);
- return result;
+ return getRegRequirements().getRegistrationProperties();
}
public List<SelectItem> getSupportedPropertyTypes()
@@ -171,10 +156,20 @@
{
try
{
+ // replicate local state to producer state
+ ProducerRegistrationRequirements registrationRequirements =
getConfiguration().getRegistrationRequirements();
+ RegistrationConfiguration configuration = getRegRequirements();
+
+
registrationRequirements.setRegistrationRequiredForFullDescription(configuration.isRegistrationRequiredForFullDescription());
+
registrationRequirements.setRegistrationRequired(configuration.isRegistrationRequired());
+
if
(!ProducerRegistrationRequirements.DEFAULT_POLICY_CLASS_NAME.equals(policyClassName))
{
- getRegRequirements().reloadPolicyFrom(policyClassName, validatorClassName);
+ registrationRequirements.reloadPolicyFrom(policyClassName,
validatorClassName);
}
+
+
registrationRequirements.setRegistrationProperties(configuration.getRegistrationRequirements().getRegistrationProperties());
+
getConfigurationService().saveConfiguration();
beanContext.createInfoMessage("bean_producer_save_success");
}
@@ -191,6 +186,10 @@
try
{
getConfigurationService().reloadConfiguration();
+
+ // force a reload local state
+ registrationConfiguration = null;
+
beanContext.createInfoMessage("bean_producer_cancel_success");
}
catch (Exception e)
@@ -235,4 +234,86 @@
{
return false; // default implementation as not used
}
+
+ private RegistrationConfiguration getRegRequirements()
+ {
+ if (registrationConfiguration == null)
+ {
+ registrationConfiguration = new RegistrationConfiguration();
+
registrationConfiguration.initFrom(getConfiguration().getRegistrationRequirements());
+ }
+
+ return registrationConfiguration;
+ }
+
+ private static class RegistrationConfiguration
+ {
+ private List<RegistrationPropertyDescription> registrationProperties;
+ private ProducerRegistrationRequirements registrationRequirements;
+
+ public void initFrom(ProducerRegistrationRequirements registrationRequirements)
+ {
+ this.registrationRequirements = new
ProducerRegistrationRequirementsImpl(registrationRequirements);
+
+ Map descriptions = registrationRequirements.getRegistrationProperties();
+ registrationProperties = new
LinkedList<RegistrationPropertyDescription>(descriptions.values());
+ Collections.sort(registrationProperties);
+ }
+
+ public boolean isRegistrationRequiredForFullDescription()
+ {
+ return registrationRequirements.isRegistrationRequiredForFullDescription();
+ }
+
+ public void setRegistrationRequiredForFullDescription(boolean
requireRegForFullDescription)
+ {
+
registrationRequirements.setRegistrationRequiredForFullDescription(requireRegForFullDescription);
+ }
+
+ public boolean isRegistrationRequired()
+ {
+ return registrationRequirements.isRegistrationRequired();
+ }
+
+ public void setRegistrationRequired(boolean requireRegistration)
+ {
+ registrationRequirements.setRegistrationRequired(requireRegistration);
+ }
+
+ public RegistrationPolicy getPolicy()
+ {
+ return registrationRequirements.getPolicy();
+ }
+
+ public List<RegistrationPropertyDescription> getRegistrationProperties()
+ {
+ return registrationProperties;
+ }
+
+ public void addEmptyRegistrationProperty(String propertyName)
+ {
+ RegistrationPropertyDescription prop =
registrationRequirements.addEmptyRegistrationProperty(propertyName);
+
+ // Search for the non-existent item
+ int index = Collections.binarySearch(registrationProperties, prop);
+
+ // Add the non-existent item to the list
+ if (index < 0)
+ {
+ registrationProperties.add(-index - 1, prop);
+ }
+ }
+
+ public void removeRegistrationProperty(String propertyName)
+ {
+ RegistrationPropertyDescription prop =
registrationRequirements.removeRegistrationProperty(propertyName);
+
+ registrationProperties.remove(prop);
+ }
+
+ public ProducerRegistrationRequirements getRegistrationRequirements()
+ {
+ return registrationRequirements;
+ }
+ }
}
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/registration/PropertyDescription.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/registration/PropertyDescription.java 2010-10-17
21:58:12 UTC (rev 4698)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/registration/PropertyDescription.java 2010-10-18
01:48:48 UTC (rev 4699)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * Copyright 2010, 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.
@@ -30,7 +30,7 @@
* @version $Revision: 9177 $
* @since 2.6.3
*/
-public interface PropertyDescription
+public interface PropertyDescription extends Comparable<PropertyDescription>
{
QName getName();
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/registration/RegistrationPropertyDescription.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/registration/RegistrationPropertyDescription.java 2010-10-17
21:58:12 UTC (rev 4698)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/registration/RegistrationPropertyDescription.java 2010-10-18
01:48:48 UTC (rev 4699)
@@ -147,6 +147,10 @@
", label=" + label;
}
+ public int compareTo(PropertyDescription o)
+ {
+ return getName().toString().compareTo(o.getName().toString());
+ }
public String getPersistentKey()
{
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/ProducerConfigurationService.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/ProducerConfigurationService.java 2010-10-17
21:58:12 UTC (rev 4698)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/ProducerConfigurationService.java 2010-10-18
01:48:48 UTC (rev 4699)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * Copyright 2010, 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.
@@ -40,6 +40,8 @@
*/
void reloadConfiguration() throws Exception;
+ void reloadConfiguration(boolean triggerListeners) throws Exception;
+
/**
* Saves the producer configuration to persistent storage.
*
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirements.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirements.java 2010-10-17
21:58:12 UTC (rev 4698)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirements.java 2010-10-18
01:48:48 UTC (rev 4699)
@@ -55,9 +55,9 @@
void addRegistrationProperty(RegistrationPropertyDescription propertyDescription);
- void removeRegistrationProperty(String propertyName);
+ RegistrationPropertyDescription removeRegistrationProperty(String propertyName);
- void removeRegistrationProperty(QName propertyName);
+ RegistrationPropertyDescription removeRegistrationProperty(QName propertyName);
void clearRegistrationProperties();
@@ -94,7 +94,7 @@
* @param name
* @since 2.6.3
*/
- void addEmptyRegistrationProperty(String name);
+ RegistrationPropertyDescription addEmptyRegistrationProperty(String name);
/**
* @param listener
@@ -116,4 +116,6 @@
Set<RegistrationPolicyChangeListener> getPolicyChangeListeners();
long getLastModified();
+
+ void setRegistrationProperties(Map<QName, RegistrationPropertyDescription>
registrationProperties);
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/AbstractProducerConfigurationService.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/AbstractProducerConfigurationService.java 2010-10-17
21:58:12 UTC (rev 4698)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/AbstractProducerConfigurationService.java 2010-10-18
01:48:48 UTC (rev 4699)
@@ -48,6 +48,11 @@
public void reloadConfiguration() throws Exception
{
+ reloadConfiguration(false);
+ }
+
+ public void reloadConfiguration(boolean triggerListeners) throws Exception
+ {
// save listeners if we already have a configuration
List<ProducerConfigurationChangeListener> listeners = null;
Set<RegistrationPolicyChangeListener> policyListeners = null;
@@ -67,13 +72,16 @@
// reload
loadConfiguration();
- // restore listeners and trigger them
+ // restore listeners and trigger them if requested
if (listeners != null)
{
for (ProducerConfigurationChangeListener listener : listeners)
{
configuration.addChangeListener(listener);
- listener.usingStrictModeChangedTo(configuration.isUsingStrictMode());
+ if (triggerListeners)
+ {
+ listener.usingStrictModeChangedTo(configuration.isUsingStrictMode());
+ }
}
}
registrationRequirements = configuration.getRegistrationRequirements();
@@ -84,7 +92,10 @@
for (RegistrationPropertyChangeListener listener : propertyListeners)
{
registrationRequirements.addRegistrationPropertyChangeListener(listener);
-
listener.propertiesHaveChanged(registrationRequirements.getRegistrationProperties());
+ if (triggerListeners)
+ {
+
listener.propertiesHaveChanged(registrationRequirements.getRegistrationProperties());
+ }
}
}
if (policyListeners != null)
@@ -92,7 +103,10 @@
for (RegistrationPolicyChangeListener listener : policyListeners)
{
registrationRequirements.addRegistrationPolicyChangeListener(listener);
- listener.policyUpdatedTo(registrationRequirements.getPolicy());
+ if (triggerListeners)
+ {
+ listener.policyUpdatedTo(registrationRequirements.getPolicy());
+ }
}
}
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java 2010-10-17
21:58:12 UTC (rev 4698)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java 2010-10-18
01:48:48 UTC (rev 4699)
@@ -78,6 +78,21 @@
registrationProperties = new HashMap<QName,
RegistrationPropertyDescription>(7);
}
+ public ProducerRegistrationRequirementsImpl(ProducerRegistrationRequirements other)
+ {
+ this(false, other.isRegistrationRequired(),
other.isRegistrationRequiredForFullDescription());
+ setPolicy(other.getPolicy());
+
+ Set<Map.Entry<QName, RegistrationPropertyDescription>> otherProps =
other.getRegistrationProperties().entrySet();
+ registrationProperties = new HashMap<QName,
RegistrationPropertyDescription>(otherProps.size());
+ for (Map.Entry<QName, RegistrationPropertyDescription> entry : otherProps)
+ {
+ registrationProperties.put(entry.getKey(), new
RegistrationPropertyDescription(entry.getValue()));
+ }
+
+ modifyNow();
+ }
+
private void modifyNow()
{
lastModified = System.nanoTime();
@@ -88,6 +103,25 @@
return lastModified;
}
+ public void setRegistrationProperties(Map<QName,
RegistrationPropertyDescription> regProps)
+ {
+ if (registrationProperties.equals(regProps))
+ {
+ return;
+ }
+ else
+ {
+ registrationProperties.clear();
+
+ for (RegistrationPropertyDescription propertyDescription : regProps.values())
+ {
+ addRegistrationProperty(new
RegistrationPropertyDescription(propertyDescription));
+ }
+
+ notifyRegistrationPropertyChangeListeners();
+ }
+ }
+
public boolean isRegistrationRequired()
{
return requiresRegistration;
@@ -95,14 +129,14 @@
public void setRegistrationRequired(boolean requiresRegistration)
{
- // if we switch from requiring registration to no registration, erase registration
properties
- if (this.requiresRegistration && !requiresRegistration)
+ if (this.requiresRegistration != requiresRegistration)
{
- clearRegistrationProperties();
- }
+ // if we switch from requiring registration to no registration, erase
registration properties
+ if (this.requiresRegistration && !requiresRegistration)
+ {
+ clearRegistrationProperties();
+ }
- if (this.requiresRegistration != requiresRegistration)
- {
this.requiresRegistration = requiresRegistration;
modifyNow();
}
@@ -139,12 +173,14 @@
notifyRegistrationPropertyChangeListeners();
}
- public void addEmptyRegistrationProperty(String name)
+ public RegistrationPropertyDescription addEmptyRegistrationProperty(String name)
{
ParameterValidation.throwIllegalArgExceptionIfNull(name, "Property
name");
RegistrationPropertyDescription reg = new RegistrationPropertyDescription(name,
WSRPConstants.XSD_STRING);
addRegistrationProperty(reg);
+
+ return reg;
}
public boolean acceptValueFor(QName propertyName, Object value)
@@ -180,14 +216,17 @@
return new
RegistrationPropertyDescription(registrationProperties.get(propertyName));
}
- public void removeRegistrationProperty(QName propertyName)
+ public RegistrationPropertyDescription removeRegistrationProperty(QName propertyName)
{
ParameterValidation.throwIllegalArgExceptionIfNull(propertyName, "Property
name");
- if (registrationProperties.remove(propertyName) != null)
+ RegistrationPropertyDescription prop =
registrationProperties.remove(propertyName);
+ if (prop != null)
{
modifyNow();
notifyRegistrationPropertyChangeListeners();
}
+
+ return prop;
}
public void clearRegistrationProperties()
@@ -197,9 +236,9 @@
notifyRegistrationPropertyChangeListeners();
}
- public void removeRegistrationProperty(String propertyName)
+ public RegistrationPropertyDescription removeRegistrationProperty(String
propertyName)
{
- removeRegistrationProperty(QName.valueOf(propertyName));
+ return removeRegistrationProperty(QName.valueOf(propertyName));
}
/*
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/xml/FileSystemXMLProducerConfigurationService.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/xml/FileSystemXMLProducerConfigurationService.java 2010-10-17
21:58:12 UTC (rev 4698)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/xml/FileSystemXMLProducerConfigurationService.java 2010-10-18
01:48:48 UTC (rev 4699)
@@ -24,10 +24,8 @@
package org.gatein.wsrp.producer.config.impl.xml;
import org.gatein.common.net.URLTools;
-//import org.jboss.xb.binding.Marshaller;
import org.jboss.xb.binding.ObjectModelProvider;
import org.jboss.xb.binding.XercesXsMarshaller;
-import org.jboss.xb.binding.sunday.marshalling.MarshallerImpl;
import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Modified:
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/DefaultRegistrationPolicyTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/DefaultRegistrationPolicyTestCase.java 2010-10-17
21:58:12 UTC (rev 4698)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/DefaultRegistrationPolicyTestCase.java 2010-10-18
01:48:48 UTC (rev 4699)
@@ -174,5 +174,10 @@
{
return TYPE;
}
+
+ public int compareTo(PropertyDescription o)
+ {
+ return name.toString().compareTo(o.getName().toString());
+ }
}
}
Added:
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirementsTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirementsTestCase.java
(rev 0)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirementsTestCase.java 2010-10-18
01:48:48 UTC (rev 4699)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, 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.wsrp.producer.config;
+
+import junit.framework.TestCase;
+import org.gatein.registration.RegistrationPolicy;
+import org.gatein.registration.RegistrationPolicyChangeListener;
+import org.gatein.registration.RegistrationPropertyChangeListener;
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.producer.config.impl.ProducerRegistrationRequirementsImpl;
+import org.gatein.wsrp.registration.PropertyDescription;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+
+import javax.xml.namespace.QName;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class ProducerRegistrationRequirementsTestCase extends TestCase
+{
+ public void testSetRegistrationProperties()
+ {
+ ProducerRegistrationRequirements requirements = new
ProducerRegistrationRequirementsImpl();
+ requirements.addEmptyRegistrationProperty("foo");
+ requirements.addEmptyRegistrationProperty("bar");
+
+ final Map<QName, RegistrationPropertyDescription> expected = new
HashMap<QName, RegistrationPropertyDescription>();
+ RegistrationPropertyDescription newFoo = new
RegistrationPropertyDescription("newFoo", WSRPConstants.XSD_STRING);
+ expected.put(newFoo.getName(), newFoo);
+
+ requirements.addRegistrationPropertyChangeListener(new
RegistrationPropertyChangeListener()
+ {
+ public void propertiesHaveChanged(Map<QName, ? extends
PropertyDescription> newRegistrationProperties)
+ {
+ assertEquals(expected, newRegistrationProperties);
+ }
+ });
+
+ requirements.setRegistrationProperties(expected);
+ }
+
+ public void testSetUnchangedRegistrationProperties()
+ {
+ ProducerRegistrationRequirements requirements = new
ProducerRegistrationRequirementsImpl();
+ requirements.addEmptyRegistrationProperty("foo");
+
+ final Map<QName, RegistrationPropertyDescription> expected = new
HashMap<QName, RegistrationPropertyDescription>();
+ RegistrationPropertyDescription newFoo = new
RegistrationPropertyDescription("foo", WSRPConstants.XSD_STRING);
+ expected.put(newFoo.getName(), newFoo);
+
+ requirements.addRegistrationPropertyChangeListener(new
RegistrationPropertyChangeListener()
+ {
+ public void propertiesHaveChanged(Map<QName, ? extends
PropertyDescription> newRegistrationProperties)
+ {
+ fail("Shouldn't have been called!");
+ }
+ });
+
+ requirements.setRegistrationProperties(expected);
+ }
+
+ public void testReloadSamePolicy()
+ {
+ ProducerRegistrationRequirements requirements = new
ProducerRegistrationRequirementsImpl();
+
+ // load policy the first time
+
requirements.reloadPolicyFrom(ProducerRegistrationRequirements.DEFAULT_POLICY_CLASS_NAME,
ProducerRegistrationRequirements.DEFAULT_VALIDATOR_CLASS_NAME);
+
+ // add listener that shouldn't been called since policy hasn't changed
+ requirements.addRegistrationPolicyChangeListener(new
RegistrationPolicyChangeListener()
+ {
+ public void policyUpdatedTo(RegistrationPolicy policy)
+ {
+ fail("Shouldn't have been called!");
+ }
+ });
+
+ // try reloading policy
+
requirements.reloadPolicyFrom(ProducerRegistrationRequirements.DEFAULT_POLICY_CLASS_NAME,
ProducerRegistrationRequirements.DEFAULT_VALIDATOR_CLASS_NAME);
+ }
+
+ public void testSetRegistrationRequired()
+ {
+ ProducerRegistrationRequirements requirements = new
ProducerRegistrationRequirementsImpl();
+
+ requirements.setRegistrationRequired(true);
+ assertTrue(requirements.isRegistrationRequired());
+
+ requirements.addRegistrationPropertyChangeListener(new
RegistrationPropertyChangeListener()
+ {
+ public void propertiesHaveChanged(Map<QName, ? extends
PropertyDescription> newRegistrationProperties)
+ {
+ fail("Shouldn't have been called!");
+ }
+ });
+
+ requirements.setRegistrationRequired(true);
+ }
+
+}
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/config/FileSystemXmlProducerConfigWithReload.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/config/FileSystemXmlProducerConfigWithReload.java 2010-10-17
21:58:12 UTC (rev 4698)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/config/FileSystemXmlProducerConfigWithReload.java 2010-10-18
01:48:48 UTC (rev 4699)
@@ -1,35 +1,33 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2010, 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. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, 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.wsrp.config;
-import java.io.FileInputStream;
-import java.net.URL;
-import java.util.Enumeration;
-
import org.gatein.common.net.URLTools;
-import
org.gatein.wsrp.producer.config.impl.xml.FileSystemXMLProducerConfigurationService;
import org.gatein.wsrp.producer.config.impl.xml.SimpleXMLProducerConfigurationService;
+import java.net.URL;
+import java.util.Enumeration;
+
/**
* @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
* @version $Revision$
@@ -40,12 +38,13 @@
// Hack to force the producer to reload when the configuration property is set.
// If unused then we will have issues with the producer not being loaded when we try
// and get an instance.
+
public void setConfigFile(String configLocation) throws Exception
{
// this.inputStream = new FileInputStream(configLocation);
// this.reloadConfiguration();
Enumeration<URL> resources =
Thread.currentThread().getContextClassLoader().getResources(configLocation);
-
+
URL configURL = null;
while (resources.hasMoreElements())
{
@@ -60,10 +59,10 @@
{
throw new Exception("The config " + configURL + " does not
exist");
}
-
+
this.inputStream = configURL.openStream();
this.reloadConfiguration();
}
-
+
}