javax.ws.rs.container
Interface ResourceContext


public interface ResourceContext

The resource context provides access to instances of resource classes.

This interface can be injected using the Context annotation.

The resource context can be utilized when instances of managed resource classes are to be returned by sub-resource locator methods. Such instances will be injected and managed within the declared scope just like instances of root resource classes.

The resource context can also be utilized when matching of URIs is required, for example when validating a URI sent in a request entity. Users should be aware that application functionality may be affected as the matching process will result in the construction or sharing of previously constructed resource classes that are in scope of the HTTP request, and the invocation of any matching sub-resource locator methods. However, no resource or sub-resource methods will be invoked.

Author:
Marek Potociar

Method Summary
<T> T
getResource(java.lang.Class<T> resourceClass)
          Get a resolved instance of a resource class.
 java.lang.Object matchResource(java.net.URI uri)
          Match a URI to a resource instance.
<T> T
matchResource(java.net.URI uri, java.lang.Class<T> type)
          Match a URI to a resource instance of a particular Java type.
 UriInfo matchUriInfo(java.net.URI uri)
          Match a URI to a URI information.
 

Method Detail

matchUriInfo

UriInfo matchUriInfo(java.net.URI uri)
                     throws java.lang.NullPointerException,
                            java.lang.IllegalArgumentException
Match a URI to a URI information.

If the URI is relative then the base URI of the application will be used to resolve the relative URI to an absolute URI. If the URI is absolute then it must match the base URI of the application, otherwise an IllegalArgumentException is thrown.

Parameters:
uri - the URI to be matched. Must not be null.
Returns:
the matched URI information, or null if the URI cannot be matched.
Throws:
java.lang.NullPointerException - if the uri parameter is null.
java.lang.IllegalArgumentException - if the uri parameter represents an absolute URI that does not match the base URI of the application.

matchResource

java.lang.Object matchResource(java.net.URI uri)
                               throws java.lang.NullPointerException,
                                      java.lang.IllegalArgumentException
Match a URI to a resource instance.

If the URI is relative then the base URI of the application will be used to resolve the relative URI to an absolute URI. If the URI is absolute then it must match the base URI of the application, otherwise an IllegalArgumentException is thrown.

Parameters:
uri - the URI to be matched. Must not be null.
Returns:
the matched resource instance, or null if the URI cannot be matched.
Throws:
java.lang.NullPointerException - if the uri parameter is null.
java.lang.IllegalArgumentException - if the uri parameter represents an absolute URI that does not match the base URI of the application.

matchResource

<T> T matchResource(java.net.URI uri,
                    java.lang.Class<T> type)
                throws java.lang.NullPointerException,
                       java.lang.IllegalArgumentException,
                       java.lang.ClassCastException
Match a URI to a resource instance of a particular Java type.

If the URI is relative then the base URI of the application will be used to resolve the relative URI to an absolute URI. If the URI is absolute then it must match the base URI of the application, otherwise an IllegalArgumentException is thrown.

Type Parameters:
T - the type of the resource class.
Parameters:
uri - the URI to be matched. Must not be null.
type - the resource class.
Returns:
the matched resource instance, or null if the URI cannot be matched.
Throws:
java.lang.NullPointerException - if the uri parameter is null.
java.lang.IllegalArgumentException - if the uri parameter represents an absolute URI that does not match the base URI of the application.
java.lang.ClassCastException - if the resource instance cannot be cast to type.

getResource

<T> T getResource(java.lang.Class<T> resourceClass)
Get a resolved instance of a resource class.

The resolved resource instance is properly initialized in the context of the current request processing scope. The scope of the resolved resource instance depends on the managing container. For resources managed by JAX-RS container the default scope is per-request.

Type Parameters:
T - the type of the resource class.
Parameters:
resourceClass - the resource class.
Returns:
an instance if it could be resolved, otherwise null.


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.