KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > javabean > SimpleBeanBeanInfo


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 SimpleBean.
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 SimpleBeanBeanInfo extends SimpleBeanInfo JavaDoc
31 {
32    /** Description of the Field */
33    protected BeanDescriptor JavaDoc bd = new BeanDescriptor JavaDoc(test.javabean.SimpleBean.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
43    /** Constructor for the SimpleBeanBeanInfo object */
44    public SimpleBeanBeanInfo() throws java.beans.IntrospectionException JavaDoc
45    {
46       // setup bean descriptor in constructor.
47
bd.setName("SimpleBean");
48
49       bd.setDisplayName("Simple Bean");
50       bd.setShortDescription("Simple example of JavaBean BeanInfo generation");
51
52       bd.setValue("literal","A sample attribute");
53       bd.setValue("expression",new StringBuffer JavaDoc());
54
55       Class JavaDoc infoSourceClass = getBeanDescriptor().getBeanClass().isInterface()
56          ? Object JavaDoc.class : getBeanDescriptor().getBeanClass().getSuperclass();
57       BeanInfo JavaDoc info = Introspector.getBeanInfo(infoSourceClass);
58       String JavaDoc order = info.getBeanDescriptor().getValue("propertyorder") == null
59          ? "" : (String JavaDoc) info.getBeanDescriptor().getValue("propertyorder");
60       PropertyDescriptor JavaDoc[] pd = getPropertyDescriptors();
61       for (int i = 0; i != pd.length; i++)
62       {
63          if (order.indexOf(pd[i].getName()) == -1)
64          {
65             order = order + (order.length() == 0 ? "" : ":") + pd[i].getName();
66          }
67       }
68       getBeanDescriptor().setValue("propertyorder", order);
69    }
70
71    /**
72     * Gets the additionalBeanInfo
73     *
74     * @return The additionalBeanInfo value
75     */

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

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

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

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

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

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

223    public MethodDescriptor JavaDoc[] getMethodDescriptors() {
224       Vector JavaDoc descriptors = new Vector JavaDoc();
225       MethodDescriptor JavaDoc descriptor = null;
226       Method JavaDoc[] m;
227       Method JavaDoc method;
228
229       try {
230          m = Class.forName("test.javabean.SimpleBean").getMethods();
231       } catch (ClassNotFoundException JavaDoc e) {
232          return new MethodDescriptor JavaDoc[0];
233       }
234
235       method = null;
236       for (int j = 0; j != m.length; j++) {
237          if (m[j].getName().equals("myFirstMethod")) {
238             method = m[j];
239             break;
240          }
241       }
242
243       if (method != null) {
244          ParameterDescriptor JavaDoc[] pd = new ParameterDescriptor JavaDoc[method.getParameterTypes().length];
245          int pidx = 0;
246
247          if (pidx == 0) {
248             descriptor = new MethodDescriptor JavaDoc(method);
249          } else {
250             descriptor = new MethodDescriptor JavaDoc(method, pd);
251          }
252          descriptor.setName("myFirstMethod");
253          descriptor.setDisplayName("My First Method");
254          descriptor.setShortDescription("Example of method without parameters");
255
256          descriptors.add(descriptor);
257       }
258
259       method = null;
260       for (int j = 0; j != m.length; j++) {
261          if (m[j].getName().equals("mySecondMethod")) {
262             method = m[j];
263             break;
264          }
265       }
266
267       if (method != null) {
268          ParameterDescriptor JavaDoc[] pd = new ParameterDescriptor JavaDoc[method.getParameterTypes().length];
269          int pidx = 0;
270
271          pd[pidx] = new ParameterDescriptor JavaDoc();
272          pd[pidx].setName("param1");
273          pd[pidx].setDisplayName("Parameter 1");
274
275          pidx++;
276
277          pd[pidx] = new ParameterDescriptor JavaDoc();
278          pd[pidx].setName("param2");
279          pd[pidx].setDisplayName("Parameter 2");
280
281          pidx++;
282
283          if (pidx == 0) {
284             descriptor = new MethodDescriptor JavaDoc(method);
285          } else {
286             descriptor = new MethodDescriptor JavaDoc(method, pd);
287          }
288          descriptor.setName("mySecondMethod");
289          descriptor.setDisplayName("My Second Method");
290          descriptor.setShortDescription("Example of method with parameters");
291
292          descriptors.add(descriptor);
293       }
294
295       return (MethodDescriptor JavaDoc[]) descriptors.toArray(new MethodDescriptor JavaDoc[descriptors.size()]);
296    }
297 }
298
Popular Tags