KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > PropertyAccessExceptionsException


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.beans;
18
19 import java.io.PrintStream JavaDoc;
20 import java.io.PrintWriter JavaDoc;
21
22 /**
23  * Combined exception, composed of individual binding propertyAccessExceptions.
24  * An object of this class is created at the beginning of the binding
25  * process, and errors added to it as necessary.
26  *
27  * <p>The binding process continues when it encounters application-level
28  * propertyAccessExceptions, applying those changes that can be applied and storing
29  * rejected changes in an object of this class.
30  *
31  * @author Rod Johnson
32  * @author Juergen Hoeller
33  * @since 18 April 2001
34  */

35 public class PropertyAccessExceptionsException extends BeansException {
36
37     /** BeanWrapper wrapping the target object for binding */
38     private final BeanWrapper beanWrapper;
39
40     /** List of PropertyAccessException objects */
41     private final PropertyAccessException[] propertyAccessExceptions;
42
43     /**
44      * Create a new PropertyAccessExceptionsException.
45      * @param beanWrapper the BeanWrapper that wraps the target object
46      * @param propertyAccessExceptions the List of PropertyAccessExceptions
47      */

48     public PropertyAccessExceptionsException(BeanWrapper beanWrapper,
49                                                                                      PropertyAccessException[] propertyAccessExceptions) {
50         super("");
51         this.beanWrapper = beanWrapper;
52         this.propertyAccessExceptions = propertyAccessExceptions;
53     }
54
55     /**
56      * Return the BeanWrapper that generated this exception.
57      */

58     public BeanWrapper getBeanWrapper() {
59         return beanWrapper;
60     }
61
62     /**
63      * Return the object we're binding to.
64      */

65     public Object JavaDoc getBindObject() {
66         return this.beanWrapper.getWrappedInstance();
67     }
68
69     /**
70      * If this returns 0, no errors were encountered during binding.
71      */

72     public int getExceptionCount() {
73         return this.propertyAccessExceptions.length;
74     }
75
76     /**
77      * Return an array of the propertyAccessExceptions stored in this object.
78      * Will return the empty array (not null) if there were no errors.
79      */

80     public PropertyAccessException[] getPropertyAccessExceptions() {
81         return this.propertyAccessExceptions;
82     }
83
84     /**
85      * Return the exception for this field, or null if there isn't one.
86      */

87     public PropertyAccessException getPropertyAccessException(String JavaDoc 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 JavaDoc getMessage() {
98         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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 JavaDoc 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 JavaDoc 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 JavaDoc toString() {
132         return "PropertyAccessExceptionsException (" + getExceptionCount() + " errors)";
133     }
134
135 }
136
Popular Tags