001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.core.joran; 015 016import java.util.HashMap; 017 018import ch.qos.logback.core.joran.action.Action; 019import ch.qos.logback.core.joran.action.NestedBasicPropertyIA; 020import ch.qos.logback.core.joran.action.NestedComplexPropertyIA; 021import ch.qos.logback.core.joran.spi.ElementSelector; 022import ch.qos.logback.core.joran.spi.Interpreter; 023import ch.qos.logback.core.joran.spi.RuleStore; 024 025public class SimpleConfigurator extends GenericConfigurator { 026 027 HashMap<ElementSelector, Action> rulesMap; 028 029 public SimpleConfigurator(HashMap<ElementSelector, Action> rules) { 030 this.rulesMap = rules; 031 } 032 033 @Override 034 protected void addImplicitRules(Interpreter interpreter) { 035 NestedComplexPropertyIA nestedIA = new NestedComplexPropertyIA(getBeanDescriptionCache()); 036 nestedIA.setContext(context); 037 interpreter.addImplicitAction(nestedIA); 038 039 NestedBasicPropertyIA nestedSimpleIA = new NestedBasicPropertyIA(getBeanDescriptionCache()); 040 nestedSimpleIA.setContext(context); 041 interpreter.addImplicitAction(nestedSimpleIA); 042 } 043 044 public Interpreter getInterpreter() { 045 return interpreter; 046 } 047 048 @Override 049 protected void addInstanceRules(RuleStore rs) { 050 for (ElementSelector elementSelector : rulesMap.keySet()) { 051 Action action = rulesMap.get(elementSelector); 052 rs.addRule(elementSelector, action); 053 } 054 } 055 056}