this.serviceLocator = serviceLocator;
this.wadlGeneratorConfig = WadlGeneratorConfigLoader.loadWadlGeneratorsFromConfig(configuration.getProperties());
// TODO perhaps this should be done another way for the moment
// create a temporary generator just to do this one task
final WadlGenerator wadlGenerator = wadlGeneratorConfig.createWadlGenerator(serviceLocator);
JAXBContext jaxb;
try {
// Nasty ClassLoader magic. JAXB-API has some strange limitation about what classloader can
// be used in OSGi environment - it must be same as context ClassLoader. Following code just
// workarounds this limitation
// see JERSEY-1818
// see JSR222-46
final ClassLoader contextClassLoader = ReflectionHelper.getContextClassLoader();
final ClassLoader jerseyModuleClassLoader = wadlGenerator.getClass().getClassLoader();
ReflectionHelper.setContextClassLoader(jerseyModuleClassLoader);
jaxb = JAXBContext.newInstance(wadlGenerator.getRequiredJaxbContextPath(),
jerseyModuleClassLoader);
ReflectionHelper.setContextClassLoader(contextClassLoader);
} catch (JAXBException ex) {
try {
// fallback for glassfish
LOGGER.log(Level.FINE, LocalizationMessages.WADL_JAXB_CONTEXT_FALLBACK(), ex);
jaxb = JAXBContext.newInstance(wadlGenerator.getRequiredJaxbContextPath());
} catch (JAXBException innerEx) {
throw new ProcessingException(LocalizationMessages.ERROR_WADL_JAXB_CONTEXT(), ex);
}
}
jaxbContext = jaxb;