View Javadoc

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: 1.3 $
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       * @return
48       */
49      public QName get(String localName) {
50          if (uri != null && uri.length() > 0) {
51              if (prefix != null) {
52                  return new QName(uri, localName, prefix);
53              }
54              else {
55                  return new QName(uri, localName);
56              }
57          }
58          else {
59              return new QName(localName);
60          }
61      }
62  
63      /***
64       * Returns the prefix mapped to this namespace
65       * 
66       * @return the prefix assigned to this namespace or null if no namespace is
67       *         mapped.
68       */
69      public String getPrefix() {
70          return prefix;
71      }
72  
73      /***
74       * Returns the URI of this namespace
75       * 
76       * @return the URI of this namespace
77       */
78      public String getUri() {
79          return uri;
80      }
81  
82  }