001package horstmann.ch10_visitor;
002import java.io.File;
003
004public class DirectoryNode implements FileSystemNode
005{
006        public DirectoryNode(File directory)
007        {
008                this.directory = directory;
009        }
010
011        public void accept(FileSystemVisitor v)
012        {
013                v.visitDirectoryNode(this);
014        }
015
016        public File getDirectory() { return directory; }
017
018        public FileSystemNode[] getChildren()
019        {
020                File[] files = directory.listFiles();
021                FileSystemNode[] children = new FileSystemNode[files.length];
022                for (int i = 0; i < files.length; i++)
023                {
024                        File f = files[i];
025                        if (f.isDirectory())
026                                children[i] = new DirectoryNode(f);
027                        else
028                                children[i] = new FileNode(f);
029                }
030                return children;
031        }
032
033        private File directory;
034}