final ResourceBag resourceBag;
final ProcessingProviders processingProviders;
final List<ComponentProvider> componentProviders;
final ComponentBag componentBag;
ResourceModel resourceModel;
CompositeApplicationEventListener compositeListener = null;
Errors.mark(); // mark begin of validation phase
try {
// AutoDiscoverable.
if (!CommonProperties.getValue(runtimeConfig.getProperties(), RuntimeType.SERVER,
CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, Boolean.FALSE, Boolean.class)) {
runtimeConfig.configureAutoDiscoverableProviders(locator);
} else {
runtimeConfig.configureForcedAutoDiscoverableProviders(locator);
}
// Configure binders and features.
runtimeConfig.configureMetaProviders(locator);
final ResourceBag.Builder resourceBagBuilder = new ResourceBag.Builder();
// Adding programmatic resource models
for (final Resource programmaticResource : runtimeConfig.getResources()) {
resourceBagBuilder.registerProgrammaticResource(programmaticResource);
}
// Introspecting classes & instances
for (final Class<?> c : runtimeConfig.getClasses()) {
try {
final Resource resource = Resource.from(c, disableValidation);
if (resource != null) {
resourceBagBuilder.registerResource(c, resource);
}
} catch (final IllegalArgumentException ex) {
LOGGER.warning(ex.getMessage());
}
}
for (final Object o : runtimeConfig.getSingletons()) {
try {
final Resource resource = Resource.from(o.getClass(), disableValidation);
if (resource != null) {
resourceBagBuilder.registerResource(o, resource);
}
} catch (final IllegalArgumentException ex) {
LOGGER.warning(ex.getMessage());
}
}
resourceBag = resourceBagBuilder.build();
runtimeConfig.lock();
// Registering Injection Bindings
componentProviders = new LinkedList<>();
// Registering Injection Bindings
for (final RankedProvider<ComponentProvider> rankedProvider : getRankedComponentProviders()) {
final ComponentProvider provider = rankedProvider.getProvider();
provider.initialize(locator);
componentProviders.add(provider);
}
componentBag = runtimeConfig.getComponentBag();
bindProvidersAndResources(componentProviders, componentBag, resourceBag.classes, resourceBag.instances);
for (final ComponentProvider componentProvider : componentProviders) {
componentProvider.done();
}
final Iterable<ApplicationEventListener> appEventListeners = Providers.getAllProviders(locator,
ApplicationEventListener.class, new RankedComparator<ApplicationEventListener>());
if (appEventListeners.iterator().hasNext()) {
compositeListener = new CompositeApplicationEventListener(appEventListeners);
compositeListener.onEvent(new ApplicationEventImpl(ApplicationEvent.Type.INITIALIZATION_START,
this.runtimeConfig, componentBag.getRegistrations(), resourceBag.classes, resourceBag.instances,
null));
}
processingProviders = getProcessingProviders(componentBag);
// initialize processing provider reference
final GenericType<Ref<ProcessingProviders>> refGenericType = new GenericType<Ref<ProcessingProviders>>() {
};
final Ref<ProcessingProviders> refProcessingProvider = locator.getService(refGenericType.getType());
refProcessingProvider.set(processingProviders);
resourceModel = new ResourceModel.Builder(resourceBag.getRootResources(), false).build();
resourceModel = processResourceModel(resourceModel);
if (!disableValidation) {
final ComponentModelValidator validator = new ComponentModelValidator(locator);
validator.validate(resourceModel);
}
if (Errors.fatalIssuesFound() && !ignoreValidationErrors) {
throw new ModelValidationException(LocalizationMessages.RESOURCE_MODEL_VALIDATION_FAILED_AT_INIT(),
ModelErrors.getErrorsAsResourceModelIssues(true));
}
} finally {
if (ignoreValidationErrors) {
Errors.logErrors(true);
Errors.reset(); // reset errors to the state before validation phase
} else {
Errors.unmark();
}
}
bindEnhancingResourceClasses(resourceModel, resourceBag, componentProviders);
// initiate resource model into JerseyResourceContext
final JerseyResourceContext jerseyResourceContext = locator.getService(JerseyResourceContext.class);
jerseyResourceContext.setResourceModel(resourceModel);
final RuntimeModelBuilder runtimeModelBuilder = locator.getService(RuntimeModelBuilder.class);
runtimeModelBuilder.setProcessingProviders(processingProviders);
// assembly request processing chain
/**
* Root hierarchical request matching acceptor.
* Invoked in a single linear stage as part of the main linear accepting chain.
*/
final Router resourceRoutingRoot = runtimeModelBuilder.buildModel(resourceModel.getRuntimeResourceModel(), false);
final ReferencesInitializer referencesInitializer = locator.createAndInitialize(ReferencesInitializer.class);
final ContainerFilteringStage preMatchRequestFilteringStage = new ContainerFilteringStage(
processingProviders.getPreMatchFilters(),
processingProviders.getGlobalResponseFilters());