2009-11-12 04:19:49 UTC
If I have ClassA and ClassB that both extend the Permissible class - will calling ClassA.addPermission(param1, param2) have the same effect as calling ClassB.addPermission(param1, param2)?
If this is the case - how do I modify it so that the hashmap ClassA.classPermissions is different from ClassB.classPermissions? I'd like to keep this functionality in the Permissible class if possible since it will be used in a lot of different places through my project.
Thanks for any help :)
package uk.ac.stand.cs.jh2009d.model.permission;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
/**
*
The superclass of any object associated with permission restrictions.
* Permissable objects contain mappings from Accessor classes to sets
* of Permission objects, each set describing the permissions that
* Accessor has (or does not have by omission) over the Permissable
* object.
* @author Pete Martin
*/
public abstract class Permissible {
private static HashMap
/**
*
Adds a permission for a particular Accessor class.
*
* @param accessorClass The accessor class to set the permission for
* @param permission The permission to set
*/
public static void addPermission(Class extends Accessor> accessorClass,Permission permission) {
if (!classPermissions.containsKey(accessorClass))
classPermissions.put(accessorClass, new HashSet
classPermissions.get(accessorClass).add(permission);
}
/**
*
Removes a permission for a particular Accessor class.
*
* @param accessorClass The accessor class to remove the permission for
* @param permission The permission to remove
*
* @return true if the permission has been removed
*/
public static boolean removePermission(Class extends Accessor> accessorClass, Permission permission) {
if (!classPermissions.containsKey(accessorClass))
return false;
return classPermissions.get(accessorClass).remove(permission);
}
/**
*
Verifies whether the specified accessor class has the specified permission
* for this permissable object.
*
* @param accessorClass The accessor class to remove the permission for
* @param permission The permission to remove
*
* @return true if the accessor class has the permission
*/
public static boolean hasPermission(Class extends Accessor> accessorClass, Permission permission) {
if (!classPermissions.containsKey(accessorClass))
return false;
return classPermissions.get(accessorClass).contains(permission);
}
}