001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2022, 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 */ 014package ch.qos.logback.core.model.processor; 015 016import ch.qos.logback.core.Context; 017import ch.qos.logback.core.model.AppenderRefModel; 018import ch.qos.logback.core.model.Model; 019 020@PhaseIndicator(phase = ProcessingPhase.DEPENDENCY_ANALYSIS) 021public class AppenderRefDependencyAnalyser extends ModelHandlerBase { 022 023 public AppenderRefDependencyAnalyser(Context context) { 024 super(context); 025 } 026 027 @Override 028 protected Class<AppenderRefModel> getSupportedModelClass() { 029 return AppenderRefModel.class; 030 } 031 032 @Override 033 public void handle(ModelInterpretationContext mic, Model model) throws ModelHandlerException { 034 035 AppenderRefModel appenderRefModel = (AppenderRefModel) model; 036 037 String ref = mic.subst(appenderRefModel.getRef()); 038 039 Model depender; 040 if (mic.isModelStackEmpty()) { 041 // appenderRefModel maybe the dependent model. This is the case in logback-access 042 depender = appenderRefModel; 043 } else { 044 Model parentModel = mic.peekModel(); 045 depender = parentModel; 046 } 047 048 DependencyDefinition dd = new DependencyDefinition(depender, ref); 049 mic.addDependencyDefinition(dd); 050 051 } 052 053}