source: fedd/abac-src/rtml/src/edu/stanford/rt/credential/RoleTerm.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: 3.9 KB
Line 
1package edu.stanford.rt.credential;
2
3import java.util.*;
4
5import edu.stanford.rt.util.*;
6import edu.stanford.rt.datatype.*;
7
8/**
9 * @author Ninghui Li, Sandra Qiu<br>
10 *
11 * Implementation of <code>RoleTerm</code> element.  Each RoleTerm object
12 * has  a reference to its corresponding RoleDeclaration object and stores
13 * its parameter values, if any.
14 *
15 */
16public class RoleTerm
17{
18        // The corresponding role declaration.
19        private RoleDeclaration roleDeclaration;
20
21        // Stores parameter values according to the prefix positions in role declaration.
22        private ValueSet[] paramValues;
23
24    /**
25     * Constructor for RoleTerm.
26     *
27     * @param roleDeclaration
28     *      corresponding role declaration.
29     */
30        public RoleTerm(RoleDeclaration roleDeclaration)
31        {
32                this.roleDeclaration = roleDeclaration;
33                this.paramValues =
34                        new ValueSet[roleDeclaration.getTotalPrefixes() + 1];
35                this.paramValues[0] = null;
36        }
37
38        /**
39         * Returns the roleDeclaration.
40         * @return RoleDeclaration 
41         *              The corresonding role decalration for this role term.
42         */
43        public RoleDeclaration getRoleDeclaration()
44        {
45                return roleDeclaration;
46        }
47
48        /**
49         * Method putParameterValue.
50     *      puts parameter value according to the position of the
51     *      its prefix.
52         * @param prefix
53     *      the parameter prefix
54         * @param parameterValue
55     *      the parameter value
56         */
57        public void putParameterValue(
58                String prefix,
59                ValueSet parameterValue)
60        {
61                //RTUtil.debugInfo("RoleTerm.putParameterValue().roleDeclaration = "
62                //          +roleDeclaration.getName());
63                RTUtil.debugInfo(
64                        "RoleTerm.putParameterValue().prefix = " + prefix);
65
66                int index = roleDeclaration.getPosition(prefix);
67                RTUtil.debugInfo(
68                        "RoleTerm.putParameterValue().index = " + index);
69                // empty element for index 0
70                paramValues[index] = parameterValue;
71        }
72
73        /**
74         * Method getParameterValue.
75         * @param prefix
76         * @return ValueSet
77         */
78        public ValueSet getParameterValue(String prefix)
79        {
80                int index = roleDeclaration.getPosition(prefix);
81                return paramValues[index];
82        }
83
84        /**
85         * Method getParameterValueAt.
86         * @param index
87         * @return ValueSet
88         */
89        public ValueSet getParameterValueAt(int index)
90        {
91                return paramValues[index];
92        }
93
94        /**
95         * Method getParameterType.
96         * @param parameterName
97         * @return DataType
98         * @throws DomainSpecException
99         */
100        public DataType getParameterType(String parameterName)
101                throws DomainSpecException
102        {
103                return roleDeclaration.getParameterType(parameterName);
104        }
105
106        public String toString(String indent)
107        {
108                String thisIndent = indent + "  ";
109                StringBuffer sb = new StringBuffer();
110                sb.append(thisIndent).append("RoleTerm: \n");
111                sb.append(thisIndent + "  ").append(
112                        "Corresponding role declaration: ");
113                sb.append(roleDeclaration.getName()).append("\n");
114                sb.append(thisIndent + "  ").append("Parameters: \n");
115                for (int i = 1; i < paramValues.length; i++)
116                {
117                        if (paramValues[i] != null
118                                && !isParameterValueNull(paramValues[i]))
119                                sb
120                                        .append(thisIndent + "    ")
121                                        .append(paramValues[i].toString(thisIndent))
122                                        .append("\n");
123                }
124
125                return sb.toString();
126        }
127   
128    /**
129     * Method isParameterValueNull.
130     *      checks if the parameter value is null. It can be null when
131     *      the parameter has <code>Equals</code> or <code>Special Principal</code>
132     *      child element.
133     * @param paramValue
134     * @return boolean
135     */
136    public boolean isParameterValueNull(ValueSet paramValue)
137    {
138        if (paramValue == null)
139            return true;
140
141        if (!(paramValue instanceof TreeValueSet)
142            && !(paramValue instanceof IntervalValueSet)
143            && !(paramValue instanceof SetValueSet)
144            && !(paramValue instanceof SingletonValueSet))
145            return true;
146        else
147            return false;
148    }
149
150
151
152}
Note: See TracBrowser for help on using the repository browser.