1
1
/*
2
- * Copyright 2010 the original author or authors.
2
+ * Copyright 2002- 2010 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
32
32
33
33
/**
34
34
* Utility for detecting the JBoss VFS version available in the classpath.
35
- * JBoss AS 5+ uses VFS 2.x (package <code>org.jboss.virtual</code>) while JBoss AS 6+ uses
36
- * VFS 3.x (package <code>org.jboss.vfs</code>).
37
- *
38
- * <p/>
39
- * Thanks go to Marius Bogoevici for the initial patch.
35
+ * JBoss AS 5+ uses VFS 2.x (package <code>org.jboss.virtual</code>) while
36
+ * JBoss AS 6+ uses VFS 3.x (package <code>org.jboss.vfs</code>).
37
+ *
38
+ * <p>Thanks go to Marius Bogoevici for the initial patch.
40
39
*
41
40
* <b>Note:</b> This is an internal class and should not be used outside the framework.
42
- *
41
+ *
43
42
* @author Costin Leau
43
+ * @since 3.0.3
44
44
*/
45
45
public abstract class VfsUtils {
46
46
47
- private static final Log log = LogFactory .getLog (VfsUtils .class );
47
+ private static final Log logger = LogFactory .getLog (VfsUtils .class );
48
48
49
49
private static final String VFS2_PKG = "org.jboss.virtual." ;
50
50
private static final String VFS3_PKG = "org.jboss.vfs." ;
51
51
private static final String VFS_NAME = "VFS" ;
52
52
53
- private static enum VFS_VER {
54
- V2 , V3
55
- }
53
+ private static enum VFS_VER { V2 , V3 }
56
54
57
- private static VFS_VER version = null ;
55
+ private static VFS_VER version ;
58
56
59
57
private static Method VFS_METHOD_GET_ROOT_URL = null ;
60
58
private static Method VFS_METHOD_GET_ROOT_URI = null ;
@@ -71,41 +69,40 @@ private static enum VFS_VER {
71
69
protected static Class <?> VIRTUAL_FILE_VISITOR_INTERFACE ;
72
70
protected static Method VIRTUAL_FILE_METHOD_VISIT ;
73
71
74
-
75
72
private static Method VFS_UTILS_METHOD_IS_NESTED_FILE = null ;
76
73
private static Method VFS_UTILS_METHOD_GET_COMPATIBLE_URI = null ;
77
74
private static Field VISITOR_ATTRIBUTES_FIELD_RECURSE = null ;
78
75
private static Method GET_PHYSICAL_FILE = null ;
79
76
80
77
static {
81
78
ClassLoader loader = VfsUtils .class .getClassLoader ();
79
+ String pkg ;
80
+ Class <?> vfsClass ;
82
81
83
- String pkg = "" ;
84
-
85
- Class <?> vfsClass = null ;
86
-
87
- // check JBoss 6
82
+ // check for JBoss 6
88
83
try {
89
84
vfsClass = loader .loadClass (VFS3_PKG + VFS_NAME );
90
85
version = VFS_VER .V3 ;
91
86
pkg = VFS3_PKG ;
92
87
93
- if (log .isDebugEnabled ())
94
- log .debug ("JBoss VFS packages for JBoss AS 6 found" );
95
- } catch (ClassNotFoundException ex ) {
88
+ if (logger .isDebugEnabled ()) {
89
+ logger .debug ("JBoss VFS packages for JBoss AS 6 found" );
90
+ }
91
+ }
92
+ catch (ClassNotFoundException ex ) {
96
93
// fallback to JBoss 5
97
- if (log .isDebugEnabled ())
98
- log .debug ("JBoss VFS packages for JBoss AS 6 not found; falling back to JBoss AS 5 packages" );
94
+ if (logger .isDebugEnabled ())
95
+ logger .debug ("JBoss VFS packages for JBoss AS 6 not found; falling back to JBoss AS 5 packages" );
99
96
try {
100
97
vfsClass = loader .loadClass (VFS2_PKG + VFS_NAME );
101
98
102
99
version = VFS_VER .V2 ;
103
100
pkg = VFS2_PKG ;
104
101
105
- if (log .isDebugEnabled ())
106
- log .debug ("JBoss VFS packages for JBoss AS 5 found" );
102
+ if (logger .isDebugEnabled ())
103
+ logger .debug ("JBoss VFS packages for JBoss AS 5 found" );
107
104
} catch (ClassNotFoundException ex1 ) {
108
- log .error ("JBoss VFS packages (for both JBoss AS 5 and 6) were not found - JBoss VFS support disabled" );
105
+ logger .error ("JBoss VFS packages (for both JBoss AS 5 and 6) were not found - JBoss VFS support disabled" );
109
106
throw new IllegalStateException ("Cannot detect JBoss VFS packages" , ex1 );
110
107
}
111
108
}
@@ -144,22 +141,24 @@ private static enum VFS_VER {
144
141
145
142
Class <?> visitorAttributesClass = loader .loadClass (pkg + "VisitorAttributes" );
146
143
VISITOR_ATTRIBUTES_FIELD_RECURSE = ReflectionUtils .findField (visitorAttributesClass , "RECURSE" );
147
-
148
- } catch (ClassNotFoundException ex ) {
144
+ }
145
+ catch (ClassNotFoundException ex ) {
149
146
throw new IllegalStateException ("Could not detect the JBoss VFS infrastructure" , ex );
150
147
}
151
148
}
152
149
153
150
protected static Object invokeVfsMethod (Method method , Object target , Object ... args ) throws IOException {
154
151
try {
155
152
return method .invoke (target , args );
156
- } catch (InvocationTargetException ex ) {
153
+ }
154
+ catch (InvocationTargetException ex ) {
157
155
Throwable targetEx = ex .getTargetException ();
158
156
if (targetEx instanceof IOException ) {
159
157
throw (IOException ) targetEx ;
160
158
}
161
159
ReflectionUtils .handleInvocationTargetException (ex );
162
- } catch (Exception ex ) {
160
+ }
161
+ catch (Exception ex ) {
163
162
ReflectionUtils .handleReflectionException (ex );
164
163
}
165
164
@@ -169,15 +168,17 @@ protected static Object invokeVfsMethod(Method method, Object target, Object...
169
168
static boolean exists (Object vfsResource ) {
170
169
try {
171
170
return (Boolean ) invokeVfsMethod (VIRTUAL_FILE_METHOD_EXISTS , vfsResource );
172
- } catch (IOException ex ) {
171
+ }
172
+ catch (IOException ex ) {
173
173
return false ;
174
174
}
175
175
}
176
176
177
177
static boolean isReadable (Object vfsResource ) {
178
178
try {
179
179
return ((Long ) invokeVfsMethod (VIRTUAL_FILE_METHOD_GET_SIZE , vfsResource ) > 0 );
180
- } catch (IOException ex ) {
180
+ }
181
+ catch (IOException ex ) {
181
182
return false ;
182
183
}
183
184
}
@@ -201,7 +202,8 @@ static URI getURI(Object vfsResource) throws IOException {
201
202
static String getName (Object vfsResource ) {
202
203
try {
203
204
return (String ) invokeVfsMethod (VIRTUAL_FILE_METHOD_GET_NAME , vfsResource );
204
- } catch (IOException ex ) {
205
+ }
206
+ catch (IOException ex ) {
205
207
throw new IllegalStateException ("Cannot get resource name" , ex );
206
208
}
207
209
}
@@ -221,7 +223,8 @@ static File getFile(Object vfsResource) throws IOException {
221
223
}
222
224
try {
223
225
return new File ((URI ) invokeVfsMethod (VFS_UTILS_METHOD_GET_COMPATIBLE_URI , null , vfsResource ));
224
- } catch (Exception ex ) {
226
+ }
227
+ catch (Exception ex ) {
225
228
throw new NestedIOException ("Failed to obtain File reference for " + vfsResource , ex );
226
229
}
227
230
}
0 commit comments