001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 *  Unless required by applicable law or agreed to in writing, software
012 *  distributed under the License is distributed on an "AS IS" BASIS,
013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 *  See the License for the specific language governing permissions and
015 *  limitations under the License.
016 */
017package org.apache.xbean.finder.filter;
018
019/**
020 * First, all Include directives are evaluated; at least one must match, or the className is rejected.
021 * Next, all Exclude directives are evaluated. If any matches, the className is rejected.
022 * Last, any classNames which do not match an Include or a Exclude directive are denied by default.
023 */
024public class IncludeExcludeFilter implements Filter {
025
026    private Filter include;
027    private Filter exclude;
028
029    public IncludeExcludeFilter(Filter include, Filter exclude) {
030        this.include = include;
031        this.exclude = exclude;
032    }
033
034    public boolean accept(String name) {
035        if (include.accept(name)) return !exclude.accept(name);
036        return false;
037    }
038
039    @Override
040    public String toString() {
041        return "Include." + include +
042                " Exclude." + exclude;
043    }
044}