commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r307360 - /jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/Tracer.java
Date Sun, 09 Oct 2005 04:41:16 GMT
Author: rahul
Date: Sat Oct  8 21:41:14 2005
New Revision: 307360

URL: http://svn.apache.org/viewcvs?rev=307360&view=rev
Log:
Have the Tracer delegate to the simple loggers.

Modified:
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/Tracer.java

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/Tracer.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/Tracer.java?rev=307360&r1=307359&r2=307360&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/Tracer.java
(original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/Tracer.java
Sat Oct  8 21:41:14 2005
@@ -17,197 +17,96 @@
  */
 package org.apache.commons.scxml.env;
 
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.apache.commons.scxml.ErrorReporter;
 import org.apache.commons.scxml.SCXMLListener;
-import org.apache.commons.scxml.model.SCXML;
-import org.apache.commons.scxml.model.State;
 import org.apache.commons.scxml.model.Transition;
 import org.apache.commons.scxml.model.TransitionTarget;
+
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 
 /**
- * A simple logger connected to Jakarta Commons Logging.
+ * A simple tracer connected to Jakarta Commons Logging.
  *
  */
-public class Tracer implements ErrorReporter, SCXMLListener, ErrorHandler {
+public class Tracer implements ErrorHandler, ErrorReporter, SCXMLListener {
 
     /** A Logger for the Tracer. */
     private static Log log = LogFactory.getLog(Tracer.class);
 
+    /** ErrorHandler delegate. */
+    ErrorHandler errHandler;
+    /** ErrorReporter delegate. */
+    ErrorReporter errReporter;
+    /** SCXMLListener delegate. */
+    SCXMLListener scxmlListener;
+
     /**
      * Constructor.
      */
     public Tracer() {
         super();
+        errHandler = new SimpleErrorHandler();
+        errReporter = new SimpleErrorReporter();
+        scxmlListener = new SimpleSCXMLListener();
     }
 
     /**
-     * @see ErrorReporter#onError(String, String, Object)
-     */
-    public void onError(final String errorCode, final String errDetail,
-            final Object errCtx) {
-        //Note: the if-then-else below is based on the actual usage
-        // (codebase search), it has to be kept up-to-date as the code changes
-        String errCode = errorCode.intern();
-        StringBuffer msg = new StringBuffer();
-        msg.append(errCode).append(" (");
-        msg.append(errDetail).append("): ");
-        if (errCode == ErrorReporter.NO_INITIAL) {
-            if (errCtx instanceof SCXML) {
-                //determineInitialStates
-                msg.append("<SCXML>");
-            } else if (errCtx instanceof State) {
-                //determineInitialStates
-                //determineTargetStates
-                msg.append("State " + Tracer.getTTPath((State) errCtx));
-            }
-        } else if (errCode == ErrorReporter.UNKNOWN_ACTION) {
-            //executeActionList
-            msg.append("Action: " + errCtx.getClass().getName());
-        } else if (errCode == ErrorReporter.NON_DETERMINISTIC) {
-            //filterTransitionSet
-            msg.append(" [");
-            if (errCtx instanceof HashSet) {
-                for (Iterator i = ((Set) errCtx).iterator(); i.hasNext();) {
-                    Transition t = (Transition) i.next();
-                    msg.append(transToString(t.getParent(), t.getTarget(), t));
-                    if (i.hasNext()) {
-                        msg.append(", ");
-                    }
-                }
-            }
-            msg.append(']');
-        } else if (errCode == ErrorReporter.ILLEGAL_CONFIG) {
-            //isLegalConfig
-            if (errCtx instanceof Map.Entry) {
-                TransitionTarget tt = (TransitionTarget)
-                    (((Map.Entry) errCtx).getKey());
-                Set vals = (Set) (((Map.Entry) errCtx).getValue());
-                msg.append(Tracer.getTTPath(tt) + " : [");
-                for (Iterator i = vals.iterator(); i.hasNext();) {
-                    TransitionTarget tx = (TransitionTarget) i.next();
-                    msg.append(Tracer.getTTPath(tx));
-                    if (i.hasNext()) {
-                        msg.append(", ");
-                    }
-                }
-                msg.append(']');
-            } else if (errCtx instanceof Set) {
-                Set vals = (Set) errCtx;
-                msg.append("<SCXML> : [");
-                for (Iterator i = vals.iterator(); i.hasNext();) {
-                    TransitionTarget tx = (TransitionTarget) i.next();
-                    msg.append(Tracer.getTTPath(tx));
-                    if (i.hasNext()) {
-                        msg.append(", ");
-                    }
-                }
-                msg.append(']');
-            }
-        }
-        log.warn(msg.toString());
-    }
-
-    /**
-     * @see SCXMLListener#onEntry(TransitionTarget)
+     * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
      */
-    public void onEntry(final TransitionTarget state) {
-        log.info(Tracer.getTTPath(state));
+    public void warning(final SAXParseException exception)
+    throws SAXException {
+        errHandler.warning(exception);
     }
 
     /**
-     * @see SCXMLListener#onExit(TransitionTarget)
+     * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
      */
-    public void onExit(final TransitionTarget state) {
-        log.info(Tracer.getTTPath(state));
+    public void error(final SAXParseException exception)
+    throws SAXException {
+        errHandler.error(exception);
     }
 
     /**
-* @see SCXMLListener#onTransition(TransitionTarget,TransitionTarget,Transition)
+     * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
      */
-    public void onTransition(final TransitionTarget from,
-            final TransitionTarget to, final Transition transition) {
-        log.info(transToString(from, to, transition));
+    public void fatalError(final SAXParseException exception)
+    throws SAXException {
+        errHandler.fatalError(exception);
     }
 
     /**
-     * Create a human readable log view of this transition.
-     *
-     * @param from The source TransitionTarget
-     * @param to The destination TransitionTarget
-     * @param transition The Transition that is taken
-     * @return String The human readable log entry
+     * @see ErrorReporter#onError(String, String, Object)
      */
-    private static String transToString(final TransitionTarget from,
-            final TransitionTarget to, final Transition transition) {
-        StringBuffer buf = new StringBuffer("transition (");
-        buf.append("event = ").append(transition.getEvent());
-        buf.append(", cond = ").append(transition.getCond());
-        buf.append(", from = ").append(Tracer.getTTPath(from));
-        buf.append(", to = ").append(Tracer.getTTPath(to));
-        buf.append(')');
-        return buf.toString();
+    public void onError(final String errCode, final String errDetail,
+            final Object errCtx) {
+        errReporter.onError(errCode, errDetail, errCtx);
     }
 
     /**
-     * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
+     * @see SCXMLListener#onEntry(TransitionTarget)
      */
-    public void warning(final SAXParseException exception)
-    throws SAXException {
-        log.warn(exception.getMessage(), exception);
+    public void onEntry(final TransitionTarget target) {
+        scxmlListener.onEntry(target);
     }
 
     /**
-     * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
+     * @see SCXMLListener#onExit(TransitionTarget)
      */
-    public void error(final SAXParseException exception)
-    throws SAXException {
-        log.error(exception.getMessage(), exception);
+    public void onExit(final TransitionTarget target) {
+        scxmlListener.onExit(target);
     }
 
     /**
-     * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
+* @see SCXMLListener#onTransition(TransitionTarget,TransitionTarget,Transition)
      */
-    public void fatalError(final SAXParseException exception)
-    throws SAXException {
-        log.fatal(exception.getMessage(), exception);
-    }
-
-    /**
-     * Write out this TransitionTarget location in a XPath style format.
-     *
-     * @param tt The TransitionTarget whose &quot;path&quot; is to needed
-     * @return String The XPath style location of the TransitionTarget within
-     *                the SCXML document
-     */
-    private static String getTTPath(final TransitionTarget tt) {
-        TransitionTarget parent = tt.getParent();
-        if (parent == null) {
-            return "/" + tt.getId();
-        } else {
-            LinkedList pathElements = new LinkedList();
-            pathElements.addFirst(tt);
-            while (parent != null) {
-                pathElements.addFirst(parent);
-                parent = parent.getParent();
-            }
-            StringBuffer names = new StringBuffer();
-            for (Iterator i = pathElements.iterator(); i.hasNext();) {
-                TransitionTarget pathElement = (TransitionTarget) i.next();
-                names.append('/').append(pathElement.getId());
-            }
-            return names.toString();
-        }
+    public void onTransition(final TransitionTarget from,
+            final TransitionTarget to, final Transition transition) {
+        scxmlListener.onTransition(from, to, transition);
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message