public final class ConfigurationBuffer extends Object
- You should be able to configure absolutely any object.
- Child configuration variables in your config become a dotted hierarchy of
varnames
- All sources of configuration data are buffered and merged (as string
var/vals) before committing to the final configuration. This class acts as
the buffer.
- Hyphenated variables (i.e. "some-var") are automatically configured by
calling your matching setter (i.e. setSomeVar)
- Implementing an getSomeVarInfo() method on your class lets you set up more
complicated config objects
- You can make variables depend on other variables having been set first.
This lets you set a root directory in one var and then use its value in
another.
- Per-variable validation can be performed in setters. Overall validation
should take place as a post-process step.
- You can keep ConfigurationBuffers around and merge multiple buffers
together before committing. Most recent definitions always win.
The contract with your configuration class:
- You must provide a method with the signature
"void setYourVar(ConfigurationValue val)" to set your config var. Your setter
method should accept either a single arg of type List or String[], or else an
arglist of simple types. For example
"void myvar(int a, boolean b, String c")".
- You can implement a function with the signature "int yourvar_argcount()" to
require a different number of arguments. This limit will be enforced by
configurators (command line, file, etc.)
- If you provide a setter and explicit parameters (i.e. not List or String[])
the number of arguments will be automatically determined.
- Each argument to your configuration variable is assumed to have a
(potentially non-unique) name. The default is the simple type of the argument
(boolean, int, string). If the var takes an undetermined number of args via
List or String[], the argname defaults to string.
- You can implement a function with the signature
"String yourvar_argnames(int)" to provide names for each of the parameters.
The integer passed in is the argument number. Return the same name (i.e.
"item") for infinite lists.
- You can implement a function with the signature "String[] yourvar_deps()"
to provide a list of other prerequisites for this var. You will be guaranteed
that the deps are committed before your var, or else a configurationexception
will be thrown if a prerequsite was unset. (Note that infinite cycles are not
checked, so be careful.)
| Constructor and Description |
|---|
ConfigurationBuffer(Class<? extends Configuration> configClass) |
ConfigurationBuffer(Class<? extends Configuration> configClass,
Map<String,String> aliases) |
ConfigurationBuffer(Class<? extends Configuration> configClass,
Map<String,String> aliases,
org.apache.royale.compiler.internal.config.IConfigurationFilter filter)
Create a configuration buffer with an optional filter.
|
ConfigurationBuffer(ConfigurationBuffer copyFrom,
boolean copyCommitted) |
| Modifier and Type | Method and Description |
|---|---|
void |
addAlias(String alias,
String var) |
void |
addPosition(String var,
int iStart,
int iEnd) |
protected static String |
c2h(String camel)
convert StudlyCaps or camelCase to hyphenated
|
void |
clearSourceVars(String source)
Remove the configuration values came from the given source.
|
void |
clearVar(String avar,
String source,
int line) |
boolean |
commit(Object config,
Collection<org.apache.royale.compiler.problems.ICompilerProblem> problems)
commit - bake the resolved map to the configuration
|
List<String> |
dump() |
static List<String> |
formatText(String input,
int columns) |
Map<String,String> |
getAliases() |
ConfigurationInfo |
getInfo(String avar) |
List<Object[]> |
getPositions() |
String |
getToken(String token) |
List<ConfigurationValue> |
getVar(String avar) |
int |
getVarArgCount(String avar) |
String |
getVarArgName(String avar,
int argnum) |
Set<String> |
getVars() |
protected static String |
h2c(String hyphenated,
boolean studly)
convert hyphenated to StudlyCaps or camelCase
|
protected static boolean |
isSupportedListType(Class<?> c) |
protected static boolean |
isSupportedSimpleType(Class<?> c) |
protected static boolean |
isSupportedValueType(Class<?> c) |
boolean |
isValidVar(String avar) |
void |
merge(ConfigurationBuffer other) |
List<ConfigurationValue> |
peekConfigurationVar(String avar) |
String |
peekSimpleConfigurationVar(String avar) |
List<String> |
processValues(String var,
List<String> args,
String source,
int line) |
void |
setToken(String token,
String value) |
void |
setVar(String var,
List<String> vals,
String source,
int line) |
void |
setVar(String avar,
List<String> vals,
String source,
int line,
String contextPath,
boolean append) |
void |
setVar(String var,
String val,
String source,
int line) |
String |
toString()
For debugging only.
|
String |
unalias(String var) |
static String |
varname(String membername,
String basename) |
public ConfigurationBuffer(Class<? extends Configuration> configClass)
public ConfigurationBuffer(Class<? extends Configuration> configClass, Map<String,String> aliases)
public ConfigurationBuffer(Class<? extends Configuration> configClass, Map<String,String> aliases, org.apache.royale.compiler.internal.config.IConfigurationFilter filter)
filter - if null there is no filter, otherwise the set of
configuration options is filtered.public ConfigurationBuffer(ConfigurationBuffer copyFrom, boolean copyCommitted)
public void setVar(String var, String val, String source, int line) throws org.apache.royale.compiler.exceptions.ConfigurationException
org.apache.royale.compiler.exceptions.ConfigurationExceptionpublic void setVar(String var, List<String> vals, String source, int line) throws org.apache.royale.compiler.exceptions.ConfigurationException
org.apache.royale.compiler.exceptions.ConfigurationExceptionpublic void setVar(String avar, List<String> vals, String source, int line, String contextPath, boolean append) throws org.apache.royale.compiler.exceptions.ConfigurationException
org.apache.royale.compiler.exceptions.ConfigurationExceptionpublic void clearVar(String avar, String source, int line) throws org.apache.royale.compiler.exceptions.ConfigurationException
org.apache.royale.compiler.exceptions.ConfigurationExceptionpublic void clearSourceVars(String source)
source - source nameCommandLineConfigurator.SOURCE_COMMAND_LINEpublic List<String> processValues(String var, List<String> args, String source, int line) throws org.apache.royale.compiler.exceptions.ConfigurationException
org.apache.royale.compiler.exceptions.ConfigurationExceptionpublic List<ConfigurationValue> getVar(String avar)
public void merge(ConfigurationBuffer other)
protected static String c2h(String camel)
camel - someVar or SomeVarprotected static String h2c(String hyphenated, boolean studly)
hyphenated - some-varpublic ConfigurationInfo getInfo(String avar)
public boolean isValidVar(String avar)
public int getVarArgCount(String avar)
public boolean commit(Object config, Collection<org.apache.royale.compiler.problems.ICompilerProblem> problems)
config - The configuration to set the buffer variables into.problems - A collection where configuration problems are reported.protected static boolean isSupportedSimpleType(Class<?> c)
protected static boolean isSupportedListType(Class<?> c)
protected static boolean isSupportedValueType(Class<?> c)
public String peekSimpleConfigurationVar(String avar) throws org.apache.royale.compiler.exceptions.ConfigurationException
org.apache.royale.compiler.exceptions.ConfigurationExceptionpublic List<ConfigurationValue> peekConfigurationVar(String avar) throws org.apache.royale.compiler.exceptions.ConfigurationException
org.apache.royale.compiler.exceptions.ConfigurationExceptionpublic void addPosition(String var, int iStart, int iEnd)
Copyright © 2023 The Apache Software Foundation. All rights reserved.