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 java.util.Collections;
24  import java.util.Iterator;
25  import java.util.Set;
26  
27  import org.apache.directory.api.ldap.aci.ProtectedItem;
28  
29  
30  /**
31   * Restricts the maximum number of attribute values allowed for a specified
32   * attribute type. It is examined if the protected item is an attribute
33   * value of the specified type and the permission sought is add. Values of
34   * that attribute in the entry are counted without regard to context or
35   * access control and as though the operation which adds the values were
36   * successful. If the number of values in the attribute exceeds maxCount,
37   * the ACI item is treated as not granting add access.
38   */
39  public class MaxValueCountItem extends ProtectedItem
40  {
41      /** The set of elements to protect */
42      private final Set<MaxValueCountElem> items;
43  
44  
45      /**
46       * Creates a new instance.
47       * 
48       * @param items the collection of {@link MaxValueCountElem}s.
49       */
50      public MaxValueCountItem( Set<MaxValueCountElem> items )
51      {
52          this.items = Collections.unmodifiableSet( items );
53      }
54  
55  
56      /**
57       * Gets an iterator of all {@link MaxValueCountElem}s.
58       *
59       * @return an iterator of all {@link MaxValueCountElem}s
60       */
61      public Iterator<MaxValueCountElem> iterator()
62      {
63          return items.iterator();
64      }
65  
66  
67      /**
68       * {@inheritDoc}
69       */
70      @Override
71      public int hashCode()
72      {
73          int hash = 37;
74          hash = hash * 17 + items.hashCode();
75          return hash;
76      }
77  
78  
79      /**
80       * {@inheritDoc}
81       */
82      @Override
83      public boolean equals( Object o )
84      {
85          if ( this == o )
86          {
87              return true;
88          }
89  
90          if ( o == null )
91          {
92              return false;
93          }
94  
95          if ( o instanceof MaxValueCountItem )
96          {
97              MaxValueCountItem that = ( MaxValueCountItem ) o;
98              return this.items.equals( that.items );
99          }
100 
101         return false;
102     }
103 
104 
105     /**
106      * {@inheritDoc}
107      */
108     @Override
109     public String toString()
110     {
111         StringBuilder buf = new StringBuilder();
112 
113         buf.append( "maxValueCount {" );
114 
115         boolean isFirst = true;
116 
117         for ( MaxValueCountElem item : items )
118         {
119             if ( isFirst )
120             {
121                 isFirst = false;
122             }
123             else
124             {
125                 buf.append( ", " );
126             }
127 
128             buf.append( item.toString() );
129         }
130 
131         buf.append( "}" );
132 
133         return buf.toString();
134     }
135 }