1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.chemistry.opencmis.commons.exceptions;
20
21 import java.math.BigInteger;
22 import java.util.Map;
23
24 /**
25 * Base exception class for all CMIS exceptions.
26 */
27 public abstract class CmisBaseException extends RuntimeException {
28
29 private static final long serialVersionUID = 1L;
30
31 /** Error code used by the Web Services binding. */
32 private BigInteger code = BigInteger.ZERO;
33
34 /**
35 * Content the of the error page returned by the AtomPub or Browser Binding
36 * server.
37 */
38 private String errorContent;
39
40 /** Additional data of this exception. */
41 private Map<String, String> additionalData;
42
43 /**
44 * Default constructor.
45 */
46 protected CmisBaseException() {
47 super();
48 }
49
50 /**
51 * Constructor.
52 *
53 * @param message
54 * error message
55 * @param code
56 * error code
57 * @param cause
58 * the cause
59 */
60 protected CmisBaseException(String message, BigInteger code, Throwable cause) {
61 super(message, cause);
62 this.code = code;
63 }
64
65 /**
66 * Constructor.
67 *
68 * @param message
69 * error message
70 * @param errorContent
71 * error page content
72 * @param additionalData
73 * additional data
74 * @param cause
75 * the cause
76 */
77 protected CmisBaseException(String message, String errorContent, Map<String, String> additionalData, Throwable cause) {
78 super(message, cause);
79 this.errorContent = errorContent;
80 this.additionalData = additionalData;
81 }
82
83 /**
84 * Constructor.
85 *
86 * @param message
87 * error message
88 * @param errorContent
89 * error page content
90 * @param cause
91 * the cause
92 */
93 protected CmisBaseException(String message, String errorContent, Throwable cause) {
94 this(message, errorContent, null, cause);
95 }
96
97 /**
98 * Constructor.
99 *
100 * @param message
101 * error message
102 * @param code
103 * error code
104 */
105 protected CmisBaseException(String message, BigInteger code) {
106 super(message);
107 this.code = code;
108 }
109
110 /**
111 * Constructor.
112 *
113 * @param message
114 * error message
115 * @param code
116 * error code
117 * @param errorContent
118 * error page content
119 */
120 protected CmisBaseException(String message, BigInteger code, String errorContent) {
121 super(message);
122 this.code = code;
123 this.errorContent = errorContent;
124 }
125
126 /**
127 * Constructor.
128 *
129 * @param message
130 * error message
131 * @param code
132 * error code
133 * @param errorContent
134 * error page content
135 * @param additionalData
136 * additional data
137 */
138 protected CmisBaseException(String message, BigInteger code, String errorContent, Map<String, String> additionalData) {
139 this(message, code, errorContent);
140 this.additionalData = additionalData;
141 }
142
143 /**
144 * Constructor.
145 *
146 * @param message
147 * error message
148 * @param errorContent
149 * error page content
150 */
151 protected CmisBaseException(String message, String errorContent) {
152 super(message);
153 this.errorContent = errorContent;
154 }
155
156 /**
157 * Constructor.
158 *
159 * @param message
160 * error message
161 * @param cause
162 * the cause
163 */
164 protected CmisBaseException(String message, Throwable cause) {
165 this(message, (BigInteger) null, cause);
166 }
167
168 /**
169 * Constructor.
170 *
171 * @param message
172 * error message
173 */
174 protected CmisBaseException(String message) {
175 this(message, (BigInteger) null);
176 }
177
178 /**
179 * Returns the error code sent by the CMIS repository (Web Services binding
180 * only).
181 *
182 * @return error code or {@code null} if the CMIS repository didn't send an
183 * error code or the binding doesn't support error codes.
184 */
185 public BigInteger getCode() {
186 return code;
187 }
188
189 /**
190 * Returns the content of the error page sent by the web server.
191 *
192 * @return the content of the error page or {@code null} if the server
193 * didn't send text content.
194 */
195 public String getErrorContent() {
196 return errorContent;
197 }
198
199 /**
200 * Returns additional data, if available.
201 *
202 * @return additional data, can be {@code null}
203 */
204 public Map<String, String> getAdditionalData() {
205 return additionalData;
206 }
207
208 /**
209 * Returns additional data, if available.
210 *
211 * @param key
212 * the data key
213 *
214 * @return additional data, can be {@code null}
215 */
216 public String getAdditionalData(String key) {
217 if (additionalData == null) {
218 return null;
219 }
220
221 return additionalData.get(key);
222 }
223
224 /**
225 * Sets additional data.
226 *
227 * @param data
228 * the data
229 */
230 public void setAdditionalData(Map<String, String> data) {
231 additionalData = data;
232 }
233
234 /**
235 * Returns the name of the exception as defined in the CMIS specification.
236 *
237 * @return the exception name
238 */
239 public abstract String getExceptionName();
240 }