1 17 18 package org.apache.geronimo.system.url.resource; 19 20 import java.io.FileNotFoundException ; 21 import java.io.IOException ; 22 import java.net.MalformedURLException ; 23 import java.net.URL ; 24 25 import org.apache.geronimo.system.url.DelegatingURLConnection; 26 27 32 public class ResourceURLConnection extends DelegatingURLConnection { 33 public ResourceURLConnection(final URL url) throws MalformedURLException , IOException { 34 super(url); 35 } 36 37 protected URL makeDelegateUrl(final URL url) throws MalformedURLException , IOException { 38 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 39 String name = url.getPath(); 40 URL target = null; 41 42 String ref = url.getRef(); 44 if (ref != null) { 45 try { 46 Class type = classLoader.loadClass(ref); 47 target = type.getResource(name); 48 } catch (ClassNotFoundException ignore) { 49 } 51 } 52 if (name.startsWith("/")) { 55 name = name.substring(1); 56 } 57 if (target == null) { 58 target = classLoader.getResource(name); 60 61 if (target == null) { 62 target = ClassLoader.getSystemClassLoader().getResource(name); 63 } 64 } 65 66 if (target == null) { 67 throw new FileNotFoundException ("Could not locate resource: " + name); 68 } 69 70 return target; 71 } 72 } 73 | Popular Tags |