01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.taskdefs.optional.ejb;
19:
20: import java.io.File;
21: import java.io.FilenameFilter;
22:
23: /**
24: * A filename filter for inner class files of a particular class.
25: */
26: public class InnerClassFilenameFilter implements FilenameFilter {
27: private String baseClassName;
28:
29: /**
30: * Constructor of filter.
31: * @param baseclass the class to filter inner classes on.
32: */
33: InnerClassFilenameFilter(String baseclass) {
34: int extidx = baseclass.lastIndexOf(".class");
35: if (extidx == -1) {
36: extidx = baseclass.length() - 1;
37: }
38: baseClassName = baseclass.substring(0, extidx);
39: }
40:
41: /**
42: * Check if the file name passes the filter.
43: * @param dir not used.
44: * @param filename the filename to filter on.
45: * @return true if the filename is an inner class of the base class.
46: */
47: public boolean accept(File dir, String filename) {
48: if ((filename.lastIndexOf(".") != filename
49: .lastIndexOf(".class"))
50: || (filename.indexOf(baseClassName + "$") != 0)) {
51: return false;
52: }
53: return true;
54: }
55: }
|