1 57 58 package org.apache.commons.discovery.ant; 59 60 import java.util.Vector ; 61 62 import org.apache.commons.discovery.Resource; 63 import org.apache.commons.discovery.jdk.JDKHooks; 64 import org.apache.commons.discovery.listeners.GatherResourcesListener; 65 import org.apache.commons.discovery.resource.DiscoverResources; 66 67 68 76 public class ServiceDiscoveryTask 77 { 78 String name; 79 int debug=0; 80 String [] drivers = null; 81 82 public void setServiceName(String name ) { 83 this.name=name; 84 } 85 86 public void setDebug(int i) { 87 this.debug=debug; 88 } 89 90 public String [] getServiceInfo() { 91 return drivers; 92 } 93 94 public void execute() throws Exception { 95 System.out.println("XXX "); 96 97 GatherResourcesListener listener = new GatherResourcesListener(); 98 DiscoverResources disc = new DiscoverResources(); 99 disc.addClassLoader( JDKHooks.getJDKHooks().getThreadContextClassLoader() ); 100 disc.addClassLoader( this.getClass().getClassLoader() ); 101 disc.setListener(listener); 102 disc.find(name); 103 104 Vector vector = listener.getResources(); 105 drivers = new String [vector.size()]; 106 for (int i = 0; i < vector.size(); i++) { 107 drivers[i] = ((Resource)vector.get(i)).getName(); 108 if( debug > 0 ) { 109 System.out.println("Found " + drivers[i]); 110 } 111 } 112 } 113 114 } 115 | Popular Tags |