/**
 * DRIVER project 2006-2007
 * 
 * file		:	A2Response.java
 * package	: 	eu.dnetlib.enabling.aas.rmi
 * project	:	driver-aa
 * created	:	2006-09-04
 * author	:	jarwyp
 */
package eu.dnetlib.enabling.aas.rmi;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Basic abstract response object. Covers all the standard parameters.
 * 
 * @author jarwyp
 *
 */
public abstract class A2Response implements Serializable{
	
	/**
	 * List of errors occured before preparing response.
	 */
	private List<A2Error>errors=new ArrayList<A2Error>();
	
	/**
	 * Default constructor for SOAP Xfire purposes.
	 */
	public A2Response() {
		
	}
	
	/**
	 * Returns collection of errors.
	 * @return Collection<A2Error>
	 */
	public A2Error[] getErrors(){
		if (errors==null)
			return null;
		return errors.toArray(new A2Error[0]);
	}
	
	/**
	 * Adds error to collection.
	 * @param error
	 */
	public void addError(A2Error error){
		errors.add(error);
	}
	
	/**
	 * Sets collection of errors.
	 * @param errors
	 */
	public void setErrors(A2Error[] errors){
		this.errors.clear();
		if (errors!=null && errors.length>0) {
			for (int i=0; i<errors.length; i++)
				this.errors.add(errors[i]);
		}
	}
	
	/**
	 * Checks if errors occured.
	 * @return true - if errors found
	 */
	public boolean hasErrors(){
		return (errors!=null && errors.size()!=0);
	}
}
