org.glassfish.jersey.server
Class ResourceConfig

java.lang.Object
  extended by javax.ws.rs.core.Application
      extended by org.glassfish.jersey.server.ResourceConfig

public class ResourceConfig
extends Application

The resource configuration for configuring a web application.

Author:
Paul Sandoz, Martin Matula (martin.matula at oracle.com), Michal Gajdos (michal.gajdos at oracle.com)

Constructor Summary
ResourceConfig()
          Create a new resource configuration without any custom properties or resource and provider classes.
ResourceConfig(Class<?>... classes)
          Create a new resource configuration initialized with a given set of resource/provider classes.
ResourceConfig(ResourceConfig original)
          Create a defensive resource configuration copy initialized with a given ResourceConfig.
ResourceConfig(Set<Class<?>> classes)
          Create a new resource configuration initialized with a given set of resource/provider classes.
 
Method Summary
 ResourceConfig addBinders(Binder... binders)
          Add HK2 binders to ResourceConfig.
 ResourceConfig addBinders(Set<Binder> binders)
          Add HK2 binders to ResourceConfig.
 ResourceConfig addClasses(Class<?>... classes)
          Add classes to ResourceConfig.
 ResourceConfig addClasses(Set<Class<?>> classes)
          Add classes to ResourceConfig.
 ResourceConfig addFinder(ResourceFinder resourceFinder)
          Add a ResourceFinder to ResourceConfig.
 ResourceConfig addProperties(Map<String,Object> properties)
          Add properties to ResourceConfig.
 ResourceConfig addResources(Resource... resources)
          Add new resource models to the configuration.
 ResourceConfig addResources(Set<Resource> resources)
          Add new resource models to the configuration.
 ResourceConfig addSingletons(Object... singletons)
          Add singletons to ResourceConfig.
 ResourceConfig addSingletons(Set<Object> singletons)
          Add singletons to ResourceConfig.
 ResourceConfig files(String... files)
          Adds array of file names to scan for providers.
static ResourceConfig forApplication(Application application)
          Returns a ResourceConfig instance for the supplied application.
static ResourceConfig forApplicationClass(Class<? extends Application> applicationClass)
          Returns a ResourceConfig instance wrapping the application of the supplied class.
static ResourceConfig forApplicationClass(Class<? extends Application> applicationClass, Set<Class<?>> defaultClasses)
          Returns a ResourceConfig instance wrapping the application of the supplied class.
 Application getApplication()
          Returns JAX-RS application corresponding with this ResourceConfig.
 Set<Class<?>> getClasses()
          Unmodifiable Set of current resource and provider classes.
 ClassLoader getClassLoader()
          Get resource and provider class loader.
 Collection<Feature> getFeatures()
           
 Map<String,Object> getProperties()
           
 Object getProperty(String name)
           
 Set<Class<?>> getProviderClasses()
           
 Set<Object> getProviderInstances()
           
 Set<Class<?>> getRegisteredClasses()
          Return classes which were registered by the user and not found by class path scanning (or any other scanning).
 Set<Resource> getResources()
          Get programmatically modeled resources.
 Set<Object> getSingletons()
          Unmodifiable Set of singletons.
 boolean isProperty(String name)
           
 ResourceConfig packages(String... packages)
          Adds array of package names which will be used to scan for providers.
 ResourceConfig register(Class<?> providerClass)
           
 ResourceConfig register(Class<?> providerClass, int bindingPriority)
           
<T> ResourceConfig
register(Class<T> providerClass, Class<? super T>... contracts)
           
<T> ResourceConfig
register(Class<T> providerClass, int bindingPriority, Class<? super T>... contracts)
           
 ResourceConfig register(Object provider)
           
<T> ResourceConfig
register(Object provider, Class<? super T>... contracts)
           
 ResourceConfig register(Object provider, int bindingPriority)
           
<T> ResourceConfig
register(Object provider, int bindingPriority, Class<? super T>... contracts)
           
 ResourceConfig setClassLoader(ClassLoader classLoader)
          Set ClassLoader which will be used for resource discovery.
 ResourceConfig setProperties(Map<String,?> properties)
           
 ResourceConfig setProperty(String name, Object value)
          Set a ResourceConfig property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceConfig

public ResourceConfig()
Create a new resource configuration without any custom properties or resource and provider classes.


ResourceConfig

public ResourceConfig(Set<Class<?>> classes)
Create a new resource configuration initialized with a given set of resource/provider classes.

Parameters:
classes - application-specific resource and/or provider classes.

ResourceConfig

public ResourceConfig(Class<?>... classes)
Create a new resource configuration initialized with a given set of resource/provider classes.

Parameters:
classes - application-specific resource and/or provider classes.

ResourceConfig

public ResourceConfig(ResourceConfig original)
Create a defensive resource configuration copy initialized with a given ResourceConfig.

Parameters:
original - resource configuration to create a defensive copy from.
Method Detail

forApplication

public static ResourceConfig forApplication(Application application)
Returns a ResourceConfig instance for the supplied application. If the application is an instance of ResourceConfig the method returns defensive copy of the resource config. Otherwise it creates a new ResourceConfig from the application.

Parameters:
application - Application to provide the ResourceConfig instance for.
Returns:
ResourceConfig instance for the supplied application.

forApplicationClass

public static ResourceConfig forApplicationClass(Class<? extends Application> applicationClass)
Returns a ResourceConfig instance wrapping the application of the supplied class.

Parameters:
applicationClass - Class representing a JAX-RS application.
Returns:
ResourceConfig wrapping the JAX-RS application defined by the supplied class.

forApplicationClass

