001/*
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2023, 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 */
014
015package ch.qos.logback.core.joran;
016
017import ch.qos.logback.core.Context;
018import ch.qos.logback.core.model.*;
019import ch.qos.logback.core.model.conditional.ElseModel;
020import ch.qos.logback.core.model.conditional.IfModel;
021import ch.qos.logback.core.model.conditional.ThenModel;
022import ch.qos.logback.core.model.processor.*;
023import ch.qos.logback.core.model.processor.conditional.ElseModelHandler;
024import ch.qos.logback.core.model.processor.conditional.IfModelHandler;
025import ch.qos.logback.core.model.processor.conditional.ThenModelHandler;
026import ch.qos.logback.core.sift.SiftModelHandler;
027
028/**
029 * For a given DefaultProcessor instance link a {@link ch.qos.logback.core.model.Model Model} class to
030 * a {@link ch.qos.logback.core.model.processor.ModelHandlerBase ModelHandler} instance in logback-core.
031 *
032 * <p>Derived classes are likely to add further links.</p>
033 *
034 * @since 1.3.9/1.4.9
035 */
036public class ModelClassToModelHandlerLinkerBase {
037
038
039    protected Context context;
040
041    public ModelClassToModelHandlerLinkerBase(Context context) {
042        this.context = context;
043    }
044
045    public void link(DefaultProcessor defaultProcessor) {
046        defaultProcessor.addHandler(ImportModel.class, ImportModelHandler::makeInstance);
047
048        defaultProcessor.addHandler(ShutdownHookModel.class, ShutdownHookModelHandler::makeInstance);
049        defaultProcessor.addHandler(SequenceNumberGeneratorModel.class, SequenceNumberGeneratorModelHandler::makeInstance);
050        defaultProcessor.addHandler(SerializeModelModel.class, SerializeModelModelHandler::makeInstance);
051
052        defaultProcessor.addHandler(EventEvaluatorModel.class, EventEvaluatorModelHandler::makeInstance);
053        defaultProcessor.addHandler(ConversionRuleModel.class, ConversionRuleModelHandler::makeInstance);
054
055        defaultProcessor.addHandler(DefineModel.class, DefineModelHandler::makeInstance);
056        defaultProcessor.addHandler(IncludeModel.class, IncludeModelHandler::makeInstance);
057
058
059        defaultProcessor.addHandler(ParamModel.class, ParamModelHandler::makeInstance);
060        defaultProcessor.addHandler(PropertyModel.class, PropertyModelHandler::makeInstance);
061        defaultProcessor.addHandler(TimestampModel.class, TimestampModelHandler::makeInstance);
062        defaultProcessor.addHandler(StatusListenerModel.class, StatusListenerModelHandler::makeInstance);
063        defaultProcessor.addHandler(ImplicitModel.class, ImplicitModelHandler::makeInstance);
064
065        defaultProcessor.addHandler(IfModel.class, IfModelHandler::makeInstance);
066        defaultProcessor.addHandler(ThenModel.class, ThenModelHandler::makeInstance);
067        defaultProcessor.addHandler(ElseModel.class, ElseModelHandler::makeInstance);
068
069        defaultProcessor.addHandler(SiftModel.class, SiftModelHandler::makeInstance);
070    }
071
072    // The final filters in the two filter chain are rather crucial.
073    // They ensure that only Models attached to the firstPhaseFilter will
074    // be handled in the first phase and all models not previously handled
075    // in the second phase will be handled in a catch-all fallback case.
076    protected void sealModelFilters(DefaultProcessor defaultProcessor) {
077        defaultProcessor.getPhaseOneFilter().denyAll();
078        defaultProcessor.getPhaseTwoFilter().allowAll();
079    }
080}