org.locomotive.loco.perm
Class PermissionSet

java.lang.Object
  |
  +--org.locomotive.loco.perm.PermissionSet
Direct Known Subclasses:
Role

public class PermissionSet
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Provides a data structure to store a set of permissions. A PermissionSet contains a bitfield in which each bit is associated with a permission. The PermissionSet is said to contain a permission if the corresponding bit is set in its bitfield.

See Also:
Serialized Form

Constructor Summary
PermissionSet()
          Creates an empty permission set.
PermissionSet(boolean[] values)
          Creates a permission set initialized to the bitfield contained in the array of booleans.
PermissionSet(int userid)
          Creates an empty permission set with the specified userid
PermissionSet(java.util.Vector ints)
          Creates a permission set initialized to the bitfield contained in the Vector of Integers.
 
Method Summary
 PermissionSet and(PermissionSet pSet)
          'Ands' this PermissionSet with another PermissionSet.
 PermissionSet clear()
          Clears all permissions in the permission set.
 java.lang.Object clone()
          Makes a clone of this PermissionSet.
static boolean exists(java.lang.String permName)
          Deprecated. in favor of Permission.exists()
static Permission get(java.lang.String permName)
          Deprecated. in favor of Permission.get()
 SortableTable getPermTable()
          returns a SortableTable of all the permissions and whether or not this permission set has them set.
 java.util.Vector getSetPerms()
          Returns an enumeration of all set permission names.
 int getUserid()
          gets the userid for this permission set
static void initialize(java.sql.Connection conn)
          Deprecated. in favor of Permission.initializeCache();
protected  boolean isSet(int position)
          a handy little method for package internal use in UserPerm
 boolean isSet(Permission perm)
          Checks if a permission is set in the permission set.
 boolean isSet(java.lang.String permName)
          Checks if a permission is set in the permission set.
 boolean isSubsetOf(PermissionSet pSet)
          Sees if this PermissionSet is a subset of another PermissionSet.
static java.util.Vector names()
          Deprecated. in favor of Permission.getPermissions()
 PermissionSet or(PermissionSet pSet)
          'Ors' this PermissionSet with another PermissionSet.
 PermissionSet set(Permission perm)
          Sets a permission in the permission set.
 PermissionSet set(java.lang.String permName)
          Sets a permission in the permission set.
 PermissionSet setAll()
          Sets all permissions in the permission set.
 void setBitfield(boolean[] values)
          takes an array of booleans and sets them as our new bitfield.
 PermissionSet setBitfield(java.util.Vector ints)
          Takes a Vector of Integers (in the format created by the toInts<\code> method), and sets it as our new bitfield.
 PermissionSet setOnOrOff(Permission perm, boolean on_or_off)
          Sets a permission in the permission set.
 PermissionSet setOnOrOff(java.lang.String permName, boolean on_or_off)
          Sets a permission in the permission set.
 void setUserid(int userid)
          sets the userid for this permission set
 int size()
          returns the size of the permission set
 boolean[] toArray()
          Transforms the Bitfield into an array of booleans.
 java.util.Vector toInts()
          Transforms the BitSet's bitfield into a Vector of Integers.
 java.lang.String toString()
          Returns the the userid + BitSet's toString().
 PermissionSet unset(Permission perm)
          Unsets a permission in the permission set.
 PermissionSet unset(java.lang.String permName)
          Unsets a permission in the permission set.
 PermissionSet xor(PermissionSet pSet)
          'Xors' the PermissionSet with another PermissionSet.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PermissionSet

public PermissionSet()
Creates an empty permission set.

PermissionSet

public PermissionSet(int userid)
Creates an empty permission set with the specified userid

PermissionSet

public PermissionSet(java.util.Vector ints)
Creates a permission set initialized to the bitfield contained in the Vector of Integers. Used for loading a permission set from the database.
Parameters:
ints - Vector of Integers representing a permissions bitfield

PermissionSet

public PermissionSet(boolean[] values)
Creates a permission set initialized to the bitfield contained in the array of booleans. An alternative means of loading a permission set from the database.
Parameters:
ints - Vector of Integers representing a permissions bitfield
Method Detail

initialize

public static void initialize(java.sql.Connection conn)
                       throws java.sql.SQLException
Deprecated. in favor of Permission.initializeCache();

Reads permissions from the database and puts them into the permission hash. This function must be executed before any instances of this class are created.
Parameters:
conn - Connection object to the database
Throws:
java.sql.SQLException - if a database error occurs

get

public static Permission get(java.lang.String permName)
Deprecated. in favor of Permission.get()

