01: /**
02: *
03: * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * 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: **/package groovy.xml;
18:
19: /**
20: * A simple helper class which acts as a factory of {@link QName} instances.
21: *
22: * @version $Revision: 4032 $
23: */
24: public class Namespace {
25:
26: private String uri;
27: private String prefix;
28:
29: public Namespace() {
30: }
31:
32: public Namespace(String uri) {
33: this .uri = uri;
34: }
35:
36: public Namespace(String uri, String prefix) {
37: this .uri = uri;
38: this .prefix = prefix;
39: }
40:
41: /**
42: * Returns the QName for the given localName.
43: *
44: * @param localName
45: * the local name within this
46: */
47: public QName get(String localName) {
48: if (uri != null && uri.length() > 0) {
49: if (prefix != null) {
50: return new QName(uri, localName, prefix);
51: } else {
52: return new QName(uri, localName);
53: }
54: } else {
55: return new QName(localName);
56: }
57: }
58:
59: /**
60: * Returns the prefix mapped to this namespace
61: *
62: * @return the prefix assigned to this namespace or null if no namespace is
63: * mapped.
64: */
65: public String getPrefix() {
66: return prefix;
67: }
68:
69: /**
70: * Returns the URI of this namespace
71: *
72: * @return the URI of this namespace
73: */
74: public String getUri() {
75: return uri;
76: }
77:
78: }
|