View Javadoc
1   package org.apache.fulcrum.security.util;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  import java.util.Collection;
22  
23  import org.apache.fulcrum.security.entity.Permission;
24  
25  /**
26   * This class represents a set of Permissions. It makes it easy to build a UI
27   * that would allow someone to add a group of Permissions to a Role. It enforces
28   * that only Permission objects are allowed in the set and only relevant methods
29   * are available.
30   * 
31   * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
32   * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
33   * @author <a href="mailto:marco@intermeta.de">Marco Kn&uuml;ttel</a>
34   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
35   * @version $Id$
36   */
37  public class PermissionSet extends SecuritySet<Permission>
38  {
39      /**
40       * Serial number
41       */
42      private static final long serialVersionUID = 4532868341893924965L;
43  
44      /**
45       * Constructs an empty PermissionSet
46       */
47      public PermissionSet()
48      {
49          super();
50      }
51  
52      /**
53       * Constructs a new PermissionSet with specified contents.
54       * 
55       * If the given collection contains multiple objects that are identical WRT
56       * equals() method, some objects will be overwritten.
57       * 
58       * @param permissions
59       *            A collection of permissions to be contained in the set.
60       */
61      public PermissionSet(Collection<? extends Permission> permissions)
62      {
63          this();
64          addAll(permissions);
65      }
66  
67      /**
68       * Returns a Permission with the given name, if it is contained in this
69       * PermissionSet.
70       * 
71       * @param permissionName
72       *            Name of Permission.
73       * @return Permission if argument matched a Permission in this
74       *         PermissionSet; null if no match.
75       * @deprecated use getByName()
76       */
77      @Deprecated
78      public Permission getPermissionByName(String permissionName)
79      {
80          return getByName(permissionName);
81      }
82  
83      /**
84       * Returns a Permission with the given id, if it is contained in this
85       * PermissionSet.
86       * 
87       * @param permissionId
88       *            Id of the Permission.
89       * @return Permission if argument matched a Permission in this
90       *         PermissionSet; null if no match.
91       * @deprecated Use getById()
92       */
93      @Deprecated
94      public Permission getPermissionById(Object permissionId)
95      {
96          return getById(permissionId);
97      }
98  
99      /**
100      * Print out a PermissionSet as a String
101      * 
102      * @return The Permission Set as String
103      * 
104      */
105     @Override
106     public String toString()
107     {
108         StringBuilder sb = new StringBuilder();
109         sb.append("PermissionSet: ");
110         sb.append(super.toString());
111 
112         return sb.toString();
113     }
114 }