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

noreply.ceki at qos.ch noreply.ceki at qos.ch
Mon Oct 16 08:28:17 CEST 2006


Author: ceki
Date: Mon Oct 16 08:28:17 2006
New Revision: 686

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/JoranConfiguratorBase.java
   logback/trunk/logback-core/src/test/input/joran/inc.xml
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventRecorderTest.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/SkippingInInterpreterTest.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialcConfiguratorTest.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadBeginAction.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadEndAction.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/HelloAction.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncAction.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java

Log:


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	Mon Oct 16 08:28:17 2006
@@ -1,3 +1,13 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 1999-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;
 
 import java.io.File;

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java	Mon Oct 16 08:28:17 2006
@@ -1,5 +1,5 @@
 /**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
  * 
  * Copyright (C) 1999-2006, QOS.ch
  * 
@@ -10,16 +10,10 @@
 
 package ch.qos.logback.core.joran;
 
-import java.io.IOException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.xml.sax.InputSource;
-
 import ch.qos.logback.core.joran.action.ActionConst;
 import ch.qos.logback.core.joran.action.AppenderAction;
 import ch.qos.logback.core.joran.action.AppenderRefAction;
@@ -51,40 +45,6 @@
 abstract public class JoranConfiguratorBase extends GenericConfigurator {
   
 
-  final public void xdoConfigure(final InputSource inputSource) {
-    // This line is needed here because there is logging from inside this
-    // method.
-    buildInterpreter();
-
-    ExecutionContext ec = interpreter.getExecutionContext();
-
-    SAXParser saxParser = null;
-    try {
-      SAXParserFactory spf = SAXParserFactory.newInstance();
-      spf.setValidating(false);
-      spf.setNamespaceAware(true);
-      saxParser = spf.newSAXParser();
-    } catch (Exception pce) {
-      String errMsg = "Parser configuration error occured";
-      ec.addError(errMsg, pce);
-      return;
-    }
-
-    try {
-      // attachListAppender(context);
-      saxParser.parse(inputSource, interpreter);
-    } catch (IOException ie) {
-      final String errMsg = "I/O error occurred while parsing xml file";
-      ec.addError(errMsg, ie);
-    } catch (Exception ex) {
-      final String errMsg = "Problem parsing XML document. See previously reported errors. Abandoning all further processing.";
-      addError(errMsg, ex);
-      return;
-    } finally {
-      // detachListAppender(repository);
-    }
-  }
-
   public List getErrorList() {
     return null;
   }

Modified: logback/trunk/logback-core/src/test/input/joran/inc.xml
==============================================================================
--- logback/trunk/logback-core/src/test/input/joran/inc.xml	(original)
+++ logback/trunk/logback-core/src/test/input/joran/inc.xml	Mon Oct 16 08:28:17 2006
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 
 <x>
-  <inc/>
+  <inc increment="1"/>
 </x>

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventRecorderTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventRecorderTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventRecorderTest.java	Mon Oct 16 08:28:17 2006
@@ -1,5 +1,5 @@
 /**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
  * 
  * Copyright (C) 1999-2006, QOS.ch
  * 
@@ -18,18 +18,21 @@
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
+
+import org.xml.sax.Attributes;
+
 import ch.qos.logback.core.Context;
 import ch.qos.logback.core.ContextBase;
 import ch.qos.logback.core.joran.spi.BodyEvent;
 import ch.qos.logback.core.joran.spi.SaxEvent;
 import ch.qos.logback.core.joran.spi.SaxEventRecorder;
+import ch.qos.logback.core.joran.spi.StartEvent;
 import ch.qos.logback.core.status.Status;
 import ch.qos.logback.core.status.StatusManager;
 import ch.qos.logback.core.util.Constants;
 
 /**
- * Test the way Interpreter skips elements in case of exceptions thrown by
- * Actions.
+ * Test whether SaxEventRecorder does a good job.
  * 
  * @author Ceki Gulcu
  */
@@ -92,13 +95,26 @@
     List<SaxEvent> seList = doTest("ampEvent.xml");
     StatusManager sm = context.getStatusManager();
     assertTrue(sm.getLevel() == Status.INFO);
-    dump(seList);  
+    //dump(seList);  
     assertEquals(3, seList.size());
     
     BodyEvent be = (BodyEvent) seList.get(1);
     assertEquals("xxx & yyy", be.getText());
   }
 
