1 8 package org.apache.avalon.phoenix.components.classloader; 9 10 import java.io.IOException ; 11 import java.net.MalformedURLException ; 12 import java.net.URL ; 13 import java.net.URLClassLoader ; 14 import java.security.CodeSource ; 15 import java.security.PermissionCollection ; 16 import java.security.Policy ; 17 import java.util.Enumeration ; 18 import org.apache.avalon.framework.logger.LogEnabled; 19 import org.apache.avalon.framework.logger.Logger; 20 21 29 class PolicyClassLoader 30 extends URLClassLoader 31 implements LogEnabled 32 { 33 private final Policy m_policy; 35 36 private Logger m_logger; 38 39 47 PolicyClassLoader( final String [] urls, 48 final ClassLoader parent, 49 final Policy policy ) 50 throws MalformedURLException 51 { 52 super( new URL [ 0 ], parent ); 53 54 if( null == policy ) 55 { 56 throw new NullPointerException ( "policy" ); 57 } 58 m_policy = policy; 59 60 for( int i = 0; i < urls.length; i++ ) 61 { 62 final URL url = new URL ( urls[ i ] ); 63 addURL( url ); 64 } 65 } 66 67 public void enableLogging( final Logger logger ) 68 { 69 m_logger = logger; 70 } 71 72 protected void addURL( final URL url ) 73 { 74 super.addURL( url ); 75 } 76 77 protected final Logger getLogger() 78 { 79 return m_logger; 80 } 81 82 91 protected Class findClass( final String name ) 92 throws ClassNotFoundException 93 { 94 if( getLogger().isDebugEnabled() ) 95 { 96 getLogger().debug( "findClass(" + name + ")" ); 97 } 98 return super.findClass( name ); 99 } 100 101 108 protected PermissionCollection getPermissions( final CodeSource codeSource ) 109 { 110 if( getLogger().isDebugEnabled() ) 111 { 112 getLogger().debug( "getPermissions(" + codeSource + ")" ); 113 } 114 return m_policy.getPermissions( codeSource ); 115 } 116 117 129 public Enumeration findResources( final String name ) 130 throws IOException 131 { 132 if( getLogger().isDebugEnabled() ) 133 { 134 getLogger().debug( "findResources(" + name + ")" ); 135 } 136 137 return super.findResources( name ); 138 } 139 140 151 public URL findResource( final String name ) 152 { 153 if( getLogger().isDebugEnabled() ) 154 { 155 getLogger().debug( "findResource(" + name + ")" ); 156 } 157 158 final URL url = super.findResource( name ); 159 160 if( getLogger().isDebugEnabled() ) 161 { 162 if( null != url ) 163 { 164 getLogger().debug( "Resource " + name + " located (" + url + ")" ); 165 } 166 else 167 { 168 getLogger().debug( "Resource " + name + " not located" ); 169 } 170 } 171 172 return url; 173 } 174 } 175 | Popular Tags |