KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > resources > selectors > Name


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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 package org.apache.tools.ant.types.resources.selectors;
19
20 import org.apache.tools.ant.types.Resource;
21 import org.apache.tools.ant.types.selectors.SelectorUtils;
22
23 /**
24  * Name ResourceSelector.
25  * @since Ant 1.7
26  */

27 public class Name implements ResourceSelector {
28     private String JavaDoc pattern;
29     private boolean cs = true;
30
31     /**
32      * Set the pattern to compare names against.
33      * @param n the pattern String to set.
34      */

35     public void setName(String JavaDoc n) {
36         pattern = n;
37     }
38
39     /**
40      * Get the pattern used by this Name ResourceSelector.
41      * @return the String selection pattern.
42      */

43     public String JavaDoc getName() {
44         return pattern;
45     }
46
47     /**
48      * Set whether the name comparisons are case-sensitive.
49      * @param b boolean case-sensitivity flag.
50      */

51     public void setCaseSensitive(boolean b) {
52         cs = b;
53     }
54
55     /**
56      * Learn whether this Name ResourceSelector is case-sensitive.
57      * @return boolean case-sensitivity flag.
58      */

59     public boolean isCaseSensitive() {
60         return cs;
61     }
62
63     /**
64      * Return true if this Resource is selected.
65      * @param r the Resource to check.
66      * @return whether the Resource was selected.
67      */

68     public boolean isSelected(Resource r) {
69         String JavaDoc n = r.getName();
70         if (SelectorUtils.match(pattern, n, cs)) {
71             return true;
72         }
73         String JavaDoc s = r.toString();
74         return s.equals(n) ? false : SelectorUtils.match(pattern, s, cs);
75     }
76
77 }
78
Popular Tags