Retrieves a permission from the database.
Parameters:
permName - String name of the permission to be retrieved
Returns:
Permission object of the specified name

names

public static java.util.Vector names()
Deprecated. in favor of Permission.getPermissions()

Returns an enumeration of all permission names in the database.
Returns:
Vector of String permission names

exists

public static boolean exists(java.lang.String permName)
Deprecated. in favor of Permission.exists()

Checks the existence of a permission in the database.
Parameters:
permName - String name of the permission
Returns:
true if the permission exists in the database

setUserid

public void setUserid(int userid)
sets the userid for this permission set

getUserid

public int getUserid()
gets the userid for this permission set

setOnOrOff

public PermissionSet setOnOrOff(java.lang.String permName,
                                boolean on_or_off)
Sets a permission in the permission set.
Parameters:
permName - name of the permission to set
on_or_off - whether to set the permission to on or off.

setOnOrOff

public PermissionSet setOnOrOff(Permission perm,
                                boolean on_or_off)
Sets a permission in the permission set.
Parameters:
perm - the permission to set
on_or_off - whether to set the permission to on or off.

set

public PermissionSet set(java.lang.String permName)
Sets a permission in the permission set.
Parameters:
permName - name of the permission to set

set

public PermissionSet set(Permission perm)
Sets a permission in the permission set.
Parameters:
perm - the permission to set

setAll

public PermissionSet setAll()
Sets all permissions in the permission set.

unset

public PermissionSet unset(java.lang.String permName)
Unsets a permission in the permission set.
Parameters:
permName - name of the permission to clear

unset

public PermissionSet unset(Permission perm)
Unsets a permission in the permission set.
Parameters:
perm - the permission to clear

clear

public PermissionSet clear()
Clears all permissions in the permission set.

isSet

public boolean isSet(java.lang.String permName)
Checks if a permission is set in the permission set.
Parameters:
permName - name of the permission in question
Returns:
true if the permission is set

isSet

public boolean isSet(Permission perm)
Checks if a permission is set in the permission set.
Parameters:
perm - the permission in question
Returns:
true if the permission is set

isSet

protected boolean isSet(int position)
a handy little method for package internal use in UserPerm

getSetPerms

public java.util.Vector getSetPerms()
Returns an enumeration of all set permission names.
Returns:
Vector of String names

getPermTable

public SortableTable getPermTable()
returns a SortableTable of all the permissions and whether or not this permission set has them set. Has the columns:
   0 perm_id (int)       1 perm_name (String)
   2 is_set  (boolean)
 
This table is sorted by Permission name.

and

public PermissionSet and(PermissionSet pSet)
'Ands' this PermissionSet with another PermissionSet.
Parameters:
pSet - PermissionSet with which to be 'And'ed

or

public PermissionSet or(PermissionSet pSet)
'Ors' this PermissionSet with another PermissionSet.
Parameters:
pSet - PermissionSet with which to be 'Or'ed

xor

public PermissionSet xor(PermissionSet pSet)
'Xors' the PermissionSet with another PermissionSet.
Parameters:
pSet - PermissionSet with which to be 'Xor'ed

size

public int size()
returns the size of the permission set

isSubsetOf

public boolean isSubsetOf(PermissionSet pSet)
Sees if this PermissionSet is a subset of another PermissionSet.
Parameters:
pSet - PermissionSet being tested with
Returns:
true if this PermissionSet is a subset of the parameter PermissionSet

toInts

public java.util.Vector toInts()
Transforms the BitSet's bitfield into a Vector of Integers. The Vector can have any number of Integers. Integers are 32 bits, so the BitSet will be a size of X * 32, where X is the number of Integers. Used primarily for storage in the database.
Returns:
Vector of Integers representing the PermissionSet's bitfield.

setBitfield

public PermissionSet setBitfield(java.util.Vector ints)
Takes a Vector of Integers (in the format created by the toInts<\code> method), and sets it as our new bitfield.
Parameters:
ints - Vector of Integers representing the PermissionsSet bitfield

toArray

public boolean[] toArray()
Transforms the Bitfield into an array of booleans. The booleans represent the each of the bits. Should be used as an alternate means to toInts() of storage in the database
See Also:
toInts()

setBitfield

public void setBitfield(boolean[] values)
takes an array of booleans and sets them as our new bitfield. An alternative to using the Vector method.
Parameters:
values - the array of boolean values to use as the bitfield

toString

public java.lang.String toString()
Returns the the userid + BitSet's toString().
Overrides:
toString in class java.lang.Object

clone

public java.lang.Object clone()
Makes a clone of this PermissionSet.
Overrides:
clone in class java.lang.Object