package com.nailabs.abac.trust; import java.util.*; import com.nailabs.abac.test.XMLizable; /** * An instance used to represent the satisfaction state of a target node * and its descendants. */ public class SatisfactionState extends Observable implements XMLizable { /** The satisfaction state variable */ private int state; /** * The satisfaction state can be proved to be satisfied or unsatisfied. * For example, an access mediator may want to later reassess a subgraph. */ public static final int UNKNOWN = 0; /** * Satisfaction mean that a trust target node has been proven correct, * possibly including a set of credential to verify the satisfaction. */ public static final int SATISFIED = 1; /** * Unsatisified mean that the requirement of a trust target cannot be * met. This generally means that an access mediator should not allow * resource access. */ public static final int FAILED = 2; /** Default constructor where the state is UNKNOWN */ public SatisfactionState() { state = UNKNOWN; } /** Explicitly defined statisfaction state. */ public SatisfactionState(int i) { state = i; } /** Accessor method for returninf the trust target satisfaction state. */ public int getState() { return state; } /** Modifier method to change the satisfaction state */ public void setState(int i) { if(i > -1 && i < 3)state = i; setChanged(); notifyObservers(); } /** convert this instance into an XML formatted string */ public String toXML() { StringBuffer buff = new StringBuffer(""); switch(state) { case SATISFIED: buff.append("satisfied"); break; case FAILED: buff.append("failed"); break; default: buff.append("unknown"); } buff.append(""); return buff.append("\n").toString(); } /** Print a human readable version of this instance */ public String toString() { StringBuffer buff = new StringBuffer("["); switch(state) { case SATISFIED: buff.append("satisfied"); break; case FAILED: buff.append("failed"); break; default: buff.append("unknown"); } return buff.append("]").toString(); } }