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