source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/types/selectors/BaseSelector.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 3.1 KB
Line 
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
18package org.apache.tools.ant.types.selectors;
19
20import java.io.File;
21
22import org.apache.tools.ant.BuildException;
23import org.apache.tools.ant.types.DataType;
24
25/**
26 * A convenience base class that you can subclass Selectors from. It
27 * provides some helpful common behaviour. Note that there is no need
28 * for Selectors to inherit from this class, it is only necessary that
29 * they implement FileSelector.
30 *
31 * @since 1.5
32 */
33public abstract class BaseSelector extends DataType implements FileSelector {
34
35 private String errmsg = null;
36
37
38 /**
39 * Do nothing constructor.
40 */
41 public BaseSelector() {
42 }
43
44 /**
45 * Allows all selectors to indicate a setup error. Note that only
46 * the first error message is recorded.
47 *
48 * @param msg The error message any BuildException should throw.
49 */
50 public void setError(String msg) {
51 if (errmsg == null) {
52 errmsg = msg;
53 }
54 }
55
56 /**
57 * Returns any error messages that have been set.
58 *
59 * @return the error condition
60 */
61 public String getError() {
62 return errmsg;
63 }
64
65
66 /**
67 * <p>Subclasses can override this method to provide checking of their
68 * state. So long as they call validate() from isSelected(), this will
69 * be called automatically (unless they override validate()).</p>
70 * <p>Implementations should check for incorrect settings and call
71 * setError() as necessary.</p>
72 */
73 public void verifySettings() {
74 }
75
76
77 /**
78 * Subclasses can use this to throw the requisite exception
79 * in isSelected() in the case of an error condition.
80 */
81 public void validate() {
82 if (getError() == null) {
83 verifySettings();
84 }
85 if (getError() != null) {
86 throw new BuildException(errmsg);
87 }
88 }
89
90 /**
91 * Method that each selector will implement to create their
92 * selection behaviour. If there is a problem with the setup
93 * of a selector, it can throw a BuildException to indicate
94 * the problem.
95 *
96 * @param basedir A java.io.File object for the base directory
97 * @param filename The name of the file to check
98 * @param file A File object for this filename
99 * @return whether the file should be selected or not
100 */
101 public abstract boolean isSelected(File basedir, String filename,
102 File file);
103
104}
105
106
Note: See TracBrowser for help on using the repository browser.