/* gnu.java.beans.IntrospectionIncubator Copyright (C) 1998 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. As a special exception, if you link this library with other files to produce an executable, this library does not by itself cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ package gnu.java.beans; import java.beans.*; import java.util.*; import java.lang.reflect.*; import gnu.java.lang.*; /** ** IntrospectionIncubator takes in a bunch of Methods, and ** Introspects only those Methods you give it. ** ** @author John Keiser ** @version 1.1.0, 30 Jul 1998 ** @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() { } /* Paving the way for automatic Introspection */ public void addMethod(Method method) { if(Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers())) { String name = ClassHelper.getTruncatedName(method.getName()); Class retType = method.getReturnType(); Class[] params = method.getParameterTypes(); boolean isVoid = retType.equals(java.lang.Void.TYPE); Class methodClass = method.getDeclaringClass(); if(propertyStopClass == null || (propertyStopClass.isAssignableFrom(methodClass) && !propertyStopClass.equals(methodClass))) { if(name.startsWith("is") && retType.equals(java.lang.Boolean.TYPE) && params.length == 0) { addToPropertyHash(name,method,IS); } else if(name.startsWith("get") && !isVoid) { if(params.length == 0) { addToPropertyHash(name,method,GET); } else if(params.length == 1 && params[0].equals(java.lang.Integer.TYPE)) { addToPropertyHash(name,method,GET_I); } else { otherMethods.addElement(method); } } else if(name.startsWith("set") && isVoid) { if(params.length == 1) { addToPropertyHash(name,method,SET); } else if(params.length == 2 && params[0].equals(java.lang.Integer.TYPE)) { addToPropertyHash(name,method,SET_I); } else { otherMethods.addElement(method); } } } if(eventStopClass == null || (eventStopClass.isAssignableFrom(methodClass) && !eventStopClass.equals(methodClass))) { if(name.startsWith("add") && isVoid && params.length == 1 && java.util.EventListener.class.isAssignableFrom(params[0])) { addToListenerHash(name,method,ADD); } else if(name.startsWith("remove") && isVoid && params.length == 1 && java.util.EventListener.class.isAssignableFrom(params[0])) { addToListenerHash(name,method,REMOVE); } } if(methodStopClass == null || (methodStopClass.isAssignableFrom(methodClass) && !methodStopClass.equals(methodClass))) { otherMethods.addElement(method); } } } public void addMethods(Method[] m) { for(int i=0;i