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

📄 resourcebundleeventpropertyhandlerutil.java

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

package jp.co.intra_mart.framework.base.event;

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

import java.util.MissingResourceException;

/**
 * 巜掕偝傟偨儕僜乕僗僶儞僪儖偐傜僀儀儞僩僾儘僷僥傿傪庢摼偡傞儐乕僥傿儕僥傿偱偡丅
 *
 * @author INTRAMART
 * @since 3.2
 */
class ResourceBundleEventPropertyHandlerUtil {

    /**
     * 僉乕偵奩摉偡傞僀儀儞僩偺僋儔僗柤傪庢摼偟傑偡丅
     * 奩摉偡傞僀儀儞僩偑懚嵼偟側偄応崌丄null傪曉偟傑偡丅
     *
     * @param applicationBundle 傾僾儕働乕僔儑儞偺儕僜乕僗僶儞僪儖
     * @param application 傾僾儕働乕僔儑儞
     * @param key 僀儀儞僩偺僉乕
     * @return 僀儀儞僩偺僋儔僗柤
     * @throws EventPropertyException 僀儀儞僩偺僋儔僗柤偺庢摼偵幐攕
     */
    public static String getEventName(
        ResourceBundle applicationBundle,
        String application,
        String key)
        throws EventPropertyException {

        String name = null;

        try {
            name = applicationBundle.getString("event.class." + key);
        } catch (MissingResourceException e) {
            name = null;
        }

        return name;
    }

    /**
     * 僉乕偵奩摉偡傞僀儀儞僩儕僗僫僼傽僋僩儕偺僋儔僗柤傪庢摼偟傑偡丅
     *
     * @param applicationBundle 傾僾儕働乕僔儑儞偺儕僜乕僗僶儞僪儖
     * @param application 傾僾儕働乕僔儑儞
     * @param key 僀儀儞僩儕僗僫僼傽僋僩儕偺僉乕
     * @return 僀儀儞僩儕僗僫僼傽僋僩儕偺僋儔僗柤
     * @throws EventPropertyException 僀儀儞僩儕僗僫僼傽僋僩儕偺僋儔僗柤偺庢摼偵幐攕
     */
    public static String getEventListenerFactoryName(
        ResourceBundle applicationBundle,
        String application,
        String key)
        throws EventPropertyException {

        String name;

        try {
            name = applicationBundle.getString("factory.class." + key);
        } catch (MissingResourceException e) {
            String message = null;
            try {
                message =
                    ResourceBundle
                        .getBundle("jp.co.intra_mart.framework.base.event.i18n")
                        .getString("ResourceBundleEventPropertyHandlerUtil.FailedToGetFactory");
            } catch (MissingResourceException ex) {
            }
            throw new EventPropertyException(
                message + " : application = " + application + ", key = " + key,
                e);
        }
        if (name == null || name.trim().equals("")) {
            String message = null;
            try {
                message =
                    ResourceBundle
                        .getBundle("jp.co.intra_mart.framework.base.event.i18n")
                        .getString("ResourceBundleEventPropertyHandlerUtil.FacotryClassNotDeclared");
            } catch (MissingResourceException e) {
            }
            throw new EventPropertyException(
                message + " : application = " + application + ", key = " + key);
        }

        return name;
    }

    /**
     * 僉乕偵奩摉偡傞僀儀儞僩儕僗僫僼傽僋僩儕偺弶婜僷儔儊乕僞傪庢摼偟傑偡丅
     *
     * @param applicationBundle 傾僾儕働乕僔儑儞偺儕僜乕僗僶儞僪儖
     * @param application 傾僾儕働乕僔儑儞
     * @param key 僀儀儞僩偺僉乕
     * @return 僀儀儞僩儕僗僫僼傽僋僩儕偺弶婜僷儔儊乕僞
     * @throws EventPropertyException 僀儀儞僩儕僗僫僼傽僋僩儕偺弶婜僷儔儊乕僞偺庢摼偵幐攕
     */
    public static EventListenerFactoryParam[] getEventListenerFactoryParams(
        ResourceBundle applicationBundle,
        String application,
        String key)
        throws EventPropertyException {

        Vector params = new Vector();
        String prefix = "factory.param." + key + ".";
        String propertyName;
        EventListenerFactoryParam[] result;
        Enumeration enum;
        EventListenerFactoryParam param;

        enum = applicationBundle.getKeys();
        while (enum.hasMoreElements()) {
            propertyName = (String)enum.nextElement();
            if (propertyName.startsWith(prefix)) {
                param = new EventListenerFactoryParam();
                param.setName(propertyName.substring(prefix.length()));
                try {
                    param.setValue(applicationBundle.getString(propertyName));
                } catch (MissingResourceException e) {
                    String message = null;
                    try {
                        message =
                            ResourceBundle
                                .getBundle("jp.co.intra_mart.framework.base.event.i18n")
                                .getString("ResourceBundleEventPropertyHandlerUtil.FailedToGetFactoryParameter");
                    } catch (MissingResourceException ex) {
                    }
                    throw new EventPropertyException(
                        message
                            + " : application = "
                            + application
                            + ", key = "
                            + key,
                        e);
                }
                params.add(param);
            }
        }
        result = new EventListenerFactoryParam[params.size()];
        for (int i = 0; i < result.length; i++) {
            result[i] = (EventListenerFactoryParam)params.elementAt(i);
        }

        return result;
    }

    /**
     * 僉乕偵奩摉偡傞僀儀儞僩偺僀儀儞僩僩儕僈忣曬傪偡傋偰庢摼偟傑偡丅
     * <CODE>application</CODE>偲<CODE>key</CODE>偱掕媊偝傟傞{@link EventTrigger}傪掕媊偝傟偨弴斣偱僜乕僩偟偨Collection偲偟偰庢摼偟傑偡丅
     *
     * @param applicationBundle 傾僾儕働乕僔儑儞偺儕僜乕僗僶儞僪儖
     * @param application 傾僾儕働乕僔儑儞
     * @param key 僀儀儞僩偺僉乕
     * @return 僀儀儞僩僩儕僈忣曬偺僐儗僋僔儑儞
     * @throws EventPropertyException 僀儀儞僩僩儕僈忣曬偺庢摼偵幐攕
     * @see EventListener
     */
    public static Collection getEventTriggerInfos(
        ResourceBundle applicationBundle,
        String application,
        String key)
        throws EventPropertyException {

        Enumeration enum = null;
        EventTriggerInfo info = null;
        TreeMap infos = new TreeMap();
        ResourceBundle targetBundle = null;
        String prefix = "trigger.class." + key + ".";
        String resourceKey = null;
        String name = null;
        String option = null;
        int num = 0;

        // 儕僜乕僗偐傜偡傋偰偺僉乕傪庢摼偡傞
        enum = applicationBundle.getKeys();

        // 僀儀儞僩僩儕僈偺僉乕偵奩摉偡傞僾儘僷僥傿偡傋偰偵懳偟偰孞傝曉偟張棟傪偡傞
        while (enum.hasMoreElements()) {
            resourceKey = (String)enum.nextElement();
            if (resourceKey.startsWith(prefix)) {
                int period = resourceKey.indexOf(".", prefix.length() + 1);

                // 僜乕僩斣崋傪庢摼偡傞
                if (period != -1) {
                    if (resourceKey.substring(period).equals(".pre")) {
                        num =
                            Integer.parseInt(
                                resourceKey.substring(
                                    prefix.length(),
                                    resourceKey.length() - ".pre".length()));
                    } else {
                        continue;
                    }
                } else {
                    num =
                        Integer.parseInt(
                            resourceKey.substring(prefix.length()));
                }
                info = new EventTriggerInfo();

                // 僜乕僩斣崋傪愝掕偡傞
                info.setNumber(num);

                // 僀儀儞僩僩儕僈偺僋儔僗柤傪愝掕偡傞
                try {
                    name = applicationBundle.getString(resourceKey);
                } catch (MissingResourceException e) {
                    String message = null;
                    try {
                        message =
                            ResourceBundle
                                .getBundle("jp.co.intra_mart.framework.base.event.i18n")
                                .getString("ResourceBundleEventPropertyHandlerUtil.FailedToGetTrigger");
                    } catch (MissingResourceException ex) {
                    }
                    throw new EventPropertyException(
                        message
                            + " : application = "
                            + application
                            + ", key = "
                            + key,
                        e);
                }
                if (name == null || name.equals("")) {
                    // 僀儀儞僩僩儕僈柤傪庢摼偱偒側偄応崌椺奜傪throw
                    String message = null;
                    try {
                        message =
                            ResourceBundle
                                .getBundle("jp.co.intra_mart.framework.base.event.i18n")
                                .getString("ResourceBundleEventPropertyHandlerUtil.TriggerNotDeclared");
                    } catch (MissingResourceException ex) {
                    }
                    throw new EventPropertyException(
                        message
                            + " : application = "
                            + application
                            + ", key = "
                            + key);
                }
                info.setName(name);

                // 僀儀儞僩僩儕僈忣曬傪捛壛偡傞
                infos.put(new Integer(num), info);
            }
        }

        return infos.values();
    }

