commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r307359 - in /jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env: LogUtils.java SimpleErrorHandler.java SimpleErrorReporter.java SimpleSCXMLListener.java
Date Sun, 09 Oct 2005 04:35:05 GMT
Author: rahul
Date: Sat Oct  8 21:35:01 2005
New Revision: 307359

URL: http://svn.apache.org/viewcvs?rev=307359&view=rev
Log:
Added simple loggers that implement ErrorHandler, ErrorReporter and SCXMLListener.

Added:
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/LogUtils.java
  (with props)
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleErrorHandler.java
  (with props)
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleErrorReporter.java
  (with props)
    jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleSCXMLListener.java
  (with props)

Added: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/LogUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/LogUtils.java?rev=307359&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/LogUtils.java
(added)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/LogUtils.java
Sat Oct  8 21:35:01 2005
@@ -0,0 +1,79 @@
+/*
+ *
+ *   Copyright 2005 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.commons.scxml.env;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.apache.commons.scxml.model.Transition;
+import org.apache.commons.scxml.model.TransitionTarget;
+
+/**
+ * Helper methods for Commons SCXML logging.
+ *
+ */
+public class LogUtils {
+
+    /**
+     * 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
+     */
+    public 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(getTTPath(from));
+        buf.append(", to = ").append(getTTPath(to));
+        buf.append(')');
+        return buf.toString();
+    }
+
+    /**
+     * Write out this TransitionTarget location in a XPath style format.
+     *
+     * @param tt The TransitionTarget whose "path" is to needed
+     * @return String The XPath style location of the TransitionTarget within
+     *                the SCXML document
+     */
+    public 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();
+        }
+    }
+
+}
+

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/LogUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/LogUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleErrorHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleErrorHandler.java?rev=307359&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleErrorHandler.java
(added)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleErrorHandler.java
Sat Oct  8 21:35:01 2005
@@ -0,0 +1,77 @@
+/*
+ *
+ *   Copyright 2005 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.commons.scxml.env;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Custom error handler that logs the parsing errors in the
+ * SCXML document.
+ */
+public class SimpleErrorHandler implements ErrorHandler {
+
+    /** Message prefix. */
+    private static final String MSG_PREFIX = "SCXML SAX Parsing: ";
+    /** Message postfix. */
+    private static final String MSG_POSTFIX = " Correct the SCXML document.";
+
+    /** Log. */
+    private Log log = LogFactory.getLog(getClass());
+
+    /**
+     * Constructor.
+     */
+    public SimpleErrorHandler() {
+        super();
+    }
+
+    /**
+     * @see ErrorHandler#error(SAXParseException)
+     */
+    public void error(SAXParseException exception) {
+        if (log.isErrorEnabled()) {
+            log.error(MSG_PREFIX + exception.getMessage() + MSG_POSTFIX,
+                exception);
+        }
+    }
+
+    /**
+     * @see ErrorHandler#fatalError(SAXParseException)
+     */
+    public void fatalError(SAXParseException exception) {
+        if (log.isFatalEnabled()) {
+            log.fatal(MSG_PREFIX + exception.getMessage() + MSG_POSTFIX,
+                exception);
+        }
+    }
+
+    /**
+     * @see ErrorHandler#warning(SAXParseException)
+     */
+    public void warning(SAXParseException exception) {
+        if (log.isWarnEnabled()) {
+            log.warn(MSG_PREFIX + exception.getMessage() + MSG_POSTFIX,
+                exception);
+        }
+    }
+}
+

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleErrorHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleErrorHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleErrorReporter.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleErrorReporter.java?rev=307359&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleErrorReporter.java
(added)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleErrorReporter.java
Sat Oct  8 21:35:01 2005
@@ -0,0 +1,120 @@
+/*
+ *
+ *   Copyright 2005 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.commons.scxml.env;
+
+import java.util.HashSet;
+import java.util.Iterator;
+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.model.SCXML;
+import org.apache.commons.scxml.model.State;
+import org.apache.commons.scxml.model.Transition;
+import org.apache.commons.scxml.model.TransitionTarget;
+
+/**
+ * Custom error reporter that log execution errors.
+ */
+public class SimpleErrorReporter implements ErrorReporter {
+
+    /** Log. */
+    private Log log = LogFactory.getLog(getClass());
+
+    /**
+     * Constructor.
+     */
+    public SimpleErrorReporter() {
+        super();
+    }
+
+    /**
+     * @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 " + LogUtils.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(LogUtils.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(LogUtils.getTTPath(tt) + " : [");
+                for (Iterator i = vals.iterator(); i.hasNext();) {
+                    TransitionTarget tx = (TransitionTarget) i.next();
+                    msg.append(LogUtils.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(LogUtils.getTTPath(tx));
+                    if (i.hasNext()) {
+                        msg.append(", ");
+                    }
+                }
+                msg.append(']');
+            }
+        }
+        if (log.isWarnEnabled()) {
+            log.warn(msg.toString());
+        }
+    }
+
+}
+

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleErrorReporter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleErrorReporter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleSCXMLListener.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleSCXMLListener.java?rev=307359&view=auto
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleSCXMLListener.java
(added)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleSCXMLListener.java
Sat Oct  8 21:35:01 2005
@@ -0,0 +1,66 @@
+/*
+ *
+ *   Copyright 2005 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.commons.scxml.env;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.commons.scxml.SCXMLListener;
+import org.apache.commons.scxml.model.Transition;
+import org.apache.commons.scxml.model.TransitionTarget;
+
+
+/**
+ * Simple SCXML Listener that logs execution.
+ */
+public class SimpleSCXMLListener implements SCXMLListener {
+
+    /** Log. */
+    private Log log = LogFactory.getLog(getClass());
+
+
+    /**
+     * @see SCXMLListener#onEntry(TransitionTarget)
+     */
+    public void onEntry(final TransitionTarget state) {
+        if (log.isInfoEnabled()) {
+            log.info(LogUtils.getTTPath(state));
+        }
+    }
+
+    /**
+     * @see SCXMLListener#onExit(TransitionTarget)
+     */
+    public void onExit(final TransitionTarget state) {
+        if (log.isInfoEnabled()) {
+            log.info(LogUtils.getTTPath(state));
+        }
+    }
+
+    /**
+* @see SCXMLListener#onTransition(TransitionTarget,TransitionTarget,Transition)
+     */
+    public void onTransition(final TransitionTarget from,
+            final TransitionTarget to, final Transition transition) {
+        if (log.isInfoEnabled()) {
+            log.info(LogUtils.transToString(from, to, transition));
+        }
+    }
+
+}
+

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleSCXMLListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleSCXMLListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



---------------------------------------------------------------------
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