[logback-dev] svn commit: r1764 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/joran/action main/java/ch/qos/logback/core/joran/spi test/java/ch/qos/logback/core/joran/action/ext

noreply.ceki at qos.ch noreply.ceki at qos.ch
Tue Aug 19 19:32:42 CEST 2008


Author: ceki
Date: Tue Aug 19 19:32:42 2008
New Revision: 1764

Modified:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderAction.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/MatcherAction.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/StatusListenerAction.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ActionException.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Interpreter.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/ext/IncAction.java

Log:
Related to LBCLASSIC-63

Simplifying the Joran's logic in case of errors within actions. 
In case of a failing action, Joran skip the children of the event 
associated with the action. In practice, this was already the case. 
However, with this commit, we are formally dropping support for 
SKIP_SIBLINGS.

Test cases will follow

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderAction.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderAction.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderAction.java	Tue Aug 19 19:32:42 2008
@@ -17,6 +17,7 @@
 import ch.qos.logback.core.Appender;
 import ch.qos.logback.core.joran.spi.ActionException;
 import ch.qos.logback.core.joran.spi.InterpretationContext;
+import ch.qos.logback.core.joran.spi.ActionException.SkipCode;
 import ch.qos.logback.core.spi.LifeCycle;
 import ch.qos.logback.core.util.OptionHelper;
 
@@ -79,7 +80,7 @@
       inError = true;
       addError(
         "Could not create an Appender of type ["+className+"].", oops);
-      throw new ActionException(ActionException.SKIP_CHILDREN, oops);
+      throw new ActionException(SkipCode.SKIP_CHILDREN, oops);
     }
   }
 

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/MatcherAction.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/MatcherAction.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/MatcherAction.java	Tue Aug 19 19:32:42 2008
@@ -15,6 +15,7 @@
 import ch.qos.logback.core.boolex.Matcher;
 import ch.qos.logback.core.joran.spi.ActionException;
 import ch.qos.logback.core.joran.spi.InterpretationContext;
+import ch.qos.logback.core.joran.spi.ActionException.SkipCode;
 import ch.qos.logback.core.util.OptionHelper;
 
 
@@ -55,9 +56,9 @@
       ec.pushObject(matcher);
     } catch (Exception oops) {
       inError = true;
-      addError("Could not attach matcher to JaninoEvenyEvaluator",
+      addError("Could not attach matcher to JaninoEventEvaluator",
           oops);
-      throw new ActionException(ActionException.SKIP_CHILDREN, oops);
+      throw new ActionException(SkipCode.SKIP_CHILDREN, oops);
     }
   }
 

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/StatusListenerAction.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/StatusListenerAction.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/StatusListenerAction.java	Tue Aug 19 19:32:42 2008
@@ -12,9 +12,9 @@
 
 import org.xml.sax.Attributes;
 
-import ch.qos.logback.core.joran.action.Action;
 import ch.qos.logback.core.joran.spi.ActionException;
 import ch.qos.logback.core.joran.spi.InterpretationContext;
+import ch.qos.logback.core.joran.spi.ActionException.SkipCode;
 import ch.qos.logback.core.spi.LifeCycle;
 import ch.qos.logback.core.status.StatusListener;
 import ch.qos.logback.core.util.OptionHelper;
@@ -46,7 +46,7 @@
       inError = true;
       addError(
         "Could not create an StatusListener of type ["+className+"].", e);
