View Javadoc

1   /*
2    * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons-sandbox//xmlio/src/java/org/apache/commons/xmlio/in/Item.java,v 1.1 2004/10/08 11:56:20 ozeigermann Exp $
3    * $Revision: 155476 $
4    * $Date: 2005-02-26 13:31:24 +0000 (Sat, 26 Feb 2005) $
5    *
6    * ====================================================================
7    *
8    * Copyright 2004 The Apache Software Foundation 
9    *
10   * Licensed under the Apache License, Version 2.0 (the "License");
11   * you may not use this file except in compliance with the License.
12   * You may obtain a copy of the License at
13   *
14   *     http://www.apache.org/licenses/LICENSE-2.0
15   *
16   * Unless required by applicable law or agreed to in writing, software
17   * distributed under the License is distributed on an "AS IS" BASIS,
18   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   * See the License for the specific language governing permissions and
20   * limitations under the License.
21   *
22   */
23  
24  package org.apache.commons.xmlio.in;
25  
26  /**
27   * Represntation of a path element. 
28   *
29   */
30  public final class Item {
31  
32      public static final Item ITEM_ANY = null;
33      
34      private final String namespaceURI;
35      private final String name;
36  
37      public Item() {
38          this(null, null);
39      }
40      public Item(String name) {
41          this(name, null);
42      }
43  
44      public Item(String name, String namespaceURI) {
45          this.namespaceURI = namespaceURI;
46          this.name = name;
47      }
48  
49      public String getName() {
50          return name;
51      }
52  
53      public String getNamespaceURI() {
54          return namespaceURI;
55      }
56  
57      public boolean equals(Object o) {
58          if (o == null) {
59              return true;
60          }
61          if (!(o instanceof Item)) {
62              return false;
63          }
64          Item token = (Item) o;
65          return (
66              (token.name == null || this.name.equals(token.name))
67                  && (this.namespaceURI == null
68                      || token.namespaceURI == null
69                      || this.namespaceURI.equals(token.namespaceURI)));
70  
71      }
72  
73      public String toString() {
74          if (namespaceURI == null || namespaceURI.length() == 0) {
75              return name;
76          } else {
77              return namespaceURI + ":" +name;
78          }
79      }
80  }