package com.vci.client.common; import java.util.LinkedHashMap; /** * 统一数据状态处类 *

Title:

*

Description:

*

Copyright: Copyright (c) 2012

*

Company: VCI

* @author xchao * @time 2013-3-19 * @version 1.0 */ public class DataStatusUtils { private static ThreadLocal threadLocal = new ThreadLocal(); public static DataStatusUtils getRMDataStatusUtils(){ return getDataStatusUtils("rm", "RMIPRm"); } public static DataStatusUtils getCodeDataStatusUtils(){ return getDataStatusUtils("code", "RMIPCode"); } private static DataStatusUtils getDataStatusUtils(String type, String il18FileName){ DataStatusUtils utils = threadLocal.get(); if(utils == null){ utils = new DataStatusUtils(type, il18FileName); threadLocal.set(utils); } return utils; } /** * 类别,RM\CODE */ private String type = ""; private String il18nName = ""; private DataStatusUtils(String type, String il18nName){ this.type = type; this.il18nName = il18nName; initStatus(); } private Integer[] supportStatus = new Integer[]{}; // key:状态值 value:状态名称 private LinkedHashMap statusToNameMap = new LinkedHashMap(); // key:状态名称 value状态值 private LinkedHashMap nameToStatusMap = new LinkedHashMap(); private void initStatus(){ reInitStatus(); } public void reInitStatus(){ // 从 指定名称的国际化文件取出状态总数 String[] statuss = ConfigUtils.getI18nString("rmip.code.status.support", il18nName).split(","); supportStatus = new Integer[statuss.length]; for (int i = 0; i < statuss.length; i++) { supportStatus[i] = Integer.valueOf(statuss[i]); } statusToNameMap.clear(); nameToStatusMap.clear(); for(int i = 0; i < supportStatus.length; i++){ Integer status = supportStatus[i]; // key format e.g //rmip.code.status.0 //rmip.code.status.1 String key = "rmip." + getType() + ".status." + status; String value = ConfigUtils.getI18nString(key, il18nName); statusToNameMap.put(status, value); nameToStatusMap.put(value, status); } } /** * 状态值(值范围:getSupportStatus()),返回对应状态的国际化名称 *

Description:

* * @author xchao * @time 2013-3-20 * @param statusValue 状态值 * @return */ public String getStatusNameByValue(Integer statusValue){ String res = String.valueOf(statusValue); if(statusToNameMap.containsKey(statusValue)){ res = statusToNameMap.get(statusValue); } return res; } /** * 根据状态的国际化名称,返回状态值(值范围:getSupportStatus()) *

Description:

* * @author xchao * @time 2013-3-20 * @param statusName 状态名称 * @return */ public Integer getStatusValueByName(String statusName){ Integer res = 0; if(nameToStatusMap.containsKey(statusName)){ res = nameToStatusMap.get(statusName); } return res; } public String getType() { return type; } public void setType(String type) { this.type = type; } public Integer[] getSupportStatus() { return supportStatus; } public void setSupportStatus(Integer[] supportStatus) { this.supportStatus = supportStatus; } public LinkedHashMap getStatusToNameMap() { return statusToNameMap; } public void setStatusToNameMap(LinkedHashMap statusToNameMap) { this.statusToNameMap = statusToNameMap; } public LinkedHashMap getNameToStatusMap() { return nameToStatusMap; } public void setNameToStatusMap(LinkedHashMap nameToStatusMap) { this.nameToStatusMap = nameToStatusMap; } }