try { ConversionContext ctx = new ConversionContext.Builder(key,targetType) .setAnnotatedElement(element).build(); List<PropertyConverter<T>> converters = configContext .getPropertyConverters(targetType); ConversionContext ctx = new ConversionContext.Builder(ConfigurationProvider.getConfiguration(), configContext, key, targetType).setAnnotatedElement(element).build(); for (PropertyConverter<T> converter : converters) { adaptedValue = converter.convert(configValue, ctx);
List<PropertyConverter<T>> converters = ConfigurationProvider.getConfigurationContext() .getPropertyConverters(type); ConversionContext context = new ConversionContext.Builder(this, ConfigurationProvider.getConfigurationContext(), key,type).build(); for (PropertyConverter<T> converter : converters) { try {
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, this.configurationContext, key, type) .build(); for (PropertyConverter<T> converter : converters) { try { T t = converter.convert(value, context); if (t != null) { return t; } } catch (Exception e) { LOG.log(Level.INFO, "PropertyConverter: " + converter + " failed to convert value: " + value, e); } } // if the target type is a String, we can return the value, no conversion required. if(type.equals(TypeLiteral.of(String.class))){ return (T)value; } // unsupported type, throw an exception throw new ConfigException("Unparseable config value for type: " + type.getRawType().getName() + ": " + key + ", supported formats: " + context.getSupportedFormats()); } return null; }
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, this.configurationContext, key, type) .build(); for (PropertyConverter<T> converter : converters) { try { T t = converter.convert(value, context); if (t != null) { return t; } } catch (Exception e) { LOG.log(Level.FINEST, "PropertyConverter: " + converter + " failed to convert value: " + value, e); } } // if the target type is a String, we can return the value, no conversion required. if(type.equals(TypeLiteral.of(String.class))){ return (T)value; } // unsupported type, throw an exception throw new ConfigException("Unparseable config value for type: " + type.getRawType().getName() + ": " + key + ", supported formats: " + context.getSupportedFormats()); } return null; }
/** * Evaluates the current value dynamically from the underlying configuration. * * @return the current actual value, or null. */ public T evaluateValue() { T value = null; for (String key : keys) { ConversionContext ctx = new ConversionContext.Builder(key, targetType).build(); if (propertyConverter == null) { value = configuration.get(key, targetType); } else { String source = configuration.get(key); value = propertyConverter.convert(source, ctx); } if (value != null) { break; } } return value; }