1 8 package org.codehaus.loom.classman.runtime; 9 10 import java.io.IOException ; 11 import java.net.URL ; 12 import java.security.SecureClassLoader ; 13 import java.util.Enumeration ; 14 import java.util.Vector ; 15 16 30 public class JoinClassLoader 31 extends SecureClassLoader  32 { 33 37 private final ClassLoader [] m_classLoaders; 38 39 46 public JoinClassLoader( final ClassLoader [] classLoaders, 47 final ClassLoader parent ) 48 { 49 super( parent ); 50 if( null == classLoaders ) 51 { 52 throw new NullPointerException ( "classLoaders" ); 53 } 54 for( int i = 0; i < classLoaders.length; i++ ) 55 { 56 if( null == classLoaders[ i ] ) 57 { 58 throw new NullPointerException ( "classLoaders[" + i + "]" ); 59 } 60 } 61 m_classLoaders = classLoaders; 62 } 63 64 73 protected Class findClass( final String name ) 74 throws ClassNotFoundException  75 { 76 for( int i = 0; i < m_classLoaders.length; i++ ) 77 { 78 try 79 { 80 return m_classLoaders[ i ].loadClass( name ); 81 } 82 catch( final ClassNotFoundException cnfe ) 83 { 84 } 86 } 87 88 return super.findClass( name ); 89 } 90 91 100 protected Enumeration findResources( final String name ) 101 throws IOException  102 { 103 final Vector result = new Vector (); 104 105 for( int i = 0; i < m_classLoaders.length; i++ ) 106 { 107 try 108 { 109 final Enumeration resources = 110 m_classLoaders[ i ].getResources( name ); 111 addAll( result, resources ); 112 } 113 catch( final IOException ioe ) 114 { 115 } 117 } 118 final Enumeration resources = super.findResources( name ); 119 addAll( result, resources ); 120 return result.elements(); 121 } 122 123 129 private void addAll( final Vector result, 130 final Enumeration resources ) 131 { 132 while( resources.hasMoreElements() ) 133 { 134 result.add( resources.nextElement() ); 135 } 136 } 137 138 145 protected URL findResource( final String name ) 146 { 147 for( int i = 0; i < m_classLoaders.length; i++ ) 148 { 149 final URL resource = m_classLoaders[ i ].getResource( name ); 150 if( null != resource ) 151 { 152 return resource; 153 } 154 } 155 return super.findResource( name ); 156 } 157 } 158 | Popular Tags |