查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
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    *   https://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.ArrayList;
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 ArrayList<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) {
58              return true;
59          }
60          if (o == null || getClass() != o.getClass()) {
61              return false;
62          }
63  
64          XmlElement that = (XmlElement) o;
65  
66          if (!name.equals(that.name)) {
67              return false;
68          }
69          if (namespace != null ? !namespace.equals(that.namespace) : that.namespace != null) {
70              return false;
71          }
72          if (!namespaces.equals(that.namespaces)) {
73              return false;
74          }
75          if (prefix != null ? !prefix.equals(that.prefix) : that.prefix != null) {
76              return false;
77          }
78  
79          return true;
80      }
81  
82      @Override
83      public int hashCode() {
84          int result = name.hashCode();
85          result = 31 * result + (namespace != null ? namespace.hashCode() : 0);
86          result = 31 * result + (prefix != null ? prefix.hashCode() : 0);
87          result = 31 * result + namespaces.hashCode();
88          return result;
89      }
90  
91      @Override
92      public String toString() {
93          return ", name='" + name + '\'' +
94                  ", namespace='" + namespace + '\'' +
95                  ", prefix='" + prefix + '\'' +
96                  ", namespaces=" + namespaces;
97      }
98  
99  }