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 org.apache.juneau.commons.httppart.*;
020
021/**
022 * Validates a bean-property value against a schema.
023 *
024 * <p>
025 * Implementations of this interface are built by a {@link PropertyValidatorFactory} and installed on the marshalling
026 * side (via {@link BeanPropertyMeta.Builder#readTransform readTransform} / {@link BeanPropertyMeta.Builder#writeTransform writeTransform})
027 * once per bean property at {@link BeanMeta} construction time.  The instance is then invoked from
028 * {@link BeanPropertyMeta#get} / {@link BeanPropertyMeta#set} at runtime when schema validation is enabled.
029 *
030 * <p>
031 * The commons-side SPI does not depend on any marshalling-side or {@code juneau-bean-jsonschema} types.  The concrete
032 * implementation that ships with Juneau is backed by the typed {@code JsonSchema} bean and lives in
033 * {@code juneau-bean-jsonschema}; it is discovered at runtime via {@link java.util.ServiceLoader ServiceLoader}.
034 *
035 * <h5 class='topic'>Thread safety</h5>
036 * Implementations must be safe to invoke from multiple threads concurrently, since a single validator is shared by all
037 * marshalling sessions for a given {@link BeanMeta}.
038 *
039 * @see PropertyValidatorFactory
040 * @see PropertyValidators
041 * @since 10.0.0
042 */
043@FunctionalInterface
044public interface PropertyValidator {
045
046   /**
047    * Validates the given value against the schema this validator was built from.
048    *
049    * @param value The value to validate.  May be <jk>null</jk>.
050    * @throws SchemaValidationException If the value violates the schema.
051    */
052   void validate(Object value) throws SchemaValidationException;
053}