1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt;
18
19 import org.apache.commons.betwixt.expression.Expression;
20 import org.apache.commons.betwixt.expression.Updater;
21
22 /*** <p>Describes a content node mapping.</p>
23 * Common superclass for types of <code>Descriptor</code></p>
24 *
25 * @author Robert Burrell Donkin
26 * @since 0.5
27 */
28 public abstract class Descriptor {
29
30 /*** the expression used to evaluate the text value of this node */
31 private Expression textExpression;
32 /*** the updater used to update the current bean from the text value of this node */
33 private Updater updater;
34 /*** The property expression to which this node refers to, or null if it is just a constant */
35 private String propertyName;
36 /*** the property type associated with this node, if any */
37 private Class propertyType;
38 /*** the singular property type (i.e. the type ignoring the Collection or Array */
39 private Class singularPropertyType;
40 /*** Options set for this Descriptor */
41 private Options options = new Options();
42
43
44 /*** Base constructor */
45 public Descriptor() {
46 }
47
48 /***
49 * Gets the expression used to evaluate the text value of this node
50 * for a particular <code>Context</code>.
51 * @return the expression used to evaluate the text value of this node
52 */
53 public Expression getTextExpression() {
54 return textExpression;
55 }
56
57 /***
58 * Sets the expression used to evaluate the text value of this node
59 * for a particular <code>Context</code>
60 * @param textExpression the Expression to be used to evaluate the value of this node
61 */
62 public void setTextExpression(Expression textExpression) {
63 this.textExpression = textExpression;
64 }
65
66 /***
67 * Gets the <code>Updater</code> used to update a <code>Context</code> from the text value
68 * corresponding to this node in an xml document
69 * @return the Update that should be used to update the value of this node
70 */
71 public Updater getUpdater() {
72 return updater;
73 }
74
75 /***
76 * Sets the <code>Updater</code> used to update a <code>Context</code> from the text value
77 * corresponding to this node in an xml document
78 * @param updater the Updater to be used to update the values of this node
79 */
80 public void setUpdater(Updater updater) {
81 this.updater = updater;
82 }
83
84 /***
85 * Gets the type of the bean property associated with this node, if any
86 * @return the property type associated with this node, if any
87 */
88 public Class getPropertyType() {
89 return propertyType;
90 }
91
92 /***
93 * Sets the type of the bean property associated with this node, if any
94 * @param propertyType the Class of the bean property
95 */
96 public void setPropertyType(Class propertyType) {
97 this.propertyType = propertyType;
98 }
99
100
101 /***
102 * Gets the name of the bean property to which this node refers
103 * @return the name of the bean property to which this node refers to,
104 * or null if it is just a constant
105 */
106 public String getPropertyName() {
107 return propertyName;
108 }
109
110 /***
111 * Sets the name of the bean property to which this node refers
112 * @param propertyName the name of the bean property.
113 * Or null, if this node is not mapped to to a bean property
114 */
115 public void setPropertyName(String propertyName) {
116 this.propertyName = propertyName;
117 }
118
119 /***
120 * Gets the underlying type ignoring any wrapping a Collection or Array.
121 *
122 * @return if this property is a 1-N relationship then this returns the type
123 * of a single property value.
124 */
125 public Class getSingularPropertyType() {
126 if ( singularPropertyType == null ) {
127 return getPropertyType();
128 }
129 return singularPropertyType;
130 }
131
132 /***
133 * Sets the underlying type ignoring any wrapping Collection or Array.
134 *
135 * @param singularPropertyType the Class of the items in the Collection or Array.
136 * If node is associated with a collective bean property, then this should not be null.
137 */
138 public void setSingularPropertyType(Class singularPropertyType) {
139 this.singularPropertyType = singularPropertyType;
140 }
141
142
143 /***
144 * Gets the options for this descriptor.
145 * Options are used to communicate non-declarative
146 * (optinal) behaviour hints.
147 * @return <code>Options</code>, not null
148 */
149 public Options getOptions() {
150 return options;
151 }
152
153 /***
154 * Sets the options for this descriptor.
155 * Options are used to communicate non-declarative
156 * (optinal) behaviour hints.
157 * @param options
158 */
159 public void setOptions(Options options) {
160 this.options = options;
161 }
162
163 }