use of org.apache.cxf.jaxrs.model.ApplicationInfo in project cxf by apache.
the class CXFNonSpringJaxrsServlet method createSingletonInstance.
protected Object createSingletonInstance(Class<?> cls, Map<String, List<String>> props, ServletConfig sc) throws ServletException {
Constructor<?> c = ResourceUtils.findResourceConstructor(cls, false);
if (c == null) {
throw new ServletException("No valid constructor found for " + cls.getName());
}
boolean isApplication = Application.class.isAssignableFrom(c.getDeclaringClass());
try {
ProviderInfo<? extends Object> provider = null;
if (c.getParameterTypes().length == 0) {
if (isApplication) {
provider = new ApplicationInfo((Application) c.newInstance(), getBus());
} else {
provider = new ProviderInfo<Object>(c.newInstance(), getBus(), false, true);
}
} else {
Map<Class<?>, Object> values = new HashMap<>();
values.put(ServletContext.class, sc.getServletContext());
values.put(ServletConfig.class, sc);
provider = ProviderFactory.createProviderFromConstructor(c, values, getBus(), isApplication, true);
}
Object instance = provider.getProvider();
injectProperties(instance, props);
configureSingleton(instance);
return isApplication ? provider : instance;
} catch (InstantiationException ex) {
ex.printStackTrace();
throw new ServletException("Resource class " + cls.getName() + " can not be instantiated");
} catch (IllegalAccessException ex) {
ex.printStackTrace();
throw new ServletException("Resource class " + cls.getName() + " can not be instantiated due to IllegalAccessException");
} catch (InvocationTargetException ex) {
ex.printStackTrace();
throw new ServletException("Resource class " + cls.getName() + " can not be instantiated due to InvocationTargetException");
}
}
Aggregations