KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > VFS


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.vfs;
17
18 import java.lang.reflect.InvocationTargetException JavaDoc;
19 import java.lang.reflect.Method JavaDoc;
20
21 /**
22  * The main entry point for the VFS. Used to create {@link FileSystemManager}
23  * instances.
24  *
25  * @author <a HREF="mailto:adammurdoch@apache.org">Adam Murdoch</a>
26  */

27 public class VFS
28 {
29     private static Boolean JavaDoc URI_STYLE = null;
30
31     private static FileSystemManager instance;
32
33     private VFS()
34     {
35     }
36
37     /**
38      * Returns the default {@link FileSystemManager} instance.
39      */

40     public static synchronized FileSystemManager getManager()
41         throws FileSystemException
42     {
43         if (instance == null)
44         {
45             instance = createManager("org.apache.commons.vfs.impl.StandardFileSystemManager");
46         }
47         return instance;
48     }
49
50     /**
51      * Creates a file system manager instance.
52      */

53     private static FileSystemManager createManager(final String JavaDoc managerClassName)
54         throws FileSystemException
55     {
56         try
57         {
58             // Create instance
59
final Class JavaDoc mgrClass = Class.forName(managerClassName);
60             final FileSystemManager mgr = (FileSystemManager) mgrClass.newInstance();
61
62             /*
63             try
64             {
65                 // Set the logger
66                 final Method setLogMethod = mgrClass.getMethod("setLogger", new Class[]{Log.class});
67                 final Log logger = LogFactory.getLog(VFS.class);
68                 setLogMethod.invoke(mgr, new Object[]{logger});
69             }
70             catch (final NoSuchMethodException e)
71             {
72                 // Ignore; don't set the logger
73             }
74             */

75
76             try
77             {
78                 // Initialise
79
final Method JavaDoc initMethod = mgrClass.getMethod("init", null);
80                 initMethod.invoke(mgr, null);
81             }
82             catch (final NoSuchMethodException JavaDoc e)
83             {
84                 // Ignore; don't initialize
85
}
86
87             return mgr;
88         }
89         catch (final InvocationTargetException JavaDoc e)
90         {
91             throw new FileSystemException("vfs/create-manager.error",
92                 managerClassName,
93                 e.getTargetException());
94         }
95         catch (final Exception JavaDoc e)
96         {
97             throw new FileSystemException("vfs/create-manager.error",
98                 managerClassName,
99                 e);
100         }
101     }
102
103     public static boolean isUriStyle()
104     {
105         if (URI_STYLE == null)
106         {
107             URI_STYLE = Boolean.FALSE;
108         }
109         return URI_STYLE.booleanValue();
110     }
111
112     public static void setUriStyle(boolean uriStyle)
113     {
114         if (URI_STYLE != null && URI_STYLE.booleanValue() != uriStyle)
115         {
116             throw new IllegalStateException JavaDoc("URI STYLE ALREADY SET TO");
117         }
118         URI_STYLE = uriStyle ? Boolean.TRUE : Boolean.FALSE;
119     }
120 }
121
Popular Tags