@Override public Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) { if (context.getConfigurationProperty() != null) { this.boundProperties.add(context.getConfigurationProperty()); } return super.onSuccess(name, target, context, result); }
@Override public Object onFailure(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Exception error) throws Exception { if (context.getDepth() == 0 && error instanceof ConverterNotFoundException) { return null; } throw error; }
private void checkNoUnboundElements(ConfigurationPropertyName name, BindContext context) { Set<ConfigurationProperty> unbound = new TreeSet<>(); for (ConfigurationPropertySource source : context.getSources()) { if (source instanceof IterableConfigurationPropertySource && this.filter.apply(source)) { collectUnbound(name, unbound, (IterableConfigurationPropertySource) source); } } if (!unbound.isEmpty()) { throw new UnboundConfigurationPropertiesException(unbound); } }
@Override public <T> Bindable<T> onStart(ConfigurationPropertyName name, Bindable<T> target, BindContext context) { ConfigurationPropertyName defaultName = getDefaultName(name); if (defaultName != null) { BindResult<T> result = context.getBinder().bind(defaultName, target); if (result.isBound()) { return target.withExistingValue(result.get()); } } return bindHandler.onStart(name, target, context); } };
@Override public void onFinish(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) throws Exception { if (context.getDepth() == 0) { checkNoUnboundElements(name, context); } }
private Object getValidationTarget(Bindable<?> target, BindContext context, Object result) { if (result != null) { return result; } if (context.getDepth() == 0 && target.getValue() != null) { return target.getValue().get(); } return null; }
private void validate(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) { Object validationTarget = getValidationTarget(target, context, result); Class<?> validationType = target.getBoxedType().resolve(); if (validationTarget != null) { validateAndPush(name, validationTarget, validationType); } if (context.getDepth() == 0 && !this.exceptions.isEmpty()) { throw this.exceptions.pop(); } }