Class CommonConfig
- java.lang.Object
-
- org.glassfish.jersey.model.internal.CommonConfig
-
- All Implemented Interfaces:
javax.ws.rs.core.Configurable<javax.ws.rs.core.FeatureContext>,javax.ws.rs.core.Configuration,javax.ws.rs.core.FeatureContext,ExtendedConfig
- Direct Known Subclasses:
ImmutableCommonConfig,ResourceConfig.State,ResourceMethodConfig
public class CommonConfig extends java.lang.Object implements javax.ws.rs.core.FeatureContext, ExtendedConfig
Common immutableConfigurationimplementation for server and client.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classCommonConfig.FeatureRegistrationA single feature registration record.
-
Field Summary
Fields Modifier and Type Field Description private static java.util.function.Function<java.lang.Object,Binder>CAST_TO_BINDERprivate ComponentBagcomponentBagConfigured providers, does not include features and binders.private booleandisableMetaProviderConfigurationFlag determining whether the configuration of meta-providers (excl.private java.util.Set<java.lang.Class<? extends javax.ws.rs.core.Feature>>enabledFeatureClassesCollection of enabled feature classes.private java.util.Set<javax.ws.rs.core.Feature>enabledFeaturesCollection of enabled feature instances.private java.util.Map<java.lang.String,java.lang.Object>immutablePropertiesViewprivate java.util.Collection<java.lang.String>immutablePropertyNamesprivate static java.util.logging.LoggerLOGGERprivate java.util.List<CommonConfig.FeatureRegistration>newFeatureRegistrationsCollection of unprocessed feature registrations.private java.util.Map<java.lang.String,java.lang.Object>propertiesConfiguration properties collection and it's immutable views.private javax.ws.rs.RuntimeTypetypeConfiguration runtime type.
-
Constructor Summary
Constructors Constructor Description CommonConfig(javax.ws.rs.RuntimeType type, java.util.function.Predicate<ContractProvider> registrationStrategy)Create a newRuntimeConfiginstance.CommonConfig(CommonConfig config)Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CommonConfigaddProperties(java.util.Map<java.lang.String,?> properties)Add properties toResourceConfig.private java.util.Set<java.lang.Class<?>>asNewIdentitySet(java.lang.Class<?>... contracts)private voidcheckComponentClassNotNull(java.lang.Class<?> componentClass)private voidcheckProviderNotNull(java.lang.Object provider)voidconfigureAutoDiscoverableProviders(InjectionManager injectionManager, java.util.Collection<AutoDiscoverable> autoDiscoverables, boolean forcedOnly)Configureauto-discoverablesin the injection manager.private java.util.Set<Binder>configureBinders(InjectionManager injectionManager, java.util.Set<Binder> configured)private voidconfigureExternalObjects(InjectionManager injectionManager)private voidconfigureFeatures(InjectionManager injectionManager, java.util.Set<CommonConfig.FeatureRegistration> processed, java.util.List<CommonConfig.FeatureRegistration> unprocessed, ManagedObjectsFinalizer managedObjectsFinalizer)voidconfigureMetaProviders(InjectionManager injectionManager, ManagedObjectsFinalizer finalizer)Configure binders in the injection manager and enable JAX-RS features.private voidcopy(CommonConfig config, boolean loadComponentBag)Copy config properties, providers from givenconfigto this instance.booleanequals(java.lang.Object o)private java.util.Collection<Binder>getBinder(java.util.Set<Binder> configured)java.util.Set<java.lang.Class<?>>getClasses()ComponentBaggetComponentBag()Returns aComponentBaginstance associated with the configuration.ExtendedConfiggetConfiguration()java.util.Map<java.lang.Class<?>,java.lang.Integer>getContracts(java.lang.Class<?> componentClass)java.util.Set<java.lang.Object>getInstances()protected Inflector<ContractProvider.Builder,ContractProvider>getModelEnhancer(java.lang.Class<?> componentClass)An extension point that provides a way how to define a custom enhancement/update operation of a contract provider model registration being produced for a given component class.java.util.Map<java.lang.String,java.lang.Object>getProperties()java.lang.ObjectgetProperty(java.lang.String name)java.util.Collection<java.lang.String>getPropertyNames()javax.ws.rs.RuntimeTypegetRuntimeType()inthashCode()booleanisEnabled(java.lang.Class<? extends javax.ws.rs.core.Feature> featureClass)booleanisEnabled(javax.ws.rs.core.Feature feature)booleanisProperty(java.lang.String name)Get the value of the property with a given name converted toboolean.booleanisRegistered(java.lang.Class<?> componentClass)booleanisRegistered(java.lang.Object component)CommonConfigloadFrom(javax.ws.rs.core.Configuration config)Load the internal configuration state from an externally provided configuration state.private voidprocessFeatureRegistration(java.lang.Object component, java.lang.Class<?> componentClass)CommonConfigproperty(java.lang.String name, java.lang.Object value)CommonConfigregister(java.lang.Class<?> componentClass)CommonConfigregister(java.lang.Class<?> componentClass, int bindingPriority)CommonConfigregister(java.lang.Class<?> componentClass, java.lang.Class<?>... contracts)CommonConfigregister(java.lang.Class<?> componentClass, java.util.Map<java.lang.Class<?>,java.lang.Integer> contracts)CommonConfigregister(java.lang.Object component)CommonConfigregister(java.lang.Object component, int bindingPriority)CommonConfigregister(java.lang.Object component, java.lang.Class<?>... contracts)CommonConfigregister(java.lang.Object component, java.util.Map<java.lang.Class<?>,java.lang.Integer> contracts)private java.util.List<CommonConfig.FeatureRegistration>resetRegistrations()CommonConfigsetProperties(java.util.Map<java.lang.String,?> properties)Set the configured properties to the provided map of properties.
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
CAST_TO_BINDER
private static final java.util.function.Function<java.lang.Object,Binder> CAST_TO_BINDER
-
type
private final javax.ws.rs.RuntimeType type
Configuration runtime type.
-
properties
private final java.util.Map<java.lang.String,java.lang.Object> properties
Configuration properties collection and it's immutable views.
-
immutablePropertiesView
private final java.util.Map<java.lang.String,java.lang.Object> immutablePropertiesView
-
immutablePropertyNames
private final java.util.Collection<java.lang.String> immutablePropertyNames
-
componentBag
private final ComponentBag componentBag
Configured providers, does not include features and binders.
-
newFeatureRegistrations
private final java.util.List<CommonConfig.FeatureRegistration> newFeatureRegistrations
Collection of unprocessed feature registrations.
-
enabledFeatureClasses
private final java.util.Set<java.lang.Class<? extends javax.ws.rs.core.Feature>> enabledFeatureClasses
Collection of enabled feature classes.
-
enabledFeatures
private final java.util.Set<javax.ws.rs.core.Feature> enabledFeatures
Collection of enabled feature instances.
-
disableMetaProviderConfiguration
private boolean disableMetaProviderConfiguration
Flag determining whether the configuration of meta-providers (excl. binders) should be disabled.
-
-
Constructor Detail
-
CommonConfig
public CommonConfig(javax.ws.rs.RuntimeType type, java.util.function.Predicate<ContractProvider> registrationStrategy)Create a newRuntimeConfiginstance.The constructor provides a way for defining a
contract provider modelregistration strategy. Once a registration model is built for a newly registered contract, the provided registration strategy filter is consulted whether the model should be registered or not.Clients can use the method to cancel any contract provider model registration that does not meet the criteria of a given configuration context, such as a model that does not have any recognized contracts associated with it.
- Parameters:
type- configuration runtime type.registrationStrategy- function driving the decision (based on the introspectedcontract provider model) whether or not should the component class registration continue towards a successful completion.
-
CommonConfig
public CommonConfig(CommonConfig config)
Copy constructor.- Parameters:
config- configurable to copy class properties from.
-
-
Method Detail
-
copy
private void copy(CommonConfig config, boolean loadComponentBag)
Copy config properties, providers from givenconfigto this instance.- Parameters:
config- configurable to copy class properties from.loadComponentBag-trueif the component bag from config should be copied as well,falseotherwise.
-
getConfiguration
public ExtendedConfig getConfiguration()
- Specified by:
getConfigurationin interfacejavax.ws.rs.core.Configurable<javax.ws.rs.core.FeatureContext>
-
getRuntimeType
public javax.ws.rs.RuntimeType getRuntimeType()
- Specified by:
getRuntimeTypein interfacejavax.ws.rs.core.Configuration
-
getProperties
public java.util.Map<java.lang.String,java.lang.Object> getProperties()
- Specified by:
getPropertiesin interfacejavax.ws.rs.core.Configuration
-
getProperty
public java.lang.Object getProperty(java.lang.String name)
- Specified by:
getPropertyin interfacejavax.ws.rs.core.Configuration
-
isProperty
public boolean isProperty(java.lang.String name)
Description copied from interface:ExtendedConfigGet the value of the property with a given name converted toboolean. Returnsfalseif the value is not convertible.- Specified by:
isPropertyin interfaceExtendedConfig- Parameters:
name- property name.- Returns:
booleanproperty value orfalseif the property is not convertible.
-
getPropertyNames
public java.util.Collection<java.lang.String> getPropertyNames()
- Specified by:
getPropertyNamesin interfacejavax.ws.rs.core.Configuration
-
isEnabled
public boolean isEnabled(java.lang.Class<? extends javax.ws.rs.core.Feature> featureClass)
- Specified by:
isEnabledin interfacejavax.ws.rs.core.Configuration
-
isEnabled
public boolean isEnabled(javax.ws.rs.core.Feature feature)
- Specified by:
isEnabledin interfacejavax.ws.rs.core.Configuration
-
isRegistered
public boolean isRegistered(java.lang.Object component)
- Specified by:
isRegisteredin interfacejavax.ws.rs.core.Configuration
-
isRegistered
public boolean isRegistered(java.lang.Class<?> componentClass)
- Specified by:
isRegisteredin interfacejavax.ws.rs.core.Configuration
-
getContracts
public java.util.Map<java.lang.Class<?>,java.lang.Integer> getContracts(java.lang.Class<?> componentClass)
- Specified by:
getContractsin interfacejavax.ws.rs.core.Configuration
-
getClasses
public java.util.Set<java.lang.Class<?>> getClasses()
- Specified by:
getClassesin interfacejavax.ws.rs.core.Configuration
-
getInstances
public java.util.Set<java.lang.Object> getInstances()
- Specified by:
getInstancesin interfacejavax.ws.rs.core.Configuration
-
getComponentBag
public final ComponentBag getComponentBag()
Returns aComponentBaginstance associated with the configuration.- Returns:
- a non-null component bag instance.
-
getModelEnhancer
protected Inflector<ContractProvider.Builder,ContractProvider> getModelEnhancer(java.lang.Class<?> componentClass)
An extension point that provides a way how to define a custom enhancement/update operation of a contract provider model registration being produced for a given component class. Default implementation return an enhancer just builds the model.Derived implementations may use this method to e.g. filter out all contracts not applicable in the given configuration context or change the model scope. The returned set of filtered contracts is then used for the actual provider registration.
- Parameters:
componentClass- class of the component being registered.- Returns:
- filter for the contracts that being registered for a given component class.
-
setProperties
public CommonConfig setProperties(java.util.Map<java.lang.String,?> properties)
Set the configured properties to the provided map of properties.- Parameters:
properties- new map of properties to be set.- Returns:
- updated configuration instance.
-
addProperties
public CommonConfig addProperties(java.util.Map<java.lang.String,?> properties)
Add properties toResourceConfig. 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 configuration instance.
-
property
public CommonConfig property(java.lang.String name, java.lang.Object value)
- Specified by:
propertyin interfacejavax.ws.rs.core.Configurable<javax.ws.rs.core.FeatureContext>
-
register
public CommonConfig register(java.lang.Class<?> componentClass)
- Specified by:
registerin interfacejavax.ws.rs.core.Configurable<javax.ws.rs.core.FeatureContext>
-
register
public CommonConfig register(java.lang.Class<?> componentClass, int bindingPriority)
- Specified by:
registerin interfacejavax.ws.rs.core.Configurable<javax.ws.rs.core.FeatureContext>
-
register
public CommonConfig register(java.lang.Class<?> componentClass, java.lang.Class<?>... contracts)
- Specified by:
registerin interfacejavax.ws.rs.core.Configurable<javax.ws.rs.core.FeatureContext>
-
register
public CommonConfig register(java.lang.Class<?> componentClass, java.util.Map<java.lang.Class<?>,java.lang.Integer> contracts)
- Specified by:
registerin interfacejavax.ws.rs.core.Configurable<javax.ws.rs.core.FeatureContext>
-
register
public CommonConfig register(java.lang.Object component)
- Specified by:
registerin interfacejavax.ws.rs.core.Configurable<javax.ws.rs.core.FeatureContext>
-
register
public CommonConfig register(java.lang.Object component, int bindingPriority)
- Specified by:
registerin interfacejavax.ws.rs.core.Configurable<javax.ws.rs.core.FeatureContext>
-
register
public CommonConfig register(java.lang.Object component, java.lang.Class<?>... contracts)
- Specified by:
registerin interfacejavax.ws.rs.core.Configurable<javax.ws.rs.core.FeatureContext>
-
register
public CommonConfig register(java.lang.Object component, java.util.Map<java.lang.Class<?>,java.lang.Integer> contracts)
- Specified by:
registerin interfacejavax.ws.rs.core.Configurable<javax.ws.rs.core.FeatureContext>
-
processFeatureRegistration
private void processFeatureRegistration(java.lang.Object component, java.lang.Class<?> componentClass)
-
loadFrom
public CommonConfig loadFrom(javax.ws.rs.core.Configuration config)
Load the internal configuration state from an externally provided configuration state. Calling this method effectively replaces existing configuration state of the instance with the state represented by the externally provided configuration. If the features, auto-discoverables of given config has been already configured then this method will make sure to not configure them for the second time.- Parameters:
config- external configuration state to replace the configuration of this configurable instance.- Returns:
- the updated common configuration instance.
-
asNewIdentitySet
private java.util.Set<java.lang.Class<?>> asNewIdentitySet(java.lang.Class<?>... contracts)
-
checkProviderNotNull
private void checkProviderNotNull(java.lang.Object provider)
-
checkComponentClassNotNull
private void checkComponentClassNotNull(java.lang.Class<?> componentClass)
-
configureAutoDiscoverableProviders
public void configureAutoDiscoverableProviders(InjectionManager injectionManager, java.util.Collection<AutoDiscoverable> autoDiscoverables, boolean forcedOnly)
Configureauto-discoverablesin the injection manager.- Parameters:
injectionManager- injection manager in which the auto-discoverables should be configured.autoDiscoverables- list of registered auto discoverable components.forcedOnly- defines whether all or only forced auto-discoverables should be configured.
-
configureMetaProviders
public void configureMetaProviders(InjectionManager injectionManager, ManagedObjectsFinalizer finalizer)
Configure binders in the injection manager and enable JAX-RS features.- Parameters:
injectionManager- injection manager in which the binders and features should be configured.
-
configureBinders
private java.util.Set<Binder> configureBinders(InjectionManager injectionManager, java.util.Set<Binder> configured)
-
configureExternalObjects
private void configureExternalObjects(InjectionManager injectionManager)
-
configureFeatures
private void configureFeatures(InjectionManager injectionManager, java.util.Set<CommonConfig.FeatureRegistration> processed, java.util.List<CommonConfig.FeatureRegistration> unprocessed, ManagedObjectsFinalizer managedObjectsFinalizer)
-
resetRegistrations
private java.util.List<CommonConfig.FeatureRegistration> resetRegistrations()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-