001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2022, QOS.ch. All rights reserved.
004 * <p>
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 * <p>
009 * or (per the licensee's choosing)
010 * <p>
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.model.processor;
015
016import ch.qos.logback.core.Context;
017import ch.qos.logback.core.model.AppenderModel;
018import ch.qos.logback.core.model.AppenderRefModel;
019import ch.qos.logback.core.model.Model;
020
021import java.util.List;
022import java.util.stream.Collectors;
023
024@PhaseIndicator(phase = ProcessingPhase.DEPENDENCY_ANALYSIS)
025public class AppenderRefDependencyAnalyser extends ModelHandlerBase {
026
027    public AppenderRefDependencyAnalyser(Context context) {
028        super(context);
029    }
030
031    @Override
032    protected Class<Model> getSupportedModelClass() {
033        return Model.class;
034    }
035
036    @Override
037    public void handle(ModelInterpretationContext mic, Model parentModel) throws ModelHandlerException {
038
039        List<AppenderRefModel> appenderRefModels =
040                parentModel.getSubModels().stream().filter(m -> m instanceof AppenderRefModel).map(m -> (AppenderRefModel) m).collect(Collectors.toList());
041
042
043        for (AppenderRefModel appenderRefModel : appenderRefModels) {
044            String ref = mic.subst(appenderRefModel.getRef());
045            DependencyDefinition dd = new DependencyDefinition(parentModel, ref);
046            mic.addDependencyDefinition(dd);
047        }
048
049    }
050
051}