[8780cbec] | 1 | public class ProofNode |
---|
| 2 | { |
---|
| 3 | EntityExpression roleExp; // What EntityExpression this node is about |
---|
| 4 | SolutionManager forwardMgr = new SolutionManager(); |
---|
| 5 | SolutionManager backwardMgr = new SolutionManager(); |
---|
| 6 | |
---|
| 7 | ProofNode (EntityExpression re) { |
---|
| 8 | debugInfo("A new node is created for " + re); |
---|
| 9 | roleExp = re; |
---|
| 10 | forwardMgr.solutionAdded(this, roleExp); |
---|
| 11 | backwardMgr.solutionAdded(this, roleExp); |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | // The method that does the work when we visit a node |
---|
| 15 | void forwardProcess() { |
---|
| 16 | // first go over all credentials that have this as subject |
---|
| 17 | Iterator credIt = findCredentialsBySubject(roleExp); |
---|
| 18 | while (credIt.hasNext()) { |
---|
| 19 | StaticCredential credential = (StaticCredential) credIt.next(); |
---|
| 20 | ProofNode node = addForwardNode(credential.getDefinedRole()); |
---|
| 21 | addProofEdge(this, node, credential); |
---|
| 22 | } |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | void backwardProcess() { |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * Class SolutionManager implements listener management and solution |
---|
| 30 | * management. |
---|
| 31 | */ |
---|
| 32 | class SolutionManager implements SolutionListener |
---|
| 33 | { |
---|
| 34 | private HashMap solutions = new HashMap(); |
---|
| 35 | private LinkedList listeners = new LinkedList(); |
---|
| 36 | |
---|
| 37 | public void solutionAdded(ProofNode s, ProofSolution r) { |
---|
| 38 | debugInfo("Solution added: " + roleExp + "; " + s.roleExp + "; " + r); |
---|
| 39 | if (! solutions.containsKey(r)) { // when solution r is new |
---|
| 40 | solutions.put(r, new SmallSet(s)); // add solution together with source |
---|
| 41 | Object[] lisArray = listeners.toArray(); // inform all listeners |
---|
| 42 | for (int i=0; i<lisArray.length; i++) { |
---|
| 43 | ((SolutionListener)lisArray[i]).solutionAdded(ProofNode.this, r); |
---|
| 44 | } |
---|
| 45 | } else if (trackAll) { |
---|
| 46 | ((SmallSet)solutions.get(r)).add(s); |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | void addListener(SolutionListener sl) { |
---|
| 51 | listeners.add(sl); |
---|
| 52 | // inform the listener of existing solutions |
---|
| 53 | Object[] sols = solutions.keySet().toArray(); |
---|
| 54 | for (int i=0; i<sols.length; i++) { |
---|
| 55 | sl.solutionAdded(ProofNode.this, (EntityExpression)(sols[i])); |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | Set getSolutions() { return solutions.keySet(); } |
---|
| 60 | } // End of class SolutionManager |
---|
| 61 | } // End of class ProofNode |
---|