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
044 /** Base constructor */
045 public Descriptor() {
046 }
047
048 /**
049 * Gets the expression used to evaluate the text value of this node
050 * for a particular <code>Context</code>.
051 * @return the expression used to evaluate the text value of this node
052 */
053 public Expression getTextExpression() {
054 return textExpression;
055 }
056
057 /**
058 * Sets the expression used to evaluate the text value of this node
059 * for a particular <code>Context</code>
060 * @param textExpression the Expression to be used to evaluate the value of this node
061 */
062 public void setTextExpression(Expression textExpression) {
063 this.textExpression = textExpression;
064 }
065
066 /**
067 * Gets the <code>Updater</code> used to update a <code>Context</code> from the text value
068 * corresponding to this node in an xml document
069 * @return the Update that should be used to update the value of this node
070 */
071 public Updater getUpdater() {
072 return updater;
073 }
074
075 /**
076 * Sets the <code>Updater</code> used to update a <code>Context</code> from the text value
077 * corresponding to this node in an xml document
078 * @param updater the Updater to be used to update the values of this node
079 */
080 public void setUpdater(Updater updater) {
081 this.updater = updater;
082 }
083
084 /**
085 * Gets the type of the bean property associated with this node, if any
086 * @return the property type associated with this node, if any
087 */
088 public Class getPropertyType() {
089 return propertyType;
090 }
091
092 /**
093 * Sets the type of the bean property associated with this node, if any
094 * @param propertyType the Class of the bean property
095 */
096 public void setPropertyType(Class propertyType) {
097 this.propertyType = propertyType;
098 }
099
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 }