You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by cr...@apache.org on 2002/01/06 01:47:06 UTC

cvs commit: jakarta-commons/beanutils/src/java/org/apache/commons/beanutils BasicDynaBean.java BasicDynaClass.java ConversionException.java DynaBean.java DynaClass.java

craigmcc    02/01/05 16:47:06

  Modified:    beanutils/src/java/org/apache/commons/beanutils
                        BasicDynaBean.java BasicDynaClass.java
                        ConversionException.java DynaBean.java
                        DynaClass.java
  Log:
  Refine the API contracts for DynaBean and DynaClass.  Specify *all* of the
  exception conditions that might be thrown.
  
  Add DynaBean.contains() and DynaBean.remove() support for mapped properties.
  These might be considered superfluous, because you can always get the Map
  value and perform the operations directly, but they are convenient.
  
  In the BasicDynaBean.get(String name) method, attempt to mimic the way Java
  works on primitive properties that have not been assigned any value yet,
  instead of returning null.
  
  Strip the BasicDynaBean and BasicDynaClass implementations down to the
  bare minimum functionality.  Anything fancier can be built on top of these.
  
  Next step is to write some unit tests (equivalent to those in
  PropertyUtilsTestCase) to see if these things actually work yet.
  
  Revision  Changes    Path
  1.2       +183 -129  jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BasicDynaBean.java
  
  Index: BasicDynaBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BasicDynaBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicDynaBean.java	28 Dec 2001 03:59:41 -0000	1.1
  +++ BasicDynaBean.java	6 Jan 2002 00:47:06 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BasicDynaBean.java,v 1.1 2001/12/28 03:59:41 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/12/28 03:59:41 $
  + * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BasicDynaBean.java,v 1.2 2002/01/06 00:47:06 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/01/06 00:47:06 $
    *
    * ====================================================================
    *
  @@ -63,7 +63,10 @@
   package org.apache.commons.beanutils;
   
   
  +import java.lang.reflect.Array;
   import java.util.HashMap;
  +import java.util.List;
  +import java.util.Map;
   
   
   /**
  @@ -74,7 +77,7 @@
    * accessed from multiple threads simultaneously need to be synchronized.</p>
    *
    * @author Craig McClanahan
  - * @version $Revision: 1.1 $ $Date: 2001/12/28 03:59:41 $
  + * @version $Revision: 1.2 $ $Date: 2002/01/06 00:47:06 $
    */
   
   public class BasicDynaBean implements DynaBean {
  @@ -108,32 +111,43 @@
   
   
       /**
  -     * Have any properties of this instance been modified since the last time
  -     * that <code>setDynaModified(false)</code> was called?
  +     * The set of property values for this DynaBean, keyed by property name.
        */
  -    protected boolean modified = false;
  +    protected HashMap values = new HashMap();
   
   
  -    /**
  -     * Has this DynaBean instance been declared read only?
  -     */
  -    protected boolean readOnly = false;
  +     // ------------------------------------------------------ DynaBean Methods
   
   
       /**
  -     * The set of property values for this DynaBean, keyed by property name.
  +     * Does the specified mapped property contain a value for the specified
  +     * key value?
  +     *
  +     * @param name Name of the property to check
  +     * @param key Name of the key to check
  +     *
  +     * @exception IllegalArgumentException if there is no property
  +     *  of the specified name
        */
  -    protected HashMap values = new HashMap();
  +    public boolean contains(String name, String key) {
   
  +        DynaProperty descriptor = getPropertyDescriptor(name);
  +        Object value = values.get(name);
  +        if (value == null) {
  +            throw new NullPointerException
  +                ("No mapped value for '" + name + "(" + key + ")'");
  +        } else if (value instanceof Map) {
  +            return (((Map) value).containsKey(key));
  +        } else {
  +            throw new IllegalArgumentException
  +                ("Non-mapped property for '" + name + "(" + key + ")'");
  +        }
   
  -     // ------------------------------------------------------ DynaBean Methods
  +    }
   
   
       /**
  -     * Return the value of a simple property with the specified name.  A
  -     * <code>null</code> return value means that either the property does
  -     * not exist, or that the property exists with a null value.  Use the
  -     * <code>contains()</code> method to distinguish these cases.
  +     * Return the value of a simple property with the specified name.
        *
        * @param name Name of the property whose value is to be retrieved
        *
  @@ -142,20 +156,44 @@
        */
       public Object get(String name) {
   
  -        if (!values.containsKey(name))
  -            throw new IllegalArgumentException
  -                ("No property " + name + " exists");
  -
  -        return (values.get(name));
  +        // Return any non-null value for the specified property
  +        Object value = values.get(name);
  +        if (value != null) {
  +            return (value);
  +        } 
  +
  +        // Return a null value for a non-primitive property
  +        Class type = getPropertyDescriptor(name).getType();
  +        if (!type.isPrimitive()) {
  +            return (value);
  +        }
  +
  +        // Manufacture default values for primitive properties
  +        if (type == Boolean.TYPE) {
  +            return (Boolean.FALSE);
  +        } else if (type == Byte.TYPE) {
  +            return (new Byte((byte) 0));
  +        } else if (type == Character.TYPE) {
  +            return (new Character((char) 0));
  +        } else if (type == Double.TYPE) {
  +            return (new Double((double) 0.0));
  +        } else if (type == Float.TYPE) {
  +            return (new Float((float) 0.0));
  +        } else if (type == Integer.TYPE) {
  +            return (new Integer((int) 0));
  +        } else if (type == Long.TYPE) {
  +            return (new Long((int) 0));
  +        } else if (type == Short.TYPE) {
  +            return (new Short((short) 0));
  +        } else {
  +            return (null);
  +        }
   
       }
   
   
       /**
  -     * Return the value of an indexed property with the specified name.  A
  -     * <code>null</code> return value means that either the property does
  -     * not exist, or that the property exists with a null value.  Use the
  -     * <code>contains()</code> method to distinguish these cases.
  +     * Return the value of an indexed property with the specified name.
        *
        * @param name Name of the property whose value is to be retrieved
        * @param index Index of the value to be retrieved
  @@ -164,23 +202,33 @@
        *  of the specified name
        * @exception IllegalArgumentException if the specified property
        *  exists, but is not indexed
  +     * @exception IndexOutOfBoundsException if the specified index
  +     *  is outside the range of the underlying property
  +     * @exception NullPointerException if no array or List has been
  +     *  initialized for this property
        */
       public Object get(String name, int index) {
   
  -        if (!values.containsKey(name))
  +        DynaProperty descriptor = getPropertyDescriptor(name);
  +        Object value = values.get(name);
  +        if (value == null) {
  +            throw new NullPointerException
  +                ("No indexed value for '" + name + "[" + index + "]'");
  +        } else if (value.getClass().isArray()) {
  +            return (Array.get(value, index));
  +        } else if (value instanceof List) {
  +            return ((List) value).get(index);
  +        } else {
               throw new IllegalArgumentException
  -                ("No property " + name + " exists");
  -
  -        return (null); // FIXME - get(String,int)
  +                ("Non-indexed property for '" + name + "[" + index + "]'");
  +        }
   
       }
   
   
       /**
  -     * Return the value of a mapped property with the specified name.  A
  -     * <code>null</code> return value means that either the property does
  -     * not exist, or that the property exists with a null value.  Use the
  -     * <code>contains()</code> method to distinguish these cases.
  +     * Return the value of a mapped property with the specified name,
  +     * or <code>null</code> if there is no value for the specified key.
        *
        * @param name Name of the property whose value is to be retrieved
        * @param key Key of the value to be retrieved
  @@ -192,11 +240,17 @@
        */
       public Object get(String name, String key) {
   
  -        if (!values.containsKey(name))
  +        DynaProperty descriptor = getPropertyDescriptor(name);
  +        Object value = values.get(name);
  +        if (value == null) {
  +            throw new NullPointerException
  +                ("No mapped value for '" + name + "(" + key + ")'");
  +        } else if (value instanceof Map) {
  +            return (((Map) value).get(key));
  +        } else {
               throw new IllegalArgumentException
  -                ("No property " + name + " exists");
  -
  -        return (null); // FIXME - get(String, String)
  +                ("Non-mapped property for '" + name + "(" + key + ")'");
  +        }
   
       }
   
  @@ -213,12 +267,35 @@
   
   
       /**
  -     * Set the value of a simple property with the specified name.  A null
  -     * value is allowed unless the underlying property type is a primitive.
  -     * If there is a Converter specified for our associated DynaClass, and
  -     * if the specified property is restricted to a particular data type,
  -     * the Converter will be used as necessary to convert the input value to
  -     * an object of the specified type.
  +     * Remove any existing value for the specified key on the
  +     * specified mapped property.
  +     *
  +     * @param name Name of the property for which a value is to
  +     *  be removed
  +     * @param key Key of the value to be removed
  +     *
  +     * @exception IllegalArgumentException if there is no property
  +     *  of the specified name
  +     */
  +    public void remove(String name, String key) {
  +
  +        DynaProperty descriptor = getPropertyDescriptor(name);
  +        Object value = values.get(name);
  +        if (value == null) {
  +            throw new NullPointerException
  +                ("No mapped value for '" + name + "(" + key + ")'");
  +        } else if (value instanceof Map) {
  +            ((Map) value).remove(key);
  +        } else {
  +            throw new IllegalArgumentException
  +                ("Non-mapped property for '" + name + "(" + key + ")'");
  +        }
  +
  +    }
  +
  +
  +    /**
  +     * Set the value of a simple property with the specified name.
        *
        * @param name Name of the property whose value is to be set
        * @param value Value to which this property is to be set
  @@ -227,38 +304,30 @@
        *  converted to the type required for this property
        * @exception IllegalArgumentException if there is no property
        *  of the specified name
  -     * @exception IllegalStateException if the specified property exists
  -     *  and is writeable, but this bean instance has been marked read only
  +     * @exception NullPointerException if an attempt is made to set a
  +     *  primitive property to null
        */
       public void set(String name, Object value) {
   
  -        DynaProperty descriptor = dynaClass.getPropertyDescriptor(name);
  -        if (descriptor == null)
  -            throw new IllegalArgumentException
  -                ("No property " + name + " exists");
  -        if (value != null)
  -            if (!descriptor.getType().isAssignableFrom(value.getClass()))
  -                throw new IllegalArgumentException
  -                    ("Cannot assign value of type " +
  -                     value.getClass().getName() +
  -                     " to property " + name);
  -        if (readOnly)
  -            throw new IllegalStateException
  -                ("This instance is read-only");
  -
  -        this.modified = true;
  +        DynaProperty descriptor = getPropertyDescriptor(name);
  +        if (value == null) {
  +            if (descriptor.getType().isPrimitive()) {
  +                throw new NullPointerException
  +                    ("Primitive value for '" + name + "'");
  +            }
  +        } else if (!descriptor.getType().isAssignableFrom(value.getClass())) {
  +            throw new ConversionException
  +                ("Cannot assign value of type '" +
  +                 value.getClass().getName() +
  +                 "' to property '" + name + "'");
  +        }
           values.put(name, value);
   
       }
   
   
       /**
  -     * Set the value of an indexed property with the specified name.  A null
  -     * value is allowed unless the underlying property type is a primitive.
  -     * If there is a Converter specified for our associated DynaClass, and
  -     * if the specified property is restricted to a particular data type,
  -     * the Converter will be used as necessary to convert the input value to
  -     * an object of the specified type.
  +     * Set the value of an indexed property with the specified name.
        *
        * @param name Name of the property whose value is to be set
        * @param index Index of the property to be set
  @@ -266,29 +335,38 @@
        *
        * @exception ConversionException if the specified value cannot be
        *  converted to the type required for this property
  -     * @exception IllegalArgumentException if the specified value cannot
  -     *  be converted to the required property type
  +     * @exception IllegalArgumentException if there is no property
  +     *  of the specified name
        * @exception IllegalArgumentException if the specified property
        *  exists, but is not indexed
  -     * @exception IllegalStateException if the specified property exists,
  -     *  but has been defined as read-only
  -     * @exception IllegalStateException if the specified property exists
  -     *  and is writeable, but this bean instance has been marked read only
  +     * @exception IndexOutOfBoundsException if the specified index
  +     *  is outside the range of the underlying property
        */
       public void set(String name, int index, Object value) {
   
  -        ; // FIXME - set(String, int, Object)
  +        DynaProperty descriptor = getPropertyDescriptor(name);
  +        Object prop = values.get(name);
  +        if (prop == null) {
  +            throw new NullPointerException
  +                ("No indexed value for '" + name + "[" + index + "]'");
  +        } else if (prop.getClass().isArray()) {
  +            Array.set(prop, index, value);
  +        } else if (prop instanceof List) {
  +            try {
  +                ((List) prop).set(index, value);
  +            } catch (ClassCastException e) {
  +                throw new ConversionException(e.getMessage());
  +            }
  +        } else {
  +            throw new IllegalArgumentException
  +                ("Non-indexed property for '" + name + "[" + index + "]'");
  +        }
   
       }
   
   
       /**
  -     * Set the value of a mapped property with the specified name.  A null
  -     * value is allowed unless the underlying property type is a primitive.
  -     * If there is a Converter specified for our associated DynaClass, and
  -     * if the specified property is restricted to a particular data type,
  -     * the Converter will be used as necessary to convert the input value to
  -     * an object of the specified type.
  +     * Set the value of a mapped property with the specified name.
        *
        * @param name Name of the property whose value is to be set
        * @param key Key of the property to be set
  @@ -296,71 +374,47 @@
        *
        * @exception ConversionException if the specified value cannot be
        *  converted to the type required for this property
  -     * @exception IllegalArgumentException if the specified value cannot
  -     *  be converted to the required property type
  +     * @exception IllegalArgumentException if there is no property
  +     *  of the specified name
        * @exception IllegalArgumentException if the specified property
        *  exists, but is not mapped
  -     * @exception IllegalStateException if the specified property exists,
  -     *  but has been defined as read-only
  -     * @exception IllegalStateException if the specified property exists
  -     *  and is writeable, but this bean instance has been marked read only
        */
       public void set(String name, String key, Object value) {
   
  -        ; // FIXME - set(String, String, Object)
  -
  -    }
  -
  -
  -    // --------------------------------------------------------- Public Methods
  -
  -
  -    /**
  -     * Return the value of the "dynamic modified" property, which will be
  -     * <code>true</code> if any dynamic property has been the subject of a
  -     * <code>set()</code> method call (even if the actual value did not
  -     * change) since the last time that <code>setDynaModified(false)</code>
  -     * was called for this instance.
  -     */
  -    public boolean isModified() {
  -
  -        return (this.modified);
  +        DynaProperty descriptor = getPropertyDescriptor(name);
  +        Object prop = values.get(name);
  +        if (prop == null) {
  +            throw new NullPointerException
  +                ("No mapped value for '" + name + "(" + key + ")'");
  +        } else if (prop instanceof Map) {
  +            ((Map) prop).put(key, value);
  +        } else {
  +            throw new IllegalArgumentException
  +                ("Non-mapped property for '" + name + "(" + key + ")'");
  +        }
   
       }
   
   
  -    /**
  -     * Return the value of the "dynamic read only" property, which will be
  -     * <code>true</code> if <code>set()</code> method calls against this
  -     * property will fail because this bean has been marked read-only.
  -     */
  -    public boolean isReadOnly() {
  -
  -        return (this.readOnly);
  -
  -    }
  +    // ------------------------------------------------------ Protected Methods
   
   
       /**
  -     * Set the value of the "dynamic modified" property.
  +     * Return the property descriptor for the specified property name.
        *
  -     * @param modified The new dynamic modified property setting
  -     */
  -    public void setModified(boolean modified) {
  -
  -        this.modified = modified;
  -
  -    }
  -
  -
  -    /**
  -     * Set the value of the "dynamic read only" property.
  +     * @param name Name of the property for which to retrieve the descriptor
        *
  -     * @param readOnly The new dynamic read only property setting
  +     * @exception IllegalArgumentException if this is not a valid property
  +     *  name for our DynaClass
        */
  -    public void setReadOnly(boolean readOnly) {
  +    protected DynaProperty getPropertyDescriptor(String name) {
   
  -        this.readOnly = readOnly;
  +        DynaProperty descriptor = getDynaClass().getPropertyDescriptor(name);
  +        if (descriptor == null) {
  +            throw new IllegalArgumentException
  +                ("Invalid property name '" + name + "'");
  +        }
  +        return (descriptor);
   
       }
   
  
  
  
  1.2       +33 -13    jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BasicDynaClass.java
  
  Index: BasicDynaClass.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BasicDynaClass.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicDynaClass.java	28 Dec 2001 03:59:41 -0000	1.1
  +++ BasicDynaClass.java	6 Jan 2002 00:47:06 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BasicDynaClass.java,v 1.1 2001/12/28 03:59:41 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/12/28 03:59:41 $
  + * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BasicDynaClass.java,v 1.2 2002/01/06 00:47:06 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/01/06 00:47:06 $
    *
    * ====================================================================
    *
  @@ -66,6 +66,7 @@
   import java.beans.PropertyDescriptor;
   import java.lang.reflect.Constructor;
   import java.lang.reflect.InvocationTargetException;
  +import java.util.HashMap;
   
   
   /**
  @@ -77,7 +78,7 @@
    * used to associate the DynaBean instance with this DynaClass.</p>
    *
    * @author Craig McClanahan
  - * @version $Revision: 1.1 $ $Date: 2001/12/28 03:59:41 $
  + * @version $Revision: 1.2 $ $Date: 2002/01/06 00:47:06 $
    */
   
   public class BasicDynaClass implements DynaClass {
  @@ -125,7 +126,7 @@
           if (dynaBeanClass != null)
               setDynaBeanClass(dynaBeanClass);
           if (properties != null)
  -            this.properties = properties;
  +            setProperties(properties);
   
       }
   
  @@ -158,7 +159,7 @@
        * The <code>DynaBean</code> implementation class we will use for
        * creating new instances.
        */
  -    protected Class dynaBeanClass = null;  // BasicDynaBean.class
  +    protected Class dynaBeanClass = BasicDynaBean.class;
   
   
       /**
  @@ -173,6 +174,14 @@
       protected DynaProperty properties[] = new DynaProperty[0];
   
   
  +    /**
  +     * The set of dynamic properties that are part of this DynaClass,
  +     * keyed by the property name.  Individual descriptor instances will
  +     * be the same instances as those in the <code>properties</code> list.
  +     */
  +    protected HashMap propertiesMap = new HashMap();
  +
  +
       // ------------------------------------------------------ DynaClass Methods
   
   
  @@ -210,12 +219,7 @@
        */
       public DynaProperty getPropertyDescriptor(String name) {
   
  -        // FIXME - HashMap for better performance?
  -        for (int i = 0; i < properties.length; i++) {
  -            if (name.equals(properties[i].getName()))
  -                return (properties[i]);
  -        }
  -        return (null);
  +        return ((DynaProperty) propertiesMap.get(name));
   
       }
   
  @@ -237,8 +241,8 @@
   
   
       /**
  -     * Instantiate and return a new DynaBean instance, using the implementation
  -     * class specified by the <code>dynaBeanClass</code> property.
  +     * Instantiate and return a new DynaBean instance, associated
  +     * with this DynaClass.
        *
        * @exception IllegalAccessException if the Class or the appropriate
        *  constructor is not accessible
  @@ -293,6 +297,22 @@
                    " does not have an appropriate constructor");
           }
           this.dynaBeanClass = dynaBeanClass;
  +
  +    }
  +
  +
  +    /**
  +     * Set the list of dynamic properties supported by this DynaClass.
  +     *
  +     * @param properties List of dynamic properties to be supported
  +     */
  +    protected void setProperties(DynaProperty properties[]) {
  +
  +        this.properties = properties;
  +        propertiesMap.clear();
  +        for (int i = 0; i < properties.length; i++) {
  +            propertiesMap.put(properties[i].getName(), properties[i]);
  +        }
   
       }
   
  
  
  
  1.2       +16 -4     jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/ConversionException.java
  
  Index: ConversionException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/ConversionException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConversionException.java	24 Dec 2001 23:27:04 -0000	1.1
  +++ ConversionException.java	6 Jan 2002 00:47:06 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/ConversionException.java,v 1.1 2001/12/24 23:27:04 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/12/24 23:27:04 $
  + * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/ConversionException.java,v 1.2 2002/01/06 00:47:06 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/01/06 00:47:06 $
    *
    * ====================================================================
    *
  @@ -74,7 +74,19 @@
   public class ConversionException extends RuntimeException {
   
   
  -    // No additional functionality is required
  +    // ----------------------------------------------------------- Constructors
  +
  +
  +    /**
  +     * Construct a new exception with the specified message.
  +     *
  +     * @param message The message describing this exception
  +     */
  +    public ConversionException(String message) {
  +
  +        super(message);
  +
  +    }
   
   
   }
  
  
  
  1.5       +59 -46    jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaBean.java
  
  Index: DynaBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaBean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DynaBean.java	28 Dec 2001 03:59:41 -0000	1.4
  +++ DynaBean.java	6 Jan 2002 00:47:06 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaBean.java,v 1.4 2001/12/28 03:59:41 craigmcc Exp $
  - * $Revision: 1.4 $
  - * $Date: 2001/12/28 03:59:41 $
  + * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaBean.java,v 1.5 2002/01/06 00:47:06 craigmcc Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/01/06 00:47:06 $
    *
    * ====================================================================
    *
  @@ -72,47 +72,63 @@
    *
    * @author Craig McClanahan
    * @author Paulo Gaspar
  - * @version $Revision: 1.4 $ $Date: 2001/12/28 03:59:41 $
  + * @version $Revision: 1.5 $ $Date: 2002/01/06 00:47:06 $
    */
   
   public interface DynaBean {
   
   
       /**
  -     * Return the value of a simple property with the specified name.  A
  -     * <code>null</code> return value means that either the property does
  -     * not exist, or that the property exists with a null value.  Use the
  -     * <code>contains()</code> method to distinguish these cases.
  +     * Does the specified mapped property contain a value for the specified
  +     * key value?
  +     *
  +     * @param name Name of the property to check
  +     * @param key Name of the key to check
  +     *
  +     * @exception IllegalArgumentException if there is no property
  +     *  of the specified name
  +     */
  +    public boolean contains(String name, String key);
  +
  +
  +    /**
  +     * Return the value of a simple property with the specified name.
        *
        * @param name Name of the property whose value is to be retrieved
  +     *
  +     * @exception IllegalArgumentException if there is no property
  +     *  of the specified name
        */
       public Object get(String name);
   
   
       /**
  -     * Return the value of an indexed property with the specified name.  A
  -     * <code>null</code> return value means that either the property does
  -     * not exist, or that the property exists with a null value.  Use the
  -     * <code>contains()</code> method to distinguish these cases.
  +     * Return the value of an indexed property with the specified name.
        *
        * @param name Name of the property whose value is to be retrieved
        * @param index Index of the value to be retrieved
        *
  +     * @exception IllegalArgumentException if there is no property
  +     *  of the specified name
        * @exception IllegalArgumentException if the specified property
        *  exists, but is not indexed
  +     * @exception IndexOutOfBoundsException if the specified index
  +     *  is outside the range of the underlying property
  +     * @exception NullPointerException if no array or List has been
  +     *  initialized for this property
        */
       public Object get(String name, int index);
   
   
       /**
  -     * Return the value of a mapped property with the specified name.  A
  -     * <code>null</code> return value means that either the property does
  -     * not exist, or that the property exists with a null value.  Use the
  -     * <code>contains()</code> method to distinguish these cases.
  +     * Return the value of a mapped property with the specified name,
  +     * or <code>null</code> if there is no value for the specified key.
        *
        * @param name Name of the property whose value is to be retrieved
        * @param key Key of the value to be retrieved
        *
  +     * @exception IllegalArgumentException if there is no property
  +     *  of the specified name
        * @exception IllegalArgumentException if the specified property
        *  exists, but is not mapped
        */
  @@ -127,29 +143,37 @@
   
   
       /**
  -     * Set the value of a simple property with the specified name.  A null
  -     * value is allowed unless the underlying property type is a primitive.
  -     * If there is a Converter specified for our associated DynaClass, and
  -     * if the specified property is restricted to a particular data type,
  -     * the Converter will be used as necessary to convert the input value to
  -     * an object of the specified type.
  +     * Remove any existing value for the specified key on the
  +     * specified mapped property.
  +     *
  +     * @param name Name of the property for which a value is to
  +     *  be removed
  +     * @param key Key of the value to be removed
  +     *
  +     * @exception IllegalArgumentException if there is no property
  +     *  of the specified name
  +     */
  +    public void remove(String name, String key);
  +
  +
  +    /**
  +     * Set the value of a simple property with the specified name.
        *
        * @param name Name of the property whose value is to be set
        * @param value Value to which this property is to be set
        *
        * @exception ConversionException if the specified value cannot be
        *  converted to the type required for this property
  +     * @exception IllegalArgumentException if there is no property
  +     *  of the specified name
  +     * @exception NullPointerException if an attempt is made to set a
  +     *  primitive property to null
        */
       public void set(String name, Object value);
   
   
       /**
  -     * Set the value of an indexed property with the specified name.  A null
  -     * value is allowed unless the underlying property type is a primitive.
  -     * If there is a Converter specified for our associated DynaClass, and
  -     * if the specified property is restricted to a particular data type,
  -     * the Converter will be used as necessary to convert the input value to
  -     * an object of the specified type.
  +     * Set the value of an indexed property with the specified name.
        *
        * @param name Name of the property whose value is to be set
        * @param index Index of the property to be set
  @@ -157,25 +181,18 @@
        *
        * @exception ConversionException if the specified value cannot be
        *  converted to the type required for this property
  -     * @exception IllegalArgumentException if the specified value cannot
  -     *  be converted to the required property type
  +     * @exception IllegalArgumentException if there is no property
  +     *  of the specified name
        * @exception IllegalArgumentException if the specified property
        *  exists, but is not indexed
  -     * @exception IllegalStateException if the specified property exists,
  -     *  but has been defined as read-only
  -     * @exception IllegalStateException if the specified property exists
  -     *  and is writeable, but this bean instance has been marked read only
  +     * @exception IndexOutOfBoundsException if the specified index
  +     *  is outside the range of the underlying property
        */
       public void set(String name, int index, Object value);
   
   
       /**
  -     * Set the value of a mapped property with the specified name.  A null
  -     * value is allowed unless the underlying property type is a primitive.
  -     * If there is a Converter specified for our associated DynaClass, and
  -     * if the specified property is restricted to a particular data type,
  -     * the Converter will be used as necessary to convert the input value to
  -     * an object of the specified type.
  +     * Set the value of a mapped property with the specified name.
        *
        * @param name Name of the property whose value is to be set
        * @param key Key of the property to be set
  @@ -183,14 +200,10 @@
        *
        * @exception ConversionException if the specified value cannot be
        *  converted to the type required for this property
  -     * @exception IllegalArgumentException if the specified value cannot
  -     *  be converted to the required property type
  +     * @exception IllegalArgumentException if there is no property
  +     *  of the specified name
        * @exception IllegalArgumentException if the specified property
        *  exists, but is not mapped
  -     * @exception IllegalStateException if the specified property exists,
  -     *  but has been defined as read-only
  -     * @exception IllegalStateException if the specified property exists
  -     *  and is writeable, but this bean instance has been marked read only
        */
       public void set(String name, String key, Object value);
   
  
  
  
  1.5       +6 -6      jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaClass.java
  
  Index: DynaClass.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaClass.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DynaClass.java	28 Dec 2001 03:59:41 -0000	1.4
  +++ DynaClass.java	6 Jan 2002 00:47:06 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaClass.java,v 1.4 2001/12/28 03:59:41 craigmcc Exp $
  - * $Revision: 1.4 $
  - * $Date: 2001/12/28 03:59:41 $
  + * $Header: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaClass.java,v 1.5 2002/01/06 00:47:06 craigmcc Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/01/06 00:47:06 $
    *
    * ====================================================================
    *
  @@ -76,7 +76,7 @@
    * @author Craig McClanahan
    * @author Michael Smith
    * @author Paulo Gaspar
  - * @version $Revision: 1.4 $ $Date: 2001/12/28 03:59:41 $
  + * @version $Revision: 1.5 $ $Date: 2002/01/06 00:47:06 $
    */
   
   public interface DynaClass {
  @@ -114,8 +114,8 @@
   
   
       /**
  -     * Instantiate and return a new DynaBean instance, using the implementation
  -     * class specified by the <code>dynaBeanClass</code> property.
  +     * Instantiate and return a new DynaBean instance, associated
  +     * with this DynaClass.
        *
        * @exception IllegalAccessException if the Class or the appropriate
        *  constructor is not accessible
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>