View Javadoc
1 /* 2 * $Header: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/NodeDescriptor.java,v 1.5 2003/01/13 18:07:52 rdonkin Exp $ 3 * $Revision: 1.5 $ 4 * $Date: 2003/01/13 18:07:52 $ 5 * 6 * ==================================================================== 7 * 8 * The Apache Software License, Version 1.1 9 * 10 * Copyright (c) 1999-2002 The Apache Software Foundation. All rights 11 * reserved. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 20 * 2. Redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in 22 * the documentation and/or other materials provided with the 23 * distribution. 24 * 25 * 3. The end-user documentation included with the redistribution, if 26 * any, must include the following acknowlegement: 27 * "This product includes software developed by the 28 * Apache Software Foundation (http://www.apache.org/)." 29 * Alternately, this acknowlegement may appear in the software itself, 30 * if and wherever such third-party acknowlegements normally appear. 31 * 32 * 4. The names "The Jakarta Project", "Commons", and "Apache Software 33 * Foundation" must not be used to endorse or promote products derived 34 * from this software without prior written permission. For written 35 * permission, please contact apache@apache.org. 36 * 37 * 5. Products derived from this software may not be called "Apache" 38 * nor may "Apache" appear in their names without prior written 39 * permission of the Apache Group. 40 * 41 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 42 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 43 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 44 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 47 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 48 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 49 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 50 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 51 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 52 * SUCH DAMAGE. 53 * ==================================================================== 54 * 55 * This software consists of voluntary contributions made by many 56 * individuals on behalf of the Apache Software Foundation. For more 57 * information on the Apache Software Foundation, please see 58 * <http://www.apache.org/>;. 59 * 60 * $Id: NodeDescriptor.java,v 1.5 2003/01/13 18:07:52 rdonkin Exp $ 61 */ 62 package org.apache.commons.betwixt; 63 64 import org.apache.commons.betwixt.expression.Expression; 65 import org.apache.commons.betwixt.expression.Updater; 66 67 /*** <p> Common superclass for <code>ElementDescriptor</code> 68 * and <code>AttributeDescriptor</code>.</p> 69 * 70 * <p> Nodes can have just a local name 71 * or they can have a local name, qualified name and a namespace uri.</p> 72 * 73 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> 74 * @version $Revision: 1.5 $ 75 */ 76 public class NodeDescriptor { 77 78 /*** The local name of this node without any namespace prefix */ 79 private String localName; 80 /*** The qualified name of the xml node associated with this descriptor. */ 81 private String qualifiedName; 82 /*** The namespace URI of this node */ 83 private String uri = ""; 84 /*** the expression used to evaluate the text value of this node */ 85 private Expression textExpression; 86 /*** the updater used to update the current bean from the text value of this node */ 87 private Updater updater; 88 /*** The property expression to which this node refers to, or null if it is just a constant */ 89 private String propertyName; 90 /*** the property type associated with this node, if any */ 91 private Class propertyType; 92 /*** the singular property type (i.e. the type ignoring the Collection or Array */ 93 private Class singularPropertyType; 94 95 96 /*** Base constructor */ 97 public NodeDescriptor() { 98 } 99 100 /*** 101 * Creates a NodeDescriptor with no namespace URI or prefix. 102 * 103 * @param localName the (xml) local name of this node. 104 * This will be used to set both qualified and local name for this name. 105 */ 106 public NodeDescriptor(String localName) { 107 this.localName = localName; 108 this.qualifiedName = localName; 109 } 110 111 112 /*** 113 * Creates a NodeDescriptor with namespace URI and qualified name 114 * @param localName the (xml) local name of this node 115 * @param qualifiedName the (xml) qualified name of this node 116 * @param uri the (xml) namespace prefix of this node 117 */ 118 public NodeDescriptor(String localName, String qualifiedName, String uri) { 119 this.localName = localName; 120 this.qualifiedName = qualifiedName; 121 this.uri = uri; 122 } 123 124 /*** 125 * Gets the local name, excluding any namespace prefix 126 * @return the (xml) local name of this node 127 */ 128 public String getLocalName() { 129 return localName; 130 } 131 132 /*** 133 * Sets the local name 134 * @param localName the (xml) local name of this node 135 */ 136 public void setLocalName(String localName) { 137 this.localName = localName; 138 } 139 140 /*** 141 * Gets the qualified name, including any namespace prefix 142 * @return the (xml) qualified name of this node. This may be null. 143 */ 144 public String getQualifiedName() { 145 if ( qualifiedName == null ) { 146 qualifiedName = localName; 147 } 148 return qualifiedName; 149 } 150 151 /*** 152 * Sets the qualified name 153 * @param qualifiedName the new (xml) qualified name for this node 154 */ 155 public void setQualifiedName(String qualifiedName) { 156 this.qualifiedName = qualifiedName; 157 } 158 159 /*** 160 * Gets the (xml) namespace URI prefix for this node. 161 * @return the namespace URI that this node belongs to 162 * or "" if there is no namespace defined 163 */ 164 public String getURI() { 165 return uri; 166 } 167 168 169 /*** 170 * Sets the namespace URI that this node belongs to. 171 * @param uri the new namespace uri for this node 172 */ 173 public void setURI(String uri) { 174 if ( uri == null ) { 175 throw new IllegalArgumentException( 176 "The namespace URI cannot be null. " 177 + "No namespace URI is specified with the empty string" 178 ); 179 } 180 this.uri = uri; 181 } 182 183 /*** 184 * Gets the expression used to evaluate the text value of this node 185 * for a particular <code>Context</code>. 186 * @return the expression used to evaluate the text value of this node 187 */ 188 public Expression getTextExpression() { 189 return textExpression; 190 } 191 192 /*** 193 * Sets the expression used to evaluate the text value of this node 194 * for a particular <code>Context</code> 195 * @param textExpression the Expression to be used to evaluate the value of this node 196 */ 197 public void setTextExpression(Expression textExpression) { 198 this.textExpression = textExpression; 199 } 200 201 /*** 202 * Gets the <code>Updater</code> used to update a <code>Context</code> from the text value 203 * corresponding to this node in an xml document 204 * @return the Update that should be used to update the value of this node 205 */ 206 public Updater getUpdater() { 207 return updater; 208 } 209 210 /*** 211 * Sets the <code>Updater</code> used to update a <code>Context</code> from the text value 212 * corresponding to this node in an xml document 213 * @param updater the Updater to be used to update the values of this node 214 */ 215 public void setUpdater(Updater updater) { 216 this.updater = updater; 217 } 218 219 /*** 220 * Gets the type of the bean property associated with this node, if any 221 * @return the property type associated with this node, if any 222 */ 223 public Class getPropertyType() { 224 return propertyType; 225 } 226 227 /*** 228 * Sets the type of the bean property associated with this node, if any 229 * @param propertyType the Class of the bean property 230 */ 231 public void setPropertyType(Class propertyType) { 232 this.propertyType = propertyType; 233 } 234 235 236 /*** 237 * Gets the name of the bean property to which this node refers 238 * @return the name of the bean property to which this node refers to, 239 * or null if it is just a constant 240 */ 241 public String getPropertyName() { 242 return propertyName; 243 } 244 245 /*** 246 * Sets the name of the bean property to which this node refers 247 * @param propertyName the name of the bean property. 248 * Or null, if this node is not mapped to to a bean property 249 */ 250 public void setPropertyName(String propertyName) { 251 this.propertyName = propertyName; 252 } 253 254 /*** 255 * Gets the underlying type ignoring any wrapping a Collection or Array. 256 * 257 * @return if this property is a 1-N relationship then this returns the type 258 * of a single property value. 259 */ 260 public Class getSingularPropertyType() { 261 if ( singularPropertyType == null ) { 262 return getPropertyType(); 263 } 264 return singularPropertyType; 265 } 266 267 /*** 268 * Sets the underlying type ignoring any wrapping Collection or Array. 269 * 270 * @param singularPropertyType the Class of the items in the Collection or Array. 271 * If node is associated with a collective bean property, then this should not be null. 272 */ 273 public void setSingularPropertyType(Class singularPropertyType) { 274 this.singularPropertyType = singularPropertyType; 275 } 276 277 }

This page was automatically generated by Maven