1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs;
18
19 import java.lang.reflect.InvocationTargetException;
20 import java.lang.reflect.Method;
21
22 /***
23 * The main entry point for the VFS. Used to create {@link FileSystemManager}
24 * instances.
25 *
26 * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
27 * @version $Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
28 */
29 public class VFS
30 {
31 private static Boolean URI_STYLE = null;
32
33 private static FileSystemManager instance;
34
35 private VFS()
36 {
37 }
38
39 /***
40 * Returns the default {@link FileSystemManager} instance
41 */
42 public static synchronized FileSystemManager getManager()
43 throws FileSystemException
44 {
45 if (instance == null)
46 {
47 instance = createManager("org.apache.commons.vfs.impl.StandardFileSystemManager");
48 }
49 return instance;
50 }
51
52 /***
53 * Creates a file system manager instance.
54 */
55 private static FileSystemManager createManager(final String managerClassName)
56 throws FileSystemException
57 {
58 try
59 {
60
61 final Class mgrClass = Class.forName(managerClassName);
62 final FileSystemManager mgr = (FileSystemManager) mgrClass.newInstance();
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 try
79 {
80
81 final Method initMethod = mgrClass.getMethod("init", null);
82 initMethod.invoke(mgr, null);
83 }
84 catch (final NoSuchMethodException e)
85 {
86
87 }
88
89 return mgr;
90 }
91 catch (final InvocationTargetException e)
92 {
93 throw new FileSystemException("vfs/create-manager.error",
94 managerClassName,
95 e.getTargetException());
96 }
97 catch (final Exception e)
98 {
99 throw new FileSystemException("vfs/create-manager.error",
100 managerClassName,
101 e);
102 }
103 }
104
105 public static boolean isUriStyle()
106 {
107 if (URI_STYLE == null)
108 {
109 URI_STYLE = Boolean.FALSE;
110 }
111 return URI_STYLE.booleanValue();
112 }
113
114 public static void setUriStyle(boolean uriStyle)
115 {
116 if (URI_STYLE != null && URI_STYLE.booleanValue() != uriStyle)
117 {
118 throw new IllegalStateException("URI STYLE ALREADY SET TO");
119 }
120 URI_STYLE = uriStyle ? Boolean.TRUE : Boolean.FALSE;
121 }
122 }