FileDocCategorySizeDatePackage
MemoryGroup.javaAPI DocApache Tomcat 6.0.145483Fri Jul 20 04:20:36 BST 2007org.apache.catalina.users

MemoryGroup

public class MemoryGroup extends AbstractGroup

Concrete implementation of {@link org.apache.catalina.Group} for the {@link MemoryUserDatabase} implementation of {@link UserDatabase}.

author
Craig R. McClanahan
version
$Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
since
4.1

Fields Summary
protected MemoryUserDatabase
database
The {@link MemoryUserDatabase} that owns this group.
protected ArrayList
roles
The set of {@link Role}s associated with this group.
Constructors Summary
MemoryGroup(MemoryUserDatabase database, String groupname, String description)
Package-private constructor used by the factory method in {@link MemoryUserDatabase}.

param
database The {@link MemoryUserDatabase} that owns this group
param
groupname Group name of this group
param
description Description of this group


        super();
        this.database = database;
        setGroupname(groupname);
        setDescription(description);

    
Methods Summary
public voidaddRole(org.apache.catalina.Role role)
Add a new {@link Role} to those assigned specifically to this group.

param
role The new role


        synchronized (roles) {
            if (!roles.contains(role)) {
                roles.add(role);
            }
        }

    
public java.util.IteratorgetRoles()
Return the set of {@link Role}s assigned specifically to this group.



    // ------------------------------------------------------------- Properties


                    
       

        synchronized (roles) {
            return (roles.iterator());
        }

    
public org.apache.catalina.UserDatabasegetUserDatabase()
Return the {@link UserDatabase} within which this Group is defined.


        return (this.database);

    
public java.util.IteratorgetUsers()
Return the set of {@link org.apache.catalina.User}s that are members of this group.


        ArrayList results = new ArrayList();
        Iterator users = database.getUsers();
        while (users.hasNext()) {
            MemoryUser user = (MemoryUser) users.next();
            if (user.isInGroup(this)) {
                results.add(user);
            }
        }
        return (results.iterator());

    
public booleanisInRole(org.apache.catalina.Role role)
Is this group specifically assigned the specified {@link Role}?

param
role The role to check


        synchronized (roles) {
            return (roles.contains(role));
        }

    
public voidremoveRole(org.apache.catalina.Role role)
Remove a {@link Role} from those assigned to this group.

param
role The old role


        synchronized (roles) {
            roles.remove(role);
        }

    
public voidremoveRoles()
Remove all {@link Role}s from those assigned to this group.


        synchronized (roles) {
            roles.clear();
        }

    
public java.lang.StringtoString()

Return a String representation of this group in XML format.


        StringBuffer sb = new StringBuffer("<group groupname=\"");
        sb.append(groupname);
        sb.append("\"");
        if (description != null) {
            sb.append(" description=\"");
            sb.append(description);
            sb.append("\"");
        }
        synchronized (roles) {
            if (roles.size() > 0) {
                sb.append(" roles=\"");
                int n = 0;
                Iterator values = roles.iterator();
                while (values.hasNext()) {
                    if (n > 0) {
                        sb.append(',");
                    }
                    n++;
                    sb.append((String) ((Role) values.next()).getRolename());
                }
                sb.append("\"");
            }
        }
        sb.append("/>");
        return (sb.toString());