Index: fedd/abac-src/ttg/test/RtmlTest.java
===================================================================
--- fedd/abac-src/ttg/test/RtmlTest.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/ttg/test/RtmlTest.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,270 @@
+package com.nailabs.abac.test;
+
+import java.io.*;
+import java.util.*;
+import com.nailabs.abac.process.*;
+
+import com.nailabs.abac.credential.RtmlEntity;
+import com.nailabs.abac.credential.RtmlExpression;
+import com.nailabs.abac.trust.TrustTarget;
+
+import edu.stanford.rt.credential.CredentialStore;
+import edu.stanford.rt.credential.RTContext;
+import edu.stanford.rt.parser.RTParser;
+import edu.stanford.peer.rbtm.credential.Entity;
+import edu.stanford.peer.rbtm.credential.EntityExpression;
+import edu.stanford.peer.rbtm.credential.Role;
+import edu.stanford.peer.rbtm.credential.RoleName;
+import edu.stanford.peer.rbtm.credential.SimpleRoleName;
+import edu.stanford.peer.rbtm.credential.StaticCredential;
+
+import org.xml.sax.SAXParseException;
+
+public class RtmlTest extends TestEngine {
+
+    public static void parsePrepInfo(HashMap conf) {
+        String section = "PrepInfo";
+        HashSet propSet = (HashSet)conf.get(section);
+	Properties props = new Properties();
+        try {
+            Iterator i = propSet.iterator();
+            while(i.hasNext()) {
+		StringTokenizer st = 
+		    new StringTokenizer((String)i.next(), "=");
+		Entity key = 
+		    (Entity)RtmlExpression.getEntityExpression(st.nextToken());
+                props.setProperty(key.toString(), st.nextToken());
+            }
+	    props.list(System.out);
+            conf.put(section, props);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+    }
+
+    public static void parseEntityId(HashMap map) {
+        String section = "EntityID";        
+	RtmlEntity eid = null;
+        HashSet propSet = (HashSet)map.get(section);
+        Properties props = new Properties();
+        try {
+            Iterator i = propSet.iterator();
+            while(i.hasNext()) {
+                props.load(new StringBufferInputStream((String)i.next()));
+            }
+	    eid = new RtmlEntity(props.getProperty("ShortName"), 
+				 props.getProperty("HashCode"));
+            //props.list(System.out);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+	map.put(section, eid);
+    }
+
+    public static void parseResourcePolicy(HashMap conf) {
+	ResourcePolicy policy = new ResourcePolicy();
+	String section = "ResourcePolicy";
+	HashSet policySet = (HashSet)conf.get(section);
+	if(policySet == null)policySet = new HashSet();
+	Iterator i = policySet.iterator();
+
+	while(i.hasNext()) {
+	    try {
+		StringTokenizer st = 
+		    new StringTokenizer((String)i.next(), "=");
+		String key = st.nextToken();
+		Role value = //(Role)StaticCredential.getRole(st.nextToken());
+		    (Role)RtmlExpression.getEntityExpression(st.nextToken());
+		policy.addResourceFact(key, value);
+	    }
+	    catch(Exception ex) {
+		ex.printStackTrace();
+	    }
+	}
+	conf.put(section, policy);
+	System.out.println("ResourcePolicy = " + policy);
+    }
+
+
+    public static void parseAckPolicy(HashMap conf) {
+	AckPolicy policy = new AckPolicy();
+	String section = "AckPolicy";
+	HashSet policySet = (HashSet)conf.get(section);
+	if(policySet == null)policySet = new HashSet();
+	Iterator i = policySet.iterator();
+
+	while(i.hasNext()) {
+	    try {
+		StringTokenizer st = 
+		    new StringTokenizer((String)i.next(), "=");
+		EntityExpression key = 
+            RtmlExpression.getEntityExpression(st.nextToken());
+		EntityExpression value = 
+            RtmlExpression.getEntityExpression(st.nextToken());
+		policy.addAckFact(key, value);
+	    }
+	    catch(Exception ex) {
+            ex.printStackTrace();
+	    }
+	}
+	conf.put(section, policy);
+	System.out.println("AckPolicy = " + policy);
+    }
+
+    public static void parseRtmlProperties(HashMap map) {
+        String section = "RTML";        
+        HashSet propSet = (HashSet)map.get(section);
+        Properties props = new Properties();
+        try {
+            Iterator i = propSet.iterator();
+            while(i.hasNext()) {
+                props.load(new StringBufferInputStream((String)i.next()));
+            }
+            //props.list(System.out);
+	    // CUSTOMIZED FOR TOMCAT
+	    if(props.containsKey("SystemDomain")) {
+		System.setProperty("edu.stanford.rt.SystemDomain", 
+				   props.getProperty("SystemDomain"));
+	    }
+            map.put(section, props);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+    }
+
+    public static void parseCredentialStore(HashMap map) {
+        String section = "CredentialStore";
+        String fileName = ((Properties)map.get("RTML")).getProperty(section);
+        RTParser parser = null;
+	RTContext context = null;
+        CredentialStore store = null;
+        try {
+            parser = new RTParser();
+	    context = new RTContext(parser);
+            store = new CredentialStore(parser);
+            FileInputStream in = new FileInputStream(new File(fileName));
+            parser.parseCredentialStore(in, context, store);
+        } 
+	catch (SAXParseException spex) { 
+	    System.out.print("SAX Parser error in element " + spex.getPublicId());
+	    System.out.print(": line = " + spex.getLineNumber());
+	    System.out.println(", col = " + spex.getColumnNumber());
+	}
+	catch (Exception ex) {
+	    System.out.println(ex.getMessage());
+            ex.printStackTrace();
+        }
+	map.put("Parser", parser);
+	map.put("RTContext", context);
+        map.put(section, store);
+    }
+
+    public static void parseDiscoveryStore(HashMap map) {
+        String section = "DDEStore";
+        String fileName = ((Properties)map.get("RTML")).getProperty(section);
+        RTParser parser = null;
+	RTContext context = null;
+        CredentialStore store = null;
+        try {
+            parser = new RTParser();
+	    context = new RTContext(parser);
+            store = new CredentialStore(parser);
+            FileInputStream in = new FileInputStream(new File(fileName));
+            parser.parseCredentialStore(in, context, store);
+        } 
+	catch (SAXParseException spex) { 
+	    System.out.print("SAX Parser error in element " + spex.getPublicId());
+	    System.out.print(": line = " + spex.getLineNumber());
+	    System.out.println(", col = " + spex.getColumnNumber());
+	}
+	catch (Exception ex) {
+	    System.out.println(ex.getMessage());
+            ex.printStackTrace();
+        }
+	map.put("DDEParser", parser);
+	map.put("DDEContext", context);
+        map.put(section, store);
+    }
+
+    public static HashMap loadConfiguration(String name) {
+        HashMap map = 
+            edu.stanford.peer.rbtm.test.TestEngine.loadConfiguration(name);
+        System.out.println("Loaded configuration from " + name);
+        System.out.println("map = " + map ); 
+        parseEntityId(map);
+	parseAckPolicy(map);
+	parseACPolicy(map);
+	parseResourcePolicy(map);
+	// CUSTOMIZED FOR RTML
+	parseRtmlProperties(map); 
+        parseCredentialStore(map); 
+        parsePolicyReachable(map);
+        parseSelfReachable(map);
+        parseStrategyHints(map);
+	// CUSTOMIZED FOR DISCOVERY
+	parsePrepInfo(map);
+	parseDiscoveryStore(map);
+        return map;
+    }
+
+    public static void main(String arg[]) {
+	HashMap oConf = loadConfiguration((arg.length>0)?arg[0]:"alice.txt");
+	HashMap vConf = loadConfiguration((arg.length>1)?arg[1]:"medsup.txt");
+	String resourceID = (arg.length > 2)? arg[2]: "default";
+	ResourcePolicy resourcePolicy = 
+	    (ResourcePolicy)vConf.get("ResourcePolicy");
+	TrustTarget primaryTT = null;
+	
+	// Create frontiers
+	FrontierManager.addFrontier(vConf);
+	FrontierManager.addFrontier(oConf);
+	// Create entities for the negotiators
+	Entity o = (Entity)oConf.get("EntityID");
+	Entity v = (Entity)vConf.get("EntityID");
+
+	System.out.println("vConf = " + vConf.toString());	
+	System.out.println("oConf = " + oConf.toString());
+
+	// Initialize the contexts for each side
+	NegotiationContext oContext = new NegotiationContext(oConf);
+	NegotiationContext vContext = new NegotiationContext(vConf);
+	
+	PropertiesObserver oObs = 
+	    new PropertiesObserver(oContext.getSelf());
+	PropertiesObserver vObs = 
+	    new PropertiesObserver(vContext.getSelf());
+	RMINegotiator oAgent = null, vAgent = null;
+
+	try {
+        oAgent = new RMINegotiator(oContext);
+        vAgent = new RMINegotiator(vContext);
+	//v = new RtmlEntity("SAdmir", "FakeHashKeySAdmir");
+	//o = new RtmlEntity("USSH", "FakeHashKeyUSSH");
+	System.out.println("opponent = " + o + "," + o.hashCode());
+	System.out.println("verifier = " + v + "," + v.hashCode());
+
+	Role targetRole = resourcePolicy.requires(resourceID);
+	System.out.println("target role = " + targetRole + 
+			   "," + targetRole.hashCode());
+	primaryTT = new TrustTarget(v, targetRole, o);
+
+	    oContext.getGraph().addObserver(oObs);
+        oContext.getStrategy().addObserver(oObs);
+	    vContext.getGraph().addObserver(vObs);
+        vContext.getStrategy().addObserver(vObs);
+	}
+	catch(Exception ex) {
+	    ex.printStackTrace(System.err);
+	}
+	vAgent.setPeer(oAgent);
+	System.out.println("Primary trust target = " + primaryTT);
+	vAgent.setRoot(primaryTT);
+	boolean success = vAgent.negotiate();
+	System.out.println("The negotiation has " + ((success)? "succeeded":
+			   "failed"));
+	oObs.close();
+	vObs.close();
+	System.exit(0);
+    }
+}
+
