Author: chris.laprun(a)jboss.com
Date: 2007-11-13 18:55:03 -0500 (Tue, 13 Nov 2007)
New Revision: 8918
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationPropertyDescriptionTestCase.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/ProducerRegistrationRequirements.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java
Log:
- Properly update the parent when a RegistrationPropertyDescription is renamed.
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationPropertyDescriptionTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationPropertyDescriptionTestCase.java 2007-11-13
23:03:14 UTC (rev 8917)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationPropertyDescriptionTestCase.java 2007-11-13
23:55:03 UTC (rev 8918)
@@ -60,6 +60,17 @@
assertTrue(parent.notifyCalled);
}
+ public void testChangingNameUpdatesParent()
+ {
+ TestParent parent = new TestParent();
+ desc.setParent(parent);
+ assertNotNull(parent.getRegistrationPropertyWith("foo"));
+
+ desc.setName(QName.valueOf("bar"));
+ assertEquals(desc, parent.getRegistrationPropertyWith("bar"));
+ assertNull(parent.getRegistrationPropertyWith("foo"));
+ }
+
public void testModifyIfNeeded()
{
String oldValue = "old";
@@ -82,6 +93,9 @@
{
private boolean notifyCalled;
+ // prop name fakes the existence of a property as only one property exists for the
tests
+ private String propName = "foo";
+
void resetNotifyCalled()
{
notifyCalled = false;
@@ -138,6 +152,12 @@
public RegistrationPropertyDescription getRegistrationPropertyWith(String name)
{
+ // return desc only if it matches the name we know about (used to fake property
name updates)
+ if (propName.equals(name))
+ {
+ return desc;
+ }
+
return null;
}
@@ -175,5 +195,16 @@
public void reloadPolicyFrom(String policyClassName, String validatorClassName)
{
}
+
+ public void propertyHasBeenRenamed(RegistrationPropertyDescription
propertyDescription, QName oldName)
+ {
+ // fake updating the property map
+ // if the old name was foo...
+ if ("foo".equals(oldName.getLocalPart()))
+ {
+ // then set the prop name to the new property name
+ propName = propertyDescription.getName().getLocalPart();
+ }
+ }
}
}
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/ProducerRegistrationRequirements.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/ProducerRegistrationRequirements.java 2007-11-13
23:03:14 UTC (rev 8917)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/ProducerRegistrationRequirements.java 2007-11-13
23:55:03 UTC (rev 8918)
@@ -79,4 +79,6 @@
RegistrationPolicy getPolicy();
void reloadPolicyFrom(String policyClassName, String validatorClassName);
+
+ void propertyHasBeenRenamed(RegistrationPropertyDescription propertyDescription, QName
oldName);
}
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java 2007-11-13
23:03:14 UTC (rev 8917)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java 2007-11-13
23:55:03 UTC (rev 8918)
@@ -286,7 +286,22 @@
}
}
+ public void propertyHasBeenRenamed(RegistrationPropertyDescription
propertyDescription, QName oldName)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyDescription,
"RegistrationPropertyDescription");
+ ParameterValidation.throwIllegalArgExceptionIfNull(oldName, "property old
name");
+ if (registrationProperties.containsKey(oldName))
+ {
+ synchronized (this)
+ {
+ registrationProperties.remove(oldName);
+ registrationProperties.put(propertyDescription.getName(),
propertyDescription);
+ }
+ }
+ }
+
+
public void setPolicyClassName(String policyClassName)
{
this.policyClassName = policyClassName;
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java 2007-11-13
23:03:14 UTC (rev 8917)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java 2007-11-13
23:55:03 UTC (rev 8918)
@@ -166,7 +166,16 @@
public void setName(QName name)
{
- this.name = (QName)modifyIfNeeded(this.name, name);
+ if (valueWillBeUpdated(this.name, name))
+ {
+ QName oldName = this.name;
+ this.name = name;
+ if (parent != null)
+ {
+ parent.notifyRegistrationPropertyChangeListeners();
+ parent.propertyHasBeenRenamed(this, oldName);
+ }
+ }
}
public QName getType()
@@ -320,7 +329,7 @@
public Object modifyIfNeeded(Object oldValue, Object newValue)
{
- if ((oldValue != null && !oldValue.equals(newValue)) || (oldValue == null
&& newValue != null))
+ if (valueWillBeUpdated(oldValue, newValue))
{
oldValue = newValue;
notifyParentOfChangeIfNeeded();
@@ -329,6 +338,11 @@
return oldValue;
}
+ private boolean valueWillBeUpdated(Object oldValue, Object newValue)
+ {
+ return (oldValue != null && !oldValue.equals(newValue)) || (oldValue ==
null && newValue != null);
+ }
+
/**
* Tries to heuristically determine the language for this
RegistrationPropertyDescription
*
Show replies by date