1 16 17 package org.springframework.beans; 18 19 import java.io.PrintStream ; 20 import java.io.PrintWriter ; 21 22 35 public class PropertyAccessExceptionsException extends BeansException { 36 37 38 private final BeanWrapper beanWrapper; 39 40 41 private final PropertyAccessException[] propertyAccessExceptions; 42 43 48 public PropertyAccessExceptionsException(BeanWrapper beanWrapper, 49 PropertyAccessException[] propertyAccessExceptions) { 50 super(""); 51 this.beanWrapper = beanWrapper; 52 this.propertyAccessExceptions = propertyAccessExceptions; 53 } 54 55 58 public BeanWrapper getBeanWrapper() { 59 return beanWrapper; 60 } 61 62 65 public Object getBindObject() { 66 return this.beanWrapper.getWrappedInstance(); 67 } 68 69 72 public int getExceptionCount() { 73 return this.propertyAccessExceptions.length; 74 } 75 76 80 public PropertyAccessException[] getPropertyAccessExceptions() { 81 return this.propertyAccessExceptions; 82 } 83 84 87 public PropertyAccessException getPropertyAccessException(String propertyName) { 88 for (int i = 0; i < this.propertyAccessExceptions.length; i++) { 89 PropertyAccessException pae = this.propertyAccessExceptions[i]; 90 if (propertyName.equals(pae.getPropertyChangeEvent().getPropertyName())) { 91 return pae; 92 } 93 } 94 return null; 95 } 96 97 public String getMessage() { 98 StringBuffer sb = new StringBuffer (); 99 sb.append(this.toString()); 100 sb.append("; nested propertyAccessExceptions are: "); 101 for (int i = 0; i < this.propertyAccessExceptions.length; i++) { 102 PropertyAccessException pae = this.propertyAccessExceptions[i]; 103 sb.append("["); 104 sb.append(pae.getClass().getName()); 105 sb.append(": "); 106 sb.append(pae.getMessage()); 107 sb.append(']'); 108 if (i < this.propertyAccessExceptions.length - 1) { 109 sb.append(", "); 110 } 111 } 112 return sb.toString(); 113 } 114 115 public void printStackTrace(PrintStream ps) { 116 ps.println(this); 117 for (int i = 0; i < this.propertyAccessExceptions.length; i++) { 118 PropertyAccessException pae = this.propertyAccessExceptions[i]; 119 pae.printStackTrace(ps); 120 } 121 } 122 123 public void printStackTrace(PrintWriter pw) { 124 pw.println(this); 125 for (int i = 0; i < this.propertyAccessExceptions.length; i++) { 126 PropertyAccessException pae = this.propertyAccessExceptions[i]; 127 pae.printStackTrace(pw); 128 } 129 } 130 131 public String toString() { 132 return "PropertyAccessExceptionsException (" + getExceptionCount() + " errors)"; 133 } 134 135 } 136 | Popular Tags |