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

org.nuiton.validator.NuitonValidatorProvider Maven / Gradle / Ivy

The newest version!
/*
 * #%L
 * Validation :: API
 * %%
 * Copyright (C) 2021 - 2024 Ultreia.io
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * .
 * #L%
 */
package org.nuiton.validator;

import java.util.ServiceLoader;

/**
 * Provider of {@link NuitonValidator}.
 * 

* An implementation of a such class provides a implementation of a validator models * and also of validator. * * Note: Providers are used in the {@link NuitonValidatorProviders} and * should be registered via the {@link ServiceLoader} api. * * @author Tony Chemit - [email protected] * @see NuitonValidatorModel * @see NuitonValidator * @see ServiceLoader * @since 2.0 */ public interface NuitonValidatorProvider { /** * Obtains the name of the provider. * * @return the name of the provider. */ String getName(); /** * Obtain a validator model, the model should be cached and not be instantiated at each time a validator model is asked. * * @param type type of the class to validate * @param context context of validation ({@code null} if no context) * @param scopes filtered scope (if nothing given, then use all scopes) * @param type of the class to validate * @return the cached model of validation */ NuitonValidatorModel getModel(Class type, String context, NuitonValidatorScope... scopes); /** * Instanciate a new validator model for the given parameters. * * @param type type of the class to validate * @param context context of validation ({@code null} if no context) * @param scopes filtered scope (if nothing given, then use all scopes) * @param type of the class to validate * @return the new instantiated model of validation */ NuitonValidatorModel newModel(Class type, String context, NuitonValidatorScope... scopes); /** * Obtains a new validator for the given {@code model}. * * @param model the model of validator to use * @param type of class to validate * @return the new validator */ NuitonValidator newValidator(NuitonValidatorModel model); /** * Obtains a new validator for the given {@code model}. * * @param type type of the class to validate * @param context context of validation ({@code null} if no context) * @param scopes filtered scope (if nothing given, then use all scopes) * @param type of class to validate * @return the new validator */ default NuitonValidator newValidator(Class type, String context, NuitonValidatorScope... scopes) { if (type == null) { throw new NullPointerException("type parameter can not be null."); } // obtain validator model form the provider NuitonValidatorModel model = getModel(type, context, scopes); // obtain validator from the the provider return newValidator(model); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy