1 17 package org.apache.geronimo.kernel.classloader; 18 19 import java.util.Enumeration ; 20 import java.util.Iterator ; 21 import java.util.Collection ; 22 import java.util.NoSuchElementException ; 23 24 27 public class ResourceEnumeration implements Enumeration { 28 private Iterator iterator; 29 private final String resourceName; 30 private Object next; 31 32 public ResourceEnumeration(Collection resourceLocations, String resourceName) { 33 this.iterator = resourceLocations.iterator(); 34 this.resourceName = resourceName; 35 } 36 37 public boolean hasMoreElements() { 38 fetchNext(); 39 return (next != null); 40 } 41 42 public Object nextElement() { 43 fetchNext(); 44 45 Object next = this.next; 47 this.next = null; 48 49 if (next == null) { 51 throw new NoSuchElementException (); 52 } 53 return next; 54 } 55 56 private void fetchNext() { 57 if (iterator == null) { 58 return; 59 } 60 if (next != null) { 61 return; 62 } 63 64 try { 65 while (iterator.hasNext()) { 66 ResourceLocation resourceLocation = (ResourceLocation) iterator.next(); 67 ResourceHandle resourceHandle = resourceLocation.getResourceHandle(resourceName); 68 if (resourceHandle != null) { 69 next = resourceHandle.getUrl(); 70 return; 71 } 72 } 73 iterator = null; 76 } catch (IllegalStateException e) { 77 iterator = null; 80 throw e; 81 } 82 } 83 } 84 | Popular Tags |