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

📄 defaultlogpropertyhandler.java

📁 intra_mart是日本NDD公司开发的著名企业应用解决方案中间件。集成了J2ee服务器
💻 JAVA
字号:
/*
 * DefaultLogPropertyHandler.java
 *
 * Created on 2003/07/10, 19:20
 */

package jp.co.intra_mart.framework.system.log;

import java.util.Enumeration;
import java.util.Vector;
import java.util.ResourceBundle;

import jp.co.intra_mart.framework.system.property.PropertyParam;

import java.util.MissingResourceException;

import jp.co.intra_mart.framework.system.property.PropertyHandlerException;

/**
 * 儘僌偵娭楢偡傞僨僼僅儖僩偺僾儘僷僥傿僴儞僪儔偱偡丅
 * 僾儘僷僥傿偺愝掕撪梕偼埲壓偺偲偍傝偱偡丅
 * <TABLE border="1">
 *  <TR>
 *      <TH>僉乕</TH>
 *      <TH>撪梕</TH>
 *  </TR>
 *  <TR>
 *      <TD>agent.class</TD>
 *      <TD>{@link LogAgent}偺僋儔僗柤</TD>
 *  </TR>
 *  <TR>
 *      <TD>agent.param.<I>僷儔儊乕僞柤</I></TD>
 *      <TD>儘僌僄乕僕僃儞僩偵搉偡僷儔儊乕僞</TD>
 *  </TR>
 * </TABLE>
 *
 * @author INTRAMART
 * @since 4.2
 */
public class DefaultLogPropertyHandler implements LogPropertyHandler {

    /**
     * 僨僼僅儖僩偺儕僜乕僗僶儞僪儖柤
     */
    public static final String DEFAULT_BUNDLE_NAME = "LogConfig";

    /**
     * 儕僜乕僗僶儞僪儖柤偺僷儔儊乕僞柤
     */
    public static final String DEFAULT_BUNDLE_NAME_PARAM = "bundle";

    /**
     * 儘僌儕僜乕僗忣曬偑愝掕偝傟偰偄傞儕僜乕僗僶儞僪儖
     */
    private ResourceBundle bundle;

    /**
     * DefaultLogPropertyHandler傪怴婯偵惗惉偟傑偡丅
     */
    public DefaultLogPropertyHandler() {
        this.bundle = null;
    }

    /**
     * 僾儘僷僥傿僴儞僪儔傪弶婜壔偟傑偡丅
     *
     * @param params 弶婜僷儔儊乕僞
     * @throws PropertyHandlerException 僾儘僷僥傿僴儞僪儔偺弶婜壔帪偵椺奜偑敪惗
     */
    public void init(PropertyParam[] params) throws PropertyHandlerException {
        String bundleName = null;

        if (params != null) {
            for (int i = 0; i < params.length; i++) {
                if (params[i].getName().equals(DEFAULT_BUNDLE_NAME_PARAM)) {
                    bundleName = params[i].getValue();
                }
            }
        }
        if (bundleName == null) {
            bundleName = DEFAULT_BUNDLE_NAME;
        }

        this.bundle = ResourceBundle.getBundle(bundleName);
    }

    /**
     * 儘僌僄乕僕僃儞僩偺僋儔僗柤傪庢摼偟傑偡丅
     * 壗傕愝掕偝傟偰偄側偄応崌null偑曉傝傑偡丅
     *
     * @return 儘僌僄乕僕僃儞僩偺僋儔僗柤乮愝掕偝傟偰偄側偄応崌null乯
     * @throws LogPropertyException 儘僌僄乕僕僃儞僩偺僋儔僗柤偺庢摼帪偵椺奜偑敪惗
     */
    public String getLogAgentName() throws LogPropertyException {
        String name;

        try {
            name = this.bundle.getString("agent.class");
        } catch (MissingResourceException e) {
            name = null;
        } catch (Throwable e) {
            String message = null;
            try {
                message =ResourceBundle.getBundle("jp.co.intra_mart.framework.system.log.i18n").getString("DefaultLogPropertyHandler.FailedToGetAgent");
            } catch (MissingResourceException ex) {
            }
            throw new LogPropertyException(message, e);
        }

        return name;
    }

    /**
     * 儘僌僄乕僕僃儞僩偺僷儔儊乕僞傪庢摼偟傑偡丅
     * 壗傕愝掕偝傟偰偄側偄応崌戝偒偝偑0偺攝楍偑曉傝傑偡丅
     *
     * @return 儘僌僄乕僕僃儞僩偺僷儔儊乕僞偺攝楍
     * @throws LogPropertyException 儘僌僄乕僕僃儞僩偺僷儔儊乕僞偺庢摼帪偵椺奜偑敪惗
     */
    public LogAgentParam[] getLogAgentParams() throws LogPropertyException {
        Enumeration keys = null;
        String key = null;
        String value = null;
        LogAgentParam param = null;
        LogAgentParam[] params = null;
        Vector temp = new Vector();

        keys = this.bundle.getKeys();
        while (keys.hasMoreElements()) {
            key = (String)keys.nextElement();
            if (key.startsWith("agent.param")) {
                value = this.bundle.getString(key);
                param = new LogAgentParam();
                param.setName(key);
                param.setValue(value);
                temp.add(param);
            }
        }
        params = new LogAgentParam[temp.size()];
        for (int i = 0; i < temp.size(); i++) {
            params[i] = (LogAgentParam)temp.elementAt(i);
        }

        return params;
    }
}

⌨️ 快捷键说明

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