1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.betwixt;
  17. import org.apache.commons.betwixt.expression.Expression;
  18. import org.apache.commons.betwixt.expression.Updater;
  19. /** <p>Describes a content node mapping.</p>
  20. * Common superclass for types of <code>Descriptor</code></p>
  21. *
  22. * @author Robert Burrell Donkin
  23. * @since 0.5
  24. */
  25. public abstract class Descriptor {
  26. /** the expression used to evaluate the text value of this node */
  27. private Expression textExpression;
  28. /** the updater used to update the current bean from the text value of this node */
  29. private Updater updater;
  30. /** The property expression to which this node refers to, or null if it is just a constant */
  31. private String propertyName;
  32. /** the property type associated with this node, if any */
  33. private Class propertyType;
  34. /** the singular property type (i.e. the type ignoring the Collection or Array */
  35. private Class singularPropertyType;
  36. /** Options set for this Descriptor */
  37. private Options options = new Options();
  38. /** Base constructor */
  39. public Descriptor() {
  40. }
  41. /**
  42. * Gets the expression used to evaluate the text value of this node
  43. * for a particular <code>Context</code>.
  44. * @return the expression used to evaluate the text value of this node
  45. */
  46. public Expression getTextExpression() {
  47. return textExpression;
  48. }
  49. /**
  50. * Sets the expression used to evaluate the text value of this node
  51. * for a particular <code>Context</code>
  52. * @param textExpression the Expression to be used to evaluate the value of this node
  53. */
  54. public void setTextExpression(Expression textExpression) {
  55. this.textExpression = textExpression;
  56. }
  57. /**
  58. * Gets the <code>Updater</code> used to update a <code>Context</code> from the text value
  59. * corresponding to this node in an xml document
  60. * @return the Update that should be used to update the value of this node
  61. */
  62. public Updater getUpdater() {
  63. return updater;
  64. }
  65. /**
  66. * Sets the <code>Updater</code> used to update a <code>Context</code> from the text value
  67. * corresponding to this node in an xml document
  68. * @param updater the Updater to be used to update the values of this node
  69. */
  70. public void setUpdater(Updater updater) {
  71. this.updater = updater;
  72. }
  73. /**
  74. * Gets the type of the bean property associated with this node, if any
  75. * @return the property type associated with this node, if any
  76. */
  77. public Class getPropertyType() {
  78. return propertyType;
  79. }
  80. /**
  81. * Sets the type of the bean property associated with this node, if any
  82. * @param propertyType the Class of the bean property
  83. */
  84. public void setPropertyType(Class propertyType) {
  85. this.propertyType = propertyType;
  86. }
  87. /**
  88. * Gets the name of the bean property to which this node refers
  89. * @return the name of the bean property to which this node refers to,
  90. * or null if it is just a constant
  91. */
  92. public String getPropertyName() {
  93. return propertyName;
  94. }
  95. /**
  96. * Sets the name of the bean property to which this node refers
  97. * @param propertyName the name of the bean property.
  98. * Or null, if this node is not mapped to to a bean property
  99. */
  100. public void setPropertyName(String propertyName) {
  101. this.propertyName = propertyName;
  102. }
  103. /**
  104. * Gets the underlying type ignoring any wrapping a Collection or Array.
  105. *
  106. * @return if this property is a 1-N relationship then this returns the type
  107. * of a single property value.
  108. */
  109. public Class getSingularPropertyType() {
  110. if ( singularPropertyType == null ) {
  111. return getPropertyType();
  112. }
  113. return singularPropertyType;
  114. }
  115. /**
  116. * Sets the underlying type ignoring any wrapping Collection or Array.
  117. *
  118. * @param singularPropertyType the Class of the items in the Collection or Array.
  119. * If node is associated with a collective bean property, then this should not be null.
  120. */
  121. public void setSingularPropertyType(Class singularPropertyType) {
  122. this.singularPropertyType = singularPropertyType;
  123. }
  124. /**
  125. * Gets the options for this descriptor.
  126. * Options are used to communicate non-declarative
  127. * (optinal) behaviour hints.
  128. * @return <code>Options</code>, not null
  129. */
  130. public Options getOptions() {
  131. return options;
  132. }
  133. /**
  134. * Sets the options for this descriptor.
  135. * Options are used to communicate non-declarative
  136. * (optinal) behaviour hints.
  137. * @param options
  138. */
  139. public void setOptions(Options options) {
  140. this.options = options;
  141. }
  142. }