private <T> Object bindAggregate(ConfigurationPropertyName name, Bindable<T> target, BindHandler handler, Context context, AggregateBinder<?> aggregateBinder) { AggregateElementBinder elementBinder = (itemName, itemTarget, source) -> { boolean allowRecursiveBinding = aggregateBinder .isAllowRecursiveBinding(source); Supplier<?> supplier = () -> bind(itemName, itemTarget, handler, context, allowRecursiveBinding); return context.withSource(source, supplier); }; return context.withIncreasedDepth( () -> aggregateBinder.bind(name, target, elementBinder)); }
/** * Perform binding for the aggregate. * @param name the configuration property name to bind * @param target the target to bind * @param elementBinder an element binder * @return the bound aggregate or null */ @SuppressWarnings("unchecked") public final Object bind(ConfigurationPropertyName name, Bindable<?> target, AggregateElementBinder elementBinder) { Object result = bindAggregate(name, target, elementBinder); Supplier<?> value = target.getValue(); if (result == null || value == null) { return result; } return merge((Supplier<T>) value, (T) result); }