All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mattbertolini.spring.web.bind.AbstractPropertyResolverRegistry Maven / Gradle / Ivy

There is a newer version: 0.6.0
Show newest version
/*
 * Copyright 2019-2021 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mattbertolini.spring.web.bind;

import com.mattbertolini.spring.web.bind.introspect.BindingProperty;
import com.mattbertolini.spring.web.bind.resolver.RequestPropertyResolverBase;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * Do not extend directly from this class. Extend from the two subclasses that are specific to Spring MVC or Spring
 * WebFlux.
 * @param  The resolver type
 */
public abstract class AbstractPropertyResolverRegistry> {
    private final Set propertyResolvers;

    protected AbstractPropertyResolverRegistry() {
        propertyResolvers = new LinkedHashSet<>();
    }

    @Nullable
    public T findResolverFor(@NonNull BindingProperty bindingProperty) {
        for (T resolver : propertyResolvers) {
            if (resolver.supports(bindingProperty)) {
                return resolver;
            }
        }
        return null;
    }

    /**
     * Add the given resolver to this registry.
     *
     * @param resolver The resolver to add.
     */
    public void addResolver(T resolver) {
        propertyResolvers.add(resolver);
    }

    /**
     * Add all the resolvers in the given set to this registry.
     *
     * @param resolvers The set of resolvers to add.
     */
    public void addResolvers(Set resolvers) {
        propertyResolvers.addAll(resolvers);
    }

    /**
     * Add all the resolvers in the given registry to this registry.
     * 
     * @param registry The registry to add resolvers from.
     */
    public void addResolvers(AbstractPropertyResolverRegistry registry) {
        addResolvers(registry.getPropertyResolvers());
    }

    /**
     * Returns an unmodifiable collection of the resolvers.
     */
    @NonNull
    public Set getPropertyResolvers() {
        return Collections.unmodifiableSet(propertyResolvers);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy