View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.common.exceptions;
17  
18  import java.io.PrintStream;
19  import java.io.PrintWriter;
20  import java.util.List;
21  
22  import javax.xml.ws.WebFault;
23  
24  import org.apache.log4j.Logger;
25  import org.kuali.student.common.validation.dto.ValidationResultInfo;
26  
27  @WebFault(faultBean="org.kuali.student.common.exceptions.jaxws.DataValidationErrorExceptionBean")
28  public class DataValidationErrorException extends Exception {
29  
30  	final Logger LOG = Logger.getLogger(DataValidationErrorException.class);
31  
32  	private static final long serialVersionUID = 1L;
33  
34  	private List<ValidationResultInfo> validationResults;
35  
36  	/**
37  	 *
38  	 */
39  	public DataValidationErrorException() {
40  		super();
41  	}
42  
43  	/**
44  	 * @param validationResults
45  	 */
46  	public DataValidationErrorException(String message, List<ValidationResultInfo> validationResults) {
47  		this(message, validationResults, null);
48  	}
49  
50  	/**
51  	 * @param message
52  	 * @param cause
53  	 */
54  	public DataValidationErrorException(String message, List<ValidationResultInfo> validationResults, Throwable cause) {
55  		super(message, cause);
56  		this.validationResults = validationResults;
57  	}
58  
59  	/**
60  	 * @param message
61  	 * @param cause
62  	 */
63  	public DataValidationErrorException(String message, Throwable cause) {
64  		super(message, cause);
65  	}
66  
67  	/**
68  	 * @param message
69  	 */
70  	public DataValidationErrorException(String message) {
71  		super(message);
72  	}
73  
74  	/**
75  	 * @param cause
76  	 */
77  	public DataValidationErrorException(Throwable cause) {
78  		super(cause);
79  	}
80  
81  
82  	/**
83  	 * @return the validationResults
84  	 */
85  	public List<ValidationResultInfo> getValidationResults() {
86  		return validationResults;
87  	}
88  
89  	@Override
90  	public void printStackTrace(PrintStream s) {
91  		super.printStackTrace(s);
92  		logValidationResults();
93  	}
94  
95  	@Override
96  	public void printStackTrace(PrintWriter s) {
97  		super.printStackTrace(s);
98  		logValidationResults();
99  	}
100 
101 	@Override
102 	public String toString() {
103 		StringBuilder sb = new StringBuilder();
104 		sb.append(super.getMessage()).append("\n");
105 		if (validationResults != null){
106 			sb.append("Validation Results: \n");
107 			for (ValidationResultInfo info:validationResults){
108 				sb.append(info).append("\n");
109 			}
110 		} else {
111 			sb.append("Validation Results: None set.");
112 		}
113 		return sb.toString();
114 	}
115 
116 	private void logValidationResults(){
117 		LOG.debug(toString());	}
118 
119 
120 
121 }