KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > javabean > SimpleI18NBeanBeanInfo


1 /*
2  * Generated file - Do not edit!
3  */

4 package test.javabean;
5
6 import java.awt.Image JavaDoc;
7 import java.beans.BeanDescriptor JavaDoc;
8 import java.beans.BeanInfo JavaDoc;
9 import java.beans.Introspector JavaDoc;
10 import java.beans.IntrospectionException JavaDoc;
11 import java.beans.PropertyDescriptor JavaDoc;
12 import java.beans.ParameterDescriptor JavaDoc;
13 import java.beans.MethodDescriptor JavaDoc;
14 import java.beans.SimpleBeanInfo JavaDoc;
15 import java.lang.reflect.Method JavaDoc;
16 import java.util.ResourceBundle JavaDoc;
17 import java.util.Vector JavaDoc;
18
19 /**
20  * BeanInfo class for SimpleI18NBean.
21  * Note: The java beans specification does NOT state that a property mutator
22  * can NOT exist with out an associated property accessor. Furthermore the
23  * implmentation of the sun bdk will look for property mutators by them self.
24  * The criteria for determining properties/accessors/mutators are determined
25  * by the JavaBeans specification, the implementation of Introspector and the
26  * implementation of the bdk not what the author or the framework thinks it
27  * "should be".
28  */

