View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2005 Kevin Rogers
4   //
5   // This file is part of MillScript.
6   //
7   // MillScript is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.commons.vfs.protocols;
22  
23  import org.millscript.commons.vfs.AbstractVVolume;
24  import org.millscript.commons.vfs.VFS;
25  import org.millscript.commons.vfs.VFolder;
26  
27  import java.net.URI;
28  
29  /**
30   * The class provides a skeletal virtual filesystem volume, intended for easing
31   * support for different protocols.
32   */
33  public abstract class AbstractProtocolVVolume extends AbstractVVolume {
34  
35      /**
36       * The underlying URI for the root of the virtual filesystem volume.
37       */
38      private final URI rootURI;
39  
40      /**
41       * The VFolder that represents the root of the virtual filesystem.
42       */
43      private VFolder rootVFolder;
44  
45      /**
46       * Constructs a new virtual volume with the specified root URI, using the
47       * default root VFolder. The root VFolder is obtained by calling the
48       * <code>makeRootVFolder</code> method.
49       *
50       * @param v the VFS that was used to create this volume
51       * @param root  the virtual filesystem volume root
52       */
53      protected AbstractProtocolVVolume( final VFS v, final URI root ) {
54          super( v );
55          this.rootURI = root;
56      }
57  
58      /**
59       * @see org.millscript.commons.vfs.VVolume#getRootVFolder()
60       */
61      public VFolder getRootVFolder() {
62          if ( this.rootVFolder == null ) {
63              this.rootVFolder = this.makeRootVFolder();
64          }
65          return this.rootVFolder;
66      }
67  
68      /**
69       * @see org.millscript.commons.vfs.VVolume#getURI()
70       */
71      public final URI getURI() {
72          return this.rootURI;
73      }
74  
75      /**
76       * Constructs the root folder for this volume, with the specified parent
77       * folder and returns it.
78       *
79       * @return  the VFolder for the root of this volume
80       */
81      protected abstract VFolder makeRootVFolder();
82  
83  }