1 36 package org.ungoverned.moduleloader.search; 37 38 import java.net.URL ; 39 40 import org.ungoverned.moduleloader.Module; 41 import org.ungoverned.moduleloader.ModuleManager; 42 import org.ungoverned.moduleloader.SearchPolicy; 43 44 64 public class ExhaustiveSearchPolicy implements SearchPolicy 65 { 66 private ModuleManager m_mgr = null; 67 68 79 public void setModuleManager(ModuleManager mgr) 80 throws IllegalStateException 81 { 82 if (m_mgr == null) 83 { 84 m_mgr = mgr; 85 } 86 else 87 { 88 throw new IllegalStateException ("Module manager is already initialized"); 89 } 90 } 91 92 100 public Class findClass(Module module, String name) 101 { 102 Module[] modules = m_mgr.getModules(); 103 for (int i = 0; i < modules.length; i++) 104 { 105 try { 106 Class clazz = modules[i].getClassLoader().searchForClass(name); 107 if (clazz != null) 108 { 109 return clazz; 110 } 111 } catch (Throwable th) { 112 } 113 } 114 115 return null; 116 } 117 118 127 public URL findResource(Module module, String name) 128 { 129 Module[] modules = m_mgr.getModules(); 130 for (int i = 0; i < modules.length; i++) 131 { 132 try { 133 URL url = modules[i].getClassLoader().searchForResource(name); 134 if (url != null) 135 { 136 return url; 137 } 138 } catch (Throwable th) { 139 } 140 } 141 142 return null; 143 } 144 } | Popular Tags |