summaryrefslogtreecommitdiff
path: root/java/beans
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2005-01-16 02:14:44 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2005-01-16 02:14:44 +0000
commit2522f3363d0ccbb714b010c6ce79eb698052cca3 (patch)
treef9753bfb14e4195fe8c928b76e7d5407375bddf2 /java/beans
parent18addaa71c45fbdb60627f349e52027b3281e879 (diff)
downloadclasspath-2522f3363d0ccbb714b010c6ce79eb698052cca3.tar.gz
2005-01-16 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of November 2004 HEAD patches to generics branch
Diffstat (limited to 'java/beans')
-rw-r--r--java/beans/Beans.java2
-rw-r--r--java/beans/PropertyChangeEvent.java4
-rw-r--r--java/beans/PropertyChangeSupport.java2
-rw-r--r--java/beans/PropertyDescriptor.java827
-rw-r--r--java/beans/PropertyEditorSupport.java391
-rw-r--r--java/beans/VetoableChangeSupport.java2
6 files changed, 753 insertions, 475 deletions
diff --git a/java/beans/Beans.java b/java/beans/Beans.java
index 20c47f9bc..0816c9bfc 100644
--- a/java/beans/Beans.java
+++ b/java/beans/Beans.java
@@ -204,7 +204,7 @@ public class Beans
* Objects.
*
* @param bean the Bean to cast.
- * @param newClass the Class to cast it to.
+ * @param newBeanClass the Class to cast it to.
*
* @return whether the Bean can be cast to the class type
* in question.
diff --git a/java/beans/PropertyChangeEvent.java b/java/beans/PropertyChangeEvent.java
index 83ca681ce..418f92f8b 100644
--- a/java/beans/PropertyChangeEvent.java
+++ b/java/beans/PropertyChangeEvent.java
@@ -105,8 +105,8 @@ public class PropertyChangeEvent extends EventObject
*
* @param source the Bean containing the property
* @param propertyName the property's name
- * @param oldValue the old value of the property
- * @param newValue the new value of the property
+ * @param oldVal the old value of the property
+ * @param newVal the new value of the property
* @throws IllegalArgumentException if source is null
*/
public PropertyChangeEvent(Object source, String propertyName,
diff --git a/java/beans/PropertyChangeSupport.java b/java/beans/PropertyChangeSupport.java
index 862302735..4796a17f1 100644
--- a/java/beans/PropertyChangeSupport.java
+++ b/java/beans/PropertyChangeSupport.java
@@ -89,7 +89,7 @@ public class PropertyChangeSupport implements Serializable
*
* @serial the serialization format
*/
- private final int propertyChangeSupportSerializedDataVersion = 2;
+ private static final int propertyChangeSupportSerializedDataVersion = 2;
/**
* The list of all registered property listeners. If this instance was
diff --git a/java/beans/PropertyDescriptor.java b/java/beans/PropertyDescriptor.java
index 21ab360e9..b62440a2e 100644
--- a/java/beans/PropertyDescriptor.java
+++ b/java/beans/PropertyDescriptor.java
@@ -1,5 +1,5 @@
/* java.beans.PropertyDescriptor
- Copyright (C) 1998, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,7 +35,6 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package java.beans;
import java.lang.reflect.Method;
@@ -58,317 +57,537 @@ import java.lang.reflect.Method;
** </OL>
**
** @author John Keiser
- ** @since JDK1.1
- ** @version 1.1.0, 26 Jul 1998
+ ** @author Robert Schuster <thebohemian@gmx.net>
+ ** @since 1.1
+ ** @status updated to 1.4
**/
-public class PropertyDescriptor extends FeatureDescriptor {
- Class propertyType;
- Method getMethod;
- Method setMethod;
-
- Class propertyEditorClass;
- boolean bound;
- boolean constrained;
-
- PropertyDescriptor(String name) {
- setName(name);
- }
-
- /** Create a new PropertyDescriptor by introspection.
- ** This form of constructor creates the PropertyDescriptor by
- ** looking for a getter method named <CODE>get&lt;name&gt;()</CODE>
- ** (or, optionally, if the property is boolean,
- ** <CODE>is&lt;name&gt;()</CODE>) and
- ** <CODE>set&lt;name&gt;()</CODE> in class
- ** <CODE>&lt;beanClass&gt;</CODE>, where &lt;name&gt; has its
- ** first letter capitalized by the constructor.<P>
- **
- ** <B>Implementation note:</B> If there is both are both isXXX and
- ** getXXX methods, the former is used in preference to the latter.
- ** We do not check that an isXXX method returns a boolean. In both
- ** cases, this matches the behaviour of JDK 1.4<P>
- **
- ** @param name the programmatic name of the property, usually
- ** starting with a lowercase letter (e.g. fooManChu
- ** instead of FooManChu).
- ** @param beanClass the class the get and set methods live in.
- ** @exception IntrospectionException if the methods are not found
- ** or invalid.
- **/
- public PropertyDescriptor(String name, Class beanClass)
- throws IntrospectionException
- {
- setName(name);
- if (name.length() == 0) {
- throw new IntrospectionException("empty property name");
+public class PropertyDescriptor extends FeatureDescriptor
+{
+ Class propertyType;
+ Method getMethod;
+ Method setMethod;
+
+ Class propertyEditorClass;
+ boolean bound;
+ boolean constrained;
+
+ PropertyDescriptor(String name)
+ {
+ setName(name);
}
- String caps = Character.toUpperCase(name.charAt(0)) + name.substring(1);
- findMethods(beanClass, "is" + caps, "get" + caps, "set" + caps);
- if (getMethod == null) {
- throw new IntrospectionException("Cannot find an is" + caps +
- " or get" + caps + " method");
+
+ /** Create a new PropertyDescriptor by introspection.
+ ** This form of constructor creates the PropertyDescriptor by
+ ** looking for a getter method named <CODE>get&lt;name&gt;()</CODE>
+ ** (or, optionally, if the property is boolean,
+ ** <CODE>is&lt;name&gt;()</CODE>) and
+ ** <CODE>set&lt;name&gt;()</CODE> in class
+ ** <CODE>&lt;beanClass&gt;</CODE>, where &lt;name&gt; has its
+ ** first letter capitalized by the constructor.<P>
+ **
+ ** Note that using this constructor the given property must be read- <strong>and</strong>
+ ** writeable. If the implementation does not both, a read and a write method, an
+ ** <code>IntrospectionException</code> is thrown.
+ **
+ ** <B>Implementation note:</B> If there is both are both isXXX and
+ ** getXXX methods, the former is used in preference to the latter.
+ ** We do not check that an isXXX method returns a boolean. In both
+ ** cases, this matches the behaviour of JDK 1.4<P>
+ **
+ ** @param name the programmatic name of the property, usually
+ ** starting with a lowercase letter (e.g. fooManChu
+ ** instead of FooManChu).
+ ** @param beanClass the class the get and set methods live in.
+ ** @exception IntrospectionException if the methods are not found
+ ** or invalid.
+ **/
+ public PropertyDescriptor(String name, Class beanClass)
+ throws IntrospectionException
+ {
+ setName(name);
+ if (name.length() == 0)
+ {
+ throw new IntrospectionException("empty property name");
+ }
+ String caps = Character.toUpperCase(name.charAt(0)) + name.substring(1);
+ findMethods(beanClass, "is" + caps, "get" + caps, "set" + caps);
+
+ if (getMethod == null)
+ {
+ throw new IntrospectionException(
+ "Cannot find a is" + caps + " or get" + caps + " method");
+ }
+
+ if (setMethod == null)
+ {
+ throw new IntrospectionException(
+ "Cannot find a " + caps + " method");
+ }
+
+ // finally check the methods compatibility
+ checkMethods(getMethod, setMethod);
}
- if (setMethod == null) {
- throw new IntrospectionException("Cannot find a " + caps + " method");
+
+ /** Create a new PropertyDescriptor by introspection.
+ ** This form of constructor allows you to specify the
+ ** names of the get and set methods to search for.<P>
+ **
+ ** <B>Implementation note:</B> If there is a get method (or
+ ** boolean isXXX() method), then the return type of that method
+ ** is used to find the set method. If there is no get method,
+ ** then the set method is searched for exhaustively.<P>
+ **
+ ** <B>Spec note:</B>
+ ** If there is no get method and multiple set methods with
+ ** the same name and a single parameter (different type of course),
+ ** then an IntrospectionException is thrown. While Sun's spec
+ ** does not state this, it can make Bean behavior different on
+ ** different systems (since method order is not guaranteed) and as
+ ** such, can be treated as a bug in the spec. I am not aware of
+ ** whether Sun's implementation catches this.
+ **
+ ** @param name the programmatic name of the property, usually
+ ** starting with a lowercase letter (e.g. fooManChu
+ ** instead of FooManChu).
+ ** @param beanClass the class the get and set methods live in.
+ ** @param getMethodName the name of the get method or <code>null</code> if the property is write-only.
+ ** @param setMethodName the name of the set method or <code>null</code> if the property is read-only.
+ ** @exception IntrospectionException if the methods are not found
+ ** or invalid.
+ **/
+ public PropertyDescriptor(
+ String name,
+ Class beanClass,
+ String getMethodName,
+ String setMethodName)
+ throws IntrospectionException
+ {
+ setName(name);
+ findMethods(beanClass, getMethodName, null, setMethodName);
+
+ if (getMethod == null && getMethodName != null)
+ {
+ throw new IntrospectionException(
+ "Cannot find a getter method called " + getMethodName);
+ }
+
+ if (setMethod == null && setMethodName != null)
+ {
+ throw new IntrospectionException(
+ "Cannot find a setter method called " + setMethodName);
+ }
+
+ checkMethods(getMethod, setMethod);
}
- checkMethods();
- }
-
- /** Create a new PropertyDescriptor by introspection.
- ** This form of constructor allows you to specify the
- ** names of the get and set methods to search for.<P>
- **
- ** <B>Implementation note:</B> If there is a get method (or
- ** boolean isXXX() method), then the return type of that method
- ** is used to find the set method. If there is no get method,
- ** then the set method is searched for exhaustively.<P>
- **
- ** <B>Spec note:</B>
- ** If there is no get method and multiple set methods with
- ** the same name and a single parameter (different type of course),
- ** then an IntrospectionException is thrown. While Sun's spec
- ** does not state this, it can make Bean behavior different on
- ** different systems (since method order is not guaranteed) and as
- ** such, can be treated as a bug in the spec. I am not aware of
- ** whether Sun's implementation catches this.
- **
- ** @param name the programmatic name of the property, usually
- ** starting with a lowercase letter (e.g. fooManChu
- ** instead of FooManChu).
- ** @param beanClass the class the get and set methods live in.
- ** @param getMethodName the name of the get method.
- ** @param setMethodName the name of the set method.
- ** @exception IntrospectionException if the methods are not found
- ** or invalid.
- **/
- public PropertyDescriptor(String name, Class beanClass,
- String getMethodName, String setMethodName)
- throws IntrospectionException
- {
- setName(name);
- findMethods(beanClass, getMethodName, null, setMethodName);
- if (getMethod == null && getMethodName != null) {
- throw new IntrospectionException("Cannot find a getter method called " +
- getMethodName);
+
+ /** Create a new PropertyDescriptor using explicit Methods.
+ ** Note that the methods will be checked for conformance to standard
+ ** Property method rules, as described above at the top of this class.
+ **<br>
+ ** It is possible to call this method with both <code>Method</code> arguments
+ ** being <code>null</code>. In such a case the property type is <code>null</code>.
+ **
+ ** @param name the programmatic name of the property, usually
+ ** starting with a lowercase letter (e.g. fooManChu
+ ** instead of FooManChu).
+ ** @param readMethod the read method or <code>null</code> if the property is write-only.
+ ** @param writeMethod the write method or <code>null</code> if the property is read-only.
+ ** @exception IntrospectionException if the methods are not found
+ ** or invalid.
+ **/
+ public PropertyDescriptor(
+ String name,
+ Method readMethod,
+ Method writeMethod)
+ throws IntrospectionException
+ {
+ setName(name);
+ getMethod = readMethod;
+ setMethod = writeMethod;
+
+ if (getMethod != null)
+ {
+ this.propertyType = getMethod.getReturnType();
+ }
+ else if (setMethod != null)
+ {
+ this.propertyType = setMethod.getParameterTypes()[0];
+ }
+
+ checkMethods(getMethod, setMethod);
}
- if (setMethod == null && setMethodName != null) {
- throw new IntrospectionException("Cannot find a setter method called " +
- setMethodName);
+
+ /** Get the property type.
+ ** This is the type the get method returns and the set method
+ ** takes in.
+ **/
+ public Class getPropertyType()
+ {
+ return propertyType;
}
- checkMethods();
- }
-
- /** Create a new PropertyDescriptor using explicit Methods.
- ** Note that the methods will be checked for conformance to standard
- ** Property method rules, as described above at the top of this class.
- **
- ** @param name the programmatic name of the property, usually
- ** starting with a lowercase letter (e.g. fooManChu
- ** instead of FooManChu).
- ** @param getMethod the get method.
- ** @param setMethod the set method.
- ** @exception IntrospectionException if the methods are not found
- ** or invalid.
- **/
- public PropertyDescriptor(String name, Method getMethod, Method setMethod)
- throws IntrospectionException
- {
- setName(name);
- this.getMethod = getMethod;
- this.setMethod = setMethod;
- if (getMethod != null) {
- this.propertyType = getMethod.getReturnType();
- }
- else if (setMethod != null) {
- this.propertyType = setMethod.getParameterTypes()[0];
+
+ /** Get the get method. Why they call it readMethod here and
+ ** get everywhere else is beyond me.
+ **/
+ public Method getReadMethod()
+ {
+ return getMethod;
+ }
+
+ /** Sets the read method.<br/>
+ * The read method is used to retrieve the value of a property. A legal
+ * read method must have no arguments. Its return type must not be
+ * <code>void</code>. If this methods succeeds the property type
+ * is adjusted to the return type of the read method.<br/>
+ * <br/>
+ * It is legal to set the read and the write method to <code>null</code>
+ * or provide method which have been declared in distinct classes.
+ *
+ * @param readMethod The new method to be used or <code>null</code>.
+ * @throws IntrospectionException If the given method is invalid.
+ * @since 1.2
+ */
+ public void setReadMethod(Method readMethod) throws IntrospectionException
+ {
+ checkMethods(readMethod, setMethod);
+
+ getMethod = readMethod;
+ }
+
+ /** Get the set method. Why they call it writeMethod here and
+ ** set everywhere else is beyond me.
+ **/
+ public Method getWriteMethod()
+ {
+ return setMethod;
+ }
+
+ /** Sets the write method.<br/>
+ * The write method is used to set the value of a property. A legal write method
+ * must have a single argument which can be assigned to the property. If no
+ * read method exists the property type changes to the argument type of the
+ * write method.<br/>
+ * <br/>
+ * It is legal to set the read and the write method to <code>null</code>
+ * or provide method which have been declared in distinct classes.
+ *
+ * @param writeMethod The new method to be used or <code>null</code>.
+ * @throws IntrospectionException If the given method is invalid.
+ * @since 1.2
+ */
+ public void setWriteMethod(Method writeMethod)
+ throws IntrospectionException
+ {
+ propertyType = checkMethods(getMethod, writeMethod);
+
+ setMethod = writeMethod;
}
- checkMethods();
- }
-
- /** Get the property type.
- ** This is the type the get method returns and the set method
- ** takes in.
- **/
- public Class getPropertyType() {
- return propertyType;
- }
-
- /** Get the get method. Why they call it readMethod here and
- ** get everywhere else is beyond me.
- **/
- public Method getReadMethod() {
- return getMethod;
- }
-
- /** Get the set method. Why they call it writeMethod here and
- ** set everywhere else is beyond me.
- **/
- public Method getWriteMethod() {
- return setMethod;
- }
-
- /** Get whether the property is bound. Defaults to false. **/
- public boolean isBound() {
- return bound;
- }
-
- /** Set whether the property is bound.
- ** As long as the the bean implements addPropertyChangeListener() and
- ** removePropertyChangeListener(), setBound(true) may safely be called.<P>
- ** If these things are not true, then the behavior of the system
- ** will be undefined.<P>
- **
- ** When a property is bound, its set method is required to fire the
- ** <CODE>PropertyChangeListener.propertyChange())</CODE> event
- ** after the value has changed.
- ** @param bound whether the property is bound or not.
- **/
- public void setBound(boolean bound) {
- this.bound = bound;
- }
-
- /** Get whether the property is constrained. Defaults to false. **/
- public boolean isConstrained() {
- return constrained;
- }
-
- /** Set whether the property is constrained.
- ** If the set method throws <CODE>java.beans.PropertyVetoException</CODE>
- ** (or subclass thereof) and the bean implements addVetoableChangeListener()
- ** and removeVetoableChangeListener(), then setConstrained(true) may safely
- ** be called. Otherwise, the system behavior is undefined.
- ** <B>Spec note:</B> given those strict parameters, it would be nice if it
- ** got set automatically by detection, but oh well.<P>
- ** When a property is constrained, its set method is required to:<P>
- ** <OL>
- ** <LI>Fire the <CODE>VetoableChangeListener.vetoableChange()</CODE>
- ** event notifying others of the change and allowing them a chance to
- ** say it is a bad thing.</LI>
- ** <LI>If any of the listeners throws a PropertyVetoException, then
- ** it must fire another vetoableChange() event notifying the others
- ** of a reversion to the old value (though, of course, the change
- ** was never made). Then it rethrows the PropertyVetoException and
- ** exits.</LI>
- ** <LI>If all has gone well to this point, the value may be changed.</LI>
- ** </OL>
- ** @param constrained whether the property is constrained or not.
- **/
- public void setConstrained(boolean constrained) {
- this.constrained = constrained;
- }
-
- /** Get the PropertyEditor class. Defaults to null. **/
- public Class getPropertyEditorClass() {
- return propertyEditorClass;
- }
-
- /** Set the PropertyEditor class. If the class does not implement
- ** the PropertyEditor interface, you will likely get an exception
- ** late in the game.
- ** @param propertyEditorClass the PropertyEditor class for this
- ** class to use.
- **/
- public void setPropertyEditorClass(Class propertyEditorClass) {
- this.propertyEditorClass = propertyEditorClass;
- }
-
- private void findMethods(Class beanClass, String getMethodName1,
- String getMethodName2, String setMethodName)
- throws IntrospectionException
- {
- try {
- // Try the first get method name
- if (getMethodName1 != null) {
- try {
- getMethod = beanClass.getMethod(getMethodName1, new Class[0]);
- }
- catch (NoSuchMethodException e) {
- }
- }
-
- // Fall back to the second get method name
- if (getMethod == null && getMethodName2 != null) {
- try {
- getMethod = beanClass.getMethod(getMethodName2, new Class[0]);
- }
- catch (NoSuchMethodException e) {
- }
- }
-
- // Try the set method name
- if (setMethodName != null) {
- if (getMethod != null) {
- // If there is a get method, use its return type to help
- // select the corresponding set method.
- Class propertyType = getMethod.getReturnType();
- if (propertyType == Void.TYPE) {
- String msg = "The property's read method has return type 'void'";
- throw new IntrospectionException(msg);
- }
-
- Class[] setArgs = new Class[]{propertyType};
- try {
- setMethod = beanClass.getMethod(setMethodName, setArgs);
- }
- catch (NoSuchMethodException e) {
- }
- }
- else if (getMethodName1 == null && getMethodName2 == null) {
- // If this is a write-only property, choose the first set method
- // with the required name, one parameter and return type 'void'
- Method[] methods = beanClass.getMethods();
- for (int i = 0; i < methods.length; i++) {
- if (methods[i].getName().equals(setMethodName) &&
- methods[i].getParameterTypes().length == 1 &&
- methods[i].getReturnType() == Void.TYPE) {
- setMethod = methods[i];
- break;
- }
- }
- }
- }
- }
- catch (SecurityException e) {
- // FIXME -- shouldn't we just allow SecurityException to propagate?
- String msg = "SecurityException thrown on attempt to access methods.";
- throw new IntrospectionException(msg);
+
+ /** Get whether the property is bound. Defaults to false. **/
+ public boolean isBound()
+ {
+ return bound;
}
- }
-
- private void checkMethods()
- throws IntrospectionException
- {
- if (getMethod != null) {
- if (getMethod.getParameterTypes().length > 0) {
- throw new IntrospectionException("get method has parameters");
- }
- this.propertyType = getMethod.getReturnType();
- if (propertyType == Void.TYPE) {
- throw new IntrospectionException("get method has void return type");
- }
+
+ /** Set whether the property is bound.
+ ** As long as the the bean implements addPropertyChangeListener() and
+ ** removePropertyChangeListener(), setBound(true) may safely be called.<P>
+ ** If these things are not true, then the behavior of the system
+ ** will be undefined.<P>
+ **
+ ** When a property is bound, its set method is required to fire the
+ ** <CODE>PropertyChangeListener.propertyChange())</CODE> event
+ ** after the value has changed.
+ ** @param bound whether the property is bound or not.
+ **/
+ public void setBound(boolean bound)
+ {
+ this.bound = bound;
}
- if (setMethod != null) {
- if (setMethod.getParameterTypes().length != 1) {
- String msg = "set method does not have exactly one parameter";
- throw new IntrospectionException(msg);
- }
- if (getMethod == null) {
- propertyType = setMethod.getParameterTypes()[0];
- }
- else {
- if (!propertyType.equals(setMethod.getParameterTypes()[0])) {
- String msg = "set and get methods do not share the same type";
- throw new IntrospectionException(msg);
- }
- if ((!getMethod.getDeclaringClass().
- isAssignableFrom(setMethod.getDeclaringClass())) &&
- (!setMethod.getDeclaringClass().
- isAssignableFrom(getMethod.getDeclaringClass()))) {
- String msg = "set and get methods are not in the same class.";
- throw new IntrospectionException(msg);
- }
- }
+
+ /** Get whether the property is constrained. Defaults to false. **/
+ public boolean isConstrained()
+ {
+ return constrained;
+ }
+
+ /** Set whether the property is constrained.
+ ** If the set method throws <CODE>java.beans.PropertyVetoException</CODE>
+ ** (or subclass thereof) and the bean implements addVetoableChangeListener()
+ ** and removeVetoableChangeListener(), then setConstrained(true) may safely
+ ** be called. Otherwise, the system behavior is undefined.
+ ** <B>Spec note:</B> given those strict parameters, it would be nice if it
+ ** got set automatically by detection, but oh well.<P>
+ ** When a property is constrained, its set method is required to:<P>
+ ** <OL>
+ ** <LI>Fire the <CODE>VetoableChangeListener.vetoableChange()</CODE>
+ ** event notifying others of the change and allowing them a chance to
+ ** say it is a bad thing.</LI>
+ ** <LI>If any of the listeners throws a PropertyVetoException, then
+ ** it must fire another vetoableChange() event notifying the others
+ ** of a reversion to the old value (though, of course, the change
+ ** was never made). Then it rethrows the PropertyVetoException and
+ ** exits.</LI>
+ ** <LI>If all has gone well to this point, the value may be changed.</LI>
+ ** </OL>
+ ** @param constrained whether the property is constrained or not.
+ **/
+ public void setConstrained(boolean constrained)
+ {
+ this.constrained = constrained;
}
- }
+
+ /** Get the PropertyEditor class. Defaults to null. **/
+ public Class getPropertyEditorClass()
+ {
+ return propertyEditorClass;
+ }
+
+ /** Set the PropertyEditor class. If the class does not implement
+ ** the PropertyEditor interface, you will likely get an exception
+ ** late in the game.
+ ** @param propertyEditorClass the PropertyEditor class for this
+ ** class to use.
+ **/
+ public void setPropertyEditorClass(Class propertyEditorClass)
+ {
+ this.propertyEditorClass = propertyEditorClass;
+ }
+
+ private void findMethods(
+ Class beanClass,
+ String getMethodName1,
+ String getMethodName2,
+ String setMethodName)
+ throws IntrospectionException
+ {
+ try
+ {
+ // Try the first get method name
+ if (getMethodName1 != null)
+ {
+ try
+ {
+ getMethod =
+ beanClass.getMethod(getMethodName1, new Class[0]);
+ }
+ catch (NoSuchMethodException e)
+ {}
+ }
+
+ // Fall back to the second get method name
+ if (getMethod == null && getMethodName2 != null)
+ {
+ try
+ {
+ getMethod =
+ beanClass.getMethod(getMethodName2, new Class[0]);
+ }
+ catch (NoSuchMethodException e)
+ {}
+ }
+
+ // Try the set method name
+ if (setMethodName != null)
+ {
+ if (getMethod != null)
+ {
+ // If there is a get method, use its return type to help
+ // select the corresponding set method.
+ Class propertyType = getMethod.getReturnType();
+ if (propertyType == Void.TYPE)
+ {
+ String msg =
+ "The property's read method has return type 'void'";
+ throw new IntrospectionException(msg);
+ }
+
+ Class[] setArgs = new Class[] { propertyType };
+ try
+ {
+ setMethod = beanClass.getMethod(setMethodName, setArgs);
+ }
+ catch (NoSuchMethodException e)
+ {}
+ }
+ else if (getMethodName1 == null && getMethodName2 == null)
+ {
+ // If this is a write-only property, choose the first set method
+ // with the required name, one parameter and return type 'void'
+ Method[] methods = beanClass.getMethods();
+ for (int i = 0; i < methods.length; i++)
+ {
+ if (methods[i].getName().equals(setMethodName)
+ && methods[i].getParameterTypes().length == 1
+ && methods[i].getReturnType() == Void.TYPE)
+ {
+ setMethod = methods[i];
+ break;
+ }
+ }
+ }
+ }
+ }
+ catch (SecurityException e)
+ {
+ // FIXME -- shouldn't we just allow SecurityException to propagate?
+ String msg =
+ "SecurityException thrown on attempt to access methods.";
+ throw new IntrospectionException(msg);
+ }
+ }
+
+ /** Checks whether the given <code>Method</code> instances are legal read and
+ * write methods. The following requirements must be met:<br/>
+ * <ul>
+ * <li>the read method must not have an argument</li>
+ * <li>the read method must have a non void return type</li>
+ * <li>the read method may not exist</li>
+ * <li>the write method must have a single argument</li>
+ * <li>the property type and the read method's return type must be assignable from the
+ * write method's argument type</li>
+ * <li>the write method may not exist</li>
+ * <ul>
+ * While checking the methods a common new property type is calculated. If the method
+ * succeeds this property type is returned.<br/>
+ * <br/>
+ * For compatibility this has to be noted:<br/>
+ * The two methods are allowed to be defined in two distinct classes and may both be null.
+ *
+ * @param readMethod The new read method to check.
+ * @param writeMethod The new write method to check.
+ * @return The common property type of the two method.
+ * @throws IntrospectionException If any of the above requirements are not met.
+ */
+ private Class checkMethods(Method readMethod, Method writeMethod)
+ throws IntrospectionException
+ {
+ Class newPropertyType = propertyType;
+
+ // a valid read method has zero arguments and a non-void return type.
+ if (readMethod != null)
+ {
+ if (readMethod.getParameterTypes().length > 0)
+ {
+ throw new IntrospectionException("read method has unexpected parameters");
+ }
+
+ newPropertyType = readMethod.getReturnType();
+
+ if (newPropertyType == Void.TYPE)
+ {
+ throw new IntrospectionException("read method return type is void");
+ }
+ }
+
+ // a valid write method has one argument which can be assigned to the property
+ if (writeMethod != null)
+ {
+ if (writeMethod.getParameterTypes().length != 1)
+ {
+ String msg = "write method does not have exactly one parameter";
+ throw new IntrospectionException(msg);
+ }
+
+ if (readMethod == null)
+ {
+ // changes the property type if there is no read method
+ newPropertyType = writeMethod.getParameterTypes()[0];
+ }
+ else
+ {
+ // checks whether the write method can be assigned to the return type of the read
+ // method (if this is not the case, the methods are not compatible)
+ // note: newPropertyType may be null if no methods or method names have been
+ // delivered in the constructor.
+ if (newPropertyType != null
+ && !newPropertyType.isAssignableFrom(
+ writeMethod.getParameterTypes()[0]))
+ {
+ // note: newPropertyType is the same as readMethod.getReturnType() at this point
+ throw new IntrospectionException("read and write method are not compatible");
+ }
+
+ /* note: the check whether both method are defined in related classes makes sense but is not
+ * done in the JDK.
+ * I leave this code here in case someone at Sun decides to add that functionality in later versions (rschuster)
+ if ((!readMethod
+ .getDeclaringClass()
+ .isAssignableFrom(writeMethod.getDeclaringClass()))
+ && (!writeMethod
+ .getDeclaringClass()
+ .isAssignableFrom(readMethod.getDeclaringClass())))
+ {
+ String msg =
+ "set and get methods are not in the same class.";
+ throw new IntrospectionException(msg);
+ }
+ */
+
+ }
+ }
+
+ return newPropertyType;
+ }
+
+ /** Compares this <code>PropertyDescriptor</code> against the
+ * given object.
+ * Two PropertyDescriptors are equals if
+ * <ul>
+ * <li>the read methods are equal</li>
+ * <li>the write methods are equal</li>
+ * <li>the property types are equals</li>
+ * <li>the property editor classes are equal</li>
+ * <li>the flags (constrained and bound) are equal</li>
+ * </ul>
+ * @return Whether both objects are equal according to the rules given above.
+ * @since 1.4
+ */
+ public boolean equals(Object o)
+ {
+ if (o instanceof PropertyDescriptor)
+ {
+ PropertyDescriptor that = (PropertyDescriptor) o;
+
+ // compares the property types and checks the case where both are null
+ boolean samePropertyType =
+ (propertyType == null)
+ ? that.propertyType == null
+ : propertyType.equals(that.propertyType);
+
+ // compares the property editor classes and checks the case where both are null
+ boolean samePropertyEditorClass =
+ (propertyEditorClass == null)
+ ? that.propertyEditorClass == null
+ : propertyEditorClass.equals(that.propertyEditorClass);
+
+ // compares the flags for equality
+ boolean sameFlags =
+ bound == that.bound && constrained == that.constrained;
+
+ // compares the read methods and checks the case where both are null
+ boolean sameReadMethod =
+ (getMethod == null)
+ ? that.getMethod == null
+ : getMethod.equals(that.getMethod);
+
+ boolean sameWriteMethod =
+ (setMethod == null)
+ ? that.setMethod == null
+ : setMethod.equals(that.setMethod);
+
+ return samePropertyType
+ && sameFlags
+ && sameReadMethod
+ && sameWriteMethod
+ && samePropertyEditorClass;
+ }
+ else
+ {
+ return false;
+ }
+
+ }
+
}
diff --git a/java/beans/PropertyEditorSupport.java b/java/beans/PropertyEditorSupport.java
index 2376867e9..2ea9aaa4f 100644
--- a/java/beans/PropertyEditorSupport.java
+++ b/java/beans/PropertyEditorSupport.java
@@ -1,5 +1,5 @@
/* java.beans.PropertyEditorSupport
- Copyright (C) 1998 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-
+
GNU Classpath 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
@@ -38,169 +38,228 @@ exception statement from your version. */
package java.beans;
+
/**
- ** PropertyEditorSupport helps with PropertyEditors,
- ** implementing base functionality that they usually must
- ** have but which is a pain to implement. You may extend
- ** from this class or use it as a standalone.<P>
- **
- ** This class does not do any painting or actual editing.
- ** For that, you must use or extend it. See the
- ** PropertyEditor class for better descriptions of what
- ** the various methods do.
- **
- ** @author John Keiser
- ** @since JDK1.1
- ** @version 1.1.0, 29 Jul 1998
- **/
-
-public class PropertyEditorSupport implements PropertyEditor {
- Object eventSource;
- Object val;
- PropertyChangeSupport pSupport;
-
- /** Call this constructor when you are deriving from
- ** PropertyEditorSupport.
- **/
- protected PropertyEditorSupport() {
- this.eventSource = this;
- this.pSupport = new PropertyChangeSupport(this);
- }
-
- /** Call this constructor when you are using
- ** PropertyEditorSupport as a helper object.
- ** @param eventSource the source to use when firing
- ** property change events.
- **/
- protected PropertyEditorSupport(Object eventSource) {
- this.eventSource = eventSource;
- this.pSupport = new PropertyChangeSupport(this);
- }
-
- /** Set the current value of the property.
- ** <STRONG>Implementation Note</STRONG> Sun does not
- ** state what exactly this version of the method does.
- ** Thus, in this implementation, it sets the value, and
- ** then if the old and new values are different, it
- ** fires a property change event with no property name
- ** and the old and new values.
- ** @param val the new value for the property.
- **/
- public void setValue(Object val) {
- Object oldVal = val;
- this.val = val;
- if(!oldVal.equals(val)) {
- pSupport.firePropertyChange(null,oldVal,val);
- }
- }
-
- /** Get the current value of the property.
- ** @return the current value of the property.
- **/
- public Object getValue() {
- return val;
- }
-
- /** Get whether this object is paintable or not.
- ** @return <CODE>false</CODE>
- **/
- public boolean isPaintable() {
- return false;
- }
-
- /** Paint this object. This class does nothing in
- ** this method.
- **/
- public void paintValue(java.awt.Graphics g, java.awt.Rectangle r) {
- }
-
- /** Get the Java initialization String for the current
- ** value of the Object. This class returns gibberish or
- ** null (though the spec does not say which).<P>
- ** <STRONG>Implementation Note:</STRONG> This class
- ** returns the string "@$#^" to make sure the code will
- ** be broken, so that you will know to override it when
- ** you create your own property editor.
- ** @return the Java initialization string.
- **/
- public String getJavaInitializationString() {
- return "@$#^";
- }
-
- /** Get the value as text.
- ** In this class, you cannot count on getAsText() doing
- ** anything useful, although in this implementation I
- ** do toString().
- ** @return the value as text.
- **/
- public String getAsText() {
- return val != null ? val.toString() : "null";
- }
-
- /** Set the value as text.
- ** In this class, you cannot count on setAsText() doing
- ** anything useful across implementations.
- ** <STRONG>Implementation Note:</STRONG> In this
- ** implementation it checks if the String is "null", and
- ** if it is, sets the value to null, otherwise it throws
- ** an IllegalArgumentException.
- ** @param s the text to convert to a new value.
- ** @exception IllegalArgumentException if the text is
- ** malformed.
- **/
- public void setAsText(String s) throws IllegalArgumentException {
- if(s.equals("null")) {
- setValue(null);
- } else {
- throw new IllegalArgumentException();
- }
- }
-
- /** Returns a list of possible choices for the value.
- ** @return <CODE>null</CODE>
- **/
- public String[] getTags() {
- return null;
- }
-
- /** Return a custom component to edit the value.
- ** @return <CODE>null</CODE> in this class.
- **/
- public java.awt.Component getCustomEditor() {
- return null;
- }
-
- /** Find out whether this property editor supports a
- ** custom component to edit its value.
- ** @return <CODE>false</CODE> in this class.
- **/
- public boolean supportsCustomEditor() {
- return false;
- }
-
- /** Add a property change listener to this property editor.
- ** @param l the listener to add.
- **/
- public void addPropertyChangeListener(PropertyChangeListener l) {
- pSupport.addPropertyChangeListener(l);
- }
-
- /** Remove a property change listener from this property editor.
- ** @param l the listener to remove.
- **/
- public void removePropertyChangeListener(PropertyChangeListener l) {
- pSupport.removePropertyChangeListener(l);
- }
-
-
- /** Notify people that we've changed, although we don't
- ** tell them just how. The only thing I can think of to
- ** send in the event is the new value (since the old value
- ** is unavailable and there is no property name).
- ** I confess I do not understand the point of this method.
- **/
- public void firePropertyChange() {
- pSupport.firePropertyChange(null,null,val);
- }
-}
+ * PropertyEditorSupport helps with PropertyEditors,
+ * implementing base functionality that they usually must
+ * have but which is a pain to implement. You may extend
+ * from this class or use it as a standalone.<P>
+ *
+ * This class does not do any painting or actual editing.
+ * For that, you must use or extend it. See the
+ * PropertyEditor class for better descriptions of what
+ * the various methods do.
+ *
+ * @author John Keiser
+ * @author Robert Schuster
+ * @since 1.1
+ * @status updated to 1.5
+ */
+public class PropertyEditorSupport implements PropertyEditor
+{
+ Object eventSource;
+ Object value;
+ PropertyChangeSupport pSupport;
+
+ /** Call this constructor when you are deriving from
+ * PropertyEditorSupport.
+ *
+ * Using this constructor the event source is this PropertyEditorSupport
+ * instance itself.
+ *
+ * @since 1.5
+ * @specnote this was <code>protected</code> prior to 1.5
+ */
+ public PropertyEditorSupport()
+ {
+ eventSource = this;
+ pSupport = new PropertyChangeSupport(this);
+ }
+
+ /** Call this constructor when you are using
+ * PropertyEditorSupport as a helper object.
+ *
+ * This constructor throws a NullPointerException when <code>source</code> is <code>null</code>,
+ * for compatibility reasons with J2SDK 1.5.0 .
+ *
+ * @param source The source to use when firing
+ * property change events.
+ * @since 1.5
+ * @specnote this was <code>protected</code> prior to 1.5
+ */
+ public PropertyEditorSupport(Object source)
+ {
+ // note: constructor rejects source being null for the sake of compatibility
+ // with official 1.5.0 implementation
+ if (source == null)
+ throw new NullPointerException("Event source must not be null.");
+
+ eventSource = source;
+ pSupport = new PropertyChangeSupport(eventSource);
+ }
+
+ /** Sets the current value of the property and a property change
+ * event is fired to all registered PropertyChangeListener instances.
+ *
+ * @param newValue The new value for the property.
+ */
+ public void setValue(Object newValue)
+ {
+ value = newValue;
+
+ // specification in java.beans.PropertyChangeEvent says
+ // that without a property name (first argument) the
+ // new and the old value should always be null
+ pSupport.firePropertyChange(null, null, null);
+ }
+
+ /** Gets the current value of the property.
+ *
+ * @return the current value of the property.
+ */
+ public Object getValue()
+ {
+ return value;
+ }
+
+ /** Gets whether this object is paintable or not.
+ *
+ * @return <CODE>false</CODE>
+ */
+ public boolean isPaintable()
+ {
+ return false;
+ }
+
+ /** Paints this object. This class does nothing in
+ * this method.
+ */
+ public void paintValue(java.awt.Graphics g, java.awt.Rectangle r)
+ {
+ }
+ /** Gets the Java initialization String for the current
+ * value of the Object. This class returns gibberish or
+ * null (though the spec does not say which).<P>
+ * <STRONG>Implementation Note:</STRONG> This class
+ * returns the string "@$#^" to make sure the code will
+ * be broken, so that you will know to override it when
+ * you create your own property editor.
+ *
+ * @return the Java initialization string.
+ */
+ public String getJavaInitializationString()
+ {
+ return "@$#^";
+ }
+
+ /** Gets the value as text.
+ * In this class, you cannot count on getAsText() doing
+ * anything useful, although in this implementation I
+ * do toString().
+ *
+ * @return the value as text.
+ */
+ public String getAsText()
+ {
+ return value != null ? value.toString() : "null";
+ }
+
+ /** Sets the value as text.
+ * In this class, you cannot count on setAsText() doing
+ * anything useful across implementations.
+ * <STRONG>Implementation Note:</STRONG> In this
+ * implementation it checks if the String is "null", and
+ * if it is, sets the value to null, otherwise it throws
+ * an IllegalArgumentException.
+ *
+ * @param s the text to convert to a new value.
+ * @exception IllegalArgumentException if the text is
+ * malformed.
+ */
+ public void setAsText(String s) throws IllegalArgumentException
+ {
+ if (s.equals("null"))
+ setValue(null);
+ else
+ throw new IllegalArgumentException();
+ }
+
+ /** Returns a list of possible choices for the value.
+ *
+ * @return <CODE>null</CODE>
+ */
+ public String[] getTags()
+ {
+ return null;
+ }
+
+ /** Returns a custom component to edit the value.
+ *
+ * @return <CODE>null</CODE> in this class.
+ */
+ public java.awt.Component getCustomEditor()
+ {
+ return null;
+ }
+
+ /** Finds out whether this property editor supports a
+ * custom component to edit its value.
+ *
+ * @return <CODE>false</CODE> in this class.
+ */
+ public boolean supportsCustomEditor()
+ {
+ return false;
+ }
+
+ /** Adds a property change listener to this property editor.
+ *
+ * @param l the listener to add.
+ */
+ public void addPropertyChangeListener(PropertyChangeListener l)
+ {
+ pSupport.addPropertyChangeListener(l);
+ }
+
+ /** Removes a property change listener from this property editor.
+ *
+ * @param l the listener to remove.
+ */
+ public void removePropertyChangeListener(PropertyChangeListener l)
+ {
+ pSupport.removePropertyChangeListener(l);
+ }
+
+ /** Notifies people that we've changed, although we don't
+ * tell them just how.
+ */
+ public void firePropertyChange()
+ {
+ pSupport.firePropertyChange(null, null, null);
+ }
+
+ /** Returns the bean that is used as the source of events.
+ *
+ * @return The event source object
+ * @since 1.5
+ */
+ public Object getSource()
+ {
+ return eventSource;
+ }
+
+ /** Sets the bean that is used as the source of events
+ * when property changes occur.
+ *
+ * The event source bean is for informational purposes only
+ * and should not be changed by the <code>PropertyEditor</code>.
+ *
+ * @param source
+ * @since 1.5
+ */
+ public void setSource(Object source)
+ {
+ eventSource = source;
+ }
+}
diff --git a/java/beans/VetoableChangeSupport.java b/java/beans/VetoableChangeSupport.java
index d7d0d2cb5..bbac648db 100644
--- a/java/beans/VetoableChangeSupport.java
+++ b/java/beans/VetoableChangeSupport.java
@@ -89,7 +89,7 @@ public class VetoableChangeSupport implements Serializable
*
* @serial the serialization format
*/
- private final int vetoableChangeSupportSerializedDataVersion = 2;
+ private static final int vetoableChangeSupportSerializedDataVersion = 2;
/**
* The list of all registered vetoable listeners. If this instance was