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 Tag.
21 */
22 public class TagBeanInfo 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.Tag.class );
35
36 private MethodDescriptor[] _methodDescriptors;
37 private PropertyDescriptor[] _propertyDescriptors;
38
39 public TagBeanInfo() throws java.beans.IntrospectionException {
40 // Let the Introspector do the dirty work.
41 _introspectedBeanInfo = Introspector.getBeanInfo( xdoclet.sdk.xtag.migrator.Tag.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("tag");
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 propertyDescriptor = (PropertyDescriptor) propertyMap.get( "name:xdoclet.sdk.xtag.migrator.Name" );
124 propertyDescriptor.setName( "name" );
125 propertyDescriptor.setHidden( false );
126 propertyDescriptor = (PropertyDescriptor) propertyMap.get( "deprecated:xdoclet.sdk.xtag.migrator.Deprecated" );
127 propertyDescriptor.setName( "deprecated" );
128 propertyDescriptor.setHidden( false );
129 propertyDescriptor = (PropertyDescriptor) propertyMap.get( "unique:xdoclet.sdk.xtag.migrator.Unique" );
130 propertyDescriptor.setName( "unique" );
131 propertyDescriptor.setHidden( false );
132 propertyDescriptor = (PropertyDescriptor) propertyMap.get( "condition:xdoclet.sdk.xtag.migrator.Condition" );
133 propertyDescriptor.setName( "condition" );
134 propertyDescriptor.setHidden( false );
135 propertyDescriptor = (PropertyDescriptor) propertyMap.get( "conditionDescription:xdoclet.sdk.xtag.migrator.ConditionDescription" );
136 propertyDescriptor.setName( "condition-description" );
137 propertyDescriptor.setHidden( false );
138 propertyDescriptor = (PropertyDescriptor) propertyMap.get( "usageDescription:xdoclet.sdk.xtag.migrator.UsageDescription" );
139 propertyDescriptor.setName( "usage-description" );
140 propertyDescriptor.setHidden( false );
141 }
142
143 public PropertyDescriptor[] getPropertyDescriptors() {
144 return _propertyDescriptors;
145 }
146
147 private void createMethodDescriptors() throws NoSuchMethodException {
148 // Map the existing method descriptors for easier manipulation.
149 Map methodMap = new HashMap();
150
151 MethodDescriptor[] methodDescriptors = _introspectedBeanInfo.getMethodDescriptors();
152 for( int i = 0; i < methodDescriptors.length; i++ ) {
153 // Set them to expert. We'll adjust that further down.
154 methodDescriptors[ i ].setHidden( true );
155 methodMap.put( methodDescriptors[ i ].getMethod(), methodDescriptors[ i ] );
156 }
157 Method method = null;
158 // The original introspected MethodDescriptor
159 MethodDescriptor methodDescriptor = null;
160 // The new methodDescriptor
161 MethodDescriptor methodDescriptor2 = null;
162 ParameterDescriptor[] parameterDescriptors = null;
163 List methodList = new ArrayList(methodMap.values());
164 _methodDescriptors = (MethodDescriptor[]) methodList.toArray(new MethodDescriptor[methodMap.size()]);
165 }
166
167 public MethodDescriptor[] getMethodDescriptors() {
168 return _methodDescriptors;
169 }
170 }
This page was automatically generated by Maven