nl.knowledgeplaza.util.configuration
Class Configuration

java.lang.Object
  extended by nl.knowledgeplaza.util.configuration.Configuration

public class Configuration
extends Object

Author:
user

Field Summary
static String ID_APPLICATION
           
static String ID_HOST
           
static String ID_OS
           
static String ID_PORT
           
static String ID_SYSTEM
           
static String ID_USER
           
static String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
 
Constructor Summary
Configuration()
          create and initialize with default settings
Configuration(File... files)
          Specify what files to use
Configuration(Map<String,String> identifiers)
          get all the settings from the system properties then override with provided identifiers
 
Method Summary
 void addConfigurationProvider(ConfigurationProviderAbstract configurationProvider)
           
 void addConfigurationProviderForMainArgs(String[] args)
          add main args as a configuration provider
 void addConfigurationProviderForPropertyFile(URL file)
           
 String describe()
          for feedback
static Configuration get()
          Singleton or thread related
 String get(Class contextClass, String propertyName)
           
 String get(Class contextClass, String propertyName, String defaultValue)
          convenience method: first check full name, then simple name then property only
 String get(Object contextObject, String propertyName)
           
 String get(Object contextObject, String propertyName, String defaultValue)
          convenience method: use the class of the object
 String get(String propertyName)
          find the first definition of a property and return its value
 String get(String context, String propertyName)
           
 String get(String context, String propertyName, String defaultValue)
          convenience method: first check the context then the pure property name
 List<File> getAdditionalPaths()
          AdditionalPaths
 Map<String,String> getCollection(Class contextClass, String propertyName)
          convenience method: first check full name, then simple name then property only
 Map<String,String> getCollection(Object contextObject, String propertyName)
          convenience method: use the class of the object
 Map<String,String> getCollection(String prefix)
          get all properties that match a prefix as a map For example: my.collection.1.f.1=A1 my.collection.1.f.2=B1 my.collection.1.f.3=C1 my.collection.3.f.1=A3 my.collection.3.f.2=B3 my.collection.3.f.3=C3 Calling this method with prefix my.collection.1, returns a map with: f.1=A1 f.2=B1 f.3=C1
 Map<String,String> getCollection(String context, String propertyName)
          convenience method: first check the context then the pure property name
 List<ConfigurationProviderAbstract> getConfigurationProviders()
          the ConfigurationProviders
 List<File> getForcedFiles()
           
 Map<String,Map<String,String>> getGroupedCollection(String prefix)
          Get all properties that match a prefix and group them.
 String getIdentifier(String key)
          identifier
 boolean getIdentifierLock()
          IdentifierLock
 Map<String,String> getIdentifiers()
           
 String getPrefix()
          the prefix is configurable
static Configuration getThreadRelatedConfiguration()
           
 void listConfiguration()
           
 void log4jDebug(String s)
           
 void removeConfigurationProvider(ConfigurationProviderAbstract configurationProvider)
           
static Configuration removeThreadRelatedConfiguration()
           
static String sanatizeIdentifier(String s)
           
static void set(Configuration Configuration)
           
 void setAdditionalPaths(File... value)
           
 void setAdditionalPaths(List<File> value)
           
 void setIdentifier(String key, String value)
          null removes the identifier
 void setIdentifierLock(boolean value)
           
 void setPrefix(String value)
           
static void setThreadRelatedConfiguration(Configuration value)
          ThreadRelatedConfiguration This is the cached Configuration so it only is created only once per thread.
 boolean setupConfiguration()
           
 Configuration withAdditionalPaths(List<File> value)
           
 Configuration withIdentifier(String key, String value)
           
 Configuration withPrefix(String value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SOURCECODE_VERSION

public static final String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values

ID_SYSTEM

public static final String ID_SYSTEM
See Also:
Constant Field Values

ID_USER

public static final String ID_USER
See Also:
Constant Field Values

ID_OS

public static final String ID_OS
See Also:
Constant Field Values

ID_APPLICATION

public static final String ID_APPLICATION
See Also:
Constant Field Values

ID_HOST

public static final String ID_HOST
See Also:
Constant Field Values

ID_PORT

public static final String ID_PORT
See Also:
Constant Field Values
Constructor Detail

Configuration

public Configuration()
create and initialize with default settings


Configuration

public Configuration(Map<String,String> identifiers)
get all the settings from the system properties then override with provided identifiers


Configuration

public Configuration(File... files)
Specify what files to use

Method Detail

get

public static Configuration get()
Singleton or thread related


set

public static void set(Configuration Configuration)

setThreadRelatedConfiguration

public static void setThreadRelatedConfiguration(Configuration value)
ThreadRelatedConfiguration This is the cached Configuration so it only is created only once per thread. It can also be used to preset a Configuration (for example from a session in a webapp).


getThreadRelatedConfiguration

public static Configuration getThreadRelatedConfiguration()

removeThreadRelatedConfiguration

public static Configuration removeThreadRelatedConfiguration()

getForcedFiles

public List<File> getForcedFiles()

sanatizeIdentifier

public static String sanatizeIdentifier(String s)
Parameters:
s -
Returns:

getIdentifier

public String getIdentifier(String key)
identifier


setIdentifier

public void setIdentifier(String key,
                          String value)
null removes the identifier


withIdentifier

public Configuration withIdentifier(String key,
                                    String value)

getIdentifiers

public Map<String,String> getIdentifiers()

getIdentifierLock

public boolean getIdentifierLock()
IdentifierLock


setIdentifierLock

public void setIdentifierLock(boolean value)

getPrefix

public String getPrefix()
the prefix is configurable


setPrefix

public void setPrefix(String value)

withPrefix

public Configuration withPrefix(String value)

getAdditionalPaths

public List<File> getAdditionalPaths()
AdditionalPaths


setAdditionalPaths

public void setAdditionalPaths(List<File> value)

setAdditionalPaths

public void setAdditionalPaths(File... value)

withAdditionalPaths

public Configuration withAdditionalPaths(List<File> value)

getConfigurationProviders

public List<ConfigurationProviderAbstract> getConfigurationProviders()
the ConfigurationProviders


addConfigurationProvider

public void addConfigurationProvider(ConfigurationProviderAbstract configurationProvider)

removeConfigurationProvider

public void removeConfigurationProvider(ConfigurationProviderAbstract configurationProvider)

addConfigurationProviderForMainArgs

public void addConfigurationProviderForMainArgs(String[] args)
add main args as a configuration provider


addConfigurationProviderForPropertyFile

public void addConfigurationProviderForPropertyFile(URL file)

setupConfiguration

public boolean setupConfiguration()

listConfiguration

public void listConfiguration()

describe

public String describe()
for feedback


get

public String get(String propertyName)
find the first definition of a property and return its value


get

public String get(String context,
                  String propertyName,
                  String defaultValue)
convenience method: first check the context then the pure property name


get

public String get(String context,
                  String propertyName)

get

public String get(Class contextClass,
                  String propertyName,
                  String defaultValue)
convenience method: first check full name, then simple name then property only


get

public String get(Class contextClass,
                  String propertyName)

get

public String get(Object contextObject,
                  String propertyName,
                  String defaultValue)
convenience method: use the class of the object


get

public String get(Object contextObject,
                  String propertyName)

getCollection

public Map<String,String> getCollection(String prefix)
get all properties that match a prefix as a map For example: my.collection.1.f.1=A1 my.collection.1.f.2=B1 my.collection.1.f.3=C1 my.collection.3.f.1=A3 my.collection.3.f.2=B3 my.collection.3.f.3=C3 Calling this method with prefix my.collection.1, returns a map with: f.1=A1 f.2=B1 f.3=C1

Parameters:
prefix -
Returns:

getCollection

public Map<String,String> getCollection(String context,
                                        String propertyName)
convenience method: first check the context then the pure property name


getCollection

public Map<String,String> getCollection(Class contextClass,
                                        String propertyName)
convenience method: first check full name, then simple name then property only


getCollection

public Map<String,String> getCollection(Object contextObject,
                                        String propertyName)
convenience method: use the class of the object


getGroupedCollection

public Map<String,Map<String,String>> getGroupedCollection(String prefix)
Get all properties that match a prefix and group them. For example: my.collection.1.f.1=A1 my.collection.1.f.2=B1 my.collection.1.f.3=C1 my.collection.3.f.1=A3 my.collection.3.f.2=B3 my.collection.3.f.3=C3 Calling this method with prefix my.collection, returns a map with under the key "1" and "3" two maps containing "f.1" with their respective values. So the result is: [1=>[f.1=>A1, f.3=>C1, f.2=>B1], 3=>[f.1=>A3, f.3=>C3, f.2=>B3]] Often de index is not relevant, but having it in a map makes it a bit of a hassle to navigate (pre 1.5) Using " list.addAll(map.values()); " makes it easier.

Parameters:
prefix -
Returns:

log4jDebug

public void log4jDebug(String s)


Copyright © 2012 KnowledgePlaza. All Rights Reserved.