View Javadoc
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.scxml2.env;
18  
19  import java.io.Serializable;
20  
21  import javax.xml.stream.Location;
22  import javax.xml.stream.XMLReporter;
23  import javax.xml.stream.XMLStreamException;
24  
25  import org.apache.commons.scxml2.ErrorReporter;
26  import org.apache.commons.scxml2.SCXMLListener;
27  import org.apache.commons.scxml2.model.EnterableState;
28  import org.apache.commons.scxml2.model.Transition;
29  import org.apache.commons.scxml2.model.TransitionTarget;
30  import org.xml.sax.ErrorHandler;
31  import org.xml.sax.SAXException;
32  import org.xml.sax.SAXParseException;
33  
34  /**
35   * A simple tracer connected to Apache Commons Logging.
36   *
37   */
38  public class Tracer implements ErrorHandler, ErrorReporter,
39                                 SCXMLListener, Serializable, XMLReporter {
40  
41      /** Serial version UID. */
42      private static final long serialVersionUID = 1L;
43      /** ErrorHandler delegate. */
44      private ErrorHandler errHandler;
45      /** ErrorReporter delegate. */
46      private ErrorReporter errReporter;
47      /** SCXMLListener delegate. */
48      private SCXMLListener scxmlListener;
49      /** XMLReporter delegate. */
50      private XMLReporter xmlReporter;
51  
52      /**
53       * Constructor.
54       */
55      public Tracer() {
56          super();
57          errHandler = new SimpleErrorHandler();
58          errReporter = new SimpleErrorReporter();
59          scxmlListener = new SimpleSCXMLListener();
60          xmlReporter = new SimpleXMLReporter();
61      }
62  
63      /**
64       * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
65       */
66      public void warning(final SAXParseException exception)
67      throws SAXException {
68          errHandler.warning(exception);
69      }
70  
71      /**
72       * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
73       */
74      public void error(final SAXParseException exception)
75      throws SAXException {
76          errHandler.error(exception);
77      }
78  
79      /**
80       * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
81       */
82      public void fatalError(final SAXParseException exception)
83      throws SAXException {
84          errHandler.fatalError(exception);
85      }
86  
87      /**
88       * @see ErrorReporter#onError(String, String, Object)
89       */
90      public void onError(final String errCode, final String errDetail,
91              final Object errCtx) {
92          errReporter.onError(errCode, errDetail, errCtx);
93      }
94  
95      /**
96       * @see SCXMLListener#onEntry(EnterableState)
97       */
98      public void onEntry(final EnterableState state) {
99          scxmlListener.onEntry(state);
100     }
101 
102     /**
103      * @see SCXMLListener#onExit(EnterableState)
104      */
105     public void onExit(final EnterableState state) {
106         scxmlListener.onExit(state);
107     }
108 
109     /**
110      * @see SCXMLListener#onTransition(TransitionTarget,TransitionTarget,Transition,String)
111      */
112     public void onTransition(final TransitionTarget from,
113             final TransitionTarget to, final Transition transition, final String event) {
114         scxmlListener.onTransition(from, to, transition, event);
115     }
116 
117     /**
118      * @see XMLReporter#report(String, String, Object, Location)
119      */
120 	public void report(final String message, final String errorType, final Object relatedInformation,
121 			final Location location)
122 	throws XMLStreamException {
123 		xmlReporter.report(message, errorType, relatedInformation, location);
124 	}
125 
126 }
127