View Javadoc
1   package org.kuali.ole.docstore.common.exception;
2   
3   import java.util.Iterator;
4   import java.util.Map;
5   import java.util.Set;
6   import java.util.TreeMap;
7   
8   /**
9    * Created with IntelliJ IDEA.
10   * User: sambasivam
11   * Date: 12/17/13
12   * Time: 12:39 PM
13   * To change this template use File | Settings | File Templates.
14   */
15  public abstract class DocstoreException extends RuntimeException {
16  
17      private String errorCode;
18      private String errorMessage;
19      private TreeMap<String, String> errorParams;
20  
21  
22      public DocstoreException() {
23          super();
24      }
25  
26      public DocstoreException(String message) {
27          super(message);
28          setErrorMessage(message);
29      }
30  
31  
32      public DocstoreException(String errorCode, String errorMessage, TreeMap<String, String> errorParams) {
33          this.errorMessage = errorMessage;
34          this.errorCode = errorCode;
35          this.errorParams = errorParams;
36  
37      }
38  
39      public DocstoreException(String errorCode, String errorMessage) {
40          this.errorMessage = errorMessage;
41          this.errorCode = errorCode;
42      }
43  
44      public String getErrorCode() {
45          return errorCode;
46      }
47  
48      public void setErrorCode(String errorCode) {
49          this.errorCode = errorCode;
50      }
51  
52      public String getErrorMessage() {
53          return errorMessage;
54      }
55  
56      public void setErrorMessage(String errorMessage) {
57          this.errorMessage = errorMessage;
58      }
59  
60      public TreeMap<String, String> getErrorParams() {
61          return errorParams;
62      }
63  
64      @Override
65      public String toString() {
66          StringBuilder stb = new StringBuilder();
67          stb.append(super.toString());
68          stb.append("\n");
69          stb.append("Error Code = ");
70          stb.append(errorCode);
71          stb.append("\n");
72          stb.append("Error Message = ");
73          stb.append(errorMessage);
74          stb.append("\n");
75          if (errorParams != null) {
76              stb.append("ErrorParams = ");
77              stb.append("\n");
78              Set keySet = errorParams.keySet();
79              Iterator<String> iterator = keySet.iterator();
80              String key = null;
81              while (iterator.hasNext()) {
82                  key = iterator.next();
83                  stb.append("\t");
84                  stb.append(key);
85                  stb.append(" = ");
86                  stb.append(errorParams.get(key));
87                  stb.append("\n");
88              }
89          }
90          return stb.toString();
91      }
92  
93      public void addErrorParams(String key, String value) {
94          if (errorParams == null) {
95              errorParams = new TreeMap<>();
96              errorParams.put(key, value);
97          } else {
98              errorParams.put(key, value);
99          }
100 
101     }
102 }