1
16
17 package org.apache.wsrp4j.exception;
18
19 import java.io.InputStream;
20 import java.util.Properties;
21
22 import org.apache.wsrp4j.log.LogManager;
23 import org.apache.wsrp4j.log.Logger;
24
25
28 public class Messages {
29
30
31 public static final int COMMON_LOWER_BOUND = 1000;
32
33
34 public static final int COMMON_UPPER_BOUND = 1999;
35
36
37 public static final int PRODUCER_LOWER_BOUND = 2000;
38
39
40 public static final int PRODUCER_UPPER_BOUND = 2999;
41
42
43 public static final int PROVIDER_LOWER_BOUND = 3000;
44
45
46 public static final int PROVIDER_UPPER_BOUND = 3999;
47
48
49 public static final int CONSUMER_LOWER_BOUND = 6000;
50
51
52 public static final int CONSUMER_UPPER_BOUND = 6999;
53
54 private static final String FILE_MSG_PROPERTIES = "wsrp-messages.properties";
55
56 private static final String MSG_EXCEPTION_ON_LOAD = "Error while loading messages from "
57 + FILE_MSG_PROPERTIES + ".";
58
59 private static final String MSG_NO_MSG_FOUND = "No message found.";
60
61 private static final String MSG_NO_MSG_FOUND_FOR = "No message found for ";
62
63 private static final String METHOD_INIT = "<init>";
64
65 private static final String METHOD_GET = "get()";
66
67 private static Logger logger = LogManager.getLogManager().getLogger(
68 Messages.class);
69
70 private static Properties msgMap = new Properties();
71
72
76 private Messages() {
77
78 try {
80 InputStream in = getClass().getClassLoader().getResourceAsStream(
81 FILE_MSG_PROPERTIES);
82 msgMap.load(in);
83 }
84 catch (Exception e) {
85 logger.text(Logger.ERROR, METHOD_INIT, e, MSG_EXCEPTION_ON_LOAD);
86 }
87 }
88
89
94 public static String get(int msgCode) {
95 String msg = (String) msgMap.get(new Integer(msgCode).toString());
96 if (msg == null) {
97 msg = MSG_NO_MSG_FOUND;
98 if (logger.isLogging(Logger.TRACE_LOW)) {
99 logger.text(Logger.TRACE_LOW, METHOD_GET, MSG_NO_MSG_FOUND_FOR
100 + msgCode + " in " + FILE_MSG_PROPERTIES + ".");
101 }
102 }
103 return msg;
104 }
105 }