private <T> T handleBindResult(ConfigurationPropertyName name, Bindable<T> target, BindHandler handler, Context context, Object result) throws Exception { if (result != null) { result = handler.onSuccess(name, target, context, result); result = context.getConverter().convert(result, target); } handler.onFinish(name, target, context, result); return context.getConverter().convert(result, target); }
public <T> T convert(Object result, Bindable<T> target) { return convert(result, target.getType(), target.getAnnotations()); }
private <T> Object bindProperty(Bindable<T> target, Context context, ConfigurationProperty property) { context.setConfigurationProperty(property); Object result = property.getValue(); result = this.placeholdersResolver.resolvePlaceholders(result); result = context.getConverter().convert(result, target); return result; }
private <T> T handleBindError(ConfigurationPropertyName name, Bindable<T> target, BindHandler handler, Context context, Exception error) { try { Object result = handler.onFailure(name, target, context, error); return context.getConverter().convert(result, target); } catch (Exception ex) { if (ex instanceof BindException) { throw (BindException) ex; } throw new BindException(name, target, context.getConfigurationProperty(), ex); } }
public void bindEntries(ConfigurationPropertySource source, Map<Object, Object> map) { if (source instanceof IterableConfigurationPropertySource) { for (ConfigurationPropertyName name : (IterableConfigurationPropertySource) source) { Bindable<?> valueBindable = getValueBindable(name); ConfigurationPropertyName entryName = getEntryName(source, name); Object key = getContext().getConverter() .convert(getKeyName(entryName), this.keyType); map.computeIfAbsent(key, (k) -> this.elementBinder.bind(entryName, valueBindable)); } } }
private <C> C convert(Object value, ResolvableType type, Annotation... annotations) { value = getContext().getPlaceholdersResolver().resolvePlaceholders(value); return getContext().getConverter().convert(value, type, annotations); }
@Override protected Object bindAggregate(ConfigurationPropertyName name, Bindable<?> target, AggregateElementBinder elementBinder) { Map<Object, Object> map = CollectionFactory.createMap((target.getValue() != null) ? Map.class : target.getType().resolve(Object.class), 0); Bindable<?> resolvedTarget = resolveTarget(target); boolean hasDescendants = hasDescendants(name); for (ConfigurationPropertySource source : getContext().getSources()) { if (!ConfigurationPropertyName.EMPTY.equals(name)) { ConfigurationProperty property = source.getConfigurationProperty(name); if (property != null && !hasDescendants) { return getContext().getConverter().convert(property.getValue(), target); } source = source.filter(name::isAncestorOf); } new EntryBinder(name, resolvedTarget, elementBinder).bindEntries(source, map); } return map.isEmpty() ? null : map; }