001/** 002 * Copyright 2010 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the 005 * "License"); you may not use this file except in compliance with the 006 * License. You may obtain a copy of the License at 007 * 008 * http://www.osedu.org/licenses/ECL-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 013 * implied. See the License for the specific language governing 014 * permissions and limitations under the License. 015 */ 016 017package org.kuali.student.r2.common.exceptions; 018 019import org.apache.log4j.Logger; 020import org.kuali.student.r2.common.dto.ValidationResultInfo; 021 022import javax.xml.ws.WebFault; 023import java.io.PrintStream; 024import java.io.PrintWriter; 025import java.util.ArrayList; 026import java.util.List; 027 028@WebFault(name = "DataValidationError") 029public class DataValidationErrorException 030 extends Exception { 031 032 private static final Logger LOG = Logger.getLogger(DataValidationErrorException.class); 033 034 private static final long serialVersionUID = 1L; 035 036 private List<ValidationResultInfo> validationResults; 037 038 public DataValidationErrorException() { 039 } 040 041 public DataValidationErrorException(String message, List<ValidationResultInfo> validationResults) { 042 this(message, validationResults, null); 043 } 044 045 public DataValidationErrorException(String message, List<ValidationResultInfo> validationResults, Throwable cause) { 046 super(message, cause); 047 this.validationResults = validationResults; 048 } 049 050 public DataValidationErrorException(String message, Throwable cause) { 051 super(message, cause); 052 } 053 054 public DataValidationErrorException(String message) { 055 super(message); 056 } 057 058 public DataValidationErrorException(Throwable cause) { 059 super(cause); 060 } 061 062 public List<ValidationResultInfo> getValidationResults() { 063 if(validationResults == null){ 064 validationResults = new ArrayList<ValidationResultInfo>(); 065 } 066 return validationResults; 067 } 068 069 public void setValidationResults(List<ValidationResultInfo> validationResults) { 070 this.validationResults = validationResults; 071 } 072 073 074 @Override 075 public void printStackTrace(PrintStream s) { 076 super.printStackTrace(s); 077 logValidationResults(); 078 } 079 080 @Override 081 public void printStackTrace(PrintWriter s) { 082 super.printStackTrace(s); 083 logValidationResults(); 084 } 085 086 @Override 087 public String toString() { 088 StringBuilder sb = new StringBuilder(); 089 sb.append(super.getMessage()).append("\n"); 090 091 if (validationResults != null) { 092 sb.append("Validation Results: \n"); 093 for (ValidationResultInfo info:validationResults) { 094 sb.append(info).append("\n"); 095 } 096 } else { 097 sb.append("Validation Results: None set."); 098 } 099 return sb.toString(); 100 } 101 102 private void logValidationResults() { 103 LOG.debug(toString()); 104 } 105}