001: /**
002: * $Id: IWAYConfiguration.java,v 1.1 2005/03/14 09:21:13 nk137934 Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.iwayutil.config;
014:
015: import java.util.ResourceBundle;
016: import java.util.MissingResourceException;
017: import java.util.logging.Logger;
018:
019: /**
020: * This class is used to read IWay related configuration data.
021: * The config parameters are initilaized from a file called
022: * "iwayconfig.properties". This file needs to be present
023: * in the classpath of any web application using this library.
024: * It would typically be present in WEB-INF/classes directory.
025: *
026: * @author nk137934
027: */
028: public class IWAYConfiguration implements IWAYConfigConstants {
029:
030: private static ResourceBundle iwayConfig = null;
031: private static boolean initFailed = false;
032: private static Logger logger = Logger
033: .getLogger("com.sun.portal.iwayutil");
034:
035: // Static initializer that reads the configuration file.
036: // If read succeeds, initFailed is set to true.
037: static {
038: try {
039: iwayConfig = ResourceBundle
040: .getBundle(IWAY_CONFIG_FILE_NAME);
041: } catch (MissingResourceException mrExcp) {
042: logger.severe("Could not read the iway config file.");
043: logger.severe("Check if config file:"
044: + IWAY_CONFIG_FILE_NAME + ".properties"
045: + " is present in Classpath ");
046: initFailed = true;
047: }
048:
049: }
050:
051: /** Private Constructor */
052: private IWAYConfiguration() {
053: }
054:
055: public static String getIWAYHomeDir()
056: throws IWAYConfigurationException {
057: checkConfig();
058: return iwayConfig.getString(IWAY_HOME_DIR);
059: }
060:
061: public static String getIWAYConfigDir()
062: throws IWAYConfigurationException {
063: checkConfig();
064: return iwayConfig.getString(IWAY_CONFIG_DIR);
065: }
066:
067: public static String getIWAYDebugLevel()
068: throws IWAYConfigurationException {
069: checkConfig();
070: return iwayConfig.getString(IWAY_DEBUG_LEVEL);
071: }
072:
073: public static String getIWAYAdapterName()
074: throws IWAYConfigurationException {
075: checkConfig();
076: return iwayConfig.getString(IWAY_ADAPTER_NAME);
077: }
078:
079: public static String getIWAYTargetName()
080: throws IWAYConfigurationException {
081: checkConfig();
082: return iwayConfig.getString(IWAY_TARGET_NAME);
083: }
084:
085: public static String getIWAYRepoURL()
086: throws IWAYConfigurationException {
087: checkConfig();
088: return iwayConfig.getString(IWAY_REPOSITORY_URL);
089: }
090:
091: public static String getIWAYUserName()
092: throws IWAYConfigurationException {
093: checkConfig();
094: return iwayConfig.getString(IWAY_USER_NAME);
095: }
096:
097: public static String getIWAYUserPassword()
098: throws IWAYConfigurationException {
099: checkConfig();
100: return iwayConfig.getString(IWAY_USER_PASSWORD);
101: }
102:
103: public static String getIWAYConnectionType()
104: throws IWAYConfigurationException {
105: checkConfig();
106: return iwayConfig.getString(IWAY_CONNECTION_TYPE);
107: }
108:
109: /**
110: * This method checks if the init has suceeded or not. If init
111: * has failed and IWAyConfiguration excpetion is thrown.
112: * @throws IWAYConfigurationException if init has failed.
113: */
114:
115: private static void checkConfig() throws IWAYConfigurationException {
116: if (initFailed)
117: throw new IWAYConfigurationException(
118: "Could not read config file:"
119: + IWAY_CONFIG_FILE_NAME);
120:
121: }
122: }
|