1 /* 2 * #%L 3 * Nuiton Validator 4 * %% 5 * Copyright (C) 2013 - 2014 Code Lutin, Tony Chemit 6 * %% 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation, either version 3 of the 10 * License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Lesser Public License for more details. 16 * 17 * You should have received a copy of the GNU General Lesser Public 18 * License along with this program. If not, see 19 * <http://www.gnu.org/licenses/lgpl-3.0.html>. 20 * #L% 21 */ 22 package org.nuiton.validator; 23 24 import java.io.File; 25 import java.util.ServiceLoader; 26 import java.util.SortedSet; 27 import java.util.regex.Pattern; 28 29 /** 30 * Provider of {@link NuitonValidator}. 31 * 32 * An implementation of a such class provides a implementation of a validator models 33 * and also of validator. 34 * 35 * <b>Note:</b> Providers are used in the {@link NuitonValidatorFactory} and 36 * should be registered via the {@link ServiceLoader} api. 37 * 38 * @author Tony Chemit - chemit@codelutin.com 39 * @see NuitonValidatorModel 40 * @see NuitonValidator 41 * @see ServiceLoader 42 * @since 2.0 43 */ 44 public interface NuitonValidatorProvider { 45 46 /** 47 * Obtains the name of the provider. 48 * 49 * @return the name of the provider. 50 */ 51 String getName(); 52 53 /** 54 * Obtain a validator model, the model should be cached and not be 55 * reinstanciated at each time a validator model is asked. 56 * 57 * @param type type of the class to validate 58 * @param context context of validation ({@code null} if no context) 59 * @param scopes filtered scope (if nothing given, then use all scopes) 60 * @param <O> type of the class to validate 61 * @return the cached model of validation 62 */ 63 <O> NuitonValidatorModel<O> getModel(Class<O> type, 64 String context, 65 NuitonValidatorScope... scopes); 66 67 /** 68 * Instanciate a new validator model for the given parameters. 69 * 70 * @param type type of the class to validate 71 * @param context context of validation ({@code null} if no context) 72 * @param scopes filtered scope (if nothing given, then use all scopes) 73 * @param <O> type of the class to validate 74 * @return the new instanciated model of validation 75 */ 76 <O> NuitonValidatorModel<O> newModel(Class<O> type, 77 String context, 78 NuitonValidatorScope... scopes); 79 80 /** 81 * Obtains a new validator for the given {@code model}. 82 * 83 * @param model the model of validator to use 84 * @param <O> type of class to validate 85 * @return the new validator 86 */ 87 <O> NuitonValidator<O> newValidator(NuitonValidatorModel<O> model); 88 89 /** 90 * Detects in the given directory validators. 91 * 92 * @param sourceRoot root directory where to seek for validators 93 * @param contextFilter the pattern of context to seek 94 * @param scopes scopes to seek (if none given, will seek for all scopes) 95 * @param types types of class to seek 96 * @return the set of validators found 97 */ 98 SortedSet<NuitonValidator<?>> detectValidators(File sourceRoot, 99 Pattern contextFilter, 100 NuitonValidatorScope[] scopes, 101 Class<?>... types); 102 }