/************************************************
 * Copyright (c) Shen Li. All rights reserved.  *
 * http://joyaop.sourceforge.net                *
 * -------------------------------------------- *
 * Distributable under LGPL license.            *
 * See terms of license at gnu.org.             *
 ************************************************/
package net.sf.joyaop.demo.rbac.model;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author Shen Li
 */
public class PermissionOwnerImpl implements PermissionOwner {
    private Set permissions = new HashSet();

    public Set getPermissions() {
        return permissions;
    }

    public void setPermissions(Set permissions) {
        this.permissions = permissions;
    }

    public void addPermission(Permission permission) {
        permissions.add(permission);
    }

    public void removePermission(Permission permission) {
        permissions.remove(permission);
    }

    public boolean hasPermission(Permission permission) {
        if (permissions.contains(permission)) {
            return true;
        }
        for (Iterator i = permissions.iterator(); i.hasNext();) {
            if (((Parent) i.next()).hasChild(permission)) {
                return true;
            }
        }
        return false;
    }
}
