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
22 import java.util.Collection;
23
24 import org.apache.fulcrum.security.entity.Role;
25
26 /**
27 * This class represents a set of Roles. It makes it easy to build a UI that
28 * would allow someone to add a group of Roles to a User. It enforces that only
29 * Role objects are allowed in the set and only relevant methods 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üttel</a>
34 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
35 * @version $Id$
36 */
37 public class RoleSet extends SecuritySet<Role>
38 {
39 /**
40 * Serial number
41 */
42 private static final long serialVersionUID = -7878336668034575930L;
43
44 /**
45 * Constructs an empty RoleSet
46 */
47 public RoleSet()
48 {
49 super();
50 }
51
52 /**
53 * Constructs a new RoleSet 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 roles
59 * A collection of roles to be contained in the set.
60 */
61 public RoleSet(Collection<? extends Role> roles)
62 {
63 this();
64 addAll(roles);
65 }
66
67 /**
68 * Returns a Role with the given name, if it is contained in this RoleSet.
69 *
70 * @param roleName
71 * Name of Role.
72 * @return Role if argument matched a Role in this RoleSet; null if no
73 * match.
74 * @deprecated use getByName()
75 */
76 @Deprecated
77 public Role getRoleByName(String roleName)
78 {
79 return getByName(roleName);
80 }
81
82 /**
83 * Returns a Role with the given id, if it is contained in this RoleSet.
84 *
85 * @param roleId
86 * id of the Role.
87 * @return Role if argument matched a Role in this RoleSet; null if no
88 * match.
89 * @deprecated Use getById()
90 */
91 @Deprecated
92 public Role getRoleById(Object roleId)
93 {
94 return getById(roleId);
95 }
96
97 /**
98 * Print out a RoleSet as a String
99 *
100 * @return The Role Set as String
101 *
102 */
103 @Override
104 public String toString()
105 {
106 StringBuilder sb = new StringBuilder();
107 sb.append("RoleSet: ");
108 sb.append(super.toString());
109
110 return sb.toString();
111 }
112 }