001/* 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2026, 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 v2.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.model.processor; 016 017import java.util.ArrayList; 018import java.util.List; 019 020import ch.qos.logback.core.model.Model; 021import ch.qos.logback.core.spi.FilterReply; 022 023public class ChainedModelFilter implements ModelFilter { 024 025 List<ModelFilter> modelFilters = new ArrayList<>(); 026 027 public ChainedModelFilter() { 028 } 029 030 static public ChainedModelFilter newInstance() { 031 return new ChainedModelFilter(); 032 } 033 034 public ChainedModelFilter allow(Class<? extends Model> allowedType) { 035 modelFilters.add(new AllowModelFilter(allowedType)); 036 return this; 037 } 038 039 public ChainedModelFilter deny(Class<? extends Model> allowedType) { 040 modelFilters.add(new DenyModelFilter(allowedType)); 041 return this; 042 } 043 044 public ChainedModelFilter denyAll() { 045 modelFilters.add(new DenyAllModelFilter()); 046 return this; 047 } 048 049 public ChainedModelFilter allowAll() { 050 modelFilters.add(new AllowAllModelFilter()); 051 return this; 052 } 053 054 @Override 055 public FilterReply decide(Model model) { 056 057 for (ModelFilter modelFilter : modelFilters) { 058 FilterReply reply = modelFilter.decide(model); 059 060 switch (reply) { 061 case ACCEPT: 062 case DENY: 063 return reply; 064 case NEUTRAL: 065 // next 066 } 067 } 068 return FilterReply.NEUTRAL; 069 } 070 071}