📄 introspector.java
字号:
{ currentInfo.addMethod(m[i]); } } } // Sets the info's BeanDescriptor to the one we extracted from the // explicit BeanInfo instance(s) if they contained one. Otherwise we // create the BeanDescriptor from scratch. // Note: We do not create a copy the retrieved BeanDescriptor which will allow // the user to modify the instance while it is cached. However this is how // the RI does it. currentInfo.setBeanDescriptor( (explicit.explicitBeanDescriptor == null ? new BeanDescriptor(beanClass, null) : explicit.explicitBeanDescriptor)); 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); }}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; static Hashtable explicitBeanInfos = new Hashtable(); static Vector emptyBeanInfos = new Vector(); 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; } } /** Throws away all cached data and makes sure we re-instantiate things * like BeanDescriptors again. */ static void flushCaches() { explicitBeanInfos.clear(); emptyBeanInfos.clear(); } 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); // Returns the beanInfo if it exists and the described class matches // the one we searched. if (beanInfo != null && beanInfo.getBeanDescriptor() != null && beanInfo.getBeanDescriptor().getBeanClass() == beanClass) 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) { return null; } catch (InstantiationException ie) { return null; } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -