org.springframework.boot.config
Class YamlProcessor

java.lang.Object
  extended by org.springframework.boot.config.YamlProcessor
Direct Known Subclasses:
YamlMapFactoryBean, YamlPropertiesFactoryBean

public class YamlProcessor
extends Object

Base class for Yaml factories.

Author:
Dave Syer

Nested Class Summary
static interface YamlProcessor.DocumentMatcher
          Strategy interface used the test if properties match.
static interface YamlProcessor.MatchCallback
          Callback interface used to process properties in a resulting map.
static class YamlProcessor.MatchStatus
          Status returned from YamlProcessor.DocumentMatcher.matches(Properties)
static class YamlProcessor.ResolutionMethod
          Resolution methods.
 
Constructor Summary
YamlProcessor()
           
 
Method Summary
protected  void process(YamlProcessor.MatchCallback callback)
          Provides an opportunity for subclasses to process the Yaml parsed from the supplied resources.
 void setDocumentMatchers(List<? extends 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(org.springframework.core.io.Resource[] resources)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

YamlProcessor

public YamlProcessor()
Method Detail

setDocumentMatchers

public void setDocumentMatchers(List<? extends YamlProcessor.DocumentMatcher> matchers)
A map of document matchers allowing callers to selectively use only some of the documents in a YAML resource. In YAML documents are separated by --- lines, and each document is converted to properties before the match is made. E.g.
 environment: dev
 url: http://dev.bar.com
 name: Developer Setup
 ---
 environment: prod
 url:http://foo.bar.com
 name: My Cool App
 
when mapped with documentMatchers = YamlProcessor.mapMatcher({"environment": "prod"}) would end up as
 environment=prod
 url=http://foo.bar.com
 name=My Cool App
 url=http://dev.bar.com
 

Parameters:
matchers - a map of keys to value patterns (regular expressions)

setMatchDefault

public void setMatchDefault(boolean matchDefault)
Flag indicating that a document for which all the document matchers abstain will nevertheless match.

Parameters:
matchDefault - the flag to set (default true)

setResolutionMethod

public void setResolutionMethod(YamlProcessor.ResolutionMethod resolutionMethod)
Method to use for resolving resources. Each resource will be converted to a Map, so this property is used to decide which map entries to keep in the final output from this factory.

Parameters:
resolutionMethod - the resolution method to set (defaults to YamlProcessor.ResolutionMethod.OVERRIDE).

setResources

public void setResources(org.springframework.core.io.Resource[] resources)
Parameters:
resources - the resources to set

process

protected void process(YamlProcessor.MatchCallback callback)
Provides an opportunity for subclasses to process the Yaml parsed from the supplied resources. Each resource is parsed in turn and the documents inside checked against the 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.

Parameters:
callback - a callback to delegate to once matching documents are found


Copyright © 2013. All Rights Reserved.