ninja.utils
Interface NinjaProperties

All Known Implementing Classes:
NinjaPropertiesImpl

public interface NinjaProperties


Field Summary
static String CONF_FILE_LOCATION_BY_CONVENTION
          The default configuration.
static String NINJA_EXTERNAL_CONF
          Often you may want to use a seperate configuration file.
 
Method Summary
 String get(String key)
          Get a String property or null if it is not there...
 Properties getAllCurrentNinjaProperties()
           
 Boolean getBoolean(String key)
           
 Boolean getBooleanOrDie(String key)
          The "die" method forces this key to be set.
 Boolean getBooleanWithDefault(String key, Boolean defaultValue)
          Get a Boolean property or a default value when property cannot be found in any configuration file.
 Integer getInteger(String key)
          Get a property as Integer of null if not there / or property no integer
 Integer getIntegerOrDie(String key)
          The "die" method forces this key to be set.
 Integer getIntegerWithDefault(String key, Integer defaultValue)
          Get a Integer property or a default value when property cannot be found in any configuration file.
 String getOrDie(String key)
          The "die" method forces this key to be set.
 String[] getStringArray(String key)
          eg.
 String getWithDefault(String key, String defaultValue)
          Get a String property or a default value when property cannot be found in any configuration file.
 boolean isDev()
          Whether we are in dev mode
 boolean isProd()
          Whether we are in prod mode
 boolean isTest()
          Whether we are in test mode
 

Field Detail

NINJA_EXTERNAL_CONF

static final String NINJA_EXTERNAL_CONF
Often you may want to use a seperate configuration file. You can define the file to use in addition to your default config at conf/application.conf by setting NINJA_EXTERNAL_CONF as JVM system property. You must make sure that the specified file is on the classpath of the application. Eg servlet containers usually have a special directory that gets included into the classpath. That makes using different configurations for different environments quite simple. We don't use file IO to get the file because we would most likely run into security issues easily.

See Also:
Constant Field Values

CONF_FILE_LOCATION_BY_CONVENTION

static final String CONF_FILE_LOCATION_BY_CONVENTION
The default configuration. Make sure that file exists. Otherwise the application won't start up.

See Also:
Constant Field Values
Method Detail

get

String get(String key)
Get a String property or null if it is not there...

Parameters:
key -
Returns:
the property of null if not there

getWithDefault

String getWithDefault(String key,
                      String defaultValue)
Get a String property or a default value when property cannot be found in any configuration file.

Parameters:
key - the key used in the configuration file.
defaultValue - Default value returned, when value cannot be found in configuration.
Returns:
the value of the key or the default value.

getInteger

Integer getInteger(String key)
Get a property as Integer of null if not there / or property no integer

Parameters:
key -
Returns:
the property or null if not there or property no integer

getIntegerWithDefault

Integer getIntegerWithDefault(String key,
                              Integer defaultValue)
Get a Integer property or a default value when property cannot be found in any configuration file.

Parameters:
key - the key used in the configuration file.
defaultValue - Default value returned, when value cannot be found in configuration.
Returns:
the value of the key or the default value.

getBoolean

Boolean getBoolean(String key)
Parameters:
key -
Returns:
the property or null if not there or property no boolean

getBooleanWithDefault

Boolean getBooleanWithDefault(String key,
                              Boolean defaultValue)
Get a Boolean property or a default value when property cannot be found in any configuration file.

Parameters:
key - the key used in the configuration file.
defaultValue - Default value returned, when value cannot be found in configuration.
Returns:
the value of the key or the default value.

getBooleanOrDie

Boolean getBooleanOrDie(String key)
The "die" method forces this key to be set. Otherwise a runtime exception will be thrown.

Parameters:
key -
Returns:
the boolean or a RuntimeException will be thrown.

getIntegerOrDie

Integer getIntegerOrDie(String key)
The "die" method forces this key to be set. Otherwise a runtime exception will be thrown.

Parameters:
key -
Returns:
the Integer or a RuntimeException will be thrown.

getOrDie

String getOrDie(String key)
The "die" method forces this key to be set. Otherwise a runtime exception will be thrown.

Parameters:
key -
Returns:
the String or a RuntimeException will be thrown.

getStringArray

String[] getStringArray(String key)
eg. key=myval1,myval2 Delimiter is a comma "," as outlined in the example above.

Returns:
an array containing the values of that key or null if not found.

isDev

boolean isDev()
Whether we are in dev mode

Returns:
True if we are in dev mode

isTest

boolean isTest()
Whether we are in test mode

Returns:
True if we are in test mode

isProd

boolean isProd()
Whether we are in prod mode

Returns:
True if we are in prod mode

getAllCurrentNinjaProperties

Properties getAllCurrentNinjaProperties()
Returns:
All properties that are currently loaded from internal and external files


Copyright © 2012. All Rights Reserved.