com.groiss.component
Class Configuration

java.lang.Object
  extended by com.groiss.component.Configuration

public class Configuration
extends java.lang.Object

This class handles the access to the configuration. There are two types of configurations: the configuration of @enterprise and the configuration of the applications. On startup @enterprise reads the configuration files and keeps the contents in memory. For access to the system configuration use Configuration.get(). For accessing the configuration of an application use Configuration.get("appl-id").

A configuration object contains the map between parameter names and values.


Field Summary
static java.lang.String OBFUSCATED_PREFIX
           
 
Method Summary
 void addParameterGroup(java.lang.String s)
           
static Configuration create(java.lang.String id)
          Add a configuration to the internal map of configurations.
static java.lang.String demansch(java.lang.String arg)
          Deprecated. 
static Configuration get()
          Return the @enterprise configuration.
static Configuration get(java.lang.String id)
          Get the configuration by the given id.
 java.lang.Boolean getBoolean(java.lang.String name)
          Return the property value as Boolean.
 java.lang.Class<?> getClass(java.lang.String name)
          Return the property value as class.
static java.util.Map<java.lang.String,Configuration> getConfigurations()
          Return the whole map of configurations.
 org.jdom.Element getDefinition()
          Return the definition of a configuration.
 java.lang.Double getDouble(java.lang.String name)
          Return the property value as Double.
 java.lang.String getFileName()
          Return the file name the configuration is loaded from.
 java.lang.Float getFloat(java.lang.String name)
          Return the property value as Float.
 java.lang.String getId()
          Return the id of this configuration.
 java.lang.Integer getInt(java.lang.String name)
          Return the property value as Integer.
 java.lang.Long getLong(java.lang.String name)
          Return the property value as Long.
 java.lang.Object getObject(java.lang.String name)
          Return the property value.
 java.lang.String getPasswordProperty(java.lang.String name)
          Get the value of a "mangled" property.
 java.util.Properties getProperties()
          Return the whole paramter map.
 java.util.Properties getPropertiesStartingWith(java.lang.String prefix)
          Returns the subset of properties with names thhat start with a given prefix.
 java.lang.String getProperty(java.lang.String name)
          Returns the value of the property with the given name.
 java.lang.String getProperty(java.lang.String name, java.lang.String defValue)
          Deprecated. define default values in the xml decsription of the configuration.
 java.util.Properties getPropertyAsProperties(java.lang.String name)
          Returns the value of the (multi-valued) property with the given name in the form of a property.
 Resource getResource()
          Rerturn the resource for this configuration.
 java.lang.Class getType(java.lang.String name)
          Return the type of the given property.
 boolean isPasswordProperty(java.lang.String name)
           
static void loadTopLevel(java.lang.String filename)
          Load the main configuration.
static java.lang.String mansch(java.lang.String arg)
          Deprecated. 
 boolean needsRestart(java.lang.String param)
          Returns true if the property change needs a server restart to become effective.
 void reload()
          Reload the configuration from the configured file.
static java.lang.String saveConvert(java.lang.String theString, boolean escapeSpace)
           
 void setFileName(java.lang.String filename)
          Set the file name for the configuration.
 void setProperty(java.lang.String name, java.lang.Object value)
          Set a property to a value.
 void setProperty(java.lang.String name, java.lang.String value)
          Set a property to a value.
 void setPropFile(java.lang.String url)
          Set the url for the description file for the configuration.
 void setResource(Resource res)
          Set a resource for internationalization of this configuration.
 void setSystemProps()
          Copy all properties of this configuration into the system properties.
 void setVisibility(java.lang.String paramGroupId, boolean visible)
          Set the visibility of a parameter group in the configuration
 void store()
          Save the configuration on the file system
static void storeProps(java.util.Properties props, java.io.File file)
           
static java.lang.String valToString(java.lang.Object value)
          Convert a value from the configuration to a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OBFUSCATED_PREFIX

public static final java.lang.String OBFUSCATED_PREFIX
See Also:
Constant Field Values
Method Detail

create

public static Configuration create(java.lang.String id)
Add a configuration to the internal map of configurations. This is called on startup for the system configuration and the application configurations.

Parameters:
id - the id of the application
Returns:
a new Configuration object

get

public static Configuration get(java.lang.String id)
Get the configuration by the given id.

Parameters:
id - the id of the configuration, normally the id of an application.
Returns:
a Configuration object

getConfigurations

public static java.util.Map<java.lang.String,Configuration> getConfigurations()
Return the whole map of configurations.

Returns:
a map

get

public static Configuration get()
Return the @enterprise configuration.

Returns:
the configuration object.

setResource

public void setResource(Resource res)
Set a resource for internationalization of this configuration. The resource of the application configuration objects is set to the application resource on startup.

Parameters:
res - a resource object

getResource

public Resource getResource()
Rerturn the resource for this configuration.

Returns:
a resource or null if none is set.

setVisibility

public void setVisibility(java.lang.String paramGroupId,
                          boolean visible)
Set the visibility of a parameter group in the configuration

Parameters:
paramGroupId - the id of the group
visible - the new visibility

getDefinition

public org.jdom.Element getDefinition()
Return the definition of a configuration.

