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