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

es.iti.wakamiti.api.extensions.ConfigContributor Maven / Gradle / Ivy

/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */
package es.iti.wakamiti.api.extensions;


import es.iti.commons.jext.ExtensionPoint;
import es.iti.wakamiti.api.imconfig.Configuration;
import es.iti.wakamiti.api.imconfig.Configurer;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;


/**
 * Defines a contract for configuring any component with the global configuration settings.
 *
 * @param  The class of the component to configure
 * @author Luis Iñesta Gelabert - [email protected]
 * @author Maria Galbis Calomarde - [email protected]
 */
@ExtensionPoint
public interface ConfigContributor extends Contributor {

    /**
     * Checks if this configurer can configure the given object. It verifies
     * if the class of the given object matches the {@code } parameter of this interface.
     *
     * @param contributor The {@link Contributor} to configure
     * @return {@code true} if the configurator is capable of configuring the given object,
     * {@code false} otherwise
     */
    default boolean accepts(Object contributor) {
        for (Type thisInterface : this.getClass().getGenericInterfaces()) {
            if (thisInterface instanceof ParameterizedType
                    && ((ParameterizedType) thisInterface).getRawType() == ConfigContributor.class) {
                Type thisT = ((ParameterizedType) thisInterface).getActualTypeArguments()[0];
                if (thisT instanceof Class && (((Class) thisT).isAssignableFrom(contributor.getClass()))) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * Retrieves the default configuration settings for the object being
     * configured.
     *
     * @return The default configuration
     */
    Configuration defaultConfiguration();

    /**
     * Retrieves a {@link Configurer}, which is responsible for performing
     * the configuration of objects of type {@code }.
     *
     * @return The configurer for objects of type {@code }
     */
    Configurer configurer();

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy