001package ch.qos.logback.core.model;
002
003import java.util.Properties;
004
005import ch.qos.logback.core.joran.action.ActionUtil.Scope;
006import ch.qos.logback.core.model.processor.ModelInterpretationContext;
007import ch.qos.logback.core.util.ContextUtil;
008import ch.qos.logback.core.util.OptionHelper;
009
010public class ModelUtil {
011
012    
013    static public void resetForReuse(Model model) {
014        if(model == null)
015           return;
016        model.resetForReuse();
017    }
018    
019    /**
020     * Add all the properties found in the argument named 'props' to an
021     * InterpretationContext.
022     */
023    static public void setProperty(ModelInterpretationContext mic, String key, String value, Scope scope) {
024        switch (scope) {
025        case LOCAL:
026            mic.addSubstitutionProperty(key, value);
027            break;
028        case CONTEXT:
029            mic.getContext().putProperty(key, value);
030            break;
031        case SYSTEM:
032            OptionHelper.setSystemProperty(mic, key, value);
033        }
034    }
035
036    /**
037     * Add all the properties found in the argument named 'props' to an
038     * InterpretationContext.
039     */
040    static public void setProperties(ModelInterpretationContext ic, Properties props, Scope scope) {
041        switch (scope) {
042        case LOCAL:
043            ic.addSubstitutionProperties(props);
044            break;
045        case CONTEXT:
046            ContextUtil cu = new ContextUtil(ic.getContext());
047            cu.addProperties(props);
048            break;
049        case SYSTEM:
050            OptionHelper.setSystemProperties(ic, props);
051        }
052    }
053}