1 2 3 10 package org.objectweb.openccm.corba.util.urlhandler.resource; 11 12 import java.io.FileNotFoundException ; 13 import java.io.IOException ; 14 15 import java.net.MalformedURLException ; 16 import java.net.URL ; 17 import java.net.URLConnection ; 18 import java.net.URLStreamHandler ; 19 20 27 public class Handler 28 extends URLStreamHandler 29 { 30 38 protected URLConnection openConnection( final URL url ) 39 throws IOException 40 { 41 String cln = url.getHost(); 42 String resrce = url.getFile().substring( 1 ); 43 44 URL realURL; 45 46 if ( cln != null && cln.length() != 0 ) 47 { 48 Class clz; 49 50 try 51 { 52 clz = Thread.currentThread().getContextClassLoader(). 53 loadClass( cln ); 54 } 55 catch ( final ClassNotFoundException ex ) 56 { 57 throw new IOException ("Class " + cln + " cannot be found (" + ex + ")"); 58 } 59 60 realURL = clz.getResource( resrce ); 61 62 if ( realURL == null ) 63 throw new FileNotFoundException ( 64 "Class resource " + resrce + " of class " 65 + cln + " cannot be found" ); 66 67 } 68 else 69 { 70 realURL = Thread.currentThread().getContextClassLoader().getResource( resrce ); 72 73 if (realURL == null) 75 realURL = ClassLoader.getSystemResource( resrce ); 76 77 if ( realURL == null ) 78 throw new FileNotFoundException ( "System resource " 79 + resrce + " cannot be found" ); 80 } 81 return realURL.openConnection(); 82 } 83 } 84 85 | Popular Tags |