Index: fedd/abac-src/rbtm/engine/RoleProofNode.java
===================================================================
--- fedd/abac-src/rbtm/engine/RoleProofNode.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rbtm/engine/RoleProofNode.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,121 @@
+package edu.stanford.peer.rbtm.engine;
+
+import java.util.*;
+
+import edu.stanford.peer.rbtm.credential.*;
+import edu.stanford.peer.rbtm.util.*;
+
+/**
+ * A proof node which represents a role in the credential graph.
+ */
+public class RoleProofNode extends AbstractProofNode
+{
+	/**
+	 * A map for managing all the partial solutions per intersection that arrive
+	 */
+   static protected PartialSolutionMap partialSolutions = 
+		 new PartialSolutionMap();
+
+   /** A forwarlinking monitor which handles linking goals */
+	private ForwardLinkingMonitor monitor;
+
+    protected RoleProofNode(ProofGraph graph, Role re, int trackType) {
+    	super(graph, re, trackType);
+    }
+
+    public HashSet getChain(int size, EntityExpression target) {
+	if(target.equals(getRoleExp())) {
+	    System.out.println("\n@@@@@ creating set of size " + size);
+	    return new HashSet(size);
+	}
+	System.out.println("\n@@@@@ this = " + getRoleExp());	
+	ResultEvidenceMap solutions = getBackwardSolutions();
+	//ProofNode nextNode =(ProofNode)solutions.getResultEvidence(target);
+	HashSet soln = (HashSet)solutions.getResultEvidence(target);
+	System.out.println("solutions = " + solutions);
+	System.out.println("soln = " + soln);
+	//In the end, there can be only ONE . . . 
+	ProofNode nextNode =(ProofNode)soln.iterator().next();
+	System.out.println("\n@@@@@ next = " + nextNode.getRoleExp() );
+	size++;
+	HashSet set = nextNode.getChain(size, target);
+	System.out.println("\n@@@@@ children  = " + nextNode.getChildren());
+        HashSet results = 
+	    (HashSet)nextNode.getChildren().getResultEvidence(getRoleExp());
+	Iterator evidence = results.iterator();
+	while(evidence.hasNext()) {
+	    set.add((Credential)evidence.next());
+	}
+	return set;
+    }
+
+    public void additionalBackwardProcess() {
+        Iterator  credIt = getGraph().findCredentialsDefiningRole((Role)getRoleExp());
+        while (credIt.hasNext()) {
+            StaticCredential credential = (StaticCredential) credIt.next();
+            ProofNode node = getGraph().addBackwardNode(credential.getSubject());
+	    node.addChild(this, credential);
+	    //if(addRole)backwardSolutionAdded(this, getRoleExp());
+        }
+    }
+
+    public void additionalForwardProcess() {
+		Role thisRole = (Role)getRoleExp();
+		// Make itself a forward solution to itself
+		forwardSolutionAdded(this, thisRole);
+		
+		if (monitor == null) {
+	        ProofNode node = getGraph().addForwardNode(thisRole.getBase());
+			monitor = new ForwardLinkingMonitor();
+	        node.addForwardListener(monitor);
+		}
+    }
+	 /**
+	  * Adds a forward solution but propagating the solution backwards along
+	  * the credential chain. If s is a partial solution and all k pieces have
+	  * arrived, then add edge from this node to the intersection.
+	  */
+	 public void forwardSolutionAdded(ProofNode s, ForwardSolution r) {
+		  EntityExpression expr = s.getRoleExp();
+		  Iterator iCreds = getGraph().findCredentialsByPartialSubject(expr);
+		  
+		  super.forwardSolutionAdded(s, r);
+		  if(iCreds.hasNext()) {  // if s is partial solution of intersection(s)
+				StaticCredential credential = (StaticCredential) iCreds.next();
+				Intersection i = (Intersection)credential.getSubject();				
+				if(partialSolutions.addPartialSolution(i, expr)) {
+					 ProofNode node = getGraph().addForwardNode(i);
+					 node.addParent(node, r);
+				}
+		  } 
+	 }
+
+    class ForwardLinkingMonitor implements ForwardSolutionListener {
+        public void forwardSolutionAdded(ProofNode s,  ForwardSolution sol) {
+			if (sol instanceof Role) {
+				Role  role = (Role)sol;
+				if (role.getName() instanceof RPermission) {
+					return;
+				}
+				LinkedRole linkedRole = 
+					 new LinkedRole(role, ((Role)getRoleExp()).getName());
+				//if (getGraph().hasCredentialsForSubject(linkedRole)) {
+				ProofNode node = getGraph().addForwardNode(linkedRole);
+				node.addParent(RoleProofNode.this, s);
+				// addProofEdge(this, node, s);
+			}
+        }
+
+	    public String toString() {
+	    	return "Monitor " + getRoleExp();
+	    }
+    }
+	
+	
+} // End of class RoleProofNode
+
+
+
+
+
+