+  public void test3() throws Exception {
+    List<SaxEvent> seList = doTest("inc.xml");
+    StatusManager sm = context.getStatusManager();
+    assertTrue(sm.getLevel() == Status.INFO);
+    //dump(seList);  
+    assertEquals(4, seList.size());
+    
+    StartEvent se = (StartEvent) seList.get(1);
+    Attributes attr = se.getAttributes();
+    assertNotNull(attr);
+    assertEquals("1", attr.getValue("increment"));
+  }
+
   public static Test XXXsuite() {
     TestSuite suite = new TestSuite();
     suite.addTest(new EventRecorderTest("test2"));

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java	Mon Oct 16 08:28:17 2006
@@ -1,3 +1,13 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 1999-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;
 
 import junit.framework.Test;

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/SkippingInInterpreterTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/SkippingInInterpreterTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/SkippingInInterpreterTest.java	Mon Oct 16 08:28:17 2006
@@ -98,7 +98,8 @@
 
     Interpreter jp = new Interpreter(rs);
     ExecutionContext ec = jp.getExecutionContext();
-
+    ec.setContext(new ContextBase());
+    
     SAXParser saxParser = createParser();
     saxParser.parse("file:" + Constants.TEST_DIR_PREFIX + "input/joran/badEnd1.xml", jp);
     
@@ -118,7 +119,8 @@
 
     Interpreter jp = new Interpreter(rs);
     ExecutionContext ec = jp.getExecutionContext();
-
+    ec.setContext(new ContextBase());
+    
     SAXParser saxParser = createParser();
     saxParser.parse("file:" + Constants.TEST_DIR_PREFIX + "input/joran/badEnd2.xml", jp);
     

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialcConfiguratorTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialcConfiguratorTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialcConfiguratorTest.java	Mon Oct 16 08:28:17 2006
@@ -33,10 +33,11 @@
   public void test() throws Exception {
     int oldBeginCount = IncAction.beginCount;
     int oldEndCount = IncAction.endCount;
+    int oldErrorCount = IncAction.errorCount;
     doTest("inc.xml");
+    assertEquals(oldErrorCount, IncAction.errorCount);
     assertEquals(oldBeginCount+1, IncAction.beginCount);
     assertEquals(oldEndCount+1, IncAction.endCount);
-
   }
 
 }

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadBeginAction.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadBeginAction.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadBeginAction.java	Mon Oct 16 08:28:17 2006
@@ -1,5 +1,5 @@
 /**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
  * 
  * Copyright (C) 1999-2006, QOS.ch
  * 

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadEndAction.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadEndAction.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadEndAction.java	Mon Oct 16 08:28:17 2006
@@ -1,5 +1,5 @@
 /**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
  * 
  * Copyright (C) 1999-2006, QOS.ch
  * 
@@ -7,7 +7,6 @@
  * the terms of the GNU Lesser General Public License as published by the Free
  * Software Foundation.
  */
-
 package ch.qos.logback.core.joran.action;
 
 

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/HelloAction.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/HelloAction.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/HelloAction.java	Mon Oct 16 08:28:17 2006
@@ -1,5 +1,5 @@
 /**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
  * 
  * Copyright (C) 1999-2006, QOS.ch
  * 
@@ -7,7 +7,6 @@
  * the terms of the GNU Lesser General Public License as published by the Free
  * Software Foundation.
  */
-
 package ch.qos.logback.core.joran.action;
 
 import org.xml.sax.Attributes;

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncAction.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncAction.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncAction.java	Mon Oct 16 08:28:17 2006
@@ -13,6 +13,7 @@
 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;
 
 
@@ -21,14 +22,20 @@
 
   static public int  beginCount;
   static public int  endCount;
+  static public int  errorCount;
 
   /**
    * Instantiates an layout of the given class and sets its name.
    *
    */
-  public void begin(ExecutionContext ec, String name, Attributes attributes) {
-    System.out.println("IncAction Begin called");
+  public void begin(ExecutionContext ec, String name, Attributes attributes) throws ActionException {
+    //System.out.println("IncAction Begin called");
     beginCount++;
+    String val = attributes.getValue("increment");
+    if(!"1".equals(val)) {
+      errorCount++;
+      throw new ActionException(ActionException.SKIP_SIBLINGS);
+    }
   }
 
   /**

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java	Mon Oct 16 08:28:17 2006
@@ -9,15 +9,13 @@
  */
 package ch.qos.logback.core.joran.spi;
 
-
-
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
 public class PackageTest extends TestCase {
 
-	public static Test suite() {
+  public static Test suite() {
     TestSuite suite = new TestSuite();
     suite.addTestSuite(PatternTest.class);
     suite.addTestSuite(SimpleStoreTest.class);



More information about the logback-dev mailing list