1 16 package org.apache.commons.vfs; 17 18 import java.lang.reflect.InvocationTargetException ; 19 import java.lang.reflect.Method ; 20 21 27 public class VFS 28 { 29 private static Boolean URI_STYLE = null; 30 31 private static FileSystemManager instance; 32 33 private VFS() 34 { 35 } 36 37 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 53 private static FileSystemManager createManager(final String managerClassName) 54 throws FileSystemException 55 { 56 try 57 { 58 final Class mgrClass = Class.forName(managerClassName); 60 final FileSystemManager mgr = (FileSystemManager) mgrClass.newInstance(); 61 62 75 76 try 77 { 78 final Method initMethod = mgrClass.getMethod("init", null); 80 initMethod.invoke(mgr, null); 81 } 82 catch (final NoSuchMethodException e) 83 { 84 } 86 87 return mgr; 88 } 89 catch (final InvocationTargetException e) 90 { 91 throw new FileSystemException("vfs/create-manager.error", 92 managerClassName, 93 e.getTargetException()); 94 } 95 catch (final Exception 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 ("URI STYLE ALREADY SET TO"); 117 } 118 URI_STYLE = uriStyle ? Boolean.TRUE : Boolean.FALSE; 119 } 120 } 121 | Popular Tags |