Class IfModelHandler

java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.model.processor.ModelHandlerBase
ch.qos.logback.tyler.base.handler.IfModelHandler
All Implemented Interfaces:
ch.qos.logback.core.spi.ContextAware

public class IfModelHandler extends ch.qos.logback.core.model.processor.ModelHandlerBase
Handler responsible for processing IfModel instances encountered during model interpretation.

This handler pushes the IfModel onto the interpretation stack, validates the condition string and emits the corresponding Java "if" control flow into the Tyler configuration method being built (via MethodSpec).

  • Field Summary

    Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase

    context
  • Constructor Summary

    Constructors
    Constructor
    Description
    IfModelHandler(ch.qos.logback.core.Context context)
    Create a new IfModelHandler.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Emit the Java "if" control flow for the given condition into the supplied TylerModelInterpretationContext's MethodSpec builder.
    protected Class<ch.qos.logback.core.model.conditional.IfModel>
    Return the model class that this handler supports.
    void
    handle(ch.qos.logback.core.model.processor.ModelInterpretationContext mic, ch.qos.logback.core.model.Model model)
    Handle an IfModel by validating its condition and emitting the corresponding Java "if" statement into the Tyler method spec builder.
    static ch.qos.logback.core.model.processor.ModelHandlerBase
    makeInstance(ch.qos.logback.core.Context context, ch.qos.logback.core.model.processor.ModelInterpretationContext ic)
    Factory method used by the model processing infrastructure.
    void
    postHandle(ch.qos.logback.core.model.processor.ModelInterpretationContext mic, ch.qos.logback.core.model.Model model)
    Finalize handling of the IfModel: verify the model stack, end the emitted control flow and pop the model from the stack.

    Methods inherited from class ch.qos.logback.core.model.processor.ModelHandlerBase

    isSupportedModelType, toString

    Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase

    addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • IfModelHandler

      public IfModelHandler(ch.qos.logback.core.Context context)
      Create a new IfModelHandler.
      Parameters:
      context - the Logback context used for this handler
  • Method Details

    • makeInstance

      public static ch.qos.logback.core.model.processor.ModelHandlerBase makeInstance(ch.qos.logback.core.Context context, ch.qos.logback.core.model.processor.ModelInterpretationContext ic)
      Factory method used by the model processing infrastructure.
      Parameters:
      context - the Logback context
      ic - the current ModelInterpretationContext (unused by this factory)
      Returns:
      a new instance of IfModelHandler
    • getSupportedModelClass

      protected Class<ch.qos.logback.core.model.conditional.IfModel> getSupportedModelClass()
      Return the model class that this handler supports.
      Overrides:
      getSupportedModelClass in class ch.qos.logback.core.model.processor.ModelHandlerBase
      Returns:
      the supported model class (IfModel.class)
    • handle

      public void handle(ch.qos.logback.core.model.processor.ModelInterpretationContext mic, ch.qos.logback.core.model.Model model) throws ch.qos.logback.core.model.processor.ModelHandlerException
      Handle an IfModel by validating its condition and emitting the corresponding Java "if" statement into the Tyler method spec builder.
      Specified by:
      handle in class ch.qos.logback.core.model.processor.ModelHandlerBase
      Parameters:
      mic - the model interpretation context
      model - the model to handle (expected to be IfModel)
      Throws:
      ch.qos.logback.core.model.processor.ModelHandlerException - if an error occurs while handling the model
    • addJavaStatement

      protected void addJavaStatement(TylerModelInterpretationContext tmic, String conditionStr)
      Emit the Java "if" control flow for the given condition into the supplied TylerModelInterpretationContext's MethodSpec builder.
      Parameters:
      tmic - the Tyler model interpretation context containing the MethodSpec builder
      conditionStr - the Java expression to use as the if condition
    • postHandle

      public void postHandle(ch.qos.logback.core.model.processor.ModelInterpretationContext mic, ch.qos.logback.core.model.Model model)
      Finalize handling of the IfModel: verify the model stack, end the emitted control flow and pop the model from the stack.
      Overrides:
      postHandle in class ch.qos.logback.core.model.processor.ModelHandlerBase
      Parameters:
      mic - the model interpretation context
      model - the model that was handled