On Fri, 24 Oct 2003 16:46:20 +0200 (CEST) Arnaud Vandyck <[EMAIL PROTECTED]> wrote:
> On Fri, 24 Oct 2003 16:21:47 +0200 > Mark Wielaard <[EMAIL PROTECTED]> wrote: > > [gnu/java/beans/IntrospectionIncubator.java] > > > That file is really badly formatted (but was already in the Classpath > > tree). If someone wants to clean that up, that would be very > > appreciated. > > I have to learn so I can reformat this file. I'll send a patch asap ;) Attached is the patch and here is the Changelog entry: 2003-10-24 Arnaud Vandyck <[EMAIL PROTECTED]> * gnu/java/beans/IntrospectionIncubator.java: reformated to conform to the GNU standards Waiting for your comments, thanks, -- Arnaud Vandyck, STE fi, ULg Formateur Cellule Programmation.
Index: IntrospectionIncubator.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/beans/IntrospectionIncubator.java,v retrieving revision 1.11 diff -u -r1.11 IntrospectionIncubator.java --- IntrospectionIncubator.java 24 Oct 2003 14:19:35 -0000 1.11 +++ IntrospectionIncubator.java 24 Oct 2003 15:16:55 -0000 @@ -53,303 +53,383 @@ ** @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())) { - 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<m.length;i++) { - addMethod(m[i]); - } - } - - public void setPropertyStopClass(Class c) { - propertyStopClass = c; - } - - public void setEventStopClass(Class c) { - eventStopClass = c; - } - - public void setMethodStopClass(Class c) { - methodStopClass = c; - } - - - public BeanInfoEmbryo getBeanInfoEmbryo() throws IntrospectionException { - BeanInfoEmbryo b = new BeanInfoEmbryo(); - findXXX(b,IS); - findXXXInt(b,GET_I); - findXXXInt(b,SET_I); - findXXX(b,GET); - findXXX(b,SET); - findAddRemovePairs(b); - for(int i=0;i<otherMethods.size();i++) { - MethodDescriptor newMethod = new MethodDescriptor((Method)otherMethods.elementAt(i)); - if(!b.hasMethod(newMethod)) { - b.addMethod(new MethodDescriptor((Method)otherMethods.elementAt(i))); - } - } - return b; - } - - public BeanInfo getBeanInfo() throws IntrospectionException { - return getBeanInfoEmbryo().getBeanInfo(); - } - - - void findAddRemovePairs(BeanInfoEmbryo b) throws IntrospectionException { - Enumeration listenerEnum = listenerMethods.keys(); - while(listenerEnum.hasMoreElements()) { - DoubleKey k = (DoubleKey)listenerEnum.nextElement(); - Method[] m = (Method[])listenerMethods.get(k); - if(m[ADD] != null && m[REMOVE] != null) { - EventSetDescriptor e = new EventSetDescriptor(Introspector.decapitalize(k.getName()), - k.getType(), k.getType().getMethods(), - m[ADD],m[REMOVE]); - e.setUnicast(ArrayHelper.contains(m[ADD].getExceptionTypes(),java.util.TooManyListenersException.class)); - if(!b.hasEvent(e)) { - b.addEvent(e); - } - } - } - } - - void findXXX(BeanInfoEmbryo b, int funcType) throws IntrospectionException { - Enumeration keys = propertyMethods.keys(); - while(keys.hasMoreElements()) { - DoubleKey k = (DoubleKey)keys.nextElement(); - Method[] m = (Method[])propertyMethods.get(k); - if(m[funcType] != null) { - PropertyDescriptor p = new PropertyDescriptor(Introspector.decapitalize(k.getName()), - m[IS] != null ? m[IS] : m[GET], - m[SET]); - if(m[SET] != null) { - p.setConstrained(ArrayHelper.contains(m[SET].getExceptionTypes(),java.beans.PropertyVetoException.class)); - } - if(!b.hasProperty(p)) { - b.addProperty(p); - } - } - } - } - - void findXXXInt(BeanInfoEmbryo b, int funcType) throws IntrospectionException { - Enumeration keys = propertyMethods.keys(); - while(keys.hasMoreElements()) { - DoubleKey k = (DoubleKey)keys.nextElement(); - Method[] m = (Method[])propertyMethods.get(k); - if(m[funcType] != null) { - boolean constrained; - if(m[SET_I] != null) { - constrained = ArrayHelper.contains(m[SET_I].getExceptionTypes(),java.beans.PropertyVetoException.class); - } else { - constrained = false; - } - - /** Find out if there is an array type get or set **/ - Class arrayType = Array.newInstance(k.getType(),0).getClass(); - DoubleKey findSetArray = new DoubleKey(arrayType,k.getName()); - Method[] m2 = (Method[])propertyMethods.get(findSetArray); - IndexedPropertyDescriptor p; - if(m2 == null) { - p = new IndexedPropertyDescriptor(Introspector.decapitalize(k.getName()), - null,null, - m[GET_I],m[SET_I]); - } else { - if(constrained && m2[SET] != null) { - constrained = ArrayHelper.contains(m2[SET].getExceptionTypes(),java.beans.PropertyVetoException.class); - } - p = new IndexedPropertyDescriptor(Introspector.decapitalize(k.getName()), - m2[GET],m2[SET], - m[GET_I],m[SET_I]); - } - p.setConstrained(constrained); - if(!b.hasProperty(p)) { - b.addProperty(p); - } - } - } - } - - static final int IS=0; - static final int GET_I=1; - static final int SET_I=2; - static final int GET=3; - static final int SET=4; - - static final int ADD=0; - static final int REMOVE=1; - - void addToPropertyHash(String name, Method method, int funcType) { - String newName; - Class type; - - switch(funcType) { - case IS: - type = java.lang.Boolean.TYPE; - newName = name.substring(2); - break; - case GET_I: - type = method.getReturnType(); - newName = name.substring(3); - break; - case SET_I: - type = method.getParameterTypes()[1]; - newName = name.substring(3); - break; - case GET: - type = method.getReturnType(); - newName = name.substring(3); - break; - case SET: - type = method.getParameterTypes()[0]; - newName = name.substring(3); - break; - default: - return; - } - newName = capitalize(newName); - - DoubleKey k = new DoubleKey(type,newName); - Method[] methods = (Method[])propertyMethods.get(k); - if(methods == null) { - methods = new Method[5]; - propertyMethods.put(k,methods); - } - methods[funcType] = method; - } - - - void addToListenerHash(String name, Method method, int funcType) { - String newName; - Class type; - - switch(funcType) { - case ADD: - type = method.getParameterTypes()[0]; - newName = name.substring(3,name.length()-8); - break; - case REMOVE: - type = method.getParameterTypes()[0]; - newName = name.substring(6,name.length()-8); - break; - default: - return; - } - newName = capitalize(newName); - - DoubleKey k = new DoubleKey(type,newName); - Method[] methods = (Method[])listenerMethods.get(k); - if(methods == null) { - methods = new Method[2]; - listenerMethods.put(k,methods); - } - methods[funcType] = method; - } - - 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; - } - } +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 ())) + { + 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<m.length;i++) + { + addMethod (m[i]); + } + } + + public void setPropertyStopClass (Class c) + { + propertyStopClass = c; + } + + public void setEventStopClass (Class c) + { + eventStopClass = c; + } + + public void setMethodStopClass (Class c) + { + methodStopClass = c; + } + + + public BeanInfoEmbryo getBeanInfoEmbryo () + throws IntrospectionException + { + BeanInfoEmbryo b = new BeanInfoEmbryo (); + findXXX (b,IS); + findXXXInt (b,GET_I); + findXXXInt (b,SET_I); + findXXX (b,GET); + findXXX (b,SET); + findAddRemovePairs (b); + for (int i=0;i<otherMethods.size ();i++) + { + MethodDescriptor newMethod = new MethodDescriptor ( (Method)otherMethods.elementAt (i)); + if(!b.hasMethod (newMethod)) + { + b.addMethod (new MethodDescriptor ( (Method)otherMethods.elementAt(i))); + } + } + return b; + } + + public BeanInfo getBeanInfo () throws IntrospectionException + { + return getBeanInfoEmbryo ().getBeanInfo (); + } + + void findAddRemovePairs (BeanInfoEmbryo b) + throws IntrospectionException + { + Enumeration listenerEnum = listenerMethods.keys (); + while (listenerEnum.hasMoreElements ()) { + DoubleKey k = (DoubleKey)listenerEnum.nextElement (); + Method[] m = (Method[])listenerMethods.get (k); + if (m[ADD] != null && m[REMOVE] != null) + { + EventSetDescriptor e = new EventSetDescriptor (Introspector.decapitalize (k.getName()), + k.getType (), k.getType ().getMethods (), + m[ADD],m[REMOVE]); + e.setUnicast (ArrayHelper.contains (m[ADD].getExceptionTypes (),java.util.TooManyListenersException.class)); + if (!b.hasEvent (e)) + { + b.addEvent (e); + } + } + } + } + + void findXXX (BeanInfoEmbryo b, int funcType) + throws IntrospectionException + { + Enumeration keys = propertyMethods.keys (); + while (keys.hasMoreElements ()) + { + DoubleKey k = (DoubleKey)keys.nextElement (); + Method[] m = (Method[])propertyMethods.get (k); + if (m[funcType] != null) + { + PropertyDescriptor p = new PropertyDescriptor (Introspector.decapitalize (k.getName()), + m[IS] != null ? m[IS] : m[GET], + m[SET]); + if (m[SET] != null) + { + p.setConstrained (ArrayHelper.contains (m[SET].getExceptionTypes (),java.beans.PropertyVetoException.class)); + } + if (!b.hasProperty (p)) + { + b.addProperty (p); + } + } + } + } + + void findXXXInt (BeanInfoEmbryo b, int funcType) + throws IntrospectionException + { + Enumeration keys = propertyMethods.keys (); + while (keys.hasMoreElements ()) + { + DoubleKey k = (DoubleKey)keys.nextElement (); + Method[] m = (Method[])propertyMethods.get (k); + if (m[funcType] != null) + { + boolean constrained; + if (m[SET_I] != null) + { + constrained = ArrayHelper.contains (m[SET_I].getExceptionTypes (),java.beans.PropertyVetoException.class); + } + else + { + constrained = false; + } + + /** Find out if there is an array type get or set **/ + Class arrayType = Array.newInstance (k.getType (),0).getClass (); + DoubleKey findSetArray = new DoubleKey (arrayType,k.getName ()); + Method[] m2 = (Method[])propertyMethods.get (findSetArray); + IndexedPropertyDescriptor p; + if (m2 == null) + { + p = new IndexedPropertyDescriptor (Introspector.decapitalize (k.getName ()), + null,null, + m[GET_I],m[SET_I]); + } + else + { + if (constrained && m2[SET] != null) + { + constrained = ArrayHelper.contains (m2[SET].getExceptionTypes (),java.beans.PropertyVetoException.class); + } + p = new IndexedPropertyDescriptor (Introspector.decapitalize (k.getName ()), + m2[GET],m2[SET], + m[GET_I],m[SET_I]); + } + p.setConstrained (constrained); + if (!b.hasProperty (p)) + { + b.addProperty (p); + } + } + } + } + + static final int IS=0; + static final int GET_I=1; + static final int SET_I=2; + static final int GET=3; + static final int SET=4; + + static final int ADD=0; + static final int REMOVE=1; + + void addToPropertyHash (String name, Method method, int funcType) + { + String newName; + Class type; + + switch (funcType) + { + case IS: + type = java.lang.Boolean.TYPE; + newName = name.substring (2); + break; + case GET_I: + type = method.getReturnType (); + newName = name.substring (3); + break; + case SET_I: + type = method.getParameterTypes ()[1]; + newName = name.substring (3); + break; + case GET: + type = method.getReturnType (); + newName = name.substring (3); + break; + case SET: + type = method.getParameterTypes ()[0]; + newName = name.substring (3); + break; + default: + return; + } + newName = capitalize (newName); + + DoubleKey k = new DoubleKey (type,newName); + Method[] methods = (Method[])propertyMethods.get (k); + if (methods == null) + { + methods = new Method[5]; + propertyMethods.put (k,methods); + } + methods[funcType] = method; + } + + + void addToListenerHash (String name, Method method, int funcType) + { + String newName; + Class type; + + switch (funcType) + { + case ADD: + type = method.getParameterTypes ()[0]; + newName = name.substring (3,name.length ()-8); + break; + case REMOVE: + type = method.getParameterTypes ()[0]; + newName = name.substring (6,name.length ()-8); + break; + default: + return; + } + newName = capitalize (newName); + + DoubleKey k = new DoubleKey (type,newName); + Method[] methods = (Method[])listenerMethods.get (k); + if (methods == null) + { + methods = new Method[2]; + listenerMethods.put (k,methods); + } + methods[funcType] = method; + } + + 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; + } + } } -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(); - } +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 (); + } }
_______________________________________________ Classpath mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/classpath