Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2011, QOS.ch. All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
 
 package ch.qos.logback.core.joran.conditional;
 
 import java.util.List;
 
 
 
 public class IfAction extends Action {
   private static final String CONDITION_ATTR = "condition";
 
   public static final String MISSING_JANINO_MSG = "Could not find Janino library on the class path. Skipping conditional processing.";
   public static final String MISSING_JANINO_SEE = "See also " + . + "#ifJanino";
 
   Stack<IfStatestack = new Stack<IfState>();
   
   @Override
   public void begin(InterpretationContext icString nameAttributes attributes)
       throws ActionException {
 
     IfState state = new IfState();
     boolean emptyStack = .isEmpty();
     .push(state);
 
     if(!emptyStack) {
       return;
     }
     
     ic.pushObject(this);
     if(!EnvUtil.isJaninoAvailable()) {
        addError();
        addError();
        return;
      }
 
     state.active = true;
     Condition condition = null;
     String conditionAttribute = attributes.getValue();
 
 
     if (!OptionHelper.isEmpty(conditionAttribute)) {
       conditionAttribute = OptionHelper.substVars(conditionAttributeic);
       PropertyEvalScriptBuilder pesb = new PropertyEvalScriptBuilder(ic);
       pesb.setContext();
       try {
         condition = pesb.build(conditionAttribute);
       } catch (Exception e) {
         addError("Failed to parse condition ["+conditionAttribute+"]"e);
       }
      
       if(condition!=null) {
         state.boolResult = condition.evaluate();
       }
       
     }
   }
 
 
   @Override
   public void end(InterpretationContext icString namethrows ActionException {
 
     IfState state = .pop();
     if(!state.active) {
       return;
     }
    
     
     Object o = ic.peekObject();
     if (o == null) {
       throw new IllegalStateException("Unexpected null object on stack");
     }
     if (!(o instanceof IfAction)) {
       throw new IllegalStateException("Unexpected object of type ["
           + o.getClass() + "] on stack");
     }
 
     if (o != this) {
       throw new IllegalStateException(
          "IfAction different then current one on stack");
    }
    ic.popObject();
    if (state.boolResult == null) {
      addError("Failed to determine \"if then else\" result");
      return;
    }
    Interpreter interpreter = ic.getJoranInterpreter();
    List<SaxEventlistToPlay = state.thenSaxEventList;
    if (!state.boolResult) {
      listToPlay = state.elseSaxEventList;
    }
    // if boolResult==false & missing else,  listToPlay may be null
    if(listToPlay != null) {
      // insert past this event
      interpreter.getEventPlayer().addEventsDynamically(listToPlay, 1);
    }
  }
  public void setThenSaxEventList(List<SaxEventthenSaxEventList) {
    IfState state = .firstElement();
    if(state.active) {
      state.thenSaxEventList = thenSaxEventList;
    } else {
      throw new IllegalStateException("setThenSaxEventList() invoked on inactive IfAction");
    }
  }
  public void setElseSaxEventList(List<SaxEventelseSaxEventList) {
    IfState state = .firstElement();
    if(state.active) {
      state.elseSaxEventList = elseSaxEventList;
    } else {
      throw new IllegalStateException("setElseSaxEventList() invoked on inactive IfAction");
    }
  }
  public boolean isActive() {
    if( == nullreturn false;
    if(.isEmpty()) return false;
    return .peek().;
  }
class IfState {
  boolean active;
New to GrepCode? Check out our FAQ X