All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.att.research.xacmlatt.pdp.policy.PolicyDefaults Maven / Gradle / Ivy

The newest version!
/*
 *
 *          Copyright (c) 2013,2019  AT&T Knowledge Ventures
 *                     SPDX-License-Identifier: MIT
 */
package com.att.research.xacmlatt.pdp.policy;

import java.net.URI;

import com.att.research.xacml.api.XACML;

/**
 * PolicyDefaults represents the default values associated with a XACML 3.0 Policy or PolicySet that may
 * be overridden or inherited by child Policies or PolicySets.
 * 
 * @author car
 * @version $Revision: 1.1 $
 */
public class PolicyDefaults {
	private static URI		xpathVersionDefault;
	
	static {
		try {
			xpathVersionDefault	= new URI(XACML.XPATHVERSION_2_0);
		} catch (Exception ex) {
			
		}
	}
	
	private URI				xpathVersion;
	private PolicyDefaults 	policyDefaultsParent;
	
	/**
	 * Creates a new PolicyDefaults with the given URI for the XPath version and
	 * the given PolicyDefaults pointing to the parent.
	 * 
	 * @param xpathVersionIn the URI representing the XPath version for the new PolicyDefaults
	 * @param policyDefaultsParentIn the PolicyDefaults object that is the parent of the new PolicyDefaults
	 */
	public PolicyDefaults(URI xpathVersionIn, PolicyDefaults policyDefaultsParentIn) {
		this.xpathVersion			= xpathVersionIn;
		this.policyDefaultsParent	= policyDefaultsParentIn;
	}
	
	/**
	 * Gets the parent PolicyDefaults for this PolicyDefaults.
	 * 
	 * @return the parent PolicyDefaults for this PolicyDefaults or null if none
	 */
	public PolicyDefaults getPolicyDefaultsParent() {
		return this.policyDefaultsParent;
	}
	
	/**
	 * Gets the XPath version URI for this PolicyDefaults.  If there is no explicit
	 * version in this PolicyDefaults, walk up the parent PolicyDefaults hierarchy until
	 * one is found, or return the default value.
	 * 
	 * @return the URI for the XPath version
	 */
	public URI getXPathVersion() {
		/*
		 * See if the XPath version was explicitly set here
		 */
		if (this.xpathVersion != null) {
			return this.xpathVersion;
		}
		
		/*
		 * Try the parent hierarchy if there is one
		 */
		PolicyDefaults	policyDefaultsParentThis	= this.getPolicyDefaultsParent();
		if (policyDefaultsParentThis != null) {
			return policyDefaultsParentThis.getXPathVersion();
		}
		
		/*
		 * Use the default
		 */
		return xpathVersionDefault;
	}
	
	@Override
	public String toString() {
		StringBuilder stringBuilder	= new StringBuilder("{");
		
		boolean	needsComma	= false;
		Object objectToDump;
		if ((objectToDump = this.xpathVersion) != null) {
			stringBuilder.append("xpathVersion=");
			stringBuilder.append(objectToDump.toString());
			needsComma	= true;
		}
		if ((objectToDump = this.getPolicyDefaultsParent()) != null) {
			if (needsComma) {
				stringBuilder.append(',');
			}
			stringBuilder.append("policyDefaultsParent=");
			stringBuilder.append(objectToDump.toString());
		}
		stringBuilder.append('}');
		return stringBuilder.toString();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy