com.bstek.dorado.console.ConsoleConfigure.java Source code

Java tutorial

Introduction

Here is the source code for com.bstek.dorado.console.ConsoleConfigure.java

Source

/*
 * This file is part of Dorado 7.x (http://dorado7.bsdn.org).
 * 
 * Copyright (c) 2002-2012 BSTEK Corp. All rights reserved.
 * 
 * This file is dual-licensed under the AGPLv3 (http://www.gnu.org/licenses/agpl-3.0.html) 
 * and BSDN commercial (http://www.bsdn.org/licenses) licenses.
 * 
 * If you are unsure which license is appropriate for your use, please contact the sales department
 * at http://www.bstek.com/contact.
 */

package com.bstek.dorado.console;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.bstek.dorado.util.Assert;

/**
 * ?Dorado Console?
 * 
 * @author Alex Tong (mailto:alex.tong@bstek.com)
 * @since 2012-12-12
 */
public abstract class ConsoleConfigure {
    private static final String PROPERTIES_PATH = "com/bstek/dorado/console/configure.properties";
    private static final Log logger = LogFactory.getLog(ConsoleConfigure.class);
    @SuppressWarnings("rawtypes")
    private static Map map;
    static {
        Properties properties = new Properties();
        map = properties;
        InputStream in = ConsoleConfigure.class.getClassLoader().getResourceAsStream(PROPERTIES_PATH);
        Assert.notNull(in, "Can not found resource \"" + PROPERTIES_PATH + "\"!");
        try {
            properties.load(in);
        } catch (IOException e) {
            logger.error(e, e);
        }
    }

    public static Object get(String key) {
        return map.get(key);

    }

    /**
     * String???
     * 
     * @param key
     *            ???
     */
    public static String getString(String key) {
        Object value = get(key);
        return (value == null) ? null : value.toString();
    }

    /**
     * boolean???
     * 
     * @param key
     *            ???
     */
    public static boolean getBoolean(String key) {
        Object value = get(key);
        return (value instanceof Boolean) ? ((Boolean) value).booleanValue()
                : BooleanUtils.toBoolean((value == null) ? null : value.toString());
    }

    /**
     * long???
     * 
     * @param key
     *            ???
     */
    public static long getLong(String key) {
        Object value = get(key);
        return (value instanceof Number) ? ((Number) value).longValue()
                : Long.parseLong((value == null) ? null : value.toString());
    }

}