public List<FruitShell> doFirstPart(String filename) throws Exception { try { HashMap<ElementSelector, Action> rulesMap = new HashMap<ElementSelector, Action>(); rulesMap.put(new ElementSelector("group/fruitShell"), new FruitShellAction()); rulesMap.put(new ElementSelector("group/fruitShell/fruit"), new FruitFactoryAction()); rulesMap.put(new ElementSelector("group/fruitShell/fruit/*"), new NOPAction()); SimpleConfigurator simpleConfigurator = new SimpleConfigurator(rulesMap); simpleConfigurator.setContext(fruitContext); simpleConfigurator.doConfigure(CoreTestConstants.TEST_SRC_PREFIX + "input/joran/replay/" + filename); return fruitContext.getFruitShellList(); } catch (Exception je) { StatusPrinter.print(fruitContext); throw je; } }
@Test public void testBasic() throws JoranException { ListenAction listenAction = new ListenAction(); rulesMap.put(new ElementSelector("fire"), listenAction); TrivialConfigurator gc = new TrivialConfigurator(rulesMap); gc.setContext(context); gc.doConfigure(CoreTestConstants.TEST_SRC_PREFIX + "input/joran/fire1.xml"); //for(SaxEvent se: listenAction.getSeList()) { // System.out.println(se); //} assertEquals(5, listenAction.getSeList().size()); assertTrue(listenAction.getSeList().get(0) instanceof StartEvent); assertTrue(listenAction.getSeList().get(1) instanceof StartEvent); assertTrue(listenAction.getSeList().get(2) instanceof BodyEvent); assertTrue(listenAction.getSeList().get(3) instanceof EndEvent); }
@Test public void testReplay() throws JoranException { ListenAction listenAction = new ListenAction(); rulesMap.put(new ElementSelector("fire"), listenAction); TrivialConfigurator gc = new TrivialConfigurator(rulesMap); gc.setContext(context); gc.doConfigure(CoreTestConstants.TEST_SRC_PREFIX + "input/joran/fire1.xml"); // for(SaxEvent se: listenAction.getSeList()) { // System.out.println(se); // } assertEquals(5, listenAction.getSeList().size()); assertTrue(listenAction.getSeList().get(0) instanceof StartEvent); assertTrue(listenAction.getSeList().get(1) instanceof StartEvent); assertTrue(listenAction.getSeList().get(2) instanceof BodyEvent); assertTrue(listenAction.getSeList().get(3) instanceof EndEvent); }
public static void main(String[] args) throws Exception { Context context = new ContextBase(); Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>(); // we start with the rule for the top-most (root) element ruleMap.put(new ElementSelector("*/foo"), new NOPAction()); // Add an implicit action. List<ImplicitAction> iaList = new ArrayList<ImplicitAction>(); iaList.add(new PrintMeImplicitAction()); SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap, iaList); // link the configurator with its context simpleConfigurator.setContext(context); simpleConfigurator.doConfigure(args[0]); StatusPrinter.printInCaseOfErrorsOrWarnings(context); }
public static void main(String[] args) throws Exception { Context context = new ContextBase(); Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>(); // we start with the rule for the top-most (root) element ruleMap.put(new ElementSelector("*/computation"), new ComputationAction1()); // 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 ruleMap.put(new ElementSelector("/computation/newRule"), new NewRuleAction()); SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap); // link the configurator with its context simpleConfigurator.setContext(context); simpleConfigurator.doConfigure(args[0]); // Print any errors that might have occured. StatusPrinter.printInCaseOfErrorsOrWarnings(context); }
public static void main(String[] args) throws Exception { Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>(); // Note the wild card character '*', in the paterns, signifying any level // of nesting. ruleMap.put(new ElementSelector("*/computation"), new ComputationAction2()); ruleMap.put(new ElementSelector("*/computation/literal"), new LiteralAction()); ruleMap.put(new ElementSelector("*/computation/add"), new AddAction()); ruleMap.put(new ElementSelector("*/computation/multiply"), new MultiplyAction()); 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); } }
public static void main(String[] args) throws Exception { Context context = new ContextBase(); Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>(); // Associate "/computation" pattern with ComputationAction1 ruleMap.put(new ElementSelector("/computation"), new ComputationAction1()); // Other associations ruleMap.put(new ElementSelector("/computation/literal"), new LiteralAction()); ruleMap.put(new ElementSelector("/computation/add"), new AddAction()); ruleMap.put(new ElementSelector("/computation/multiply"), new MultiplyAction()); SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap); // link the configurator with its context simpleConfigurator.setContext(context); simpleConfigurator.doConfigure(args[0]); // Print any errors that might have occured. StatusPrinter.print(context); }
@Override public void addInstanceRules(RuleStore rs) { super.addInstanceRules(rs); rs.addRule(new ElementSelector("configuration"), new ConfigurationAction()); rs.addRule(new ElementSelector("configuration/appender-ref"), new AppenderRefAction()); rs.addRule(new ElementSelector("configuration/appender/sift"), new SiftAction()); rs.addRule(new ElementSelector("configuration/appender/sift/*"), new NOPAction()); rs.addRule(new ElementSelector("configuration/evaluator"), new EvaluatorAction()); // add if-then-else support rs.addRule(new ElementSelector("*/if"), new IfAction()); rs.addRule(new ElementSelector("*/if/then"), new ThenAction()); rs.addRule(new ElementSelector("*/if/then/*"), new NOPAction()); rs.addRule(new ElementSelector("*/if/else"), new ElseAction()); rs.addRule(new ElementSelector("*/if/else/*"), new NOPAction()); rs.addRule(new ElementSelector("configuration/include"), new IncludeAction()); }
@Override public void addInstanceRules(RuleStore rs) { super.addInstanceRules(rs); Environment environment = this.initializationContext.getEnvironment(); rs.addRule(new ElementSelector("configuration/springProperty"), new SpringPropertyAction(environment)); rs.addRule(new ElementSelector("*/springProfile"), new SpringProfileAction(this.initializationContext.getEnvironment())); rs.addRule(new ElementSelector("*/springProfile/*"), new NOPAction()); }
@Override protected void addInstanceRules(RuleStore rs) { // is "configuration/variable" referenced in the docs? rs.addRule(new ElementSelector("configuration/variable"), new PropertyAction()); rs.addRule(new ElementSelector("configuration/property"), new PropertyAction()); rs.addRule(new ElementSelector("configuration/substitutionProperty"), new PropertyAction()); rs.addRule(new ElementSelector("configuration/timestamp"), new TimestampAction()); rs.addRule(new ElementSelector("configuration/shutdownHook"), new ShutdownHookAction()); rs.addRule(new ElementSelector("configuration/define"), new DefinePropertyAction()); // the contextProperty pattern is deprecated. It is undocumented // and will be dropped in future versions of logback rs.addRule(new ElementSelector("configuration/contextProperty"), new ContextPropertyAction()); rs.addRule(new ElementSelector("configuration/conversionRule"), new ConversionRuleAction()); rs.addRule(new ElementSelector("configuration/statusListener"), new StatusListenerAction()); rs.addRule(new ElementSelector("configuration/appender"), new AppenderAction()); rs.addRule(new ElementSelector("configuration/appender/appender-ref"), new AppenderRefAction()); rs.addRule(new ElementSelector("configuration/newRule"), new NewRuleAction()); rs.addRule(new ElementSelector("*/param"), new ParamAction()); }
/** * Instantiates an layout of the given class and sets its name. */ public void begin(InterpretationContext ec, String localName, Attributes attributes) { // Let us forget about previous errors (in this object) inError = false; String errorMsg; String pattern = attributes.getValue(Action.PATTERN_ATTRIBUTE); String actionClass = attributes.getValue(Action.ACTION_CLASS_ATTRIBUTE); if (OptionHelper.isEmpty(pattern)) { inError = true; errorMsg = "No 'pattern' attribute in <newRule>"; addError(errorMsg); return; } if (OptionHelper.isEmpty(actionClass)) { inError = true; errorMsg = "No 'actionClass' attribute in <newRule>"; addError(errorMsg); return; } try { addInfo("About to add new Joran parsing rule [" + pattern + "," + actionClass + "]."); ec.getJoranInterpreter().getRuleStore().addRule(new ElementSelector(pattern), actionClass); } catch (Exception oops) { inError = true; errorMsg = "Could not add new Joran parsing rule [" + pattern + "," + actionClass + "]"; addError(errorMsg); } }
@Override protected void addInstanceRules(RuleStore rs) { for(ElementSelector elementSelector : rulesMap.keySet()) { Action action = rulesMap.get(elementSelector); rs.addRule(elementSelector, action); } }
@Before public void setUp() throws Exception { HashMap<ElementSelector, Action> rulesMap = new HashMap<ElementSelector, Action>(); rulesMap.put(new ElementSelector("x"), new NOPAction()); rulesMap.put(new ElementSelector("x/stack"), stackAction); rulesMap.put(new ElementSelector("x/property"), new PropertyAction()); rulesMap.put(new ElementSelector("*/if"), new IfAction()); rulesMap.put(new ElementSelector("*/if/then"), new ThenAction()); rulesMap.put(new ElementSelector("*/if/then/*"), new NOPAction()); rulesMap.put(new ElementSelector("*/if/else"), new ElseAction()); rulesMap.put(new ElementSelector("*/if/else/*"), new NOPAction()); tc = new TrivialConfigurator(rulesMap); tc.setContext(context); }
@Before public void setUp() throws Exception { HashMap<ElementSelector, Action> rulesMap = new HashMap<ElementSelector, Action>(); rulesMap.put(new ElementSelector("x"), new NOPAction()); rulesMap.put(new ElementSelector("x/stack"), stackAction); rulesMap.put(new ElementSelector("*/if"), new IfAction()); rulesMap.put(new ElementSelector("*/if/then"), new ThenAction()); rulesMap.put(new ElementSelector("*/if/then/*"), new NOPAction()); rulesMap.put(new ElementSelector("*/if/else"), new ElseAction()); rulesMap.put(new ElementSelector("*/if/else/*"), new NOPAction()); rulesMap.put(new ElementSelector("x/include"), new IncludeAction()); tc = new TrivialConfigurator(rulesMap); tc.setContext(context); }
@Before public void setUp() throws Exception { fruitContext.setName("fruits"); HashMap<ElementSelector, Action> rulesMap = new HashMap<ElementSelector, Action>(); rulesMap.put(new ElementSelector("/context/"), new FruitContextAction()); simpleConfigurator = new SimpleConfigurator(rulesMap); simpleConfigurator.setContext(fruitContext); }
@Before public void setUp() throws Exception { HashMap<ElementSelector, Action> rulesMap = new HashMap<ElementSelector, Action>(); rulesMap.put(new ElementSelector("define"), new DefinePropertyAction()); simpleConfigurator = new SimpleConfigurator(rulesMap); simpleConfigurator.setContext(context); }
@Before public void setUp() throws Exception { FileTestUtil.makeTestOutputDir(); HashMap<ElementSelector, Action> rulesMap = new HashMap<ElementSelector, Action>(); rulesMap.put(new ElementSelector("x"), new NOPAction()); rulesMap.put(new ElementSelector("x/include"), new IncludeAction()); rulesMap.put(new ElementSelector("x/stack"), stackAction); tc = new TrivialConfigurator(rulesMap); tc.setContext(context); }
void doTest(String filename, Integer expectedInt, Class<?> exceptionClass) throws Exception { rulesMap.put(new ElementSelector("test"), new NOPAction()); rulesMap.put(new ElementSelector("test/badBegin"), new BadBeginAction()); rulesMap.put(new ElementSelector("test/badBegin/touch"), new TouchAction()); rulesMap.put(new ElementSelector("test/badEnd"), new BadEndAction()); rulesMap.put(new ElementSelector("test/badEnd/touch"), new TouchAction()); rulesMap.put(new ElementSelector("test/hello"), new HelloAction()); rulesMap.put(new ElementSelector("test/isolate"), new NOPAction()); rulesMap.put(new ElementSelector("test/isolate/badEnd"), new BadEndAction()); rulesMap.put(new ElementSelector("test/isolate/badEnd/touch"), new TouchAction()); rulesMap.put(new ElementSelector("test/isolate/touch"), new TouchAction()); rulesMap.put(new ElementSelector("test/hello"), new HelloAction()); TrivialConfigurator tc = new TrivialConfigurator(rulesMap); tc.setContext(context); tc.doConfigure(CoreTestConstants.TEST_SRC_PREFIX + "input/joran/skip/" + filename); String str = context.getProperty(HelloAction.PROPERTY_KEY); assertEquals("Hello John Doe.", str); Integer i = (Integer) context.getObject(TouchAction.KEY); if (expectedInt == null) { assertNull(i); } else { assertEquals(expectedInt, i); } // check the existence of an ERROR status List<Status> statusList = sm.getCopyOfStatusList(); Status s0 = statusList.get(0); assertEquals(Status.ERROR, s0.getLevel()); assertTrue(s0.getThrowable().getClass() == exceptionClass); }
public static void main(String[] args) throws Exception { Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>(); // Associate "hello-world" pattern with HelloWorldAction ruleMap.put(new ElementSelector("hello-world"), new HelloWorldAction()); // 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); simpleConfigurator.doConfigure(args[0]); StatusPrinter.print(context); }
@Override protected void addInstanceRules(RuleStore rs) { for (ElementSelector elementSelector : ruleMap.keySet()) { Action action = ruleMap.get(elementSelector); rs.addRule(elementSelector, action); } }
/** {@inheritDoc} */ @Override public void addInstanceRules(RuleStore ruleStore) { super.addInstanceRules(ruleStore); ruleStore.addRule(new ElementSelector("*/springProfile"), new SpringProfileAction()); ruleStore.addRule(new ElementSelector("*/springProfile/*"), new NOPAction()); ruleStore.addRule(new ElementSelector("configuration/springProperty"), new SpringPropertyAction()); }
@Override protected void addInstanceRules(RuleStore rs) { rs.addRule(new ElementSelector("configuration/property"), new PropertyAction()); rs.addRule(new ElementSelector("configuration/timestamp"), new TimestampAction()); rs.addRule(new ElementSelector("configuration/define"), new DefinePropertyAction()); }
public TrivialConfigurator(HashMap<ElementSelector, Action> rules) { this.rulesMap = rules; }
@Override protected void addInstanceRules(RuleStore rs) { rs.addRule(new ElementSelector("fruitShell"), new NOPAction()); }
public SimpleConfigurator(HashMap<ElementSelector, Action> rules) { this.rulesMap = rules; }
@Override public void addInstanceRules(RuleStore rs) { // parent rules already added super.addInstanceRules(rs); rs.addRule(new ElementSelector("configuration"), new ConfigurationAction()); rs.addRule(new ElementSelector("configuration/contextName"), new ContextNameAction()); rs.addRule(new ElementSelector("configuration/contextListener"), new LoggerContextListenerAction()); rs.addRule(new ElementSelector("configuration/insertFromJNDI"), new InsertFromJNDIAction()); rs.addRule(new ElementSelector("configuration/evaluator"), new EvaluatorAction()); rs.addRule(new ElementSelector("configuration/appender/sift"), new SiftAction()); rs.addRule(new ElementSelector("configuration/appender/sift/*"), new NOPAction()); rs.addRule(new ElementSelector("configuration/logger"), new LoggerAction()); rs.addRule(new ElementSelector("configuration/logger/level"), new LevelAction()); rs.addRule(new ElementSelector("configuration/root"), new RootLoggerAction()); rs.addRule(new ElementSelector("configuration/root/level"), new LevelAction()); rs.addRule(new ElementSelector("configuration/logger/appender-ref"), new AppenderRefAction()); rs.addRule(new ElementSelector("configuration/root/appender-ref"), new AppenderRefAction()); // add if-then-else support rs.addRule(new ElementSelector("*/if"), new IfAction()); rs.addRule(new ElementSelector("*/if/then"), new ThenAction()); rs.addRule(new ElementSelector("*/if/then/*"), new NOPAction()); rs.addRule(new ElementSelector("*/if/else"), new ElseAction()); rs.addRule(new ElementSelector("*/if/else/*"), new NOPAction()); // add jmxConfigurator only if we have JMX available. // If running under JDK 1.4 (retrotranslateed logback) then we // might not have JMX. if (PlatformInfo.hasJMXObjectName()) { rs.addRule(new ElementSelector("configuration/jmxConfigurator"), new JMXConfiguratorAction()); } rs.addRule(new ElementSelector("configuration/include"), new IncludeAction()); rs.addRule(new ElementSelector("configuration/consolePlugin"), new ConsolePluginAction()); rs.addRule(new ElementSelector("configuration/receiver"), new ReceiverAction()); }
@Override protected void addInstanceRules(RuleStore rs) { super.addInstanceRules(rs); rs.addRule(new ElementSelector("configuration/appender"), new AppenderAction()); }
public SimpleConfigurator(Map<ElementSelector, Action> ruleMap) { this(ruleMap, null); }
public SimpleConfigurator(Map<ElementSelector, Action> ruleMap, List<ImplicitAction> iaList) { this.ruleMap = ruleMap; this.iaList = iaList; }
@Override protected void addInstanceRules(RuleStore rs) { rs.addRule(new ElementSelector("configuration/appender"), new AppenderAction()); }
public void doTest(String filename) throws Exception { // rule store is case insensitve rulesMap.put(new ElementSelector("x/inc"), new IncAction()); TrivialConfigurator trivialConfigurator = new TrivialConfigurator(rulesMap); trivialConfigurator.setContext(context); trivialConfigurator.doConfigure(filename); }