001    /**
002     * Copyright 2005-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
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 implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.kew.exception;
017    
018    import java.util.ArrayList;
019    import java.util.Collection;
020    
021    /**
022     * RuntimeException thrown from Service level classes when business rule validation
023     * fails.  This exception is caught by StrutsExceptionHandler.  If any service errors
024     * have been set on in the serviceErrors collection these are stripped off of the 
025     * exception put into ActionMessages in the Error que and the request is directed back to 
026     * the original ActionMapping input page.
027     */
028    public class WorkflowServiceErrorException extends RuntimeException {
029    
030    
031            private static final long serialVersionUID = 2457592489303923040L;
032            private Collection serviceErrors;
033        
034        public WorkflowServiceErrorException(String message) {
035            this(message, (Throwable)null);
036        }
037        
038        public WorkflowServiceErrorException(String message, Throwable throwable) {
039            super(message, throwable);
040            serviceErrors = new ArrayList();
041        }
042        
043        public WorkflowServiceErrorException(String msg, WorkflowServiceError error) {
044            super(msg);
045            serviceErrors = new ArrayList();
046            serviceErrors.add(error);
047        }
048    
049            public WorkflowServiceErrorException(String msg, Throwable t, WorkflowServiceError error) {
050            super(msg, t);
051            serviceErrors = new ArrayList();
052            serviceErrors.add(error);
053        }
054        
055        
056        public WorkflowServiceErrorException(String msg, Collection errors) {
057            super(msg);
058            setServiceErrors(errors);
059        }
060        
061        public Collection getServiceErrors() {
062            return serviceErrors;
063        }
064    
065        public void setServiceErrors(Collection serviceErrors) {
066            this.serviceErrors = serviceErrors;
067        }
068    
069        public String toString() {
070            if (serviceErrors != null) {
071                return super.toString() + " " + serviceErrors;    
072            } else {
073                return super.toString() + " (no service errors)";
074            }
075        }
076    }