public class ConfTreeOperations extends Object
| Modifier and Type | Field and Description |
|---|---|
ConfTree |
confTree |
protected static org.slf4j.Logger |
log |
| Constructor and Description |
|---|
ConfTreeOperations(ConfTree confTree) |
| Modifier and Type | Method and Description |
|---|---|
static ConfTreeOperations |
fromFile(File resource)
Load from a resource.
|
static ConfTreeOperations |
fromInstance(ConfTree instance)
Build from an existing instance -which is cloned via JSON ser/deser
|
static ConfTreeOperations |
fromResource(String resource)
Load from a resource.
|
String |
get(String key)
get a global option
|
MapOperations |
getComponent(String component)
look up a component and return its options
|
Set<String> |
getComponentNames() |
String |
getComponentOpt(String name,
String option,
String defVal)
Get a component option
|
int |
getComponentOptInt(String name,
String option,
int defVal)
Get a component opt; use
Integer.decode(String) so as to take hex
oct and bin values too. |
Map<String,Map<String,String>> |
getComponents()
Get at the underlying component map
|
ConfTree |
getConfTree()
Get the underlying conf tree
|
MapOperations |
getGlobalOptions()
Get operations on the global set
|
MapOperations |
getMandatoryComponent(String name)
Get a component whose presence is mandatory
|
MapOperations |
getOrAddComponent(String name)
Get a component -adding it to the components map if
none with that name exists
|
void |
merge(ConfTree that)
Merge in another tree with overwrites
|
void |
mergeComponents(Map<String,Map<String,String>> commandOptions)
Merge in components
|
void |
mergeComponentsPrefix(Map<String,Map<String,String>> commandOptions,
String prefix,
boolean overwrite)
Merge in components
|
void |
mergeFile(File file)
Load from a file and merge it in
|
void |
mergeFile(File file,
InputPropertiesValidator validator)
Load from a file and merge it in
|
void |
mergeInGlobal(Map<String,String> component)
Merge any options
|
void |
mergeSingleComponentMap(String component,
Map<String,String> map)
Merge the map of a single component
|
void |
mergeSingleComponentMapPrefix(String component,
Map<String,String> map,
String prefix,
boolean overwrite)
Merge the map of a single component
|
void |
mergeWithoutOverwrite(ConfTree that)
Merge in another tree -no overwrites of global or conf data
(note that metadata does a naive putAll merge/overwrite)
|
void |
propagateGlobalKeys(ConfTreeOperations src,
String prefix)
Propagate all global keys matching a prefix
|
void |
propagateGlobalKeys(ConfTree src,
String prefix)
Propagate all global keys matching a prefix
|
void |
resolve()
Resolve a ConfTree by mapping all global options into each component
-if there is none there already
|
void |
set(String key,
Object value)
Set a global option, converting it to a string as needed
|
void |
setComponentOpt(String role,
String option,
int val)
Set an integer role option, creating the role if necessary
|
void |
setComponentOpt(String role,
String option,
long val)
Set a long role option, creating the role if necessary
|
void |
setComponentOpt(String component,
String option,
String val)
Set a component option, creating the component if necessary
|
String |
toJson()
Convert to a JSON string
|
String |
toString() |
void |
validate()
Validate the configuration
|
void |
validate(InputPropertiesValidator validator)
Validate the configuration
|
public final ConfTree confTree
protected static final org.slf4j.Logger log
public ConfTreeOperations(ConfTree confTree)
public ConfTree getConfTree()
public void validate()
throws BadConfigException
BadConfigExceptionpublic void validate(InputPropertiesValidator validator) throws BadConfigException
validator - a provided properties validatorBadConfigExceptionpublic void resolve()
public void mergeInGlobal(Map<String,String> component)
component - dest valuespublic MapOperations getGlobalOptions()
public MapOperations getComponent(String component)
component - component namepublic Map<String,Map<String,String>> getComponents()
public MapOperations getOrAddComponent(String name)
name - rolepublic MapOperations getMandatoryComponent(String name) throws BadConfigException
name - component nameBadConfigException - if the name is not therepublic void set(String key, Object value)
key - keyvalue - non null valuepublic void propagateGlobalKeys(ConfTree src, String prefix)
src - sourceprefix - prefixpublic void propagateGlobalKeys(ConfTreeOperations src, String prefix)
src - sourceprefix - prefixpublic void mergeSingleComponentMap(String component, Map<String,String> map)
component - component namemap - map to mergepublic void mergeSingleComponentMapPrefix(String component, Map<String,String> map, String prefix, boolean overwrite)
component - component namemap - map to mergepublic void mergeComponents(Map<String,Map<String,String>> commandOptions)
commandOptions - component options on the CLIpublic void mergeComponentsPrefix(Map<String,Map<String,String>> commandOptions, String prefix, boolean overwrite)
commandOptions - component options on the CLIpublic void mergeWithoutOverwrite(ConfTree that)
that - the other treepublic void merge(ConfTree that)
that - the other treepublic static ConfTreeOperations fromResource(String resource) throws IOException
resource - resourceIOException - load failurepublic static ConfTreeOperations fromFile(File resource) throws IOException
resource - resourceIOException - load failurepublic static ConfTreeOperations fromInstance(ConfTree instance) throws IOException
instance - the source instanceIOException - load failurepublic void mergeFile(File file) throws IOException, BadConfigException
file - fileIOException - any IO problemBadConfigException - if the file is invalidpublic void mergeFile(File file, InputPropertiesValidator validator) throws IOException, BadConfigException
file - filevalidator - properties validatorIOException - any IO problemBadConfigException - if the file is invalidpublic String toJson() throws IOException, org.codehaus.jackson.JsonGenerationException, org.codehaus.jackson.map.JsonMappingException
IOExceptionorg.codehaus.jackson.JsonGenerationExceptionorg.codehaus.jackson.map.JsonMappingExceptionpublic String getComponentOpt(String name, String option, String defVal)
name - component nameoption - option namedefVal - default valuepublic int getComponentOptInt(String name, String option, int defVal)
Integer.decode(String) so as to take hex
oct and bin values too.name - component nameoption - option namedefVal - default valueNumberFormatException - if the role could not be parsed.public void setComponentOpt(String component, String option, String val)
component - component nameoption - option nameval - valuepublic void setComponentOpt(String role, String option, int val)
role - role nameoption - option nameval - integer valueCopyright © 2014–2015 The Apache Software Foundation. All rights reserved.