29
30 public class SimpleI18NBeanBeanInfo extends SimpleBeanInfo JavaDoc
31 {
32    /** Description of the Field */
33    protected BeanDescriptor JavaDoc bd = new BeanDescriptor JavaDoc(test.javabean.SimpleI18NBean.class);
34    /** Description of the Field */
35    protected Image JavaDoc iconMono16;
36    /** Description of the Field */
37    protected Image JavaDoc iconColor16 = loadImage("/toolbarButtonGraphics/general/Stop16.gif");
38    /** Description of the Field */
39    protected Image JavaDoc iconMono32;
40    /** Description of the Field */
41    protected Image JavaDoc iconColor32;
42    /** Description of the Field */
43    private final static ResourceBundle JavaDoc res = ResourceBundle.getBundle("test.javabean.SimpleI18NBeanBeanInfo");
44
45    /** Constructor for the SimpleI18NBeanBeanInfo object */
46    public SimpleI18NBeanBeanInfo() throws java.beans.IntrospectionException JavaDoc
47    {
48       // setup bean descriptor in constructor.
49
bd.setName("SimpleI18NBean");
50
51       bd.setDisplayName(res.getString("bean.displayName"));
52       bd.setShortDescription(res.getString("bean.shortDescription"));
53
54       bd.setValue("literal","A sample attribute");
55       bd.setValue("expression",new StringBuffer JavaDoc());
56
57       Class JavaDoc infoSourceClass = getBeanDescriptor().getBeanClass().isInterface()
58          ? Object JavaDoc.class : getBeanDescriptor().getBeanClass().getSuperclass();
59       BeanInfo JavaDoc info = Introspector.getBeanInfo(infoSourceClass);
60       String JavaDoc order = info.getBeanDescriptor().getValue("propertyorder") == null
61          ? "" : (String JavaDoc) info.getBeanDescriptor().getValue("propertyorder");
62       PropertyDescriptor JavaDoc[] pd = getPropertyDescriptors();
63       for (int i = 0; i != pd.length; i++)
64       {
65          if (order.indexOf(pd[i].getName()) == -1)
66          {
67             order = order + (order.length() == 0 ? "" : ":") + pd[i].getName();
68          }
69       }
70       getBeanDescriptor().setValue("propertyorder", order);
71    }
72
73    /**
74     * Gets the additionalBeanInfo
75     *
76     * @return The additionalBeanInfo value
77     */

78    public BeanInfo JavaDoc[] getAdditionalBeanInfo()
79    {
80       Vector JavaDoc bi = new Vector JavaDoc();
81       BeanInfo JavaDoc[] biarr = null;
82       try
83       {
84       }
85       catch (Exception JavaDoc e)
86       {
87          // Ignore it
88
}
89       return biarr;
90    }
91
92    /**
93     * Gets the beanDescriptor
94     *
95     * @return The beanDescriptor value
96     */

97    public BeanDescriptor JavaDoc getBeanDescriptor()
98    {
99       return bd;
100    }
101
102    /**
103     * Gets the defaultPropertyIndex
104     *
105     * @return The defaultPropertyIndex value
106     */

107    public int getDefaultPropertyIndex()
108    {
109       String JavaDoc defName = "";
110       if (defName.equals(""))
111       {
112          return -1;
113       }
114       PropertyDescriptor JavaDoc[] pd = getPropertyDescriptors();
115       for (int i = 0; i < pd.length; i++)
116       {
117          if (pd[i].getName().equals(defName))
118          {
119             return i;
120          }
121       }
122       return -1;
123    }
124
125    /**
126     * Gets the icon
127     *
128     * @param type Description of the Parameter
129     * @return The icon value
130     */

131    public Image JavaDoc getIcon(int type)
132    {
133       if (type == BeanInfo.ICON_COLOR_16x16)
134       {
135          return iconColor16;
136       }
137       if (type == BeanInfo.ICON_MONO_16x16)
138       {
139          return iconMono16;
140       }
141       if (type == BeanInfo.ICON_COLOR_32x32)
142       {
143          return iconColor32;
144       }
145       if (type == BeanInfo.ICON_MONO_32x32)
146       {
147          return iconMono32;
148       }
149       return null;
150    }
151
152    /**
153     * Gets the Property Descriptors
154     *
155     * @return The propertyDescriptors value
156     */

157    public PropertyDescriptor JavaDoc[] getPropertyDescriptors()
158    {
159       // create a property descriptor for each property
160
// if no property name is specified (javabean.property name) the the introspector will guess the property name from the method name (at generation time)
161

162       // do not ignore, bomb politely so use has chance to discover what went wrong...
163
// I know that this is suboptimal solution, but swallowing silently is
164
// even worse... Propose better solution!
165
Vector JavaDoc descriptors = new Vector JavaDoc();
166
167       try
168       {
169          PropertyDescriptor JavaDoc descriptor = new PropertyDescriptor JavaDoc("flag", test.javabean.SimpleBean.class, "isFlag", "setFlag");
170          descriptor.setDisplayName(res.getString("property.flag.displayName"));
171          descriptor.setShortDescription(res.getString("property.flag.shortDescription"));
172          descriptor.setHidden(false);
173          descriptor.setBound(true);
174          descriptors.add(descriptor);
175       }
176       catch (Exception JavaDoc ex)
177       {
178          ex.printStackTrace();
179       }
180
181       try
182       {
183          PropertyDescriptor JavaDoc descriptor = new PropertyDescriptor JavaDoc("name", test.javabean.SimpleBean.class, "getName", "setName");
184          descriptor.setDisplayName(res.getString("property.name.displayName"));
185          descriptor.setShortDescription(res.getString("property.name.shortDescription"));
186          descriptors.add(descriptor);
187       }
188       catch (Exception JavaDoc ex)
189       {
190          ex.printStackTrace();
191       }
192
193       try
194       {
195          //explicit read only property
196
PropertyDescriptor JavaDoc descriptor = new PropertyDescriptor JavaDoc("count", test.javabean.SimpleBean.class, "getCount", null);
197          descriptor.setDisplayName(res.getString("property.count.displayName"));
198          descriptor.setShortDescription(res.getString("property.count.shortDescription"));
199          descriptors.add(descriptor);
200       }
201       catch (Exception JavaDoc ex)
202       {
203          ex.printStackTrace();
204       }
205
206       try
207       {
208          PropertyDescriptor JavaDoc descriptor = new PropertyDescriptor JavaDoc("parent", test.javabean.SimpleBean.class, "getParent", null);
209          descriptor.setDisplayName(res.getString("property.parent.displayName"));
210          descriptor.setShortDescription(res.getString("property.parent.shortDescription"));
211          descriptors.add(descriptor);
212       }
213       catch (Exception JavaDoc ex)
214       {
215          ex.printStackTrace();
216       }
217       return (PropertyDescriptor JavaDoc[]) descriptors.toArray(new PropertyDescriptor JavaDoc[descriptors.size()]);
218    }
219
220    /**
221     * Gets the methodDescriptors attribute ...
222     *
223     * @return The methodDescriptors value
224     */

225    public MethodDescriptor JavaDoc[] getMethodDescriptors() {
226       Vector JavaDoc descriptors = new Vector JavaDoc();
227       MethodDescriptor JavaDoc descriptor = null;
228       Method JavaDoc[] m;
229       Method JavaDoc method;
230
231       try {
232          m = Class.forName("test.javabean.SimpleI18NBean").getMethods();
233       } catch (ClassNotFoundException JavaDoc e) {
234          return new MethodDescriptor JavaDoc[0];
235       }
236
237       method = null;
238       for (int j = 0; j != m.length; j++) {
239          if (m[j].getName().equals("myFirstMethod")) {
240             method = m[j];
241             break;
242          }
243       }
244
245       if (method != null) {
246          ParameterDescriptor JavaDoc[] pd = new ParameterDescriptor JavaDoc[method.getParameterTypes().length];
247          int pidx = 0;
248
249          if (pidx == 0) {
250             descriptor = new MethodDescriptor JavaDoc(method);
251          } else {
252             descriptor = new MethodDescriptor JavaDoc(method, pd);
253          }
254          descriptor.setName("myFirstMethod");
255          descriptor.setDisplayName(res.getString("method.myFirstMethod.displayName"));
256          descriptor.setDisplayName(res.getString("method.myFirstMethod.shortDescription"));
257
258          descriptors.add(descriptor);
259       }
260
261       method = null;
262       for (int j = 0; j != m.length; j++) {
263          if (m[j].getName().equals("mySecondMethod")) {
264             method = m[j];
265             break;
266          }
267       }
268
269       if (method != null) {
270          ParameterDescriptor JavaDoc[] pd = new ParameterDescriptor JavaDoc[method.getParameterTypes().length];
271          int pidx = 0;
272
273          pd[pidx] = new ParameterDescriptor JavaDoc();
274          pd[pidx].setName("param1");
275          pd[pidx].setDisplayName(res.getString("method.mySecondMethod.param1.displayName"));
276
277          pidx++;
278
279          pd[pidx] = new ParameterDescriptor JavaDoc();
280          pd[pidx].setName("param2");
281          pd[pidx].setDisplayName(res.getString("method.mySecondMethod.param2.displayName"));
282
283          pidx++;
284
285          pd[pidx] = new ParameterDescriptor JavaDoc();
286          pd[pidx].setName("param1");
287          pd[pidx].setDisplayName(res.getString("method.mySecondMethod.param1.displayName"));
288
289          pidx++;
290
291          pd[pidx] = new ParameterDescriptor JavaDoc();
292          pd[pidx].setName("param2");
293          pd[pidx].setDisplayName(res.getString("method.mySecondMethod.param2.displayName"));
294
295          pidx++;
296
297          if (pidx == 0) {
298             descriptor = new MethodDescriptor JavaDoc(method);
299          } else {
300             descriptor = new MethodDescriptor JavaDoc(method, pd);
301          }
302          descriptor.setName("mySecondMethod");
303          descriptor.setDisplayName(res.getString("method.mySecondMethod.displayName"));
304          descriptor.setDisplayName(res.getString("method.mySecondMethod.shortDescription"));
305
306          descriptors.add(descriptor);
307       }
308
309       return (MethodDescriptor JavaDoc[]) descriptors.toArray(new MethodDescriptor JavaDoc[descriptors.size()]);
310    }
311 }
312
Popular Tags