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.syncope.common.lib.to;
20  
21  import javax.ws.rs.PathParam;
22  import org.apache.commons.lang3.builder.EqualsBuilder;
23  import org.apache.commons.lang3.builder.HashCodeBuilder;
24  import org.apache.commons.lang3.builder.ToStringBuilder;
25  
26  public abstract class SAML2EntityTO implements EntityTO {
27  
28      private static final long serialVersionUID = 1L;
29  
30      protected abstract static class Builder<P extends SAML2EntityTO, B extends Builder<P, B>> {
31  
32          protected P instance;
33  
34          protected abstract P newInstance();
35  
36          protected P getInstance() {
37              if (instance == null) {
38                  instance = newInstance();
39              }
40              return instance;
41          }
42  
43          @SuppressWarnings("unchecked")
44          public B key(final String key) {
45              getInstance().setKey(key);
46              return (B) this;
47          }
48  
49          public P build() {
50              return getInstance();
51          }
52      }
53  
54      private String key;
55  
56      @Override
57      public String getKey() {
58          return key;
59      }
60  
61      @PathParam("key")
62      @Override
63      public void setKey(final String key) {
64          this.key = key;
65      }
66  
67      @Override
68      public boolean equals(final Object obj) {
69          if (this == obj) {
70              return true;
71          }
72          if (obj == null) {
73              return false;
74          }
75          if (getClass() != obj.getClass()) {
76              return false;
77          }
78          SAML2EntityTO other = (SAML2EntityTO) obj;
79          return new EqualsBuilder().
80                  append(key, other.key).
81                  build();
82      }
83  
84      @Override
85      public int hashCode() {
86          return new HashCodeBuilder().
87                  append(key).
88                  build();
89      }
90  
91      @Override
92      public String toString() {
93          return new ToStringBuilder(this).
94                  append("key", key).
95                  toString();
96      }
97  }