public abstract class YamlProcessor
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
YamlProcessor.DocumentMatcher
Strategy interface used to test if properties match.
|
static interface |
YamlProcessor.MatchCallback
Callback interface used to process the YAML parsing results.
|
static class |
YamlProcessor.MatchStatus
Status returned from
YamlProcessor.DocumentMatcher.matches(java.util.Properties) |
static class |
YamlProcessor.ResolutionMethod
Method to use for resolving resources.
|
protected static class |
YamlProcessor.StrictMapAppenderConstructor
A specialized
Constructor that checks for duplicate keys. |
Modifier and Type | Field and Description |
---|---|
private java.util.List<YamlProcessor.DocumentMatcher> |
documentMatchers |
private Log |
logger |
private boolean |
matchDefault |
private YamlProcessor.ResolutionMethod |
resolutionMethod |
private Resource[] |
resources |
Constructor and Description |
---|
YamlProcessor() |
Modifier and Type | Method and Description |
---|---|
private java.util.Map<java.lang.String,java.lang.Object> |
asMap(java.lang.Object object) |
private void |
buildFlattenedMap(java.util.Map<java.lang.String,java.lang.Object> result,
java.util.Map<java.lang.String,java.lang.Object> source,
java.lang.String path) |
protected Yaml |
createYaml()
Create the
Yaml instance to use. |
protected java.util.Map<java.lang.String,java.lang.Object> |
getFlattenedMap(java.util.Map<java.lang.String,java.lang.Object> source)
Return a flattened version of the given map, recursively following any nested Map
or Collection values.
|
private void |
handleProcessError(Resource resource,
java.io.IOException ex) |
private boolean |
process(java.util.Map<java.lang.String,java.lang.Object> map,
YamlProcessor.MatchCallback callback) |
protected void |
process(YamlProcessor.MatchCallback callback)
Provide an opportunity for subclasses to process the Yaml parsed from the supplied
resources.
|
private boolean |
process(YamlProcessor.MatchCallback callback,
Yaml yaml,
Resource resource) |
void |
setDocumentMatchers(YamlProcessor.DocumentMatcher... matchers)
A map of document matchers allowing callers to selectively use only
some of the documents in a YAML resource.
|
void |
setMatchDefault(boolean matchDefault)
Flag indicating that a document for which all the
document matchers abstain will
nevertheless match. |
void |
setResolutionMethod(YamlProcessor.ResolutionMethod resolutionMethod)
Method to use for resolving resources.
|
void |
setResources(Resource... resources)
Set locations of YAML
resources to be loaded. |
private final Log logger
private YamlProcessor.ResolutionMethod resolutionMethod
private Resource[] resources
private java.util.List<YamlProcessor.DocumentMatcher> documentMatchers
private boolean matchDefault
public void setDocumentMatchers(YamlProcessor.DocumentMatcher... matchers)
--- lines, and each document is converted
to properties before the match is made. E.g.
environment: dev
url: https://dev.bar.com
name: Developer Setup
---
environment: prod
url:https://foo.bar.com
name: My Cool App
when mapped with
setDocumentMatchers(properties ->
("prod".equals(properties.getProperty("environment")) ? MatchStatus.FOUND : MatchStatus.NOT_FOUND));
would end up as
environment=prod
url=https://foo.bar.com
name=My Cool App
public void setMatchDefault(boolean matchDefault)
document matchers
abstain will
nevertheless match. Default is true
.public void setResolutionMethod(YamlProcessor.ResolutionMethod resolutionMethod)
YamlProcessor.ResolutionMethod.OVERRIDE
.public void setResources(Resource... resources)
resources
to be loaded.YamlProcessor.ResolutionMethod
protected void process(YamlProcessor.MatchCallback callback)
matchers
. If a document
matches it is passed into the callback, along with its representation as Properties.
Depending on the setResolutionMethod(ResolutionMethod)
not all of the
documents will be parsed.callback
- a callback to delegate to once matching documents are foundcreateYaml()
protected Yaml createYaml()
Yaml
instance to use.private boolean process(YamlProcessor.MatchCallback callback, Yaml yaml, Resource resource)
private void handleProcessError(Resource resource, java.io.IOException ex)
private java.util.Map<java.lang.String,java.lang.Object> asMap(java.lang.Object object)
private boolean process(java.util.Map<java.lang.String,java.lang.Object> map, YamlProcessor.MatchCallback callback)
protected final java.util.Map<java.lang.String,java.lang.Object> getFlattenedMap(java.util.Map<java.lang.String,java.lang.Object> source)
YamlProcessor.MatchCallback
the result will
contain the same values as the YamlProcessor.MatchCallback
Properties.source
- the source mapprivate void buildFlattenedMap(java.util.Map<java.lang.String,java.lang.Object> result, java.util.Map<java.lang.String,java.lang.Object> source, java.lang.String path)