[8780cbec] | 1 | package edu.stanford.rt.credential; |
---|
| 2 | /** |
---|
| 3 | * @author Ninghui Li, Sandra Qiu<br> |
---|
| 4 | * |
---|
| 5 | * Implementation of role definition in RTML, which is represented by |
---|
| 6 | * <code>Definition</code> group element. |
---|
| 7 | * |
---|
| 8 | * A role definition has a head and a body. |
---|
| 9 | */ |
---|
| 10 | public class RoleDefinition |
---|
| 11 | { |
---|
| 12 | /** |
---|
| 13 | * Role head. |
---|
| 14 | */ |
---|
| 15 | private Role head; // always a local role |
---|
| 16 | /** |
---|
| 17 | * Role body. |
---|
| 18 | */ |
---|
| 19 | private PrincipalExpression body; |
---|
| 20 | /** |
---|
| 21 | * role definition context |
---|
| 22 | */ |
---|
| 23 | private CredentialDomain context; |
---|
| 24 | |
---|
| 25 | /** |
---|
| 26 | * Constructor for RoleDefinition. |
---|
| 27 | */ |
---|
| 28 | public RoleDefinition( |
---|
| 29 | CredentialDomain context, |
---|
| 30 | Role head, |
---|
| 31 | PrincipalExpression body) |
---|
| 32 | { |
---|
| 33 | this.context = context; |
---|
| 34 | this.head = head; |
---|
| 35 | this.body = body; |
---|
| 36 | } |
---|
| 37 | /** |
---|
| 38 | * Returns the body. |
---|
| 39 | * @return PrincipalExpression |
---|
| 40 | */ |
---|
| 41 | public PrincipalExpression getBody() |
---|
| 42 | { |
---|
| 43 | return body; |
---|
| 44 | } |
---|
| 45 | /** |
---|
| 46 | * Returns the head. |
---|
| 47 | * @return Role |
---|
| 48 | */ |
---|
| 49 | public Role getHead() |
---|
| 50 | { |
---|
| 51 | return head; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | /** |
---|
| 55 | * Method getContext. |
---|
| 56 | * @return CredentialDomain |
---|
| 57 | */ |
---|
| 58 | public CredentialDomain getContext() throws DomainSpecException |
---|
| 59 | { |
---|
| 60 | if (!context.isComplete()) |
---|
| 61 | throw new DomainSpecException("Incomplete CredentialDomain"); |
---|
| 62 | return context; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /** |
---|
| 66 | * Method toString. |
---|
| 67 | * @param indent |
---|
| 68 | * @return String |
---|
| 69 | */ |
---|
| 70 | public String toString(String indent) |
---|
| 71 | { |
---|
| 72 | String thisIndent = indent + " "; |
---|
| 73 | StringBuffer sb = new StringBuffer(); |
---|
| 74 | sb.append(thisIndent).append("Role Definition: \n"); |
---|
| 75 | sb.append(thisIndent + " ").append("Head: \n"); |
---|
| 76 | sb.append(head.toString(thisIndent + " ")).append("\n"); |
---|
| 77 | sb.append(thisIndent + " ").append("Body: \n"); |
---|
| 78 | sb.append(body.toString(thisIndent + " ")).append("\n"); |
---|
| 79 | return sb.toString(); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | } |
---|