    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     */
    017    package org.apache.commons.scxml.env;
    018
    019    import java.io.Serializable;
    020
    021    import org.apache.commons.scxml.ErrorReporter;
    022    import org.apache.commons.scxml.SCXMLListener;
    023    import org.apache.commons.scxml.model.Transition;
    024    import org.apache.commons.scxml.model.TransitionTarget;
    025    import org.xml.sax.ErrorHandler;
    026    import org.xml.sax.SAXException;
    027    import org.xml.sax.SAXParseException;
    028
    029    /**
    030     * A simple tracer connected to Apache Commons Logging.
    031     *
    032     */
    033    public class Tracer implements ErrorHandler, ErrorReporter,
    034                                   SCXMLListener, Serializable {
    035
    036        /** Serial version UID. */
    037        private static final long serialVersionUID = 1L;
    038        /** ErrorHandler delegate. */
    039        private ErrorHandler errHandler;
    040        /** ErrorReporter delegate. */
    041        private ErrorReporter errReporter;
    042        /** SCXMLListener delegate. */
    043        private SCXMLListener scxmlListener;
    044
    045        /**
    046         * Constructor.
    047         */
    048        public Tracer() {
    049            super();
    050            errHandler = new SimpleErrorHandler();
    051            errReporter = new SimpleErrorReporter();
    052            scxmlListener = new SimpleSCXMLListener();
    053        }
    054
    055        /**
    056         * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
    057         */
    058        public void warning(final SAXParseException exception)
    059        throws SAXException {
    060            errHandler.warning(exception);
    061        }
    062
    063        /**
    064         * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
    065         */
    066        public void error(final SAXParseException exception)
    067        throws SAXException {
    068            errHandler.error(exception);
    069        }
    070
    071        /**
    072         * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
    073         */
    074        public void fatalError(final SAXParseException exception)
    075        throws SAXException {
    076            errHandler.fatalError(exception);
    077        }
    078
    079        /**
    080         * @see ErrorReporter#onError(String, String, Object)
    081         */
    082        public void onError(final String errCode, final String errDetail,
    083                final Object errCtx) {
    084            errReporter.onError(errCode, errDetail, errCtx);
    085        }
    086
    087        /**
    088         * @see SCXMLListener#onEntry(TransitionTarget)
    089         */
    090        public void onEntry(final TransitionTarget target) {
    091            scxmlListener.onEntry(target);
    092        }
    093
    094        /**
    095         * @see SCXMLListener#onExit(TransitionTarget)
    096         */
    097        public void onExit(final TransitionTarget target) {
    098            scxmlListener.onExit(target);
    099        }
    100
    101        /**
    102    * @see SCXMLListener#onTransition(TransitionTarget,TransitionTarget,Transition)
    103         */
    104        public void onTransition(final TransitionTarget from,
    105                final TransitionTarget to, final Transition transition) {
    106            scxmlListener.onTransition(from, to, transition);
    107        }
    108
    109    }
    110