package edu.stanford.rt.credential;
/**
* @author Ninghui Li, Sandra Qiu
*
* Implementation of role definition in RTML, which is represented by
* Definition
group element.
*
* A role definition has a head and a body.
*/
public class RoleDefinition
{
/**
* Role head.
*/
private Role head; // always a local role
/**
* Role body.
*/
private PrincipalExpression body;
/**
* role definition context
*/
private CredentialDomain context;
/**
* Constructor for RoleDefinition.
*/
public RoleDefinition(
CredentialDomain context,
Role head,
PrincipalExpression body)
{
this.context = context;
this.head = head;
this.body = body;
}
/**
* Returns the body.
* @return PrincipalExpression
*/
public PrincipalExpression getBody()
{
return body;
}
/**
* Returns the head.
* @return Role
*/
public Role getHead()
{
return head;
}
/**
* Method getContext.
* @return CredentialDomain
*/
public CredentialDomain getContext() throws DomainSpecException
{
if (!context.isComplete())
throw new DomainSpecException("Incomplete CredentialDomain");
return context;
}
/**
* Method toString.
* @param indent
* @return String
*/
public String toString(String indent)
{
String thisIndent = indent + " ";
StringBuffer sb = new StringBuffer();
sb.append(thisIndent).append("Role Definition: \n");
sb.append(thisIndent + " ").append("Head: \n");
sb.append(head.toString(thisIndent + " ")).append("\n");
sb.append(thisIndent + " ").append("Body: \n");
sb.append(body.toString(thisIndent + " ")).append("\n");
return sb.toString();
}
}