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 org.apache.commons.logging.Log;
020import org.apache.commons.vfs2.FileSystemException;
021
022/**
023 * A partial {@link VfsComponent} implementation.
024 */
025public abstract class AbstractVfsComponent implements VfsComponent {
026
027    private VfsComponentContext context;
028    private Log log;
029
030    /**
031     * Constructs a new instance for subclasses.
032     */
033    public AbstractVfsComponent() {
034        // empty
035    }
036
037    /**
038     * Closes the provider. This implementation does nothing.
039     */
040    @Override
041    public void close() {
042        // default is noop.
043    }
044
045    /**
046     * Returns the context for this provider.
047     *
048     * @return provider context
049     */
050    protected final VfsComponentContext getContext() {
051        return context;
052    }
053
054    /**
055     * Returns the logger for this file system to use.
056     *
057     * @return logger for this file system
058     */
059    protected final Log getLogger() {
060        return log;
061    }
062
063    /**
064     * Initializes the component. This implementation does nothing.
065     *
066     * @throws FileSystemException if an error occurs.
067     */
068    @Override
069    public void init() throws FileSystemException {
070        // default is noop.
071    }
072
073    /**
074     * Sets the context for this file system provider.
075     *
076     * @param context The VfsComponentContext.
077     */
078    @Override
079    public final void setContext(final VfsComponentContext context) {
080        this.context = context;
081    }
082
083    /**
084     * Sets the Logger to use for the component.
085     *
086     * @param log The Log to use.
087     */
088    @Override
089    public final void setLogger(final Log log) {
090        this.log = log;
091    }
092}