    /**
     * 僉乕偵奩摉偡傞僀儀儞僩偺僀儀儞僩僩儕僈忣曬傪偡傋偰庢摼偟傑偡丅
     * <CODE>application</CODE>偲<CODE>key</CODE>偱掕媊偝傟傞{@link EventTrigger}傪掕媊偝傟偨弴斣偱僜乕僩偟偨Collection偲偟偰庢摼偟傑偡丅
     *
     * @param applicationBundle 傾僾儕働乕僔儑儞偺儕僜乕僗僶儞僪儖
     * @param application 傾僾儕働乕僔儑儞
     * @param key 僀儀儞僩偺僉乕
     * @return 僀儀儞僩僩儕僈忣曬偺僐儗僋僔儑儞
     * @throws EventPropertyException 僀儀儞僩僩儕僈忣曬偺庢摼偵幐攕
     * @see EventListener
     */
    public static Collection getPostEventTriggerInfos(
        ResourceBundle applicationBundle,
        String application,
        String key)
        throws EventPropertyException {

        Enumeration enum = null;
        EventTriggerInfo info = null;
        TreeMap infos = new TreeMap();
        ResourceBundle targetBundle = null;
        String prefix = "trigger.class." + key + ".";
        String resourceKey = null;
        String name = null;
        String option = null;
        int num = 0;

        // 儕僜乕僗偐傜偡傋偰偺僉乕傪庢摼偡傞
        enum = applicationBundle.getKeys();

        // 僀儀儞僩僩儕僈偺僉乕偵奩摉偡傞僾儘僷僥傿偡傋偰偵懳偟偰孞傝曉偟張棟傪偡傞
        while (enum.hasMoreElements()) {
            resourceKey = (String)enum.nextElement();
            if (resourceKey.startsWith(prefix)) {
                int period = resourceKey.indexOf(".", prefix.length() + 1);

                // 僜乕僩斣崋傪庢摼偡傞
                if (period != -1) {
                    if (resourceKey.substring(period).equals(".post")) {
                        num =
                            Integer.parseInt(
                                resourceKey.substring(
                                    prefix.length(),
                                    resourceKey.length() - ".post".length()));
                    } else {
                        continue;
                    }
                } else {
                    continue;
                }
                info = new EventTriggerInfo();

                // 僜乕僩斣崋傪愝掕偡傞
                info.setNumber(num);

                // 僀儀儞僩僩儕僈偺僋儔僗柤傪愝掕偡傞
                try {
                    name = applicationBundle.getString(resourceKey);
                } catch (MissingResourceException e) {
                    String message = null;
                    try {
                        message =
                            ResourceBundle
                                .getBundle("jp.co.intra_mart.framework.base.event.i18n")
                                .getString("ResourceBundleEventPropertyHandlerUtil.FailedToGetTrigger");
                    } catch (MissingResourceException ex) {
                    }
                    throw new EventPropertyException(
                        message
                            + " : application = "
                            + application
                            + ", key = "
                            + key,
                        e);
                }
                if (name == null || name.equals("")) {
                    // 僀儀儞僩僩儕僈柤傪庢摼偱偒側偄応崌椺奜傪throw
                    String message = null;
                    try {
                        message =
                            ResourceBundle
                                .getBundle("jp.co.intra_mart.framework.base.event.i18n")
                                .getString("ResourceBundleEventPropertyHandlerUtil.TriggerNotDeclared");
                    } catch (MissingResourceException ex) {
                    }
                    throw new EventPropertyException(
                        message
                            + " : application = "
                            + application
                            + ", key = "
                            + key);
                }
                info.setName(name);

                // 僀儀儞僩僩儕僈忣曬傪捛壛偡傞
                infos.put(new Integer(num), info);
            }
        }

        return infos.values();
    }
}

⌨️ 快捷键说明

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