001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.context.properties.bind;
018
019import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
020import org.springframework.util.Assert;
021
022/**
023 * Abstract base class for {@link BindHandler} implementations.
024 *
025 * @author Phillip Webb
026 * @author Madhura Bhave
027 * @since 2.0.0
028 */
029public abstract class AbstractBindHandler implements BindHandler {
030
031        private final BindHandler parent;
032
033        /**
034         * Create a new binding handler instance.
035         */
036        public AbstractBindHandler() {
037                this(BindHandler.DEFAULT);
038        }
039
040        /**
041         * Create a new binding handler instance with a specific parent.
042         * @param parent the parent handler
043         */
044        public AbstractBindHandler(BindHandler parent) {
045                Assert.notNull(parent, "Parent must not be null");
046                this.parent = parent;
047        }
048
049        @Override
050        public <T> Bindable<T> onStart(ConfigurationPropertyName name, Bindable<T> target,
051                        BindContext context) {
052                return this.parent.onStart(name, target, context);
053        }
054
055        @Override
056        public Object onSuccess(ConfigurationPropertyName name, Bindable<?> target,
057                        BindContext context, Object result) {
058                return this.parent.onSuccess(name, target, context, result);
059        }
060
061        @Override
062        public Object onFailure(ConfigurationPropertyName name, Bindable<?> target,
063                        BindContext context, Exception error) throws Exception {
064                return this.parent.onFailure(name, target, context, error);
065        }
066
067        @Override
068        public void onFinish(ConfigurationPropertyName name, Bindable<?> target,
069                        BindContext context, Object result) throws Exception {
070                this.parent.onFinish(name, target, context, result);
071        }
072
073}