|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.agimatec.commons.config.ConfigManager
public class ConfigManager
Provides central access to configuration files.
The singleton can be used (getDefault()).
A ConfigManger uses a resource name (file) in the classpath that contains
the absolute config root path.
If the resource cannot be found, the config manager tries
to access a system property with the same name.
If such a system property exists,
its value is used as the config root path.
The default configrootressourcename is "configroot.ini".
ConfigManager.getDefault() sucht eine Resource configroot.ini im Klassenpfad.
Es koennen andere ConfigManager instanziert werden, die ggf. eine andere Resource verwenden,
wenn man mehrere config-roots haben moechte.
Die configroot.ini Datei enthaelt den Pfad, in dem die Datei configroot.xml zu finden ist.
Wird die Resource nicht gefunden, so ist config-root das aktuelle Verzeichnis.
Im Config-root wird als Einstieg in die Konfigurationen die configDatei configroot.xml
gesucht (die muss immer so heissen).
In dieser Datei sind nur <file> Tags erlaubt, die auf andere ConfigFiles verweisen und
zwar entweder relativ zum configroot (als Default) oder mit absolutem Pfad (relative="false").
Alle anderen Configfiles koennen beliebige Datenstrukturen darstellen:
- alle primitiv-Typen als Wrapperklasse oder als Node-Klasse
- list, map, ArrayList, HashMap
- filenodes auf andere Dateien, die ggf. keine config-dateien mehr sind
(so kann auf bel. Resourcen verwiesen werden ohne den JavaSource Pfadabh. zu machen)
Author: Roman Stumm
| Field Summary | |
|---|---|
static java.lang.String |
C_ProtocolClassPath
|
protected java.util.Map |
myConfigMap
|
protected Config |
myConfigroot
|
protected java.lang.String |
myConfigrootPath
|
protected java.lang.String |
myConfigRootRessouceName
|
protected static ConfigManager |
singleton
|
| Constructor Summary | |
|---|---|
ConfigManager(java.lang.String aConfigRootRessouceName)
Creates a new ConfigManager. |
|
| Method Summary | |
|---|---|
void |
cacheConfig(Config aConfig,
java.lang.String aConfigName)
put the config into the cache |
void |
clearCache()
remove all cached configs from the cache |
protected org.xml.sax.XMLReader |
createParser()
initialize lazy and return the receiver's script instance ready to be used. |
Config |
getCachedConfig(java.lang.String aConfigName)
|
Config |
getConfig(java.lang.String configname)
get or read the config named configname. |
Config |
getConfig(java.lang.String configname,
boolean allowNullReturn)
|
Config |
getConfig(java.lang.String aConfigname,
java.lang.String aPath)
return the config with the given name from the cache. |
Config |
getConfig(java.lang.String aConfigName,
java.lang.String aPath,
boolean isRelativeFlag)
return the config with the given name from the cache. |
Config |
getConfigRoot()
|
java.lang.String |
getConfigRootPath()
|
Config |
getConfigUncached(java.lang.String configname)
the same as this#getConfig(java.lang.String) but the
config is read from file and not cached. |
static ConfigManager |
getDefault()
|
Config |
parseConfig(java.lang.String aConfigXMLString)
|
protected void |
parseResource(org.xml.sax.XMLReader aParser,
java.lang.String aPath)
parse either from a file or the classpath |
protected void |
parseString(org.xml.sax.XMLReader aParser,
java.lang.String aConfigXMLString)
parse xml in the given string |
Config |
readConfig(java.lang.String aPath)
open and parse the file name given in path. |
Config |
readConfig(java.lang.String aPath,
boolean isRelativeFlag)
open and parse the file name given in path. |
protected java.lang.String |
readConfigrootPath()
|
protected java.lang.String |
readConfigrootPath(java.lang.String aResourceName)
|
static java.lang.String |
readRessource(java.lang.ClassLoader aClassLoader,
java.lang.String aResourceName)
|
void |
setConfigRootPath(java.lang.String aConfigRootPath)
directly set the config root path. |
static java.net.URL |
toURL(java.lang.String path)
|
static java.util.List<java.net.URL> |
toURLs(java.lang.String path)
|
void |
uncacheConfig(Config aConfig)
remove the config from the cache |
java.lang.String |
writeConfig(Config aConfig)
|
void |
writeConfig(Config aConfig,
java.io.PrintWriter aPrintWriter)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String C_ProtocolClassPath
protected static ConfigManager singleton
protected final java.lang.String myConfigRootRessouceName
protected Config myConfigroot
protected java.lang.String myConfigrootPath
protected java.util.Map myConfigMap
| Constructor Detail |
|---|
public ConfigManager(java.lang.String aConfigRootRessouceName)
aConfigRootRessouceName - the resource name (file) in the classpath that contains
the absolute config root path. If the resource cannot be found, the config manager tries
to access a system property with the same name. If such a system property exists,
its value is used as the config root path.
The default configrootressourcename is "configroot.ini".| Method Detail |
|---|
public static ConfigManager getDefault()
public Config readConfig(java.lang.String aPath,
boolean isRelativeFlag)
public Config parseConfig(java.lang.String aConfigXMLString)
protected void parseString(org.xml.sax.XMLReader aParser,
java.lang.String aConfigXMLString)
throws java.io.IOException,
org.xml.sax.SAXException
aParser - - the parse to useaConfigXMLString - - the xml to parse
java.io.IOException
org.xml.sax.SAXException
protected void parseResource(org.xml.sax.XMLReader aParser,
java.lang.String aPath)
throws java.io.IOException,
org.xml.sax.SAXException
java.io.IOException
org.xml.sax.SAXException
public static java.net.URL toURL(java.lang.String path)
throws java.net.MalformedURLException
java.net.MalformedURLException
public static java.util.List<java.net.URL> toURLs(java.lang.String path)
throws java.io.IOException
java.io.IOExceptionprotected org.xml.sax.XMLReader createParser()
public Config readConfig(java.lang.String aPath)
public void writeConfig(Config aConfig,
java.io.PrintWriter aPrintWriter)
throws java.io.IOException
java.io.IOException
public java.lang.String writeConfig(Config aConfig)
throws java.io.IOException
java.io.IOException
public Config getConfig(java.lang.String aConfigname,
java.lang.String aPath)
public Config getConfig(java.lang.String aConfigName,
java.lang.String aPath,
boolean isRelativeFlag)
isRelativeFlag - - is true when the path is relative to configroot, so that
the absolute path will be created. - is false, when the path should not be modified.public Config getCachedConfig(java.lang.String aConfigName)
public Config getConfig(java.lang.String configname)
java.lang.IllegalArgumentException - if the config is unknownpublic Config getConfigUncached(java.lang.String configname)
this#getConfig(java.lang.String) but the
config is read from file and not cached.
configname -
public Config getConfig(java.lang.String configname,
boolean allowNullReturn)
public Config getConfigRoot()
public void cacheConfig(Config aConfig,
java.lang.String aConfigName)
public void uncacheConfig(Config aConfig)
public void clearCache()
public java.lang.String getConfigRootPath()
public void setConfigRootPath(java.lang.String aConfigRootPath)
protected java.lang.String readConfigrootPath()
protected final java.lang.String readConfigrootPath(java.lang.String aResourceName)
public static java.lang.String readRessource(java.lang.ClassLoader aClassLoader,
java.lang.String aResourceName)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||