KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > NodeDescriptor


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: 1.10 $
26   */

27 public class NodeDescriptor extends Descriptor {
28
29     /** The local name of this node without any namespace prefix */
30     private String JavaDoc localName;
31     /** The qualified name of the xml node associated with this descriptor. */
32     private String JavaDoc qualifiedName;
33     /** The namespace URI of this node */
34     private String JavaDoc 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 JavaDoc 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 JavaDoc localName, String JavaDoc qualifiedName, String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc uri) {
114         if ( uri == null ) {
115             throw new IllegalArgumentException JavaDoc(
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 }
123
Popular Tags