001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.commons.bean; 018 019import java.util.*; 020 021/** 022 * Builds {@link PropertyValidator} instances from a JSON-Schema-shaped map of constraints. 023 * 024 * <p> 025 * The factory is resolved at runtime via {@link ServiceLoader ServiceLoader} through 026 * {@link PropertyValidators#factory()}. If no factory is on the classpath (i.e. {@code juneau-bean-jsonschema} is 027 * not present), schema-validation mode silently becomes a no-op. 028 * 029 * <p> 030 * The marshalling side calls the factory once per bean property at {@link BeanMeta} construction time and installs 031 * the resulting validator into the property's read/write transform slots. 032 * 033 * <h5 class='topic'>Thread safety</h5> 034 * Factory implementations must be safe to invoke from multiple threads concurrently. 035 * 036 * @see PropertyValidator 037 * @see PropertyValidators 038 * @since 10.0.0 039 */ 040@FunctionalInterface 041public interface PropertyValidatorFactory { 042 043 /** 044 * Builds a validator from a JSON-Schema-shaped map of constraints. 045 * 046 * @param schemaMap 047 * A map mirroring the JSON Schema constraint shape (the same shape produced by 048 * {@code SchemaAnnotation.asMap()}). May be empty, in which case implementations should return <jk>null</jk>. 049 * @param propertyType 050 * The Java type of the property being validated. May be used by the factory to choose narrower numeric or 051 * collection validators. May be <jk>null</jk>. 052 * @return A validator, or <jk>null</jk> if the map carries no actionable constraints. 053 */ 054 PropertyValidator create(Map<String,Object> schemaMap, Class<?> propertyType); 055}