KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > bean > BeanProperty


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.bean;
4
5 import jodd.introspector.DefaultIntrospector;
6 import jodd.introspector.ClassDescriptor;
7
8 /**
9  * Represents a bean named property. Contains two informations:
10  * <ol>
11  * <li>Bean instance (and cached class descriptor)</li>
12  * <li>Property name</li>
13  * </ol>
14  * Should be used only by {@link BeanUtil} and similar utils.
15  */

16 public class BeanProperty {
17
18     BeanProperty(Object JavaDoc bean, String JavaDoc propertyName) {
19         this.name = propertyName;
20         setBean(bean);
21         last = true;
22     }
23
24     // ---------------------------------------------------------------- bean and descriptor
25

26     Object JavaDoc bean;
27     ClassDescriptor cd;
28
29     /**
30      * Set new bean instance.
31      */

32     public void setBean(Object JavaDoc bean) {
33         this.bean = bean;
34         this.cd = (bean == null ? null : DefaultIntrospector.lookup(bean.getClass()));
35     }
36
37     /**
38      * Returns bean instance.
39      */

40     public Object JavaDoc getBean() {
41         return bean;
42     }
43     /**
44      * Returns class descriptor of a bean.
45      */

46     public ClassDescriptor getClassDescriptor() {
47         return cd;
48     }
49
50     // ---------------------------------------------------------------- name
51

52     String JavaDoc name;
53
54     /**
55      * Returns property name.
56      */

57     public String JavaDoc getName() {
58         return name;
59     }
60
61     /**
62      * Sets bean property name.
63      */

64     public void setName(String JavaDoc name) {
65         this.name = name;
66     }
67
68     // ---------------------------------------------------------------- last
69

70     boolean last;
71
72     public boolean isLast() {
73         return last;
74     }
75
76     public void setLast(boolean last) {
77         this.last = last;
78     }
79
80     // ---------------------------------------------------------------- toString
81

82     public String JavaDoc toString() {
83         return bean.getClass().getName() + '#' + name;
84     }
85 }
86
Popular Tags