1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2013 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.
25
25
import java .net .URI ;
26
26
import java .net .URL ;
27
27
28
- import org .apache .commons .logging .Log ;
29
- import org .apache .commons .logging .LogFactory ;
30
-
31
- import org .springframework .core .NestedIOException ;
32
28
import org .springframework .util .ReflectionUtils ;
33
29
34
30
/**
35
31
* Utility for detecting the JBoss VFS version available in the classpath.
36
- * JBoss AS 5+ uses VFS 2.x (package {@code org.jboss.virtual}) while
37
- * JBoss AS 6+ uses VFS 3.x (package {@code org.jboss.vfs}).
32
+ * As of Spring 4.0, supports VFS 3.x on JBoss AS 6+ (package {@code org.jboss.vfs}).
38
33
*
39
34
* <p>Thanks go to Marius Bogoevici for the initial patch.
40
35
*
41
36
* <b>Note:</b> This is an internal class and should not be used outside the framework.
42
37
*
43
38
* @author Costin Leau
39
+ * @author Juergen Hoeller
44
40
* @since 3.0.3
45
41
*/
46
42
public abstract class VfsUtils {
47
43
48
- private static final Log logger = LogFactory .getLog (VfsUtils .class );
49
-
50
- private static final String VFS2_PKG = "org.jboss.virtual." ;
51
44
private static final String VFS3_PKG = "org.jboss.vfs." ;
52
45
private static final String VFS_NAME = "VFS" ;
53
46
54
- private static enum VFS_VER { V2 , V3 }
55
-
56
- private static VFS_VER version ;
57
-
58
47
private static Method VFS_METHOD_GET_ROOT_URL = null ;
59
48
private static Method VFS_METHOD_GET_ROOT_URI = null ;
60
49
@@ -71,54 +60,17 @@ private static enum VFS_VER { V2, V3 }
71
60
protected static Class <?> VIRTUAL_FILE_VISITOR_INTERFACE ;
72
61
protected static Method VIRTUAL_FILE_METHOD_VISIT ;
73
62
74
- private static Method VFS_UTILS_METHOD_IS_NESTED_FILE = null ;
75
- private static Method VFS_UTILS_METHOD_GET_COMPATIBLE_URI = null ;
76
63
private static Field VISITOR_ATTRIBUTES_FIELD_RECURSE = null ;
77
64
private static Method GET_PHYSICAL_FILE = null ;
78
65
79
66
static {
80
67
ClassLoader loader = VfsUtils .class .getClassLoader ();
81
- String pkg ;
82
- Class <?> vfsClass ;
83
-
84
- // check for JBoss 6
85
- try {
86
- vfsClass = loader .loadClass (VFS3_PKG + VFS_NAME );
87
- version = VFS_VER .V3 ;
88
- pkg = VFS3_PKG ;
89
-
90
- if (logger .isDebugEnabled ()) {
91
- logger .debug ("JBoss VFS packages for JBoss AS 6 found" );
92
- }
93
- }
94
- catch (ClassNotFoundException ex ) {
95
- // fallback to JBoss 5
96
- if (logger .isDebugEnabled ())
97
- logger .debug ("JBoss VFS packages for JBoss AS 6 not found; falling back to JBoss AS 5 packages" );
98
- try {
99
- vfsClass = loader .loadClass (VFS2_PKG + VFS_NAME );
100
-
101
- version = VFS_VER .V2 ;
102
- pkg = VFS2_PKG ;
103
-
104
- if (logger .isDebugEnabled ())
105
- logger .debug ("JBoss VFS packages for JBoss AS 5 found" );
106
- }
107
- catch (ClassNotFoundException ex2 ) {
108
- logger .error ("JBoss VFS packages (for both JBoss AS 5 and 6) were not found - JBoss VFS support disabled" );
109
- throw new IllegalStateException ("Cannot detect JBoss VFS packages" , ex2 );
110
- }
111
- }
112
-
113
- // cache reflective information
114
68
try {
115
- String methodName = (VFS_VER .V3 .equals (version ) ? "getChild" : "getRoot" );
116
-
117
- VFS_METHOD_GET_ROOT_URL = ReflectionUtils .findMethod (vfsClass , methodName , URL .class );
118
- VFS_METHOD_GET_ROOT_URI = ReflectionUtils .findMethod (vfsClass , methodName , URI .class );
119
-
120
- Class <?> virtualFile = loader .loadClass (pkg + "VirtualFile" );
69
+ Class <?> vfsClass = loader .loadClass (VFS3_PKG + VFS_NAME );
70
+ VFS_METHOD_GET_ROOT_URL = ReflectionUtils .findMethod (vfsClass , "getChild" , URL .class );
71
+ VFS_METHOD_GET_ROOT_URI = ReflectionUtils .findMethod (vfsClass , "getChild" , URI .class );
121
72
73
+ Class <?> virtualFile = loader .loadClass (VFS3_PKG + "VirtualFile" );
122
74
VIRTUAL_FILE_METHOD_EXISTS = ReflectionUtils .findMethod (virtualFile , "exists" );
123
75
VIRTUAL_FILE_METHOD_GET_INPUT_STREAM = ReflectionUtils .findMethod (virtualFile , "openStream" );
124
76
VIRTUAL_FILE_METHOD_GET_SIZE = ReflectionUtils .findMethod (virtualFile , "getSize" );
@@ -128,25 +80,16 @@ private static enum VFS_VER { V2, V3 }
128
80
VIRTUAL_FILE_METHOD_GET_NAME = ReflectionUtils .findMethod (virtualFile , "getName" );
129
81
VIRTUAL_FILE_METHOD_GET_PATH_NAME = ReflectionUtils .findMethod (virtualFile , "getPathName" );
130
82
GET_PHYSICAL_FILE = ReflectionUtils .findMethod (virtualFile , "getPhysicalFile" );
83
+ VIRTUAL_FILE_METHOD_GET_CHILD = ReflectionUtils .findMethod (virtualFile , "getChild" , String .class );
131
84
132
- methodName = (VFS_VER .V3 .equals (version ) ? "getChild" : "findChild" );
133
-
134
- VIRTUAL_FILE_METHOD_GET_CHILD = ReflectionUtils .findMethod (virtualFile , methodName , String .class );
135
-
136
- Class <?> utilsClass = loader .loadClass (pkg + "VFSUtils" );
137
-
138
- VFS_UTILS_METHOD_GET_COMPATIBLE_URI = ReflectionUtils .findMethod (utilsClass , "getCompatibleURI" ,
139
- virtualFile );
140
- VFS_UTILS_METHOD_IS_NESTED_FILE = ReflectionUtils .findMethod (utilsClass , "isNestedFile" , virtualFile );
141
-
142
- VIRTUAL_FILE_VISITOR_INTERFACE = loader .loadClass (pkg + "VirtualFileVisitor" );
85
+ VIRTUAL_FILE_VISITOR_INTERFACE = loader .loadClass (VFS3_PKG + "VirtualFileVisitor" );
143
86
VIRTUAL_FILE_METHOD_VISIT = ReflectionUtils .findMethod (virtualFile , "visit" , VIRTUAL_FILE_VISITOR_INTERFACE );
144
87
145
- Class <?> visitorAttributesClass = loader .loadClass (pkg + "VisitorAttributes" );
88
+ Class <?> visitorAttributesClass = loader .loadClass (VFS3_PKG + "VisitorAttributes" );
146
89
VISITOR_ATTRIBUTES_FIELD_RECURSE = ReflectionUtils .findField (visitorAttributesClass , "RECURSE" );
147
90
}
148
91
catch (ClassNotFoundException ex ) {
149
- throw new IllegalStateException ("Could not detect the JBoss VFS infrastructure" , ex );
92
+ throw new IllegalStateException ("Could not detect JBoss VFS infrastructure" , ex );
150
93
}
151
94
}
152
95
@@ -224,20 +167,7 @@ static Object getChild(Object vfsResource, String path) throws IOException {
224
167
}
225
168
226
169
static File getFile (Object vfsResource ) throws IOException {
227
- if (VFS_VER .V2 .equals (version )) {
228
- if ((Boolean ) invokeVfsMethod (VFS_UTILS_METHOD_IS_NESTED_FILE , null , vfsResource )) {
229
- throw new IOException ("File resolution not supported for nested resource: " + vfsResource );
230
- }
231
- try {
232
- return new File ((URI ) invokeVfsMethod (VFS_UTILS_METHOD_GET_COMPATIBLE_URI , null , vfsResource ));
233
- }
234
- catch (Exception ex ) {
235
- throw new NestedIOException ("Failed to obtain File reference for " + vfsResource , ex );
236
- }
237
- }
238
- else {
239
- return (File ) invokeVfsMethod (GET_PHYSICAL_FILE , vfsResource );
240
- }
170
+ return (File ) invokeVfsMethod (GET_PHYSICAL_FILE , vfsResource );
241
171
}
242
172
243
173
static Object getRoot (URI url ) throws IOException {
@@ -257,4 +187,5 @@ protected static Object doGetVisitorAttribute() {
257
187
protected static String doGetPath (Object resource ) {
258
188
return (String ) ReflectionUtils .invokeMethod (VIRTUAL_FILE_METHOD_GET_PATH_NAME , resource );
259
189
}
190
+
260
191
}
0 commit comments