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;
21  
22  
23  import java.util.ArrayList;
24  import java.util.Collection;
25  import java.util.Collections;
26  
27  
28  /**
29   * Represents permissions to be applied to all {@link ProtectedItem}s in
30   * {@link ItemFirstACIItem}.
31   * 
32   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
33   */
34  public class ItemPermission extends Permission
35  {
36      /** The user classes. */
37      private final Collection<UserClass> userClasses;
38  
39  
40      /**
41       * Creates a new instance
42       * 
43       * @param precedence the precedence of this permission (<tt>-1</tt> to use the
44       *         default)
45       * @param grantsAndDenials the collection of {@link GrantAndDenial}s
46       * @param userClasses the collection of {@link UserClass}es
47       */
48      public ItemPermission( Integer precedence, Collection<GrantAndDenial> grantsAndDenials,
49          Collection<UserClass> userClasses )
50      {
51          super( precedence, grantsAndDenials );
52  
53          this.userClasses = Collections.unmodifiableCollection( new ArrayList<UserClass>( userClasses ) );
54      }
55  
56  
57      /**
58       * Gets the collection of {@link UserClass}es.
59       *
60       * @return the collection of {@link UserClass}es
61       */
62      public Collection<UserClass> getUserClasses()
63      {
64          return userClasses;
65      }
66  
67  
68      /**
69       * {@inheritDoc}
70       */
71      @Override
72      public String toString()
73      {
74          StringBuilder buffer = new StringBuilder();
75  
76          buffer.append( "{ " );
77  
78          if ( getPrecedence() != null )
79          {
80              buffer.append( "precedence " );
81              buffer.append( getPrecedence() );
82              buffer.append( ", " );
83          }
84  
85          buffer.append( "userClasses { " );
86  
87          boolean isFirst = true;
88  
89          for ( UserClass userClass : userClasses )
90          {
91              if ( isFirst )
92              {
93                  isFirst = false;
94              }
95              else
96              {
97                  buffer.append( ", " );
98              }
99  
100             buffer.append( userClass.toString() );
101         }
102 
103         buffer.append( " }, grantsAndDenials { " );
104 
105         isFirst = true;
106 
107         for ( GrantAndDenial grantAndDenial : getGrantsAndDenials() )
108         {
109             if ( isFirst )
110             {
111                 isFirst = false;
112             }
113             else
114             {
115                 buffer.append( ", " );
116             }
117 
118             buffer.append( grantAndDenial.toString() );
119         }
120 
121         buffer.append( " } }" );
122 
123         return buffer.toString();
124     }
125 }