org.jboss.solder.resourceLoader
Class ResourceProvider

java.lang.Object
  extended by org.jboss.solder.resourceLoader.ResourceProvider
All Implemented Interfaces:
Serializable

@Veto
public class ResourceProvider
extends Object
implements Serializable

The ResourceProvider allows dynamic loading of managed resources. For example:

 @Inject
 void readXml(ResourceProvider provider, String fileName)
 {
    InputStream webXml = provider.loadResourceStream(fileName);
 }
 

If you know the name of the resource you are loading at development time you can inject it directly using the @Resource qualifier.

If a input stream is loaded, it will be automatically closed when the InputStream goes out of scope. If a URL is used to create an input stream, the application is responsible for closing it. For this reason it is recommended that managed input streams are used where possible.

Author:
Pete Muir
See Also:
Resource, Serialized Form

Method Summary
 Properties loadPropertiesBundle(String name)
           Load a properties bundle.
 Collection<Properties> loadPropertiesBundles(String name)
           Load all properties bundles known to the resource loader by name.
 URL loadResource(String name)
           Load a resource.
 Collection<URL> loadResources(String name)
           Load all resources known to the resource loader by name.
 Collection<InputStream> loadResourcesStreams(String name)
           Load all resources known to the resource loader by name.
 InputStream loadResourceStream(String name)
           Load a resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadResourceStream

public InputStream loadResourceStream(String name)

Load a resource.

The resource loaders will be searched in precedence order, the first result found being returned. The default search order is:

However extensions may extend this list.

Parameters:
name - the resource to load
Returns:
an input stream providing access to the resource, or null if no resource can be loaded
Throws:
RuntimeException - if an error occurs loading the resource

loadResourcesStreams

public Collection<InputStream> loadResourcesStreams(String name)

Load all resources known to the resource loader by name.

By default, Solder will search:

However extensions may extend this list.

Parameters:
name - the resource to load
Returns:
a collection of input streams pointing to the resources, or an empty collection if no resources are found
Throws:
RuntimeException - if an error occurs loading the resource

loadResource

public URL loadResource(String name)

Load a resource.

The resource loaders will be searched in precedence order, the first result found being returned. The default search order is:

However extensions may extend this list.

Parameters:
name - the resource to load
Returns:
a URL pointing to the resource, or null if no resource can be loaded
Throws:
RuntimeException - if an error occurs loading the resource

loadResources

public Collection<URL> loadResources(String name)

Load all resources known to the resource loader by name.

By default, Solder will search:

However extensions may extend this list.

Parameters:
name - the resource to load
Returns:
a collection of URLs pointing to the resources, or an empty collection if no resources are found
Throws:
RuntimeException - if an error occurs loading the resource

loadPropertiesBundle

public Properties loadPropertiesBundle(String name)

Load a properties bundle.

The resource loaders will be searched in precedence order, the first result found being returned. The default search order is:

However extensions may extend this list.

Parameters:
name - the name of the properties bundle to load
Returns:
a set of properties, or an empty set if no properties bundle can be loaded
Throws:
RuntimeException - if an error occurs loading the resource

loadPropertiesBundles

public Collection<Properties> loadPropertiesBundles(String name)

Load all properties bundles known to the resource loader by name.

By default, Solder will search:

However extensions may extend this list.

Parameters:
name - the name of the properties bundle to load
Returns:
a collection of properties bundles, or an empty collection if no resources are found
Throws:
RuntimeException - if an error occurs loading the properties bundle


Copyright © 2011 Seam Framework. All Rights Reserved.