package config; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import com.amarsoft.are.ARE; /** * 接口配置数据管理 * @author EX-YANGSONG001 * */ public class InterfaceConfig{ public static final String MESSAGE_RESOURCE_BASE = "config"; /** * EOA接口配置文件 */ public static String EOA_CONFIG_FILE = "EOASetting.properties"; /** * 影像接口配置文件 */ public static String IM_CONFIG_FILE = "IMClient.properties"; /** * 邮件接口配置文件 */ public static String MAIL_CONFIG_FILE = "MailClient.properties"; /** * 投管中心接口配置文件 */ public static String NCMS_CONFIG_FILE = "NcmsSetting.properties"; /** * UM/SSO接口配置文件 */ public static String UMSSO_CONFIG_FILE = "UMSSO.properties"; private static Properties eoaProperties = null; private static Properties imProperties = null; private static Properties mailProperties = null; private static Properties ncmsProperties = null; private static Properties umssoProperties = null; private static Properties getProperties(String file){ //根据客户要求,需要分离配置文件到独立的目录中,配置文件目录会被添加到CLASSPATH中 //因此,先直接去读配置文件,如果读不到,则最终到配置目录config下去读 InputStream in = InterfaceConfig.class.getClassLoader().getResourceAsStream(file); Properties properties = new Properties(); if(in==null){ ARE.getLog().error("从CLASSPATH读取不到配置文件["+file+"]"); // ARE.getLog().warn("从CLASSPATH读取不到配置文件["+file+"],使用默认配置"); // in = InterfaceConfig.class.getClassLoader().getResourceAsStream(MESSAGE_RESOURCE_BASE+"/"+file); } try { properties.load(in); } catch (IOException e) { ARE.getLog().error("配置目录下读配置文件["+file+"]出错", e); }finally{ if(in!=null) try { in.close(); } catch (IOException e) { } } return properties; } /** * EOA配置项获取 * @param name * @return */ public static String getEOAConfigItem(String name){ if(eoaProperties==null)eoaProperties=getProperties(EOA_CONFIG_FILE); return eoaProperties.getProperty(name); } /** * 获取IM配置数据 * @param name * @return */ public static String getIMConfigItem(String name){ if(imProperties==null)imProperties=getProperties(IM_CONFIG_FILE); return imProperties.getProperty(name); } /** * 邮件配置数据 * @param name * @return */ public static String getMailConfigItem(String name){ if(mailProperties==null)mailProperties=getProperties(MAIL_CONFIG_FILE); return mailProperties.getProperty(name); } /** * NCMS配置数据 * @param name * @return */ public static String getNCMSConfigItem(String name){ if(ncmsProperties==null)ncmsProperties=getProperties(NCMS_CONFIG_FILE); return ncmsProperties.getProperty(name); } /** * UMSSO配置数据 * @param name * @return */ public static String getUMSSOConfigItem(String name){ if(umssoProperties==null)umssoProperties=getProperties(UMSSO_CONFIG_FILE); return umssoProperties.getProperty(name); } }