KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > impl > VirtualFileProvider


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.impl;
17
18 import org.apache.commons.vfs.FileName;
19 import org.apache.commons.vfs.FileObject;
20 import org.apache.commons.vfs.FileSystemException;
21 import org.apache.commons.vfs.FileType;
22 import org.apache.commons.vfs.provider.AbstractVfsContainer;
23
24
25 /**
26  * A virtual filesystem provider.
27  *
28  * @author <a HREF="mailto:adammurdoch@apache.org">Adam Murdoch</a>
29  */

30 public class VirtualFileProvider
31     extends AbstractVfsContainer
32 {
33     /**
34      * Creates a virtual file system, with the supplied file as its root.
35      */

36     public FileObject createFileSystem(final FileObject rootFile)
37         throws FileSystemException
38     {
39         final FileName rootName =
40             getContext().getFileSystemManager().resolveName(rootFile.getName(), FileName.ROOT_PATH);
41         // final FileName rootName =
42
// new BasicFileName(rootFile.getName(), FileName.ROOT_PATH);
43
final VirtualFileSystem fs = new VirtualFileSystem(rootName, null);
44         addComponent(fs);
45         fs.addJunction(FileName.ROOT_PATH, rootFile);
46         return fs.getRoot();
47     }
48
49     /**
50      * Creates an empty virtual file system.
51      */

52     public FileObject createFileSystem(final String JavaDoc rootUri) throws FileSystemException
53     {
54         final FileName rootName =
55             new VirtualFileName(rootUri, FileName.ROOT_PATH, FileType.FOLDER);
56         // final FileName rootName =
57
// new BasicFileName(rootUri, FileName.ROOT_PATH);
58
final VirtualFileSystem fs = new VirtualFileSystem(rootName, null);
59         addComponent(fs);
60         return fs.getRoot();
61     }
62 }
63
Popular Tags