Author: chris.laprun(a)jboss.com
Date: 2007-04-28 12:05:14 -0400 (Sat, 28 Apr 2007)
New Revision: 7125
Added:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationPropertyDescriptionTestCase.java
Modified:
trunk/wsrp/build.xml
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationProperty.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/registration/LocalizedString.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java
Log:
- Fixed several issues with RegistrationPropertyDescription (shouldn't notify parents
for non-modifications, removed several potential NPEs) and added test case (could use more
work).
- Added equals and hashCode methods.
Modified: trunk/wsrp/build.xml
===================================================================
--- trunk/wsrp/build.xml 2007-04-28 15:44:42 UTC (rev 7124)
+++ trunk/wsrp/build.xml 2007-04-28 16:05:14 UTC (rev 7125)
@@ -756,6 +756,8 @@
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.EndpointConfigurationInfoTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.ProducerInfoTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.RegistrationInfoTestCase"/>
+ <test todir="${test.reports}"
+
name="org.jboss.portal.test.wsrp.other.RegistrationPropertyDescriptionTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.handler.RequestHeaderClientHandlerTestCase"/>
</x-test>
<x-sysproperty>
Added:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationPropertyDescriptionTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationPropertyDescriptionTestCase.java
(rev 0)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationPropertyDescriptionTestCase.java 2007-04-28
16:05:14 UTC (rev 7125)
@@ -0,0 +1,166 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2007, 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.jboss.portal.test.wsrp.other;
+
+import junit.framework.TestCase;
+import org.jboss.portal.registration.RegistrationPolicy;
+import org.jboss.portal.registration.RegistrationPropertyChangeListener;
+import org.jboss.portal.wsrp.WSRPConstants;
+import org.jboss.portal.wsrp.producer.config.ProducerRegistrationRequirements;
+import org.jboss.portal.wsrp.registration.RegistrationPropertyDescription;
+
+import javax.xml.namespace.QName;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public class RegistrationPropertyDescriptionTestCase extends TestCase
+{
+ private RegistrationPropertyDescription desc;
+
+ protected void setUp() throws Exception
+ {
+ desc = new RegistrationPropertyDescription("foo",
WSRPConstants.XSD_STRING);
+ }
+
+ public void testNotify()
+ {
+ TestParent parent = new TestParent();
+ desc.setParent(parent);
+ desc.setDefaultHint(null);
+ assertFalse(parent.notifyCalled);
+ parent.resetNotifyCalled();
+ desc.setDefaultHint("hint");
+ assertTrue(parent.notifyCalled);
+ }
+
+ public void testModifyIfNeeded()
+ {
+ String oldValue = "old";
+ String newValue = "new";
+ assertEquals(oldValue, desc.modifyIfNeeded(oldValue, oldValue));
+ assertEquals(newValue, desc.modifyIfNeeded(oldValue, newValue));
+ assertEquals(null, desc.modifyIfNeeded(null, null));
+ assertEquals(newValue, desc.modifyIfNeeded(null, newValue));
+ assertEquals(null, desc.modifyIfNeeded(oldValue, null));
+ }
+
+ class TestParent implements ProducerRegistrationRequirements
+ {
+ private boolean notifyCalled;
+
+ void resetNotifyCalled()
+ {
+ notifyCalled = false;
+ }
+
+ public boolean requiresRegistration()
+ {
+ return false;
+ }
+
+ public void setRequiresRegistration(boolean requiresRegistration)
+ {
+ }
+
+ public boolean fullServiceDescriptionRequiresRegistration()
+ {
+ return false;
+ }
+
+ public void setFullServiceDescriptionRequiresRegistration(boolean
fullServiceDescriptionRequiresRegistration)
+ {
+ }
+
+ public Map getRegistrationProperties()
+ {
+ return null;
+ }
+
+ public void addRegistrationProperty(RegistrationPropertyDescription
propertyDescription)
+ {
+ }
+
+ public void removeRegistrationProperty(String propertyName)
+ {
+ }
+
+ public void removeRegistrationProperty(QName propertyName)
+ {
+ }
+
+ public void clearRegistrationProperties()
+ {
+ }
+
+ public boolean acceptValueFor(QName propertyName, Object value)
+ {
+ return false;
+ }
+
+ public boolean acceptValueFor(String propertyName, Object value)
+ {
+ return false;
+ }
+
+ public RegistrationPropertyDescription getRegistrationPropertyWith(String name)
+ {
+ return null;
+ }
+
+ public RegistrationPropertyDescription getRegistrationPropertyWith(QName name)
+ {
+ return null;
+ }
+
+ public void notifyRegistrationPropertyChangeListeners()
+ {
+ notifyCalled = true;
+ }
+
+ public void
addRegistrationPropertyChangeListeners(RegistrationPropertyChangeListener listener)
+ {
+ }
+
+ public void clearRegistrationPropertyChangeListeners()
+ {
+ }
+
+ public void
removeRegistrationPropertyChangeListener(RegistrationPropertyChangeListener listener)
+ {
+ }
+
+ public void setPolicy(RegistrationPolicy policy)
+ {
+ }
+
+ public RegistrationPolicy getPolicy()
+ {
+ return null;
+ }
+ }
+}
Property changes on:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationPropertyDescriptionTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationProperty.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationProperty.java 2007-04-28
15:44:42 UTC (rev 7124)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationProperty.java 2007-04-28
16:05:14 UTC (rev 7125)
@@ -51,6 +51,59 @@
}
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ RegistrationProperty that = (RegistrationProperty)o;
+
+ if (key != null ? !key.equals(that.key) : that.key != null)
+ {
+ return false;
+ }
+ if (!name.equals(that.name))
+ {
+ return false;
+ }
+ if (value != null ? !value.equals(that.value) : that.value != null)
+ {
+ return false;
+ }
+ if (invalid != that.invalid)
+ {
+ return false;
+ }
+ if (lang != null ? !lang.equals(that.lang) : that.lang != null)
+ {
+ return false;
+ }
+ if (description != null ? !description.equals(that.description) : that.description
!= null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (key != null ? key.hashCode() : 0);
+ result = 31 * result + (description != null ? description.hashCode() : 0);
+ result = 31 * result + (invalid ? 1 : 0);
+ result = 31 * result + (lang != null ? lang.hashCode() : 0);
+ result = 31 * result + name.hashCode();
+ result = 31 * result + (value != null ? value.hashCode() : 0);
+ return result;
+ }
+
public Long getKey()
{
return key;
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/registration/LocalizedString.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/registration/LocalizedString.java 2007-04-28
15:44:42 UTC (rev 7124)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/registration/LocalizedString.java 2007-04-28
16:05:14 UTC (rev 7125)
@@ -58,6 +58,7 @@
public LocalizedString(LocalizedString other)
{
+ ParameterValidation.throwIllegalArgExceptionIfNull(other,
"LocalizedString");
this.value = other.value;
this.locale = other.locale;
this.resourceName = other.resourceName;
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java 2007-04-28
15:44:42 UTC (rev 7124)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java 2007-04-28
16:05:14 UTC (rev 7125)
@@ -23,11 +23,13 @@
package org.jboss.portal.wsrp.registration;
+import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.wsrp.producer.config.ProducerRegistrationRequirements;
import javax.xml.namespace.QName;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Arrays;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -65,24 +67,78 @@
public RegistrationPropertyDescription(RegistrationPropertyDescription other)
{
+ ParameterValidation.throwIllegalArgExceptionIfNull(other,
"RegistrationPropertyDescription");
+
setName(new QName(other.name.toString()));
setType(new QName(other.type.toString()));
- aliases = new QName[other.aliases.length];
- System.arraycopy(other.aliases, 0, aliases, 0, other.aliases.length);
+ if (other.aliases != null)
+ {
+ aliases = new QName[other.aliases.length];
+ System.arraycopy(other.aliases, 0, aliases, 0, other.aliases.length);
+ }
- setDescription(new LocalizedString(other.description));
- setHint(new LocalizedString(other.hint));
- setLabel(new LocalizedString(other.label));
- setSchemaLocation(other.schemaLocation);
+ if (other.description != null)
+ {
+ setDescription(new LocalizedString(other.description));
+ }
+ if (other.hint != null)
+ {
+ setHint(new LocalizedString(other.hint));
+ }
+ if (other.label != null)
+ {
+ setLabel(new LocalizedString(other.label));
+ }
+ if (other.schemaLocation != null)
+ {
+ setSchemaLocation(other.schemaLocation);
+ }
- usages = new String[other.usages.length];
- System.arraycopy(other.usages, 0, usages, 0, other.usages.length);
+ if (other.usages != null)
+ {
+ usages = new String[other.usages.length];
+ System.arraycopy(other.usages, 0, usages, 0, other.usages.length);
+ }
parent = other.parent;
}
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ RegistrationPropertyDescription that = (RegistrationPropertyDescription)o;
+
+ if (key != null ? !key.equals(that.key) : that.key != null)
+ {
+ return false;
+ }
+ if (!name.equals(that.name))
+ {
+ return false;
+ }
+ return type.equals(that.type);
+
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (key != null ? key.hashCode() : 0);
+ result = 31 * result + name.hashCode();
+ result = 31 * result + type.hashCode();
+ return result;
+ }
+
public String toString()
{
return "Registration Property Description named '" + name +
@@ -109,8 +165,7 @@
public void setName(QName name)
{
- this.name = name;
- notifyParentOfChangeIfNeeded();
+ this.name = (QName)modifyIfNeeded(this.name, name);
}
public QName getType()
@@ -120,8 +175,7 @@
public void setType(QName type)
{
- this.type = type;
- notifyParentOfChangeIfNeeded();
+ this.type = (QName)modifyIfNeeded(this.type, type);
}
public String getSchemaLocation()
@@ -144,18 +198,21 @@
public void setSchemaLocation(String schemaLocation)
{
- // first check if schemaLocation is a valid URI
- try
+ //
+ if (schemaLocation != null)
{
- new URI(schemaLocation);
+ // first check if schemaLocation is a valid URI
+ try
+ {
+ new URI(schemaLocation);
+ }
+ catch (URISyntaxException e)
+ {
+ throw new IllegalArgumentException("Invalid URI: " + schemaLocation
+ ". Cause: " + e.getLocalizedMessage());
+ }
+
+ this.schemaLocation = (String)modifyIfNeeded(this.schemaLocation,
schemaLocation);
}
- catch (URISyntaxException e)
- {
- throw new IllegalArgumentException("Invalid URI: " + schemaLocation +
". Cause: " + e.getLocalizedMessage());
- }
-
- this.schemaLocation = schemaLocation;
- notifyParentOfChangeIfNeeded();
}
public LocalizedString getDescription()
@@ -165,13 +222,12 @@
public void setDescription(LocalizedString description)
{
- this.description = description;
- notifyParentOfChangeIfNeeded();
+ this.description = (LocalizedString)modifyIfNeeded(this.description, description);
}
public void setDefaultDescription(String value)
{
- setDescription(new LocalizedString(value));
+ setDescription(value == null ? null : new LocalizedString(value));
}
public LocalizedString getHint()
@@ -181,13 +237,12 @@
public void setHint(LocalizedString hint)
{
- this.hint = hint;
- notifyParentOfChangeIfNeeded();
+ this.hint = (LocalizedString)modifyIfNeeded(this.hint, hint);
}
public void setDefaultHint(String value)
{
- setHint(new LocalizedString(value));
+ setHint(value == null ? null : new LocalizedString(value));
}
public LocalizedString getLabel()
@@ -197,13 +252,12 @@
public void setLabel(LocalizedString label)
{
- this.label = label;
- notifyParentOfChangeIfNeeded();
+ this.label = (LocalizedString)modifyIfNeeded(this.label, label);
}
public void setDefaultLabel(String value)
{
- setLabel(new LocalizedString(value));
+ setLabel(value == null ? null : new LocalizedString(value));
}
public String[] getUsages()
@@ -213,9 +267,19 @@
public void setUsages(String[] usages)
{
- this.usages = new String[usages.length];
- System.arraycopy(usages, 0, this.usages, 0, usages.length);
- notifyParentOfChangeIfNeeded();
+ if (!Arrays.equals(this.usages, usages))
+ {
+ if (usages != null)
+ {
+ this.usages = new String[usages.length];
+ System.arraycopy(usages, 0, this.usages, 0, usages.length);
+ }
+ else
+ {
+ this.usages = null;
+ }
+ notifyParentOfChangeIfNeeded();
+ }
}
public QName[] getAliases()
@@ -225,9 +289,19 @@
public void setAliases(QName[] aliases)
{
- this.aliases = new QName[aliases.length];
- System.arraycopy(aliases, 0, this.aliases, 0, aliases.length);
- notifyParentOfChangeIfNeeded();
+ if (!Arrays.equals(this.aliases, aliases))
+ {
+ if (aliases != null)
+ {
+ this.aliases = new QName[aliases.length];
+ System.arraycopy(aliases, 0, this.aliases, 0, aliases.length);
+ }
+ else
+ {
+ this.aliases = null;
+ }
+ notifyParentOfChangeIfNeeded();
+ }
}
public void setParent(ProducerRegistrationRequirements requirements)
@@ -242,4 +316,15 @@
parent.notifyRegistrationPropertyChangeListeners();
}
}
+
+ public Object modifyIfNeeded(Object oldValue, Object newValue)
+ {
+ if ((oldValue != null && !oldValue.equals(newValue)) || (oldValue == null
&& newValue != null))
+ {
+ oldValue = newValue;
+ notifyParentOfChangeIfNeeded();
+ }
+
+ return oldValue;
+ }
}