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  public class RestrictedByElem
30  {
31      /** The AttributeType on which the restriction is applied */
32      private AttributeType attributeType;
33  
34      /** The list of allowed AttributeType values */
35      private AttributeType valuesIn;
36  
37  
38      /**
39       * Creates a new instance.
40       * 
41       * @param attributeType the attribute type to restrict
42       * @param valuesIn the attribute type only whose values are allowed in <tt>attributeType</tt>.
43       */
44      public RestrictedByElem( AttributeType attributeType, AttributeType valuesIn )
45      {
46          this.attributeType = attributeType;
47          this.valuesIn = valuesIn;
48      }
49  
50  
51      /**
52       * Gets the attribute type to restrict.
53       *
54       * @return the attribute type
55       */
56      public AttributeType getAttributeType()
57      {
58          return attributeType;
59      }
60  
61  
62      /**
63       * Gets the attribute type only whose values are allowed in
64       * <tt>attributeType</tt>.
65       *
66       * @return the list of allowed AttributeType values
67       */
68      public AttributeType getValuesIn()
69      {
70          return valuesIn;
71      }
72  
73  
74      /**
75       * {@inheritDoc}
76       */
77      @Override
78      public int hashCode()
79      {
80          int hash = 37;
81          hash = hash * 17 + attributeType.hashCode();
82          hash = hash * 17 + valuesIn.hashCode();
83          return hash;
84      }
85  
86  
87      /**
88       * {@inheritDoc}
89       */
90      @Override
91      public boolean equals( Object o )
92      {
93          if ( o == null )
94          {
95              return false;
96          }
97  
98          if ( this == o )
99          {
100             return true;
101         }
102 
103         if ( o instanceof RestrictedByElem )
104         {
105             RestrictedByElem that = ( RestrictedByElem ) o;
106             if ( this.attributeType == null )
107             {
108                 if ( that.attributeType == null )
109                 {
110                     if ( this.valuesIn == null )
111                     {
112                         return that.valuesIn == null;
113                     }
114                     else
115                     {
116                         return this.valuesIn.equals( that.valuesIn );
117                     }
118                 }
119                 return false;
120             }
121             else
122             {
123                 if ( this.attributeType.equals( that.attributeType ) )
124                 {
125                     if ( this.valuesIn == null )
126                     {
127                         return that.valuesIn == null;
128                     }
129                     else
130                     {
131                         return this.valuesIn.equals( that.valuesIn );
132                     }
133                 }
134                 return false;
135             }
136         }
137         return false;
138     }
139 
140 
141     /**
142      * {@inheritDoc}
143      */
144     @Override
145     public String toString()
146     {
147         return "{ type " + attributeType.getName() + ", valuesIn " + valuesIn.getName() + " }";
148     }
149 }