001package org.apache.fulcrum.security.util;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.Collection;
023
024import org.apache.fulcrum.security.entity.Role;
025
026/**
027 * This class represents a set of Roles. It makes it easy to build a UI that
028 * would allow someone to add a group of Roles to a User. It enforces that only
029 * Role objects are allowed in the set and only relevant methods are available.
030 * 
031 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
032 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
033 * @author <a href="mailto:marco@intermeta.de">Marco Kn&uuml;ttel</a>
034 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
035 * @version $Id$
036 */
037public class RoleSet extends SecuritySet<Role>
038{
039    /**
040     * Serial number
041     */
042    private static final long serialVersionUID = -7878336668034575930L;
043
044    /**
045     * Constructs an empty RoleSet
046     */
047    public RoleSet()
048    {
049        super();
050    }
051
052    /**
053     * Constructs a new RoleSet with specified contents.
054     * 
055     * If the given collection contains multiple objects that are identical WRT
056     * equals() method, some objects will be overwritten.
057     * 
058     * @param roles
059     *            A collection of roles to be contained in the set.
060     */
061    public RoleSet(Collection<? extends Role> roles)
062    {
063        this();
064        addAll(roles);
065    }
066
067    /**
068     * Returns a Role with the given name, if it is contained in this RoleSet.
069     * 
070     * @param roleName
071     *            Name of Role.
072     * @return Role if argument matched a Role in this RoleSet; null if no
073     *         match.
074     * @deprecated use getByName()
075     */
076    @Deprecated
077    public Role getRoleByName(String roleName)
078    {
079        return getByName(roleName);
080    }
081
082    /**
083     * Returns a Role with the given id, if it is contained in this RoleSet.
084     * 
085     * @param roleId
086     *            id of the Role.
087     * @return Role if argument matched a Role in this RoleSet; null if no
088     *         match.
089     * @deprecated Use getById()
090     */
091    @Deprecated
092    public Role getRoleById(Object roleId)
093    {
094        return getById(roleId);
095    }
096
097    /**
098     * Print out a RoleSet as a String
099     * 
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}