1 49 50 package org.openejb.util.urlhandler.resource; 51 52 import java.net.URL ; 53 import java.net.URLConnection ; 54 55 60 public class Handler extends java.net.URLStreamHandler { 61 62 protected URLConnection openConnection( URL url ) throws java.io.IOException { 63 String cln = url.getHost(); 64 65 String resrce = url.getFile().substring( 1 ); 66 67 URL realURL; 68 69 if ( cln != null && cln.length() != 0 ) { 70 Class clz; 71 ClassLoader cl = getContextClassLoader(); 72 73 try { 74 clz = Class.forName( cln, true, cl ); 76 } catch ( ClassNotFoundException ex ) { 77 throw new java.net.MalformedURLException ( "Class " + cln + " cannot be found (" + ex + ")" ); 78 } 79 80 realURL = cl.getResource( resrce ); 81 82 if ( realURL == null ) 83 throw new java.io.FileNotFoundException ( "Class resource " + resrce + " of class " + cln + " cannot be found" ); 84 } else { 85 ClassLoader cl = getContextClassLoader(); 86 realURL = cl.getResource( resrce ); 87 88 if ( realURL == null ) 89 throw new java.io.FileNotFoundException ( "System resource " + resrce + " cannot be found" ); 90 } 91 92 return realURL.openConnection(); 93 } 94 95 public static ClassLoader getContextClassLoader() { 96 return (ClassLoader ) java.security.AccessController.doPrivileged( 97 new java.security.PrivilegedAction () { 98 public Object run() { 99 return Thread.currentThread().getContextClassLoader(); 100 } 101 } 102 ); 103 } 104 105 } 106 | Popular Tags |