View Javadoc
1 package xdoclet.sdk.xtag.migrator; 2 3 import java.awt.Image; 4 import java.beans.BeanDescriptor; 5 import java.beans.BeanInfo; 6 import java.beans.Introspector; 7 import java.beans.IntrospectionException; 8 import java.beans.PropertyDescriptor; 9 import java.beans.ParameterDescriptor; 10 import java.beans.MethodDescriptor; 11 import java.beans.SimpleBeanInfo; 12 import java.beans.PropertyEditorManager; 13 import java.lang.reflect.Method; 14 import java.util.List; 15 import java.util.ArrayList; 16 import java.util.Map; 17 import java.util.HashMap; 18 19 /*** 20 * BeanInfo for OptionSets. 21 */ 22 public class OptionSetsBeanInfo extends SimpleBeanInfo { 23 24 /*** 25 * The BeanInfo provided by java.beans.Introspector. 26 */ 27 private final BeanInfo _introspectedBeanInfo; 28 29 private Map _icons = new HashMap(); 30 31 32 private final String _defaultProperty = null; 33 34 private final BeanDescriptor _beanDescriptor = new BeanDescriptor( xdoclet.sdk.xtag.migrator.OptionSets.class ); 35 36 private MethodDescriptor[] _methodDescriptors; 37 private PropertyDescriptor[] _propertyDescriptors; 38 39 public OptionSetsBeanInfo() throws java.beans.IntrospectionException { 40 // Let the Introspector do the dirty work. 41 _introspectedBeanInfo = Introspector.getBeanInfo( xdoclet.sdk.xtag.migrator.OptionSets.class, Introspector.IGNORE_ALL_BEANINFO ); 42 43 createPropertyDescriptors(); 44 try { 45 createMethodDescriptors(); 46 } catch( NoSuchMethodException e ) { 47 throw new IntrospectionException( e.getMessage() ); 48 } 49 50 try{ 51 _beanDescriptor.setName("option-sets"); 52 53 54 // Set property descriptors from superclass 55 BeanInfo info = Introspector.getBeanInfo(getBeanDescriptor().getBeanClass().getSuperclass()); 56 String order = info.getBeanDescriptor().getValue("propertyorder") == null ? "" : (String) info.getBeanDescriptor().getValue("propertyorder"); 57 PropertyDescriptor[] pd = getPropertyDescriptors(); 58 if( pd != null ) { 59 for (int i = 0; i != pd.length; i++) { 60 if (order.indexOf(pd[i].getName()) == -1) { 61 order = order + (order.length() == 0 ? "" : ":") + pd[i].getName(); 62 } 63 } 64 } 65 getBeanDescriptor().setValue("propertyorder", order); 66 67 }catch(Throwable t){t.printStackTrace();} 68 } 69 70 /*** 71 * Gets the additional BeanInfo. 72 * 73 * @return additional BeanInfo. 74 */ 75 public BeanInfo[] getAdditionalBeanInfo() { 76 List bi = new ArrayList(); 77 BeanInfo[] result = null; 78 return result; 79 } 80 81 public Image getIcon( int iconKind ) { 82 return (Image) _icons.get( new Integer( iconKind ) ); 83 } 84 85 /*** 86 * Gets the BeanDescriptor. 87 * 88 * @return The BeanDescriptor. 89 */ 90 public BeanDescriptor getBeanDescriptor() { 91 return _beanDescriptor; 92 } 93 94 /*** 95 * Gets the defaultPropertyIndex 96 * 97 * @return The defaultPropertyIndex value 98 */ 99 public int getDefaultPropertyIndex() { 100 if (_defaultProperty == null) { 101 return -1; 102 } 103 PropertyDescriptor[] pd = getPropertyDescriptors(); 104 for (int i = 0; i < pd.length; i++) { 105 if (pd[i].getName().equals(_defaultProperty)) { 106 return i; 107 } 108 } 109 return -1; 110 } 111 112 private void createPropertyDescriptors() { 113 // Map the existing property descriptors for easier manipulation. 114 Map propertyMap = new HashMap(); 115 116 _propertyDescriptors = _introspectedBeanInfo.getPropertyDescriptors(); 117 for( int i = 0; i < _propertyDescriptors.length; i++ ) { 118 // Set them to hidden. We'll adjust that further down. 119 _propertyDescriptors[ i ].setHidden( true ); 120 propertyMap.put( _propertyDescriptors[ i ].getName() + ":" + _propertyDescriptors[ i ].getPropertyType().getName(), _propertyDescriptors[ i ] ); 121 } 122 PropertyDescriptor propertyDescriptor = null; 123 } 124 125 public PropertyDescriptor[] getPropertyDescriptors() { 126 return _propertyDescriptors; 127 } 128 129 private void createMethodDescriptors() throws NoSuchMethodException { 130 // Map the existing method descriptors for easier manipulation. 131 Map methodMap = new HashMap(); 132 133 MethodDescriptor[] methodDescriptors = _introspectedBeanInfo.getMethodDescriptors(); 134 for( int i = 0; i < methodDescriptors.length; i++ ) { 135 // Set them to expert. We'll adjust that further down. 136 methodDescriptors[ i ].setHidden( true ); 137 methodMap.put( methodDescriptors[ i ].getMethod(), methodDescriptors[ i ] ); 138 } 139 Method method = null; 140 // The original introspected MethodDescriptor 141 MethodDescriptor methodDescriptor = null; 142 // The new methodDescriptor 143 MethodDescriptor methodDescriptor2 = null; 144 ParameterDescriptor[] parameterDescriptors = null; 145 List methodList = new ArrayList(methodMap.values()); 146 _methodDescriptors = (MethodDescriptor[]) methodList.toArray(new MethodDescriptor[methodMap.size()]); 147 } 148 149 public MethodDescriptor[] getMethodDescriptors() { 150 return _methodDescriptors; 151 } 152 }

This page was automatically generated by Maven