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