1 20 package org.enhydra.barracuda.core.forms; 21 22 import java.io.*; 23 import java.util.*; 24 25 import org.enhydra.barracuda.plankton.exceptions.NestableException; 26 27 32 public class ValidationException extends NestableException { 33 34 protected List subExceptions = null; 35 protected Object source = null; 36 protected static final String sep = System.getProperty("line.separator"); 37 38 41 public ValidationException () { 42 this("Generic Validation Exception"); 43 } 44 45 50 public ValidationException (String s) { 51 this(null, s); 52 } 53 54 60 public ValidationException (Object source) { 61 this(source, null); 62 } 63 64 71 public ValidationException (Object source, String s) { 72 this(source, s, null); 73 } 74 75 83 public ValidationException (Object isource, String s, Exception ibaseException) { 84 super(s, ibaseException); 85 source = isource; 86 } 87 88 93 public Object getSource() { 94 return source; 95 } 96 97 104 public boolean hasSubExceptions() { 105 return (subExceptions!=null && subExceptions.size()>0); 106 } 107 108 113 public void addSubException(ValidationException ve) { 114 if (subExceptions==null) subExceptions = new ArrayList(); 115 subExceptions.add(ve); 116 } 117 118 124 public List getSubExceptions() { 125 return (subExceptions==null ? null : new ArrayList(subExceptions)); 126 } 127 128 public String toString() { 129 StringBuffer sb = new StringBuffer (200); 130 sb.append(this.getClass().getName()+"@"+Integer.toHexString(this.hashCode())); 131 sb.append(", Msg:"+getMessage()); 132 if (source!=null && source instanceof ValidationException) sb.append(", Src: ValidationException[@"+Integer.toHexString(source.hashCode())+"]"); 133 else sb.append(", Src:"+source); 134 if (subExceptions!=null) { 135 sb.append(sep+"Sub-exceptions:"); 136 Iterator it = subExceptions.iterator(); 137 while (it.hasNext()) { 138 sb.append(sep+" "+it.next()); 139 } 140 } 141 return sb.toString(); 142 } 143 144 148 public List getExceptionList() { 149 List list = new ArrayList(); 150 list.addAll(getExceptionList(this)); 151 return list; 152 } 153 154 protected List getExceptionList(ValidationException ve) { 155 List list = new ArrayList(); 156 if (!ve.hasSubExceptions()) { 157 list.add(ve); 158 } else { 159 Iterator it = ve.getSubExceptions().iterator(); 160 while (it.hasNext()) { 161 list.addAll(getExceptionList((ValidationException) it.next())); 162 } 163 } 164 return list; 165 } 166 167 } 168 | Popular Tags |