KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > test > FileInfo


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.vfs.test;
17
18 import org.apache.commons.vfs.FileType;
19
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22
23 /**
24  * Info about a file.
25  */

26 class FileInfo
27 {
28     String JavaDoc baseName;
29     FileType type;
30     String JavaDoc content;
31     Map JavaDoc children = new HashMap JavaDoc();
32     FileInfo parent;
33
34     public FileInfo(final String JavaDoc name, final FileType type)
35     {
36         baseName = name;
37         this.type = type;
38         this.content = null;
39     }
40
41     public FileInfo(final String JavaDoc name, final FileType type, final String JavaDoc content)
42     {
43         baseName = name;
44         this.type = type;
45         this.content = content;
46     }
47
48     public FileInfo getParent()
49     {
50         return parent;
51     }
52
53     /**
54      * Adds a child.
55      */

56     public void addChild(final FileInfo child)
57     {
58         children.put(child.baseName, child);
59         child.parent = this;
60     }
61
62     /**
63      * Adds a child file.
64      */

65     public FileInfo addFile(final String JavaDoc baseName, final String JavaDoc content)
66     {
67         final FileInfo child = new FileInfo(baseName, FileType.FILE, content);
68         addChild(child);
69         return child;
70     }
71
72     /**
73      * Adds a child folder.
74      */

75     public FileInfo addFolder(final String JavaDoc baseName)
76     {
77         final FileInfo child = new FileInfo(baseName, FileType.FOLDER, null);
78         addChild(child);
79         return child;
80     }
81 }
82
Popular Tags