001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.hivemind.methodmatch; 016 017 import java.util.Iterator; 018 import java.util.List; 019 020 import org.apache.hivemind.service.MethodSignature; 021 022 /** 023 * Runs a suite of {@link org.apache.hivemind.methodmatch.MethodFilter}s, returning 024 * true only if each filter does. The tests short-circuit with the first filter 025 * to return false. 026 * 027 * @author Howard Lewis Ship 028 */ 029 public class CompositeFilter extends MethodFilter 030 { 031 private List _filters; 032 033 /** 034 * Creates a new composite filter; the list passed in is <em>retained not copied</em> 035 * and should not be changed futher by the caller. 036 * 037 * @param filters {@link List} of {@link MethodFilter}. 038 */ 039 public CompositeFilter(List filters) 040 { 041 _filters = filters; 042 } 043 044 public boolean matchMethod(MethodSignature sig) 045 { 046 Iterator i = _filters.iterator(); 047 while (i.hasNext()) 048 { 049 MethodFilter mf = (MethodFilter) i.next(); 050 051 if (!mf.matchMethod(sig)) 052 return false; 053 } 054 055 // All matches! 056 057 return true; 058 } 059 060 }