protected boolean validateCondition ( String key , String value ) { boolean valid = false ; FaxClientSpiConfigurationConstants condition = FaxClientSpiConfigurationConstants . getEnum ( key ) ; String propertyValue = null ; switch ( condition ) { case PROPERTY_CONDITION : //get value propertyValue = this . getConfigurationValue ( value ) ; if ( propertyValue != null ) { valid = true ; } break ; case OS_CONDITION : //get OS name String osName = System . getProperty ( "os.name" ) ; //change values to lower case osName = osName . toLowerCase ( ) ; String updatedValue = value . toLowerCase ( ) ; if ( osName . contains ( updatedValue ) ) { valid = true ; } break ; case JAVA_CLASS_CONDITION : try { //load class ReflectionHelper . getType ( value ) ; valid = true ; } catch ( Throwable throwable ) { //ignore } break ; case NATIVE_LIB_CONDITION : try { //load library System . loadLibrary ( value ) ; valid = true ; } catch ( Throwable throwable ) { //ignore } break ; case EXECUTABLE_CONDITION : //get system path String systemPath = System . getProperty ( "java.library.path" ) ; String [ ] systemPathElements = systemPath . split ( System . getProperty ( "path.separator" ) ) ; //get amount int amount = systemPathElements . length ; String directoryPath = null ; File file = null ; for ( int index = 0 ; index < amount ; index ++ ) { //get next element directoryPath = systemPathElements [ index ] ; //get file file = new File ( directoryPath , value ) ; if ( ( file . exists ( ) ) && ( file . isFile ( ) ) ) { valid = true ; } } break ; case STABLE_CONDITION : //get property key String propertyKey = FaxClientSpiConfigurationConstants . SPI_STABLE_PROPERTY_KEY_PREFIX + value + FaxClientSpiConfigurationConstants . SPI_STABLE_PROPERTY_KEY_SUFFIX ; //get value propertyValue = this . getConfigurationValue ( propertyKey ) ; valid = Boolean . parseBoolean ( propertyValue ) ; break ; default : throw new FaxException ( "Invalid condition key provided: " + key ) ; } return valid ; }
Validates the SPI condition .