001: /*
002: * Copyright 2000-2001,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.wsrp4j.exception;
018:
019: import java.io.InputStream;
020: import java.util.Properties;
021:
022: import org.apache.wsrp4j.log.LogManager;
023: import org.apache.wsrp4j.log.Logger;
024:
025: /**
026: Holds all exception messages
027: */
028: public class Messages {
029:
030: /** defines the lowest message code for common messages */
031: public static final int COMMON_LOWER_BOUND = 1000;
032:
033: /** defines the highest message code for common messages */
034: public static final int COMMON_UPPER_BOUND = 1999;
035:
036: /** defines the lowest message code for producer messages */
037: public static final int PRODUCER_LOWER_BOUND = 2000;
038:
039: /** defines the highest message code for producer messages */
040: public static final int PRODUCER_UPPER_BOUND = 2999;
041:
042: /** defines the lowest message code for provider messages */
043: public static final int PROVIDER_LOWER_BOUND = 3000;
044:
045: /** defines the highest message code for provider messages */
046: public static final int PROVIDER_UPPER_BOUND = 3999;
047:
048: /** defines the lowest message code for consumer messages */
049: public static final int CONSUMER_LOWER_BOUND = 6000;
050:
051: /** defines the highest message code for consumer messages */
052: public static final int CONSUMER_UPPER_BOUND = 6999;
053:
054: private static final String FILE_MSG_PROPERTIES = "wsrp-messages.properties";
055:
056: private static final String MSG_EXCEPTION_ON_LOAD = "Error while loading messages from "
057: + FILE_MSG_PROPERTIES + ".";
058:
059: private static final String MSG_NO_MSG_FOUND = "No message found.";
060:
061: private static final String MSG_NO_MSG_FOUND_FOR = "No message found for ";
062:
063: private static final String METHOD_INIT = "<init>";
064:
065: private static final String METHOD_GET = "get()";
066:
067: private static Logger logger = LogManager.getLogManager()
068: .getLogger(Messages.class);
069:
070: private static Properties msgMap = new Properties();
071:
072: /**
073: Private constructor loads messages from <code>messages.properties</code> file in
074: <code>org.apache.wsrp4j.exception</code>
075: */
076: private Messages() {
077:
078: //load properties file
079: try {
080: InputStream in = getClass().getClassLoader()
081: .getResourceAsStream(FILE_MSG_PROPERTIES);
082: msgMap.load(in);
083: } catch (Exception e) {
084: logger.text(Logger.ERROR, METHOD_INIT, e,
085: MSG_EXCEPTION_ON_LOAD);
086: }
087: }
088:
089: /**
090: Returns an error message for a message code
091: @param msgCode code that identifies a message
092: @return String representing a message
093: */
094: public static String get(int msgCode) {
095: String msg = (String) msgMap.get(new Integer(msgCode)
096: .toString());
097: if (msg == null) {
098: msg = MSG_NO_MSG_FOUND;
099: if (logger.isLogging(Logger.TRACE_LOW)) {
100: logger.text(Logger.TRACE_LOW, METHOD_GET,
101: MSG_NO_MSG_FOUND_FOR + msgCode + " in "
102: + FILE_MSG_PROPERTIES + ".");
103: }
104: }
105: return msg;
106: }
107: }
|