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

noreply.ceki at qos.ch noreply.ceki at qos.ch
Wed Oct 18 18:07:23 CEST 2006


Author: ceki
Date: Wed Oct 18 18:07:22 2006
New Revision: 712

Added:
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/event/FruitConfigAction.java
Modified:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/EventPlayer.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/event/InPlayFireTest.java

Log:
Let listener action get the begin action immediately prior to their registration.

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java	Wed Oct 18 18:07:22 2006
@@ -30,9 +30,8 @@
 
 public abstract class GenericConfigurator extends ContextAwareBase {
 
-  List<SaxEvent> saxEventList;
   Interpreter interpreter;
-  
+
   final public void doConfigure(URL url) throws JoranException {
     try {
       InputStream in = url.openStream();
@@ -65,7 +64,7 @@
         } catch (java.io.IOException ioe) {
           String errMsg = "Could not close [" + file.getName() + "].";
           addError(errMsg, ioe);
-          throw new JoranException(errMsg,ioe);
+          throw new JoranException(errMsg, ioe);
         }
       }
     }
@@ -76,8 +75,9 @@
   }
 
   abstract protected void addInstanceRules(RuleStore rs);
+
   abstract protected void addImplicitRules(Interpreter interpreter);
-  
+
   protected void buildInterpreter() {
     RuleStore rs = new SimpleRuleStore(context);
     addInstanceRules(rs);
@@ -85,21 +85,23 @@
     ExecutionContext ec = interpreter.getExecutionContext();
     ec.setContext(context);
     addImplicitRules(interpreter);
-    
+
   }
-  
+
   final public void doConfigure(final InputSource inputSource)
       throws JoranException {
     SaxEventRecorder recorder = new SaxEventRecorder();
     recorder.setContext(context);
-    saxEventList = recorder.recordEvents(inputSource);
+    recorder.recordEvents(inputSource);
     buildInterpreter();
     EventPlayer player = new EventPlayer(interpreter);
     player.play(recorder.saxEventList);
   }
 
-  public List<SaxEvent> getSaxEventList() {
-    return saxEventList;
+  final public void doConfigure(final List<SaxEvent> eventList)
+      throws JoranException {
+    buildInterpreter();
+    EventPlayer player = new EventPlayer(interpreter);
+    player.play(eventList);
   }
-
 }

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/EventPlayer.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/EventPlayer.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/EventPlayer.java	Wed Oct 18 18:07:22 2006
@@ -28,9 +28,9 @@
     
     for(SaxEvent se : seList) {
       if(se instanceof StartEvent) {
-        // invoke fireInPlay before  startElement processing
-        interpreter.getExecutionContext().fireInPlay(se);
         interpreter.startElement((StartEvent) se);
+        // invoke fireInPlay after startElement processing
+        interpreter.getExecutionContext().fireInPlay(se);
       }
       if(se instanceof BodyEvent) {
         // invoke fireInPlay before  characters processing
@@ -38,9 +38,9 @@
         interpreter.characters((BodyEvent) se);
       }
       if(se instanceof EndEvent) {
-        interpreter.endElement((EndEvent) se);
-        // invoke fireInPlay after endElement processing
+        // invoke fireInPlay before endElement processing
         interpreter.getExecutionContext().fireInPlay(se);
+        interpreter.endElement((EndEvent) se);
       }
     
     }

Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/event/FruitConfigAction.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/event/FruitConfigAction.java	Wed Oct 18 18:07:22 2006
@@ -0,0 +1,46 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework for Java.
+ * 
+ * Copyright (C) 2000-2006, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
+package ch.qos.logback.core.joran.event;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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.ExecutionContext;
+
+public class FruitConfigAction extends Action implements InPlayListener {
+
+  List<SaxEvent> seList = new ArrayList<SaxEvent>();
+
+  @Override
+  public void begin(ExecutionContext ec, String name, Attributes attributes)
+      throws ActionException {
+    ec.addInPlayListener(this);
+  }
+
+  @Override
+  public void end(ExecutionContext ec, String name) throws ActionException {
+    ec.removeInPlayListener(this);
+
+  }
+
+  public void inPlay(SaxEvent event) {
+    seList.add(event);
+  }
+
+  public List<SaxEvent> getSeList() {
+    return seList;
+  }
+
+}

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/event/InPlayFireTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/event/InPlayFireTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/event/InPlayFireTest.java	Wed Oct 18 18:07:22 2006
@@ -34,10 +34,14 @@
     gc.setContext(context);
     gc.doConfigure(Constants.TEST_DIR_PREFIX + "input/joran/fire1.xml");
     
-    assertEquals(3, listenAction.getSeList().size());
+    for(SaxEvent se: listenAction.getSeList()) {
+      System.out.println(se);
+    }
+    assertEquals(5, listenAction.getSeList().size());
     assertTrue(listenAction.getSeList().get(0) instanceof StartEvent);
-    assertTrue(listenAction.getSeList().get(1) instanceof BodyEvent);
-    assertTrue(listenAction.getSeList().get(2) instanceof EndEvent);
+    assertTrue(listenAction.getSeList().get(1) instanceof StartEvent);
+    assertTrue(listenAction.getSeList().get(2) instanceof BodyEvent);
+    assertTrue(listenAction.getSeList().get(3) instanceof EndEvent);
     
   }
 }



More information about the logback-dev mailing list