View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.wss4j.policy.model;
20  
21  public class Header {
22  
23      private final String name;
24      private final String namespace;
25  
26      public Header(String name, String namespace) {
27          this.name = name;
28          this.namespace = namespace;
29      }
30  
31      public String getName() {
32          return name;
33      }
34  
35      public String getNamespace() {
36          return namespace;
37      }
38  
39      @Override
40      public boolean equals(Object object) {
41          if (object == this) {
42              return true;
43          }
44  
45          if (!(object instanceof Header)) {
46              return false;
47          }
48  
49          Header that = (Header)object;
50          if (name != null && !name.equals(that.name)
51              || name == null && that.name != null) {
52              return false;
53          }
54  
55          return !(namespace != null && !namespace.equals(that.namespace)
56              || namespace == null && that.namespace != null);
57      }
58  
59      @Override
60      public int hashCode() {
61          int result = 17;
62          if (name != null) {
63              result = 31 * result + name.hashCode();
64          }
65          if (namespace != null) {
66              result = 31 * result + namespace.hashCode();
67          }
68  
69          return 31 * result + super.hashCode();
70      }
71  
72      @Override
73      public String toString() {
74          StringBuilder stringBuilder = new StringBuilder();
75          stringBuilder.append('{');
76          if (namespace != null) {
77              stringBuilder.append(namespace);
78          } else {
79              stringBuilder.append('*');
80          }
81          stringBuilder.append('}');
82          if (name != null) {
83              stringBuilder.append(name);
84          } else {
85              stringBuilder.append('*');
86          }
87          return stringBuilder.toString();
88      }
89  }