com.att.research.xacml.std.pip.StdMutablePIPResponse Maven / Gradle / Ivy
/*
* AT&T - PROPRIETARY
* THIS FILE CONTAINS PROPRIETARY INFORMATION OF
* AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN
* ACCORDANCE WITH APPLICABLE AGREEMENTS.
*
* Copyright (c) 2013 AT&T Knowledge Ventures
* Unpublished and Not for Publication
* All Rights Reserved
*/
package com.att.research.xacml.std.pip;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import com.att.research.xacml.api.Attribute;
import com.att.research.xacml.api.Status;
import com.att.research.xacml.api.pip.PIPResponse;
import com.att.research.xacml.std.StdStatus;
/**
* Mutable implementation of the {@link com.att.research.xacml.api.pip.PIPResponse} interface with methods for
* keeping a collection of {@link com.att.research.xacml.api.Attribute}s with a {@link com.att.research.xacml.api.Status}.
*
* @author Christopher A. Rath
* @version $Revision: 1.2 $
*/
public class StdMutablePIPResponse implements PIPResponse {
private static final List EMPTY_LIST = Collections.unmodifiableList(new ArrayList());
private List attributes = EMPTY_LIST;
private Status status;
private boolean simple;
/**
* Creates a new StdMutablePIPResponse
with the given {@link com.att.research.xacml.api.Status}.
*
* @param statusIn the Status
of the new StdMutablePIPResponse
*/
public StdMutablePIPResponse(Status statusIn) {
this.status = statusIn;
this.simple = true;
}
/**
* Creates a new StdMutablePIPResponse
with an OK {@link com.att.research.xacml.api.Status} and the single
* given {@link com.att.research.xacml.api.Attribute}.
*
* @param attribute the Attribute
for the new StdMutablePIPResponse
>
*/
public StdMutablePIPResponse(Attribute attribute) {
this(StdStatus.STATUS_OK);
if (attribute != null) {
this.addAttribute(attribute);
}
}
/**
* Creates a new StdMutablePIPResponse
with an OK {@link com.att.research.xacml.api.Status} and a copy of
* the given Collection
of {@link com.att.research.xacml.api.Attribute}s.
*
* @param attributesIn the Collection
of Attribute
s for the new StdMutablePIPResponse
.
*/
public StdMutablePIPResponse(Collection attributesIn) {
this(StdStatus.STATUS_OK);
if (attributesIn != null) {
this.addAttributes(attributesIn);
}
}
/**
* Creates a new StdMutablePIPResponse
with an OK {@link com.att.research.xacml.api.Status}.
*/
public StdMutablePIPResponse() {
this(StdStatus.STATUS_OK);
}
@Override
public Status getStatus() {
return this.status;
}
/**
* Sets the {@link com.att.research.xacml.api.Status} for this StdMutablePIPResponse
>
*
* @param statusIn the Status
for this StdMutablePIPResponse
.
*/
public void setStatus(Status statusIn) {
this.status = statusIn;
}
@Override
public boolean isSimple() {
return this.simple;
}
@Override
public Collection getAttributes() {
return (this.attributes == EMPTY_LIST ? this.attributes : Collections.unmodifiableCollection(this.attributes));
}
/**
* Adds a single {@link com.att.research.xacml.api.Attribute} to this StdMutablePIPResponse
.
*
* @param attributeIn the Attribute
to add to this StdMutablePIPResponse
.
*/
public void addAttribute(Attribute attributeIn) {
if (this.attributes == EMPTY_LIST) {
this.attributes = new ArrayList();
}
/*
* Determine if the simple status should be changed or not
*/
if (this.simple) {
if (this.attributes.size() > 0) {
this.simple = false;
}
}
this.attributes.add(attributeIn);
}
/**
* Adds a copy of the given Collection
of {@link com.att.research.xacml.api.Attribute}s to this
* StdMutablePIPResponse
.
*
* @param attributesIn the Collection
of Attribute
s to add to this StdMutablePIPResponse
.
*/
public void addAttributes(Collection attributesIn) {
if (attributesIn != null && attributesIn.size() > 0) {
if (this.attributes == EMPTY_LIST) {
this.attributes = new ArrayList();
}
if (this.simple) {
if (this.attributes.size() > 0 || attributesIn.size() > 1) {
this.simple = false;
}
}
this.attributes.addAll(attributesIn);
}
}
/**
* Sets the {@link com.att.research.xacml.api.Attribute}s in this StdMutablePIPResponse
to a copy of the
* given Collection
.
*
* @param attributesIn the Collection
of Attribute
s to set in this StdMutablePIPResponse
.
*/
public void setAttributes(Collection attributesIn) {
this.attributes = EMPTY_LIST;
this.simple = true;
this.addAttributes(attributesIn);
}
}