1 61 62 package org.apache.commons.discovery.jdk; 63 64 import java.util.Enumeration ; 65 import java.io.IOException ; 66 67 68 71 class JDK12Hooks extends JDKHooks { 72 79 public ClassLoader getThreadContextClassLoader() { 80 ClassLoader classLoader; 81 82 try { 83 classLoader = Thread.currentThread().getContextClassLoader(); 84 } catch (SecurityException e) { 85 96 classLoader = null; } 98 99 return classLoader; 101 } 102 103 110 public ClassLoader getSystemClassLoader() { 111 ClassLoader classLoader; 112 113 try { 114 classLoader = ClassLoader.getSystemClassLoader(); 115 } catch (SecurityException e) { 116 119 classLoader = null; } 121 122 return classLoader; 124 } 125 126 129 public Enumeration getResources(ClassLoader loader, 130 String resourceName) 131 throws IOException 132 { 133 156 157 final URL first = (URL)loader.getResource(resourceName); 158 final Enumeration rest = loader.getResources(resourceName); 159 160 return new Enumeration () { 161 private boolean firstDone = (first == null); 162 private URL next = getNext(); 163 164 public Object nextElement() { 165 URL o = next; 166 next = getNext(); 167 return o; 168 } 169 170 public boolean hasMoreElements() { 171 return next != null; 172 } 173 174 private URL getNext() { 175 URL n; 176 177 if (!firstDone) { 178 182 firstDone = true; 183 n = first; 184 } else { 185 193 n = null; 194 while (rest.hasMoreElements() && n == null) { 195 n = (URL)rest.nextElement(); 196 if (first != null && 197 n != null && 198 n.equals(first)) 199 { 200 n = null; 201 } 202 } 203 } 204 205 return n; 206 } 207 }; 208 } 209 } 210 | Popular Tags |