org.apache.turbine.util.security
Class RoleSet

java.lang.Object
  |
  +--org.apache.turbine.util.security.RoleSet
All Implemented Interfaces:
java.io.Serializable

public class RoleSet
extends java.lang.Object
implements java.io.Serializable

This class represents a set of Roles. It makes it easy to build a UI that would allow someone to add a group of Roles to a User. It wraps a TreeSet object to enforce that only Role objects are allowed in the set and only relevant methods are available. TreeSet's contain only unique Objects (no duplicates).

Version:
$Id: RoleSet.java,v 1.2 2002/07/11 16:53:20 mpoeschl Exp $
Author:
John D. McNally, Brett McLaughlin
See Also:
Serialized Form

Constructor Summary
RoleSet()
          Constructs an empty RoleSet
RoleSet(java.util.Collection roles)
          Constructs a new RoleSet with specifed contents.
 
Method Summary
 boolean add(java.util.Collection roles)
          Adds the Roles in a Collection to this RoleSet.
 boolean add(Role role)
          Adds a Role to this RoleSet.
 boolean add(RoleSet roleSet)
          Adds the Roles in another RoleSet to this RoleSet.
 void clear()
          Removes all Roles from this RoleSet.
 boolean contains(Role role)
          Checks whether this RoleSet contains a Role.
 boolean contains(java.lang.String roleName)
          Compares by name a Role with the Roles contained in this RoleSet.
 java.util.Iterator elements()
          Returns an Iterator for Roles in this RoleSet.
 Role getRole(java.lang.String roleName)
          Returns a Role with the given name, if it is contained in this RoleSet.
 Role[] getRolesArray()
          Returns an Roles[] of Roles in this RoleSet.
 boolean remove(Role role)
          Removes a Role from this RoleSet.
 int size()
          Returns size (cardinality) of this set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RoleSet

public RoleSet()
Constructs an empty RoleSet

RoleSet

public RoleSet(java.util.Collection roles)
Constructs a new RoleSet with specifed contents. If the given collection contains multiple objects that are identical WRT equals() method, some objects will be overwriten.
Parameters:
roles - A collection of roles to be contained in the set.
Method Detail

add

public boolean add(Role role)
Adds a Role to this RoleSet.
Parameters:
role - A Role.
Returns:
True if Role was added; false if RoleSet already contained the Role.

add

public boolean add(java.util.Collection roles)
Adds the Roles in a Collection to this RoleSet.
Parameters:
roles - A Collection of Roles.
Returns:
True if this RoleSet changed as a result; false if no change to this RoleSet occurred (this RoleSet already contained all members of the added RoleSet).

add

public boolean add(RoleSet roleSet)
Adds the Roles in another RoleSet to this RoleSet.
Parameters:
roleSet - A RoleSet.
Returns:
True if this RoleSet changed as a result; false if no change to this RoleSet occurred (this RoleSet already contained all members of the added RoleSet).

remove

public boolean remove(Role role)
Removes a Role from this RoleSet.
Parameters:
role - A Role.
Returns:
True if this RoleSet contained the Role before it was removed.

clear

public void clear()
Removes all Roles from this RoleSet.

contains

public boolean contains(Role role)
Checks whether this RoleSet contains a Role.
Parameters:
role - A Role.
Returns:
True if this RoleSet contains the Role, false otherwise.

contains

public boolean contains(java.lang.String roleName)
Compares by name a Role with the Roles contained in this RoleSet.
Parameters:
roleName - Name of Role.
Returns:
True if argument matched a Role in this RoleSet; false if no match.

getRole

public Role getRole(java.lang.String roleName)
Returns a Role with the given name, if it is contained in this RoleSet.
Parameters:
roleName - Name of Role.
Returns:
Role if argument matched a Role in this RoleSet; null if no match.

getRolesArray

public Role[] getRolesArray()
Returns an Roles[] of Roles in this RoleSet.
Returns:
A Role[].

elements

public java.util.Iterator elements()
Returns an Iterator for Roles in this RoleSet.

size

public int size()
Returns size (cardinality) of this set.
Returns:
The cardinality of this RoleSet.


Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.