Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
NodeDescriptor |
|
| 1.3333333333333333;1.333 |
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 | ||
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 | 33359 | private String uri = ""; |
35 | ||
36 | /** Base constructor */ |
|
37 | 32267 | public NodeDescriptor() { |
38 | 32267 | } |
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 | 1001 | public NodeDescriptor(String localName) { |
47 | 1001 | this.localName = localName; |
48 | 1001 | this.qualifiedName = localName; |
49 | 1001 | } |
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 | 91 | public NodeDescriptor(String localName, String qualifiedName, String uri) { |
59 | 91 | this.localName = localName; |
60 | 91 | this.qualifiedName = qualifiedName; |
61 | 91 | this.uri = uri; |
62 | 91 | } |
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 | 32047 | 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 | 31443 | this.localName = localName; |
78 | 31443 | } |
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 | 77487 | if ( qualifiedName == null ) { |
86 | 16584 | qualifiedName = localName; |
87 | } |
|
88 | 77487 | 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 | 11451 | this.qualifiedName = qualifiedName; |
97 | 11451 | } |
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 | 25782 | 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 | 2119 | if ( uri == null ) { |
115 | 0 | throw new IllegalArgumentException( |
116 | 0 | "The namespace URI cannot be null. " |
117 | + "No namespace URI is specified with the empty string" |
|
118 | ); |
|
119 | } |
|
120 | 2119 | this.uri = uri; |
121 | 2119 | } |
122 | } |