[jboss-cvs] JBossAS SVN: r89347 - projects/spring-int/trunk/vfs/src/main/java/org/jboss/spring/vfs.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun May 24 21:05:42 EDT 2009
Author: marius.bogoevici
Date: 2009-05-24 21:05:41 -0400 (Sun, 24 May 2009)
New Revision: 89347
Modified:
projects/spring-int/trunk/vfs/src/main/java/org/jboss/spring/vfs/VFSResourceLoader.java
Log:
getResource() must always return a Resource, if it is not found in the classpath, existent() must be false.
Modified: projects/spring-int/trunk/vfs/src/main/java/org/jboss/spring/vfs/VFSResourceLoader.java
===================================================================
--- projects/spring-int/trunk/vfs/src/main/java/org/jboss/spring/vfs/VFSResourceLoader.java 2009-05-24 10:53:52 UTC (rev 89346)
+++ projects/spring-int/trunk/vfs/src/main/java/org/jboss/spring/vfs/VFSResourceLoader.java 2009-05-25 01:05:41 UTC (rev 89347)
@@ -29,13 +29,15 @@
import java.net.URL;
import java.io.InputStream;
import java.io.IOException;
+import java.io.FileNotFoundException;
/**
* VFS based ResourceLoader.
*
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public class VFSResourceLoader extends DefaultResourceLoader
+public class
+ VFSResourceLoader extends DefaultResourceLoader
{
public VFSResourceLoader(ClassLoader classLoader)
{
@@ -47,11 +49,7 @@
Assert.notNull(location, "Location must not be null");
if (location.startsWith(CLASSPATH_URL_PREFIX))
{
- URL url = getClassLoader().getResource(location.substring(CLASSPATH_URL_PREFIX.length()));
- if (url != null)
- return new VFSResource(url);
- else
- return new InexistentResource();
+ return getResourceByPath(location.substring(CLASSPATH_URL_PREFIX.length()));
}
else
{
@@ -61,22 +59,34 @@
protected Resource getResourceByPath(String path)
{
- return new VFSResource(getClassLoader().getResource(path));
+ URL url = getClassLoader().getResource(path);
+ if (url != null)
+ return new VFSResource(url);
+ else
+ return new InexistentResource(path);
}
- private static class InexistentResource extends AbstractResource {
+ /* A special type of resource, for the case when the resource does not exit */
+ private static class InexistentResource extends AbstractResource
+ {
+ private final String path;
- public String getDescription() {
- return null;
- }
+ private InexistentResource(String path) {
+ this.path = path;
+ }
- public InputStream getInputStream() throws IOException {
- throw new IOException("Resource does not exist");
- }
+ public String getDescription()
+ {
+ return null;
+ }
- @Override
- public boolean exists() {
- return false;
- }
+ public InputStream getInputStream() throws IOException
+ {
+ throw new FileNotFoundException("Resource does not exist for path " + path);
+ }
+
+ public boolean exists() {
+ return false;
+ }
}
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list