public class JerseyResourceContext extends Object implements ExtendedResourceContext
resource context
.Constructor and Description |
---|
JerseyResourceContext(Function<Class<?>,?> getOrCreateInstance,
Consumer<Object> injectInstance,
Consumer<Binding> registerBinding)
Creates a new JerseyResourceContext.
|
Modifier and Type | Method and Description |
---|---|
<T> void |
bindResource(Class<T> resourceClass)
Binds
resourceClass into HK2 context as singleton. |
<T> void |
bindResourceIfSingleton(T resource)
Binds
resourceClass into HK2 context as singleton. |
<T> T |
getResource(Class<T> resourceClass)
Get a resolved instance of a resource or sub-resource class.
|
ResourceModel |
getResourceModel()
Return
resource model from which the current jersey application is built. |
<T> T |
initResource(T resource)
Initialize the resource or sub-resource instance.
|
void |
setResourceModel(ResourceModel resourceModel)
Set the
resource mode of the application associated with this context. |
<T> void |
unsafeBindResource(Class<T> resourceClass,
ContractProvider providerModel)
Bind a resource class in a HK2 context.
|
void |
unsafeBindResource(Object resource,
ContractProvider providerModel)
Bind a resource instance in a InjectionManager.
|
public JerseyResourceContext(Function<Class<?>,?> getOrCreateInstance, Consumer<Object> injectInstance, Consumer<Binding> registerBinding)
getOrCreateInstance
- function to create or get existing instance.injectInstance
- consumer to inject instances into an unmanaged instance.registerBinding
- consumer to register a new binding into injection manager.public <T> T getResource(Class<T> resourceClass)
ResourceContext
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.
getResource
in interface ResourceContext
T
- the type of the resource class.resourceClass
- the resource class.null
.public <T> T initResource(T resource)
ResourceContext
initResource
in interface ResourceContext
T
- resource instance type.resource
- resource instance.public <T> void bindResource(Class<T> resourceClass)
resourceClass
into HK2 context as singleton.
The bound class is then cached internally so that any sub-sequent attempt to bind that class
as a singleton is silently ignored.T
- type of the resource class.resourceClass
- resource class that should be bound. If the class is not
annotated with Singleton annotation
it
will be ignored by this method.public <T> void bindResourceIfSingleton(T resource)
resourceClass
into HK2 context as singleton.
The bound class is then cached internally so that any sub-sequent attempt to bind that class
as a singleton is silently ignored.resource
- singleton resource instance that should be bound as singleton. If the class is not
annotated with Singleton annotation
it
will be ignored by this method.public void unsafeBindResource(Object resource, ContractProvider providerModel)
WARNING: This version of method is not synchronized as well as the cache is not checked for existing bindings before the resource is bound and cached.
resource
- resource instance to be bound.providerModel
- provider model for the resource class. If not null
, the class
wil be bound as a contract provider too.public <T> void unsafeBindResource(Class<T> resourceClass, ContractProvider providerModel)
WARNING: This version of method is not synchronized as well as the cache is not checked for existing bindings before the resource is bound and cached.
T
- resource class type.resourceClass
- resource class to be bound.providerModel
- provider model for the class. If not null
, the class
wil be bound as a contract provider too.public ResourceModel getResourceModel()
ExtendedResourceContext
resource model
from which the current jersey application is built.getResourceModel
in interface ExtendedResourceContext
resource processor
.public void setResourceModel(ResourceModel resourceModel)
resource mode
of the application associated with this context.resourceModel
- Resource model on which the application
is based.Copyright © 2007-2024, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.