⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servicepropertyreader.java

📁 STRUTS数据库项目开发宝典
💻 JAVA
字号:
package org.helpsoft.servicelocator;

import com.helpsoft.util.log.LogService;
import com.helpsoft.util.log.Logger;

import java.net.URL;
import java.util.Properties;
import java.io.Serializable;
import com.helpsoft.util.log.LogService;
import com.helpsoft.util.log.Logger;


/**
 * Read the service to implementation mappings from the services.properties file.
 * @author cao guangxin - www.relationinfo.com
 */
public class ServicePropertyReader implements Serializable {

    /**
     * De logger.
     */
    private static Logger log = LogService.getLogger(ServicePropertyReader.class);

    /**
     * property file waarin applicatie configuraties staan.
     */
    private static final String SERVICES_PROPERTIES_FILE_PATH = "/conf/service.properties";

    /**
     * property.
     */
    private static Properties properties = null;

    /**
     * Lees de woz online property file in.
     *
     * @return properties, null als de properties niet worden gevonden.
     *
     */
    public static synchronized Properties getProperties() {
        if (properties == null) {
            properties = new Properties();
            try {
                URL url = ServicePropertyReader.class.getResource(SERVICES_PROPERTIES_FILE_PATH);
                properties.load(url.openStream());
            } catch (Exception ex) {
                // If the properties are not loaded, it's fatal!
                log.fatal("Property file: " + SERVICES_PROPERTIES_FILE_PATH + " could not be read!", ex);
                return null;
            }
        }
        return properties;
    }

    /**
     * Read a property .
     *
     * @param propertyName the property name
     * @return property value of the property, otherwise: <tt>null</tt>
     */
    public static String getProperty(String propertyName) {
        return getProperties().getProperty(propertyName);
    }

    /**
     * Read a property with a fall back value.
     *
     * @param propertyName the property name.
     * @param defaultValue fall back value
     * @return property value if not null, otherwise the fallback value.
     */
    public static String getProperty(String propertyName, String defaultValue) {
        return getProperties().getProperty(propertyName, defaultValue);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -