KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > provider > AbstractOriginatingFileProvider


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.provider;
17
18 import org.apache.commons.vfs.FileName;
19 import org.apache.commons.vfs.FileObject;
20 import org.apache.commons.vfs.FileSystem;
21 import org.apache.commons.vfs.FileSystemException;
22 import org.apache.commons.vfs.FileSystemOptions;
23
24 /**
25  * A {@link FileProvider} that handles physical files, such as the files in a
26  * local fs, or on an FTP server. An originating file system cannot be
27  * layered on top of another file system.
28  *
29  * @author <a HREF="mailto:adammurdoch@apache.org">Adam Murdoch</a>
30  */

31 public abstract class AbstractOriginatingFileProvider
32     extends AbstractFileProvider
33 {
34     public AbstractOriginatingFileProvider()
35     {
36         super();
37     }
38
39     /**
40      * Locates a file object, by absolute URI.
41      *
42      * @param uri
43      */

44     public FileObject findFile(final FileObject baseFile,
45                                final String JavaDoc uri,
46                                final FileSystemOptions fileSystemOptions) throws FileSystemException
47     {
48         // Parse the URI
49
final FileName name;
50         try
51         {
52             name = parseUri(baseFile!=null?baseFile.getName():null, uri);
53         }
54         catch (FileSystemException exc)
55         {
56             throw new FileSystemException("vfs.provider/invalid-absolute-uri.error", uri, exc);
57         }
58
59         // Locate the file
60
return findFile(name, fileSystemOptions);
61     }
62
63     /**
64      * Locates a file from its parsed URI.
65      */

66     protected synchronized FileObject findFile(final FileName name, final FileSystemOptions fileSystemOptions)
67         throws FileSystemException
68     {
69         // Check in the cache for the file system
70
final FileName rootName = getContext().getFileSystemManager().resolveName(name, FileName.ROOT_PATH);
71         FileSystem fs = findFileSystem(rootName, fileSystemOptions);
72         if (fs == null)
73         {
74             // Need to create the file system, and cache it
75
fs = doCreateFileSystem(rootName, fileSystemOptions);
76             addFileSystem(rootName, fs);
77         }
78
79         // Locate the file
80
return fs.resolveFile(name.getPath());
81     }
82
83     /**
84      * Creates a {@link FileSystem}. If the returned FileSystem implements
85      * {@link VfsComponent}, it will be initialised.
86      *
87      * @param rootName The name of the root file of the file system to create.
88      */

89     protected abstract FileSystem doCreateFileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions)
90         throws FileSystemException;
91 }
92
Popular Tags