Author: julien(a)jboss.com
Date: 2006-12-11 11:08:27 -0500 (Mon, 11 Dec 2006)
New Revision: 5793
Added:
trunk/common/src/main/org/jboss/portal/test/common/TypedMapTestCase.java
Modified:
trunk/common/build.xml
trunk/common/src/main/org/jboss/portal/common/util/ParameterMap.java
trunk/common/src/main/org/jboss/portal/common/util/TypedMap.java
trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentRegistration.java
trunk/portlet/src/main/org/jboss/portal/portlet/Parameters.java
trunk/portlet/src/main/org/jboss/portal/test/portlet/ParametersTestCase.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/Registration.java
Log:
- improved the TypedMap class to support more stuff
- added a test case for TypedMap
- in core extends the TypedMap class to provide registration properties type checking and
equality implementation
Modified: trunk/common/build.xml
===================================================================
--- trunk/common/build.xml 2006-12-11 11:06:15 UTC (rev 5792)
+++ trunk/common/build.xml 2006-12-11 16:08:27 UTC (rev 5793)
@@ -201,6 +201,7 @@
-->
<x-test>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.common.TypedMapTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.test.InfoTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.test.TestParameterValueTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.test.TestParametrizationTestCase"/>
Modified: trunk/common/src/main/org/jboss/portal/common/util/ParameterMap.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/ParameterMap.java 2006-12-11
11:06:15 UTC (rev 5792)
+++ trunk/common/src/main/org/jboss/portal/common/util/ParameterMap.java 2006-12-11
16:08:27 UTC (rev 5793)
@@ -22,6 +22,8 @@
******************************************************************************/
package org.jboss.portal.common.util;
+import java.util.Arrays;
+
/**
* A decorator that enforce the map content to be <String,String[]>
*
@@ -87,4 +89,11 @@
{
return value;
}
+
+ protected boolean internalValueEquals(Object left, Object right)
+ {
+ String[] valuesL = (String[])left;
+ String[] valuesR = (String[])right;
+ return Arrays.equals(valuesL, valuesR);
+ }
}
Modified: trunk/common/src/main/org/jboss/portal/common/util/TypedMap.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/TypedMap.java 2006-12-11 11:06:15
UTC (rev 5792)
+++ trunk/common/src/main/org/jboss/portal/common/util/TypedMap.java 2006-12-11 16:08:27
UTC (rev 5793)
@@ -32,6 +32,7 @@
/**
* A decorator that enforce the map content to be checked against a type.
+ * Null internal values are not supported.
*
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision$
@@ -43,9 +44,8 @@
/**
* @throws ClassCastException if the key is of an inappropriate type for this map
- * @throws NullPointerException if the key is null and this map does not not permit
null keys
*/
- protected abstract void assertKeyValidity(Object key) throws ClassCastException,
NullPointerException;
+ protected abstract void assertKeyValidity(Object key) throws ClassCastException;
/**
* Unwrap the value to the the internal value that will be stored in the map.
@@ -54,15 +54,72 @@
* @return the unwrapped value
* @throws ClassCastException if the class of the specified value prevents it from
being stored in this map
* @throws IllegalArgumentException if some aspect of this key prevents it from being
stored in this map
- * @throws NullPointerException this map does not permit null values, and the
specified value is null
*/
- protected abstract Object getInternalValue(Object value) throws
IllegalArgumentException, ClassCastException, NullPointerException;
+ protected abstract Object getInternalValue(Object value) throws
IllegalArgumentException, ClassCastException;
/**
* Wrap the internal value into its external representation.
*/
protected abstract Object getExternalValue(Object value);
+ private void validateKey(Object key)
+ {
+ if (key == null)
+ {
+ throw new NullPointerException("No null value accepted");
+ }
+ assertKeyValidity(key);
+ }
+
+ private Object unwrapValue(Object value) throws IllegalArgumentException,
ClassCastException, NullPointerException
+ {
+ if (value == null)
+ {
+ throw new NullPointerException("No null value accepted");
+ }
+
+ //
+ value = getInternalValue(value);
+ if (value == null)
+ {
+ throw new IllegalArgumentException("The provided value " + value +
" was converted to a null value");
+ }
+
+ //
+ return value;
+ }
+
+ private Object wrapValue(Object value) throws IllegalStateException
+ {
+ if (value == null)
+ {
+ return null;
+ }
+
+ //
+ Object wrappedValue = getExternalValue(value);
+ if (wrappedValue == null)
+ {
+ throw new IllegalStateException("Converted an internal value to a null
value " + value);
+ }
+
+ //
+ return wrappedValue;
+ }
+
+ /**
+ * Compare internal values, the default implementation delegates the operation to the
equals method
+ * of the left argument.
+ *
+ * @param left
+ * @param right
+ * @return true if the values are equals
+ */
+ protected boolean internalValueEquals(Object left, Object right)
+ {
+ return left.equals(right);
+ }
+
public int size()
{
return getDelegate().size();
@@ -80,13 +137,13 @@
public boolean containsKey(Object key)
{
- assertKeyValidity(key);
+ validateKey(key);
return getDelegate().containsKey(key);
}
public boolean containsValue(Object value)
{
- value = getInternalValue(value);
+ value = unwrapValue(value);
return getDelegate().containsValue(value);
}
@@ -98,14 +155,8 @@
public void putAll(Map t)
{
Map tmp = new HashMap(t);
- for (Iterator i = tmp.entrySet().iterator(); i.hasNext();)
- {
- Entry entry = (Entry)i.next();
- assertKeyValidity(entry.getKey());
- Object value = getInternalValue(entry.getValue());
- entry.setValue(value);
- }
- getDelegate().putAll(tmp);
+ validate(tmp, true);
+ getDelegate().putAll(t);
}
public Set entrySet()
@@ -120,28 +171,161 @@
public Object get(Object key)
{
- assertKeyValidity(key);
+ validateKey(key);
Object value = getDelegate().get(key);
- return getExternalValue(value);
+ value = wrapValue(value);
+ return value;
}
public Object remove(Object key)
{
- assertKeyValidity(key);
+ validateKey(key);
Object value = getDelegate().remove(key);
- value = getExternalValue(value);
+ value = wrapValue(value);
return value;
}
public Object put(Object key, Object value)
{
- assertKeyValidity(key);
- value = getInternalValue(value);
+ validateKey(key);
+ value = unwrapValue(value);
value = getDelegate().put(key, value);
- value = getExternalValue(value);
+ value = wrapValue(value);
return value;
}
+ // Overriden methods
+
+ /** Compare to parameters objects. */
+ public boolean equals(Object o)
+ {
+ if (o == this)
+ {
+ return true;
+ }
+ if (o instanceof Map)
+ {
+ Map that = (Map)o;
+ Map delegate = getDelegate();
+
+ // Must have same sizes
+ if (that.size() != delegate.size())
+ {
+ return false;
+ }
+
+ //
+ for (Iterator i = that.entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry thatEntry = (Map.Entry)i.next();
+ Object thatKey = thatEntry.getKey();
+ Object thatValue = thatEntry.getValue();
+
+ //
+ try
+ {
+ // We don't support null values
+ if (thatValue == null)
+ {
+ return false;
+ }
+
+ // Check key validity
+ validateKey(thatKey);
+
+ // Unwrap
+ Object thatInternalValue = unwrapValue(thatValue);
+
+ // Get the internal value
+ Object internalValue = delegate.get(thatKey);
+
+ // Check the internal value
+ if (internalValue == null)
+ {
+ return false;
+ }
+
+ // Perform value comparison
+ if (internalValueEquals(internalValue, thatInternalValue) == false)
+ {
+ return false;
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ return false;
+ }
+ catch (ClassCastException e)
+ {
+ return false;
+ }
+ catch (NullPointerException e)
+ {
+ return false;
+ }
+ }
+
+ //
+ return true;
+ }
+
+ //
+ return false;
+ }
+
+ // API extension
+
+ /**
+ * Replace the content with the new map which is validated before replacement.
+ *
+ * @param t the replacement map
+ * @throws ClassCastException
+ * @throws NullPointerException
+ * @throws IllegalArgumentException
+ */
+ public void replace(Map t) throws ClassCastException, NullPointerException,
IllegalArgumentException
+ {
+ validate(t, false);
+
+ //
+ Map delegate = getDelegate();
+ delegate.clear();
+ delegate.putAll(t);
+ }
+
+ /**
+ * Validate the content.
+ *
+ * @throws ClassCastException
+ * @throws NullPointerException
+ * @throws IllegalArgumentException
+ */
+ public void validate() throws ClassCastException, NullPointerException,
IllegalArgumentException
+ {
+ validate(this, false);
+ }
+
+ /**
+ * Validate the map and unwrap it if necessary.
+ */
+ protected final void validate(Map t, boolean unwrap) throws IllegalArgumentException,
NullPointerException, ClassCastException
+ {
+ if (t == null)
+ {
+ throw new NullPointerException("No null map can be accepted");
+ }
+ for (Iterator i = t.entrySet().iterator(); i.hasNext();)
+ {
+ Entry entry = (Entry)i.next();
+ validateKey(entry.getKey());
+ Object value = unwrapValue(entry.getValue());
+ if (unwrap)
+ {
+ entry.setValue(value);
+ }
+ }
+ }
+
public class TypedEntrySet implements Set
{
@@ -281,13 +465,13 @@
public Object getValue()
{
Object value = delegate.getValue();
- value = getExternalValue(value);
+ value = wrapValue(value);
return value;
}
public Object setValue(Object value)
{
- value = getInternalValue(value);
+ value = unwrapValue(value);
return delegate.setValue(value);
}
}
Added: trunk/common/src/main/org/jboss/portal/test/common/TypedMapTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/TypedMapTestCase.java 2006-12-11
11:06:15 UTC (rev 5792)
+++ trunk/common/src/main/org/jboss/portal/test/common/TypedMapTestCase.java 2006-12-11
16:08:27 UTC (rev 5793)
@@ -0,0 +1,417 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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.common;
+
+import junit.framework.TestCase;
+import org.jboss.portal.common.util.TypedMap;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class TypedMapTestCase extends TestCase
+{
+
+ public TypedMapTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testGetWithBrokenGetInternalValue()
+ {
+ StringToIntegerMap map = new StringToIntegerMap();
+ map.internalValueReturnsNull = true;
+ map.get("abc");
+ map.delegate.put("abc", new Integer(0));
+ map.get("abc");
+ }
+
+ public void testPutWithBrokenGetInternalValue()
+ {
+ StringToIntegerMap map = new StringToIntegerMap();
+ map.internalValueReturnsNull = true;
+ try
+ {
+ map.put("abc", "0");
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testRemoveWithBrokenGetInternalValue()
+ {
+ StringToIntegerMap map = new StringToIntegerMap();
+ map.internalValueReturnsNull = true;
+ map.remove("abc");
+ }
+
+ public void testRemoveWithBrokenGetExternalValue()
+ {
+ StringToIntegerMap map = new StringToIntegerMap();
+ map.externalValueReturnsNull = true;
+ map.remove("abc");
+ map.delegate.put("abc", new Integer(0));
+ try
+ {
+ map.remove("abc");
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ }
+ }
+
+ public void testGetWithBrokenGetExternalValue()
+ {
+ StringToIntegerMap map = new StringToIntegerMap();
+ map.externalValueReturnsNull = true;
+ map.get("abc");
+ map.delegate.put("abc", new Integer(0));
+ try
+ {
+ map.get("abc");
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ }
+ }
+
+ public void testPutWithBrokenGetExternalValue()
+ {
+ StringToIntegerMap map = new StringToIntegerMap();
+ map.externalValueReturnsNull = true;
+ map.put("abc", "0");
+ try
+ {
+ map.put("abc", "0");
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ }
+ }
+
+ public void testGetWithInvalidInternalValue()
+ {
+ StringToIntegerMap map = new StringToIntegerMap();
+ map.delegate.put("abc", "0");
+ try
+ {
+ map.get("abc");
+ fail();
+ }
+ catch (ClassCastException expected)
+ {
+ }
+ }
+
+ public void testPutWithInvalidInternalValue()
+ {
+ StringToIntegerMap map = new StringToIntegerMap();
+ map.delegate.put("abc", "0");
+ try
+ {
+ map.put("abc", "0");
+ fail();
+ }
+ catch (ClassCastException expected)
+ {
+ }
+ }
+
+ public void testRemoveWithInvalidInternalValue()
+ {
+ StringToIntegerMap map = new StringToIntegerMap();
+ map.delegate.put("abc", "0");
+ try
+ {
+ map.remove("abc");
+ fail();
+ }
+ catch (ClassCastException expected)
+ {
+ }
+ }
+
+ public void testRemove()
+ {
+ StringToIntegerMap map = new StringToIntegerMap();
+ assertNull(map.remove("abc"));
+ map.delegate.put("abc", new Integer(0));
+ assertEquals("0", map.remove("abc"));
+ assertTrue(map.delegate.isEmpty());
+ }
+
+ public void testPut()
+ {
+ StringToIntegerMap map = new StringToIntegerMap();
+ map.put("abc", "0");
+ assertEquals(Collections.singletonMap("abc", new Integer(0)),
map.delegate);
+ }
+
+ public void testGet()
+ {
+ StringToIntegerMap map = new StringToIntegerMap();
+ assertNull(map.get("abc"));
+ map.delegate.put("abc", new Integer(0));
+ assertEquals(Collections.singletonMap("abc", "0"), map);
+ }
+
+ public void testContainsKeyWithInvalidKey()
+ {
+ try
+ {
+ new StringToIntegerMap().containsKey(null);
+ fail();
+ }
+ catch (NullPointerException expected)
+ {
+ }
+ try
+ {
+ new StringToIntegerMap().containsKey(new Object());
+ fail();
+ }
+ catch (ClassCastException expected)
+ {
+ }
+ }
+
+ public void testContainsValueWithInvalidValue()
+ {
+ try
+ {
+ new StringToIntegerMap().containsValue(null);
+ fail();
+ }
+ catch (NullPointerException expected)
+ {
+ }
+ try
+ {
+ new StringToIntegerMap().containsValue(new Object());
+ fail();
+ }
+ catch (ClassCastException expected)
+ {
+ }
+ }
+
+ public void testRemoveWithInvalidKey()
+ {
+ try
+ {
+ new StringToIntegerMap().remove(null);
+ fail();
+ }
+ catch (NullPointerException expected)
+ {
+ }
+ try
+ {
+ new StringToIntegerMap().remove(new Object());
+ fail();
+ }
+ catch (ClassCastException expected)
+ {
+ }
+ }
+
+ public void testGetWithInvalidKey()
+ {
+ try
+ {
+ new StringToIntegerMap().get(null);
+ fail();
+ }
+ catch (NullPointerException expected)
+ {
+ }
+ try
+ {
+ new StringToIntegerMap().get(new Object());
+ fail();
+ }
+ catch (ClassCastException expected)
+ {
+ }
+ }
+
+ public void testPutWithInvalidKey()
+ {
+ try
+ {
+ new StringToIntegerMap().put(null, "0");
+ fail();
+ }
+ catch (NullPointerException expected)
+ {
+ }
+ try
+ {
+ new StringToIntegerMap().put(new Object(), "0");
+ fail();
+ }
+ catch (ClassCastException expected)
+ {
+ }
+ }
+
+ public void testWithPutInvalidValue()
+ {
+ try
+ {
+ new StringToIntegerMap().put("", null);
+ fail();
+ }
+ catch (NullPointerException expected)
+ {
+ }
+ try
+ {
+ new StringToIntegerMap().put("", new Object());
+ fail();
+ }
+ catch (ClassCastException expected)
+ {
+ }
+ }
+
+ public void testEquals()
+ {
+ StringToIntegerMap left = new StringToIntegerMap();
+ left.delegate.put("abc", new Integer(0));
+ Map right = new HashMap();
+
+ //
+ assertFalse(left.equals(right));
+ assertFalse(right.equals(left));
+
+ //
+ right.put("abc", new Object());
+ assertFalse(left.equals(right));
+ assertFalse(right.equals(left));
+
+ //
+ right.put("abc", "abc");
+ assertFalse(left.equals(right));
+ assertFalse(right.equals(left));
+
+ //
+ right.put("abc", "0");
+ assertTrue(left.equals(right));
+ assertTrue(right.equals(left));
+
+ //
+ right.put("def", "1");
+ assertFalse(left.equals(right));
+ assertFalse(right.equals(left));
+
+ //
+ right.remove("def");
+ right.put(null, "0");
+ assertFalse(left.equals(right));
+ assertFalse(right.equals(left));
+
+ //
+ right.remove(null);
+ right.put("def", null);
+ assertFalse(left.equals(right));
+ assertFalse(right.equals(left));
+ }
+
+ public static class StringToIntegerMap extends TypedMap
+ {
+
+ /** . */
+ final Map delegate = new HashMap();
+
+ /** . */
+ boolean internalValueReturnsNull = false;
+
+ /** . */
+ boolean externalValueReturnsNull = false;
+
+ protected Map getDelegate()
+ {
+ return delegate;
+ }
+
+ protected void assertKeyValidity(Object key) throws ClassCastException
+ {
+ assertNotNull(key);
+ if (key instanceof String == false)
+ {
+ throw new ClassCastException();
+ }
+ }
+
+ protected Object getInternalValue(Object value) throws IllegalArgumentException,
ClassCastException
+ {
+ assertNotNull(value);
+ if (internalValueReturnsNull)
+ {
+ return null;
+ }
+ String s = (String)value;
+ try
+ {
+ return new Integer(s);
+ }
+ catch (NumberFormatException e)
+ {
+ IllegalArgumentException iae = new IllegalArgumentException();
+ iae.initCause(e);
+ throw iae;
+ }
+ }
+
+ protected Object getExternalValue(Object value)
+ {
+ assertNotNull(value);
+ if (externalValueReturnsNull)
+ {
+ return null;
+ }
+ Integer i = (Integer)value;
+ return i.toString();
+ }
+
+ protected boolean internalValueEquals(Object left, Object right)
+ {
+ assertNotNull(left);
+ assertNotNull(right);
+ Integer li = (Integer)left;
+ Integer ri = (Integer)right;
+ return li.intValue() == ri.intValue();
+ }
+ }
+
+}
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentRegistration.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentRegistration.java 2006-12-11
11:06:15 UTC (rev 5792)
+++
trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentRegistration.java 2006-12-11
16:08:27 UTC (rev 5793)
@@ -25,9 +25,12 @@
import org.jboss.portal.wsrp.producer.registration.api.Registration;
import org.jboss.portal.wsrp.producer.registration.api.Consumer;
import org.jboss.portal.wsrp.producer.registration.api.RegistrationStatus;
+import org.jboss.portal.common.util.TypedMap;
+import org.jboss.portal.common.NotYetImplemented;
import javax.xml.namespace.QName;
import java.util.Map;
+import java.util.Collections;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -47,6 +50,10 @@
private PersistentConsumer relatedConsumer;
+ // Wrapper
+
+ private Properties properties;
+
/**
* Hibernate constructor.
*/
@@ -56,6 +63,8 @@
this.persistentHandle = null;
this.relatedConsumer = null;
this.persistentStatus = null;
+ this.persistentProperties = null;
+ this.properties = new Properties();
}
PersistentRegistration(Map properties, RegistrationStatus status)
@@ -64,6 +73,11 @@
this.persistentHandle = null;
this.relatedConsumer = null;
this.persistentStatus = status;
+ this.persistentProperties = properties;
+ this.properties = new Properties();
+
+ // Perform properties validation
+ this.properties.validate();
}
// Hibernate
@@ -147,66 +161,185 @@
public Map getProperties()
{
- return null;
+ return Collections.unmodifiableMap(persistentProperties);
}
public void setPropertyValueFor(QName propertyName, Object value)
{
- //To change body of implemented methods use File | Settings | File Templates.
+ properties.setProperty(propertyName, value);
}
public void setPropertyValueFor(String propertyName, Object value)
{
- //To change body of implemented methods use File | Settings | File Templates.
+ properties.setProperty(propertyName, value);
}
- public boolean hasEqualProperties(Registration registration)
+ public void removeProperty(QName propertyName)
{
- return false; //To change body of implemented methods use File | Settings | File
Templates.
+ properties.removeProperty(propertyName);
}
- public boolean hasEqualProperties(Map properties)
+ public void removeProperty(String propertyName)
{
- return false; //To change body of implemented methods use File | Settings | File
Templates.
+ properties.removeProperty(propertyName);
}
- public RegistrationStatus getStatus()
+ public Object getPropertyValueFor(QName propertyName)
{
- return persistentStatus;
+ return properties.getProperty(propertyName);
}
- public void setStatus(RegistrationStatus status)
+ public Object getPropertyValueFor(String propertyName)
{
- this.persistentStatus = status;
+ return properties.getProperty(propertyName);
}
- public void clearAssociatedState()
+ public void updateProperties(Map registrationProperties)
{
- //To change body of implemented methods use File | Settings | File Templates.
+ properties.replace(registrationProperties);
}
- public void updateProperties(Map registrationProperties)
+ public boolean hasEqualProperties(Registration registration)
{
- //To change body of implemented methods use File | Settings | File Templates.
+ if (registration != null)
+ {
+ PersistentRegistration preg = (PersistentRegistration)registration;
+
+ //
+ return hasEqualProperties(preg.persistentProperties);
+ }
+
+ //
+ return false;
}
- public void removeProperty(QName propertyName)
+ public boolean hasEqualProperties(Map properties)
{
- //To change body of implemented methods use File | Settings | File Templates.
+ return this.properties.equals(properties);
}
- public void removeProperty(String propertyName)
+ public RegistrationStatus getStatus()
{
- //To change body of implemented methods use File | Settings | File Templates.
+ return persistentStatus;
}
- public Object getPropertyValueFor(QName propertyName)
+ public void setStatus(RegistrationStatus status)
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ this.persistentStatus = status;
}
- public Object getPropertyValueFor(String propertyName)
+ public void clearAssociatedState()
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ throw new NotYetImplemented();
}
+
+ // ***********
+
+ /**
+ * Implement registration properties semantics, mostly validation and equality.
+ */
+ public class Properties extends TypedMap
+ {
+
+ protected Map getDelegate()
+ {
+ return persistentProperties;
+ }
+
+ protected void assertKeyValidity(Object key) throws ClassCastException,
NullPointerException
+ {
+ if (key == null)
+ {
+ throw new NullPointerException();
+ }
+ if (key instanceof QName == false)
+ {
+ throw new ClassCastException();
+ }
+ }
+
+ protected Object getInternalValue(Object value) throws IllegalArgumentException,
ClassCastException, NullPointerException
+ {
+ if (value == null)
+ {
+ throw new NullPointerException();
+ }
+ if (value instanceof String == false)
+ {
+ throw new ClassCastException();
+ }
+ return value;
+ }
+
+ protected Object getExternalValue(Object value)
+ {
+ return value;
+ }
+
+ public void setProperty(String propertyName, Object value)
+ {
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException("No null property name
accepted");
+ }
+
+ //
+ setProperty(new QName(propertyName), value);
+ }
+
+ public void setProperty(QName propertyName, Object value)
+ {
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException("No null property name
accepted");
+ }
+
+ //
+ put(propertyName, value);
+ }
+
+ public void removeProperty(QName propertyName)
+ {
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException("No null property name
accepted");
+ }
+
+ //
+ remove(propertyName);
+ }
+
+ public void removeProperty(String propertyName)
+ {
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException("No null property name
accepted");
+ }
+
+ //
+ removeProperty(new QName(propertyName));
+ }
+
+ public Object getProperty(QName propertyName)
+ {
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException("No null property name
accepted");
+ }
+
+ //
+ return get(propertyName);
+ }
+
+ public Object getProperty(String propertyName)
+ {
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException("No null property name
accepted");
+ }
+
+ //
+ return getProperty(new QName(propertyName));
+ }
+ }
}
Modified: trunk/portlet/src/main/org/jboss/portal/portlet/Parameters.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/Parameters.java 2006-12-11 11:06:15
UTC (rev 5792)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/Parameters.java 2006-12-11 16:08:27
UTC (rev 5793)
@@ -25,7 +25,6 @@
import org.jboss.portal.common.util.ParameterMap;
import java.io.Serializable;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -80,6 +79,12 @@
*/
public Parameters(Map parameterMap) throws NullPointerException, ClassCastException,
IllegalArgumentException
{
+ if (parameterMap == null)
+ {
+ throw new IllegalArgumentException("No null map accepted");
+ }
+
+ //
this.map = new HashMap();
//
@@ -159,32 +164,12 @@
*/
public void append(Map params) throws ClassCastException, NullPointerException,
IllegalArgumentException
{
- checkValidity(params);
+ validate(params, false);
//
internalAppend(params);
}
- /**
- * Replace all the existing parameters with the new ones. The argument validation is
performed before the state is
- * updated.
- *
- * @param params the parameters to replace
- * @throws NullPointerException if the map contains a null key or a null value
- * @throws IllegalArgumentException if the map is null or it contains a value with a
zero length array or a null
- * element in the array
- * @throws ClassCastException if the map contains a key that is not a string or
a value that is not a string
- * array
- */
- public void replace(Map params)
- {
- checkValidity(params);
-
- //
- clear();
- putAll(params);
- }
-
/** Append actual implementation. */
private void internalAppend(Map params)
{
@@ -213,47 +198,6 @@
}
}
- /** Compare to parameters objects. */
- public boolean equals(Object o)
- {
- if (o == this)
- {
- return true;
- }
- if (o instanceof Parameters)
- {
- Parameters that = (Parameters)o;
- if (that.map == null)
- {
- return map == null || map.size() == 0;
- }
- else if (map == null)
- {
- return that.map.size() == 0;
- }
- else if (that.map.size() != map.size())
- {
- return false;
- }
- for (Iterator i = that.map.entrySet().iterator(); i.hasNext();)
- {
- Map.Entry entry = (Map.Entry)i.next();
- String[] values2 = (String[])map.get(entry.getKey());
- if (values2 == null)
- {
- return false;
- }
- String[] values1 = (String[])entry.getValue();
- if (!Arrays.equals(values1, values2))
- {
- return false;
- }
- }
- return true;
- }
- return false;
- }
-
public String toString()
{
StringBuffer buffer = new StringBuffer("Parameters[");
@@ -278,18 +222,4 @@
buffer.append(']');
return buffer.toString();
}
-
- protected void checkValidity(Map that) throws IllegalArgumentException
- {
- if (that == null)
- {
- throw new IllegalArgumentException("Map cannot be null");
- }
- for (Iterator i = that.entrySet().iterator(); i.hasNext();)
- {
- Entry entry = (Entry)i.next();
- assertKeyValidity(entry.getKey());
- getInternalValue(entry.getValue());
- }
- }
}
Modified: trunk/portlet/src/main/org/jboss/portal/test/portlet/ParametersTestCase.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/test/portlet/ParametersTestCase.java 2006-12-11
11:06:15 UTC (rev 5792)
+++
trunk/portlet/src/main/org/jboss/portal/test/portlet/ParametersTestCase.java 2006-12-11
16:08:27 UTC (rev 5793)
@@ -173,18 +173,6 @@
}
}
- public void testSetValuesWithNullParameters()
- {
- try
- {
- param.replace((Parameters)null);
- fail("Expected IllegalArgumentException");
- }
- catch (IllegalArgumentException e)
- {
- }
- }
-
public void testReplaceWithParameters()
{
Parameters other = new Parameters();
@@ -199,7 +187,7 @@
{
try
{
- new Parameters((Parameters)null);
+ new Parameters(null);
fail("Expected IllegalArgumentException");
}
catch (IllegalArgumentException e)
@@ -223,10 +211,10 @@
{
try
{
- param.replace((Map)null);
- fail("Expected IllegalArgumentException");
+ param.replace(null);
+ fail("Expected NullPointerException");
}
- catch (IllegalArgumentException e)
+ catch (NullPointerException e)
{
}
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/Registration.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/Registration.java 2006-12-11
11:06:15 UTC (rev 5792)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/Registration.java 2006-12-11
16:08:27 UTC (rev 5793)
@@ -23,6 +23,8 @@
package org.jboss.portal.wsrp.producer.registration.api;
+import org.jboss.portal.common.util.TypedMap;
+
import javax.xml.namespace.QName;
import java.util.Map;
@@ -72,7 +74,7 @@
*/
Map getProperties();
- void setPropertyValueFor(QName propertyName, Object value);
+ void setPropertyValueFor(QName propertyName, Object value) throws
IllegalArgumentException;
void setPropertyValueFor(String propertyName, Object value);