| 
01 /*02  * Copyright 2008-2015 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 package griffon.core.resources;
 17
 18 import javax.annotation.Nonnull;
 19 import javax.annotation.Nullable;
 20 import java.io.InputStream;
 21 import java.net.URL;
 22 import java.util.List;
 23
 24 /**
 25  * Indicates a type that knows how to load resources from the classpath.
 26  *
 27  * @author Andres Almiray
 28  * @since 2.0.0
 29  */
 30 public interface ResourceHandler {
 31     /**
 32      * Finds the resource with the given name.  A resource is some data
 33      * (images, audio, text, etc) that can be accessed by class code in a way
 34      * that is independent of the location of the code.
 35      * <p/>
 36      * <p> The name of a resource is a '<tt>/</tt>'-separated path name that
 37      * identifies the resource.
 38      *
 39      * @param name The resource name
 40      * @return A <tt>URL</tt> object for reading the resource, or
 41      *         <tt>null</tt> if the resource could not be found.
 42      */
 43     @Nullable
 44     URL getResourceAsURL(@Nonnull String name);
 45
 46     /**
 47      * Returns an input stream for reading the specified resource.
 48      *
 49      * @param name The resource name
 50      * @return An input stream for reading the resource, or <tt>null</tt>
 51      *         if the resource could not be found
 52      */
 53     @Nullable
 54     InputStream getResourceAsStream(@Nonnull String name);
 55
 56     /**
 57      * Finds all the resources with the given name. A resource is some data
 58      * (images, audio, text, etc) that can be accessed by class code in a way
 59      * that is independent of the location of the code.
 60      * <p/>
 61      * <p>The name of a resource is a <tt>/</tt>-separated path name that
 62      * identifies the resource.
 63      *
 64      * @param name The resource name
 65      * @return An java.util.List of {@link java.net.URL <tt>URL</tt>} objects for
 66      *         the resource.  If no resources could  be found, the list
 67      *         will be empty.  Resources that the class loader doesn't have
 68      *         access to will not be in the list.
 69      */
 70     @Nullable
 71     List<URL> getResources(@Nonnull String name);
 72
 73     /**
 74      * Returns the classloader used to resolve resources.
 75      *
 76      * @return a classloader instance
 77      */
 78     @Nonnull
 79     ClassLoader classloader();
 80 }
 |