source: fedd/abac-src/rtml/src/edu/stanford/rt/credential/DataValuePrincipal.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.1 KB
Line 
1package edu.stanford.rt.credential;
2import edu.stanford.rt.datatype.*;
3/**
4 * @author Ninghui Li, Sandra Qiu<br>
5 *
6 * This class handles <code>Principal</code> element, which consists of
7 * IntegerValue or StringValue.
8 */
9public class DataValuePrincipal extends Principal
10{
11        /**
12         * the principal value, which could be an integer or a string.
13         */
14        private DataValue value;
15
16        /**
17         * Constructor for DataValuePrincipal.
18         *
19         *   Contruct a Principal object using a DataValue object.
20         *   DomainSpecException  is thrown if value passed in is not an instance of
21         *   IntegerValue, StringValue, or KeyValue.
22         *   <br>
23         *   <code>IllegalArgumentException</code> is thrown if value
24         *   is not of <code>IntegerValue</code> or <code>StringValue</code> type.
25        */
26        public DataValuePrincipal(DataValue value)
27        {
28                if (!(value instanceof IntegerValue)
29                        && !(value instanceof StringValue))
30                        throw new IllegalArgumentException("Illegal argument");
31
32                this.value = value;
33        }
34        /**
35         * Method getValue.
36         * @return DataValue
37         */
38        public DataValue getValue()
39        {
40                return value;
41        }
42        /* (non-Javadoc)
43         * @see java.lang.Object#toString()
44         */
45        public String toString()
46        {
47                return value.toString();
48        }
49        /* (non-Javadoc)
50         * @see java.lang.Object#hashCode()
51         */
52        public int hashCode()
53        {
54                return value.hashCode();
55        }
56        /* (non-Javadoc)
57         * @see java.lang.Object#equals(Object)
58         */
59        public boolean equals(Object value)
60        {
61                if (!(value instanceof IntegerValue)
62                        && !(value instanceof StringValue))
63                        return false;
64           
65                if (value instanceof IntegerValue)
66                {
67                        if (!(value instanceof IntegerValue))
68                                return false;
69                        else
70                                return this.hashCode() == value.hashCode();
71                }
72                else
73                {
74                        if (!(value instanceof StringValue))
75                                return false;
76                        else
77                                return this.hashCode() == value.hashCode();
78                }
79        }
80
81        /* (non-Javadoc)
82         * @see edu.stanford.rt.credential.PrincipalExpression#toString(String)
83         */
84        public String toString(String indent)
85        {
86                String thisIndent = indent + "  ";
87                return thisIndent + "DataValuePrincipal: " + value.toString();
88        }
89}
Note: See TracBrowser for help on using the repository browser.