001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.vfs2.provider;
018
019import java.io.File;
020
021import org.apache.commons.vfs2.FileName;
022import org.apache.commons.vfs2.FileObject;
023import org.apache.commons.vfs2.FileSystemException;
024import org.apache.commons.vfs2.FileSystemManager;
025import org.apache.commons.vfs2.FileSystemOptions;
026
027/**
028 * Allows VFS components to access the services they need, such as the file replicator. A VFS component is supplied with
029 * a context as part of its initialization.
030 *
031 * @see VfsComponent#setContext
032 */
033public interface VfsComponentContext {
034
035    /**
036     * Gets the file system manager for the current context.
037     *
038     * @return the file system manager
039     */
040    FileSystemManager getFileSystemManager();
041
042    /**
043     * Gets a file replicator for the provider to use.
044     *
045     * @return The FileReplicator.
046     * @throws FileSystemException if an error occurs.
047     */
048    FileReplicator getReplicator() throws FileSystemException;
049
050    /**
051     * Gets a temporary file store for the provider to use.
052     *
053     * @return The TemporaryFileStore.
054     * @throws FileSystemException if an error occurs.
055     */
056    TemporaryFileStore getTemporaryFileStore() throws FileSystemException;
057
058    /**
059     * Parses a URI into a FileName.
060     *
061     * @param uri The URI String.
062     * @return The FileName.
063     * @throws FileSystemException if an error occurs.
064     */
065    FileName parseURI(String uri) throws FileSystemException;
066
067    /**
068     * Resolves a file by name. See {@link FileSystemManager#resolveFile(FileObject, String)} for a description of how
069     * this works.
070     *
071     * @param baseFile The base FileObject.
072     * @param name The name of the file to locate.
073     * @param fileSystemOptions The FileSystemOptions.
074     * @return The FileObject for the located file.
075     * @throws FileSystemException if an error occurs.
076     */
077    FileObject resolveFile(FileObject baseFile, String name, FileSystemOptions fileSystemOptions)
078            throws FileSystemException;
079
080    /**
081     * Resolves a file by name. See {@link FileSystemManager#resolveFile( String)} for a description of how this works.
082     *
083     * @param name The name of the file to locate.
084     * @param fileSystemOptions The FileSystemOptions.
085     * @return The FileObject for the located file.
086     * @throws FileSystemException if an error occurs.
087     */
088    FileObject resolveFile(String name, FileSystemOptions fileSystemOptions) throws FileSystemException;
089
090    /**
091     * Returns a {@link FileObject} for a local file.
092     *
093     * @param file The File to convert to a FileObject.
094     * @return the FileObject.
095     * @throws FileSystemException if an error occurs.
096     */
097    FileObject toFileObject(File file) throws FileSystemException;
098}