package eu.dnetlib.enabling.aas.rmi;


/**
 * Contains request informations for authorization process. Created for all
 * incoming requests.
 * 
 * @author mhorst
 * 
 */
public class AuthorizeRequest extends A2Request {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6863641801149690752L;

	private TypedString resource = null;

	private TypedString action = null;

	private Attribute[] attributes = null;

	/**
	 * Default constructor for SOAP Xfire purposes.
	 */
	public AuthorizeRequest() {
		
	}
	
	/**
	 * Constructor with String resource parameter.
	 * 
	 * @param resource
	 */
	public AuthorizeRequest(String resource) {
		this.resource = new TypedString(resource);
	}

	/**
	 * Constructor with TypedString resource parameter.
	 * 
	 * @param resource
	 */
	public AuthorizeRequest(TypedString resource) {
		this.resource = resource;
	}

	/**
	 * Constructor with String type parameters.
	 * 
	 * @param resource
	 * @param action
	 */
	public AuthorizeRequest(String resource, String action) {
		this.resource = new TypedString(resource);
		this.action = new TypedString(action);
	}

	/**
	 * Constructor with TypedString type parameters.
	 * 
	 * @param resource
	 * @param action
	 */
	public AuthorizeRequest(TypedString resource, TypedString action) {
		this.resource = resource;
		this.action = action;
	}

	/**
	 * Constructor with String type parameters and attributes.
	 * 
	 * @param resource
	 * @param action
	 * @param attributes
	 */
	public AuthorizeRequest(String resource, String action,
			Attribute[] attributes) {
		this.resource = new TypedString(resource);
		this.action = new TypedString(action);
		this.attributes = attributes;
	}

	/**
	 * Constructor with TypedString type parameters and attributes.
	 * 
	 * @param resource
	 * @param action
	 * @param attributes
	 */
	public AuthorizeRequest(TypedString resource, TypedString action,
			Attribute[] attributes) {
		this.resource = resource;
		this.action = action;
		this.attributes = attributes;
	}

	/**
	 * Returns true if is a reaource.
	 * 
	 * @return true if is a reaource.
	 */
	public boolean checkIfResource() {
		return resource != null && action == null;
	}

	/**
	 * Returns true if is an action.
	 * 
	 * @return true if is an action.
	 */
	public boolean checkIfAction() {
		return resource != null && action != null;
	}

	/**
	 * Returns true if is an attributable action.
	 * 
	 * @return true if is an attributable action.
	 */
	public boolean checkIfAttributableAction() {
		return resource != null && action != null && attributes != null;
	}

	/**
	 * Returns attributes of request.
	 * 
	 * @return attributes
	 */
	public Attribute[] getAttributes() {
		return attributes;
	}

	/**
	 * Returns action of request.
	 * 
	 * @return action
	 */
	public TypedString getAction() {
		return action;
	}

	/**
	 * Sets action for request.
	 * 
	 * @param action
	 */
	public void setAction(TypedString action) {
		this.action = action;
	}

	/**
	 * Returns resource of request.
	 * 
	 * @return resource
	 */
	public TypedString getResource() {
		return resource;
	}

	/**
	 * Sets resource for request.
	 * 
	 * @param resource
	 */
	public void setResource(TypedString resource) {
		this.resource = resource;
	}

	/**
	 * Sets attributes for request.
	 * 
	 * @param attributes
	 */
	public void setAttributes(Attribute[] attributes) {
		this.attributes = attributes;
	}

}
