package edu.stanford.rt.credential; /** * @author Ninghui Li, Sandra Qiu
* * Implementation of Role object in RTML. * A role consists of 2 parts: a principal and a role term. */ public class Role implements PrincipalExpression { private Principal principal; // required element. private RoleTerm roleTerm; // required element. /** * Constructor for Role. */ public Role(Principal principal, RoleTerm roleTerm) { this.principal = principal; this.roleTerm = roleTerm; } /* (non-Javadoc) * @see java.lang.Object#hashCode() */ public int hashCode() { return getPrincipal().hashCode() * 2 + getName().hashCode(); } /** * Two roles are equal if both their principals are equal and * the role names are equal. * */ public boolean equals(Object o) { return (o instanceof Role) && getPrincipal().equals(((Role) o).getPrincipal()) && getName().equals(((Role) o).getName()); } /** * Returns the principal. * @return Principal */ public Principal getPrincipal() { return principal; } /** * Returns the roleTerm. * @return RoleTerm */ public RoleTerm getRoleTerm() { return roleTerm; } /** * Method getRoleDeclaration. * @return RoleDeclaration * The corresponding role declaration. */ public RoleDeclaration getRoleDeclaration() { return roleTerm.getRoleDeclaration(); } /** * Method getName. * @return String * The role name. */ public String getName() { return roleTerm.getRoleDeclaration().getName(); } /* (non-Javadoc) * @see edu.stanford.rt.credential.PrincipalExpression#toString(String) */ public String toString(String indent) { String thisIndent = indent + " "; StringBuffer sb = new StringBuffer(); sb.append(thisIndent).append("Role: \n"); if (principal != null) sb.append(principal.toString(thisIndent + " ")).append( "\n"); sb.append(roleTerm.toString(thisIndent + " ")).append("\n"); return sb.toString(); } }