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 configClass) |
ConfigurationBuffer(Class configClass,
Map<String,String> aliases) |
ConfigurationBuffer(Class configClass,
Map<String,String> aliases,
ConfigurationFilter 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 |
calculateChecksum(String name,
Long lastModified) |
void |
calculateChecksum(VirtualFile f) |
void |
calculateLinkChecksum(String name,
Long lastModified) |
int |
checksum_ts()
This value takes timestamps into account and is the actual value embedded in the cache file.
|
int |
checksum()
This value is good for naming the cache file.
|
void |
clearSourceVars(String source) |
void |
clearVar(String avar,
String source,
int line) |
void |
commit(Object config)
commit - bake the resolved map to the configuration
|
static List<String> |
formatText(String input,
int columns) |
Map<String,String> |
getAliases() |
Class |
getChildConfigClass(String var) |
ConfigurationInfo |
getInfo(String avar) |
List<Object[]> |
getPositions() |
String |
getToken(String token) |
List |
getVar(String avar) |
Iterator<String> |
getVarIterator() |
protected static String |
h2c(String hyphenated,
boolean studly)
convert hyphenated to StudlyCaps or camelCase
|
boolean |
isChildConfig(String var) |
protected static boolean |
isSupportedListType(Class c) |
protected static boolean |
isSupportedSimpleType(Class c) |
protected static boolean |
isSupportedValueType(Class c) |
boolean |
isValidVar(String avar) |
int |
link_checksum_ts() |
void |
merge(ConfigurationBuffer other) |
void |
mergeChild(String prefix,
ConfigurationBuffer child) |
List<ConfigurationValue> |
peekConfigurationVar(String avar) |
String |
peekSimpleConfigurationVar(String avar) |
List<String> |
processValues(String var,
List<String> args,
String source,
int line) |
void |
setDefaultVar(String var) |
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 |
unalias(String var) |
public ConfigurationBuffer(Class configClass)
public ConfigurationBuffer(Class configClass, Map<String,String> aliases, ConfigurationFilter 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 ConfigurationException
ConfigurationException
public void setVar(String var, List<String> vals, String source, int line) throws ConfigurationException
ConfigurationException
public void setVar(String avar, List<String> vals, String source, int line, String contextPath, boolean append) throws ConfigurationException
ConfigurationException
public void clearVar(String avar, String source, int line) throws ConfigurationException
ConfigurationException
public void clearSourceVars(String source)
public List<String> processValues(String var, List<String> args, String source, int line) throws ConfigurationException
ConfigurationException
public void merge(ConfigurationBuffer other)
public void mergeChild(String prefix, ConfigurationBuffer child)
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 boolean isChildConfig(String var)
public void commit(Object config) throws ConfigurationException
ConfigurationException
protected static boolean isSupportedSimpleType(Class c)
protected static boolean isSupportedListType(Class c)
protected static boolean isSupportedValueType(Class c)
public String peekSimpleConfigurationVar(String avar) throws ConfigurationException
ConfigurationException
public List<ConfigurationValue> peekConfigurationVar(String avar) throws ConfigurationException
ConfigurationException
public void addPosition(String var, int iStart, int iEnd)
public void setDefaultVar(String var)
public void calculateChecksum(VirtualFile f)
public int checksum()
public int checksum_ts()
public int link_checksum_ts()
Copyright © 2016 The Apache Software Foundation. All rights reserved.