KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > management > autoload > InstallDirectoryScanner


1 /**
2  * PETALS: PETALS Services Platform
3  * Copyright (C) 2005 EBM WebSourcing
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.1 of the License, or 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
18  * USA.
19  *
20  * Initial developer(s): EBM WebSourcing
21  * --------------------------------------------------------------------------
22  * $Id: InstallDirectoryScanner.java,v 1.2 2006/04/07 10:24:27 alouis Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.petals.jbi.management.autoload;
26
27 import java.io.File JavaDoc;
28 import java.io.FilenameFilter JavaDoc;
29 import java.util.TimerTask JavaDoc;
30
31 /**
32  * Periodicly check if new Install or Deploy elements are presents in the
33  * autoload directories.
34  *
35  * @author alouis
36  *
37  */

38 public class InstallDirectoryScanner extends TimerTask JavaDoc {
39
40     File JavaDoc installDir;
41
42     AutoLoaderImpl autoLoader;
43
44     ArchiveFileFilter archiveFilter;
45
46     public InstallDirectoryScanner(AutoLoaderImpl autoLoader, File JavaDoc installDir) {
47         this.installDir = installDir;
48         this.autoLoader = autoLoader;
49         archiveFilter = new ArchiveFileFilter();
50     }
51
52     public void run() {
53         File JavaDoc[] newInstall = installDir.listFiles(archiveFilter);
54
55         if (newInstall != null && newInstall.length > 0) {
56             autoLoader.install(newInstall);
57         }
58     }
59
60     /**
61      * filter for autoloading. Return true if the file is an archive : JAR or
62      * ZIP.
63      *
64      * @author alouis
65      *
66      */

67     private class ArchiveFileFilter implements FilenameFilter JavaDoc {
68
69         /**
70          * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
71          */

72         public boolean accept(File JavaDoc dir, String JavaDoc name) {
73
74             String JavaDoc lcName = name.toLowerCase();
75
76             if (lcName.endsWith("jar") || lcName.endsWith("zip")) {
77                 return true;
78             }
79             return false;
80         }
81
82     }
83 }
84
Popular Tags