1 16 17 package org.springframework.beans; 18 19 import java.io.PrintStream ; 20 import java.io.PrintWriter ; 21 22 import org.springframework.util.Assert; 23 24 37 public class PropertyBatchUpdateException extends BeansException { 38 39 40 private PropertyAccessException[] propertyAccessExceptions; 41 42 43 47 public PropertyBatchUpdateException(PropertyAccessException[] propertyAccessExceptions) { 48 super(null); 49 Assert.notEmpty(propertyAccessExceptions, "At least 1 PropertyAccessException required"); 50 this.propertyAccessExceptions = propertyAccessExceptions; 51 } 52 53 54 57 public final int getExceptionCount() { 58 return this.propertyAccessExceptions.length; 59 } 60 61 65 public final PropertyAccessException[] getPropertyAccessExceptions() { 66 return this.propertyAccessExceptions; 67 } 68 69 72 public PropertyAccessException getPropertyAccessException(String propertyName) { 73 for (int i = 0; i < this.propertyAccessExceptions.length; i++) { 74 PropertyAccessException pae = this.propertyAccessExceptions[i]; 75 if (propertyName.equals(pae.getPropertyChangeEvent().getPropertyName())) { 76 return pae; 77 } 78 } 79 return null; 80 } 81 82 83 public String getMessage() { 84 StringBuffer sb = new StringBuffer ("Failed properties: "); 85 for (int i = 0; i < this.propertyAccessExceptions.length; i++) { 86 sb.append(this.propertyAccessExceptions[i].getMessage()); 87 if (i < this.propertyAccessExceptions.length - 1) { 88 sb.append("; "); 89 } 90 } 91 return sb.toString(); 92 } 93 94 public String toString() { 95 StringBuffer sb = new StringBuffer (); 96 sb.append(getClass().getName()).append("; nested PropertyAccessExceptions ("); 97 sb.append(getExceptionCount()).append(") are:"); 98 for (int i = 0; i < this.propertyAccessExceptions.length; i++) { 99 sb.append('\n').append("PropertyAccessException ").append(i + 1).append(": "); 100 sb.append(this.propertyAccessExceptions[i]); 101 } 102 return sb.toString(); 103 } 104 105 public void printStackTrace(PrintStream ps) { 106 ps.println(getClass().getName() + "; nested PropertyAccessException details (" + 107 getExceptionCount() + ") are:"); 108 for (int i = 0; i < this.propertyAccessExceptions.length; i++) { 109 ps.println("PropertyAccessException " + (i + 1) + ":"); 110 this.propertyAccessExceptions[i].printStackTrace(ps); 111 } 112 } 113 114 public void printStackTrace(PrintWriter pw) { 115 pw.println(getClass().getName() + "; nested PropertyAccessException details (" + 116 getExceptionCount() + ") are:"); 117 for (int i = 0; i < this.propertyAccessExceptions.length; i++) { 118 pw.println("PropertyAccessException " + (i + 1) + ":"); 119 this.propertyAccessExceptions[i].printStackTrace(pw); 120 } 121 } 122 123 public boolean contains(Class exClass) { 124 if (exClass == null) { 125 return false; 126 } 127 if (exClass.isInstance(this)) { 128 return true; 129 } 130 for (int i = 0; i < this.propertyAccessExceptions.length; i++) { 131 PropertyAccessException pae = this.propertyAccessExceptions[i]; 132 if (pae.contains(exClass)) { 133 return true; 134 } 135 } 136 return false; 137 } 138 139 } 140 | Popular Tags |