svn commit: r741 - in logback/trunk/logback-core: examples/src/joran examples/src/joran/calculator examples/src/joran/helloWorld examples/src/joran/implicit examples/src/joran/newRule src/main/java/ch/qos/logback/core src/main/java/ch/qos/logback/core/joran src/main/java/ch/qos/logback/core/joran/action src/main/java/ch/qos/logback/core/joran/event src/main/java/ch/qos/logback/core/joran/spi src/main/java/ch/qos/logback/core/rolling src/main/java/ch/qos/logback/core/spi src/main/java/ch/qos/lo

Author: ceki Date: Mon Oct 23 18:45:52 2006 New Revision: 741 Added: logback/trunk/logback-core/examples/src/joran/SimpleConfigurator.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java - copied, changed from r734, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ExecutionContext.java logback/trunk/logback-core/src/test/input/joran/fruitWithSubst.xml Removed: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ExecutionContext.java Modified: logback/trunk/logback-core/examples/src/joran/calculator/AddAction.java logback/trunk/logback-core/examples/src/joran/calculator/Calculator1.java logback/trunk/logback-core/examples/src/joran/calculator/Calculator2.java logback/trunk/logback-core/examples/src/joran/calculator/ComputationAction1.java logback/trunk/logback-core/examples/src/joran/calculator/ComputationAction2.java logback/trunk/logback-core/examples/src/joran/calculator/LiteralAction.java logback/trunk/logback-core/examples/src/joran/calculator/MultiplyAction.java logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorld.java logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorldAction.java logback/trunk/logback-core/examples/src/joran/implicit/NOPAction.java logback/trunk/logback-core/examples/src/joran/implicit/PrintMe.java logback/trunk/logback-core/examples/src/joran/implicit/PrintMeImplicitAction.java logback/trunk/logback-core/examples/src/joran/newRule/NewRuleCalculator.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/Context.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/ContextBase.java 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/main/java/ch/qos/logback/core/joran/action/AbstractEventEvaluatorAction.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractLayoutAction.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/Action.java 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/AppenderRefAction.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ConversionRuleAction.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ImplicitAction.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/NOPAction.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedSimplePropertyIA.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NewRuleAction.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ParamAction.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/PropertyAction.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/RepositoryPropertyAction.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/SubstitutionPropertyAction.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/event/SaxEventRecorder.java 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/rolling/TimeBasedRollingPolicy.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareBase.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareImpl.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/PropertySetter.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/action/StackCounterAction.java logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/TouchAction.java logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/event/ListenAction.java logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitConfigurationTest.java logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitFactory.java logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitFactoryAction.java logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitShellAction.java logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/SimpleStoreTest.java Log: - Added support for variable substitition from the context (in Joran) - Other small changes - minor license related corrections Added: logback/trunk/logback-core/examples/src/joran/SimpleConfigurator.java ============================================================================== --- (empty file) +++ logback/trunk/logback-core/examples/src/joran/SimpleConfigurator.java Mon Oct 23 18:45:52 2006 @@ -0,0 +1,55 @@ +/** + * 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 joran; + +import java.util.List; +import java.util.Map; + +import ch.qos.logback.core.joran.GenericConfigurator; +import ch.qos.logback.core.joran.action.Action; +import ch.qos.logback.core.joran.action.ImplicitAction; +import ch.qos.logback.core.joran.spi.Interpreter; +import ch.qos.logback.core.joran.spi.Pattern; +import ch.qos.logback.core.joran.spi.RuleStore; + +public class SimpleConfigurator extends GenericConfigurator { + + final Map<Pattern, Action> ruleMap; + final List<ImplicitAction> iaList; + + public SimpleConfigurator(Map<Pattern, Action> ruleMap) { + this(ruleMap, null); + } + + public SimpleConfigurator(Map<Pattern, Action> ruleMap, List<ImplicitAction> iaList) { + this.ruleMap = ruleMap; + this.iaList = iaList; + } + + @Override + protected void addInstanceRules(RuleStore rs) { + + for (Pattern pattern : ruleMap.keySet()) { + Action action = ruleMap.get(pattern); + rs.addRule(pattern, action); + } + } + + @Override + protected void addImplicitRules(Interpreter interpreter) { + if(iaList == null) { + return; + } + for (ImplicitAction ia : iaList) { + interpreter.addImplicitAction(ia); + } + } + +} Modified: logback/trunk/logback-core/examples/src/joran/calculator/AddAction.java ============================================================================== --- logback/trunk/logback-core/examples/src/joran/calculator/AddAction.java (original) +++ logback/trunk/logback-core/examples/src/joran/calculator/AddAction.java Mon Oct 23 18:45:52 2006 @@ -15,7 +15,7 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.Action; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import java.util.EmptyStackException; @@ -28,7 +28,7 @@ */ public class AddAction extends Action { - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { int first = fetchInteger(ec); int second = fetchInteger(ec); // Push the result of the addition for the following actions. @@ -39,7 +39,7 @@ * Pop the Integer object at the top of the stack. * This code illustrates usage of Joran's error handling paradigm. */ - int fetchInteger(ExecutionContext ec) { + int fetchInteger(InterpretationContext ec) { int result = 0; try { @@ -62,7 +62,7 @@ return result; } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { // Nothing to do here. // In general, the end() method of actions associated with elements // having no children do not need to perform any processing in their Modified: logback/trunk/logback-core/examples/src/joran/calculator/Calculator1.java ============================================================================== --- logback/trunk/logback-core/examples/src/joran/calculator/Calculator1.java (original) +++ logback/trunk/logback-core/examples/src/joran/calculator/Calculator1.java Mon Oct 23 18:45:52 2006 @@ -10,72 +10,59 @@ package joran.calculator; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; +import java.util.HashMap; +import java.util.Map; +import joran.SimpleConfigurator; import ch.qos.logback.core.Context; import ch.qos.logback.core.ContextBase; -import ch.qos.logback.core.joran.spi.ExecutionContext; -import ch.qos.logback.core.joran.spi.Interpreter; +import ch.qos.logback.core.joran.action.Action; +import ch.qos.logback.core.joran.spi.JoranException; import ch.qos.logback.core.joran.spi.Pattern; -import ch.qos.logback.core.joran.spi.RuleStore; -import ch.qos.logback.core.joran.spi.SimpleRuleStore; import ch.qos.logback.core.util.StatusPrinter; - /** * This examples illustrates collaboration between multiple actions through the * common execution context stack. * - * The first and only argument of this application must be the path to - * the XML file to interpret. There are sample XML files in the - * <em>examples/src/joran/calculator/</em> directory. - * + * The first and only argument of this application must be the path to the XML + * file to interpret. There are sample XML files in the + * <em>examples/src/joran/calculator/</em> directory. + * * For example, - * -<pre> - java joran.calculator.Calculator1 examples/src/joran/calculator/calculator1.xml -</pre> - * + * + * <pre> + * java joran.calculator.Calculator1 examples/src/joran/calculator/calculator1.xml + * </pre> + * * Please refer to the comments in the source code for more information. * * @author Ceki Güulcü */ public class Calculator1 { - - + public static void main(String[] args) throws Exception { Context context = new ContextBase(); - - // Create a simple rule store where pattern and action associations will - // be kept. This is a basic requirement before invoking a Joran Interpreter. - RuleStore ruleStore = new SimpleRuleStore(context); - // Associate "/computation" pattern with ComputationAction1 - ruleStore.addRule(new Pattern("/computation"), new ComputationAction1()); + Map<Pattern, Action> ruleMap = new HashMap<Pattern, Action>(); + + // Associate "/computation" pattern with ComputationAction1 + ruleMap.put(new Pattern("/computation"), new ComputationAction1()); // Other associations - ruleStore.addRule(new Pattern("/computation/literal"), new LiteralAction()); - ruleStore.addRule(new Pattern("/computation/add"), new AddAction()); - ruleStore.addRule(new Pattern("/computation/multiply"), new MultiplyAction()); - - // Create a new Joran Interpreter and hand it our simple rule store. - Interpreter ji = new Interpreter(ruleStore); - // set the context for the interpreter's execution context - ExecutionContext ec = ji.getExecutionContext(); - ec.setContext(context); - - - // Create a SAX parser - SAXParserFactory spf = SAXParserFactory.newInstance(); - SAXParser saxParser = spf.newSAXParser(); - - // Parse the file given as the application's first argument and - // set the SAX ContentHandler to the Joran Interpreter we just created. - saxParser.parse(args[0], ji); - - // The file has been parsed and interpreted. We now print any errors that - // might have occured. - StatusPrinter.print(context); + ruleMap.put(new Pattern("/computation/literal"), new LiteralAction()); + ruleMap.put(new Pattern("/computation/add"), new AddAction()); + ruleMap.put(new Pattern("/computation/multiply"), new MultiplyAction()); + + SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap); + // link the configurator with its context + simpleConfigurator.setContext(context); + + try { + simpleConfigurator.doConfigure(args[0]); + } catch (JoranException e) { + // Print any errors that might have occured. + StatusPrinter.print(context); + } } } Modified: logback/trunk/logback-core/examples/src/joran/calculator/Calculator2.java ============================================================================== --- logback/trunk/logback-core/examples/src/joran/calculator/Calculator2.java (original) +++ logback/trunk/logback-core/examples/src/joran/calculator/Calculator2.java Mon Oct 23 18:45:52 2006 @@ -9,16 +9,15 @@ */ package joran.calculator; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; +import java.util.HashMap; +import java.util.Map; +import joran.SimpleConfigurator; import ch.qos.logback.core.Context; import ch.qos.logback.core.ContextBase; -import ch.qos.logback.core.joran.spi.ExecutionContext; -import ch.qos.logback.core.joran.spi.Interpreter; +import ch.qos.logback.core.joran.action.Action; +import ch.qos.logback.core.joran.spi.JoranException; import ch.qos.logback.core.joran.spi.Pattern; -import ch.qos.logback.core.joran.spi.RuleStore; -import ch.qos.logback.core.joran.spi.SimpleRuleStore; import ch.qos.logback.core.util.StatusPrinter; @@ -35,36 +34,27 @@ */ public class Calculator2 { public static void main(String[] args) throws Exception { - Context context = new ContextBase(); - RuleStore ruleStore = new SimpleRuleStore(context); + Map<Pattern, Action> ruleMap = new HashMap<Pattern, Action>(); // Note the wild card character '*', in the paterns, signifying any level // of nesting. - ruleStore.addRule(new Pattern("*/computation"), new ComputationAction2()); - - ruleStore.addRule(new Pattern("*/computation/literal"), new LiteralAction()); - ruleStore.addRule(new Pattern("*/computation/add"), new AddAction()); - ruleStore.addRule(new Pattern("*/computation/multiply"), new MultiplyAction()); - - // Create a new Joran Interpreter and hand it our simple rule store. - Interpreter ji = new Interpreter(ruleStore); - // set the context for the interpreter's execution context - ExecutionContext ec = ji.getExecutionContext(); - ec.setContext(context); + ruleMap.put(new Pattern("*/computation"), new ComputationAction2()); + ruleMap.put(new Pattern("*/computation/literal"), new LiteralAction()); + ruleMap.put(new Pattern("*/computation/add"), new AddAction()); + ruleMap.put(new Pattern("*/computation/multiply"), new MultiplyAction()); - // Create a SAX parser - SAXParserFactory spf = SAXParserFactory.newInstance(); - SAXParser saxParser = spf.newSAXParser(); - - // Parse the file given as the application's first argument and - // set the SAX ContentHandler to the Joran Interpreter we just created. - saxParser.parse(args[0], ji); - - // The file has been parsed and interpreted. We now print any errors that - // might have occured. - StatusPrinter.print(context); - + Context context = new ContextBase(); + SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap); + // link the configurator with its context + simpleConfigurator.setContext(context); + + try { + simpleConfigurator.doConfigure(args[0]); + } catch (JoranException e) { + // Print any errors that might have occured. + StatusPrinter.print(context); + } } } Modified: logback/trunk/logback-core/examples/src/joran/calculator/ComputationAction1.java ============================================================================== --- logback/trunk/logback-core/examples/src/joran/calculator/ComputationAction1.java (original) +++ logback/trunk/logback-core/examples/src/joran/calculator/ComputationAction1.java Mon Oct 23 18:45:52 2006 @@ -15,7 +15,7 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.Action; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.util.OptionHelper; @@ -35,7 +35,7 @@ /** * Store the value of the name attribute for future use. */ - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { nameStr = attributes.getValue(NAME_ATR); } @@ -46,7 +46,7 @@ * This value will be printed on the console but only if the action is * named. Anonymous computation will not print their result. */ - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { if (OptionHelper.isEmpty(nameStr)) { // nothing to do } else { Modified: logback/trunk/logback-core/examples/src/joran/calculator/ComputationAction2.java ============================================================================== --- logback/trunk/logback-core/examples/src/joran/calculator/ComputationAction2.java (original) +++ logback/trunk/logback-core/examples/src/joran/calculator/ComputationAction2.java Mon Oct 23 18:45:52 2006 @@ -15,7 +15,7 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.Action; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.util.OptionHelper; @@ -61,14 +61,14 @@ Stack<String> nameStrStack = new Stack<String>(); - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { String nameStr = attributes.getValue(NAME_ATR); // save nameStr value in a special stack. Note that the value is saved // even if it is empty or null. nameStrStack.push(nameStr); } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { // pop nameStr value from the special stack String nameStr = (String) nameStrStack.pop(); Modified: logback/trunk/logback-core/examples/src/joran/calculator/LiteralAction.java ============================================================================== --- logback/trunk/logback-core/examples/src/joran/calculator/LiteralAction.java (original) +++ logback/trunk/logback-core/examples/src/joran/calculator/LiteralAction.java Mon Oct 23 18:45:52 2006 @@ -13,7 +13,7 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.Action; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.util.OptionHelper; /** @@ -29,7 +29,7 @@ public class LiteralAction extends Action { public static String VALUE_ATR = "value"; - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { String valueStr = attributes.getValue(VALUE_ATR); if (OptionHelper.isEmpty(valueStr)) { @@ -47,7 +47,7 @@ } } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { // Nothing to do here. // In general, the end() method of actions associated with elements // having no children do not need to perform any processing in their Modified: logback/trunk/logback-core/examples/src/joran/calculator/MultiplyAction.java ============================================================================== --- logback/trunk/logback-core/examples/src/joran/calculator/MultiplyAction.java (original) +++ logback/trunk/logback-core/examples/src/joran/calculator/MultiplyAction.java Mon Oct 23 18:45:52 2006 @@ -1,5 +1,5 @@ /** - * Logback: the reliable, fast and flexible logging library for Java. + * Logback: the generic, reliable, fast and flexible logging framework. * * Copyright (C) 1999-2006, QOS.ch * @@ -14,7 +14,7 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.Action; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import java.util.EmptyStackException; @@ -29,7 +29,7 @@ public class MultiplyAction extends Action { - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { int first = fetchInteger(ec); int second = fetchInteger(ec); ec.pushObject(new Integer(first * second)); @@ -39,7 +39,7 @@ * Pop the Integer object at the top of the stack. * This code illustrates usage of Joran's error handling paradigm. */ - int fetchInteger(ExecutionContext ec) { + int fetchInteger(InterpretationContext ec) { int result = 0; try { @@ -61,7 +61,7 @@ return result; } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { // Nothing to do here. // In general, the end() method of actions associated with elements // having no children do not need to perform any processing in their Modified: logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorld.java ============================================================================== --- logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorld.java (original) +++ logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorld.java Mon Oct 23 18:45:52 2006 @@ -10,16 +10,15 @@ package joran.helloWorld; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; +import java.util.HashMap; +import java.util.Map; +import joran.SimpleConfigurator; import ch.qos.logback.core.Context; import ch.qos.logback.core.ContextBase; -import ch.qos.logback.core.joran.spi.ExecutionContext; -import ch.qos.logback.core.joran.spi.Interpreter; +import ch.qos.logback.core.joran.action.Action; +import ch.qos.logback.core.joran.spi.JoranException; import ch.qos.logback.core.joran.spi.Pattern; -import ch.qos.logback.core.joran.spi.RuleStore; -import ch.qos.logback.core.joran.spi.SimpleRuleStore; import ch.qos.logback.core.util.StatusPrinter; @@ -40,29 +39,22 @@ */ public class HelloWorld { public static void main(String[] args) throws Exception { - // Create a simple rule store where pattern and action associations will - // be kept. - Context context = new ContextBase(); - RuleStore ruleStore = new SimpleRuleStore(context); + Map<Pattern, Action> ruleMap = new HashMap<Pattern, Action>(); // Associate "hello-world" pattern with HelloWorldAction - ruleStore.addRule(new Pattern("hello-world"), new HelloWorldAction()); + ruleMap.put(new Pattern("hello-world"), new HelloWorldAction()); - // Create a new Joran Interpreter and hand it our simple rule store. - Interpreter ji = new Interpreter(ruleStore); - ExecutionContext ec = ji.getExecutionContext(); - ec.setContext(context); - - // Create a SAX parser - SAXParserFactory spf = SAXParserFactory.newInstance(); - SAXParser saxParser = spf.newSAXParser(); - - // Parse the file given as the application's first argument and - // set the SAX ContentHandler to the Joran Interpreter we just created. - saxParser.parse(args[0], ji); - - // The file has been parsed and interpreted. We now print any errors that - // might have occured. - StatusPrinter.print(context); - } + // Joran needs to work within a context. + Context context = new ContextBase(); + SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap); + // link the configurator with its context + simpleConfigurator.setContext(context); + + try { + simpleConfigurator.doConfigure(args[0]); + } catch (JoranException e) { + // Print any errors that might have occured. + StatusPrinter.print(context); + } + } } Modified: logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorldAction.java ============================================================================== --- logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorldAction.java (original) +++ logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorldAction.java Mon Oct 23 18:45:52 2006 @@ -15,7 +15,7 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.Action; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; /** @@ -26,10 +26,10 @@ * @author Ceki Gülcü */ public class HelloWorldAction extends Action { - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { System.out.println("Hello World"); } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { } } Modified: logback/trunk/logback-core/examples/src/joran/implicit/NOPAction.java ============================================================================== --- logback/trunk/logback-core/examples/src/joran/implicit/NOPAction.java (original) +++ logback/trunk/logback-core/examples/src/joran/implicit/NOPAction.java Mon Oct 23 18:45:52 2006 @@ -12,7 +12,7 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.Action; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; @@ -23,10 +23,10 @@ */ public class NOPAction extends Action { - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { } } Modified: logback/trunk/logback-core/examples/src/joran/implicit/PrintMe.java ============================================================================== --- logback/trunk/logback-core/examples/src/joran/implicit/PrintMe.java (original) +++ logback/trunk/logback-core/examples/src/joran/implicit/PrintMe.java Mon Oct 23 18:45:52 2006 @@ -1,5 +1,5 @@ /** - * Logback: the reliable, fast and flexible logging library for Java. + * Logback: the generic, reliable, fast and flexible logging framework. * * Copyright (C) 1999-2006, QOS.ch * @@ -7,20 +7,20 @@ * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation. */ - - package joran.implicit; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import joran.SimpleConfigurator; import ch.qos.logback.core.Context; import ch.qos.logback.core.ContextBase; -import ch.qos.logback.core.joran.spi.ExecutionContext; -import ch.qos.logback.core.joran.spi.Interpreter; +import ch.qos.logback.core.joran.action.Action; +import ch.qos.logback.core.joran.action.ImplicitAction; +import ch.qos.logback.core.joran.spi.JoranException; import ch.qos.logback.core.joran.spi.Pattern; -import ch.qos.logback.core.joran.spi.RuleStore; -import ch.qos.logback.core.joran.spi.SimpleRuleStore; import ch.qos.logback.core.util.StatusPrinter; @@ -39,34 +39,29 @@ public static void main(String[] args) throws Exception { Context context = new ContextBase(); - RuleStore ruleStore = new SimpleRuleStore(context); + Map<Pattern, Action> ruleMap = new HashMap<Pattern, Action>(); + // we start with the rule for the top-most (root) element - ruleStore.addRule(new Pattern("*/foo"), new NOPAction()); + ruleMap.put(new Pattern("*/foo"), new NOPAction()); - // Create a new Joran Interpreter and hand it our simple rule store. - Interpreter ji = new Interpreter(ruleStore); - // set the context for the interpreter's execution context - ExecutionContext ec = ji.getExecutionContext(); - ec.setContext(context); - - + List<ImplicitAction> iaList = new ArrayList<ImplicitAction>(); // --------------------------+ // Add an implicit action. | // --------------------------+ - ji.addImplicitAction(new PrintMeImplicitAction()); + iaList.add(new PrintMeImplicitAction()); + + SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap, iaList); + // link the configurator with its context + simpleConfigurator.setContext(context); + + try { + simpleConfigurator.doConfigure(args[0]); + } catch (JoranException e) { + // Print any errors that might have occured. + StatusPrinter.print(context); + } - // Create a SAX parser - SAXParserFactory spf = SAXParserFactory.newInstance(); - SAXParser saxParser = spf.newSAXParser(); - - // Parse the file given as the application's first argument and - // set the SAX ContentHandler to the Joran Interpreter we just created. - saxParser.parse(args[0], ji); - - // The file has been parsed and interpreted. We now print any errors that - // might have occured. - StatusPrinter.print(context); } } Modified: logback/trunk/logback-core/examples/src/joran/implicit/PrintMeImplicitAction.java ============================================================================== --- logback/trunk/logback-core/examples/src/joran/implicit/PrintMeImplicitAction.java (original) +++ logback/trunk/logback-core/examples/src/joran/implicit/PrintMeImplicitAction.java Mon Oct 23 18:45:52 2006 @@ -13,7 +13,7 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.ImplicitAction; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.joran.spi.Pattern; @@ -28,17 +28,17 @@ public class PrintMeImplicitAction extends ImplicitAction { public boolean isApplicable( - Pattern pattern, Attributes attributes, ExecutionContext ec) { + Pattern pattern, Attributes attributes, InterpretationContext ec) { String printmeStr = attributes.getValue("printme"); return Boolean.valueOf(printmeStr).booleanValue(); } - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { System.out.println("Element <"+name+"> asked to be printed."); } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { } } Modified: logback/trunk/logback-core/examples/src/joran/newRule/NewRuleCalculator.java ============================================================================== --- logback/trunk/logback-core/examples/src/joran/newRule/NewRuleCalculator.java (original) +++ logback/trunk/logback-core/examples/src/joran/newRule/NewRuleCalculator.java Mon Oct 23 18:45:52 2006 @@ -10,18 +10,17 @@ package joran.newRule; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; +import java.util.HashMap; +import java.util.Map; +import joran.SimpleConfigurator; import joran.calculator.ComputationAction2; import ch.qos.logback.core.Context; import ch.qos.logback.core.ContextBase; +import ch.qos.logback.core.joran.action.Action; import ch.qos.logback.core.joran.action.NewRuleAction; -import ch.qos.logback.core.joran.spi.ExecutionContext; -import ch.qos.logback.core.joran.spi.Interpreter; +import ch.qos.logback.core.joran.spi.JoranException; import ch.qos.logback.core.joran.spi.Pattern; -import ch.qos.logback.core.joran.spi.RuleStore; -import ch.qos.logback.core.joran.spi.SimpleRuleStore; import ch.qos.logback.core.util.StatusPrinter; @@ -36,38 +35,31 @@ */ public class NewRuleCalculator { public static void main(String[] args) throws Exception { - // As usual, we create a simple rule store. + Context context = new ContextBase(); - RuleStore ruleStore = new SimpleRuleStore(context); + + Map<Pattern, Action> ruleMap = new HashMap<Pattern, Action>(); + // we start with the rule for the top-most (root) element - ruleStore.addRule(new Pattern("*/computation"), new ComputationAction2()); + ruleMap.put(new Pattern("*/computation"), new ComputationAction2()); // Associate "/new-rule" pattern with NewRuleAction from the // org.apache.joran.action package. // // We will let the XML file to teach the Joran interpreter about new rules - ruleStore.addRule( + ruleMap.put( new Pattern("/computation/new-rule"), new NewRuleAction()); - // Create a new Joran Interpreter and hand it our simple rule store. - Interpreter ji = new Interpreter(ruleStore); - // set the context for the interpreter's execution context - ExecutionContext ec = ji.getExecutionContext(); - ec.setContext(context); - - - // Create a SAX parser - SAXParserFactory spf = SAXParserFactory.newInstance(); - SAXParser saxParser = spf.newSAXParser(); - - // Parse the file given as the application's first argument and - // set the SAX ContentHandler to the Joran Interpreter we just created. - saxParser.parse(args[0], ji); - - - // The file has been parsed and interpreted. We now print any errors that - // might have occured. - StatusPrinter.print(context); - } + SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap); + // link the configurator with its context + simpleConfigurator.setContext(context); + + try { + simpleConfigurator.doConfigure(args[0]); + } catch (JoranException e) { + // Print any errors that might have occured. + StatusPrinter.print(context); + } + } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/Context.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/Context.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/Context.java Mon Oct 23 18:45:52 2006 @@ -36,10 +36,13 @@ */ public void putObject(String key, Object value); - /** - * Get the properties specific for this context. + /** + * Get all the properties for this context as a Map. Note that + * the returned cop might be a copy not the original. Thus, modifying + * the returned Map will have no effect (on the original.) + * @return */ - public Map getPropertyMap(); + public Map<String, String> getPropertyMap(); /** * Get the property of this context. @@ -51,7 +54,7 @@ */ public void setProperty(String key, String value); - + /** * LB contexts have a notion of context-specific converter maps. * @return Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/ContextBase.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/ContextBase.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/ContextBase.java Mon Oct 23 18:45:52 2006 @@ -16,10 +16,9 @@ import ch.qos.logback.core.spi.FilterAttachableImpl; import ch.qos.logback.core.status.StatusManager; - public class ContextBase implements Context { - private String name; + private String name; StatusManager sm = new BasicStatusManager(); // TODO propertyMap should be observable so that we can be notified // when it changes so that a new instance of propertyMap can be @@ -28,19 +27,19 @@ Map<String, Object> objectMap = new HashMap<String, Object>(); Map<String, String> converterMap = new HashMap<String, String>(); private FilterAttachableImpl fai = new FilterAttachableImpl(); - + public StatusManager getStatusManager() { return sm; } - + public Map<String, String> getPropertyMap() { - return propertyMap; + return new HashMap<String, String>(propertyMap); } public void setProperty(String key, String val) { this.propertyMap.put(key, val); } - + public String getProperty(String key) { return (String) this.propertyMap.get(key); } @@ -52,7 +51,7 @@ public void putObject(String key, Object value) { objectMap.put(key, value); } - + public Map<String, String> getConverterMap() { return converterMap; } @@ -60,7 +59,7 @@ public void addFilter(Filter newFilter) { fai.addFilter(newFilter); } - + public Filter getFirstFilter() { return fai.getFirstFilter(); } @@ -73,14 +72,14 @@ return fai.getFilterChainDecision(event); } - public String getName() { - return name; - } - - public void setName(String name) { - if(this.name != null) { - throw new IllegalStateException("Context has been already given a name"); - } - this.name = name; - } + public String getName() { + return name; + } + + public void setName(String name) { + if (this.name != null) { + throw new IllegalStateException("Context has been already given a name"); + } + this.name = name; + } } 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 23 18:45:52 2006 @@ -21,7 +21,7 @@ import ch.qos.logback.core.joran.event.SaxEvent; import ch.qos.logback.core.joran.event.SaxEventRecorder; import ch.qos.logback.core.joran.spi.EventPlayer; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.joran.spi.Interpreter; import ch.qos.logback.core.joran.spi.JoranException; import ch.qos.logback.core.joran.spi.RuleStore; @@ -81,8 +81,8 @@ protected void buildInterpreter() { RuleStore rs = new SimpleRuleStore(context); addInstanceRules(rs); - this.interpreter = new Interpreter(rs); - ExecutionContext ec = interpreter.getExecutionContext(); + this.interpreter = new Interpreter(context, rs); + InterpretationContext ec = interpreter.getExecutionContext(); ec.setContext(context); addImplicitRules(interpreter); 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 23 18:45:52 2006 @@ -24,7 +24,7 @@ import ch.qos.logback.core.joran.action.ParamAction; import ch.qos.logback.core.joran.action.RepositoryPropertyAction; import ch.qos.logback.core.joran.action.SubstitutionPropertyAction; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.joran.spi.Interpreter; import ch.qos.logback.core.joran.spi.Pattern; import ch.qos.logback.core.joran.spi.RuleStore; @@ -85,7 +85,7 @@ omap.put(ActionConst.FILTER_CHAIN_BAG, new HashMap()); } - public ExecutionContext getExecutionContext() { + public InterpretationContext getExecutionContext() { return interpreter.getExecutionContext(); } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractEventEvaluatorAction.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractEventEvaluatorAction.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractEventEvaluatorAction.java Mon Oct 23 18:45:52 2006 @@ -18,7 +18,7 @@ import ch.qos.logback.core.CoreGlobal; import ch.qos.logback.core.boolex.EventEvaluator; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.spi.LifeCycle; import ch.qos.logback.core.util.OptionHelper; @@ -31,7 +31,7 @@ /** * Instantiates an evaluator of the given class and sets its name. */ - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { // Let us forget about previous errors (in this instance) inError = false; evaluator = null; @@ -94,7 +94,7 @@ * Once the children elements are also parsed, now is the time to activate * the evaluator options. */ - public void end(ExecutionContext ec, String e) { + public void end(InterpretationContext ec, String e) { if (inError) { return; } @@ -122,6 +122,6 @@ } } - public void finish(ExecutionContext ec) { + public void finish(InterpretationContext ec) { } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractLayoutAction.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractLayoutAction.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractLayoutAction.java Mon Oct 23 18:45:52 2006 @@ -16,7 +16,7 @@ import ch.qos.logback.core.Appender; import ch.qos.logback.core.Layout; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.spi.LifeCycle; import ch.qos.logback.core.util.OptionHelper; @@ -30,7 +30,7 @@ * Instantiates an layout of the given class and sets its name. * */ - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { // Let us forget about previous errors (in this object) inError = false; @@ -66,7 +66,7 @@ * Once the children elements are also parsed, now is the time to activate * the appender options. */ - public void end(ExecutionContext ec, String e) { + public void end(InterpretationContext ec, String e) { if (inError) { return; } @@ -95,6 +95,6 @@ } } - public void finish(ExecutionContext ec) { + public void finish(InterpretationContext ec) { } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/Action.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/Action.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/Action.java Mon Oct 23 18:45:52 2006 @@ -15,7 +15,7 @@ import org.xml.sax.Locator; import ch.qos.logback.core.joran.spi.ActionException; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.joran.spi.Interpreter; import ch.qos.logback.core.spi.ContextAwareBase; @@ -51,20 +51,20 @@ * the returned value is 'false', then child elements are ignored. */ public abstract void begin( - ExecutionContext ec, String name, Attributes attributes) throws ActionException ; + InterpretationContext ec, String name, Attributes attributes) throws ActionException ; - public void body(ExecutionContext ec, String body) throws ActionException { + public void body(InterpretationContext ec, String body) throws ActionException { // NOP } - public abstract void end(ExecutionContext ec, String name) throws ActionException; + public abstract void end(InterpretationContext ec, String name) throws ActionException; public String toString() { return this.getClass().getName(); } - protected int getColumnNumber(ExecutionContext ec) { + protected int getColumnNumber(InterpretationContext ec) { Interpreter jp = ec.getJoranInterpreter(); Locator locator = jp.getLocator(); if (locator != null) { @@ -73,7 +73,7 @@ return -1; } - protected int getLineNumber(ExecutionContext ec) { + protected int getLineNumber(InterpretationContext ec) { Interpreter jp = ec.getJoranInterpreter(); Locator locator = jp.getLocator(); if (locator != null) { 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 Mon Oct 23 18:45:52 2006 @@ -16,7 +16,7 @@ import ch.qos.logback.core.Appender; import ch.qos.logback.core.joran.spi.ActionException; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.spi.LifeCycle; import ch.qos.logback.core.util.OptionHelper; @@ -32,7 +32,7 @@ * The appender thus generated is placed in the ExecutionContext appender bag. */ public void begin( - ExecutionContext ec, String localName, Attributes attributes) throws ActionException { + InterpretationContext ec, String localName, Attributes attributes) throws ActionException { String className = attributes.getValue(CLASS_ATTRIBUTE); // We are just beginning, reset variables @@ -79,7 +79,7 @@ * Once the children elements are also parsed, now is the time to activate * the appender options. */ - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { if (inError) { return; } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderRefAction.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderRefAction.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderRefAction.java Mon Oct 23 18:45:52 2006 @@ -14,7 +14,7 @@ import ch.qos.logback.core.Appender; import ch.qos.logback.core.CoreGlobal; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.spi.AppenderAttachable; import ch.qos.logback.core.util.OptionHelper; @@ -24,7 +24,7 @@ public class AppenderRefAction extends Action { boolean inError = false; - public void begin(ExecutionContext ec, String tagName, Attributes attributes) { + public void begin(InterpretationContext ec, String tagName, Attributes attributes) { // Let us forget about previous errors (in this object) inError = false; @@ -72,9 +72,9 @@ appenderAttachable.addAppender(appender); } - public void end(ExecutionContext ec, String n) { + public void end(InterpretationContext ec, String n) { } - public void finish(ExecutionContext ec) { + public void finish(InterpretationContext ec) { } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ConversionRuleAction.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ConversionRuleAction.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ConversionRuleAction.java Mon Oct 23 18:45:52 2006 @@ -16,7 +16,7 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.CoreGlobal; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.util.OptionHelper; @@ -28,7 +28,7 @@ * Instantiates an layout of the given class and sets its name. * */ - public void begin(ExecutionContext ec, String localName, Attributes attributes) { + public void begin(InterpretationContext ec, String localName, Attributes attributes) { // Let us forget about previous errors (in this object) inError = false; @@ -79,9 +79,9 @@ * Once the children elements are also parsed, now is the time to activate * the appender options. */ - public void end(ExecutionContext ec, String n) { + public void end(InterpretationContext ec, String n) { } - public void finish(ExecutionContext ec) { + public void finish(InterpretationContext ec) { } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ImplicitAction.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ImplicitAction.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ImplicitAction.java Mon Oct 23 18:45:52 2006 @@ -12,7 +12,7 @@ import org.xml.sax.Attributes; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.joran.spi.Pattern; @@ -37,7 +37,7 @@ * @return Whether the implicit action is applicable in the current context */ public abstract boolean isApplicable( - Pattern currentPattern, Attributes attributes, ExecutionContext ec); + Pattern currentPattern, Attributes attributes, InterpretationContext ec); } 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 Mon Oct 23 18:45:52 2006 @@ -14,7 +14,7 @@ import ch.qos.logback.core.boolex.JaninoEventEvaluatorBase; import ch.qos.logback.core.boolex.Matcher; import ch.qos.logback.core.joran.spi.ActionException; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.util.OptionHelper; @@ -28,7 +28,7 @@ * * The appender thus generated is placed in the ExecutionContext appender bag. */ - public void begin(ExecutionContext ec, String localName, Attributes attributes) + public void begin(InterpretationContext ec, String localName, Attributes attributes) throws ActionException { matcher = null; @@ -61,7 +61,7 @@ } } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { if (inError) { return; } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NOPAction.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NOPAction.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NOPAction.java Mon Oct 23 18:45:52 2006 @@ -13,7 +13,7 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.Action; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; /** @@ -25,10 +25,10 @@ */ public class NOPAction extends Action { - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java Mon Oct 23 18:45:52 2006 @@ -14,7 +14,7 @@ import org.xml.sax.Attributes; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.joran.spi.Pattern; import ch.qos.logback.core.spi.ContextAware; import ch.qos.logback.core.spi.LifeCycle; @@ -44,7 +44,7 @@ Stack<ImplicitActionData> actionDataStack = new Stack<ImplicitActionData>(); public boolean isApplicable( - Pattern pattern, Attributes attributes, ExecutionContext ec) { + Pattern pattern, Attributes attributes, InterpretationContext ec) { //LogLog.debug("in NestComponentIA.isApplicable <" + pattern + ">"); String nestedElementTagName = pattern.peekLast(); @@ -72,7 +72,7 @@ } public void begin( - ExecutionContext ec, String localName, Attributes attributes) { + InterpretationContext ec, String localName, Attributes attributes) { //LogLog.debug("in NestComponentIA begin method"); // get the action data object pushed in isApplicable() method call ImplicitActionData actionData = (ImplicitActionData) actionDataStack.peek(); @@ -112,7 +112,7 @@ } } - public void end(ExecutionContext ec, String tagName) { + public void end(InterpretationContext ec, String tagName) { // pop the action data object pushed in isApplicable() method call // we assume that each this begin Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedSimplePropertyIA.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedSimplePropertyIA.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedSimplePropertyIA.java Mon Oct 23 18:45:52 2006 @@ -16,7 +16,7 @@ import org.xml.sax.Attributes; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.joran.spi.Pattern; import ch.qos.logback.core.util.PropertySetter; @@ -41,7 +41,7 @@ Stack<ImplicitActionData> actionDataStack = new Stack<ImplicitActionData>(); public boolean isApplicable( - Pattern pattern, Attributes attributes, ExecutionContext ec) { + Pattern pattern, Attributes attributes, InterpretationContext ec) { //LogLog.debug("in NestComponentIA.isApplicable <" + pattern + ">"); String nestedElementTagName = pattern.peekLast(); @@ -69,20 +69,21 @@ } public void begin( - ExecutionContext ec, String localName, Attributes attributes) { + InterpretationContext ec, String localName, Attributes attributes) { // NOP } - public void body(ExecutionContext ec, String body) { - + public void body(InterpretationContext ec, String body) { + String finalBody = ec.subst(body); + System.out.println("body "+body+", finalBody="+finalBody); // get the action data object pushed in isApplicable() method call ImplicitActionData actionData = (ImplicitActionData) actionDataStack.peek(); actionData.parentBean.setProperty(actionData.propertyName, finalBody); } - public void end(ExecutionContext ec, String tagName) { + public void end(InterpretationContext ec, String tagName) { // pop the action data object pushed in isApplicable() method call actionDataStack.pop(); } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NewRuleAction.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NewRuleAction.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NewRuleAction.java Mon Oct 23 18:45:52 2006 @@ -12,7 +12,7 @@ import org.xml.sax.Attributes; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.joran.spi.Pattern; import ch.qos.logback.core.util.OptionHelper; @@ -23,7 +23,7 @@ /** * Instantiates an layout of the given class and sets its name. */ - public void begin(ExecutionContext ec, String localName, Attributes attributes) { + public void begin(InterpretationContext ec, String localName, Attributes attributes) { // Let us forget about previous errors (in this object) inError = false; String errorMsg; @@ -61,9 +61,9 @@ * Once the children elements are also parsed, now is the time to activate the * appender options. */ - public void end(ExecutionContext ec, String n) { + public void end(InterpretationContext ec, String n) { } - public void finish(ExecutionContext ec) { + public void finish(InterpretationContext ec) { } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ParamAction.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ParamAction.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/ParamAction.java Mon Oct 23 18:45:52 2006 @@ -13,7 +13,7 @@ import org.xml.sax.Attributes; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.util.PropertySetter; @@ -24,7 +24,7 @@ boolean inError = false; public void begin( - ExecutionContext ec, String localName, Attributes attributes) { + InterpretationContext ec, String localName, Attributes attributes) { String name = attributes.getValue(NAME_ATTRIBUTE); String value = attributes.getValue(VALUE_ATTRIBUTE); @@ -55,9 +55,9 @@ propSetter.setProperty(name, value); } - public void end(ExecutionContext ec, String localName) { + public void end(InterpretationContext ec, String localName) { } - public void finish(ExecutionContext ec) { + public void finish(InterpretationContext ec) { } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/PropertyAction.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/PropertyAction.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/PropertyAction.java Mon Oct 23 18:45:52 2006 @@ -11,7 +11,7 @@ import org.xml.sax.Attributes; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.pattern.util.EscapeUtil; import ch.qos.logback.core.util.OptionHelper; @@ -32,8 +32,8 @@ "In <property> element, either the \"file\" attribute or both the \"name\" and \"value\" attributes must be set."; - abstract void setProperties(ExecutionContext ec, Properties props); - abstract void setProperty(ExecutionContext ec, String key, String value); + abstract void setProperties(InterpretationContext ec, Properties props); + abstract void setProperty(InterpretationContext ec, String key, String value); /** * Set a new property for the execution context by name, value pair, or adds @@ -41,7 +41,7 @@ * */ public void begin( - ExecutionContext ec, String localName, Attributes attributes) { + InterpretationContext ec, String localName, Attributes attributes) { String name = attributes.getValue(NAME_ATTRIBUTE); String value = attributes.getValue(NAME_ATTRIBUTE); String fileName = attributes.getValue(FILE_ATTRIBUTE); @@ -75,9 +75,9 @@ } } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { } - public void finish(ExecutionContext ec) { + public void finish(InterpretationContext ec) { } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/RepositoryPropertyAction.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/RepositoryPropertyAction.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/RepositoryPropertyAction.java Mon Oct 23 18:45:52 2006 @@ -3,7 +3,7 @@ import java.util.Properties; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; /** @@ -13,14 +13,16 @@ /** * Add all the properties found in the argument named 'props' to an ExecutionContext. - * */ - @SuppressWarnings("unchecked") - public void setProperties(ExecutionContext ec, Properties props) { - this.context.getPropertyMap().putAll(props); + public void setProperties(InterpretationContext ec, Properties props) { + // TODO : test this method + for(Object o: props.keySet()) { + String key = (String) o; + this.context.setProperty(key, props.getProperty(key)); + } } - public void setProperty(ExecutionContext ec, String key, String value) { + public void setProperty(InterpretationContext ec, String key, String value) { this.context.setProperty(key, value); } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/SubstitutionPropertyAction.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/SubstitutionPropertyAction.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/SubstitutionPropertyAction.java Mon Oct 23 18:45:52 2006 @@ -12,7 +12,7 @@ import java.util.Properties; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; /** * This action sets new substitution properties for the execution context by @@ -23,11 +23,16 @@ */ public class SubstitutionPropertyAction extends PropertyAction { - public void setProperties(ExecutionContext ec, Properties props) { + public void setProperties(InterpretationContext ec, Properties props) { ec.addProperties(props); +// for(Object o: props.keySet()) { +// String key = (String) o; +// ec.getContext().setProperty(key, props.getProperty(key)); +// } } - public void setProperty(ExecutionContext ec, String key, String value) { + public void setProperty(InterpretationContext ec, String key, String value) { ec.addProperty(key, value); + //ec.getContext().setProperty(key, value); } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/event/SaxEventRecorder.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/event/SaxEventRecorder.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/event/SaxEventRecorder.java Mon Oct 23 18:45:52 2006 @@ -34,8 +34,12 @@ public class SaxEventRecorder extends DefaultHandler implements ContextAware { - ContextAwareImpl cai = new ContextAwareImpl(); - + + final ContextAwareImpl cai; + + public SaxEventRecorder() { + cai = new ContextAwareImpl(this); + } public List<SaxEvent> saxEventList = new ArrayList<SaxEvent>(); Locator locator; Pattern globalPattern = new Pattern(); Copied: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java (from r734, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ExecutionContext.java) ============================================================================== --- /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ExecutionContext.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java Mon Oct 23 18:45:52 2006 @@ -19,13 +19,11 @@ import org.xml.sax.Locator; +import ch.qos.logback.core.Context; import ch.qos.logback.core.joran.action.Action; import ch.qos.logback.core.joran.event.InPlayListener; import ch.qos.logback.core.joran.event.SaxEvent; import ch.qos.logback.core.spi.ContextAwareBase; -import ch.qos.logback.core.status.ErrorStatus; -import ch.qos.logback.core.status.InfoStatus; -import ch.qos.logback.core.status.WarnStatus; import ch.qos.logback.core.util.OptionHelper; @@ -37,56 +35,19 @@ * * @author Ceki Gülcü */ -public class ExecutionContext extends ContextAwareBase { +public class InterpretationContext extends ContextAwareBase { Stack<Object> objectStack; Map<String, Object> objectMap; - Properties substitutionProperties; + Map<String, String> substitutionMap; Interpreter joranInterpreter; final List<InPlayListener> listenerList = new ArrayList<InPlayListener>(); - public ExecutionContext(Interpreter joranInterpreter) { + public InterpretationContext(Context context, Interpreter joranInterpreter) { this.joranInterpreter = joranInterpreter; objectStack = new Stack<Object> (); objectMap = new HashMap<String, Object>(5); - substitutionProperties = new Properties(); + substitutionMap = new HashMap<String, String>(); } - - // /** - // * Clear the internal structures for reuse of the execution context - // * - // */ - // public void clear() { - // objectStack.clear(); - // objectMap.clear(); - // errorList.clear(); - // substitutionProperties.clear(); - // } - - public void addError(String msg, Object origin) { - msg = updateLocationInfo(msg); - addStatus(new ErrorStatus(msg, origin)); - } - - public void addError(String msg, Object origin, Exception e) { - msg = updateLocationInfo(msg); - addStatus(new ErrorStatus(msg, origin, e)); - } - - public void addWarn(String msg, Object origin) { - msg = updateLocationInfo(msg); - addStatus(new WarnStatus(msg, origin)); - } - - public void addWarn(String msg, Object origin, Exception e) { - msg = updateLocationInfo(msg); - addStatus(new WarnStatus(msg, origin, e)); - } - - public void addInfo(String msg, Object origin) { - msg = updateLocationInfo(msg); - addStatus(new InfoStatus(msg, origin)); - } - String updateLocationInfo(String msg) { Locator locator = joranInterpreter.getLocator(); @@ -146,7 +107,7 @@ // values with leading or trailing spaces are bad. We remove them now. value = value.trim(); - substitutionProperties.put(key, value); + substitutionMap.put(key, value); } public void addProperties(Properties props) { @@ -161,19 +122,19 @@ } public String getSubstitutionProperty(String key) { - return substitutionProperties.getProperty(key); + return substitutionMap.get(key); } public String subst(String value) { if (value == null) { return null; } - return OptionHelper.substVars(value, substitutionProperties); + return OptionHelper.substVars(value, substitutionMap, context.getPropertyMap()); } public void addInPlayListener(InPlayListener ipl) { if(listenerList.contains(ipl)) { - System.out.println("InPlayListener "+ipl+" has been already registered"); + addWarn("InPlayListener "+ipl+" has been already registered"); } else { listenerList.add(ipl); } 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 Mon Oct 23 18:45:52 2006 @@ -18,11 +18,13 @@ import org.xml.sax.Attributes; import org.xml.sax.Locator; +import ch.qos.logback.core.Context; import ch.qos.logback.core.joran.action.Action; import ch.qos.logback.core.joran.action.ImplicitAction; import ch.qos.logback.core.joran.event.BodyEvent; import ch.qos.logback.core.joran.event.EndEvent; import ch.qos.logback.core.joran.event.StartEvent; +import ch.qos.logback.core.spi.ContextAwareImpl; /** * <id>Interpreter</id> is Joran's main driving class. It extends SAX @@ -57,12 +59,13 @@ * @author Ceki Gülcuü * */ -public class Interpreter { +public class Interpreter { private static List EMPTY_LIST = new Vector(0); final private RuleStore ruleStore; - final private ExecutionContext ec; + final private InterpretationContext ec; final private ArrayList<ImplicitAction> implicitActions; + final private ContextAwareImpl cai; Pattern pattern; Locator locator; @@ -82,15 +85,17 @@ */ Pattern skip = null; - public Interpreter(RuleStore rs) { - ruleStore = rs; - ec = new ExecutionContext(this); + public Interpreter(Context context, RuleStore rs) { + this.cai = new ContextAwareImpl(this); + this.cai.setContext(context); + ruleStore = rs; + ec = new InterpretationContext(context, this); implicitActions = new ArrayList<ImplicitAction>(3); pattern = new Pattern(); actionListStack = new Stack<List>(); } - public ExecutionContext getExecutionContext() { + public InterpretationContext getExecutionContext() { return ec; } @@ -197,7 +202,7 @@ * one element. */ List lookupImplicitAction(Pattern pattern, Attributes attributes, - ExecutionContext ec) { + InterpretationContext ec) { int len = implicitActions.size(); for (int i = 0; i < len; i++) { @@ -265,7 +270,7 @@ } catch (Exception e) { skip = (Pattern) pattern.clone(); // getLogger().info("Skip pattern set to <{}>", skip); - ec.addError("Exception in Action for tag <" + tagName + ">", this, e); + cai.addError("Exception in Action for tag <" + tagName + ">", e); } } } @@ -281,8 +286,7 @@ try { action.body(ec, body); } catch (ActionException ae) { - ec.addError("Exception in end() methd for action [" + action + "]", - this, ae); + cai.addError("Exception in end() methd for action [" + action + "]", ae); } } } @@ -313,7 +317,7 @@ } // getLogger().info("Skip pattern set to <{}>", skip); } catch (Exception e) { - ec.addError("Exception in Action for tag <" + tagName + ">", this, e); + cai.addError("Exception in Action for tag <" + tagName + ">", e); skip = (Pattern) pattern.clone(); skip.pop(); // induce the siblings to be skipped // getLogger().info("Skip pattern set to <{}>.", skip); Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java Mon Oct 23 18:45:52 2006 @@ -213,8 +213,8 @@ } public void rollover() throws RolloverFailure { - addInfo("roll-over called"); - addInfo("compressionMode: " + compressionMode); + //addInfo("roll-over called"); + //addInfo("compressionMode: " + compressionMode); if (activeFileName == null) { switch (compressionMode) { Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareBase.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareBase.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareBase.java Mon Oct 23 18:45:52 2006 @@ -9,14 +9,78 @@ */ package ch.qos.logback.core.spi; +import ch.qos.logback.core.Context; +import ch.qos.logback.core.status.ErrorStatus; +import ch.qos.logback.core.status.InfoStatus; +import ch.qos.logback.core.status.Status; +import ch.qos.logback.core.status.StatusManager; +import ch.qos.logback.core.status.WarnStatus; + /** - * A helper class that implements ContextAware methods. This class can be either - * extended or alternatively included as a component. + * A helper class that implements ContextAware methods. A class can implement + * the ContextAware interface by deriving from this class. * * @author Ceki Gülcü */ -public class ContextAwareBase extends ContextAwareImpl { - // to be removed +public class ContextAwareBase implements ContextAware { + private int noContextWarning = 0; + protected Context context; + + public void setContext(Context context) { + if (this.context == null) { + this.context = context; + } else if (this.context != context) { + throw new IllegalStateException("Context has been already set"); + } + } + + public Context getContext() { + return this.context; + } + + public StatusManager getStatusManager() { + if (context == null) { + return null; + } + return context.getStatusManager(); + } + + public void addStatus(Status status) { + if (context == null) { + if (noContextWarning++ == 0) { + System.out.println("LOGBACK: No context given for " + this); + } + return; + } + StatusManager sm = context.getStatusManager(); + if (sm != null) { + sm.add(status); + } + } + + public void addInfo(String msg) { + addStatus(new InfoStatus(msg, this)); + } + + public void addInfo(String msg, Throwable ex) { + addStatus(new InfoStatus(msg, this, ex)); + } + + public void addWarn(String msg) { + addStatus(new WarnStatus(msg, this)); + } + + public void addWarn(String msg, Throwable ex) { + addStatus(new WarnStatus(msg, this, ex)); + } + + public void addError(String msg) { + addStatus(new ErrorStatus(msg, this)); + } + + public void addError(String msg, Throwable ex) { + addStatus(new ErrorStatus(msg, this, ex)); + } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareImpl.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareImpl.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareImpl.java Mon Oct 23 18:45:52 2006 @@ -18,16 +18,21 @@ /** - * A helper class that implements ContextAware methods. This class can be either - * extended or alternatively included as a component. + * A helper class that implements ContextAware methods. Use this class to + * implement the ContextAware interface by composition. * * @author Ceki Gülcü */ -public class ContextAwareImpl implements ContextAware { +final public class ContextAwareImpl implements ContextAware { private int noContextWarning = 0; protected Context context; - + final Object origin; + + public ContextAwareImpl(Object origin) { + this.origin = origin; + } + public void setContext(Context context) { if (this.context == null) { this.context = context; @@ -61,27 +66,27 @@ } public void addInfo(String msg) { - addStatus(new InfoStatus(msg, this)); + addStatus(new InfoStatus(msg, origin)); } public void addInfo(String msg, Throwable ex) { - addStatus(new InfoStatus(msg, this, ex)); + addStatus(new InfoStatus(msg, origin, ex)); } public void addWarn(String msg) { - addStatus(new WarnStatus(msg, this)); + addStatus(new WarnStatus(msg, origin)); } public void addWarn(String msg, Throwable ex) { - addStatus(new WarnStatus(msg, this, ex)); + addStatus(new WarnStatus(msg, origin, ex)); } public void addError(String msg) { - addStatus(new ErrorStatus(msg, this)); + addStatus(new ErrorStatus(msg, origin)); } public void addError(String msg, Throwable ex) { - addStatus(new ErrorStatus(msg, this, ex)); + addStatus(new ErrorStatus(msg, origin, ex)); } } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java Mon Oct 23 18:45:52 2006 @@ -1,5 +1,5 @@ /** - * LOGBack: the reliable, fast and flexible logging library for Java. + * Logback: the generic, reliable, fast and flexible logging framework. * * Copyright (C) 1999-2006, QOS.ch * @@ -9,7 +9,7 @@ */ package ch.qos.logback.core.util; -import java.util.Properties; +import java.util.Map; import ch.qos.logback.core.CoreGlobal; @@ -39,19 +39,19 @@ * Then perform variable substitution on the found value. * */ - public static String findAndSubst(String key, Properties props) { - String value = props.getProperty(key); - - if (value == null) { - return null; - } - - try { - return substVars(value, props); - } catch (IllegalArgumentException e) { - return value; - } - } +// public static String findAndSubst(String key, Properties props) { +// String value = props.getProperty(key); +// +// if (value == null) { +// return null; +// } +// +// try { +// return substVars(value, props); +// } catch (IllegalArgumentException e) { +// return value; +// } +// } final static String DELIM_START = "${"; final static char DELIM_STOP = '}'; @@ -59,25 +59,24 @@ final static int DELIM_STOP_LEN = 1; /** * Perform variable substitution in string <code>val</code> from the values - * of keys found the properties passed as parameter or in the system - * properties. + * of keys found the primary map passed as first parameter, then in the secondary + * map, and last in the system properties. * * <p> * The variable substitution delimeters are <b>${</b> and <b>}</b>. * * <p> - * For example, if the properties parameter contains a property "key1" set as + * For example, if the primary map parameter contains a property "key1" set as * "value1", then the call * * <pre> - * String s = OptionConverter.substituteVars("Value of key is ${key1}."); + * String s = OptionConverter.substituteVars("Value of key is ${key1}.", priMap, null); * </pre> - * * will set the variable <code>s</code> to "Value of key is value1.". * * <p> - * If no value could be found for the specified key, then the system - * properties are searched, if the value could not be found there, then + * If no value could be found for the specified key, then the secondary map is searches, + * and if that fails, the system properties are searched, if that fails, then * substitution defaults to the empty string. * * <p> @@ -86,7 +85,7 @@ * * <pre> * String s = OptionConverter - * .subsVars("Value of inexistentKey is [${inexistentKey}]"); + * .subsVars("Value of inexistentKey is [${inexistentKey}]", priMap, null); * </pre> * * will set <code>s</code> to "Value of inexistentKey is []". @@ -113,7 +112,7 @@ * @throws IllegalArgumentException * if <code>val</code> is malformed. */ - public static String substVars(String val, Properties props) { + public static String substVars(String val, Map<String, String> primaryMap, Map<String, String> secondaryMap) { StringBuffer sbuf = new StringBuffer(); @@ -155,8 +154,12 @@ String replacement = null; // first try the props passed as parameter - if (props != null) { - replacement = props.getProperty(key); + if (primaryMap != null) { + replacement = primaryMap.get(key); + } + + if(replacement == null && secondaryMap != null) { + replacement = secondaryMap.get(key); } // then try in System properties @@ -176,7 +179,7 @@ // where the properties are // x1=p1 // x2=${x1} - String recursiveReplacement = substVars(replacement, props); + String recursiveReplacement = substVars(replacement, primaryMap, secondaryMap); sbuf.append(recursiveReplacement); } Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/PropertySetter.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/PropertySetter.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/PropertySetter.java Mon Oct 23 18:45:52 2006 @@ -22,12 +22,8 @@ import java.beans.Introspector; import java.beans.MethodDescriptor; import java.beans.PropertyDescriptor; +import java.lang.reflect.Method; -import java.lang.reflect.*; - -import java.util.*; - -import ch.qos.logback.core.Appender; import ch.qos.logback.core.spi.ContextAwareBase; /** @@ -96,33 +92,33 @@ * Set the properties for the object that match the <code>prefix</code> * passed as parameter. */ - public void setProperties(Properties properties, String prefix) { - int len = prefix.length(); - - for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) { - String key = (String) e.nextElement(); - - // handle only properties that start with the desired frefix. - if (key.startsWith(prefix)) { - // ignore key if it contains dots after the prefix - if (key.indexOf('.', len + 1) > 0) { - // System.err.println("----------Ignoring---["+key - // +"], prefix=["+prefix+"]."); - continue; - } - - String value = OptionHelper.findAndSubst(key, properties); - - key = key.substring(len); - - if ("layout".equals(key) && obj instanceof Appender) { - continue; - } - - setProperty(key, value); - } - } - } +// public void setProperties(Properties properties, String prefix) { +// int len = prefix.length(); +// +// for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) { +// String key = (String) e.nextElement(); +// +// // handle only properties that start with the desired frefix. +// if (key.startsWith(prefix)) { +// // ignore key if it contains dots after the prefix +// if (key.indexOf('.', len + 1) > 0) { +// // System.err.println("----------Ignoring---["+key +// // +"], prefix=["+prefix+"]."); +// continue; +// } +// +// String value = OptionHelper.findAndSubst(key, properties); +// +// key = key.substring(len); +// +// if ("layout".equals(key) && obj instanceof Appender) { +// continue; +// } +// +// setProperty(key, value); +// } +// } +// } /** * Set a property on this PropertySetter's Object. If successful, this method Added: logback/trunk/logback-core/src/test/input/joran/fruitWithSubst.xml ============================================================================== --- (empty file) +++ logback/trunk/logback-core/src/test/input/joran/fruitWithSubst.xml Mon Oct 23 18:45:52 2006 @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<group> + <fruitShell name="fs0"> + <fruit class="ch.qos.logback.core.joran.replay.WeightytFruit"> + <name>${fruitKey}</name> + <weight>1.2</weight> + </fruit> + </fruitShell> +</group> \ No newline at end of file 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 23 18:45:52 2006 @@ -13,7 +13,7 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.Action; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; @@ -23,10 +23,10 @@ public BadBeginAction() { } - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { throw new IllegalStateException("bad begin"); } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { } } 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 23 18:45:52 2006 @@ -14,17 +14,17 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.Action; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; public class BadEndAction extends Action { - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { throw new IllegalStateException("bad end"); } } 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 23 18:45:52 2006 @@ -12,7 +12,7 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.Action; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; @@ -25,7 +25,7 @@ * Instantiates an layout of the given class and sets its name. * */ - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { String str = "Hello "+attributes.getValue("name")+"."; ec.getContext().setProperty("hello", str); } @@ -34,6 +34,6 @@ * Once the children elements are also parsed, now is the time to activate * the appender options. */ - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { } } 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 23 18:45:52 2006 @@ -14,7 +14,7 @@ import ch.qos.logback.core.joran.action.Action; import ch.qos.logback.core.joran.spi.ActionException; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; @@ -28,7 +28,7 @@ * Instantiates an layout of the given class and sets its name. * */ - public void begin(ExecutionContext ec, String name, Attributes attributes) throws ActionException { + public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { //System.out.println("IncAction Begin called"); beginCount++; String val = attributes.getValue("increment"); @@ -42,7 +42,7 @@ * Once the children elements are also parsed, now is the time to activate * the appender options. */ - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { endCount++; } } Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/StackCounterAction.java ============================================================================== --- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/StackCounterAction.java (original) +++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/StackCounterAction.java Mon Oct 23 18:45:52 2006 @@ -15,7 +15,7 @@ import ch.qos.logback.core.Layout; import ch.qos.logback.core.joran.action.Action; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; @@ -29,7 +29,7 @@ * Instantiates an layout of the given class and sets its name. * */ - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { //String str = "Pushing "+name+"-begin"; ec.pushObject(name+"-begin"); } @@ -38,11 +38,11 @@ * Once the children elements are also parsed, now is the time to activate * the appender options. */ - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { //String str = "Pushing "+name+"-end"; ec.pushObject(name+"-end"); } - public void finish(ExecutionContext ec) { + public void finish(InterpretationContext ec) { } } Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/TouchAction.java ============================================================================== --- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/TouchAction.java (original) +++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/TouchAction.java Mon Oct 23 18:45:52 2006 @@ -14,7 +14,7 @@ import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.Action; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; @@ -28,7 +28,7 @@ * Instantiates an layout of the given class and sets its name. * */ - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { Integer i = (Integer) ec.getContext().getObject(KEY); if(i == null) { ec.getContext().putObject(KEY, new Integer(1)); @@ -41,6 +41,6 @@ * Once the children elements are also parsed, now is the time to activate * the appender options. */ - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { } } Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/event/ListenAction.java ============================================================================== --- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/event/ListenAction.java (original) +++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/event/ListenAction.java Mon Oct 23 18:45:52 2006 @@ -17,20 +17,20 @@ import ch.qos.logback.core.joran.action.Action; import ch.qos.logback.core.joran.spi.ActionException; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; public class ListenAction extends Action implements InPlayListener { List<SaxEvent> seList = new ArrayList<SaxEvent>(); @Override - public void begin(ExecutionContext ec, String name, Attributes attributes) + public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { ec.addInPlayListener(this); } @Override - public void end(ExecutionContext ec, String name) throws ActionException { + public void end(InterpretationContext ec, String name) throws ActionException { ec.removeInPlayListener(this); } Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitConfigurationTest.java ============================================================================== --- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitConfigurationTest.java (original) +++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitConfigurationTest.java Mon Oct 23 18:45:52 2006 @@ -3,9 +3,11 @@ import java.util.HashMap; import java.util.List; +import junit.framework.Test; import junit.framework.TestCase; -import ch.qos.logback.core.joran.action.NOPAction; +import junit.framework.TestSuite; import ch.qos.logback.core.joran.action.Action; +import ch.qos.logback.core.joran.action.NOPAction; import ch.qos.logback.core.joran.spi.Pattern; import ch.qos.logback.core.util.Constants; import ch.qos.logback.core.util.StatusPrinter; @@ -76,4 +78,25 @@ assertEquals("orange", fruit1.getName()); assertEquals(1.2, ((WeightytFruit) fruit1).getWeight()); } + + public void testWithSubst() throws Exception { + List<FruitShell> fsList = doFirstPart("fruitWithSubst.xml"); + assertNotNull(fsList); + assertEquals(1, fsList.size()); + + FruitShell fs0 = fsList.get(0); + assertNotNull(fs0); + assertEquals("fs0", fs0.getName()); + Fruit fruit0 = fs0.fruitFactory.buildFruit(); + assertTrue(fruit0 instanceof WeightytFruit); + assertEquals("orange-0", fruit0.getName()); + assertEquals(1.2, ((WeightytFruit) fruit0).getWeight()); + } + + public static Test suite() { + TestSuite suite = new TestSuite(); + suite.addTest(new FruitConfigurationTest("testWithSubst")); + //suite.addTestSuite(FruitConfigurationTest.class); + return suite; + } } Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitFactory.java ============================================================================== --- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitFactory.java (original) +++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitFactory.java Mon Oct 23 18:45:52 2006 @@ -9,6 +9,8 @@ public class FruitFactory { + static int count = 0; + List<SaxEvent> eventList; Fruit fruit; @@ -22,6 +24,9 @@ } Context context = new ContextBase(); this.fruit = null; + context.setProperty("fruitKey", "orange-"+count); + // for next round + count++; FruitConfigurator fruitConfigurator = new FruitConfigurator(this); fruitConfigurator.setContext(context); try { Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitFactoryAction.java ============================================================================== --- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitFactoryAction.java (original) +++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitFactoryAction.java Mon Oct 23 18:45:52 2006 @@ -19,20 +19,20 @@ import ch.qos.logback.core.joran.event.InPlayListener; import ch.qos.logback.core.joran.event.SaxEvent; import ch.qos.logback.core.joran.spi.ActionException; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; public class FruitFactoryAction extends Action implements InPlayListener { List<SaxEvent> seList = new ArrayList<SaxEvent>(); @Override - public void begin(ExecutionContext ec, String name, Attributes attributes) + public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { ec.addInPlayListener(this); } @Override - public void end(ExecutionContext ec, String name) throws ActionException { + public void end(InterpretationContext ec, String name) throws ActionException { ec.removeInPlayListener(this); Object o = ec.peekObject(); Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitShellAction.java ============================================================================== --- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitShellAction.java (original) +++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/replay/FruitShellAction.java Mon Oct 23 18:45:52 2006 @@ -14,7 +14,7 @@ import ch.qos.logback.core.joran.action.Action; import ch.qos.logback.core.joran.spi.ActionException; -import ch.qos.logback.core.joran.spi.ExecutionContext; +import ch.qos.logback.core.joran.spi.InterpretationContext; import ch.qos.logback.core.util.OptionHelper; public class FruitShellAction extends Action { @@ -24,7 +24,7 @@ @Override - public void begin(ExecutionContext ec, String name, Attributes attributes) + public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { // We are just beginning, reset variables @@ -56,7 +56,7 @@ } @Override - public void end(ExecutionContext ec, String name) throws ActionException { + public void end(InterpretationContext ec, String name) throws ActionException { if (inError) { return; } Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/SimpleStoreTest.java ============================================================================== --- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/SimpleStoreTest.java (original) +++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/SimpleStoreTest.java Mon Oct 23 18:45:52 2006 @@ -137,35 +137,35 @@ class XAction extends Action { - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { } - public void finish(ExecutionContext ec) { + public void finish(InterpretationContext ec) { } } class YAction extends Action { - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { } - public void finish(ExecutionContext ec) { + public void finish(InterpretationContext ec) { } } class ZAction extends Action { - public void begin(ExecutionContext ec, String name, Attributes attributes) { + public void begin(InterpretationContext ec, String name, Attributes attributes) { } - public void end(ExecutionContext ec, String name) { + public void end(InterpretationContext ec, String name) { } - public void finish(ExecutionContext ec) { + public void finish(InterpretationContext ec) { } } }
participants (1)
-
noreply.ceki@qos.ch