All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bitbucket.fermenter.stout.authz.AttributeValue Maven / Gradle / Ivy

Go to download

Provides base functionality and patterns for utilizing Authzforce to provide core authorization needs.

There is a newer version: 2.7.0
Show newest version
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);
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy