001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.modeshape.schematic.internal.schema;
017
018import java.io.Serializable;
019import org.modeshape.schematic.annotation.Immutable;
020import org.modeshape.schematic.document.Document;
021import org.modeshape.schematic.document.Path;
022
023@Immutable
024public interface Validator extends Serializable {
025
026    /**
027     * Validate a portion of the supplied document.
028     * 
029     * @param fieldValue the field value to be validated; may be null
030     * @param fieldName the field name to be validated; may be null if the field value is not known or the validator is to
031     *        validate the document
032     * @param document the document; never null
033     * @param pathToDocument the path to the supplied document; never null but may be a zero-length path if the document is the
034     *        top-level document
035     * @param problems the problems where any errors or warnings should be recorded; never null
036     * @param resolver the component that can be used to resolve references to other schema documents
037     */
038    void validate( Object fieldValue,
039                   String fieldName,
040                   Document document,
041                   Path pathToDocument,
042                   Problems problems,
043                   SchemaDocumentResolver resolver );
044
045    static interface Factory {
046        public Validator create( Document schemaDocument,
047                                 Path pathToDoc );
048    }
049
050    static interface SchemaDocumentResolver {
051        SchemaDocument get( String uri,
052                            Problems problems );
053    }
054
055}