01: package org.andromda.core.common;
02:
03: import java.net.URL;
04:
05: import java.util.ArrayList;
06: import java.util.Collection;
07: import java.util.Enumeration;
08:
09: /**
10: * Finds and loads file resources from the current classpath.
11: *
12: * @author Chad Brandon
13: */
14: public class ResourceFinder {
15: /**
16: * Returns a URL[] containing the URL of each resource and the File which represents the library the resource was
17: * found in.
18: *
19: * @param resource the resource to find
20: * @return a <code>array of resource URLs<code>
21: */
22: public static URL[] findResources(final String resource) {
23: ExceptionUtils.checkEmpty("resource", resource);
24: try {
25: final Collection resources = new ArrayList();
26: for (final Enumeration enumeration = ClassUtils
27: .getClassLoader().getResources(resource); enumeration
28: .hasMoreElements();) {
29: resources.add(enumeration.nextElement());
30: }
31: return (URL[]) resources.toArray(new URL[0]);
32: } catch (final Exception exception) {
33: throw new ResourceFinderException(exception);
34: }
35: }
36: }
|