Returns:
the root node of the definition as JDOM Element

setPropFile

public void setPropFile(java.lang.String url)
Set the url for the description file for the configuration.

Parameters:
url -

addParameterGroup

public void addParameterGroup(java.lang.String s)
Parameters:
s -

needsRestart

public boolean needsRestart(java.lang.String param)
Returns true if the property change needs a server restart to become effective.

Parameters:
param - name of the property
Returns:
true if restart is necessary

reload

public void reload()
            throws java.io.IOException
Reload the configuration from the configured file.

Throws:
java.io.IOException

loadTopLevel

public static void loadTopLevel(java.lang.String filename)
                         throws java.io.IOException,
                                java.io.FileNotFoundException
Load the main configuration.

Throws:
java.io.IOException
java.io.FileNotFoundException

setSystemProps

public void setSystemProps()
Copy all properties of this configuration into the system properties.


getFileName

public java.lang.String getFileName()
Return the file name the configuration is loaded from.

Returns:
a path name

setFileName

public void setFileName(java.lang.String filename)
Set the file name for the configuration. The file name is used when the configuration is stored.

Parameters:
filename -

getId

public java.lang.String getId()
Return the id of this configuration.

Returns:
a string

getPropertiesStartingWith

public java.util.Properties getPropertiesStartingWith(java.lang.String prefix)
Returns the subset of properties with names thhat start with a given prefix.

Parameters:
prefix - the prefix to search for
Returns:
the matching properties

getPropertyAsProperties

public java.util.Properties getPropertyAsProperties(java.lang.String name)
Returns the value of the (multi-valued) property with the given name in the form of a property. If there is no property with this name the method returns null.

Parameters:
name - name of a property
Returns:
the value of the specified property as Property Object or null if the configuration entry is either not found or empty.

getProperty

public java.lang.String getProperty(java.lang.String name)
Returns the value of the property with the given name. If there is no property with this name the method returns null. If the property value is not of type string the method toString() is called on it.

Parameters:
name - name of a property
Returns:
the value

getProperty

@Deprecated
public java.lang.String getProperty(java.lang.String name,
                                               java.lang.String defValue)
Deprecated. define default values in the xml decsription of the configuration.

Returns the value of the specified configuration key or the defValue, if the configuration entry is not found.

Parameters:
name - the configuration entry key
defValue - the default value
Returns:
the value of the specified configuration key or the defValue, if the configuration entry is not found.

getBoolean

public java.lang.Boolean getBoolean(java.lang.String name)
Return the property value as Boolean.

Parameters:
name - the name of the property
Returns:
the value casted to Boolean

getInt

public java.lang.Integer getInt(java.lang.String name)
Return the property value as Integer.

Parameters:
name - the name of the property
Returns:
the value casted to Integer

getLong

public java.lang.Long getLong(java.lang.String name)
Return the property value as Long.

Parameters:
name - the name of the property
Returns:
the value casted to Long

getFloat

public java.lang.Float getFloat(java.lang.String name)
Return the property value as Float.

Parameters:
name - the name of the property
Returns:
the value casted to Float

getDouble

public java.lang.Double getDouble(java.lang.String name)
Return the property value as Double.

Parameters:
name - the name of the property
Returns:
the value casted to Double

getClass

public java.lang.Class<?> getClass(java.lang.String name)
Return the property value as class.

Parameters:
name - the name of the property
Returns:
the value casted to Class

getObject

public java.lang.Object getObject(java.lang.String name)
Return the property value.

Parameters:
name - the name of the property
Returns:
the value without any conversion

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value)
Set a property to a value.

Parameters:
name - the name of the property
value - the value string

setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
Set a property to a value.

Parameters:
name - the name of the property
value - the value object

isPasswordProperty

public boolean isPasswordProperty(java.lang.String name)

getPasswordProperty

public java.lang.String getPasswordProperty(java.lang.String name)
Get the value of a "mangled" property.

Parameters:
name -
Returns:
the plain value

getType

public java.lang.Class getType(java.lang.String name)
Return the type of the given property.

Parameters:
name - the name of the property
Returns:
the type

store

public void store()
Save the configuration on the file system


storeProps

public static void storeProps(java.util.Properties props,
                              java.io.File file)

valToString

public static java.lang.String valToString(java.lang.Object value)
Convert a value from the configuration to a string. The method converts null to the empty string, returns the classname for classes and calls toString() to all other values. Moreover it calls trim() on the result.

Parameters:
value - an object
Returns:
a string representation of a configuration value

mansch

@Deprecated
public static java.lang.String mansch(java.lang.String arg)
Deprecated. 

This method makes a string unreadable. Is is used to store passwords in a configuration file. It is not an encryption but is much better than storing the value unchanged.


demansch

@Deprecated
public static java.lang.String demansch(java.lang.String arg)
Deprecated. 

Inverse function to mansch.


getProperties

public java.util.Properties getProperties()
Return the whole paramter map.

Returns:
a Properties object

saveConvert

public static java.lang.String saveConvert(java.lang.String theString,
                                           boolean escapeSpace)


@enterprise 8.0.22989 Copyright © 2001-2017 Groiss Informatics GmbH. All Rights Reserved.