KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > util > ErrorCatalog


1 /**
2  * Copyright 2004-2005 jManage.org
3  *
4  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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.jmanage.core.util;
17
18 import java.util.Properties JavaDoc;
19 import java.util.logging.Logger JavaDoc;
20 import java.util.logging.Level JavaDoc;
21 import java.io.FileInputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.text.MessageFormat JavaDoc;
24
25 /**
26  *
27  * date: Feb 15, 2005
28  * @author Rakesh Kalra
29  */

30 public class ErrorCatalog {
31
32     private static final Logger JavaDoc logger = Loggers.getLogger(ErrorCatalog.class);
33
34     private static final Properties JavaDoc errorMap;
35
36     static{
37         final String JavaDoc errorProperties = CoreUtils.getConfigDir() +
38                 "/errors.properties";
39         errorMap = new Properties JavaDoc();
40         try {
41             errorMap.load(new FileInputStream JavaDoc(errorProperties));
42         } catch (IOException JavaDoc e) {
43             logger.log(Level.WARNING, "Error reading " +
44                   errorProperties + ". error: " + e.getMessage());
45         }
46     }
47
48     public static String JavaDoc getMessage(String JavaDoc errorCode){
49         return getMessage(errorCode, null);
50     }
51
52     public static String JavaDoc getMessage(String JavaDoc errorCode, Object JavaDoc value0){
53         return getMessage(errorCode, new Object JavaDoc[]{value0});
54     }
55
56     public static String JavaDoc getMessage(String JavaDoc errorCode, Object JavaDoc[] values){
57         String JavaDoc message = errorMap.getProperty(errorCode,
58                 "ErrorCode=" + errorCode);
59         if(values != null){
60             message = MessageFormat.format(message, values);
61         }
62         return message;
63     }
64 }
65
Popular Tags