001package ch.qos.logback.core.model.processor;
002
003import java.util.ArrayList;
004import java.util.List;
005
006import ch.qos.logback.core.model.Model;
007import ch.qos.logback.core.spi.FilterReply;
008
009public class ChainedModelFilter implements ModelFilter {
010
011    List<ModelFilter> modelFilters = new ArrayList<>();
012
013    public ChainedModelFilter() {
014    }
015
016    static public ChainedModelFilter newInstance() {
017        return new ChainedModelFilter();
018    }
019
020    public ChainedModelFilter allow(Class<? extends Model> allowedType) {
021        modelFilters.add(new AllowModelFilter(allowedType));
022        return this;
023    }
024
025    public ChainedModelFilter deny(Class<? extends Model> allowedType) {
026        modelFilters.add(new DenyModelFilter(allowedType));
027        return this;
028    }
029
030    public ChainedModelFilter denyAll() {
031        modelFilters.add(new DenyAllModelFilter());
032        return this;
033    }
034
035    public ChainedModelFilter allowAll() {
036        modelFilters.add(new AllowAllModelFilter());
037        return this;
038    }
039
040    @Override
041    public FilterReply decide(Model model) {
042
043        for (ModelFilter modelFilter : modelFilters) {
044            FilterReply reply = modelFilter.decide(model);
045
046            switch (reply) {
047            case ACCEPT:
048            case DENY:
049                return reply;
050            case NEUTRAL:
051                // next
052            }
053        }
054        return FilterReply.NEUTRAL;
055    }
056
057}