1 57 58 package org.apache.commons.discovery; 59 60 import java.net.URL ; 61 62 import org.apache.commons.discovery.log.DiscoveryLogFactory; 63 import org.apache.commons.logging.Log; 64 65 66 75 public class ResourceClass extends Resource 76 { 77 private static Log log = DiscoveryLogFactory.newLog(ResourceClass.class); 78 public static void setLog(Log _log) { 79 log = _log; 80 } 81 protected Class resourceClass; 82 83 public ResourceClass(Class resourceClass, URL resource) { 84 super(resourceClass.getName(), resource, resourceClass.getClassLoader()); 85 this.resourceClass = resourceClass; 86 } 87 88 public ResourceClass(String resourceName, URL resource, ClassLoader loader) { 89 super(resourceName, resource, loader); 90 this.resourceClass = resourceClass; 91 } 92 93 97 public Class loadClass() { 98 if (resourceClass == null && getClassLoader() != null) { 99 if (log.isDebugEnabled()) 100 log.debug("loadClass: Loading class '" + getName() + "' with " + getClassLoader()); 101 102 try { 103 resourceClass = getClassLoader().loadClass(getName()); 104 } catch (ClassNotFoundException e) { 105 resourceClass = null; 106 } 107 } 108 return resourceClass; 109 } 110 111 public String toString() { 112 return "ResourceClass[name='" + getName() + "', url='" + getResource() + "', loader='" + getClassLoader() + "']"; 113 } 114 } 115 | Popular Tags |