package edu.stanford.peer.rbtm.engine; import java.util.*; import edu.stanford.peer.rbtm.credential.*; import edu.stanford.peer.rbtm.util.*; public class LinkedRoleProofNode extends AbstractProofNode { private BackwardLinkingMonitor monitor; protected LinkedRoleProofNode(ProofGraph graph, LinkedRole re, int trackType) { super(graph, re, trackType); } public HashSet getChain(int size, EntityExpression target) { if(target.equals(getRoleExp())) { return new HashSet(size); } System.out.println("\n+++++ this = " + getRoleExp()); ResultEvidenceMap solutions = getBackwardSolutions(); 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); Role aDotR1 = ((LinkedRole)getRoleExp()).getFirstRole(); System.out.println("\n+++++ A.r1 = " + aDotR1); Entity b = ((Role)nextNode.getRoleExp()).getBase(); System.out.println("\n+++++ B = " + b); HashSet results = getGraph().getChain((EntityExpression)aDotR1, (EntityExpression)b); System.out.println("\n+++++ results = " + results); Iterator evidence = results.iterator(); while(evidence.hasNext()) { set.add((Credential)evidence.next()); } return set; } public void additionalBackwardProcess() { if (monitor != null) { return; } Role firstRole = (Role) ((LinkedRole)getRoleExp()).getFirstRole(); ProofNode node = getGraph().addBackwardNode(firstRole); monitor = new BackwardLinkingMonitor(); node.addBackwardListener(monitor); //if(addRole)backwardSolutionAdded(this, getRoleExp()); } class BackwardLinkingMonitor implements BackwardSolutionListener { public void backwardSolutionAdded(ProofNode s, BackwardSolution re) { if (re instanceof Entity) { Role r = new Role((Entity)re, ((LinkedRole)getRoleExp()).getSecondRoleName()); ProofNode node = getGraph().addBackwardNode(r); node.addChild(LinkedRoleProofNode.this, s); } } public String toString() { return "Monitor " + getRoleExp(); } } public void additionalForwardProcess() { } } // End of class LinkedRoleProofNode