View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.rice.kew.exception;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.Iterator;
22  import java.util.List;
23  
24  import org.kuali.rice.krad.util.MessageMap;
25  
26  
27  
28  /**
29   * <p>Title: DocElementError </p>
30   * <p>Description: A simple object holding any error(s) generated by
31   * an IDocElement and it's children IDocElements.  See IDocElement
32   * documentation for further explanation.</p>
33   * <p>Copyright: Copyright (c) 2002</p>
34   * <p>Company: Indiana University</p>
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  public class WorkflowServiceErrorImpl implements Serializable, WorkflowServiceError {
38  
39  	private static final String CHILDREN_IN_ERROR = "-1";
40  
41    static final long serialVersionUID = 6900090941686297017L;
42    private Collection children;
43    private String type;
44    private String message;
45    private String arg1;
46    private String arg2;
47    
48    /**
49     * Passing the actual message map around so we don't lose doc search messages in standalone.
50     */
51    private MessageMap messageMap;
52  
53  
54  
55    private WorkflowServiceErrorImpl() {
56    }
57  
58    public WorkflowServiceErrorImpl(String message, String type) {
59      children = new ArrayList();
60      this.message = message;
61      this.type = type;
62    }
63  
64    public WorkflowServiceErrorImpl(String message, String type, String arg1) {
65        children = new ArrayList();
66        this.message = message;
67        this.type = type;
68        this.arg1 = arg1;
69    }
70  
71    public WorkflowServiceErrorImpl(String message, String type, String arg1, String arg2) {
72        children = new ArrayList();
73        this.message = message;
74        this.type = type;
75        this.arg1 = arg1;
76        this.arg2 = arg2;
77    }
78    public WorkflowServiceErrorImpl(String message, String type, String arg1, String arg2, MessageMap messageMap) {
79        children = new ArrayList();
80        this.message = message;
81        this.type = type;
82        this.arg1 = arg1;
83        this.arg2 = arg2;
84        this.messageMap = messageMap;
85    }
86  
87    public Collection getChildren() {
88      return this.children;
89    }
90  
91    public String getMessage() {
92      return this.message;
93    }
94  
95    public String getKey() {
96      return this.type;
97    }
98  
99    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 }