com.sun.jersey.api.core
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 be utilized when matching of URIs are required, for example when validating URIs sent in a request entity. Note 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 matching sub-resource locator methods. No resource methods wll be invoked.

Author:
Martin Grotzke, [email protected]

Method Summary
<T> T
getResource(java.lang.Class<T> c)
          Provides an instance of the given resource class.
 java.lang.Object matchResource(java.net.URI u)
          Match a URI to a resource instance.
<T> T
matchResource(java.net.URI u, java.lang.Class<T> c)
          Match a URI to a resource instance.
 ExtendedUriInfo matchUriInfo(java.net.URI u)
          Match a URI to URI information.
 

Method Detail

matchUriInfo

ExtendedUriInfo matchUriInfo(java.net.URI u)
                             throws ContainerException
Match a URI to 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 be relative to the base URI of the application.

Parameters:
u - the URI.
Returns:
the URI information, otherwise null if the URI cannot be matched.
Throws:
ContainerException - if there is an error when matching.

matchResource

java.lang.Object matchResource(java.net.URI u)
                               throws ContainerException
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 be relative to the base URI of the application.

Parameters:
u - the URI.
Returns:
the resource instance, otherwise null if the URI cannot be matched.
Throws:
ContainerException - if there is an error when matching.

matchResource

<T> T matchResource(java.net.URI u,
                    java.lang.Class<T> c)
                throws ContainerException,
                       java.lang.ClassCastException
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 be relative to the base URI of the application.

Type Parameters:
T - the type of the resource.
Parameters:
u - the URI.
c - the resource class.
Returns:
the resource instance, otherwise null if the URI cannot be matched.
Throws:
ContainerException - if there is an error when matching.
java.lang.ClassCastException - if the resource instance cannot be cast to c.

getResource

<T> T getResource(java.lang.Class<T> c)
              throws ContainerException
Provides an instance of the given resource class.

Type Parameters:
T - the type of the resource class
Parameters:
c - the resource class
Returns:
an instance if it could be resolved, otherwise null.
Throws:
ContainerException - if the resource class cannot be found.


Copyright © 2011 Oracle Corporation. All Rights Reserved.