1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt;
18
19 /*** <p> Common superclass for <code>ElementDescriptor</code>
20 * and <code>AttributeDescriptor</code>.</p>
21 *
22 * <p> Nodes can have just a local name
23 * or they can have a local name, qualified name and a namespace uri.</p>
24 *
25 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
26 * @version $Revision: 438373 $
27 */
28 public class NodeDescriptor extends Descriptor {
29
30 /*** The local name of this node without any namespace prefix */
31 private String localName;
32 /*** The qualified name of the xml node associated with this descriptor. */
33 private String qualifiedName;
34 /*** The namespace URI of this node */
35 private String uri = "";
36
37 /*** Base constructor */
38 public NodeDescriptor() {
39 }
40
41 /***
42 * Creates a NodeDescriptor with no namespace URI or prefix.
43 *
44 * @param localName the (xml) local name of this node.
45 * This will be used to set both qualified and local name for this name.
46 */
47 public NodeDescriptor(String localName) {
48 this.localName = localName;
49 this.qualifiedName = localName;
50 }
51
52
53 /***
54 * Creates a NodeDescriptor with namespace URI and qualified name
55 * @param localName the (xml) local name of this node
56 * @param qualifiedName the (xml) qualified name of this node
57 * @param uri the (xml) namespace prefix of this node
58 */
59 public NodeDescriptor(String localName, String qualifiedName, String uri) {
60 this.localName = localName;
61 this.qualifiedName = qualifiedName;
62 this.uri = uri;
63 }
64
65 /***
66 * Gets the local name, excluding any namespace prefix
67 * @return the (xml) local name of this node
68 */
69 public String getLocalName() {
70 return localName;
71 }
72
73 /***
74 * Sets the local name
75 * @param localName the (xml) local name of this node
76 */
77 public void setLocalName(String localName) {
78 this.localName = localName;
79 }
80
81 /***
82 * Gets the qualified name, including any namespace prefix
83 * @return the (xml) qualified name of this node. This may be null.
84 */
85 public String getQualifiedName() {
86 if ( qualifiedName == null ) {
87 qualifiedName = localName;
88 }
89 return qualifiedName;
90 }
91
92 /***
93 * Sets the qualified name
94 * @param qualifiedName the new (xml) qualified name for this node
95 */
96 public void setQualifiedName(String qualifiedName) {
97 this.qualifiedName = qualifiedName;
98 }
99
100 /***
101 * Gets the (xml) namespace URI prefix for this node.
102 * @return the namespace URI that this node belongs to
103 * or "" if there is no namespace defined
104 */
105 public String getURI() {
106 return uri;
107 }
108
109
110 /***
111 * Sets the namespace URI that this node belongs to.
112 * @param uri the new namespace uri for this node
113 */
114 public void setURI(String uri) {
115 if ( uri == null ) {
116 throw new IllegalArgumentException(
117 "The namespace URI cannot be null. "
118 + "No namespace URI is specified with the empty string"
119 );
120 }
121 this.uri = uri;
122 }
123 }