org.glassfish.jersey.server
Class ResourceConfig

java.lang.Object
  extended by javax.ws.rs.core.Application
      extended by org.glassfish.jersey.server.ResourceConfig
All Implemented Interfaces:
FeaturesAndProperties

public class ResourceConfig
extends Application
implements FeaturesAndProperties

The resource configuration for configuring a web application.

Author:
Paul Sandoz, Martin Matula (martin.matula at oracle.com)

Constructor Summary
ResourceConfig()
          Create a new resource configuration without any custom properties or resource and provider classes.
ResourceConfig(java.lang.Class<?>... classes)
          Create a new resource configuration initialized with a given set of resource/provider classes.
ResourceConfig(java.util.Set<java.lang.Class<?>> classes)
          Create a new resource configuration initialized with a given set of resource/provider classes.
 
Method Summary
 ResourceConfig addClasses(java.lang.Class<?>... classes)
          Add classes to ResourceConfig.
 ResourceConfig addClasses(java.util.Set<java.lang.Class<?>> classes)
          Add classes to ResourceConfig.
 ResourceConfig addFinder(ResourceFinder resourceFinder)
          Add a ResourceFinder to ResourceConfig.
 ResourceConfig addModules(org.glassfish.hk2.Module... modules)
          Add HK2 modules to ResourceConfig.
 ResourceConfig addModules(java.util.Set<org.glassfish.hk2.Module> modules)
          Add HK2 modules to ResourceConfig.
 ResourceConfig addProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
          Add properties to ResourceConfig.
 ResourceConfig addResources(Resource... resources)
          Add new resource models to the configuration.
 ResourceConfig addResources(java.util.Set<Resource> resources)
          Add new resource models to the configuration.
 ResourceConfig addSingletons(java.lang.Object... singletons)
          Add singletons to ResourceConfig.
 ResourceConfig addSingletons(java.util.Set<java.lang.Object> singletons)
          Add singletons to ResourceConfig.
 ResourceConfig files(java.lang.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(java.lang.Class<? extends Application> applicationClass)
          Returns a ResourceConfig instance wrapping the application of the supplied class.
static ResourceConfig forApplicationClass(java.lang.Class<? extends Application> applicationClass, java.util.Set<java.lang.Class<?>> defaultClasses)
          Returns a ResourceConfig instance wrapping the application of the supplied class.
 Application getApplication()
          Returns JAX-RS application corresponding with this ResourceConfig.
 java.util.Set<java.lang.Class<?>> getClasses()
          Unmodifiable Set of current resource and provider classes.
 java.lang.ClassLoader getClassLoader()
          Get resource and provider class loader.
static java.lang.String[] getElements(java.lang.String[] elements)
          Get a canonical array of String elements from a String array where each entry may contain zero or more elements separated by ';'.
static java.lang.String[] getElements(java.lang.String[] elements, java.lang.String delimiters)
          Get a canonical array of String elements from a String array where each entry may contain zero or more elements separated by characters in delimiters string.
static java.lang.String[] getElements(java.lang.String elements, java.lang.String delimiters)
          Get a canonical array of String elements from a String that may contain zero or more elements separated by characters in delimiters string.
 java.util.Map<java.lang.String,java.lang.Object> getProperties()
           
 java.lang.Object getProperty(java.lang.String name)
           
 java.util.Set<Resource> getResources()
          Get programmatically modeled resources.
 java.util.Set<java.lang.Object> getSingletons()
          Unmodifiable Set of singletons.
 boolean isProperty(java.lang.String name)
           
 ResourceConfig packages(java.lang.String... packages)
          Adds array of package names which will be used to scan for providers.
 ResourceConfig setClassLoader(java.lang.ClassLoader classLoader)
          Set ClassLoader which will be used for resource discovery.
 ResourceConfig setProperty(java.lang.String name, java.lang.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(java.util.Set<java.lang.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(java.lang.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.
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 simply returns the application. Otherwise it creates a new ResourceConfig wrapping the application.

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

forApplicationClass

public static ResourceConfig forApplicationClass(java.lang.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(java.lang.Class<? extends Application> applicationClass,
                                                 java.util.Set<java.lang.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(java.util.Set<java.lang.Class<?>> classes)
Add classes to ResourceConfig.

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

addClasses

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

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

addSingletons

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

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

addSingletons

public final ResourceConfig addSingletons(java.lang.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(java.util.Set<Resource> resources)
Add new resource models to the configuration.

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

setProperty

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

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

addProperties

public final ResourceConfig addProperties(java.util.Map<java.lang.String,java.lang.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.

addModules

public final ResourceConfig addModules(java.util.Set<org.glassfish.hk2.Module> modules)
Add HK2 modules to ResourceConfig. These modules will be added when creating Services instance.

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

addModules

public final ResourceConfig addModules(org.glassfish.hk2.Module... modules)
Add HK2 modules to ResourceConfig. These modules will be added when creating Services instance.

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

setClassLoader

public final ResourceConfig setClassLoader(java.lang.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(java.lang.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(java.lang.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 java.util.Set<java.lang.Class<?>> getClasses()
Unmodifiable Set of current resource and provider classes.

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

getSingletons

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

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

getResources

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

Returns:
programmatically modeled resources.

getClassLoader

public final java.lang.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 java.util.Map<java.lang.String,java.lang.Object> getProperties()
Specified by:
getProperties in interface FeaturesAndProperties

getProperty

public final java.lang.Object getProperty(java.lang.String name)
Specified by:
getProperty in interface FeaturesAndProperties

isProperty

public final boolean isProperty(java.lang.String name)
Specified by:
isProperty in interface FeaturesAndProperties

getApplication

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

Returns:
JAX-RS application corresponding with this ResourceConfig.

getElements

public static java.lang.String[] getElements(java.lang.String[] elements)
Get a canonical array of String elements from a String array where each entry may contain zero or more elements separated by ';'.

Parameters:
elements - an array where each String entry may contain zero or more ServerProperties.COMMON_DELIMITERS separated elements.
Returns:
the array of elements, each element is trimmed, the array will not contain any empty or null entries.

getElements

public static java.lang.String[] getElements(java.lang.String[] elements,
                                             java.lang.String delimiters)
Get a canonical array of String elements from a String array where each entry may contain zero or more elements separated by characters in delimiters string.

Parameters:
elements - an array where each String entry may contain zero or more delimiters separated elements.
delimiters - string with delimiters, every character represents one delimiter.
Returns:
the array of elements, each element is trimmed, the array will not contain any empty or null entries.

getElements

public static java.lang.String[] getElements(java.lang.String elements,
                                             java.lang.String delimiters)
Get a canonical array of String elements from a String that may contain zero or more elements separated by characters in delimiters string.

Parameters:
elements - a String that may contain zero or more delimiters separated elements.
delimiters - string with delimiters, every character represents one delimiter.
Returns:
the array of elements, each element is trimmed.


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