1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.commons.vfs.util;
22
23 import org.millscript.commons.vfs.VFS;
24 import org.millscript.commons.vfs.VFolder;
25 import org.millscript.commons.vfs.VVolume;
26
27 import java.net.URI;
28
29 /**
30 * This class implements a Unix style chroot volume, which can have its real
31 * root at any virtual folder.
32 */
33 public class ChrootVolume implements VVolume {
34
35 /**
36 * The root folder for this volume.
37 */
38 private final ChrootFolder rootFolder;
39
40 /**
41 * Constructs a new chroot volume with the specified folder as its root.
42 *
43 * @param root the root folder for the chroot volume
44 */
45 public ChrootVolume( final VFolder root ) {
46 this.rootFolder = this.makeRootVFolder( root );
47 }
48
49 /**
50 * @see org.millscript.commons.vfs.VVolume#appendBaseURI(java.lang.StringBuffer)
51 */
52 public StringBuffer appendBaseURI( final StringBuffer buffer ) {
53
54 return buffer;
55 }
56
57 /**
58 * @see org.millscript.commons.vfs.VVolume#getRootVFolder()
59 */
60 public VFolder getRootVFolder() {
61 return this.rootFolder;
62 }
63
64 /**
65 * @see org.millscript.commons.vfs.VVolume#getURI()
66 */
67 public URI getURI() {
68
69 return URI.create( "/" );
70 }
71
72 /**
73 * Constructs the root folder for this volume, with the specified parent
74 * folder and returns it.
75 *
76 * @param parent the virtual folder for the source of this volume
77 * @return the VFolder for the root of this volume
78 */
79 public ChrootFolder makeRootVFolder( final VFolder parent ) {
80 return new ChrootFolder( this, null, parent );
81 }
82
83 /**
84 * @see org.millscript.commons.vfs.VVolume#getParentVFS()
85 */
86 public VFS getParentVFS() {
87 return this.rootFolder.getVolume().getParentVFS();
88 }
89
90 /**
91 * @see java.lang.Object#toString()
92 */
93 @Override
94 public final String toString() {
95 final StringBuffer buff = new StringBuffer( "CHROOT_VOLUME( " );
96 buff.append( this.getURI().toString() );
97 buff.append( " )" );
98 return buff.toString();
99 }
100
101 }