001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.betwixt;
018:
019: import org.apache.commons.betwixt.expression.Expression;
020: import org.apache.commons.betwixt.expression.Updater;
021:
022: /** <p>Describes a content node mapping.</p>
023: * Common superclass for types of <code>Descriptor</code></p>
024: *
025: * @author Robert Burrell Donkin
026: * @since 0.5
027: */
028: public abstract class Descriptor {
029:
030: /** the expression used to evaluate the text value of this node */
031: private Expression textExpression;
032: /** the updater used to update the current bean from the text value of this node */
033: private Updater updater;
034: /** The property expression to which this node refers to, or null if it is just a constant */
035: private String propertyName;
036: /** the property type associated with this node, if any */
037: private Class propertyType;
038: /** the singular property type (i.e. the type ignoring the Collection or Array */
039: private Class singularPropertyType;
040: /** Options set for this Descriptor */
041: private Options options = new Options();
042:
043: /** Base constructor */
044: public Descriptor() {
045: }
046:
047: /**
048: * Gets the expression used to evaluate the text value of this node
049: * for a particular <code>Context</code>.
050: * @return the expression used to evaluate the text value of this node
051: */
052: public Expression getTextExpression() {
053: return textExpression;
054: }
055:
056: /**
057: * Sets the expression used to evaluate the text value of this node
058: * for a particular <code>Context</code>
059: * @param textExpression the Expression to be used to evaluate the value of this node
060: */
061: public void setTextExpression(Expression textExpression) {
062: this .textExpression = textExpression;
063: }
064:
065: /**
066: * Gets the <code>Updater</code> used to update a <code>Context</code> from the text value
067: * corresponding to this node in an xml document
068: * @return the Update that should be used to update the value of this node
069: */
070: public Updater getUpdater() {
071: return updater;
072: }
073:
074: /**
075: * Sets the <code>Updater</code> used to update a <code>Context</code> from the text value
076: * corresponding to this node in an xml document
077: * @param updater the Updater to be used to update the values of this node
078: */
079: public void setUpdater(Updater updater) {
080: this .updater = updater;
081: }
082:
083: /**
084: * Gets the type of the bean property associated with this node, if any
085: * @return the property type associated with this node, if any
086: */
087: public Class getPropertyType() {
088: return propertyType;
089: }
090:
091: /**
092: * Sets the type of the bean property associated with this node, if any
093: * @param propertyType the Class of the bean property
094: */
095: public void setPropertyType(Class propertyType) {
096: this .propertyType = propertyType;
097: }
098:
099: /**
100: * Gets the name of the bean property to which this node refers
101: * @return the name of the bean property to which this node refers to,
102: * or null if it is just a constant
103: */
104: public String getPropertyName() {
105: return propertyName;
106: }
107:
108: /**
109: * Sets the name of the bean property to which this node refers
110: * @param propertyName the name of the bean property.
111: * Or null, if this node is not mapped to to a bean property
112: */
113: public void setPropertyName(String propertyName) {
114: this .propertyName = propertyName;
115: }
116:
117: /**
118: * Gets the underlying type ignoring any wrapping a Collection or Array.
119: *
120: * @return if this property is a 1-N relationship then this returns the type
121: * of a single property value.
122: */
123: public Class getSingularPropertyType() {
124: if (singularPropertyType == null) {
125: return getPropertyType();
126: }
127: return singularPropertyType;
128: }
129:
130: /**
131: * Sets the underlying type ignoring any wrapping Collection or Array.
132: *
133: * @param singularPropertyType the Class of the items in the Collection or Array.
134: * If node is associated with a collective bean property, then this should not be null.
135: */
136: public void setSingularPropertyType(Class singularPropertyType) {
137: this .singularPropertyType = singularPropertyType;
138: }
139:
140: /**
141: * Gets the options for this descriptor.
142: * Options are used to communicate non-declarative
143: * (optinal) behaviour hints.
144: * @return <code>Options</code>, not null
145: */
146: public Options getOptions() {
147: return options;
148: }
149:
150: /**
151: * Sets the options for this descriptor.
152: * Options are used to communicate non-declarative
153: * (optinal) behaviour hints.
154: * @param options
155: */
156: public void setOptions(Options options) {
157: this.options = options;
158: }
159:
160: }
|