01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.tools.ant.types.selectors;
20:
21: import java.io.File;
22: import java.util.Enumeration;
23:
24: /**
25: * This selector has a collection of other selectors, any of which have to
26: * select a file in order for this selector to select it.
27: *
28: * @since 1.5
29: */
30: public class OrSelector extends BaseSelectorContainer {
31:
32: /**
33: * Default constructor.
34: */
35: public OrSelector() {
36: }
37:
38: /**
39: * @return a string representation of the selector
40: */
41: public String toString() {
42: StringBuffer buf = new StringBuffer();
43: if (hasSelectors()) {
44: buf.append("{orselect: ");
45: buf.append(super .toString());
46: buf.append("}");
47: }
48: return buf.toString();
49: }
50:
51: /**
52: * Returns true (the file is selected) if any of the other selectors
53: * agree that the file should be selected.
54: *
55: * @param basedir the base directory the scan is being done from
56: * @param filename the name of the file to check
57: * @param file a java.io.File object for the filename that the selector
58: * can use
59: * @return whether the file should be selected or not
60: */
61: public boolean isSelected(File basedir, String filename, File file) {
62: validate();
63: Enumeration e = selectorElements();
64: boolean result;
65:
66: // First, check that all elements are correctly configured
67: while (e.hasMoreElements()) {
68: result = ((FileSelector) e.nextElement()).isSelected(
69: basedir, filename, file);
70: if (result) {
71: return true;
72: }
73: }
74: return false;
75: }
76:
77: }
|