View Javadoc
1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. 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, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.xml;
17  
18  import java.util.LinkedList;
19  import java.util.List;
20  
21  /**
22   * Generic XML element in document, {@link XmlElementStart} represents open element and provides access to attributes,
23   * {@link XmlElementEnd} represents closing element.
24   */
25  public abstract class XmlElement {
26  
27      private final String name;
28      private final String namespace;
29      private final String prefix;
30  
31      private final List<XmlNamespace> namespaces = new LinkedList<XmlNamespace>();
32  
33      protected XmlElement(String name, String namespace, String prefix) {
34          this.name = name;
35          this.namespace = namespace;
36          this.prefix = prefix;
37      }
38  
39      public String name() {
40          return name;
41      }
42  
43      public String namespace() {
44          return namespace;
45      }
46  
47      public String prefix() {
48          return prefix;
49      }
50  
51      public List<XmlNamespace> namespaces() {
52          return namespaces;
53      }
54  
55      @Override
56      public boolean equals(Object o) {
57          if (this == o) { return true; }
58          if (o == null || getClass() != o.getClass()) { return false; }
59  
60          XmlElement that = (XmlElement) o;
61  
62          if (!name.equals(that.name)) { return false; }
63          if (namespace != null ? !namespace.equals(that.namespace) : that.namespace != null) { return false; }
64          if (namespaces != null ? !namespaces.equals(that.namespaces) : that.namespaces != null) { return false; }
65          if (prefix != null ? !prefix.equals(that.prefix) : that.prefix != null) { return false; }
66  
67          return true;
68      }
69  
70      @Override
71      public int hashCode() {
72          int result = name.hashCode();
73          result = 31 * result + (namespace != null ? namespace.hashCode() : 0);
74          result = 31 * result + (prefix != null ? prefix.hashCode() : 0);
75          result = 31 * result + (namespaces != null ? namespaces.hashCode() : 0);
76          return result;
77      }
78  
79      @Override
80      public String toString() {
81          return ", name='" + name + '\'' +
82                  ", namespace='" + namespace + '\'' +
83                  ", prefix='" + prefix + '\'' +
84                  ", namespaces=" + namespaces;
85      }
86  
87  }