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. package org.apache.tools.ant.types.selectors;
  18. import java.io.File;
  19. import java.util.Enumeration;
  20. /**
  21. * This selector has a collection of other selectors, any of which have to
  22. * select a file in order for this selector to select it.
  23. *
  24. * @since 1.5
  25. */
  26. public class OrSelector extends BaseSelectorContainer {
  27. /**
  28. * Default constructor.
  29. */
  30. public OrSelector() {
  31. }
  32. /**
  33. * @return a string representation of the selector
  34. */
  35. public String toString() {
  36. StringBuffer buf = new StringBuffer();
  37. if (hasSelectors()) {
  38. buf.append("{orselect: ");
  39. buf.append(super.toString());
  40. buf.append("}");
  41. }
  42. return buf.toString();
  43. }
  44. /**
  45. * Returns true (the file is selected) if any of the other selectors
  46. * agree that the file should be selected.
  47. *
  48. * @param basedir the base directory the scan is being done from
  49. * @param filename the name of the file to check
  50. * @param file a java.io.File object for the filename that the selector
  51. * can use
  52. * @return whether the file should be selected or not
  53. */
  54. public boolean isSelected(File basedir, String filename, File file) {
  55. validate();
  56. Enumeration e = selectorElements();
  57. boolean result;
  58. // First, check that all elements are correctly configured
  59. while (e.hasMoreElements()) {
  60. result = ((FileSelector) e.nextElement()).isSelected(basedir,
  61. filename, file);
  62. if (result) {
  63. return true;
  64. }
  65. }
  66. return false;
  67. }
  68. }