Author: chris.laprun(a)jboss.com
Date: 2010-06-15 18:29:02 -0400 (Tue, 15 Jun 2010)
New Revision: 3343
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/impl/ProducerRegistrationRequirementsImpl.java
Log:
- Added last modification date so that clients can know whether they can use cached data
or not.
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-06-15
22:27:28 UTC (rev 3342)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirements.java 2010-06-15
22:29:02 UTC (rev 3343)
@@ -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.
@@ -114,4 +114,6 @@
Set<RegistrationPropertyChangeListener> getPropertyChangeListeners();
Set<RegistrationPolicyChangeListener> getPolicyChangeListeners();
+
+ long getLastModified();
}
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-06-15
22:27:28 UTC (rev 3342)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java 2010-06-15
22:29:02 UTC (rev 3343)
@@ -58,6 +58,7 @@
private RegistrationPolicy policy;
private String policyClassName;
private String validatorClassName;
+ private long lastModified;
private Map<QName, RegistrationPropertyDescription> registrationProperties;
@@ -69,6 +70,7 @@
this();
this.requiresRegistration = requiresRegistration;
this.fullServiceDescriptionRequiresRegistration =
fullServiceDescriptionRequiresRegistration;
+ modifyNow();
}
public ProducerRegistrationRequirementsImpl()
@@ -76,6 +78,16 @@
registrationProperties = new HashMap<QName,
RegistrationPropertyDescription>(7);
}
+ private void modifyNow()
+ {
+ lastModified = System.currentTimeMillis();
+ }
+
+ public long getLastModified()
+ {
+ return lastModified;
+ }
+
public boolean isRegistrationRequired()
{
return requiresRegistration;
@@ -89,7 +101,11 @@
clearRegistrationProperties();
}
- this.requiresRegistration = requiresRegistration;
+ if (this.requiresRegistration != requiresRegistration)
+ {
+ this.requiresRegistration = requiresRegistration;
+ modifyNow();
+ }
}
public boolean isRegistrationRequiredForFullDescription()
@@ -99,7 +115,11 @@
public void setRegistrationRequiredForFullDescription(boolean
fullServiceDescriptionRequiresRegistration)
{
- this.fullServiceDescriptionRequiresRegistration =
fullServiceDescriptionRequiresRegistration;
+ if (this.fullServiceDescriptionRequiresRegistration !=
fullServiceDescriptionRequiresRegistration)
+ {
+ this.fullServiceDescriptionRequiresRegistration =
fullServiceDescriptionRequiresRegistration;
+ modifyNow();
+ }
}
public Map<QName, RegistrationPropertyDescription> getRegistrationProperties()
@@ -114,6 +134,7 @@
ParameterValidation.throwIllegalArgExceptionIfNull(name, "Property
name");
registrationProperties.put(name, propertyDescription);
+ modifyNow();
propertyDescription.setValueChangeListener(this);
notifyRegistrationPropertyChangeListeners();
}
@@ -137,13 +158,13 @@
public boolean acceptValueFor(String propertyName, Object value)
{
- return acceptValueFor(new QName(propertyName), value);
+ return acceptValueFor(QName.valueOf(propertyName), value);
}
public RegistrationPropertyDescription getRegistrationPropertyWith(String name)
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "Property
name", null);
- return getRegistrationPropertyWith(new QName(name));
+ return getRegistrationPropertyWith(QName.valueOf(name));
}
@@ -162,19 +183,23 @@
public void removeRegistrationProperty(QName propertyName)
{
ParameterValidation.throwIllegalArgExceptionIfNull(propertyName, "Property
name");
- registrationProperties.remove(propertyName);
- notifyRegistrationPropertyChangeListeners();
+ if (registrationProperties.remove(propertyName) != null)
+ {
+ modifyNow();
+ notifyRegistrationPropertyChangeListeners();
+ }
}
public void clearRegistrationProperties()
{
registrationProperties.clear();
+ modifyNow();
notifyRegistrationPropertyChangeListeners();
}
public void removeRegistrationProperty(String propertyName)
{
- removeRegistrationProperty(new QName(propertyName));
+ removeRegistrationProperty(QName.valueOf(propertyName));
}
/*
@@ -183,6 +208,7 @@
public void valueHasChanged(RegistrationPropertyDescription originatingProperty,
Object oldValue, Object newValue, boolean isName)
{
+ modifyNow();
notifyRegistrationPropertyChangeListeners();
if (isName && oldValue instanceof QName)
{
@@ -196,9 +222,10 @@
public void notifyRegistrationPropertyChangeListeners()
{
+ Map<QName, RegistrationPropertyDescription> newRegistrationProperties =
Collections.unmodifiableMap(registrationProperties);
for (RegistrationPropertyChangeListener listener : propertyChangeListeners)
{
- listener.propertiesHaveChanged(registrationProperties);
+ listener.propertiesHaveChanged(newRegistrationProperties);
}
}
@@ -275,6 +302,7 @@
}
}
+ modifyNow();
notifyRegistrationPolicyChangeListeners();
}
}
@@ -291,69 +319,80 @@
public void reloadPolicyFrom(String policyClassName, String validatorClassName)
{
- if (policyClassName != null &&
!DEFAULT_POLICY_CLASS_NAME.equals(policyClassName))
+ // only reload if we don't already have a policy or if the requested
policy/validator classes are different
+ // from the ones we already have
+ if (
+ policy == null ||
+ (
+ ParameterValidation.isOldAndNewDifferent(this.policyClassName,
policyClassName) &&
+ ParameterValidation.isOldAndNewDifferent(this.validatorClassName,
validatorClassName)
+ )
+ )
{
- log.debug("Using registration policy: " + policyClassName);
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- try
+ if (policyClassName != null &&
!DEFAULT_POLICY_CLASS_NAME.equals(policyClassName))
{
- Class policyClass = loader.loadClass(policyClassName);
- if (!RegistrationPolicy.class.isAssignableFrom(policyClass))
- {
- throw new IllegalArgumentException("Policy class does not implement
RegistrationPolicy!");
- }
- RegistrationPolicy policy = (RegistrationPolicy)policyClass.newInstance();
-
- // wrap policy so that we can perform minimal sanitization of values
- RegistrationPolicyWrapper wrapper = new RegistrationPolicyWrapper(policy);
-
- setPolicy(wrapper);
- }
- catch (ClassNotFoundException e)
- {
- throw new IllegalArgumentException("Couldn't find policy class
" + policyClassName + ".", e);
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("Couldn't instantiate policy
class.", e);
- }
- }
- else
- {
- log.debug("Using default registration policy: " +
DEFAULT_POLICY_CLASS_NAME);
- RegistrationPropertyValidator validator;
- if (validatorClassName != null &&
!DEFAULT_VALIDATOR_CLASS_NAME.equals(validatorClassName))
- {
- log.debug("Using registration property validator: " +
validatorClassName);
+ log.debug("Using registration policy: " + policyClassName);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
try
{
- Class validatorClass = loader.loadClass(validatorClassName);
- if
(!RegistrationPropertyValidator.class.isAssignableFrom(validatorClass))
+ Class policyClass = loader.loadClass(policyClassName);
+ if (!RegistrationPolicy.class.isAssignableFrom(policyClass))
{
- throw new IllegalArgumentException("Validator class does not
implement RegistrationPropertyValidator!");
+ throw new IllegalArgumentException("Policy class does not
implement RegistrationPolicy!");
}
- validator = (RegistrationPropertyValidator)validatorClass.newInstance();
+ RegistrationPolicy policy =
(RegistrationPolicy)policyClass.newInstance();
+
+ // wrap policy so that we can perform minimal sanitization of values
+ RegistrationPolicyWrapper wrapper = new
RegistrationPolicyWrapper(policy);
+
+ setPolicy(wrapper);
}
catch (ClassNotFoundException e)
{
- throw new IllegalArgumentException("Couldn't find validator class
" + validatorClassName + ".", e);
+ throw new IllegalArgumentException("Couldn't find policy class
" + policyClassName + ".", e);
}
catch (Exception e)
{
- throw new IllegalArgumentException("Couldn't instantiate
validator class.", e);
+ throw new IllegalArgumentException("Couldn't instantiate policy
class.", e);
}
}
else
{
- log.debug("Using default registration property validator: " +
DEFAULT_VALIDATOR_CLASS_NAME);
- validator = new DefaultRegistrationPropertyValidator();
- }
+ log.debug("Using default registration policy: " +
DEFAULT_POLICY_CLASS_NAME);
+ RegistrationPropertyValidator validator;
+ if (validatorClassName != null &&
!DEFAULT_VALIDATOR_CLASS_NAME.equals(validatorClassName))
+ {
+ log.debug("Using registration property validator: " +
validatorClassName);
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Class validatorClass = loader.loadClass(validatorClassName);
+ if
(!RegistrationPropertyValidator.class.isAssignableFrom(validatorClass))
+ {
+ throw new IllegalArgumentException("Validator class does not
implement RegistrationPropertyValidator!");
+ }
+ validator =
(RegistrationPropertyValidator)validatorClass.newInstance();
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new IllegalArgumentException("Couldn't find validator
class " + validatorClassName + ".", e);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("Couldn't instantiate
validator class.", e);
+ }
+ }
+ else
+ {
+ log.debug("Using default registration property validator: " +
DEFAULT_VALIDATOR_CLASS_NAME);
+ validator = new DefaultRegistrationPropertyValidator();
+ }
- DefaultRegistrationPolicy policy = new DefaultRegistrationPolicy();
- policy.setValidator(validator);
- setPolicy(policy);
+ DefaultRegistrationPolicy policy = new DefaultRegistrationPolicy();
+ policy.setValidator(validator);
+ setPolicy(policy);
+ }
}
}
@@ -368,6 +407,7 @@
{
registrationProperties.remove(oldName);
registrationProperties.put(propertyDescription.getName(),
propertyDescription);
+ modifyNow();
}
}
}