001/*
002 *  Copyright 2012 Anyware Services
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.ametys.runtime.parameter;
017
018import java.util.Map;
019
020import org.xml.sax.ContentHandler;
021import org.xml.sax.SAXException;
022
023/**
024 * Validator for parameters values 
025 */
026public interface Validator
027{
028    /**
029     * Validates a value.
030     * @param value the value to validate (can be <code>null</code>).
031     * @param errors the structure to populate if the validation failed.
032     */
033    public void validate(Object value, Errors errors);
034    
035    /**
036     * Sax the configuration of the validator to allow the client side to prevalidate
037     * @param handler The content handler where to sax parameters
038     * @throws SAXException if an error occured
039     */
040    public void saxConfiguration(ContentHandler handler) throws SAXException;
041    
042    /**
043     * Returns a object representing the validator able to be converted into a JSON string
044     * @return the JSON object
045     */
046    public Map<String, Object> toJson ();
047    
048    /**
049     * Retrieves the configuration of the validator. Information contained in
050     * the returned map should be the same than those SAX'ed in
051     * {@link #saxConfiguration(ContentHandler)}
052     * @return a map containing the configuration information.
053     */
054    public Map<String, Object> getConfiguration();
055}