package org.springframework.beans;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.util.StringUtils;

/**
 * Combined exception, composed of individual binding exceptions.
 * An object of this class is created at the beginning of the binding
 * process, and errors added to it as necessary.
 *
 * <p>The binding process continues when it encounters application-level
 * exceptions, applying those changes that can be applied and storing
 * rejected changes in an object of this class.
 *
 * @author Rod Johnson
 * @since 18 April 2001
 * @version $Id: PropertyAccessExceptionsException.java,v 1.1 2004-02-02 11:33:34 jhoeller Exp $
 */
public class PropertyAccessExceptionsException extends BeansException {

	/** List of ErrorCodedPropertyVetoException objects */
	private List exceptions = new ArrayList();

	/** BeanWrapper wrapping the target object for binding */
	private BeanWrapper beanWrapper;

	/**
	 * Create new empty PropertyAccessExceptionsException.
	 * We'll add errors to it as we attempt to bind properties.
	 */
	PropertyAccessExceptionsException(BeanWrapper beanWrapper) {
		super("");
		this.beanWrapper = beanWrapper;
	}

	/**
	 * Return the BeanWrapper that generated this exception.
	 */
	public BeanWrapper getBeanWrapper() {
		return beanWrapper;
	}

	/**
	 * Return the object we're binding to.
	 */
	public Object getBindObject() {
		return this.beanWrapper.getWrappedInstance();
	}

	/**
	 * If this returns 0, no errors were encountered during binding.
	 */
	public int getExceptionCount() {
		return this.exceptions.size();
	}

	/**
	 * Return an array of the exceptions stored in this object.
	 * Will return the empty array (not null) if there were no errors.
	 */
	public PropertyAccessException[] getPropertyAccessExceptions() {
		return (PropertyAccessException[]) this.exceptions.toArray(new PropertyAccessException[this.exceptions.size()]);
	}

	/**
	 * Return the exception for this field, or null if there isn't one.
	 */
	public PropertyAccessException getPropertyAccessException(String propertyName) {
		for (Iterator itr = this.exceptions.iterator(); itr.hasNext();) {
			PropertyAccessException pve = (PropertyAccessException) itr.next();
			if (propertyName.equals(pve.getPropertyChangeEvent().getPropertyName())) {
				return pve;
			}
		}
		return null;
	}

	/* package */
	void addPropertyAccessException(PropertyAccessException ex) {
		this.exceptions.add(ex);
	}

	public String toString() {
		return "PropertyAccessExceptionsException (" + getExceptionCount() + " errors):\n" +
				StringUtils.collectionToDelimitedString(this.exceptions, "\n");
	}

}

@@ -106,16 +106,72 @@
 il.List;
+%0Aimport java.io.PrintStream;%0Aimport java.io.PrintWriter;
 %0A%0Aimport
@@ -703,17 +703,17 @@
 ava,v 1.
-1
+2
  2004-02
@@ -718,18 +718,18 @@
 02-0
-2 11:33:34
+7 00:14:02
  jho
@@ -2170,17 +2170,16 @@
 rator it
-r
  = this.
@@ -2203,17 +2203,16 @@
 or(); it
-r
 .hasNext
@@ -2246,17 +2246,17 @@
 eption p
-v
+a
 e = (Pro
@@ -2279,17 +2279,16 @@
 tion) it
-r
 .next();
@@ -2316,17 +2316,17 @@
 equals(p
-v
+a
 e.getPro
@@ -2378,17 +2378,17 @@
 return p
-v
+a
 e;%0A%09%09%09%7D%0A
@@ -2531,181 +2531,587 @@
 lic 
-String toString() %7B%0A%09%09return %22PropertyAccessExceptionsException (%22 + getExceptionCount() + %22 errors):%5Cn%22 +%0A%09%09%09%09StringUtils.collectionToDelimitedString(this.exceptions, %22%5Cn%22)
+void printStackTrace(PrintStream ps) %7B%0A%09%09ps.println(this);%0A%09%09for (Iterator it = this.exceptions.iterator(); it.hasNext();) %7B%0A%09%09%09PropertyAccessException pae = (PropertyAccessException) it.next();%0A%09%09%09pae.printStackTrace(ps);%0A%09%09%7D%0A%09%7D%0A%0A%09public void printStackTrace(PrintWriter pw) %7B%0A%09%09pw.println(this);%0A%09%09for (Iterator it = this.exceptions.iterator(); it.hasNext();) %7B%0A%09%09%09PropertyAccessException pae = (PropertyAccessException) it.next();%0A%09%09%09pae.printStackTrace(pw);%0A%09%09%7D%0A%09%7D%0A%0A%09public String toString() %7B%0A%09%09return %22PropertyAccessExceptionsException (%22 + getExceptionCount() + %22 errors)%22
 ;%0A%09%7D

print out stacktraces of contained exceptions