|
||||||||||
| 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 String |
C_ProtocolClassPath
|
protected Map |
myConfigMap
|
protected Config |
myConfigroot
|
protected String |
myConfigrootPath
|
protected String |
myConfigRootRessouceName
|
protected static ConfigManager |
singleton
|
| Constructor Summary | |
|---|---|
ConfigManager(String aConfigRootRessouceName)
Creates a new ConfigManager. |
|
| Method Summary | |
|---|---|
void |
cacheConfig(Config aConfig,
String aConfigName)
put the config into the cache |
void |
clearCache()
remove all cached configs from the cache |
protected XMLReader |
createParser()
initialize lazy and return the receiver's script instance ready to be used. |
Config |
getCachedConfig(String aConfigName)
|
Config |
getConfig(String configname)
get or read the config named configname. |
Config |
getConfig(String configname,
boolean allowNullReturn)
|
Config |
getConfig(String aConfigname,
String aPath)
return the config with the given name from the cache. |
Config |
getConfig(String aConfigName,
String aPath,
boolean isRelativeFlag)
return the config with the given name from the cache. |
Config |
getConfigRoot()
|
String |
getConfigRootPath()
|
Config |
getConfigUncached(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(String aConfigXMLString)
|
protected void |
parseResource(XMLReader aParser,
String aPath)
parse either from a file or the classpath |
protected void |
parseString(XMLReader aParser,
String aConfigXMLString)
parse xml in the given string |
Config |
readConfig(String aPath)
open and parse the file name given in path. |
Config |
readConfig(String aPath,
boolean isRelativeFlag)
open and parse the file name given in path. |
protected String |
readConfigrootPath()
|
protected String |
readConfigrootPath(String aResourceName)
|
static String |
readRessource(ClassLoader aClassLoader,
String aResourceName)
|
static String |
resolvePath(String theResPath)
|
void |
setConfigRootPath(String aConfigRootPath)
directly set the config root path. |
static URL |
toURL(String path)
|
static List<URL> |
toURLs(String path)
|
void |
uncacheConfig(Config aConfig)
remove the config from the cache |
String |
writeConfig(Config aConfig)
|
void |
writeConfig(Config aConfig,
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 String C_ProtocolClassPath
protected static ConfigManager singleton
protected final String myConfigRootRessouceName
protected Config myConfigroot
protected String myConfigrootPath
protected Map myConfigMap
| Constructor Detail |
|---|
public ConfigManager(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(String aPath,
boolean isRelativeFlag)
public Config parseConfig(String aConfigXMLString)
protected void parseString(XMLReader aParser,
String aConfigXMLString)
throws IOException,
SAXException
aParser - - the parse to useaConfigXMLString - - the xml to parse
IOException
SAXException
protected void parseResource(XMLReader aParser,
String aPath)
throws IOException,
SAXException
IOException
SAXException
public static URL toURL(String path)
throws MalformedURLException
MalformedURLException
public static List<URL> toURLs(String path)
throws IOException
IOExceptionpublic static String resolvePath(String theResPath)
protected XMLReader createParser()
public Config readConfig(String aPath)
public void writeConfig(Config aConfig,
PrintWriter aPrintWriter)
throws IOException
IOException
public String writeConfig(Config aConfig)
throws IOException
IOException
public Config getConfig(String aConfigname,
String aPath)
public Config getConfig(String aConfigName,
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(String aConfigName)
public Config getConfig(String configname)
IllegalArgumentException - if the config is unknownpublic Config getConfigUncached(String configname)
this#getConfig(java.lang.String) but the
config is read from file and not cached.
configname -
public Config getConfig(String configname,
boolean allowNullReturn)
public Config getConfigRoot()
public void cacheConfig(Config aConfig,
String aConfigName)
public void uncacheConfig(Config aConfig)
public void clearCache()
public String getConfigRootPath()
public void setConfigRootPath(String aConfigRootPath)
protected String readConfigrootPath()
protected final String readConfigrootPath(String aResourceName)
public static String readRessource(ClassLoader aClassLoader,
String aResourceName)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||