public class ApplicationConfig extends Object
useOnlyAliases
getOptionAsList(String)
TODO A revoir en introduisant le nouveau constructeur avec ApplicationConfigInit
Vous devez créer une factory pour créer les instances d'ApplicationConfig qui contiendra par exemple une méthode :
public static ApplicationConfig getConfig(
Properties props, String configFilename, String ... args) {
ApplicationConfig conf = new ApplicationConfig(
MyAppConfigOption.class, MyAppConfigAction.class,
props, configFilename);
try {
conf.parse(args);
} catch (ArgumentsParserException eee) {
if (log.isErrorEnabled()) {
log.error("Can't load app configuration", eee);
}
}
return conf;
}
ConfigOptionDef et décrire les options de la configuration de l'application.
ConfigActionDef et décrire la liste des actions
et de leur alias disponible pour l'application.
La lecture des fichiers de configuration se fait durant l'appel de la méthode
parse(String...) en utilisant la valeur de qui doit être définit
dans les options avec pour clef CONFIG_FILE_NAME pour
trouver les fichiers (voir Les options de configuration pour l'ordre de
chargement des fichiers)
save(File, boolean, String...) sauve les données dans le fichier demandé
saveForSystem(String...) sauvegarde les données dans /etc
saveForUser(String...) sauvegarde les données dans $HOME
Lors de l'utilisation de la methode saveForSystem(String...) ou
saveForUser(String...) seules les options lues dans un fichier ou modifiées par
programmation (setOption(String, String) seront sauvegardées. Par exemple les
options passees sur la ligne de commande ne seront pas sauvées.
Cette classe permet de lire les fichiers de configuration, utiliser les variable d'environnement et de parser la ligne de commande. L'ordre de prise en compte des informations trouvées est le suivant (le premier le plus important) :
setOption(String, String)setDefaultOption(String, String)Les options sur la ligne de commande sont de la forme:
--option key value --monOption key value1 value2
ApplicationConfig. Dans ce cas vous pouvez mettre les
arguments que vous souhaitez du moment qu'ils soient convertibles de la
representation String vers le type que vous avez mis.
Les actions ne peuvent etre que sur la ligne de commande. Elles sont de la forme:
--le.package.LaClass#laMethode arg1 arg2 arg3 ... argN
Une action est donc défini par le chemin complet vers la méthode qui traitera
l'action. Cette méthode peut-être une méthode static ou non. Si la méthode
n'est pas static lors de l'instanciation de l'objet on essaie de passer en
paramètre du constructeur la classe de configuration utilisée pour permettre
a l'action d'avoir a sa disposition les options de configuration. Si aucun
constructeur avec comme seul paramètre une classe héritant de
ApplicationConfig n'existe alors le constructeur par défaut est
utilise (il doit être accessible). Toutes methodes d'actions faisant
parties d'un meme objet utiliseront la meme instance de cette objet lors
de leur execution.
Si la méthode utilise les arguments variants alors tous les arguments jusqu'au prochain -- ou la fin de la ligne de commande sont utilises. Sinon Le nombre exact d'argument nécessaire a la méthode sont utilises.
Les arguments sont automatiquement converti dans le bon type réclamé par la methode.
Si l'on veut des arguments optionnels le seul moyen actuellement est d'utiliser une méthode avec des arguments variants
Les actions ne sont pas execute mais seulement parsées. Pour les exécuter
il faut utiliser la méthode doAction(int) qui prend en argument un numéro
de 'step' ou doAllAction() qui fait les actions dans l'ordre de leur step.
Par défaut toutes les actions sont de niveau 0 et sont exécutées
dans l'ordre d'apparition sur la ligne de commande. Si l'on souhaite
distinguer les actions il est possible d'utiliser l'annotation
ApplicationConfig.Action.Step sur la methode qui fera l'action en
precisant une autre valeur que 0.
doAction(0); ... do something ... doAction(1);
dans cette exemple on fait un traitement entre l'execution des actions de niveau 0 et les actions de niveau 1.
Tout ce qui n'est pas option ou action est considèré comme non parse et peut
etre recupere par la methode getUnparsed(). Si l'on souhaite forcer
la fin du parsing de la ligne de commande il est possible de mettre --.
Par exemple:
monProg "mon arg" --option k1 v1 -- --option k2 v2 -- autre
Dans cet exemple seule la premiere option sera considère comme une option.
On retrouvera dans unparsed: "mon arg", "--option", "k2", "v2", "--",
"autre"
On voit qu'aussi bien pour les actions que pour les options, le nom de la
méthode doit être utilise. Pour éviter ceci il est possible de définir
des alias ce qui permet de creer des options courtes par exemple. Pour cela,
on utilise la méthode addAlias(String, String...).
addAlias("-v", "--option", "verbose", "true");
addAlias("-o", "--option", "outputfile");
addAlias("-i", "--mon.package.MaClass#MaMethode", "import");
En faite avant le parsing de la ligne de commande tous les alias trouves sont
automatiquement remplacer par leur correspondance. Il est donc possible
d'utiliser ce mécanisme pour autre chose par exemple:
addAlias("cl", "Code Lutin");
addAlias("bp", "Benjamin POUSSIN);
Dans le premier exemple on simplifie une option de flags l'option -v n'attend donc plus d'argument. Dans le second exemple on simplifie une option qui attend encore un argument de type File. Enfin dans le troisième exemple on simplifie la syntaxe d'une action et on force le premier argument de l'action a être "import".
Pour la conversion de type nous utilisons common-beans. Les types supportes sont:
String
File
URL
Class
Date
Time
Timestamp
String. Chaque element doit
etre separe par une virgule.
Pour supporter d'autre type, il vous suffit d'enregistrer de nouveau converter dans commons-beans.
ApplicationConfig supporte les substituions de variables de la forme
${xxx} où xxx est une autre variable de la configuration.
Exemple (dans un fichier de configuration):
firstname = John
lastname = Doe
fullname = ${firstname} ${lastname}
getOption("fullname") retournera "John Doe".| Modifier and Type | Class and Description |
|---|---|
static class |
ApplicationConfig.Action
Defines a runtime action to be launched via the
ApplicationConfig.Action.doAction()
method. |
protected static class |
ApplicationConfig.CacheItem<T>
Item used for cacheOption
|
static class |
ApplicationConfig.OptionList |
| Modifier and Type | Field and Description |
|---|---|
protected Map<Integer,List<ApplicationConfig.Action>> |
actions
TODO
|
protected Map<String,List<String>> |
aliases
TODO
|
static String |
APP_NAME
Permet d'associer un nom de contexte pour prefixer les options
CONFIG_PATH et CONFIG_FILE_NAME. |
protected Map<Class<?>,Object> |
cacheAction
TODO
|
protected Map<String,ApplicationConfig.CacheItem<?>> |
cacheOption
TODO
|
static String |
CONFIG_ENCODING
Configuration encoding key option.
|
static String |
CONFIG_FILE_NAME
Configuration file key option.
|
static String |
CONFIG_PATH
Configuration directory where config path in located.
|
protected ApplicationConfigReader |
configReader
To read config.
|
protected ApplicationConfigWriter |
configWriter
To write config.
|
protected Map<String,Object> |
context
permet de conserver des objets associe avec ce ApplicationConfig
|
protected boolean |
inParseOptionPhase
vrai si on est en train de parser les options de la ligne de commande.
|
static String |
LIST_SEPARATOR |
protected String |
osName
System os name.
|
protected EnumMap<ApplicationConfigScope,Properties> |
propertiesByScope
Contient les fichiers de propriétés par scope.
|
protected List<String> |
unparsed
contient apres l'appel de parse, la liste des arguments non utilises
|
protected boolean |
useOnlyAliases
TODO
|
| Constructor and Description |
|---|
ApplicationConfig()
Init ApplicationConfig with current simple class name as config file.
|
ApplicationConfig(ApplicationConfigInit init)
All in one, this constructor allow to pass all necessary argument to
initialise ApplicationConfig and parse command line
|
ApplicationConfig(Properties defaults)
Init ApplicationConfig with current simple class name as config file
and use Properties parameter as defaults
|
ApplicationConfig(Properties defaults,
String configFilename)
All in one, this constructor allow to pass all necessary argument to
initialise ApplicationConfig and parse command line
|
ApplicationConfig(String configFilename)
Create configuration for a particular configuration filename
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAction(ApplicationConfig.Action action)
Add action to list of action to do.
|
void |
addActionAlias(String alias,
String actionMethod)
Add alias for action.
|
void |
addAlias(String alias,
String... target)
All argument in aliases as key is substitued by target.
|
void |
cleanUserConfig(String... excludeKeys)
Clean the user configuration file (The one in user home) and save it
in user config file.
|
protected <T> Object |
convertOption(Class<T> clazz,
String key,
String value,
boolean asList)
Convert value in instance of clazz or List if asList is true
|
protected ApplicationConfig.Action |
createAction(String name,
ListIterator<String> args)
Create action from string, string must be [package.][class][#][method]
if package, class or method missing, default is used
|
void |
doAction(int step)
Do action in specified step.
|
void |
doAllAction()
Do all action in specified order step (first 0).
|
List<Integer> |
getActionStep()
Return ordered action step number.
|
ApplicationConfig |
getConfig(Map<String,String> overwrite) |
String |
getConfigFileName()
Get name of file where options are read (in /etc, $HOME, $CURDIR).
|
protected String |
getConfigFileNameOption() |
String |
getConfigPath()
Get configuration file path to use.
|
File |
getCurrentConfigFile()
Obtain the current directory config file location.
|
String |
getEncoding()
Get the encoding used to read/write resources.
|
protected String |
getEncodingOption()
Obtains the key used to store the option encoding.
|
Properties |
getFlatOptions()
Get all options as flat
Properties object (replace inner options). |
Properties |
getFlatOptions(boolean replaceInner)
Get all options as flat
Properties object. |
protected Map<String,Method> |
getMethods()
Get all set method on this object or super object.
|
<E> E |
getObject(Class<E> clazz)
recupere un objet de la class<E>, s'il n'existe pas encore, il est cree
(il faut donc que class<E> soit instanciable).
|
<E> E |
getObject(Class<E> clazz,
String name)
recupere un objet ayant le nom 'name', s'il n'existe pas encore, il est
cree en utilisant la class<E>, sinon il est simplement caster vers cette
classe.
|
<T> T |
getOption(Class<T> clazz,
String key)
Get option value as typed value.
|
Object |
getOption(ConfigOptionDef key)
Get option value from a option definition.
|
String |
getOption(String key)
get option value as string.
|
boolean |
getOptionAsBoolean(String key)
Get option value as
boolean. |
Class<?> |
getOptionAsClass(String key)
Get option value as
Class. |
Color |
getOptionAsColor(String key)
Get option value as
Color. |
Date |
getOptionAsDate(String key)
Get option value as
Date. |
double |
getOptionAsDouble(String key)
Get option value as
double. |
File |
getOptionAsFile(String key)
Get option value as
File. |
float |
getOptionAsFloat(String key)
Get option value as
float. |
int |
getOptionAsInt(String key)
Get option value as
int. |
KeyStroke |
getOptionAsKeyStroke(String key)
Get option value as
KeyStroke. |
ApplicationConfig.OptionList |
getOptionAsList(String key)
Help to convert value to list of object.
|
Locale |
getOptionAsLocale(String key)
Get option value as
Locale. |
long |
getOptionAsLong(String key)
Get option value as
long. |
<E> E |
getOptionAsObject(Class<E> clazz,
String key)
retourne une nouvelle instance d'un objet dont on recupere la la class
dans la configuration via la cle 'key' et le cast en E.
|
Object |
getOptionAsObject(String key)
retourne une nouvelle instance d'un objet dont on recupere la la class
dans la configuration via la cle 'key'.
|
Properties |
getOptionAsProperties(String key)
Get option value as
Properties, this property must be a filepath
and file must be a properties. |
<E> E |
getOptionAsSingleton(Class<E> clazz,
String key)
retourne l'objet caster en 'E', instancier via la classe recupere dans la
configuration via la cle 'key'.
|
Object |
getOptionAsSingleton(String key)
retourne l'objet instancier via la classe recupere dans la configuration
via la cle 'key'.
|
Time |
getOptionAsTime(String key)
Get option value as
Time. |
Timestamp |
getOptionAsTimestamp(String key)
Get option value as
Timestamp. |
URL |
getOptionAsURL(String key)
Get option value as
URL. |
org.nuiton.version.Version |
getOptionAsVersion(String key)
Get option value as
Version. |
Properties |
getOptions()
Get all options from configuration.
|
Properties |
getOptionStartsWith(String prefix)
Permet de recuperer l'ensemble des options commencant par une certaine
chaine.
|
String |
getOsArch()
Get os arch (system property
os.arch). |
String |
getOsName()
Get os name (system property
os.name). |
protected String[] |
getParams(Method m,
ListIterator<String> args)
Take required argument for method in args.
|
String |
getPrintableConfig(String includePattern,
int padding)
Return all configuration used with value, that respect includePattern
|
protected Properties |
getProperties(ApplicationConfigScope scope) |
SubApplicationConfig |
getSubConfig(String prefix)
Returns a sub config that encapsulate this ApplicationConfig.
|
File |
getSystemConfigFile()
Obtain the system config file location.
|
protected String |
getSystemConfigurationPath()
Get system configuration path.
|
List<String> |
getUnparsed()
Return list of unparsed command line argument
|
String |
getUserConfigDirectory()
Get user configuration path.
|
File |
getUserConfigFile()
Obtain the user config file location.
|
static String |
getUserHome()
Get user home directory (system property
user.home). |
String |
getUsername()
Get user name (system property
user.name). |
boolean |
hasOption(ConfigOptionDef key)
Teste si un option existe ou non
|
boolean |
hasOption(String key)
Teste si un option existe ou non.
|
protected void |
init(ApplicationConfigInit init)
On sépare l'initialisation du constructeur pour pouvoir ne pas exécuter ce code sur des classes surchargeant ApplicationConfig
|
boolean |
isUseOnlyAliases() |
<A extends ConfigActionDef> |
loadActions(A[] actions)
Load given actions.
|
<O extends ConfigOptionDef> |
loadDefaultOptions(O[] options)
Load default given options.
|
protected void |
loadResource(URI uri,
Properties properties)
Load a resources given by his
uri to the given
properties argument. |
ApplicationConfig |
parse(String... args)
Parse option and call set necessary method, read jvm, env variable,
Load configuration file and prepare Action.
|
void |
printConfig()
For debugging.
|
void |
printConfig(PrintStream output)
Print out current configuration in specified output.
|
protected void |
putAll(Properties prop,
ApplicationConfigScope scope) |
void |
putObject(Object o)
ajoute un objet dans le context, la classe de l'objet est utilise comme cle
|
void |
putObject(String name,
Object o)
ajoute un objet dans le context, 'name' est utilise comme cle
|
protected void |
remove(String key,
ApplicationConfigScope... scopes) |
String |
replaceRecursiveOptions(String option)
Replace included ${xxx} suboptions by their values.
|
void |
save(File file,
boolean forceAll,
String... excludeKeys)
Save configuration, in specified file.
|
void |
saveForCurrent(String... excludeKeys)
Save configuration, in current directory using the
getConfigFileName(). |
void |
saveForSystem(String... excludeKeys)
Save configuration, in system directory (/etc/) using the
getConfigFileName(). |
void |
saveForUser(String... excludeKeys)
Save configuration, in user home directory using the
getConfigFileName(). |
protected void |
saveResource(File file,
Properties properties,
String comment)
Save the given
properties into the given file with
the given comment. |
void |
setAppName(String appName)
Use appName to add a context in config.file and config.path options.
|
void |
setConfigFileName(String name)
Set name of file where options are read (in /etc, $HOME, $CURDIR)
This set used
setDefaultOption(String, String). |
void |
setDefaultOption(String key,
String value)
Used to put default configuration option in config option.
|
void |
setEncoding(String encoding)
Set the new encoding option.
|
void |
setOption(String key,
String value)
Set option value.
|
void |
setOptions(Properties options)
Set manually options when you don't want to use parse method to check
properties file configured by
setConfigFileName(String). |
void |
setUseOnlyAliases(boolean useOnlyAliases) |
public static final String LIST_SEPARATOR
public static final String CONFIG_FILE_NAME
public static final String CONFIG_ENCODING
public static final String APP_NAME
CONFIG_PATH et CONFIG_FILE_NAME.public static final String CONFIG_PATH
Use default system configuration if nothing is defined:
protected String osName
protected boolean useOnlyAliases
protected boolean inParseOptionPhase
protected EnumMap<ApplicationConfigScope,Properties> propertiesByScope
protected Map<String,ApplicationConfig.CacheItem<?>> cacheOption
protected List<String> unparsed
protected Map<Integer,List<ApplicationConfig.Action>> actions
protected Map<String,Object> context
protected ApplicationConfigReader configReader
protected ApplicationConfigWriter configWriter
public ApplicationConfig()
Also init converters.
ConverterUtil.initConverters()public ApplicationConfig(String configFilename)
configFilename - name of config to usepublic ApplicationConfig(Properties defaults)
Also init converters.
defaults - propertiesConverterUtil.initConverters()public ApplicationConfig(Properties defaults, String configFilename)
defaults - properties that override default value of optionClass, can be nullconfigFilename - override default config filename, can be nullpublic ApplicationConfig(ApplicationConfigInit init)
init - configuration builderpublic static String getUserHome()
user.home).protected void init(ApplicationConfigInit init)
init - l'objet d'initialisation de l'applicationConfigpublic String getUsername()
user.name).public String getOsName()
os.name).public String getOsArch()
os.arch).public <O extends ConfigOptionDef> void loadDefaultOptions(O[] options)
O - type of enum extend ConfigOptionDefoptions - options to loadpublic <A extends ConfigActionDef> void loadActions(A[] actions)
A - type of enum extend ConfigActionDefactions - actions to loadpublic void setDefaultOption(String key, String value)
key - default property keyvalue - default property valueprotected Properties getProperties(ApplicationConfigScope scope)
protected void putAll(Properties prop, ApplicationConfigScope scope)
public void save(File file, boolean forceAll, String... excludeKeys) throws IOException
file - file where config will be writenforceAll - if true save all config option
(with defaults, classpath, env, command line)excludeKeys - optional list of keys to exclude fromIOException - if IO pbpublic void saveForSystem(String... excludeKeys) throws ApplicationConfigSaveException
getConfigFileName(). Default, env and commande line note saved.excludeKeys - optional list of keys to exclude fromApplicationConfigSaveExceptionpublic void saveForUser(String... excludeKeys) throws ApplicationConfigSaveException
getConfigFileName(). Default, env and commande line note savedexcludeKeys - optional list of keys to exclude fromApplicationConfigSaveExceptionpublic void saveForCurrent(String... excludeKeys) throws ApplicationConfigSaveException
getConfigFileName().
Default, env and command line note saved.excludeKeys - optional list of keys to exclude fromApplicationConfigSaveExceptionpublic void cleanUserConfig(String... excludeKeys) throws ApplicationConfigSaveException
All options with an empty value will be removed from this file.
Moreover, like saveForUser(String...) the given
excludeKeys will never be saved.
This method can be useful when migrating some configuration from a version to another one with deprecated options (otherwise they will stay for ever in the configuration file with an empty value which is not acceptable). Important note: Using this method can have some strange side effects, since it could then allow to reuse default configurations from other level (default, env, jvm,...). Use with care only!
excludeKeys - optional list of key to not treat in cleaning process,
nor save in user user config file.ApplicationConfigSaveExceptionpublic File getSystemConfigFile() throws ApplicationConfigFileNameNotInitializedException
ApplicationConfigFileNameNotInitializedException - if no config file name found in configurationpublic File getUserConfigFile() throws ApplicationConfigFileNameNotInitializedException
ApplicationConfigFileNameNotInitializedException - if no config file name found in configurationpublic File getCurrentConfigFile() throws ApplicationConfigFileNameNotInitializedException
ApplicationConfigFileNameNotInitializedException - if no config file name found in configurationpublic List<String> getUnparsed()
public void addAction(ApplicationConfig.Action action)
action - action to add, can be null.public List<Integer> getActionStep()
public void doAllAction()
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException,
InstantiationException
IllegalAccessException - if action invocation failedIllegalArgumentException - if action invocation failedInvocationTargetException - if action invocation failedInstantiationException - if action invocation failedApplicationConfig.Action.Steppublic void doAction(int step)
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException,
InstantiationException
step - do action only defined in this stepIllegalAccessException - if action invocation failedIllegalArgumentException - if action invocation failedInvocationTargetException - if action invocation failedInstantiationException - if action invocation failedApplicationConfig.Action.Steppublic boolean isUseOnlyAliases()
public void setUseOnlyAliases(boolean useOnlyAliases)
public String getEncoding()
This value is stored as an option using the
getEncodingOption() key.
public void setEncoding(String encoding)
encoding - the new value of the option encodingpublic void addAlias(String alias, String... target)
alias - alias string as '-v'target - substitution as '--option verbose true'public void addActionAlias(String alias, String actionMethod)
addAlias(String, String...).alias - the alias to add for the given method actionactionMethod - must be fully qualified method path:
package.Class#methodpublic String getConfigFileName()
public void setConfigFileName(String name)
setDefaultOption(String, String).name - file nameprotected String getConfigFileNameOption()
protected String getEncodingOption()
public void setAppName(String appName)
Ex for an application named 'pollen' : config.file option becomes
pollen.config.file and config.path becomes
pollen.config.path
appName - to use as application contextpublic String getConfigPath()
Use (in order) one of the following definition:
CONFIG_PATH optionFile.separatorprotected String getSystemConfigurationPath()
Currently supported:
public String getUserConfigDirectory()
Currently supported:
Unix norm is based on freedesktop concept explained here : http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
public boolean hasOption(String key)
key - la clef de l'option à testertrue si l'option existe, false sinon.public boolean hasOption(ConfigOptionDef key)
key - la clef de l'option à testertrue si 'loption existe, false sinon.public void putObject(Object o)
o - l'objet à ajouterpublic void putObject(String name, Object o)
name - clef de l'optiono - value de l'optionpublic <E> E getObject(Class<E> clazz)
E peut prendre en argument du contruteur un objet de type ApplicationConfig
E - le type de l'option à récupérerclazz - le type de l'option à récupérer (ou créer)public <E> E getObject(Class<E> clazz, String name)
E peut prendre en argument du contruteur un objet de type ApplicationConfig
E - le type de l'option à récupérerclazz - le type de l'option à récupérer (ou créer)name - le nom de l'option à récupérer (ou créer)public Object getOptionAsObject(String key)
key - le nom de l'option à récupérerpublic <E> E getOptionAsObject(Class<E> clazz, String key)
E peut prendre en argument du contruteur un objet de type ApplicationConfig
E - le type de l'option à récupérerclazz - le type de l'option à récupérerkey - le nom de l'option à récupérerpublic Object getOptionAsSingleton(String key)
La classe peut avoir un constructeur prenant un ApplicationConfig
key - le nom de l'option à récupérerpublic <E> E getOptionAsSingleton(Class<E> clazz, String key)
La classe peut avoir un constructeur prenant un ApplicationConfig
E - le type de l'option à récupérerclazz - le type de l'option à récupérerkey - le nom de l'option à récupérerpublic void setOption(String key, String value)
key - property keyvalue - property valuepublic String getOption(String key)
Replace inner ${xxx} value.
key - the option's keypublic String replaceRecursiveOptions(String option)
option - option to replace intopublic ApplicationConfig getConfig(Map<String,String> overwrite)
overwrite - overwrite propertiespublic SubApplicationConfig getSubConfig(String prefix)
prefix - prefix to put automaticaly at beginning of all keypublic Properties getOptionStartsWith(String prefix)
prefix - debut de cle a recupererpublic Object getOption(ConfigOptionDef key)
key - the definition of the optionpublic <T> T getOption(Class<T> clazz, String key)
T - type of the object wanted as return typeclazz - type of object wanted as return typekey - the option's keyprotected <T> Object convertOption(Class<T> clazz, String key, String value, boolean asList)
example:
T - result type expectedclazz - result type expectedkey - option keyvalue - value to convertasList - value is string that represente a listpublic ApplicationConfig.OptionList getOptionAsList(String key)
key - the key of searched optionpublic File getOptionAsFile(String key)
File.key - the option's keypublic Color getOptionAsColor(String key)
Color.key - the option's keypublic Properties getOptionAsProperties(String key) throws IOException
Properties, this property must be a filepath
and file must be a properties.
Returned Properties is RecursiveProperties.
key - the option's keyIOException - if exception occured on read filepublic URL getOptionAsURL(String key)
URL.key - the option's keypublic Class<?> getOptionAsClass(String key)
Class.key - the option's keypublic Date getOptionAsDate(String key)
Date.key - the option's keypublic Time getOptionAsTime(String key)
Time.key - the option's keypublic Timestamp getOptionAsTimestamp(String key)
Timestamp.key - the option's keypublic int getOptionAsInt(String key)
int.key - the option's keyintpublic long getOptionAsLong(String key)
long.key - the option's keylongpublic float getOptionAsFloat(String key)
float.key - the option's keyfloatpublic double getOptionAsDouble(String key)
double.key - the option's keydoublepublic boolean getOptionAsBoolean(String key)
boolean.key - the option's keyboolean.public Locale getOptionAsLocale(String key)
Locale.key - the option's keyLocale.public org.nuiton.version.Version getOptionAsVersion(String key)
Version.key - the option's keyVersion.public KeyStroke getOptionAsKeyStroke(String key)
KeyStroke.key - the option's keyKeyStroke.public Properties getOptions()
public void setOptions(Properties options)
setConfigFileName(String).options - Properties which contains all options to setpublic Properties getFlatOptions()
Properties object (replace inner options).public Properties getFlatOptions(boolean replaceInner)
Properties object.replaceInner - if true replace imbricated options by theirs valuesprotected Map<String,Method> getMethods()
protected String[] getParams(Method m, ListIterator<String> args)
m - the method to callargs - iterator with many argument (equals or more than necessaryprotected ApplicationConfig.Action createAction(String name, ListIterator<String> args) throws ArgumentsParserException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
name - name of the actionargs - arguments for action invocationArgumentsParserException - if parsing failedIllegalAccessException - if could not create actionIllegalArgumentException - if could not create actionInstantiationException - if could not create actionInvocationTargetException - if could not create actionpublic ApplicationConfig parse(String... args) throws ArgumentsParserException
args - argument as main(String[] args)ArgumentsParserException - if parsing failedprotected void loadResource(URI uri, Properties properties) throws IOException
uri to the given
properties argument.uri - the uri to loadproperties - the properties file to loadIOException - if something occurs bad while loading resourceProperties.load(Reader)protected void saveResource(File file, Properties properties, String comment)
properties into the given file with
the given comment.file - the location where to store the propertiesproperties - the properties file to savecomment - the comment to add in the saved fileProperties.store(Writer, String)public void printConfig()
public void printConfig(PrintStream output)
output - output to write config topublic String getPrintableConfig(String includePattern, int padding)
includePattern - null for all value, or config key pattern (ex: "wikitty.*")padding - for better presentation, you can use padding to align '=' signprotected void remove(String key, ApplicationConfigScope... scopes)
Copyright © 2016–2018 Ultreia.io. All rights reserved.