KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > examples > website > PersonBeanInfo


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package org.jmock.examples.website;
4
5 import java.beans.IntrospectionException JavaDoc;
6 import java.beans.MethodDescriptor JavaDoc;
7 import java.beans.PropertyDescriptor JavaDoc;
8 import java.beans.SimpleBeanInfo JavaDoc;
9 import java.util.ArrayList JavaDoc;
10
11
12 public class PersonBeanInfo extends SimpleBeanInfo JavaDoc
13 {
14     ArrayList JavaDoc properties = new ArrayList JavaDoc();
15     ArrayList JavaDoc methods = new ArrayList JavaDoc();
16
17     public PersonBeanInfo() throws IntrospectionException JavaDoc {
18         Class JavaDoc beanClass = Person.class;
19
20         properties.add(new PropertyDescriptor JavaDoc("name", beanClass, "name", null));
21         properties.add(new PropertyDescriptor JavaDoc("age", beanClass, "age", null));
22         properties.add(new PropertyDescriptor JavaDoc("spouse", beanClass, "spouse", null));
23         properties.add(new PropertyDescriptor JavaDoc("children", beanClass, "children", null));
24
25         try {
26             methods.add(new MethodDescriptor JavaDoc(beanClass.getMethod("birth", new Class JavaDoc[0])));
27             methods.add(new MethodDescriptor JavaDoc(beanClass.getMethod("school", new Class JavaDoc[0])));
28             methods.add(new MethodDescriptor JavaDoc(beanClass.getMethod("work", new Class JavaDoc[0])));
29             methods.add(new MethodDescriptor JavaDoc(beanClass.getMethod("death", new Class JavaDoc[0])));
30         }
31         catch (NoSuchMethodException JavaDoc ex) {
32             throw new IntrospectionException JavaDoc(ex.getMessage());
33         }
34     }
35
36     public MethodDescriptor JavaDoc[] getMethodDescriptors() {
37         return (MethodDescriptor JavaDoc[])methods.toArray(new MethodDescriptor JavaDoc[methods.size()]);
38     }
39
40     public PropertyDescriptor JavaDoc[] getPropertyDescriptors() {
41         return (PropertyDescriptor JavaDoc[])properties.toArray(new PropertyDescriptor JavaDoc[properties.size()]);
42     }
43 }
44
Popular Tags