package com.nailabs.abac.trust; import com.nailabs.abac.process.*; import edu.stanford.peer.rbtm.credential.*; import java.util.*; /** * An instance of this class represents a linking goal of the form:
*
<V: ?X.r2 <-- S >

* where V is on the negotiators; * r2 is a simple role name; and * ?X represents entities * S is a role expression called the subject role. S is frequently the * opponent negotiator of V. */ public class LinkingGoal extends Goal { /** The role name suffix (in ?X.r2 this is r2) */ private RoleName targetRoleName; private Entity x = new SimpleEntity("X"); /** Itemized default constructor */ public LinkingGoal(Entity v, RoleName e, EntityExpression s) throws TrustTargetParsingException, CredentialParsingException { verifier = v; targetRoleName = e; subject = s; } /** Construct a new trust target from a string */ public LinkingGoal(String s) throws TrustTargetParsingException, CredentialParsingException { StringTokenizer st = new StringTokenizer(s, ":<-? "); try { verifier = new SimpleEntity(st.nextToken()); StringTokenizer rt = new StringTokenizer(st.nextToken(), "."); x = new SimpleEntity(rt.nextToken()); targetRoleName = new SimpleRoleName(rt.nextToken()); subject = new SimpleEntity(st.nextToken()); } catch (NoSuchElementException nonesuch) { throw new TrustTargetParsingException("Bad linking goal: ", s); } } /** Unique hash function based on a verifier-target-subject triplet */ public int hashCode() { return verifier.hashCode() * 4 + targetRoleName.hashCode() * 2 + subject.hashCode(); } /** processing state for a node repsenting this goal is added to a TTG */ public ProcessingState getInitialProcessingState(NegotiationContext ctx) { // a linking goal is initially verifier-processed */ return new ProcessingState(true, false); } /** accessor method for the target role expressin of this target */ public RoleName getTargetRoleName() { return targetRoleName; } /** type name for pretty printing an instance */ public String getType() { return new String("LinkingGoal"); } public String toString() { StringBuffer buff = new StringBuffer(); buff.append(getVerifier().toString()).append(": "); buff.append("?").append(x).append(".").append(targetRoleName); buff.append(" <<-?- ").append(getSubject().toString()); return buff.toString(); } public String toXML() { /* StringBuffer buff = new StringBuffer("\n"); buff.append("\t"); buff.append(getVerifier().toString()); buff.append("\n"); buff.append("\t"); buff.append(targetRoleName.toString()); buff.append("\n"); buff.append("\t"); buff.append(getSubject().toString()); buff.append("\n"); buff.append("\n"); return buff.toString(); */ return toString().replaceAll("<", "<"); } }