01: import java.io.*;
02: 
03: public class DirectoryNode implements FileSystemNode
04: {
05:    public DirectoryNode(File directory)
06:    {
07:       this.directory = directory;
08:    }
09: 
10:    public void accept(FileSystemVisitor v)
11:    {
12:       v.visitDirectoryNode(this);
13:    }
14: 
15:    public File getDirectory() { return directory; }
16: 
17:    public FileSystemNode[] getChildren()
18:    {
19:       File[] files = directory.listFiles();
20:       FileSystemNode[] children = new FileSystemNode[files.length];
21:       for (int i = 0; i < files.length; i++)
22:       {
23:          File f = files[i];
24:          if (f.isDirectory())
25:             children[i] = new DirectoryNode(f);
26:          else
27:             children[i] = new FileNode(f);
28:       }
29:       return children;
30:    }
31: 
32:    private File directory;
33: }