001/** 002 * Copyright 2005-2016 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 */ 016package org.kuali.rice.kew.exception; 017 018import java.io.Serializable; 019import java.util.ArrayList; 020import java.util.Collection; 021import java.util.Iterator; 022import java.util.List; 023 024import org.kuali.rice.krad.util.MessageMap; 025 026 027 028/** 029 * <p>Title: DocElementError </p> 030 * <p>Description: A simple object holding any error(s) generated by 031 * an IDocElement and it's children IDocElements. See IDocElement 032 * documentation for further explanation.</p> 033 * <p>Copyright: Copyright (c) 2002</p> 034 * <p>Company: Indiana University</p> 035 * @author Kuali Rice Team (rice.collab@kuali.org) 036 */ 037public class WorkflowServiceErrorImpl implements Serializable, WorkflowServiceError { 038 039 private static final String CHILDREN_IN_ERROR = "-1"; 040 041 static final long serialVersionUID = 6900090941686297017L; 042 private Collection children; 043 private String type; 044 private String message; 045 private String arg1; 046 private String arg2; 047 048 /** 049 * Passing the actual message map around so we don't lose doc search messages in standalone. 050 */ 051 private MessageMap messageMap; 052 053 054 055 private WorkflowServiceErrorImpl() { 056 } 057 058 public WorkflowServiceErrorImpl(String message, String type) { 059 children = new ArrayList(); 060 this.message = message; 061 this.type = type; 062 } 063 064 public WorkflowServiceErrorImpl(String message, String type, String arg1) { 065 children = new ArrayList(); 066 this.message = message; 067 this.type = type; 068 this.arg1 = arg1; 069 } 070 071 public WorkflowServiceErrorImpl(String message, String type, String arg1, String arg2) { 072 children = new ArrayList(); 073 this.message = message; 074 this.type = type; 075 this.arg1 = arg1; 076 this.arg2 = arg2; 077 } 078 public WorkflowServiceErrorImpl(String message, String type, String arg1, String arg2, MessageMap messageMap) { 079 children = new ArrayList(); 080 this.message = message; 081 this.type = type; 082 this.arg1 = arg1; 083 this.arg2 = arg2; 084 this.messageMap = messageMap; 085 } 086 087 public Collection getChildren() { 088 return this.children; 089 } 090 091 public String getMessage() { 092 return this.message; 093 } 094 095 public String getKey() { 096 return this.type; 097 } 098 099 public String getArg1() { 100 return arg1; 101 } 102 103 public String getArg2() { 104 return arg2; 105 } 106 107 public void addChild(WorkflowServiceError busError) { 108 if (busError != null) { 109 children.add(busError); 110 } 111 } 112 113 public void addChildren(Collection children) { 114 this.children.addAll(children); 115 } 116 117 public Collection getFlatChildrenList() { 118 return buildFlatChildrenList(this, null); 119 } 120 121 private static Collection buildFlatChildrenList(WorkflowServiceError error, List flatList) { 122 if (flatList == null) { 123 flatList = new ArrayList(); 124 } 125 126 if (error.getKey() != CHILDREN_IN_ERROR) { 127 flatList.add(error); 128 } 129 130 Iterator iter = error.getChildren().iterator(); 131 132 while (iter.hasNext()) { 133 WorkflowServiceError childError = (WorkflowServiceError) iter.next(); 134 buildFlatChildrenList(childError, flatList); 135 } 136 137 return flatList; 138 } 139 140 public String toString() { 141 String s = "[WorkflowServiceErrorImpl: type=" + type + ", message=" + message + ", arg1=" + arg1 + ", arg2=" + arg2 + ", children="; 142 if (children == null) { 143 s += "null"; 144 } else { 145 s += children; 146 } 147 s += "]"; 148 return s; 149 } 150 151 /** 152 * @return the messageMap 153 */ 154 @Override 155 public MessageMap getMessageMap() { 156 return this.messageMap; 157 } 158 159 /** 160 * @param messageMap the messageMap to set 161 */ 162 public void setMessageMap(MessageMap messageMap) { 163 this.messageMap = messageMap; 164 } 165}