View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2.provider;
18  
19  import org.apache.commons.logging.Log;
20  import org.apache.commons.vfs2.FileSystemException;
21  
22  /**
23   * A partial {@link VfsComponent} implementation.
24   */
25  public abstract class AbstractVfsComponent implements VfsComponent {
26  
27      private VfsComponentContext context;
28      private Log log;
29  
30      /**
31       * Constructs a new instance for subclasses.
32       */
33      public AbstractVfsComponent() {
34          // empty
35      }
36  
37      /**
38       * Closes the provider. This implementation does nothing.
39       */
40      @Override
41      public void close() {
42          // default is noop.
43      }
44  
45      /**
46       * Returns the context for this provider.
47       *
48       * @return provider context
49       */
50      protected final VfsComponentContext getContext() {
51          return context;
52      }
53  
54      /**
55       * Returns the logger for this file system to use.
56       *
57       * @return logger for this file system
58       */
59      protected final Log getLogger() {
60          return log;
61      }
62  
63      /**
64       * Initializes the component. This implementation does nothing.
65       *
66       * @throws FileSystemException if an error occurs.
67       */
68      @Override
69      public void init() throws FileSystemException {
70          // default is noop.
71      }
72  
73      /**
74       * Sets the context for this file system provider.
75       *
76       * @param context The VfsComponentContext.
77       */
78      @Override
79      public final void setContext(final VfsComponentContext context) {
80          this.context = context;
81      }
82  
83      /**
84       * Sets the Logger to use for the component.
85       *
86       * @param log The Log to use.
87       */
88      @Override
89      public final void setLogger(final Log log) {
90          this.log = log;
91      }
92  }