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 Options.
21 */
22 public class OptionsBeanInfo 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.Options.class );
35
36 private MethodDescriptor[] _methodDescriptors;
37 private PropertyDescriptor[] _propertyDescriptors;
38
39 public OptionsBeanInfo() throws java.beans.IntrospectionException {
40 // Let the Introspector do the dirty work.
41 _introspectedBeanInfo = Introspector.getBeanInfo( xdoclet.sdk.xtag.migrator.Options.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("options");
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 }
125
126 public PropertyDescriptor[] getPropertyDescriptors() {
127 return _propertyDescriptors;
128 }
129
130 private void createMethodDescriptors() throws NoSuchMethodException {
131 // Map the existing method descriptors for easier manipulation.
132 Map methodMap = new HashMap();
133
134 MethodDescriptor[] methodDescriptors = _introspectedBeanInfo.getMethodDescriptors();
135 for( int i = 0; i < methodDescriptors.length; i++ ) {
136 // Set them to expert. We'll adjust that further down.
137 methodDescriptors[ i ].setHidden( true );
138 methodMap.put( methodDescriptors[ i ].getMethod(), methodDescriptors[ i ] );
139 }
140 Method method = null;
141 // The original introspected MethodDescriptor
142 MethodDescriptor methodDescriptor = null;
143 // The new methodDescriptor
144 MethodDescriptor methodDescriptor2 = null;
145 ParameterDescriptor[] parameterDescriptors = null;
146 List methodList = new ArrayList(methodMap.values());
147 _methodDescriptors = (MethodDescriptor[]) methodList.toArray(new MethodDescriptor[methodMap.size()]);
148 }
149
150 public MethodDescriptor[] getMethodDescriptors() {
151 return _methodDescriptors;
152 }
153 }
This page was automatically generated by Maven