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     */
017    package org.apache.camel.impl.scan;
018    
019    import java.util.LinkedHashSet;
020    import java.util.Set;
021    
022    import org.apache.camel.spi.PackageScanFilter;
023    
024    /**
025     * <code>CompositePackageScanFilter</code> allows multiple
026     * {@link PackageScanFilter}s to be composed into a single filter. For a
027     * {@link Class} to match a {@link CompositePackageScanFilter} it must match
028     * each of the filters the composite contains
029     */
030    public class CompositePackageScanFilter implements PackageScanFilter {
031        private Set<PackageScanFilter> filters;
032    
033        public CompositePackageScanFilter() {
034            filters = new LinkedHashSet<PackageScanFilter>();
035        }
036    
037        public CompositePackageScanFilter(Set<PackageScanFilter> filters) {
038            this.filters = new LinkedHashSet<PackageScanFilter>(filters);
039        }
040    
041        public void addFilter(PackageScanFilter filter) {
042            filters.add(filter);
043        }
044    
045        public boolean matches(Class<?> type) {
046            for (PackageScanFilter filter : filters) {
047                if (!filter.matches(type)) {
048                    return false;
049                }
050            }
051            return true;
052        }
053    }