KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > plugin > SearchPluginFile


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2004 France Telecom R&D
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * CLIF
20 *
21 * Contact: clif@objectweb.org
22 */

23 package org.objectweb.clif.scenario.util.isac.plugin;
24 import java.io.File JavaDoc;
25 import java.util.Vector JavaDoc;
26
27 import org.apache.log4j.Category;
28 /**
29  * This class implements method which is able to search file in a tree structure
30  *
31  * @author JC Meillaud
32  * @author A Peyrard
33  */

34 public class SearchPluginFile {
35     static Category cat = Category.getInstance(SearchPluginFile.class.getName());
36     /**
37      * Search plugins into the directory whose name is given in parameter
38      * @param dirName the name of the directory
39      * @return the path of the plugin.xml founds
40      */

41     public static String JavaDoc[] searchPlugins(String JavaDoc dirName, String JavaDoc fileName) {
42         cat.debug("-> searchPlugins") ;
43         try {
44             File JavaDoc dir = new File JavaDoc(dirName);
45             File JavaDoc[] files = dir.listFiles();
46             if (files == null) {
47                 return null;
48             }
49             Vector JavaDoc result = new Vector JavaDoc();
50             for (int i = 0; i < files.length; i++) {
51                 if (files[i].isDirectory()) {
52                     String JavaDoc[] temp = searchPlugins(dirName + files[i].getName(), fileName);
53                     if (temp == null)
54                         continue;
55                     for (int j = 0; j < temp.length; j++)
56                         result.add(temp[j]);
57                 } else if (files[i].isFile()) {
58                     if (((String JavaDoc) (files[i].getName())).equals(fileName))
59                         result.add(dirName + "/" /*+ files[i].getName()*/);
60                 } else
61                     cat.warn(
62                         "File is not reconize : " + files[i].getName());
63             }
64             if (result != null)
65                 return (String JavaDoc[]) result.toArray(new String JavaDoc[0]);
66         } catch (Exception JavaDoc e) {
67             e.printStackTrace();
68             System.exit(0);
69         }
70         // must nether append
71
return null;
72     }
73 }
74
Popular Tags