Allow subclasses to configure the Yaml instance

Provide an additional hook-point for YamlProcessor subclasses willing to
change how the Yaml instance is configured. Also expose the default
StrictMapAppenderConstructor so that  they can compose a custom instance
with it.

Issue: SPR-12671
master
Stephane Nicoll 10 years ago
parent a32b5e61d0
commit d8cec8534e
  1. 16
      spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java

@ -130,9 +130,10 @@ public abstract class YamlProcessor {
* Properties. Depending on the {@link #setResolutionMethod(ResolutionMethod)} not all
* of the documents will be parsed.
* @param callback a callback to delegate to once matching documents are found
* @see #createYaml()
*/
protected void process(MatchCallback callback) {
Yaml yaml = new Yaml(new StrictMapAppenderConstructor());
Yaml yaml = createYaml();
for (Resource resource : this.resources) {
boolean found = process(callback, yaml, resource);
if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND && found) {
@ -141,6 +142,13 @@ public abstract class YamlProcessor {
}
}
/**
* Create the {@link Yaml} instance to use.
*/
protected Yaml createYaml() {
return new Yaml(new StrictMapAppenderConstructor());
}
private boolean process(MatchCallback callback, Yaml yaml, Resource resource) {
int count = 0;
try {
@ -331,7 +339,7 @@ public abstract class YamlProcessor {
/**
* Status returned from {@link DocumentMatcher#matches(java.util.Properties)}
*/
public static enum MatchStatus {
public enum MatchStatus {
/**
* A match was found.
@ -360,7 +368,7 @@ public abstract class YamlProcessor {
/**
* Method to use for resolving resources.
*/
public static enum ResolutionMethod {
public enum ResolutionMethod {
/**
* Replace values from earlier in the list.
@ -382,7 +390,7 @@ public abstract class YamlProcessor {
/**
* A specialized {@link Constructor} that checks for duplicate keys.
*/
private static class StrictMapAppenderConstructor extends Constructor {
protected static class StrictMapAppenderConstructor extends Constructor {
public StrictMapAppenderConstructor() {
super();

Loading…
Cancel
Save