org.bitbucket.fermenter.stout.authz.AttributeValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stout-authzforce Show documentation
Show all versions of stout-authzforce Show documentation
Provides base functionality and patterns for utilizing Authzforce to provide core
authorization needs.
package org.bitbucket.fermenter.stout.authz;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.xml.datatype.XMLGregorianCalendar;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.ow2.authzforce.core.pdp.api.XmlUtils;
import org.ow2.authzforce.core.pdp.api.value.AnyUriValue;
import org.ow2.authzforce.core.pdp.api.value.BooleanValue;
import org.ow2.authzforce.core.pdp.api.value.DateValue;
import org.ow2.authzforce.core.pdp.api.value.DoubleValue;
import org.ow2.authzforce.core.pdp.api.value.IntegerValue;
import org.ow2.authzforce.core.pdp.api.value.MediumInteger;
import org.ow2.authzforce.core.pdp.api.value.StringValue;
/**
* Holds an attribute value returned via a {@link AttributeStoutProvider}.
*/
public class AttributeValue {
private String attributeId;
private T value;
public AttributeValue(String attributeId, T value) {
this.attributeId = attributeId;
this.value = value;
}
public String getAttributeId() {
return attributeId;
}
public T getValue() {
return value;
}
public StringValue getAsStringValue() {
return (value != null) ? new StringValue(value.toString()) : null;
}
public IntegerValue getAsIntegerValue() {
Integer valueAsInteger = (Integer)value;
return (valueAsInteger != null) ? new IntegerValue(new MediumInteger(valueAsInteger.intValue())) : null;
}
public DoubleValue getAsDoubleValue() {
Double valueAsDouble = (Double)value;
return (valueAsDouble != null) ? new DoubleValue(valueAsDouble) : null;
}
public AnyUriValue getAsAnyUriValue() {
return (value != null) ? new AnyUriValue(value.toString()) : null;
}
public BooleanValue getAsBooleanValue() {
Boolean valueAsBoolean = (Boolean)value;
return (valueAsBoolean != null) ? new BooleanValue(valueAsBoolean) : null;
}
public DateValue getAsDateValue() {
Date valueAsDate = (Date)value;
GregorianCalendar valueAsGc = new GregorianCalendar();
valueAsGc.setTime(valueAsDate);
XMLGregorianCalendar xmlGc = XmlUtils.XML_TEMPORAL_DATATYPE_FACTORY.newXMLGregorianCalendar(valueAsGc);
return (valueAsDate != null) ? DateValue.getInstance(xmlGc): null;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}