1 /***
2 *
3 * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18 package groovy.xml;
19
20 /***
21 * A simple helper class which acts as a factory of {@link QName} instances.
22 *
23 * @version $Revision: 4032 $
24 */
25 public class Namespace {
26
27 private String uri;
28 private String prefix;
29
30 public Namespace() {
31 }
32
33 public Namespace(String uri) {
34 this.uri = uri;
35 }
36
37 public Namespace(String uri, String prefix) {
38 this.uri = uri;
39 this.prefix = prefix;
40 }
41
42 /***
43 * Returns the QName for the given localName.
44 *
45 * @param localName
46 * the local name within this
47 */
48 public QName get(String localName) {
49 if (uri != null && uri.length() > 0) {
50 if (prefix != null) {
51 return new QName(uri, localName, prefix);
52 }
53 else {
54 return new QName(uri, localName);
55 }
56 }
57 else {
58 return new QName(localName);
59 }
60 }
61
62 /***
63 * Returns the prefix mapped to this namespace
64 *
65 * @return the prefix assigned to this namespace or null if no namespace is
66 * mapped.
67 */
68 public String getPrefix() {
69 return prefix;
70 }
71
72 /***
73 * Returns the URI of this namespace
74 *
75 * @return the URI of this namespace
76 */
77 public String getUri() {
78 return uri;
79 }
80
81 }