You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2016/02/17 01:21:07 UTC
[2/5] incubator-tamaya git commit: Added ConfigurationContext to
ConversionContext.
Added ConfigurationContext to ConversionContext.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/ce626a1b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/ce626a1b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/ce626a1b
Branch: refs/heads/master
Commit: ce626a1b5181aca965b522046a6cdfd69dc8edfe
Parents: de7bb74
Author: anatole <an...@apache.org>
Authored: Wed Feb 17 00:33:30 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Feb 17 00:33:30 2016 +0100
----------------------------------------------------------------------
.../apache/tamaya/spi/ConversionContext.java | 26 +++++++++++++++++---
.../core/internal/DefaultConfiguration.java | 4 +--
2 files changed, 25 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ce626a1b/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java b/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
index 14e683f..4a470b0 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
@@ -40,6 +40,7 @@ public class ConversionContext {
private final TypeLiteral<?> targetType;
private final AnnotatedElement annotatedElement;
private final List<String> supportedFormats = new ArrayList<>();
+ private final ConfigurationContext configurationContext;
/**
* Private constructor used from builder.
@@ -51,6 +52,7 @@ public class ConversionContext {
this.targetType = builder.targetType;
this.supportedFormats.addAll(builder.supportedFormats);
this.configuration = builder.configuration;
+ this.configurationContext = builder.configurationContext;
}
/**
@@ -124,12 +126,18 @@ public class ConversionContext {
'}';
}
+ public ConfigurationContext getConfigurationContext() {
+ return configurationContext;
+ }
+
/**
* Builder to create new instances of {@link ConversionContext}.
*/
public static final class Builder{
/** The backing configuration. */
private Configuration configuration;
+ /** The configuration context. */
+ private ConfigurationContext configurationContext;
/** The accessed key, or null. */
private String key;
/** The target type. */
@@ -144,7 +152,7 @@ public class ConversionContext {
* @param targetType the target type
*/
public Builder(TypeLiteral<?> targetType) {
- this(null, null, targetType);
+ this(null, null, null, targetType);
}
/**
@@ -153,7 +161,7 @@ public class ConversionContext {
* @param targetType the target type
*/
public Builder(String key, TypeLiteral<?> targetType) {
- this(null, key, targetType);
+ this(null, null, key, targetType);
}
/**
@@ -162,9 +170,10 @@ public class ConversionContext {
* @param key the requested key, may be null.
* @param targetType the target type
*/
- public Builder(Configuration configuration, String key, TypeLiteral<?> targetType){
+ public Builder(Configuration configuration, ConfigurationContext context, String key, TypeLiteral<?> targetType){
this.key = key;
this.configuration = configuration;
+ this.configurationContext = context;
this.targetType = Objects.requireNonNull(targetType);
}
@@ -189,6 +198,16 @@ public class ConversionContext {
}
/**
+ * Sets the configuration.
+ * @param configurationContext the configuration, not null
+ * @return the builder instance, for chaining
+ */
+ public Builder setConfigurationContext(ConfigurationContext configurationContext){
+ this.configurationContext = Objects.requireNonNull(configurationContext);
+ return this;
+ }
+
+ /**
* Sets the annotated element, when configuration is injected.
* @param annotatedElement the annotated element, not null
* @return the builder instance, for chaining
@@ -224,6 +243,7 @@ public class ConversionContext {
public String toString() {
return "Builder{" +
"configuration=" + configuration +
+ "context=" + configurationContext +
", key='" + key + '\'' +
", targetType=" + targetType +
", annotatedElement=" + annotatedElement +
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ce626a1b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index 0f74628..9e50c87 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -168,7 +168,7 @@ public class DefaultConfiguration implements Configuration {
protected <T> T convertValue(String key, String value, TypeLiteral<T> type) {
if (value != null) {
List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
- ConversionContext context = new ConversionContext.Builder(this, key, type).build();
+ ConversionContext context = new ConversionContext.Builder(this, this.configurationContext, key, type).build();
for (PropertyConverter<T> converter : converters) {
try {
T t = converter.convert(value, context);
@@ -176,7 +176,7 @@ public class DefaultConfiguration implements Configuration {
return t;
}
} catch (Exception e) {
- LOG.log(Level.FINEST, "PropertyConverter: " + converter + " failed to convert value: " + value, e);
+ LOG.log(Level.INFO, "PropertyConverter: " + converter + " failed to convert value: " + value, e);
}
}
throw new ConfigException("Unparseable config value for type: " + type.getRawType().getName() + ": " + key +