FileDocCategorySizeDatePackage
Rights.javaAPI DocGlassfish v2 API12376Wed May 23 10:57:54 BST 2007com.sun.mail.imap

Rights

public class Rights extends Object implements Cloneable
The Rights class represents the set of rights for an authentication identifier (for instance, a user or a group).

A right is represented by the Rights.Right inner class.

A set of standard rights are predefined (see RFC 2086). Most folder implementations are expected to support these rights. Some implementations may also support site-defined rights.

The following code sample illustrates how to examine your rights for a folder.


Rights rights = folder.myRights();

// Check if I can write this folder
if (rights.contains(Rights.Right.WRITE))
System.out.println("Can write folder");

// Now give Joe all my rights, except the ability to write the folder
rights.remove(Rights.Right.WRITE);
ACL acl = new ACL("joe", rights);
folder.setACL(acl);

author
Bill Shannon

Fields Summary
private boolean[]
rights
Constructors Summary
public Rights()
Construct an empty Rights object.

 
public Rights(Rights rights)
Construct a Rights object initialized with the given rights.

param
rights the rights for initialization

	System.arraycopy(rights.rights, 0, this.rights, 0, this.rights.length);
    
public Rights(String rights)
Construct a Rights object initialized with the given rights.

param
rights the rights for initialization

	for (int i = 0; i < rights.length(); i++)
	    add(Right.getInstance(rights.charAt(i)));
    
public Rights(Right right)
Construct a Rights object initialized with the given right.

param
right the right for initialization

	this.rights[(int)right.right] = true;
    
Methods Summary
public voidadd(com.sun.mail.imap.Rights$Right right)
Add the specified right to this Rights object.

param
right the right to add

	this.rights[(int)right.right] = true;
    
public voidadd(com.sun.mail.imap.Rights rights)
Add all the rights in the given Rights object to this Rights object.

param
rights Rights object

	for (int i = 0; i < rights.rights.length; i++)
	    if (rights.rights[i])
		this.rights[i] = true;
    
public java.lang.Objectclone()
Returns a clone of this Rights object.

	Rights r = null;
	try {
	    r = (Rights)super.clone();
	    r.rights = new boolean[128];
	    System.arraycopy(this.rights, 0, r.rights, 0, this.rights.length);
	} catch (CloneNotSupportedException cex) {
	    // ignore, can't happen
	}
	return r;
    
public booleancontains(com.sun.mail.imap.Rights rights)
Check whether all the rights in the specified Rights object are present in this Rights object.

return
true if all rights in the given Rights object are present, otherwise false.

	for (int i = 0; i < rights.rights.length; i++)
	    if (rights.rights[i] && !this.rights[i])
		return false;

	// If we've made it till here, return true
	return true;
    
public booleancontains(com.sun.mail.imap.Rights$Right right)
Check whether the specified right is present in this Rights object.

return
true of the given right is present, otherwise false.

	return this.rights[(int)right.right];
    
public booleanequals(java.lang.Object obj)
Check whether the two Rights objects are equal.

return
true if they're equal

	if (!(obj instanceof Rights))
	    return false;

	Rights rights = (Rights)obj;

	for (int i = 0; i < rights.rights.length; i++)
	    if (rights.rights[i] != this.rights[i])
		return false;

	return true;
    
public com.sun.mail.imap.Rights$Right[]getRights()
Return all the rights in this Rights object. Returns an array of size zero if no rights are set.

return
array of Rights.Right objects representing rights

	Vector v = new Vector();
	for (int i = 0; i < this.rights.length; i++)
	    if (this.rights[i])
		v.addElement(Right.getInstance((char)i));
	Right[] rights = new Right[v.size()];
	v.copyInto(rights);
	return rights;
    
public inthashCode()
Compute a hash code for this Rights object.

return
the hash code

	int hash = 0;
	for (int i = 0; i < this.rights.length; i++)
	    if (this.rights[i])
		hash++;
	return hash;
    
public voidremove(com.sun.mail.imap.Rights$Right right)
Remove the specified right from this Rights object.

param
right the right to be removed

	this.rights[(int)right.right] = false;
    
public voidremove(com.sun.mail.imap.Rights rights)
Remove all rights in the given Rights object from this Rights object.

param
rights the rights to be removed

	for (int i = 0; i < rights.rights.length; i++)
	    if (rights.rights[i])
		this.rights[i] = false;
    
public java.lang.StringtoString()

	StringBuffer sb = new StringBuffer();
	for (int i = 0; i < this.rights.length; i++)
	    if (this.rights[i])
		sb.append((char)i);
	return sb.toString();