1 61 62 package org.apache.commons.discovery.tools; 63 64 import org.apache.commons.discovery.ResourceClass; 65 import org.apache.commons.discovery.ResourceClassListener; 66 import org.apache.commons.discovery.resource.ClassLoaders; 67 import org.apache.commons.discovery.resource.classes.DiscoverClasses; 68 69 70 78 public class DefaultClassHolder { 79 private Class defaultClass; 80 private final String defaultName; 81 82 public DefaultClassHolder(Class defaultClass) { 83 this.defaultClass = defaultClass; 84 this.defaultName = defaultClass.getName(); 85 } 86 87 public DefaultClassHolder(String defaultName) { 88 this.defaultClass = null; 89 this.defaultName = defaultName; 90 } 91 92 100 public Class getDefaultClass(SPInterface spi, ClassLoaders loaders) { 101 if (defaultClass == null) { 102 ResourceClassListener listener = 103 new ResourceClassListener() { 104 public boolean found(ResourceClass resource) { 105 defaultClass = resource.loadClass(); 106 return false; } 108 }; 109 DiscoverClasses classDiscovery = new DiscoverClasses(loaders); 110 classDiscovery.setListener(listener); 111 classDiscovery.find(getDefaultName()); 112 } 113 114 if (defaultClass != null) { 115 spi.verifyAncestory(defaultClass); 116 } 117 118 return defaultClass; 119 } 120 121 public String getDefaultName() { 122 return defaultName; 123 } 124 } 125 | Popular Tags |