View Javadoc
1   package org.andromda.core.common;
2   
3   import java.net.URL;
4   import java.util.ArrayList;
5   import java.util.Collection;
6   import java.util.Enumeration;
7   
8   /**
9    * Finds and loads file resources from the current classpath.
10   *
11   * @author Chad Brandon
12   */
13  public class ResourceFinder
14  {
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      {
24          ExceptionUtils.checkEmpty("resource", resource);
25          try
26          {
27              final Collection<URL> resources = new ArrayList<URL>();
28              for (final Enumeration<URL> enumeration = ClassUtils.getClassLoader().getResources(resource);
29                   enumeration.hasMoreElements();)
30              {
31                  resources.add(enumeration.nextElement());
32              }
33  
34              return resources.toArray(new URL[resources.size()]);
35          }
36          catch (final Exception exception)
37          {
38              throw new ResourceFinderException(exception);
39          }
40      }
41  }