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 Parameter. 21 */ 22 public class ParameterBeanInfo 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.Parameter.class ); 35 36 private MethodDescriptor[] _methodDescriptors; 37 private PropertyDescriptor[] _propertyDescriptors; 38 39 public ParameterBeanInfo() throws java.beans.IntrospectionException { 40 // Let the Introspector do the dirty work. 41 _introspectedBeanInfo = Introspector.getBeanInfo( xdoclet.sdk.xtag.migrator.Parameter.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("parameter"); 52 53 _icons.put( new Integer(ICON_COLOR_16x16), loadImage( "jelly16.gif" ) ); 54 55 // Set property descriptors from superclass 56 BeanInfo info = Introspector.getBeanInfo(getBeanDescriptor().getBeanClass().getSuperclass()); 57 String order = info.getBeanDescriptor().getValue("propertyorder") == null ? "" : (String) info.getBeanDescriptor().getValue("propertyorder"); 58 PropertyDescriptor[] pd = getPropertyDescriptors(); 59 if( pd != null ) { 60 for (int i = 0; i != pd.length; i++) { 61 if (order.indexOf(pd[i].getName()) == -1) { 62 order = order + (order.length() == 0 ? "" : ":") + pd[i].getName(); 63 } 64 } 65 } 66 getBeanDescriptor().setValue("propertyorder", order); 67 68 }catch(Throwable t){t.printStackTrace();} 69 } 70 71 /*** 72 * Gets the additional BeanInfo. 73 * 74 * @return additional BeanInfo. 75 */ 76 public BeanInfo[] getAdditionalBeanInfo() { 77 List bi = new ArrayList(); 78 BeanInfo[] result = null; 79 return result; 80 } 81 82 public Image getIcon( int iconKind ) { 83 return (Image) _icons.get( new Integer( iconKind ) ); 84 } 85 86 /*** 87 * Gets the BeanDescriptor. 88 * 89 * @return The BeanDescriptor. 90 */ 91 public BeanDescriptor getBeanDescriptor() { 92 return _beanDescriptor; 93 } 94 95 /*** 96 * Gets the defaultPropertyIndex 97 * 98 * @return The defaultPropertyIndex value 99 */ 100 public int getDefaultPropertyIndex() { 101 if (_defaultProperty == null) { 102 return -1; 103 } 104 PropertyDescriptor[] pd = getPropertyDescriptors(); 105 for (int i = 0; i < pd.length; i++) { 106 if (pd[i].getName().equals(_defaultProperty)) { 107 return i; 108 } 109 } 110 return -1; 111 } 112 113 private void createPropertyDescriptors() { 114 // Map the existing property descriptors for easier manipulation. 115 Map propertyMap = new HashMap(); 116 117 _propertyDescriptors = _introspectedBeanInfo.getPropertyDescriptors(); 118 for( int i = 0; i < _propertyDescriptors.length; i++ ) { 119 // Set them to hidden. We'll adjust that further down. 120 _propertyDescriptors[ i ].setHidden( true ); 121 propertyMap.put( _propertyDescriptors[ i ].getName() + ":" + _propertyDescriptors[ i ].getPropertyType().getName(), _propertyDescriptors[ i ] ); 122 } 123 PropertyDescriptor propertyDescriptor = null; 124 propertyDescriptor = (PropertyDescriptor) propertyMap.get( "name:xdoclet.sdk.xtag.migrator.Name" ); 125 propertyDescriptor.setName( "name" ); 126 propertyDescriptor.setHidden( false ); 127 propertyDescriptor = (PropertyDescriptor) propertyMap.get( "optionSets:xdoclet.sdk.xtag.migrator.OptionSets" ); 128 propertyDescriptor.setName( "option-sets" ); 129 propertyDescriptor.setHidden( false ); 130 propertyDescriptor = (PropertyDescriptor) propertyMap.get( "xmldefault:xdoclet.sdk.xtag.migrator.Xmldefault" ); 131 propertyDescriptor.setName( "default" ); 132 propertyDescriptor.setHidden( false ); 133 propertyDescriptor = (PropertyDescriptor) propertyMap.get( "mandatory:xdoclet.sdk.xtag.migrator.Mandatory" ); 134 propertyDescriptor.setName( "mandatory" ); 135 propertyDescriptor.setHidden( false ); 136 propertyDescriptor = (PropertyDescriptor) propertyMap.get( "type_Att:java.lang.String" ); 137 propertyDescriptor.setName( "type" ); 138 propertyDescriptor.setHidden( false ); 139 propertyDescriptor = (PropertyDescriptor) propertyMap.get( "condition:xdoclet.sdk.xtag.migrator.Condition" ); 140 propertyDescriptor.setName( "condition" ); 141 propertyDescriptor.setHidden( false ); 142 propertyDescriptor = (PropertyDescriptor) propertyMap.get( "conditionDescription:xdoclet.sdk.xtag.migrator.ConditionDescription" ); 143 propertyDescriptor.setName( "condition-description" ); 144 propertyDescriptor.setHidden( false ); 145 propertyDescriptor = (PropertyDescriptor) propertyMap.get( "usageDescription:xdoclet.sdk.xtag.migrator.UsageDescription" ); 146 propertyDescriptor.setName( "usage-description" ); 147 propertyDescriptor.setHidden( false ); 148 } 149 150 public PropertyDescriptor[] getPropertyDescriptors() { 151 return _propertyDescriptors; 152 } 153 154 private void createMethodDescriptors() throws NoSuchMethodException { 155 // Map the existing method descriptors for easier manipulation. 156 Map methodMap = new HashMap(); 157 158 MethodDescriptor[] methodDescriptors = _introspectedBeanInfo.getMethodDescriptors(); 159 for( int i = 0; i < methodDescriptors.length; i++ ) { 160 // Set them to expert. We'll adjust that further down. 161 methodDescriptors[ i ].setHidden( true ); 162 methodMap.put( methodDescriptors[ i ].getMethod(), methodDescriptors[ i ] ); 163 } 164 Method method = null; 165 // The original introspected MethodDescriptor 166 MethodDescriptor methodDescriptor = null; 167 // The new methodDescriptor 168 MethodDescriptor methodDescriptor2 = null; 169 ParameterDescriptor[] parameterDescriptors = null; 170 List methodList = new ArrayList(methodMap.values()); 171 _methodDescriptors = (MethodDescriptor[]) methodList.toArray(new MethodDescriptor[methodMap.size()]); 172 } 173 174 public MethodDescriptor[] getMethodDescriptors() { 175 return _methodDescriptors; 176 } 177 }

This page was automatically generated by Maven