source: fedd/abac-src/rtml/src/edu/stanford/rt/credential/Role.java @ 8780cbec

axis_examplecompt_changesinfo-opsversion-1.30version-2.00version-3.01version-3.02
Last change on this file since 8780cbec was 8780cbec, checked in by Jay Jacobs <Jay.Jacobs@…>, 15 years ago

ABAC sources from Cobham

  • Property mode set to 100644
File size: 2.0 KB
Line 
1package edu.stanford.rt.credential;
2/**
3 * @author Ninghui Li, Sandra Qiu<br>
4 *
5 * Implementation of <code>Role</code> object in RTML.
6 * A role consists of 2 parts: a principal and a role term.
7 */
8public class Role implements PrincipalExpression
9{
10        private Principal principal; // required element.
11        private RoleTerm roleTerm; // required element.
12        /**
13         * Constructor for Role.
14         */
15        public Role(Principal principal, RoleTerm roleTerm)
16        {
17                this.principal = principal;
18                this.roleTerm = roleTerm;
19        }
20        /* (non-Javadoc)
21         * @see java.lang.Object#hashCode()
22         */
23        public int hashCode()
24        {
25                return getPrincipal().hashCode() * 2 + getName().hashCode();
26        }
27        /**
28         * Two roles are equal if both their principals are equal and
29         * the role names are equal.
30         *
31         */
32        public boolean equals(Object o)
33        {
34                return (o instanceof Role)
35                        && getPrincipal().equals(((Role) o).getPrincipal())
36                        && getName().equals(((Role) o).getName());
37        }
38        /**
39         * Returns the principal.
40         * @return Principal
41         */
42        public Principal getPrincipal()
43        {
44                return principal;
45        }
46        /**
47         * Returns the roleTerm.
48         * @return RoleTerm
49         */
50        public RoleTerm getRoleTerm()
51        {
52                return roleTerm;
53        }
54        /**
55         * Method getRoleDeclaration.
56         * @return RoleDeclaration
57         *              The corresponding role declaration.
58         */
59        public RoleDeclaration getRoleDeclaration()
60        {
61                return roleTerm.getRoleDeclaration();
62        }
63        /**
64         * Method getName.
65         * @return String
66         *              The role name.
67         */
68        public String getName()
69        {
70                return roleTerm.getRoleDeclaration().getName();
71        }
72        /* (non-Javadoc)
73         * @see edu.stanford.rt.credential.PrincipalExpression#toString(String)
74         */
75        public String toString(String indent)
76        {
77                String thisIndent = indent + "  ";
78
79                StringBuffer sb = new StringBuffer();
80                sb.append(thisIndent).append("Role: \n");
81                if (principal != null)
82                        sb.append(principal.toString(thisIndent + "  ")).append(
83                                "\n");
84                sb.append(roleTerm.toString(thisIndent + "  ")).append("\n");
85                return sb.toString();
86        }
87}
Note: See TracBrowser for help on using the repository browser.