1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.scxml.env;
18
19 import java.io.Serializable;
20
21 import org.apache.commons.scxml.ErrorReporter;
22 import org.apache.commons.scxml.SCXMLListener;
23 import org.apache.commons.scxml.model.Transition;
24 import org.apache.commons.scxml.model.TransitionTarget;
25 import org.xml.sax.ErrorHandler;
26 import org.xml.sax.SAXException;
27 import org.xml.sax.SAXParseException;
28
29 /**
30 * A simple tracer connected to Apache Commons Logging.
31 *
32 */
33 public class Tracer implements ErrorHandler, ErrorReporter,
34 SCXMLListener, Serializable {
35
36 /** Serial version UID. */
37 private static final long serialVersionUID = 1L;
38 /** ErrorHandler delegate. */
39 private ErrorHandler errHandler;
40 /** ErrorReporter delegate. */
41 private ErrorReporter errReporter;
42 /** SCXMLListener delegate. */
43 private SCXMLListener scxmlListener;
44
45 /**
46 * Constructor.
47 */
48 public Tracer() {
49 super();
50 errHandler = new SimpleErrorHandler();
51 errReporter = new SimpleErrorReporter();
52 scxmlListener = new SimpleSCXMLListener();
53 }
54
55 /**
56 * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
57 */
58 public void warning(final SAXParseException exception)
59 throws SAXException {
60 errHandler.warning(exception);
61 }
62
63 /**
64 * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
65 */
66 public void error(final SAXParseException exception)
67 throws SAXException {
68 errHandler.error(exception);
69 }
70
71 /**
72 * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
73 */
74 public void fatalError(final SAXParseException exception)
75 throws SAXException {
76 errHandler.fatalError(exception);
77 }
78
79 /**
80 * @see ErrorReporter#onError(String, String, Object)
81 */
82 public void onError(final String errCode, final String errDetail,
83 final Object errCtx) {
84 errReporter.onError(errCode, errDetail, errCtx);
85 }
86
87 /**
88 * @see SCXMLListener#onEntry(TransitionTarget)
89 */
90 public void onEntry(final TransitionTarget target) {
91 scxmlListener.onEntry(target);
92 }
93
94 /**
95 * @see SCXMLListener#onExit(TransitionTarget)
96 */
97 public void onExit(final TransitionTarget target) {
98 scxmlListener.onExit(target);
99 }
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