com.cisco.oss.foundation.configuration
Class ConfigUtil

java.lang.Object
  extended by com.cisco.oss.foundation.configuration.ConfigUtil

public final class ConfigUtil
extends Object

Simple utility class useful for handling the common configuration framework.

Author:
Joel Gurfinkel

Method Summary
static org.apache.commons.configuration.Configuration createCompositeConfiguration(Class<?> clazz, org.apache.commons.configuration.Configuration configuration)
          create a composite configuration that wraps the configuration sent by the user.
static void disableCcp()
           
static void enableCcp(String componentName, String componentVersion, String installPath, String compoentHostName, String ccpServerHostName)
           
static void enableCcp(String componentName, String componentVersion, String installPath, String compoentHostName, String ccpServerHostName, int ccpServerPort)
           
static boolean equalValues(Object o1, Object o2)
           
static org.apache.commons.configuration.HierarchicalConfiguration getHierarchicalConfiguration(org.apache.commons.configuration.Configuration configuration)
          returns the hierarchical part of a configuration
static URL getResource(String fileName)
           
static InputStream getResourceAsStream(String fileName)
           
static String getResourcePath(String fileName)
           
static boolean isEmpty(Object value)
           
static boolean isEmpty(String value)
           
static boolean isHexadecimal(String value)
          return if the given string is a valid hexadecimal string
static boolean isNumeric(String value)
           
static boolean isNumeric(String value, int startIndex, int endIndex)
           
static Map<String,Map<String,String>> parseComplexArrayStructure(String configPrefix)
          Parse a complex array structure and return it as a map containing maps as values for further internal structures
Example of configuration we support: smartcardAdaptor.cardFeatures.1.cardFamily=VGE smartcardAdaptor.cardFeatures.1.supportSbm=true smartcardAdaptor.cardFeatures.1.maxSbmBlocks=16 smartcardAdaptor.cardFeatures.1.sbmMSB.0=0x00 smartcardAdaptor.cardFeatures.1.sbmMSB.1=0x01 smartcardAdaptor.cardFeatures.1.maxRegions=4 smartcardAdaptor.cardFeatures.1.initialCounter=1000 smartcardAdaptor.cardFeatures.1.maxNumOfOPPVs=25 smartcardAdaptor.cardFeatures.23.cardFamily=VGE smartcardAdaptor.cardFeatures.23.supportSbm=true smartcardAdaptor.cardFeatures.23.maxSbmBlocks=16 smartcardAdaptor.cardFeatures.23.sbmMSB.0=0x00 smartcardAdaptor.cardFeatures.23.sbmMSB.1=0x01 smartcardAdaptor.cardFeatures.23.maxRegions=4 smartcardAdaptor.cardFeatures.23.initialCounter=1000 smartcardAdaptor.cardFeatures.23.maxNumOfOPPVs=25
Will return a map where key is 1, 23 and values are the key/value pairs the follow the key.
static Map<String,String> parseSimpleArrayAsMap(org.apache.commons.configuration.Configuration configuration, String configPrefix)
           
static Map<String,String> parseSimpleArrayAsMap(String configPrefix)
          parse an simple array and return it as a Map.
static Double toNumber(String value)
           
static Double toNumber(String value, int startIndex, int endIndex)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getHierarchicalConfiguration

public static org.apache.commons.configuration.HierarchicalConfiguration getHierarchicalConfiguration(org.apache.commons.configuration.Configuration configuration)
returns the hierarchical part of a configuration

Parameters:
configuration - the given configuration
Returns:
the hierarchical configuration or null if not found in the given configuration object.

createCompositeConfiguration

public static org.apache.commons.configuration.Configuration createCompositeConfiguration(Class<?> clazz,
                                                                                          org.apache.commons.configuration.Configuration configuration)
create a composite configuration that wraps the configuration sent by the user. this util will also load the "defaultConfig.properties" file loaded relative to the given "clazz" parameter

Parameters:
clazz - - the class that acts as referenced location of "defaultConfig.properties".
configuration - - the configuration supplied by the user that may override values in "defaultConfig.properties". If null is ignored.
Returns:
the created compsite configuration.

enableCcp

public static void enableCcp(String componentName,
                             String componentVersion,
                             String installPath,
                             String compoentHostName,
                             String ccpServerHostName)

enableCcp

public static void enableCcp(String componentName,
                             String componentVersion,
                             String installPath,
                             String compoentHostName,
                             String ccpServerHostName,
                             int ccpServerPort)

disableCcp

public static void disableCcp()

parseComplexArrayStructure

public static Map<String,Map<String,String>> parseComplexArrayStructure(String configPrefix)
Parse a complex array structure and return it as a map containing maps as values for further internal structures
Example of configuration we support: smartcardAdaptor.cardFeatures.1.cardFamily=VGE smartcardAdaptor.cardFeatures.1.supportSbm=true smartcardAdaptor.cardFeatures.1.maxSbmBlocks=16 smartcardAdaptor.cardFeatures.1.sbmMSB.0=0x00 smartcardAdaptor.cardFeatures.1.sbmMSB.1=0x01 smartcardAdaptor.cardFeatures.1.maxRegions=4 smartcardAdaptor.cardFeatures.1.initialCounter=1000 smartcardAdaptor.cardFeatures.1.maxNumOfOPPVs=25 smartcardAdaptor.cardFeatures.23.cardFamily=VGE smartcardAdaptor.cardFeatures.23.supportSbm=true smartcardAdaptor.cardFeatures.23.maxSbmBlocks=16 smartcardAdaptor.cardFeatures.23.sbmMSB.0=0x00 smartcardAdaptor.cardFeatures.23.sbmMSB.1=0x01 smartcardAdaptor.cardFeatures.23.maxRegions=4 smartcardAdaptor.cardFeatures.23.initialCounter=1000 smartcardAdaptor.cardFeatures.23.maxNumOfOPPVs=25
Will return a map where key is 1, 23 and values are the key/value pairs the follow the key.
E.g Map - key = 1, value= Map(cardFamily -> VGE, supportSbm ->true) etc.


parseSimpleArrayAsMap

public static Map<String,String> parseSimpleArrayAsMap(String configPrefix)
parse an simple array and return it as a Map. Can be used in conjunction with ConfigUtil#parseComplexArrayStructure(String)

Parameters:
configPrefix - the prefix that is the basis of the array. E.g. given: smartcardAdaptor.cardFeatures.23.sbmMSB.0=0x00 smartcardAdaptor.cardFeatures.23.sbmMSB.1=0x01 the config prefix will be: smartcardAdaptor.cardFeatures.23.sbmMSB
Returns:
the Map where the index is the key and the value is the value.

parseSimpleArrayAsMap

public static Map<String,String> parseSimpleArrayAsMap(org.apache.commons.configuration.Configuration configuration,
                                                       String configPrefix)

isNumeric

public static boolean isNumeric(String value)

isNumeric

public static boolean isNumeric(String value,
                                int startIndex,
                                int endIndex)

isEmpty

public static boolean isEmpty(Object value)

isEmpty

public static boolean isEmpty(String value)

isHexadecimal

public static boolean isHexadecimal(String value)
return if the given string is a valid hexadecimal string


toNumber

public static Double toNumber(String value)

toNumber

public static Double toNumber(String value,
                              int startIndex,
                              int endIndex)

equalValues

public static boolean equalValues(Object o1,
                                  Object o2)

getResource

public static URL getResource(String fileName)

getResourcePath

public static String getResourcePath(String fileName)

getResourceAsStream

public static InputStream getResourceAsStream(String fileName)


Copyright © 2014 Cisco. All Rights Reserved.