1 57 58 package org.apache.commons.discovery.resource.classes; 59 60 import java.net.URL ; 61 import java.util.Vector ; 62 63 import org.apache.commons.discovery.ResourceClass; 64 import org.apache.commons.discovery.ResourceClassDiscover; 65 import org.apache.commons.discovery.ResourceNameListener; 66 import org.apache.commons.discovery.log.DiscoveryLogFactory; 67 import org.apache.commons.discovery.resource.ClassLoaders; 68 import org.apache.commons.logging.Log; 69 70 71 79 public class DiscoverClasses extends ResourceClassDiscoverImpl 80 implements ResourceClassDiscover, ResourceNameListener 81 { 82 private static Log log = DiscoveryLogFactory.newLog(DiscoverClasses.class); 83 public static void setLog(Log _log) { 84 log = _log; 85 } 86 87 89 public DiscoverClasses() { 90 super(); 91 } 92 93 95 public DiscoverClasses(ClassLoaders classLoaders) { 96 super(classLoaders); 97 } 98 99 public boolean find(String className) { 100 final String resourceName = className.replace('.','/') + ".class"; 101 102 if (log.isDebugEnabled()) 103 log.debug("find: className='" + className + "'"); 104 105 Vector history = new Vector (); 106 107 for (int idx = 0; idx < getClassLoaders().size(); idx++) { 108 ClassLoader loader = getClassLoaders().get(idx); 109 URL url = loader.getResource(resourceName); 110 if (url != null) { 111 if (!history.contains(url)) { 112 history.addElement(url); 113 if (!notifyListener(new ResourceClass(className, 114 url, 115 loader))) 116 return false; 117 } else { 118 if (log.isDebugEnabled()) 119 log.debug("find: duplicate URL='" + url + "'"); 120 } 121 } else { 122 if (log.isDebugEnabled()) 123 log.debug("find: '" + resourceName + "' not found with loader: " + loader); 124 } 125 } 126 127 return true; 128 } 129 130 public boolean found(String className) { 131 return find(className); 132 } 133 } 134 | Popular Tags |