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   */
20  package org.apache.directory.api.ldap.aci.protectedItem;
21  
22  
23  import org.apache.directory.api.ldap.model.schema.AttributeType;
24  
25  
26  /**
27   * An element of {@link RestrictedByItem}.
28   * 
29   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
30   */
31  public class RestrictedByElem
32  {
33      /** The AttributeType on which the restriction is applied */
34      private AttributeType attributeType;
35  
36      /** The list of allowed AttributeType values */
37      private AttributeType valuesIn;
38  
39      /**
40       * Creates a new instance.
41       * 
42       * @param attributeType the attribute type to restrict
43       * @param valuesIn the attribute type only whose values are allowed in <tt>attributeType</tt>.
44       */
45      public RestrictedByElem( AttributeType attributeType, AttributeType valuesIn )
46      {
47          this.attributeType = attributeType;
48          this.valuesIn = valuesIn;
49      }
50  
51  
52      /**
53       * Gets the attribute type to restrict.
54       *
55       * @return the attribute type
56       */
57      public AttributeType getAttributeType()
58      {
59          return attributeType;
60      }
61  
62  
63      /**
64       * Gets the attribute type only whose values are allowed in
65       * <tt>attributeType</tt>.
66       *
67       * @return the list of allowed AttributeType values
68       */
69      public AttributeType getValuesIn()
70      {
71          return valuesIn;
72      }
73  
74  
75      /**
76       * {@inheritDoc}
77       */
78      @Override
79      public int hashCode()
80      {
81          int hash = 37;
82          
83          if ( attributeType != null )
84          {
85              hash = hash * 17 + attributeType.hashCode();
86          }
87          
88          if ( valuesIn != null )
89          {
90              hash = hash * 17 + valuesIn.hashCode();
91          }
92          
93          return hash;
94      }
95  
96  
97      /**
98       * {@inheritDoc}
99       */
100     @Override
101     public boolean equals( Object o )
102     {
103         if ( this == o )
104         {
105             return true;
106         }
107 
108         if ( o instanceof RestrictedByElem )
109         {
110             RestrictedByElem that = ( RestrictedByElem ) o;
111             
112             if ( attributeType == null )
113             {
114                 if ( that.attributeType == null )
115                 {
116                     if ( valuesIn == null )
117                     {
118                         return that.valuesIn == null;
119                     }
120                     else
121                     {
122                         return valuesIn.equals( that.valuesIn );
123                     }
124                 }
125             }
126             else
127             {
128                 if ( attributeType.equals( that.attributeType ) )
129                 {
130                     if ( valuesIn == null )
131                     {
132                         return that.valuesIn == null;
133                     }
134                     else
135                     {
136                         return valuesIn.equals( that.valuesIn );
137                     }
138                 }
139             }
140         }
141         
142         return false;
143     }
144 
145 
146     /**
147      * {@inheritDoc}
148      */
149     @Override
150     public String toString()
151     {
152         StringBuilder sb = new StringBuilder();
153         
154         sb.append( "{ type " );
155         
156         if ( attributeType != null )
157         {
158             sb.append( attributeType.getName() );
159         }
160         else
161         {
162             sb.append( "null" );
163         }
164         
165         sb.append( ", valuesIn " );
166 
167         if ( valuesIn != null )
168         {
169             sb.append( valuesIn.getName() );
170         }
171         else
172         {
173             sb.append( "null" );
174         }
175         
176         sb.append( "}" );
177         
178         return sb.toString();
179     }
180 }