package com.nailabs.abac.process; import edu.stanford.peer.rbtm.credential.*; import com.nailabs.abac.trust.*; import java.util.*; public abstract class EdgeOperation implements Operation { /** the parent node of the edge (beginning point) */ private Goal parent; /** the child node of the edge (end point) */ private Goal child; private transient HashSet evidence; protected String type; protected ProcessingState state; public EdgeOperation(Goal p, Goal c, ProcessingState s, HashSet list) { parent = p; child = c; evidence = list; state = s; } /** Constructor method to make XML processing easier */ public EdgeOperation() { parent = null; child = null; evidence = null; state = null; } /** * Modifier method for the setting the parent node of an edge. * Added this method to make XML processing easier */ public void setParent(Goal p) { parent = p; } /** * Modifier method for setting the child node of an edge. * Added this method to make XML processing easier */ public void setChild(Goal c) { child = c; } /** * Modifier method for setting the processing state of the child node. * Added this method to make XML processing easier */ public void setProcessingState(ProcessingState s) { state = s; } public final boolean hasNewChild() { return (state != null); } public final void perform(TTG graph) { if(hasNewChild()) performNewAdditional(graph); else performAdditional(graph); } public Goal getParent() { return parent; } public Goal getChild() { return child; } public String getType() { return type; } public ProcessingState getProcessingState() { return state; } public HashSet getEvidence() { return evidence; } public void setEvidence(HashSet set) { evidence = set; } public abstract void performAdditional(TTG graph); public abstract void performNewAdditional(TTG graph); protected String performNewInfo() { StringBuffer buff = new StringBuffer("adding new child for "); buff.append(getChild().toString()); return buff.toString(); } public String toXML() { return toXML(""); } protected String toXML(String args) { StringBuffer buff = new StringBuffer("\n"); if(getParent() != null) { buff.append("\n"); buff.append(getParent().toXML()); buff.append("\n"); } if(getChild() != null) { buff.append("\n"); buff.append(getChild().toXML()); buff.append("\n"); } if(state != null) buff.append(state.toXML()); //if(evidence != null) { if(false) { int count = 0; Iterator i = evidence.iterator(); StringBuffer creds = new StringBuffer(); for(count = 0;i.hasNext();count++) { try { StaticCredential cred = (StaticCredential)i.next(); //creds.append(""); //creds.append(cred.toXML()); //creds.append("\n"); } catch(Exception ex) { //ex.printStackTrace(); } if(count > 0) { //buff.append("\n"); //buff.append(creds.toString()); //buff.append("\n"); } } } buff.append("\n"); return buff.toString(); } /** convert this edge into a human-readable formatted String */ public String toString() { StringBuffer buff = new StringBuffer("["); buff.append(type).append("Edge"); buff.append(getParent()).append(" <<=== "); buff.append(getChild()).append(", state = "); buff.append(state).append("]"); return buff.toString(); } }