craigmcc 01/12/27 19:59:41
Modified: beanutils/src/java/org/apache/commons/beanutils
DynaBean.java DynaClass.java
Added: beanutils/src/java/org/apache/commons/beanutils
BasicDynaBean.java BasicDynaClass.java
DynaProperty.java
Log:
Here's bare-bones implementations of the DynaBean and DynaClass interfaces
for us to start chewing over -- BasicDynaBean only implements simple
properties at the moment (not indexed or mapped).
I also removed (from DynaBean) the support for "modified" and "readOnly"
properties of the DynaBean instance itself. In keeping with the minimalist
design that Paulo is nudging me towards :-), these are now value-added
features of a particular implementation.
Revision Changes Path
1.4 +5 -52
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DynaBean.java 2001/12/28 00:33:56 1.3
+++ DynaBean.java 2001/12/28 03:59:41 1.4
@@ -1,13 +1,13 @@
/*
- * $Header:
/home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaBean.java,v
1.3 2001/12/28 00:33:56 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2001/12/28 00:33:56 $
+ * $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 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -72,7 +72,7 @@
*
* @author Craig McClanahan
* @author Paulo Gaspar
- * @version $Revision: 1.3 $ $Date: 2001/12/28 00:33:56 $
+ * @version $Revision: 1.4 $ $Date: 2001/12/28 03:59:41 $
*/
public interface DynaBean {
@@ -85,9 +85,6 @@
* <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);
@@ -103,8 +100,6 @@
*
* @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);
@@ -120,8 +115,6 @@
*
* @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);
@@ -134,24 +127,6 @@
/**
- * 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 isDynaModified();
-
-
- /**
- * 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 isDynaReadOnly();
-
-
- /**
* 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
@@ -164,12 +139,6 @@
*
* @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
- * @exception IllegalStateException if the specified property exists
- * and is writeable, but this bean instance has been marked read only
*/
public void set(String name, Object value);
@@ -224,22 +193,6 @@
* and is writeable, but this bean instance has been marked read only
*/
public void set(String name, String key, Object value);
-
-
- /**
- * Set the value of the "dynamic modified" property.
- *
- * @param dynaModified The new dynamic modified property setting
- */
- public void setDynaModified(boolean dynaModified);
-
-
- /**
- * Set the value of the "dynamic read only" property.
- *
- * @param dynaReadOnly The new dynamic read only property setting
- */
- public void setDynaReadOnly(boolean dynaReadOnly);
}
1.4 +15 -8
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DynaClass.java 2001/12/28 00:33:56 1.3
+++ DynaClass.java 2001/12/28 03:59:41 1.4
@@ -1,13 +1,13 @@
/*
- * $Header:
/home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaClass.java,v
1.3 2001/12/28 00:33:56 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2001/12/28 00:33:56 $
+ * $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 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -76,7 +76,7 @@
* @author Craig McClanahan
* @author Michael Smith
* @author Paulo Gaspar
- * @version $Revision: 1.3 $ $Date: 2001/12/28 00:33:56 $
+ * @version $Revision: 1.4 $ $Date: 2001/12/28 03:59:41 $
*/
public interface DynaClass {
@@ -98,7 +98,7 @@
* @param name Name of the dynamic property for which a descriptor
* is requested
*/
- public PropertyDescriptor getPropertyDescriptor(String name);
+ public DynaProperty getPropertyDescriptor(String name);
/**
@@ -110,14 +110,21 @@
* <code>getBeanInfo()</code> instead, which returns property descriptors
* and a bunch of other stuff?</p>
*/
- public PropertyDescriptor[] getPropertyDescriptors();
+ public DynaProperty[] getPropertyDescriptors();
/**
* Instantiate and return a new DynaBean instance, using the implementation
* class specified by the <code>dynaBeanClass</code> property.
+ *
+ * @exception IllegalAccessException if the Class or the appropriate
+ * constructor is not accessible
+ * @exception InstantiationException if this Class represents an abstract
+ * class, an array class, a primitive type, or void; or if instantiation
+ * fails for some other reason
*/
- public DynaBean newInstance();
+ public DynaBean newInstance()
+ throws IllegalAccessException, InstantiationException;
}
1.1
jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BasicDynaBean.java
Index: BasicDynaBean.java
===================================================================
/*
* $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 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 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.util.HashMap;
/**
* <p>Minimal implementation of the <code>DynaBean</code> interface. Can be
* used as a convenience base class for more sophisticated implementations.</p>
*
* <p><strong>IMPLEMENTATION NOTE</strong> - Instances of this class that are
* accessed from multiple threads simultaneously need to be synchronized.</p>
*
* @author Craig McClanahan
* @version $Revision: 1.1 $ $Date: 2001/12/28 03:59:41 $
*/
public class BasicDynaBean implements DynaBean {
// ---------------------------------------------------------- Constructors
/**
* Construct a new <code>DynaBean</code> associated with the specified
* <code>DynaClass</code> instance.
*
* @param dynaClass The DynaClass we are associated with
*/
public BasicDynaBean(DynaClass dynaClass) {
super();
this.dynaClass = dynaClass;
}
// ---------------------------------------------------- Instance Variables
/**
* The <code>DynaClass</code> "base class" that this DynaBean
* is associated with.
*/
protected DynaClass dynaClass = null;
/**
* Have any properties of this instance been modified since the last time
* that <code>setDynaModified(false)</code> was called?
*/
protected boolean modified = false;
/**
* Has this DynaBean instance been declared read only?
*/
protected boolean readOnly = false;
/**
* The set of property values for this DynaBean, keyed by property name.
*/
protected HashMap values = new HashMap();
// ------------------------------------------------------ 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.
*
* @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) {
if (!values.containsKey(name))
throw new IllegalArgumentException
("No property " + name + " exists");
return (values.get(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 there is no property
* of the specified name
* @exception IllegalArgumentException if the specified property
* exists, but is not indexed
*/
public Object get(String name, int index) {
if (!values.containsKey(name))
throw new IllegalArgumentException
("No property " + name + " exists");
return (null); // FIXME - get(String,int)
}
/**
* 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 there is no property
* of the specified name
* @exception IllegalArgumentException if the specified property
* exists, but is not mapped
*/
public Object get(String name, String key) {
if (!values.containsKey(name))
throw new IllegalArgumentException
("No property " + name + " exists");
return (null); // FIXME - get(String, String)
}
/**
* Return the <code>DynaClass</code> instance that describes the set of
* properties available for this DynaBean.
*/
public DynaClass getDynaClass() {
return (this.dynaClass);
}
/**
* 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 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
*/
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;
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.
*
* @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
* @exception IllegalStateException if the specified property exists
* and is writeable, but this bean instance has been marked read only
*/
public void set(String name, int index, Object value) {
; // FIXME - set(String, int, Object)
}
/**
* 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
* @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);
}
/**
* 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);
}
/**
* Set the value of the "dynamic modified" property.
*
* @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 readOnly The new dynamic read only property setting
*/
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
}
1.1
jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BasicDynaClass.java
Index: BasicDynaClass.java
===================================================================
/*
* $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 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 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;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
* <p>Minimal implementation of the <code>DynaClass</code> interface. Can be
* used as a convenience base class for more sophisticated implementations.</p> *
* <p><strong>IMPLEMENTATION NOTE</strong> - The <code>DynaBean</code>
* implementation class supplied to our constructor MUST have a one-argument
* constructor of its own that accepts a <code>DynaClass</code>. This is
* used to associate the DynaBean instance with this DynaClass.</p>
*
* @author Craig McClanahan
* @version $Revision: 1.1 $ $Date: 2001/12/28 03:59:41 $
*/
public class BasicDynaClass implements DynaClass {
// ----------------------------------------------------------- Constructors
/**
* Construct a new BasicDynaClass with default parameters.
*/
public BasicDynaClass() {
this(null, null, null);
}
/**
* Construct a new BasicDynaClass with the specified parameters.
*
* @param name Name of this DynaBean class
* @param dynaBeanClass The implementation class for new instances
*/
public BasicDynaClass(String name, Class dynaBeanClass) {
this(name, dynaBeanClass, null);
}
/**
* Construct a new BasicDynaClass with the specified parameters.
*
* @param name Name of this DynaBean class
* @param dynaBeanClass The implementation class for new intances
* @param properties Property descriptors for the supported properties
*/
public BasicDynaClass(String name, Class dynaBeanClass,
DynaProperty properties[]) {
super();
if (name != null)
this.name = name;
if (dynaBeanClass != null)
setDynaBeanClass(dynaBeanClass);
if (properties != null)
this.properties = properties;
}
// ----------------------------------------------------- Instance Variables
/**
* The constructor of the <code>dynaBeanClass</code> that we will use
* for creating new instances.
*/
protected Constructor constructor = null;
/**
* The method signature of the constructor we will use to create
* new DynaBean instances.
*/
protected static Class constructorTypes[] = { DynaClass.class };
/**
* The argument values to be passed to the constructore we will use
* to create new DynaBean instances.
*/
protected Object constructorValues[] = { this };
/**
* The <code>DynaBean</code> implementation class we will use for
* creating new instances.
*/
protected Class dynaBeanClass = null; // BasicDynaBean.class
/**
* The "name" of this DynaBean class.
*/
protected String name = this.getClass().getName();
/**
* The set of dynamic properties that are part of this DynaClass.
*/
protected DynaProperty properties[] = new DynaProperty[0];
// ------------------------------------------------------ DynaClass Methods
/**
* Return the Class object we will use to create new instances in the
* <code>newInstance()</code> method. This Class <strong>MUST</strong>
* implement the <code>DynaBean</code> interface.
*/
public Class getDynaBeanClass() {
return (this.dynaBeanClass);
}
/**
* 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 (this.name);
}
/**
* 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 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);
}
/**
* <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 DynaProperty[] getPropertyDescriptors() {
return (properties);
}
/**
* Instantiate and return a new DynaBean instance, using the implementation
* class specified by the <code>dynaBeanClass</code> property.
*
* @exception IllegalAccessException if the Class or the appropriate
* constructor is not accessible
* @exception InstantiationException if this Class represents an abstract
* class, an array class, a primitive type, or void; or if instantiation
* fails for some other reason
*/
public DynaBean newInstance()
throws IllegalAccessException, InstantiationException {
try {
return ((DynaBean) constructor.newInstance(constructorValues));
} catch (InvocationTargetException e) {
throw new InstantiationException
(e.getTargetException().getMessage());
}
}
// ------------------------------------------------------ Protected Methods
/**
* Set the Class object we will use to create new instances in the
* <code>newInstance()</code> method. This Class <strong>MUST</strong>
* implement the <code>DynaBean</code> interface.
*
* @param dynaBeanClass The new Class object
*
* @exception IllegalArgumentException if the specified Class does not
* implement the <code>DynaBean</code> interface
*/
protected void setDynaBeanClass(Class dynaBeanClass) {
// Validate the argument type specified
if (dynaBeanClass.isInterface())
throw new IllegalArgumentException
("Class " + dynaBeanClass.getName() +
" is an interface, not a class");
if (DynaBean.class.isAssignableFrom(dynaBeanClass))
throw new IllegalArgumentException
("Class " + dynaBeanClass.getName() +
" does not implement DynaBean");
// Identify the Constructor we will use in newInstance()
try {
this.constructor = dynaBeanClass.getConstructor(constructorTypes);
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException
("Class " + dynaBeanClass.getName() +
" does not have an appropriate constructor");
}
this.dynaBeanClass = dynaBeanClass;
}
}
1.1
jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaProperty.java
Index: DynaProperty.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/DynaProperty.java,v
1.1 2001/12/28 03:59:41 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2001/12/28 03:59:41 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 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>The metadata describing an individual property of a DynaBean.</p>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/12/28 03:59:41 $
*/
public class DynaProperty {
// ----------------------------------------------------------- Constructors
/**
* Construct a property that accepts any data type.
*
* @param name Name of the property being described
*/
public DynaProperty(String name) {
this(name, Object.class);
}
/**
* Construct a property of the specified data type.
*
* @param name Name of the property being described
* @param type Java class representing the property data type
*/
public DynaProperty(String name, Class type) {
super();
this.name = name;
this.type = type;
}
// ------------------------------------------------------------- Properties
/**
* The name of this property.
*/
protected String name = null;
public String getName() {
return (this.name);
}
/**
* The Java class representing the data type of the underlying property
* values.
*/
protected Class type = null;
public Class getType() {
return (this.type);
}
// --------------------------------------------------------- Public Methods
/**
* Return a String representation of this Object.
*/
public String toString() {
StringBuffer sb = new StringBuffer("DynaProperty[name=");
sb.append(this.name);
sb.append(",type=");
sb.append(this.type);
sb.append("]");
return (sb.toString());
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>