package com.nailabs.abac.trust; import java.util.*; import com.nailabs.abac.test.*; import com.nailabs.abac.process.*; import edu.stanford.peer.rbtm.credential.*; public class IntersectionTTNode extends TargetNode { TTGNodeSet intersectionChildren = new TTGNodeSet(); int k = 0, satisfactionCount = 0; public IntersectionTTNode(TrustTarget target) { super(target); k = ((Intersection)target.getTargetRole()).getPartsCount(); subName = "Intersection"; } public void addIntersectionChild(TargetNode child) { intersectionChildren.add(child); } protected TTGNodeSet send(TrustTarget source, SatisfactionState state) { TTGNodeSet results = new TTGNodeSet(); setState(state); Iterator i = implicationParents.values().iterator(); while(i.hasNext()) { try { // this will fail if the parent is a linking goal SatisfactionListener listener = (SatisfactionListener)i.next(); TTGNodeSet branchResult = listener.receive((TrustTarget)getGoal(), state); if(branchResult == null && branchResult.size() > 0) { results.addAll(branchResult); } } catch(Exception ex) { // to print out exception uncomment ex.printStackTrace(); } } i = controlParents.values().iterator(); Strategy strategy = context.getStrategy(); while(i.hasNext()) { // add each control parent to the work list strategy.addToWorklist((TTGNode)i.next()); } return results; } public TTGNodeSet receive(TrustTarget source, SatisfactionState state) { debug("satisfaction", getGoal() + " received " + state + " from " + source + " with count = " + satisfactionCount); switch(state.getState()) { case SatisfactionState.SATISFIED: satisfactionCount += 1; if(satisfactionCount < k) { debug("statisfaction", "Intersection received partial satisfaction = " + satisfactionCount + "/" + k); break; } case SatisfactionState.FAILED: debug("satisfaction", "Intersection is propagating received " + state + " with " + satisfactionCount + "/" + k); return send(source, state); default: debug("satisfaction", "Intersection default received " + state + " with " + satisfactionCount + "/" + k); } return new TTGNodeSet(); } private void intersectionProcess(NegotiationContext context) { debug("satisfaction", "target expression = " + getTargetExpression()); Intersection i = (Intersection)getTargetExpression(); EntityExpression subject = getSubject(); Entity verifier = getVerifier(); Iterator parts = i.getParts(); //k = i.getPartsCount(); while(parts.hasNext()) { EntityExpression aDotR = (EntityExpression)parts.next(); try { TrustTarget child = new TrustTarget(verifier, aDotR, subject); context.getGraph().addIntersectionEdge((TrustTarget)getGoal(), child); } catch(Exception ex) { ex.printStackTrace(); } } } public void opponentProcess(NegotiationContext context) { if(processor.isOpponentProcessed()) { return; } intersectionProcess(context); processor.opponentProcess(); } public void verifierProcess(NegotiationContext context) { if(processor.isVerifierProcessed()) { return; } intersectionProcess(context); processor.verifierProcess(); } }