KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > error > AlfrescoRuntimeException


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.error;
18
19 import org.alfresco.i18n.I18NUtil;
20
21 /**
22  * I18n'ed runtime exception thrown by Alfresco code.
23  *
24  * @author gavinc
25  */

26 public class AlfrescoRuntimeException extends RuntimeException JavaDoc
27 {
28     /**
29      * Serial version UUID
30      */

31     private static final long serialVersionUID = 3834594313622859827L;
32
33     /**
34      * Constructor
35      *
36      * @param msgId the message id
37      */

38     public AlfrescoRuntimeException(String JavaDoc msgId)
39     {
40         super(resolveMessage(msgId, null));
41     }
42     
43     /**
44      * Constructor
45      *
46      * @param msgId the message id
47      * @param msgParams the message parameters
48      */

49     public AlfrescoRuntimeException(String JavaDoc msgId, Object JavaDoc[] msgParams)
50     {
51         super(resolveMessage(msgId, msgParams));
52     }
53
54     /**
55      * Constructor
56      *
57      * @param msgId the message id
58      * @param cause the exception cause
59      */

60     public AlfrescoRuntimeException(String JavaDoc msgId, Throwable JavaDoc cause)
61     {
62         super(resolveMessage(msgId, null), cause);
63     }
64     
65     /**
66      * Constructor
67      *
68      * @param msgId the message id
69      * @param msgParams the message parameters
70      * @param cause the exception cause
71      */

72     public AlfrescoRuntimeException(String JavaDoc msgId, Object JavaDoc[] msgParams, Throwable JavaDoc cause)
73     {
74         super(resolveMessage(msgId, msgParams), cause);
75     }
76     
77     /**
78      * Resolves the message id to the localised string.
79      * <p>
80      * If a localised message can not be found then the message Id is
81      * returned.
82      *
83      * @param messageId the message Id
84      * @param params message parameters
85      * @return the localised message (or the message id if none found)
86      */

87     private static String JavaDoc resolveMessage(String JavaDoc messageId, Object JavaDoc[] params)
88     {
89         String JavaDoc message = I18NUtil.getMessage(messageId, params);
90         if (message == null)
91         {
92             // If a localised string cannot be found then return the messageId
93
message = messageId;
94         }
95         return message;
96     }
97 }
98
Popular Tags