package com.nailabs.abac.process; import com.nailabs.abac.trust.*; import com.nailabs.abac.test.*; /** * This is a specialized operation for transmitting a root node between * negotiators. */ public class NodeOperation implements Operation { /** The new node to construct */ Goal goal; /** An optional processing state */ ProcessingState state; /** a flag to denote whether this is a new (i.e. root) node or not */ boolean isRoot = false; /** root node operation constructor */ public NodeOperation(Goal g, ProcessingState ps, boolean isRoot) { goal = g; state = ps; this.isRoot = isRoot; } /** non-root, node state change operation */ public NodeOperation(Goal g, ProcessingState ps) { goal = g; state = ps; isRoot = false; } /** Jared: Added this method to make XML processing easier */ public NodeOperation() { goal = null; state = null; } /** Jared: Added this method to make XML processing easier */ public void setGoal(Goal g) { goal = g; } /** Jared: Added this method to make XML processing easier */ public void setProcessingState(ProcessingState ps) { state = ps; } /** Jared: Added this method to make XML processing easier */ public void setRoot(boolean isRoot) { this.isRoot = isRoot; } /** public accessor method used for logging this node's goal */ public Goal getGoal() { return goal; } /** public accessor method for determinig whether this is a root node */ public boolean isRoot() { return isRoot; } /** public accessor method for finding the updated processing state */ public ProcessingState getProcessingState() { return state; } /** * Either add a new node to the root of the trust target graph or * update the processing state of an existing node. */ public void perform(TTG graph) { StringBuffer buff; if(isRoot) { buff = new StringBuffer("adding root node "); buff.append(goal).append(" to ").append(graph); debug("root", buff.toString()); graph.putRoot((TargetNode)graph.getNode((TrustTarget)goal)); } buff = new StringBuffer("updating node "); buff.append(goal).append(" with ").append(state); debug("node", buff.toString()); TTGNode node = graph.getNodeByHash(goal); //node.getProcessingState().update(state); node.updateProcessingState(state); } /** Friendly debugging convenience method */ protected void debug(String level, String message) { StringBuffer buff = new StringBuffer("NodeOperation:"); buff.append(message); Debug.debug(level, buff.toString()); } public String toXML() { StringBuffer buff = new StringBuffer("\n"); } else { buff.append(">\n"); } buff.append(""); buff.append(goal.toXML()); buff.append("\n"); buff.append(state.toXML()); buff.append("\n"); return buff.toString(); } /** Converts this operation into a string */ public String toString() { StringBuffer buff = new StringBuffer("[NodeOperation "); if(isRoot){ buff.append("root = ").append(goal); if(state != null) { buff.append(", processing state = ").append(state); } } else { buff.append("node = ").append(goal); buff.append(", processing state = ").append(state); } buff.append("]"); return buff.toString(); } }