/* gnu.java.beans.IntrospectionIncubator
Copyright (C) 1998, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
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 gnu.java.beans;
import gnu.java.lang.ArrayHelper;
import gnu.java.lang.ClassHelper;
import java.beans.BeanInfo;
import java.beans.EventSetDescriptor;
import java.beans.IndexedPropertyDescriptor;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.MethodDescriptor;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
/**
** IntrospectionIncubator takes in a bunch of Methods, and
** Introspects only those Methods you give it.
**
** See {@link addMethod(Method)} for details which rules apply to
** the methods.
**
** @author John Keiser
** @author Robert Schuster
** @see gnu.java.beans.ExplicitBeanInfo
** @see java.beans.BeanInfo
**/
public class IntrospectionIncubator {
Hashtable propertyMethods = new Hashtable();
Hashtable listenerMethods = new Hashtable();
Vector otherMethods = new Vector();
Class propertyStopClass;
Class eventStopClass;
Class methodStopClass;
public IntrospectionIncubator() {
}
/** Examines the given method and files it in a suitable collection.
* It files the method as a property method if it finds:
*
java.util.EventListener
null
* or declaringClass is a true subclass of stopClass
.
* This expression is useful to detect whether a method should be introspected or not.
* The rules for this are described in {@link java.beans.Introspector.getBeanInfo(Class, Class)}.
*/
static boolean isReachable(Class stopClass, Class declaringClass) {
return stopClass == null || (stopClass.isAssignableFrom(declaringClass) && !stopClass.equals(declaringClass));
}
/** Transforms a property name into a part of a method name.
* E.g. "value" becomes "Value" which can then concatenated with
* "set", "get" or "is" to form a valid method name.
*
* Implementation notes:
* If "" is the argument, it is returned without changes.
* If null
is the argument, null
is returned.
*
* @param name Name of a property.
* @return Part of a method name of a property.
*/
static String capitalize(String name) {
try {
if(Character.isUpperCase(name.charAt(0))) {
return name;
} else {
char[] c = name.toCharArray();
c[0] = Character.toLowerCase(c[0]);
return new String(c);
}
} catch(StringIndexOutOfBoundsException E) {
return name;
} catch(NullPointerException E) {
return null;
}
}
}
/** This class is a hashmap key that consists of a Class
and a
* String
element.
*
* It is used for XXX: find out what this is used for
*
* @author John Keiser
* @author Robert Schuster
*/
class DoubleKey {
Class type;
String name;
DoubleKey(Class type, String name) {
this.type = type;
this.name = name;
}
Class getType() {
return type;
}
String getName() {
return name;
}
public boolean equals(Object o) {
if(o instanceof DoubleKey) {
DoubleKey d = (DoubleKey)o;
return d.type.equals(type) && d.name.equals(name);
} else {
return false;
}
}
public int hashCode() {
return type.hashCode() ^ name.hashCode();
}
}