1 | package edu.stanford.peer.rbtm.engine; |
---|
2 | |
---|
3 | import java.util.*; |
---|
4 | |
---|
5 | import edu.stanford.peer.rbtm.credential.*; |
---|
6 | import edu.stanford.peer.rbtm.util.*; |
---|
7 | |
---|
8 | |
---|
9 | public class LinkedRoleProofNode extends AbstractProofNode |
---|
10 | { |
---|
11 | private BackwardLinkingMonitor monitor; |
---|
12 | |
---|
13 | protected LinkedRoleProofNode(ProofGraph graph, LinkedRole re, int trackType) { |
---|
14 | super(graph, re, trackType); |
---|
15 | } |
---|
16 | |
---|
17 | |
---|
18 | public HashSet getChain(int size, EntityExpression target) { |
---|
19 | if(target.equals(getRoleExp())) { |
---|
20 | return new HashSet(size); |
---|
21 | } |
---|
22 | System.out.println("\n+++++ this = " + getRoleExp()); |
---|
23 | ResultEvidenceMap solutions = getBackwardSolutions(); |
---|
24 | HashSet soln = (HashSet)solutions.getResultEvidence(target); |
---|
25 | System.out.println("solutions = " + solutions); |
---|
26 | System.out.println("soln = " + soln); |
---|
27 | //In the end, there can be only ONE . . . |
---|
28 | ProofNode nextNode =(ProofNode)soln.iterator().next(); |
---|
29 | System.out.println("\n+++++ next = " + nextNode.getRoleExp() ); |
---|
30 | size++; |
---|
31 | HashSet set = nextNode.getChain(size, target); |
---|
32 | Role aDotR1 = ((LinkedRole)getRoleExp()).getFirstRole(); |
---|
33 | System.out.println("\n+++++ A.r1 = " + aDotR1); |
---|
34 | Entity b = ((Role)nextNode.getRoleExp()).getBase(); |
---|
35 | System.out.println("\n+++++ B = " + b); |
---|
36 | HashSet results = |
---|
37 | getGraph().getChain((EntityExpression)aDotR1, (EntityExpression)b); |
---|
38 | System.out.println("\n+++++ results = " + results); |
---|
39 | Iterator evidence = results.iterator(); |
---|
40 | while(evidence.hasNext()) { |
---|
41 | set.add((Credential)evidence.next()); |
---|
42 | } |
---|
43 | return set; |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | public void additionalBackwardProcess() { |
---|
48 | if (monitor != null) { |
---|
49 | return; |
---|
50 | } |
---|
51 | Role firstRole = (Role) ((LinkedRole)getRoleExp()).getFirstRole(); |
---|
52 | ProofNode node = getGraph().addBackwardNode(firstRole); |
---|
53 | monitor = new BackwardLinkingMonitor(); |
---|
54 | node.addBackwardListener(monitor); |
---|
55 | //if(addRole)backwardSolutionAdded(this, getRoleExp()); |
---|
56 | } |
---|
57 | |
---|
58 | class BackwardLinkingMonitor implements BackwardSolutionListener { |
---|
59 | public void backwardSolutionAdded(ProofNode s, BackwardSolution re) { |
---|
60 | if (re instanceof Entity) { |
---|
61 | Role r = new Role((Entity)re, |
---|
62 | ((LinkedRole)getRoleExp()).getSecondRoleName()); |
---|
63 | ProofNode node = getGraph().addBackwardNode(r); |
---|
64 | node.addChild(LinkedRoleProofNode.this, s); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | public String toString() { |
---|
69 | return "Monitor " + getRoleExp(); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | public void additionalForwardProcess() { |
---|
74 | } |
---|
75 | } // End of class LinkedRoleProofNode |
---|