Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
LocalizedException |
|
| 1.0;1 |
1 | /* | |
2 | * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons-sandbox//i18n/src/java/org/apache/commons/i18n/LocalizedException.java,v 1.1 2004/10/04 13:41:09 dflorey Exp $ | |
3 | * $Revision: 480489 $ | |
4 | * $Date: 2006-11-29 09:00:46 +0000 (Wed, 29 Nov 2006) $ | |
5 | * | |
6 | * ==================================================================== | |
7 | * | |
8 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
9 | * contributor license agreements. See the NOTICE file distributed with | |
10 | * this work for additional information regarding copyright ownership. | |
11 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
12 | * (the "License"); you may not use this file except in compliance with | |
13 | * the License. You may obtain a copy of the License at | |
14 | * | |
15 | * http://www.apache.org/licenses/LICENSE-2.0 | |
16 | * | |
17 | * Unless required by applicable law or agreed to in writing, software | |
18 | * distributed under the License is distributed on an "AS IS" BASIS, | |
19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
20 | * See the License for the specific language governing permissions and | |
21 | * limitations under the License. | |
22 | * | |
23 | */ | |
24 | package org.apache.commons.i18n; | |
25 | ||
26 | import java.text.MessageFormat; | |
27 | import java.util.Locale; | |
28 | ||
29 | import org.apache.commons.i18n.bundles.ErrorBundle; | |
30 | ||
31 | /** | |
32 | * The <code>LocalizedException</code> class is the base class for all exceptions | |
33 | * that provide locaized error informations. | |
34 | * | |
35 | */ | |
36 | public class LocalizedException extends Exception { | |
37 | private ErrorBundle errorMessage; | |
38 | ||
39 | /** | |
40 | * @param errorMessage The error message contains a detailed localized description of the error that caused the exception | |
41 | * @param throwable The <code>Throwable</code> that caused this exception | |
42 | */ | |
43 | public LocalizedException(ErrorBundle errorMessage, Throwable throwable) { | |
44 | 2 | super(errorMessage.getSummary(Locale.getDefault(), throwable.getMessage()), throwable); |
45 | 2 | this.errorMessage = errorMessage; |
46 | 2 | } |
47 | ||
48 | /** | |
49 | * @param errorMessage The error message contains a detailed localized description of the error that caused the exception | |
50 | */ | |
51 | public LocalizedException(ErrorBundle errorMessage) { | |
52 | 2 | super(errorMessage.getSummary( |
53 | Locale.getDefault(), | |
54 | MessageFormat.format( | |
55 | I18nUtils.INTERNAL_MESSAGES.getString(I18nUtils.MESSAGE_ENTRY_NOT_FOUND), | |
56 | new String[] { errorMessage.getId(), ErrorBundle.SUMMARY }))); | |
57 | 2 | this.errorMessage = errorMessage; |
58 | 2 | } |
59 | ||
60 | /** | |
61 | * @return the detailed error message that describes this exception | |
62 | */ | |
63 | public ErrorBundle getErrorMessage() { | |
64 | 4 | return errorMessage; |
65 | } | |
66 | } |