Class JerseyResourceContext
- java.lang.Object
-
- org.glassfish.jersey.server.internal.JerseyResourceContext
-
- All Implemented Interfaces:
ResourceContext,ExtendedResourceContext
public class JerseyResourceContext extends Object implements ExtendedResourceContext
Jersey implementation of JAX-RSresource context.- Author:
- Marek Potociar
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> voidbindResource(Class<T> resourceClass)BindsresourceClassinto HK2 context as singleton.<T> voidbindResourceIfSingleton(T resource)BindsresourceClassinto HK2 context as singleton.<T> TgetResource(Class<T> resourceClass)Get a resolved instance of a resource or sub-resource class.ResourceModelgetResourceModel()Returnresource modelfrom which the current jersey application is built.<T> TinitResource(T resource)Initialize the resource or sub-resource instance.voidsetResourceModel(ResourceModel resourceModel)Set theresource modeof the application associated with this context.<T> voidunsafeBindResource(Class<T> resourceClass, ContractProvider providerModel)Bind a resource class in a HK2 context.voidunsafeBindResource(Object resource, ContractProvider providerModel)Bind a resource instance in a InjectionManager.
-
-
-
Constructor Detail
-
JerseyResourceContext
public JerseyResourceContext(Function<Class<?>,?> getOrCreateInstance, Consumer<Object> injectInstance, Consumer<org.glassfish.jersey.internal.inject.Binding> registerBinding)
Creates a new JerseyResourceContext.- Parameters:
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.
-
-
Method Detail
-
getResource
public <T> T getResource(Class<T> resourceClass)
Description copied from interface:ResourceContextGet a resolved instance of a resource or sub-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.
- Specified by:
getResourcein interfaceResourceContext- Type Parameters:
T- the type of the resource class.- Parameters:
resourceClass- the resource class.- Returns:
- an instance if it could be resolved, otherwise
null.
-
initResource
public <T> T initResource(T resource)
Description copied from interface:ResourceContextInitialize the resource or sub-resource instance. All JAX-RS injectable fields in the resource instance will be properly initialized in the context of the current request processing scope.- Specified by:
initResourcein interfaceResourceContext- Type Parameters:
T- resource instance type.- Parameters:
resource- resource instance.- Returns:
- initialized (same) resource instance.
-
bindResource
public <T> void bindResource(Class<T> resourceClass)
BindsresourceClassinto 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.- Type Parameters:
T- type of the resource class.- Parameters:
resourceClass- resource class that should be bound. If the class is not annotated withSingleton annotationit will be ignored by this method.
-
bindResourceIfSingleton
public <T> void bindResourceIfSingleton(T resource)
BindsresourceClassinto 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.- Parameters:
resource- singleton resource instance that should be bound as singleton. If the class is not annotated withSingleton annotationit will be ignored by this method.
-
unsafeBindResource
public void unsafeBindResource(Object resource, ContractProvider providerModel)
Bind a resource instance in a InjectionManager. The bound resource instance is internally cached to make sure any sub-sequent attempts to service the class are silently ignored.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.
- Parameters:
resource- resource instance to be bound.providerModel- provider model for the resource class. If notnull, the class wil be bound as a contract provider too.
-
unsafeBindResource
public <T> void unsafeBindResource(Class<T> resourceClass, ContractProvider providerModel)
Bind a resource class in a HK2 context. The bound resource class is internally cached to make sure any sub-sequent attempts to bind the class are silently ignored.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.
- Type Parameters:
T- resource class type.- Parameters:
resourceClass- resource class to be bound.providerModel- provider model for the class. If notnull, the class wil be bound as a contract provider too.
-
getResourceModel
public ResourceModel getResourceModel()
Description copied from interface:ExtendedResourceContextReturnresource modelfrom which the current jersey application is built.- Specified by:
getResourceModelin interfaceExtendedResourceContext- Returns:
- Resource model with all resources including resources created
by
resource processor.
-
setResourceModel
public void setResourceModel(ResourceModel resourceModel)
Set theresource modeof the application associated with this context.- Parameters:
resourceModel- Resource model on which theapplicationis based.
-
-