001    /*
002     * Copyright (c) 2006 Henri Sivonen
003     *
004     * Permission is hereby granted, free of charge, to any person obtaining a 
005     * copy of this software and associated documentation files (the "Software"), 
006     * to deal in the Software without restriction, including without limitation 
007     * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
008     * and/or sell copies of the Software, and to permit persons to whom the 
009     * Software is furnished to do so, subject to the following conditions:
010     *
011     * The above copyright notice and this permission notice shall be included in 
012     * all copies or substantial portions of the Software.
013     *
014     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
015     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
016     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
017     * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
018     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
019     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
020     * DEALINGS IN THE SOFTWARE.
021     */
022    
023    package fi.iki.hsivonen.xml.checker.jing;
024    
025    import org.xml.sax.ContentHandler;
026    import org.xml.sax.DTDHandler;
027    import org.xml.sax.ErrorHandler;
028    
029    import com.thaiopensource.util.PropertyMap;
030    import com.thaiopensource.validate.ValidateProperty;
031    import com.thaiopensource.validate.Validator;
032    
033    import fi.iki.hsivonen.xml.checker.Checker;
034    
035    /**
036     * Wraps a <code>Checker</code> so that it can be used like a Jing <code>Validator</code>.
037     * 
038     * @version $Id: CheckerValidator.java,v 1.3 2006/12/01 12:34:31 hsivonen Exp $
039     * @author hsivonen
040     */
041    public final class CheckerValidator implements Validator {
042    
043        /**
044         * The wrapped <code>Checker</code>
045         */
046        private final Checker checker;
047        
048        /**
049         * Constructor
050         * 
051         * @param checker the <code>Checker</code> to wrap
052         * @param propertyMap a property map containing a mapping for 
053         * <code>ValidateProperty.ERROR_HANDLER</code>
054         */
055        public CheckerValidator(Checker checker, PropertyMap propertyMap) {
056            super();
057            this.checker = checker;
058            this.checker.setErrorHandler((ErrorHandler) propertyMap.get(ValidateProperty.ERROR_HANDLER));
059        }
060    
061        /**
062         * Returns the wrapped <code>Checker</code>.
063         * @return the wrapped <code>Checker</code>
064         * @see com.thaiopensource.validate.Validator#getContentHandler()
065         */
066        public ContentHandler getContentHandler() {
067            return checker;
068        }
069        
070        /**
071         * Returns <code>null</code>.
072         * @return <code>null</code>
073         * @see com.thaiopensource.validate.Validator#getDTDHandler()
074         */
075        public DTDHandler getDTDHandler() {
076            return null;
077        }
078    
079        /**
080         * Resets the wrapped <code>Checker</code>.
081         * @see com.thaiopensource.validate.Validator#reset()
082         */
083        public void reset() {
084            this.checker.reset();
085        }
086    
087    }