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. All of those selectors
  22. * must refuse to select a file before the file is considered selected by
  23. * this selector.
  24. *
  25. * @since 1.5
  26. */
  27. public class NoneSelector extends BaseSelectorContainer {
  28. /**
  29. * Default constructor.
  30. */
  31. public NoneSelector() {
  32. }
  33. /**
  34. * @return a string representation of the selector
  35. */
  36. public String toString() {
  37. StringBuffer buf = new StringBuffer();
  38. if (hasSelectors()) {
  39. buf.append("{noneselect: ");
  40. buf.append(super.toString());
  41. buf.append("}");
  42. }
  43. return buf.toString();
  44. }
  45. /**
  46. * Returns true (the file is selected) only if all other selectors
  47. * agree that the file should not be selected.
  48. *
  49. * @param basedir the base directory the scan is being done from
  50. * @param filename is the name of the file to check
  51. * @param file is a java.io.File object for the filename that the selector
  52. * can use
  53. * @return whether the file should be selected or not
  54. */
  55. public boolean isSelected(File basedir, String filename, File file) {
  56. validate();
  57. Enumeration e = selectorElements();
  58. boolean result;
  59. while (e.hasMoreElements()) {
  60. result = ((FileSelector) e.nextElement()).isSelected(basedir,
  61. filename, file);
  62. if (result) {
  63. return false;
  64. }
  65. }
  66. return true;
  67. }
  68. }