From d8cec8534e2c9ffd0056665f9421710e44a3ebec Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 2 Feb 2015 11:28:54 +0100 Subject: [PATCH] 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 --- .../beans/factory/config/YamlProcessor.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java index 89a7687b1e..67aa52c91a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java +++ b/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();