Index: fedd/abac-src/rtml/src/edu/stanford/rt/credential/ApplicationDomain.java
===================================================================
--- fedd/abac-src/rtml/src/edu/stanford/rt/credential/ApplicationDomain.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
+++ fedd/abac-src/rtml/src/edu/stanford/rt/credential/ApplicationDomain.java	(revision 8780cbecc6db2bdc2b9ef31eec6e5209ad3bff15)
@@ -0,0 +1,216 @@
+package edu.stanford.rt.credential;
+
+import java.util.Iterator;
+
+import edu.stanford.rt.datatype.*;
+import edu.stanford.rt.util.*;
+/**
+ * @author Ninghui Li, Sandra Qiu<br>
+ * 
+ * Implementation of <code>ApplicationDomain</code> element.
+ *
+ */
+public class ApplicationDomain extends DomainSpecification
+{
+	/**
+	 * Attribute uri (required).
+	 */
+	private String uri;
+
+	/**
+	 * A flag indicates whether this domain is the built-in system one.
+	 */
+	private boolean isSystemDomain = false;
+
+	/**
+	 * Constructor for ApplicationDomain.
+	 * @param uri
+	 * @param isSystemDomain
+	 * @param context
+	 * @throws DomainSpecException
+	 */
+	public ApplicationDomain(
+		String uri,
+		boolean isSystemDomain,
+		RTContext context)
+		throws DomainSpecException
+	{
+		super(context);
+		this.uri = uri;
+		this.isSystemDomain = isSystemDomain;
+	}
+	/**
+	 * Method getUri.
+	 * @return String
+	 */
+	public String getUri()
+	{
+		return uri;
+	}
+
+	/**
+	 * Method lookupType.
+	 *  Look up the DataType declaration by given typeName 
+     *  in the current domain. If cannot find one and this domain is 
+     *  not system domain, then look up in the system domain.
+	 * @param typeName
+	 * @return DataType
+	 * @throws DomainSpecException
+	 *      if cannot find a DataType declaration by the given name.
+	 */
+	public DataType lookupType(String typeName)
+		throws DomainSpecException
+	{
+		//RTUtil.debugInfo(" lookupType()>>>> isSystemDomain = " + isSystemDomain);
+		DataType type = super.lookupType(typeName);
+
+		if (!isSystemDomain && type == null)
+		{
+			type =
+				getContext().getSystemDomain().lookupType(typeName);
+		}
+		if (type == null)
+		{
+			throw new DomainSpecException(
+				"Type '" + typeName + "' not found.");
+		}
+		return type;
+	}
+
+	/**
+	 * Method lookupRoleDeclaration.
+	 *      Look up the role declaration by given roleName in the 
+     *  current domain. If cannot find one and this domain is not system
+     *  domain, then look it up in system domain.
+	 * @param roleName
+	 * @return RoleDeclaration
+	 * @throws DomainSpecException
+	 *      if cannot find one.
+	 */
+	public RoleDeclaration lookupRoleDeclaration(String roleName)
+		throws DomainSpecException
+	{
+		RTUtil.debugInfo(
+			"DomainSpecification(id="
+				+ ((getHashID() == null)
+					? "null"
+					: getHashID().toString())
+				+ ") looking up role '"
+				+ roleName
+				+ "'");
+
+		RoleDeclaration role = super.lookupRoleDeclaration(roleName);
+		if (!isSystemDomain && role == null)
+		{
+			role =
+				getContext().getSystemDomain().lookupRoleDeclaration(
+					roleName);
+		}
+		if (role == null)
+		{
+			throw new DomainSpecException(
+				"Role '" + roleName + "' has not been declared.");
+		}
+		return role;
+	}
+
+	public String toString(String indent)
+	{
+		String thisIndent = indent + "  ";
+		StringBuffer sb = new StringBuffer();
+
+		sb.append(thisIndent).append(
+			"ApplicationDomain:  hashID = "
+				+ getHashID().toString()
+				+ "\n");
+		sb.append(thisIndent + "  ").append("uri = ").append(
+			uri).append(
+			"\n");
+		sb
+			.append(thisIndent + "  ")
+			.append("PrincipalType = ")
+			.append(getPrincipalType())
+			.append("\n");
+
+		sb.append(thisIndent + "  ").append("Imported Domains: \n");
+		try
+		{
+			Iterator it = getImportedDomains().keyIterator();
+			while (it.hasNext())
+			{
+				String key = (String) it.next();
+				ApplicationDomain value =
+					(ApplicationDomain) getImportedDomains().get(key);
+				sb.append(thisIndent + "    ").append(key).append(
+					"\n");
+				sb.append(thisIndent + "    ").append(
+					value.getUri()).append(
+					"\n");
+
+			}
+		}
+		catch (DomainSpecException e)
+		{
+			e.printStackTrace();
+		}
+
+		sb.append(thisIndent + "  ").append("Type Declarations: \n");
+		try
+		{
+			Iterator it = getTypeDeclarations().keyIterator();
+			while (it.hasNext())
+			{
+				String key = (String) it.next();
+				DataType value =
+					(DataType) getTypeDeclarations().get(key);
+
+				sb
+					.append(thisIndent + "    ")
+					.append(key)
+                    .append("\n")
+					.append(value.toString(thisIndent + "    "))
+					.append("\n");
+			}
+		}
+		catch (DomainSpecException e)
+		{
+			e.printStackTrace();
+		}
+
+		sb.append(thisIndent + "  ").append("Role Declarations: \n");
+		try
+		{
+			Iterator it = getRoleDeclarations().keyIterator();
+			while (it.hasNext())
+			{
+				String key = (String) it.next();
+				RoleDeclaration value =
+					(RoleDeclaration) getRoleDeclarations().get(key);
+				sb.append(thisIndent + "    ").append(key).append(
+					"\n");
+				sb.append(
+					value.toString(thisIndent + "    ")).append(
+					"\n");
+			}
+		}
+		catch (DomainSpecException e)
+		{
+			e.printStackTrace();
+		}
+		return sb.toString();
+	} // end of toString()
+
+	/* (non-Javadoc)
+	 * @see edu.stanford.rt.credential.DomainSpecification#setHashID(HashID)
+	 */
+	public synchronized void setHashID(HashID hashID)
+		throws DomainSpecException
+	{
+		if (isComplete())
+			throw new DomainSpecException("ApplicationDomain unmodifiable.");
+		if (hashID.getHashType() != HashID.APPLICATION_DOMAIN)
+			throw new DomainSpecException("Wrong type of hash id");
+		super.setHashID(hashID);
+	}
+
+}
