KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > ejb > InnerClassFilenameFilter


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.taskdefs.optional.ejb;
19
20 import java.io.File JavaDoc;
21 import java.io.FilenameFilter JavaDoc;
22
23 /**
24  * A filename filter for inner class files of a particular class.
25  */

26 public class InnerClassFilenameFilter implements FilenameFilter JavaDoc {
27     private String JavaDoc baseClassName;
28
29     /**
30      * Constructor of filter.
31      * @param baseclass the class to filter inner classes on.
32      */

33     InnerClassFilenameFilter(String JavaDoc 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 JavaDoc dir, String JavaDoc filename) {
48         if ((filename.lastIndexOf(".") != filename.lastIndexOf(".class"))
49             || (filename.indexOf(baseClassName + "$") != 0)) {
50             return false;
51         }
52         return true;
53     }
54 }
55
Popular Tags