public static ResourceConfig forApplicationClass(Class<? extends Application> applicationClass,
                                                 Set<Class<?>> defaultClasses)
Returns a ResourceConfig instance wrapping the application of the supplied class. This method provides an option of supplying the set of classes that should be returned from getClasses() method if the application defined by the supplied application class returns empty sets from .Application#getClasses() and Application.getSingletons() methods.

Parameters:
applicationClass - Class representing a JAX-RS application.
defaultClasses - Default set of classes that should be returned from getClasses() if the underlying application does not provide any classes and singletons.
Returns:
ResourceConfig wrapping the JAX-RS application defined by the supplied class.

addClasses

public final ResourceConfig addClasses(Set<Class<?>> classes)
Add classes to ResourceConfig.

Parameters:
classes - list of classes to add.
Returns:
updated resource configuration instance.

addClasses

public final ResourceConfig addClasses(Class<?>... classes)
Add classes to ResourceConfig.

Parameters:
classes - Set of classes to add.
Returns:
updated resource configuration instance.

addSingletons

public final ResourceConfig addSingletons(Set<Object> singletons)
Add singletons to ResourceConfig.

Parameters:
singletons - Set of instances to add.
Returns:
updated resource configuration instance.

addSingletons

public final ResourceConfig addSingletons(Object... singletons)
Add singletons to ResourceConfig.

Parameters:
singletons - list of instances to add.
Returns:
updated resource configuration instance.

addResources

public final ResourceConfig addResources(Resource... resources)
Add new resource models to the configuration.

Parameters:
resources - resource models.
Returns:
updated resource configuration.

addResources

public final ResourceConfig addResources(Set<Resource> resources)
Add new resource models to the configuration.

Parameters:
resources - resource models.
Returns:
updated resource configuration.

setProperty

public ResourceConfig setProperty(String name,
                                  Object value)
Set a ResourceConfig property.

Parameters:
name - property name.
value - property value.
Returns:
updated resource configuration instance.

setProperties

public ResourceConfig setProperties(Map<String,?> properties)

getFeatures

public Collection<Feature> getFeatures()

getProviderClasses

public Set<Class<?>> getProviderClasses()

getProviderInstances

public Set<Object> getProviderInstances()

register

public ResourceConfig register(Class<?> providerClass)

register

public ResourceConfig register(Object provider)

register

public ResourceConfig register(Class<?> providerClass,
                               int bindingPriority)

register

public <T> ResourceConfig register(Class<T> providerClass,
                                   Class<? super T>... contracts)

register

public <T> ResourceConfig register(Class<T> providerClass,
                                   int bindingPriority,
                                   Class<? super T>... contracts)

register

public ResourceConfig register(Object provider,
                               int bindingPriority)

register

public <T> ResourceConfig register(Object provider,
                                   Class<? super T>... contracts)

register

public <T> ResourceConfig register(Object provider,
                                   int bindingPriority,
                                   Class<? super T>... contracts)

addProperties

public final ResourceConfig addProperties(Map<String,Object> properties)
Add properties to ResourceConfig. If any of the added properties exists already, he values of the existing properties will be replaced with new values.

Parameters:
properties - properties to add.
Returns:
updated resource configuration instance.

addFinder

public final ResourceConfig addFinder(ResourceFinder resourceFinder)
Add a ResourceFinder to ResourceConfig.

Parameters:
resourceFinder - ResourceFinder
Returns:
updated resource configuration instance.

addBinders

public final ResourceConfig addBinders(Set<Binder> binders)
Add HK2 binders to ResourceConfig. These binders will be added when creating ServiceLocator instance.

Parameters:
binders - custom binders.
Returns:
updated resource configuration instance.

addBinders

public final ResourceConfig addBinders(Binder... binders)
Add HK2 binders to ResourceConfig. These binders will be added when creating ServiceLocator instance.

Parameters:
binders - custom binders.
Returns:
updated resource configuration instance.

setClassLoader

public final ResourceConfig setClassLoader(ClassLoader classLoader)
Set ClassLoader which will be used for resource discovery.

Parameters:
classLoader - provided ClassLoader.
Returns:
updated resource configuration instance.

packages

public final ResourceConfig packages(String... packages)
Adds array of package names which will be used to scan for providers.

Parameters:
packages - array of package names
Returns:
updated resource configuration instance.

files

public final ResourceConfig files(String... files)
Adds array of file names to scan for providers.

Parameters:
files - array of file names.
Returns:
updated resource configuration instance.

getClasses

public final Set<Class<?>> getClasses()
Unmodifiable Set of current resource and provider classes.

Overrides:
getClasses in class Application
Returns:
Unmodifiable Set of resource and provider classes.

getRegisteredClasses

public Set<Class<?>> getRegisteredClasses()
Return classes which were registered by the user and not found by class path scanning (or any other scanning).

Returns:
Set of classes registered by the user.

getSingletons

public final Set<Object> getSingletons()
Unmodifiable Set of singletons.

Overrides:
getSingletons in class Application
Returns:
Unmodifiable Set of singletons.

getResources

public final Set<Resource> getResources()
Get programmatically modeled resources.

Returns:
programmatically modeled resources.

getClassLoader

public final ClassLoader getClassLoader()
Get resource and provider class loader.

Returns:
class loader to be used when looking up the resource classes and providers.

getProperties

public final Map<String,Object> getProperties()

getProperty

public final Object getProperty(String name)

isProperty

public final boolean isProperty(String name)

getApplication

public final Application getApplication()
Returns JAX-RS application corresponding with this ResourceConfig.

Returns:
JAX-RS application corresponding with this ResourceConfig.


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