package edu.stanford.rt.credential;
import edu.stanford.rt.datatype.*;
/**
* @author Ninghui Li, Sandra Qiu
*
* This class handles Principal
element, which consists of
* IntegerValue or StringValue.
*/
public class DataValuePrincipal extends Principal
{
/**
* the principal value, which could be an integer or a string.
*/
private DataValue value;
/**
* Constructor for DataValuePrincipal.
*
* Contruct a Principal object using a DataValue object.
* DomainSpecException is thrown if value passed in is not an instance of
* IntegerValue, StringValue, or KeyValue.
*
* IllegalArgumentException
is thrown if value
* is not of IntegerValue
or StringValue
type.
*/
public DataValuePrincipal(DataValue value)
{
if (!(value instanceof IntegerValue)
&& !(value instanceof StringValue))
throw new IllegalArgumentException("Illegal argument");
this.value = value;
}
/**
* Method getValue.
* @return DataValue
*/
public DataValue getValue()
{
return value;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString()
{
return value.toString();
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode()
{
return value.hashCode();
}
/* (non-Javadoc)
* @see java.lang.Object#equals(Object)
*/
public boolean equals(Object value)
{
if (!(value instanceof IntegerValue)
&& !(value instanceof StringValue))
return false;
if (value instanceof IntegerValue)
{
if (!(value instanceof IntegerValue))
return false;
else
return this.hashCode() == value.hashCode();
}
else
{
if (!(value instanceof StringValue))
return false;
else
return this.hashCode() == value.hashCode();
}
}
/* (non-Javadoc)
* @see edu.stanford.rt.credential.PrincipalExpression#toString(String)
*/
public String toString(String indent)
{
String thisIndent = indent + " ";
return thisIndent + "DataValuePrincipal: " + value.toString();
}
}