org.jboss.solder.resourceLoader
Class ResourceProvider

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

@Veto
public class ResourceProvider
extends java.lang.Object
implements java.io.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
 java.util.Properties loadPropertiesBundle(java.lang.String name)
           Load a properties bundle.
 java.util.Collection<java.util.Properties> loadPropertiesBundles(java.lang.String name)
           Load all properties bundles known to the resource loader by name.
 java.net.URL loadResource(java.lang.String name)
           Load a resource.
 java.util.Collection<java.net.URL> loadResources(java.lang.String name)
           Load all resources known to the resource loader by name.
 java.util.Collection<java.io.InputStream> loadResourcesStreams(java.lang.String name)
           Load all resources known to the resource loader by name.
 java.io.InputStream loadResourceStream(java.lang.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 java.io.InputStream loadResourceStream(java.lang.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:
java.lang.RuntimeException - if an error occurs loading the resource

loadResourcesStreams

public java.util.Collection<java.io.InputStream> loadResourcesStreams(java.lang.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:
java.lang.RuntimeException - if an error occurs loading the resource

loadResource

public java.net.URL loadResource(java.lang.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:
java.lang.RuntimeException - if an error occurs loading the resource

loadResources

public java.util.Collection<java.net.URL> loadResources(java.lang.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:
java.lang.RuntimeException - if an error occurs loading the resource

loadPropertiesBundle

public java.util.Properties loadPropertiesBundle(java.lang.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:
java.lang.RuntimeException - if an error occurs loading the resource

loadPropertiesBundles

public java.util.Collection<java.util.Properties> loadPropertiesBundles(java.lang.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:
java.lang.RuntimeException - if an error occurs loading the properties bundle


Copyright © 2008-2012 Seam Framework. All Rights Reserved.