01: // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
02:
03: package jodd.bean;
04:
05: import jodd.introspector.DefaultIntrospector;
06: import jodd.introspector.ClassDescriptor;
07:
08: import java.lang.reflect.Method;
09: import java.lang.reflect.Field;
10:
11: /**
12: * Represents a bean named property. Contains two informations:
13: * <ol>
14: * <li>Bean instance (and cached class descriptor)</li>
15: * <li>Property name</li>
16: * </ol>
17: * Should be used only by {@link BeanUtil} and similar utils.
18: */
19: class BeanProperty {
20:
21: BeanProperty(Object bean, String propertyName, boolean forced) {
22: this .name = propertyName;
23: setBean(bean);
24: this .last = true;
25: this .forced = forced;
26: this .fullName = bean.getClass().getSimpleName() + '#'
27: + propertyName;
28: }
29:
30: // ---------------------------------------------------------------- bean and descriptor
31:
32: final String fullName; // initial name
33: Object bean;
34: ClassDescriptor cd;
35: String name; // property name
36: boolean last; // is it a last property (when nested)
37:
38: /**
39: * Sets new bean instance.
40: */
41: public void setBean(Object bean) {
42: this .bean = bean;
43: this .cd = (bean == null ? null : DefaultIntrospector
44: .lookup(bean.getClass()));
45: }
46:
47: // ---------------------------------------------------------------- flags
48:
49: final boolean forced;
50:
51: // ---------------------------------------------------------------- simple properties
52:
53: Method method;
54: Field field;
55:
56: // ---------------------------------------------------------------- toString
57:
58: @Override
59: public String toString() {
60: return '\'' + fullName + "' (actual:'"
61: + bean.getClass().getSimpleName() + '#' + name
62: + "', forced=" + forced + ')';
63: }
64: }
|