[kaffe] CVS kaffe (dalibor): Finished java.beans merge with GNU Classpath
Kaffe CVS
cvs-commits at kaffe.org
Fri Oct 24 06:56:02 PDT 2003
PatchSet 4121
Date: 2003/10/24 13:53:59
Author: dalibor
Branch: HEAD
Tag: (none)
Log:
Finished java.beans merge with GNU Classpath
Merged in the Introspector class from GNU Classpath needed to get JBoss 3.2.2 to
load further. Fixed a small bug in IntrospectionIncubator that showed up in kaffe's
regression test suite.
Members:
ChangeLog:1.1713->1.1714
libraries/javalib/gnu/java/beans/IntrospectionIncubator.java:1.2->1.3
libraries/javalib/java/beans/Introspector.java:1.14->1.15
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1713 kaffe/ChangeLog:1.1714
--- kaffe/ChangeLog:1.1713 Thu Oct 23 16:52:13 2003
+++ kaffe/ChangeLog Fri Oct 24 13:53:59 2003
@@ -1,3 +1,11 @@
+2003-10-24 Dalibor Topic <robilad at kaffe.org>
+
+ * libraries/javalib/gnu/java/beans/IntrospectionIncubator.java:
+ (addMethod) Add public static methods.
+
+ * libraries/javalib/java/beans/Introspector.java:
+ Merged in from GNU Classpath.
+
2003-10-23 Marc Kleine-Budde <kleine-budde at gmx.de>
* kaffe/kaffevm/systems/win32/winthread.c
Index: kaffe/libraries/javalib/gnu/java/beans/IntrospectionIncubator.java
diff -u kaffe/libraries/javalib/gnu/java/beans/IntrospectionIncubator.java:1.2 kaffe/libraries/javalib/gnu/java/beans/IntrospectionIncubator.java:1.3
--- kaffe/libraries/javalib/gnu/java/beans/IntrospectionIncubator.java:1.2 Wed Oct 22 10:34:45 2003
+++ kaffe/libraries/javalib/gnu/java/beans/IntrospectionIncubator.java Fri Oct 24 13:54:00 2003
@@ -67,7 +67,7 @@
/* Paving the way for automatic Introspection */
public void addMethod(Method method) {
- if(Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers())) {
+ if(Modifier.isPublic(method.getModifiers())) {
String name = ClassHelper.getTruncatedName(method.getName());
Class retType = method.getReturnType();
Class[] params = method.getParameterTypes();
Index: kaffe/libraries/javalib/java/beans/Introspector.java
diff -u kaffe/libraries/javalib/java/beans/Introspector.java:1.14 kaffe/libraries/javalib/java/beans/Introspector.java:1.15
--- kaffe/libraries/javalib/java/beans/Introspector.java:1.14 Thu Jul 4 00:45:02 2002
+++ kaffe/libraries/javalib/java/beans/Introspector.java Fri Oct 24 13:54:01 2003
@@ -1,398 +1,571 @@
-package java.beans;
+/* java.beans.Introspector
+ Copyright (C) 1998, 2002, 2003 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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. */
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.TooManyListenersException;
-/*
- * Java core library component.
+package java.beans;
+
+import gnu.java.beans.*;
+import java.util.*;
+import java.lang.reflect.*;
+import gnu.java.lang.*;
+
+/**
+ * Introspector is the class that does the bulk of the
+ * design-time work in Java Beans. Every class must have
+ * a BeanInfo in order for an RAD tool to use it; but, as
+ * promised, you don't have to write the BeanInfo class
+ * yourself if you don't want to. All you have to do is
+ * call getBeanInfo() in the Introspector and it will use
+ * standard JavaBeans-defined method signatures to
+ * determine the information about your class.<P>
+ *
+ * Don't worry about it too much, though: you can provide
+ * JavaBeans with as much customized information as you
+ * want, or as little as you want, using the BeanInfo
+ * interface (see BeanInfo for details).<P>
+ *
+ * <STRONG>Order of Operations</STRONG><P>
+ *
+ * When you call getBeanInfo(class c), the Introspector
+ * first searches for BeanInfo class to see if you
+ * provided any explicit information. It searches for a
+ * class named <bean class name>BeanInfo in different
+ * packages, first searching the bean class's package
+ * and then moving on to search the beanInfoSearchPath.<P>
+ *
+ * If it does not find a BeanInfo class, it acts as though
+ * it had found a BeanInfo class returning null from all
+ * methods (meaning it should discover everything through
+ * Introspection). If it does, then it takes the
+ * information it finds in the BeanInfo class to be
+ * canonical (that is, the information speaks for its
+ * class as well as all superclasses).<P>
+ *
+ * When it has introspected the class, calls
+ * getBeanInfo(c.getSuperclass) and adds that information
+ * to the information it has, not adding to any information
+ * it already has that is canonical.<P>
+ *
+ * <STRONG>Introspection Design Patterns</STRONG><P>
*
- * Copyright (c) 1997, 1998
- * Transvirtual Technologies, Inc. All rights reserved.
+ * When the Introspector goes in to read the class, it
+ * follows a well-defined order in order to not leave any
+ * methods unaccounted for. Its job is to step over all
+ * of the public methods in a class and determine whether
+ * they are part of a property, an event, or a method (in
+ * that order).
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
+ *
+ * <STRONG>Properties:</STRONG><P>
+ *
+ * <OL>
+ * <LI>If there is a <CODE>public boolean isXXX()</CODE>
+ * method, then XXX is a read-only boolean property.
+ * <CODE>boolean getXXX()</CODE> may be supplied in
+ * addition to this method, although isXXX() is the
+ * one that will be used in this case and getXXX()
+ * will be ignored. If there is a
+ * <CODE>public void setXXX(boolean)</CODE> method,
+ * it is part of this group and makes it a read-write
+ * property.</LI>
+ * <LI>If there is a
+ * <CODE>public <type> getXXX(int)</CODE>
+ * method, then XXX is a read-only indexed property of
+ * type <type>. If there is a
+ * <CODE>public void setXXX(int,<type>)</CODE>
+ * method, then it is a read-write indexed property of
+ * type <type>. There may also be a
+ * <CODE>public <type>[] getXXX()</CODE> and a
+ * <CODE>public void setXXX(<type>)</CODE>
+ * method as well.</CODE></LI>
+ * <LI>If there is a
+ * <CODE>public void setXXX(int,<type>)</CODE>
+ * method, then it is a write-only indexed property of
+ * type <type>. There may also be a
+ * <CODE>public <type>[] getXXX()</CODE> and a
+ * <CODE>public void setXXX(<type>)</CODE>
+ * method as well.</CODE></LI>
+ * <LI>If there is a
+ * <CODE>public <type> getXXX()</CODE> method,
+ * then XXX is a read-only property of type
+ * <type>. If there is a
+ * <CODE>public void setXXX(<type>)</CODE>
+ * method, then it will be used for the property and
+ * the property will be considered read-write.</LI>
+ * <LI>If there is a
+ * <CODE>public void setXXX(<type>)</CODE>
+ * method, then as long as XXX is not already used as
+ * the name of a property, XXX is assumed to be a
+ * write-only property of type <type>.</LI>
+ * <LI>In all of the above cases, if the setXXX() method
+ * throws <CODE>PropertyVetoException</CODE>, then the
+ * property in question is assumed to be constrained.
+ * No properties are ever assumed to be bound
+ * (<STRONG>Spec Note:</STRONG> this is not in the
+ * spec, it just makes sense). See PropertyDescriptor
+ * for a description of bound and constrained
+ * properties.</LI>
+ * </OL>
+ *
+ * <STRONG>Events:</STRONG><P>
+ *
+ * If there is a pair of methods,
+ * <CODE>public void addXXX(<type>)</CODE> and
+ * <CODE>public void removeXXX(<type>)</CODE>, where
+ * <type> is a descendant of
+ * <CODE>java.util.EventListener</CODE>, then the pair of
+ * methods imply that this Bean will fire events to
+ * listeners of type <type>.<P>
+ *
+ * If the addXXX() method throws
+ * <CODE>java.util.TooManyListenersException</CODE>, then
+ * the event set is assumed to be <EM>unicast</EM>. See
+ * EventSetDescriptor for a discussion of unicast event
+ * sets.<P>
+ *
+ * <STRONG>Spec Note:</STRONG> the spec seems to say that
+ * the listener type's classname must be equal to the XXX
+ * part of addXXX() and removeXXX(), but that is not the
+ * case in Sun's implementation, so I am assuming it is
+ * not the case in general.<P>
+ *
+ * <STRONG>Methods:</STRONG><P>
+ *
+ * Any public methods (including those which were used
+ * for Properties or Events) are used as Methods.
+ *
+ * @author John Keiser
+ * @since JDK1.1
+ * @see java.beans.BeanInfo
*/
public class Introspector {
-
-public static final int USE_ALL_BEANINFO = 1;
-public static final int IGNORE_IMMEDIATE_BEANINFO = 2;
-public static final int IGNORE_ALL_BEANINFO = 3;
-
-private static String[] beansearch = { "kaffe.beans.infos" };
-
-private static Hashtable cache = new Hashtable();
-
-private static final String ADD = "add";
-private static final String GET = "get";
-private static final String IS = "is";
-private static final String LISTENER = "Listener";
-private static final String REMOVE = "remove";
-private static final String SET = "set";
-private static final int ADD_LENGTH = ADD.length();
-private static final int GET_LENGTH = GET.length();
-private static final int IS_LENGTH = IS.length();
-private static final int LISTENER_LENGTH = LISTENER.length();
-private static final int REMOVE_LENGTH = REMOVE.length();
-private static final int SET_LENGTH = SET.length();
-
-private static final String BEAN_INFO = "BeanInfo";
-private static final String ADD_PROPERTY_CHANGE_LISTENER = ADD + "PropertyChange" + LISTENER;
-
-private Introspector() {}
+
+ public static final int USE_ALL_BEANINFO = 1;
+ public static final int IGNORE_IMMEDIATE_BEANINFO = 2;
+ public static final int IGNORE_ALL_BEANINFO = 3;
+
+ static String[] beanInfoSearchPath = {"gnu.java.beans.info"};
+ static Hashtable beanInfoCache = new Hashtable();
+
+ private Introspector() {}
+
+ /**
+ * Get the BeanInfo for class <CODE>beanClass</CODE>,
+ * first by looking for explicit information, next by
+ * using standard design patterns to determine
+ * information about the class.
+ *
+ * @param beanClass the class to get BeanInfo about.
+ * @return the BeanInfo object representing the class.
+ */
+ public static BeanInfo getBeanInfo(Class beanClass)
+ throws IntrospectionException
+ {
+ BeanInfo cachedInfo;
+ synchronized(beanClass)
+ {
+ cachedInfo = (BeanInfo)beanInfoCache.get(beanClass);
+ if(cachedInfo != null)
+ {
+ return cachedInfo;
+ }
+ cachedInfo = getBeanInfo(beanClass,null);
+ beanInfoCache.put(beanClass,cachedInfo);
+ return cachedInfo;
+ }
+ }
+
+ /**
+ * Flush all of the Introspector's internal caches.
+ *
+ * @since 1.2
+ */
+ public static void flushCaches()
+ {
+ beanInfoCache.clear();
+ }
+
+ /**
+ * Flush the Introspector's internal cached information for a given
+ * class.
+ *
+ * @param clz the class to be flushed.
+ * @throws NullPointerException if clz is null.
+ * @since 1.2
+ */
+ public static void flushFromCaches(Class clz)
+ {
+ synchronized (clz)
+ {
+ beanInfoCache.remove(clz);
+ }
+ }
+
+ /**
+ * Get the BeanInfo for class <CODE>beanClass</CODE>,
+ * first by looking for explicit information, next by
+ * using standard design patterns to determine
+ * information about the class. It crawls up the
+ * inheritance tree until it hits <CODE>topClass</CODE>.
+ *
+ * @param beanClass the Bean class.
+ * @param stopClass the class to stop at.
+ * @return the BeanInfo object representing the class.
+ */
+ public static BeanInfo getBeanInfo(Class beanClass, Class stopClass)
+ throws IntrospectionException
+ {
+ ExplicitInfo explicit = new ExplicitInfo(beanClass,stopClass);
-public static String decapitalize(String name) {
- if (name.length() > 2 && Character.isUpperCase(name.charAt(0)) && Character.isUpperCase(name.charAt(1))) {
- return (name);
- }
- else if (name.length() > 0) { /* empty string */
- return (Character.toLowerCase(name.charAt(0)) + name.substring(1));
- }
- else {
- return (name);
- }
-}
-
-public static BeanInfo getBeanInfo(Class beanClass) throws IntrospectionException {
- return (getBeanInfo(beanClass, null));
-}
-
-public static BeanInfo getBeanInfo(Class beanClass, Class stopClass) throws IntrospectionException {
-
- Object cobj = cache.get(beanClass);
- if (cobj != null) {
- return ((BeanInfo)cobj);
- }
-
- BeanInfo bean = loadBeanInfo(beanClass);
-
- // Check stop class is really a superclass of bean class
- if (stopClass != null
- && (!stopClass.isAssignableFrom(beanClass)
- || beanClass.isInterface())) {
- throw new IntrospectionException(stopClass.getName()
- + " not superclass of " + beanClass.getName());
- }
-
- BeanDescriptor desc = null;
- PropertyDescriptor[] props = null;
- MethodDescriptor[] meths = null;
- EventSetDescriptor[] events = null;
- int dprops = -1;
- int devents = -1;
-
- // If we found a bean info, use as much of that as there is.
- if (bean != null) {
- desc = bean.getBeanDescriptor();
- props = bean.getPropertyDescriptors();
- meths = bean.getMethodDescriptors();
- events = bean.getEventSetDescriptors();
- dprops = bean.getDefaultPropertyIndex();
- devents = bean.getDefaultEventIndex();
- }
-
- // Introspect the rest.
- if (desc == null) {
- desc = new BeanDescriptor(beanClass);
- }
- if (props == null) {
- props = getProperties(beanClass, stopClass);
- }
- if (meths == null) {
- meths = getMethods(beanClass, stopClass);
- }
- if (events == null) {
- events = getListeners(beanClass, stopClass);
- }
-
- bean = new GenericBeanInfo(desc, props, meths, events, devents, dprops, bean);
- cache.put(beanClass, bean);
- return (bean);
-}
-
-public static String[] getBeanInfoSearchPath() {
- return (beansearch);
-}
-
-private static EventSetDescriptor[] getListeners(Class startClass, Class stopClass) throws IntrospectionException {
- Hashtable addMethods = new Hashtable();
- Hashtable removeMethods = new Hashtable();
- Hashtable keys = new Hashtable();
- Hashtable listenerClasses = new Hashtable();
-
- for (Class cls = startClass; cls != stopClass; cls = cls.getSuperclass()) {
- Method[] meths = cls.getDeclaredMethods();
- for (int i = 0; i < meths.length; i++) {
- Method method = meths[i];
- int modifiers = method.getModifiers();
- if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)) {
- String mname = method.getName();
- if (mname.startsWith(ADD) && mname.endsWith(LISTENER)) {
- mname = mname.substring(ADD_LENGTH, mname.length() - LISTENER_LENGTH);
- keys.put(mname, mname);
- /* XXX: Do we need to check that
- * there's only one parameter?
- */
- listenerClasses.put(mname, method.getParameterTypes()[0]);
- if (addMethods.get(mname) == null) {
- addMethods.put(mname, method);
- }
- }
- else if (mname.startsWith(REMOVE) && mname.endsWith(LISTENER)) {
- mname = mname.substring(REMOVE_LENGTH, mname.length() - LISTENER_LENGTH);
- keys.put(mname, mname);
- if (removeMethods.get(mname) == null) {
- removeMethods.put(mname, method);
- }
- }
- }
- }
- }
-
- // Now look through add/remove methods and create descriptors.
- EventSetDescriptor props[] = new EventSetDescriptor[keys.size()];
- Enumeration k = keys.elements();
- for (int i = 0; i < props.length; i++) {
- String key = (String)k.nextElement();
- Method add = (Method)addMethods.get(key);
- Method remove = (Method)removeMethods.get(key);
- Class listenerType = (Class)listenerClasses.get(key);
- if (add != null && remove != null) {
- props[i] = new EventSetDescriptor(decapitalize(key), listenerType, listenerType.getDeclaredMethods(), add, remove);
-
- Class except[] = add.getExceptionTypes();
- if (except != null) {
- for (int j = 0; j < except.length; j++) {
- try {
- if (except[j].newInstance() instanceof TooManyListenersException) {
- props[i].setUnicast(true);
- break;
- }
- }
- catch (IllegalAccessException _) {
- }
- catch (InstantiationException _) {
- }
- }
- }
- }
- }
-
- return (props);
-}
-
-private static MethodDescriptor[] getMethods(Class startClass, Class stopClass) throws IntrospectionException {
- Hashtable hash = new Hashtable();
-
- for (Class cls = startClass; cls != stopClass; cls = cls.getSuperclass()) {
- Method[] meths = cls.getDeclaredMethods();
- for (int i = 0; i < meths.length; i++) {
-
- if (!Modifier.isPublic(meths[i].getModifiers())) {
- continue;
- }
-
- String mname = meths[i].toString();
- if (hash.get(mname) == null) {
- hash.put(mname, meths[i]);
- }
- }
- }
-
- MethodDescriptor[] methdesc = new MethodDescriptor[hash.size()];
- Enumeration e = hash.elements();
- for (int i = 0; i < methdesc.length; i++) {
- methdesc[i] = new MethodDescriptor((Method)e.nextElement());
- }
-
- return (methdesc);
-}
-
-private static PropertyDescriptor[] getProperties(Class startClass, Class stopClass) throws IntrospectionException {
- Hashtable setMethods = new Hashtable();
- Hashtable getMethods = new Hashtable();
- Hashtable setIdxMethods = new Hashtable();
- Hashtable getIdxMethods = new Hashtable();
- Hashtable keys = new Hashtable();
-
- for (Class cls = startClass; cls != stopClass; cls = cls.getSuperclass()) {
- Method[] meths = cls.getDeclaredMethods();
- for (int i = 0; i < meths.length; i++) {
-
- Method meth = meths[i];
-
- // We should only consider public non-statics.
- int mod = meth.getModifiers();
- if (!Modifier.isPublic(mod) || Modifier.isStatic(mod)) {
- continue;
- }
-
- String mname = meth.getName();
- Class[] mclasses = meth.getParameterTypes();
-
- switch (mclasses.length) {
- case 0:
- if (mname.startsWith(GET)
- && !mname.equals(GET)) {
- mname = mname.substring(GET_LENGTH);
- keys.put(mname, mname);
- if (getMethods.get(mname) == null) {
- getMethods.put(mname, meth);
- }
- }
- else if (mname.startsWith(IS)
- && !mname.equals(IS)) {
- mname = mname.substring(IS_LENGTH);
- keys.put(mname, mname);
- if (getMethods.get(mname) == null) {
- getMethods.put(mname, meth);
- }
- }
- break;
-
- case 1:
- if (mname.startsWith(SET)
- && !mname.equals(SET)
- && meth.getReturnType().equals(Void.TYPE)) {
- mname = mname.substring(SET_LENGTH);
- keys.put(mname, mname);
- if (setMethods.get(mname) == null) {
- setMethods.put(mname, meth);
- }
- }
- else if (mname.startsWith(GET)
- && !mname.equals(GET)
- && mclasses[0] == Integer.TYPE) {
- mname = mname.substring(GET_LENGTH);
- keys.put(mname, mname);
- if (getIdxMethods.get(mname) == null) {
- getIdxMethods.put(mname, meth);
- }
- }
- break;
-
- case 2:
- if (mname.startsWith(SET)
- && !mname.equals(SET)
- && meth.getReturnType().equals(Void.TYPE)
- && mclasses[0] == Integer.TYPE) {
- mname = mname.substring(SET_LENGTH);
- keys.put(mname, mname);
- if (setIdxMethods.get(mname) == null) {
- setIdxMethods.put(mname, meth);
- }
- }
- break;
- }
-
- }
- }
-
- // check if the bean fires PropertyChangeEvent
- boolean bound = false;
-
- try {
- startClass.getMethod(ADD_PROPERTY_CHANGE_LISTENER, new Class [] {PropertyChangeListener.class});
- bound = true;
- }
- catch (NoSuchMethodException e) {
- /* the bean does not allow to add property change listeners,
- * thus it does not fire poperty change events, i.e. its
- * properties are not bound.
- */
- }
-
- // Now look through set/get methods and create desciptors.
- // Eliminate any methods that don't make sense.
- PropertyDescriptor props[] = new PropertyDescriptor[keys.size()];
-
- Enumeration k = keys.elements();
- for (int i = 0; i < props.length; i++) {
- String key = (String)k.nextElement();
- Method set = (Method)setMethods.get(key);
- Method get = (Method)getMethods.get(key);
- Method setidx = (Method)setIdxMethods.get(key);
- Method getidx = (Method)getIdxMethods.get(key);
- if (setidx == null && getidx == null) {
- if (get != null && set != null) {
- if (!set.getReturnType().equals(Void.TYPE))
- set = null;
- else if (!get.getReturnType().equals(
- set.getParameterTypes()[0]))
- get = null;
- }
- props[i] = new PropertyDescriptor(
- decapitalize(key), get, set);
- }
- else {
- if (getidx != null && setidx != null) {
- if (!setidx.getReturnType().equals(Void.TYPE))
- setidx = null;
- else if (!getidx.getReturnType().equals(
- setidx.getParameterTypes()[1]))
- getidx = null;
- }
- props[i] = new IndexedPropertyDescriptor(
- decapitalize(key), get, set, getidx, setidx);
- }
-
- if (bound) {
- props[i].setBound(true);
- }
- }
-
- return (props);
-}
-
-private static BeanInfo loadBeanInfo(Class beanClass) {
- String bname = beanClass.getName();
-
- // First try to load bean info from package.
- BeanInfo bean = loadNamedBean(beanClass.getClassLoader(),
- bname + BEAN_INFO);
- if (bean != null) {
- return (bean);
- }
-
- // Extract the name of the bean without package information.
- // We make allowances for both '.' and '/' seperators.
- int pos = bname.lastIndexOf('.');
- int spos = bname.lastIndexOf('/');
- if (spos > pos) {
- pos = spos;
- }
- bname = bname.substring(pos+1);
-
- // Next try the search paths
- for (int i = 0; i < beansearch.length; i++) {
- bean = loadNamedBean(beanClass.getClassLoader(),
- beansearch[i] + "." + bname + BEAN_INFO);
- if (bean != null) {
- return (bean);
- }
- }
-
- return (null);
-}
-
-private static BeanInfo loadNamedBean(ClassLoader loader, String cl) {
- try {
- return (BeanInfo)Class.forName(cl, true, loader).newInstance();
- }
- catch (ClassNotFoundException _) {
- }
- catch (ClassCastException _) {
- }
- catch (IllegalAccessException _) {
- }
- catch (InstantiationException _) {
- }
- return (null);
+ IntrospectionIncubator ii = new IntrospectionIncubator();
+ ii.setPropertyStopClass(explicit.propertyStopClass);
+ ii.setEventStopClass(explicit.eventStopClass);
+ ii.setMethodStopClass(explicit.methodStopClass);
+ ii.addMethods(beanClass.getMethods());
+
+ BeanInfoEmbryo currentInfo = ii.getBeanInfoEmbryo();
+ PropertyDescriptor[] p = explicit.explicitPropertyDescriptors;
+ if(p!=null)
+ {
+ for(int i=0;i<p.length;i++)
+ {
+ if(!currentInfo.hasProperty(p[i]))
+ {
+ currentInfo.addProperty(p[i]);
+ }
+ }
+ if(explicit.defaultProperty != -1)
+ {
+ currentInfo.setDefaultPropertyName(p[explicit.defaultProperty].getName());
+ }
+ }
+ EventSetDescriptor[] e = explicit.explicitEventSetDescriptors;
+ if(e!=null)
+ {
+ for(int i=0;i<e.length;i++)
+ {
+ if(!currentInfo.hasEvent(e[i]))
+ {
+ currentInfo.addEvent(e[i]);
+ }
+ }
+ if(explicit.defaultEvent != -1)
+ {
+ currentInfo.setDefaultEventName(e[explicit.defaultEvent].getName());
+ }
+ }
+ MethodDescriptor[] m = explicit.explicitMethodDescriptors;
+ if(m!=null)
+ {
+ for(int i=0;i<m.length;i++)
+ {
+ if(!currentInfo.hasMethod(m[i]))
+ {
+ currentInfo.addMethod(m[i]);
+ }
+ }
+ }
+
+ if(explicit.explicitBeanDescriptor != null)
+ {
+ currentInfo.setBeanDescriptor(new BeanDescriptor(beanClass,explicit.explicitBeanDescriptor.getCustomizerClass()));
+ }
+ else
+ {
+ currentInfo.setBeanDescriptor(new BeanDescriptor(beanClass,null));
+ }
+
+ currentInfo.setAdditionalBeanInfo(explicit.explicitBeanInfo);
+ currentInfo.setIcons(explicit.im);
+
+ return currentInfo.getBeanInfo();
+ }
+
+ /**
+ * Get the search path for BeanInfo classes.
+ *
+ * @return the BeanInfo search path.
+ */
+ public static String[] getBeanInfoSearchPath()
+ {
+ return beanInfoSearchPath;
+ }
+
+ /**
+ * Set the search path for BeanInfo classes.
+ * @param beanInfoSearchPath the new BeanInfo search
+ * path.
+ */
+ public static void setBeanInfoSearchPath(String[] beanInfoSearchPath)
+ {
+ Introspector.beanInfoSearchPath = beanInfoSearchPath;
+ }
+
+ /**
+ * A helper method to convert a name to standard Java
+ * naming conventions: anything with two capitals as the
+ * first two letters remains the same, otherwise the
+ * first letter is decapitalized. URL = URL, I = i,
+ * MyMethod = myMethod.
+ *
+ * @param name the name to decapitalize.
+ * @return the decapitalized name.
+ */
+ public static String decapitalize(String name)
+ {
+ try
+ {
+ if(!Character.isUpperCase(name.charAt(0)))
+ {
+ return name;
+ }
+ else
+ {
+ try
+ {
+ if(Character.isUpperCase(name.charAt(1)))
+ {
+ return name;
+ }
+ else
+ {
+ char[] c = name.toCharArray();
+ c[0] = Character.toLowerCase(c[0]);
+ return new String(c);
+ }
+ }
+ catch(StringIndexOutOfBoundsException E)
+ {
+ char[] c = new char[1];
+ c[0] = Character.toLowerCase(name.charAt(0));
+ return new String(c);
+ }
+ }
+ }
+ catch(StringIndexOutOfBoundsException E)
+ {
+ return name;
+ }
+ catch(NullPointerException E)
+ {
+ return null;
+ }
+ }
+
+ static BeanInfo copyBeanInfo(BeanInfo b)
+ {
+ java.awt.Image[] icons = new java.awt.Image[4];
+ for(int i=1;i<=4;i++)
+ {
+ icons[i-1] = b.getIcon(i);
+ }
+ return new ExplicitBeanInfo(b.getBeanDescriptor(),
+ b.getAdditionalBeanInfo(),
+ b.getPropertyDescriptors(),
+ b.getDefaultPropertyIndex(),
+ b.getEventSetDescriptors(),
+ b.getDefaultEventIndex(),
+ b.getMethodDescriptors(),icons);
+ }
}
-public static void setBeanInfoSearchPath(String path[]) {
- beansearch = path;
-}
+class ExplicitInfo
+{
+ BeanDescriptor explicitBeanDescriptor;
+ BeanInfo[] explicitBeanInfo;
+
+ PropertyDescriptor[] explicitPropertyDescriptors;
+ EventSetDescriptor[] explicitEventSetDescriptors;
+ MethodDescriptor[] explicitMethodDescriptors;
+
+ int defaultProperty;
+ int defaultEvent;
+
+ java.awt.Image[] im = new java.awt.Image[4];
+
+ Class propertyStopClass;
+ Class eventStopClass;
+ Class methodStopClass;
+
+ ExplicitInfo(Class beanClass, Class stopClass)
+ {
+ while(beanClass != null && !beanClass.equals(stopClass))
+ {
+ BeanInfo explicit = findExplicitBeanInfo(beanClass);
+ if(explicit != null)
+ {
+ if(explicitBeanDescriptor == null)
+ {
+ explicitBeanDescriptor = explicit.getBeanDescriptor();
+ }
+ if(explicitBeanInfo == null)
+ {
+ explicitBeanInfo = explicit.getAdditionalBeanInfo();
+ }
+ if(explicitPropertyDescriptors == null)
+ {
+ if(explicit.getPropertyDescriptors() != null)
+ {
+ explicitPropertyDescriptors = explicit.getPropertyDescriptors();
+ defaultProperty = explicit.getDefaultPropertyIndex();
+ propertyStopClass = beanClass;
+ }
+ }
+ if(explicitEventSetDescriptors == null)
+ {
+ if(explicit.getEventSetDescriptors() != null)
+ {
+ explicitEventSetDescriptors = explicit.getEventSetDescriptors();
+ defaultEvent = explicit.getDefaultEventIndex();
+ eventStopClass = beanClass;
+ }
+ }
+ if(explicitMethodDescriptors == null)
+ {
+ if(explicit.getMethodDescriptors() != null)
+ {
+ explicitMethodDescriptors = explicit.getMethodDescriptors();
+ methodStopClass = beanClass;
+ }
+ }
+ if(im[0] == null && im[1] == null
+ && im[2] == null && im[3] == null)
+ {
+ im[0] = explicit.getIcon(0);
+ im[1] = explicit.getIcon(1);
+ im[2] = explicit.getIcon(2);
+ im[3] = explicit.getIcon(3);
+ }
+ }
+ beanClass = beanClass.getSuperclass();
+ }
+ if(propertyStopClass == null)
+ {
+ propertyStopClass = stopClass;
+ }
+ if(eventStopClass == null)
+ {
+ eventStopClass = stopClass;
+ }
+ if(methodStopClass == null)
+ {
+ methodStopClass = stopClass;
+ }
+ }
+
+ static Hashtable explicitBeanInfos = new Hashtable();
+ static Vector emptyBeanInfos = new Vector();
+
+ static BeanInfo findExplicitBeanInfo(Class beanClass)
+ {
+ BeanInfo retval = (BeanInfo)explicitBeanInfos.get(beanClass);
+ if(retval != null)
+ {
+ return retval;
+ }
+ else if(emptyBeanInfos.indexOf(beanClass) != -1)
+ {
+ return null;
+ }
+ else
+ {
+ retval = reallyFindExplicitBeanInfo(beanClass);
+ if(retval != null)
+ {
+ explicitBeanInfos.put(beanClass,retval);
+ }
+ else
+ {
+ emptyBeanInfos.addElement(beanClass);
+ }
+ return retval;
+ }
+ }
+
+ static BeanInfo reallyFindExplicitBeanInfo(Class beanClass)
+ {
+ ClassLoader beanClassLoader = beanClass.getClassLoader();
+ BeanInfo beanInfo;
+
+ beanInfo = getBeanInfo(beanClassLoader, beanClass.getName() + "BeanInfo");
+ if (beanInfo == null)
+ {
+ String newName;
+ newName = ClassHelper.getTruncatedClassName(beanClass) + "BeanInfo";
+
+ for(int i = 0; i < Introspector.beanInfoSearchPath.length; i++)
+ {
+ if (Introspector.beanInfoSearchPath[i].equals(""))
+ beanInfo = getBeanInfo(beanClassLoader, newName);
+ else
+ beanInfo = getBeanInfo(beanClassLoader,
+ Introspector.beanInfoSearchPath[i] + "."
+ + newName);
+
+ if (beanInfo != null)
+ return beanInfo;
+ }
+ }
+
+ return beanInfo;
+ }
+
+ /**
+ * Returns an instance of the given class name when it can be loaded
+ * through the given class loader, or null otherwise.
+ */
+ private static BeanInfo getBeanInfo(ClassLoader cl, String infoName)
+ {
+ try
+ {
+ return (BeanInfo) Class.forName(infoName, true, cl).newInstance();
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ return null;
+ }
+ catch (IllegalAccessException iae)
*** Patch too long, truncated ***
More information about the kaffe
mailing list