KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > perseus > fos > lib > FosExtension


1 /**
2  * Copyright (C) 2000
3  */

4
5 package org.objectweb.perseus.fos.lib;
6
7 import org.objectweb.perseus.fos.api.FosException;
8
9 import java.io.File JavaDoc;
10 import java.io.FilenameFilter JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.NoSuchElementException JavaDoc;
13
14 /**
15  * Defines the way to iterate over the Object Files within a directory.
16  * @author S. Chassande-Barrioz, P. Déchamboux
17  */

18 public class FosExtension implements Iterator JavaDoc, FilenameFilter JavaDoc {
19     private String JavaDoc[] fnList;
20     private int next = 0;
21
22     private FosExtension() {
23     }
24
25     /**
26      * Constructs a Data Object Files extension iterator.
27      * @param dn The name of the Data Object Files directory.
28      */

29     FosExtension(String JavaDoc dn) throws FosException {
30         File JavaDoc fod = new File JavaDoc(dn);
31         if (!fod.exists())
32             fnList = null;
33         else if (!fod.isDirectory()) {
34             fnList = null;
35             throw new FosException("Wrong directory name: " + dn);
36         }
37         fnList = fod.list(this);
38     }
39
40     /**
41      * Tests if there are more elements to tranverse.
42      */

43     public boolean hasNext() {
44         if (fnList == null)
45             return false;
46         return next < fnList.length;
47     }
48
49     /**
50      * Traverses the next element.
51      */

52     public Object JavaDoc next() throws NoSuchElementException JavaDoc {
53         if (next >= fnList.length)
54             throw new NoSuchElementException JavaDoc();
55         return fnList[next++];
56     }
57
58     /**
59      * remove unsupported.
60      */

61     public void remove()
62         throws UnsupportedOperationException JavaDoc, IllegalStateException JavaDoc {
63         throw new UnsupportedOperationException JavaDoc();
64     }
65
66     /**
67      * The filter for retrieving relevant FOS file names. Names with
68      * deletion or writing suffixes are ignored, as well as non regular files.
69      */

70     public boolean accept(File JavaDoc dir, String JavaDoc name) {
71         if (name.endsWith(FosObjectFile.WRITESUFFIX))
72             return false;
73         if (name.endsWith(FosObjectFile.DELETSUFFIX))
74             return false;
75         File JavaDoc f = new File JavaDoc(dir.getPath() + File.separator + name);
76         return f.isFile();
77     }
78 }
Popular Tags