craigmcc 01/12/24 15:27:04
Added: beanutils/src/java/org/apache/commons/beanutils
ConversionException.java Converter.java
DynaBean.java DynaClass.java
Log:
Add proposed interface and class definitions that correspond to the
COMMONS-DEV mail message "[Design Discussion] DynaBeans - Round 2".
Revision Changes Path
1.1
jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/ConversionException.java
Index: ConversionException.java
===================================================================
/*
* $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 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.beanutils;
/**
* <p>A <strong>ConversionException</strong> indicates that a call to
* <code>Converter.convert()</code> has failed to complete successfully.
*
* @author Craig McClanahan
* @author Paulo Gaspar
*/
public class ConversionException extends RuntimeException {
// No additional functionality is required
}
1.1
jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/Converter.java
Index: Converter.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/Converter.java,v
1.1 2001/12/24 23:27:04 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2001/12/24 23:27:04 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.beanutils;
/**
* <p>General purpose data type converter that can be registered and used
* within the BeanUtils package to manage the conversion of objects from
* one type to another.
*
* @author Craig McClanahan
* @author Paulo Gaspar
* @version $Revision: 1.1 $ $Date: 2001/12/24 23:27:04 $
*/
public interface Converter {
/**
* Convert the specified input object into an output object of the
* specified type.
*
* @param type Data type to which this value should be converted
* @param value The input value to be converted
*
* @exception ConversionException if conversion cannot be performed
* successfully
*/
public Object convert(Class type, Object value);
}
1.1
jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaBean.java
Index: DynaBean.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaBean.java,v
1.1 2001/12/24 23:27:04 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2001/12/24 23:27:04 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.beanutils;
/**
* <p>A <strong>DynaBean</strong> is a Java object that supports properties
* whose names and data types, as well as values, may be dynamically modified.
* To the maximum degree feasible, other components of the BeanUtils package
* will recognize such beans and treat them as standard JavaBeans for the
* purpose of retrieving and setting property values.</p>
*
* @author Craig McClanahan
* @version $Revision: 1.1 $ $Date: 2001/12/24 23:27:04 $
*/
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.
*
* @param name Name of the property whose value is to be retrieved
*
* @exception IllegalStateException if the specified property
* exists, but has been defined as write-only
*/
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.
*
* @param name Name of the property whose value is to be retrieved
* @param index Index of the value to be retrieved
*
* @exception IllegalArgumentException if the specified property
* exists, but is not indexed
* @exception IllegalStateException if the specified property
* exists, but has been defined as write-only
*/
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.
*
* @param name Name of the property whose value is to be retrieved
* @param key Key of the value to be retrieved
*
* @exception IllegalArgumentException if the specified property
* exists, but is not mapped
* @exception IllegalStateException if the specified property
* exists, but has been defined as write-only
*/
public Object get(String name, String key);
/**
* Return the <code>DynaClass</code> instance that describes the set of
* properties available for this DynaBean.
*/
public DynaClass getDynaClass();
/**
* 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.
*
* @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 the specified value cannot
* be converted to the required property type
* @exception IllegalStateException if the specified property exists,
* but has been defined as read-only
*/
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.
*
* @param name Name of the property whose value is to be set
* @param index Index of the property 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 the specified value cannot
* be converted to the required property type
* @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
*/
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.
*
* @param name Name of the property whose value is to be set
* @param key Key of the property 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 the specified value cannot
* be converted to the required property type
* @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
*/
public void set(String name, String key, Object value);
}
1.1
jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaClass.java
Index: DynaClass.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaClass.java,v
1.1 2001/12/24 23:27:04 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2001/12/24 23:27:04 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.beanutils;
import java.beans.PropertyDescriptor;
/**
* <p>A <strong>DynaClass</strong> is a simulation of the functionality of
* <code>java.lang.Class</code> for classes implementing the
* <code>DynaBean</code> interface. DynaBean instances that share the same
* DynaClass all have the same set of available properties, along with any
* associated data types, read-only states, and write-only states.</p>
*
* @author Craig McClanahan
* @author Michael Smith
* @version $Revision: 1.1 $ $Date: 2001/12/24 23:27:04 $
*/
public interface DynaClass {
/**
* Add a new dynamic property with no restrictions on data type,
* readability, or writeability.
*
* @param name Name of the new dynamic property
*
* @exception IllegalArgumentException if name is null
* @exception IllegalStateException if this DynaClass is currently
* restricted, so no new properties can be added
*/
public void add(String name);
/**
* Add a new dynamic property with the specified data type, but with
* no restrictions on readability or writeability.
*
* @param name Name of the new dynamic property
* @param type Data type of the new dynamic property (null for no
* restrictions)
*
* @exception IllegalArgumentException if name is null
* @exception IllegalStateException if this DynaClass is currently
* restricted, so no new properties can be added
*/
public void add(String name, Class type);
/**
* Add a new dynamic property with the specified data type, readability,
* and writeability.
*
* @param name Name of the new dynamic property
* @param type Data type of the new dynamic property (null for no
* restrictions)
* @param readable Set to <code>true</code> if this property value
* should be readable
* @param writeable Set to <code>true</code> if this property value
* should be writeable
*
* @exception IllegalArgumentException if name is null
* @exception IllegalStateException if this DynaClass is currently
* restricted, so no new properties can be added
*/
public void add(String name, Class type, boolean readable,
boolean writeable);
/**
* Return the <code>Converter</code> instance that will be used to
* convert input property values to the appropriate types (if any).
*/
public Converter getConverter();
/**
* Return the name of this DynaClass (analogous to the
* <code>getName()</code> method of <code>java.lang.Class</code), which
* allows the same <code>DynaClass</code> implementation class to support
* different dynamic classes, with different sets of properties.
*/
public String getName();
/**
* Return a property descriptor for the specified property, if it exists;
* otherwise, return <code>null</code>.
*
* @param name Name of the dynamic property for which a descriptor
* is requested
*/
public PropertyDescriptor[] getPropertyDescriptor(String name);
/**
* <p>Return an array of <code>ProperyDescriptors</code> for the properties
* currently defined in this DynaClass. If no properties are defined, a
* zero-length array will be returned.</p>
*
* <p><strong>FIXME</strong> - Should we really be implementing
* <code>getBeanInfo()</code> instead, which returns property descriptors
* and a bunch of other stuff?</p>
*/
public PropertyDescriptor[] getPropertyDescriptors();
/**
* Is this DynaClass currently restricted? If so, no changes to the
* existing registration of property names, data types, readability, or
* writeability are allowed.
*/
public boolean isRestricted();
/**
* Remove the specified dynamic property, and any associated data type,
* readability, and writeability, from this dynamic class.
* <strong>NOTE</strong> - This does <strong>NOT</strong> cause any
* corresponding property values to be removed from DynaBean instances
* associated with this DynaClass.
*
* @param name Name of the dynamic property to remove
*
* @exception IllegalArgumentException if name is null
* @exception IllegalStateException if this DynaClass is currently
* restricted, so no properties can be removed
*/
public void remove(String name);
/**
* Set the restricted state of this DynaClass to the specified value.
*
* @param restricted The new restricted state
*/
public void setRestricted(boolean restricted);
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>