public class Configuration { public final static String DEF_CATTP_VERSION = "cardprofile.default_CATTP_version"; private final static Logger logger = Logger.getLogger (Configuration.class); private final static String DEFAULT_CONFIGURATION_FILE_PATH = "/migration.properties"; public static Properties props; public static synchronized Configuration getInstance(){ if(instance==null){ props = new Properties(); instance = new Configuration(); try{ props.load(Configuration.class.getResourceAsStream (DEFAULT_CONFIGURATION_FILE_PATH)); }catch(IOException e){ logger.error(e,e); } } return instance; } //parameter format :xx=xx public static synchronized Configuration getInstance(final String[] args){ if(instance == null){ props = new Properties(); instance = new Configuration(); } //first load the default config try{ props.load(Configuration.class.getClass ().getResourceAsStream (DEFAULT_CONFIGURATION_FILE_PATH)); }catch (final IOException e){ logger.error(e, e); } //go through the command line arguments and override the default config for(final String arg:args){ parseArgument(arg); } return instance; } /** * Default constructor */ public Configuration (final String[] args) { props = new Properties (); // First load the default config try { props.load (this.getClass ().getResourceAsStream (DEFAULT_CONFIGURATION_FILE_PATH)); } catch (final IOException e) { logger.error (e, e); } // Go through the command line arguments, and override the default config for (final String arg: args) { parseArgument (arg); } instance = this; } public Configuration() { // TODO Auto-generated constructor stub } private static void parseArgument (final String argument) { final String[] splitArg = argument.split ("="); if (splitArg.length != 2) { logger.warn ("Command line argument using wrong format: " + argument); } else { props.put (splitArg[0], splitArg[1]); } } /** * Returns the {@link String} value of a configuration parameter. This is the default value form * when read from the configuration file. * * @param name The name of the value to return * @return the value from the map */ public String getValue (final String name) { return props.getProperty (name); } /** * Add a value to the configuration map * * @param name Name of the new value * @param value Value to insert */ public void putValue (final String name, final Object value) { props.put (name, value); } /** * Returns a value, converted to {@link Integer} * * @param name the name of the configuration value * @return converted value */ public Integer getIntValue (final String name) { return Integer.parseInt (props.getProperty (name)); } /** * Returns a value converted to {@link Long} * * @param name the name of the configuration value * @return converted value */ public Long getLongValue (final String name) { return Long.parseLong (props.getProperty (name)); } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString () { String configPart = ""; for (final Iterator<Entry<Object, Object>> it = props.entrySet ().iterator (); it.hasNext ();) { final Entry<Object, Object> entry = it.next (); configPart += entry.getKey () + "=" + entry.getValue (); if (it.hasNext ()) { configPart += ", "; } } return "Configurations [" + configPart + "]"; } }
public class OTAManagerConnector { private final String USER_NAME; private final String USER_PASSWORD; private final String RCA_PRODUCT_NAME; private final String OSAGENT_ADDRESS; private final String OSAGENT_PROT; private platformaccesspoint platform; private CardManagerAccessPoint cardManagerAccessPoint = null; private CardManagementFacility cardManagementFacility = null; private static OTAManagerConnector instance = null; private OTAManagerConnector () throws Exception { USER_NAME = Configuration.getInstance ().getValue (Configuration.OTAM_PLATFORM_USERNAME); USER_PASSWORD = Configuration.getInstance () .getValue (Configuration.OTAM_PLATFORM_PASSWORD); RCA_PRODUCT_NAME = Configuration.getInstance ().getValue ( Configuration.OTAM_PLATFORM_PRODUCT_NAME); OSAGENT_ADDRESS = Configuration.getInstance ().getValue ( Configuration.OTAM_PLATFORM_OSAGENT_ADDRESS); OSAGENT_PROT = Configuration.getInstance ().getValue ( Configuration.OTAM_PLATFORM_OSAGENT_PORT); initParameter (); authenticate (); } public static synchronized OTAManagerConnector getInstance () throws Exception { if (instance == null) { instance = new OTAManagerConnector (); } return instance; } public CardProfileLoader getCardProfileLoader () throws Exception { return cardManagementFacility.getCardProfileLoader (); } private void authenticate () throws Exception { final PlatformCheckPoint pltfCheckPoint = PlatformCheckPoint.instance (); final Authenticator auth = pltfCheckPoint.identify (USER_NAME); ((PasswordAuthenticator)auth).setPassword (USER_PASSWORD); platform = pltfCheckPoint.grant (auth); cardManagerAccessPoint = (CardManagerAccessPoint)platform.getProductAccessPoint ( CardManagerAccessPoint.class, RCA_PRODUCT_NAME); cardManagementFacility = cardManagerAccessPoint.getCardManagementFacility (); } private void initParameter () { System.setProperty ("gxs.invocationmanager.name", RCA_PRODUCT_NAME); System.setProperty ("gxs.product.name", RCA_PRODUCT_NAME); System.setProperty ("vbroker.agent.port", OSAGENT_PROT); System.setProperty ("vbroker.agent.addr", OSAGENT_ADDRESS); } }
public class Configuration { public static final String OTAA_DATABASE_URL = "otaa.database.url"; public static final String OTAA_DATABASE_USERNAME = "otaa.database.username"; public static final String OTAA_DATABASE_PASSWORD = "otaa.database.password"; public static final String ADF_TYPES = "ADFTypes"; public final static String ADF_ISIM_FileId = "ISIMFileId"; public final static String ADF_ISIM_Application_AID = "ISIMApplicationAID"; public final static String ADF_USIM_FileId = "USIMFileId"; public final static String ADF_USIM_Application_AID = "USIMApplicationAID"; public final static String ADF_CSIM_FileId = "CSIMFileId"; public final static String ADF_CSIM_Application_AID = "CSIMApplicationAID"; public final static String DEF_PLATFORM_TYPE = "carddefinition.default_platform_type"; public final static String DEF_PLATFORM_VERSION = "carddefinition.default_platform_version"; public final static String DEF_PLATFORM_OSTYPE = "carddefinition.default_platform_ostype"; public final static String DEF_PLATFORM_OSVERSION = "carddefinition.default_platform_osversion"; public final static String DEF_COMMERCIAL_NAME = "carddefinition.default_commercial_name"; public final static String DEF_CHIP_RAM_SIZE = "carddefinition.defalut_chip_ram_size"; public final static String DEF_CHIP_ROM_SIZE = "carddefinition.defalut_chip_rom_size"; public final static String DEF_FLASH_SIZE = "carddefinition.default_flash_size"; public final static String DEF_CARD_TYPE = "cardprofile.default_card_type"; public final static String DEF_FREE_RAM_SIZE = "cardprofile.default_free_ram_size"; public final static String DEF_FREE_EEPROM_SIZE = "cardprofile.default_free_eeprom_size"; public final static String DEF_FREE_FLASH_SIZE = "cardprofile.default_free_flash_size"; public final static String DEF_CATTP_VERSION = "cardprofile.default_CATTP_version"; private final static Logger logger = Logger.getLogger (Configuration.class); private final static String DEFAULT_CONFIGURATION_FILE_PATH = "/migration.properties"; public static Properties props; private static Configuration instance = null; public static synchronized Configuration getInstance () { if(instance == null){ props = new Properties(); instance = new Configuration(); try { props.load(Configuration.class.getResourceAsStream (DEFAULT_CONFIGURATION_FILE_PATH)); } catch (IOException e) { logger.error(e,e); } } return instance; } //parameter format :xx=xx public static synchronized Configuration getInstance(final String[] args){ if(instance == null){ props = new Properties(); instance = new Configuration(); } //first load the default config try{ props.load(Configuration.class.getClass ().getResourceAsStream (DEFAULT_CONFIGURATION_FILE_PATH)); }catch (final IOException e){ logger.error(e, e); } //go through the command line arguments and override the default config for(final String arg:args){ parseArgument(arg); } return instance; } /** * Default constructor */ public Configuration (final String[] args) { props = new Properties (); // First load the default config try { props.load (this.getClass ().getResourceAsStream (DEFAULT_CONFIGURATION_FILE_PATH)); } catch (final IOException e) { logger.error (e, e); } // Go through the command line arguments, and override the default config for (final String arg: args) { parseArgument (arg); } instance = this; } public Configuration() { // TODO Auto-generated constructor stub } private static void parseArgument (final String argument) { final String[] splitArg = argument.split ("="); if (splitArg.length != 2) { logger.warn ("Command line argument using wrong format: " + argument); } else { props.put (splitArg[0], splitArg[1]); } } /** * Returns the {@link String} value of a configuration parameter. This is the default value form * when read from the configuration file. * * @param name The name of the value to return * @return the value from the map */ public String getValue (final String name) { return props.getProperty (name); } /** * Add a value to the configuration map * * @param name Name of the new value * @param value Value to insert */ public void putValue (final String name, final Object value) { props.put (name, value); } /** * Returns a value, converted to {@link Integer} * * @param name the name of the configuration value * @return converted value */ public Integer getIntValue (final String name) { return Integer.parseInt (props.getProperty (name)); } /** * Returns a value converted to {@link Long} * * @param name the name of the configuration value * @return converted value */ public Long getLongValue (final String name) { return Long.parseLong (props.getProperty (name)); } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString () { String configPart = ""; for (final Iterator<Entry<Object, Object>> it = props.entrySet ().iterator (); it.hasNext ();) { final Entry<Object, Object> entry = it.next (); configPart += entry.getKey () + "=" + entry.getValue (); if (it.hasNext ()) { configPart += ", "; } } return "Configurations [" + configPart + "]"; } }
原文:http://www.cnblogs.com/cici-new/p/3687462.html