ResourceHandler.java
01 /*
02  * Copyright 2009-2012 the original author or authors.
03  *
04  * Licensed under the Apache License, Version 2.0 (the "License");
05  * you may not use this file except in compliance with the License.
06  * You may obtain a copy of the License at
07  *
08  *      http://www.apache.org/licenses/LICENSE-2.0
09  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package griffon.core;
18 
19 import java.io.InputStream;
20 import java.net.URL;
21 import java.util.List;
22 
23 /**
24  * Indicates a type that knows how to load resources from the classpath.
25  *
26  @author Andres Almiray
27  @since 0.9.5
28  */
29 public interface ResourceHandler {
30     /**
31      * Finds the resource with the given name.  A resource is some data
32      * (images, audio, text, etc) that can be accessed by class code in a way
33      * that is independent of the location of the code.
34      <p/>
35      <p> The name of a resource is a '<tt>/</tt>'-separated path name that
36      * identifies the resource.
37      *
38      @param name The resource name
39      @return <tt>URL</tt> object for reading the resource, or
40      *         <tt>null</tt> if the resource could not be found.
41      */
42     URL getResourceAsURL(String name);
43 
44     /**
45      * Returns an input stream for reading the specified resource.
46      *
47      @param name The resource name
48      @return An input stream for reading the resource, or <tt>null</tt>
49      *         if the resource could not be found
50      */
51     InputStream getResourceAsStream(String name);
52 
53     /**
54      * Finds all the resources with the given name. A resource is some data
55      * (images, audio, text, etc) that can be accessed by class code in a way
56      * that is independent of the location of the code.
57      <p/>
58      <p>The name of a resource is a <tt>/</tt>-separated path name that
59      * identifies the resource.
60      *
61      @param name The resource name
62      @return An java.util.List of {@link java.net.URL <tt>URL</tt>} objects for
63      *         the resource.  If no resources could  be found, the list
64      *         will be empty.  Resources that the class loader doesn't have
65      *         access to will not be in the list.
66      */
67     List<URL> getResources(String name);
68 }