-      throw new ActionException(ActionException.SKIP_CHILDREN, e);
+      throw new ActionException(SkipCode.SKIP_CHILDREN, e);
     }
     
   }

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ActionException.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ActionException.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ActionException.java	Tue Aug 19 19:32:42 2008
@@ -19,28 +19,28 @@
  */
 public class ActionException extends Exception {
 
+  
+  public enum SkipCode {
+    /**
+     * SKIP_CHILDREN signals the {@link Interpreter} to skip processing all the
+     * nested elements contained within the element causing this ActionException.
+     * 
+     * <p>It is the only recognized skipping mode in Joran.
+     */
+    SKIP_CHILDREN;
+  }
+  
   private static final long serialVersionUID = 2743349809995319806L;
 
-  /**
-   * SKIP_CHILDREN signals the {@link Interpreter} to skip processing all the
-   * nested elements contained within the element causing this ActionException.
-   */
-  public static final int SKIP_CHILDREN = 1;
-
-  /**
-   * SKIP_SIBLINGS signals the {@link Interpreter} to skip processing all the
-   * children of this element as well as all the siblings of this elements,
-   * including any children they may have.
-   */
-  public static final int SKIP_SIBLINGS = 2;
+
   final Throwable rootCause;
-  final int skipCode;
+  final SkipCode skipCode;
 
-  public ActionException(final int skipCode) {
+  public ActionException(final SkipCode skipCode) {
     this(skipCode, null);
   }
 
-  public ActionException(final int skipCode, final Throwable rootCause) {
+  public ActionException(final SkipCode skipCode, final Throwable rootCause) {
     this.skipCode = skipCode;
     this.rootCause = rootCause;
   }
@@ -49,7 +49,7 @@
     return rootCause;
   }
 
-  public int getSkipCode() {
+  public SkipCode getSkipCode() {
     return skipCode;
   }
 }

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Interpreter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Interpreter.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Interpreter.java	Tue Aug 19 19:32:42 2008
@@ -159,15 +159,9 @@
     // System.out.println("endElement ["+getTagName(localName, qName)+"]");
 
     if (skip != null) {
-      // System.err.println("In End, pattern is "+pattern+", skip pattern
-      // "+skip);
       if (skip.equals(pattern)) {
-        // ec.addInfo("Normal processing will continue with the next element.
-        // Current pattern is ["+ pattern+"]", this);
         skip = null;
-      } else {
-        // getLogger().debug("Skipping invoking end() method for [{}].",
-        // pattern);
+        callEndAction(applicableActionList, getTagName(localName, qName));
       }
     } else if (applicableActionList != EMPTY_LIST) {
       callEndAction(applicableActionList, getTagName(localName, qName));
@@ -259,15 +253,9 @@
         action.begin(ec, tagName, atts);
       } catch (ActionException ae) {
         switch (ae.getSkipCode()) {
-        case ActionException.SKIP_CHILDREN:
+        case SKIP_CHILDREN:
           skip = (Pattern) pattern.clone();
           break;
-        case ActionException.SKIP_SIBLINGS:
-          skip = (Pattern) pattern.clone();
-          // pretend the exception came from one level up. This will cause
-          // all children and following siblings elements to be skipped
-          skip.pop();
-          break;
         }
         // getLogger().info("Skip pattern set to [{}]", skip);
       } catch (Exception e) {
@@ -310,15 +298,10 @@
         action.end(ec, tagName);
       } catch (ActionException ae) {
         switch (ae.getSkipCode()) {
-        case ActionException.SKIP_CHILDREN:
+        case SKIP_CHILDREN:
           // after end() is called there can't be any children
           break;
-        case ActionException.SKIP_SIBLINGS:
-          skip = (Pattern) pattern.clone();
-          skip.pop();
-          break;
         }
-        // getLogger().info("Skip pattern set to <{}>", skip);
       } catch (Exception e) {
         cai.addError("Exception in Action for tag [" + tagName + "]", e);
         skip = (Pattern) pattern.clone();

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/ext/IncAction.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/ext/IncAction.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/ext/IncAction.java	Tue Aug 19 19:32:42 2008
@@ -15,6 +15,7 @@
 import ch.qos.logback.core.joran.action.Action;
 import ch.qos.logback.core.joran.spi.ActionException;
 import ch.qos.logback.core.joran.spi.InterpretationContext;
+import ch.qos.logback.core.joran.spi.ActionException.SkipCode;
 
 
 
@@ -39,7 +40,7 @@
     String val = attributes.getValue("increment");
     if(!"1".equals(val)) {
       errorCount++;
-      throw new ActionException(ActionException.SKIP_SIBLINGS);
+      throw new ActionException(SkipCode.SKIP_CHILDREN);
     }
   }
 


More information about the logback-dev mailing list