package com.nailabs.abac.trust;
import java.util.*;
import java.io.*;
import com.nailabs.abac.test.XMLizable;
/**
* A class to represent the processing state of a TTGNode instance. A node is
* considered fully processed when the state is both verifier and opponent
* processed. This class is serializable for use in node operations.
*/
public class ProcessingState extends Observable
implements Serializable, XMLizable {
/** internal state variable, set if the verifier has processed a node */
private boolean verifierProcessed = false;
/** internal state variable, set if the opponent has processed a node */
private boolean opponentProcessed = false;
/**
* Default constructor for a state where NO processing has
* occured.
*/
public ProcessingState() { }
/** Explicit constructor method for setting state */
public ProcessingState(boolean v, boolean o) {
verifierProcessed = v;
opponentProcessed = o;
}
/** Jared: Added this method to make XML processing easier */
public void setVerifierProcessed() {
verifierProcessed = true;
}
/** Jared: Added this method to make XML processing easier */
public void setOpponentProcessed() {
opponentProcessed = true;
}
/** Jared: Added this method to make XML processing easier */
public void setFullyProcessed() {
setVerifierProcessed();
setOpponentProcessed();
}
/** Jared: Added this method to make XML processing easier */
public void setUnprocessed() {
verifierProcessed = false;
opponentProcessed = false;
}
/** Jared: Added this method to make XML processing easier */
public void setProcessingState(String state) {
if(state.equals("Fully Processed")) setFullyProcessed();
else if(state.equals("Verifier Processed")) setVerifierProcessed();
else if(state.equals("Opponent Processed")) setOpponentProcessed();
else if(state.equals("Unprocessed")) setUnprocessed();
}
/** method used to indicate that this node has been verifier processed */
public void verifierProcess() {
verifierProcessed = true;
setChanged();
notifyObservers();
}
/** method used to indicate that this node has been opponent processed */
public void opponentProcess() {
opponentProcessed = true;
setChanged();
notifyObservers();
}
/** boolean query to find out if the node has been verifier processed */
public boolean isVerifierProcessed() { return verifierProcessed; }
/** boolean query to find out if the node has been opponent processed */
public boolean isOpponentProcessed() { return opponentProcessed; }
/**
* boolean query to find out if the node was processed by opponent and
* and verifier.
*/
public boolean isFullyProcessed() {
return (verifierProcessed && opponentProcessed);
}
/** Update the processing state by duplicating the the specified state */
public void update(ProcessingState state) {
//if(state == null)return;
verifierProcessed |= state.isVerifierProcessed();
opponentProcessed |= state.isOpponentProcessed();
setChanged();
notifyObservers();
}
/** convert this instance into XML formatted text */
public String toXML() {
StringBuffer buff = new StringBuffer("");
String value;
if(isFullyProcessed()) {
value = "Fully Processed";
}
else if(isVerifierProcessed()) {
value = "Verifier Processed";
}
else if(isOpponentProcessed()) {
value = "Opponent Processed";
}
else {
value = "Unprocessed";
}
buff.append(value).append("");
return buff.append("\n").toString();
}
/** Convert this instance into human readable format */
public String toString() {
if(isFullyProcessed()) {
//return "[Fully Processed]";
return "fully";
}
else if(isVerifierProcessed()) {
//return "[Verifier Processed]";
return "verifier";
}
else if(isOpponentProcessed()) {
//return "[OpponentProcessed]";
return "opponent";
}
else {
//return "[Unprocessed]";
return "unprocessed";
}
}
}