1 package org.apache.slide.projector.engine; 2 3 import java.io.ByteArrayOutputStream ; 4 import java.io.IOException ; 5 import java.io.InputStream ; 6 7 import org.apache.slide.projector.Context; 8 import org.apache.slide.projector.Projector; 9 import org.apache.slide.projector.SystemContext; 10 import org.apache.slide.projector.URI; 11 import org.apache.slide.projector.util.StreamHelper; 12 import org.apache.slide.projector.value.StreamableValue; 13 import org.apache.slide.projector.value.URIValue; 14 15 public class ProjectorClassLoader extends ClassLoader { 16 URI uri; 17 18 public ProjectorClassLoader(ClassLoader parent, URI uri) { 19 super(parent); 20 this.uri = uri; 21 } 22 23 public Class findClass(String name) throws ClassNotFoundException { 24 Context context = new SystemContext(); 25 try { 26 URI rendererUri = new URIValue(uri.toString() + name.replace('.', '/') + ".class"); 27 StreamableValue resource = ((StreamableValue)Projector.getRepository().getResource(rendererUri, context.getCredentials())); 28 if ( resource == null ) { 29 throw new ClassNotFoundException ("Class " + name + " at URI '"+rendererUri+"' not found in collection '" + uri + "'!"); 30 } 31 InputStream inputStream = resource.getInputStream(); 32 ByteArrayOutputStream outputStream = new ByteArrayOutputStream (1024); 33 StreamHelper.copy(inputStream, outputStream); 34 byte[] b = outputStream.toByteArray(); 35 return defineClass(name, b, 0, b.length); 36 } catch (IOException e) { 37 throw new ClassNotFoundException ("Class " + name + " not found in collection " + uri + "!", e); 38 } 39 } 40 } | Popular Tags |