1 22 package org.jboss.net.protocol.resource; 23 24 import java.io.IOException ; 25 import java.io.FileNotFoundException ; 26 27 import java.net.URL ; 28 import java.net.MalformedURLException ; 29 30 import org.jboss.net.protocol.DelegatingURLConnection; 31 32 import org.jboss.logging.Logger; 33 34 41 public class ResourceURLConnection 42 extends DelegatingURLConnection 43 { 44 private static final Logger log = Logger.getLogger(ResourceURLConnection.class); 45 46 public ResourceURLConnection(final URL url) 47 throws MalformedURLException , IOException 48 { 49 super(url); 50 } 51 52 protected URL makeDelegateUrl(final URL url) 53 throws MalformedURLException , IOException 54 { 55 String name = url.getHost(); 56 String file = url.getFile(); 57 if (file != null && !file.equals("")) 58 { 59 name += file; 60 } 61 62 64 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 65 URL target = cl.getResource(name); 66 67 if (target == null) 68 { 69 cl = ClassLoader.getSystemClassLoader(); 70 target = cl.getResource(name); 71 } 72 73 if (target == null) 74 throw new FileNotFoundException ("Could not locate resource: " + name); 75 76 if (log.isTraceEnabled()) 77 { 78 log.trace("Target resource URL: " + target); 79 try 80 { 81 log.trace("Target resource URL connection: " + target.openConnection()); 82 } 83 catch (Exception ignore) 84 { 85 } 86 } 87 88 return new URL (target.toExternalForm()); 90 } 91 } 92 | Popular Tags |