public static Object[] createConstructorArguments(Constructor<?> c, Message m, boolean perRequest, Map<Class<?>, Object> contextValues) { Class<?>[] params = c.getParameterTypes(); Annotation[][] anns = c.getParameterAnnotations(); Type[] genericTypes = c.getGenericParameterTypes(); return createConstructorArguments(c, m, perRequest, contextValues, params, anns, genericTypes); }
/** * {@inheritDoc} */ public Object getInstance(Message m) { Object[] values = ResourceUtils.createConstructorArguments(c, m); Object instance = values.length > 0 ? ac.getBean(beanId, values) : ac.getBean(beanId); initInstance(m, instance); return instance; }
Object[] cArgs = ResourceUtils.createConstructorArguments(c, null, false, values); if (existingProxies != null && existingProxies.size() <= paramTypes.length) { for (int i = 0; i < paramTypes.length; i++) {
public Object getInstance(Message m) { //TODO -- This is not the BP way. Object[] values = ResourceUtils.createConstructorArguments(c, m); //TODO Very springish... Object instance = values.length > 0 ? blueprintContainer.getComponentInstance(beanId) : blueprintContainer.getComponentInstance(beanId); if (!isSingleton || m == null) { InjectionUtils.invokeLifeCycleMethod(instance, postConstructMethod); } return instance; }
/** * {@inheritDoc} */ public Object getInstance(Message m) { if (singletonInstance != null) { return singletonInstance; } ProviderInfo<?> application = m == null ? null : (ProviderInfo<?>)m.getExchange().getEndpoint().get(Application.class.getName()); Map<Class<?>, Object> mapValues = CastUtils.cast(application == null ? null : Collections.singletonMap(Application.class, application.getProvider())); Object[] values = ResourceUtils.createConstructorArguments(c, m, !isSingleton(), mapValues); Object instance = values.length > 0 ? ac.getBean(beanId, values) : ac.getBean(beanId); initInstance(m, instance); return instance; }
protected Object createInstance(Message m) { Object[] values = ResourceUtils.createConstructorArguments(c, m); try { Object instance = values.length > 0 ? c.newInstance(values) : c.newInstance(new Object[]{}); InjectionUtils.invokeLifeCycleMethod(instance, postConstructMethod); return instance; } catch (InstantiationException ex) { String msg = "Resource class " + c.getDeclaringClass().getName() + " can not be instantiated"; throw ExceptionUtils.toInternalServerErrorException(null, serverError(msg)); } catch (IllegalAccessException ex) { String msg = "Resource class " + c.getDeclaringClass().getName() + " can not be instantiated" + " due to IllegalAccessException"; throw ExceptionUtils.toInternalServerErrorException(null, serverError(msg)); } catch (InvocationTargetException ex) { Response r = JAXRSUtils.convertFaultToResponse(ex.getCause(), m); if (r != null) { m.getExchange().put(Response.class, r); throw new WebApplicationException(); } String msg = "Resource class " + c.getDeclaringClass().getName() + " can not be instantiated" + " due to InvocationTargetException"; throw ExceptionUtils.toInternalServerErrorException(null, serverError(msg)); } }
protected Object createInstance(Message m) { ProviderInfo<?> application = (ProviderInfo<?>)m.getExchange().getEndpoint().get(Application.class.getName()); Map<Class<?>, Object> mapValues = CastUtils.cast(application == null ? null : Collections.singletonMap(Application.class, application.getProvider())); Object[] values = ResourceUtils.createConstructorArguments(c, m, true, mapValues, params, anns, genericTypes); try { Object instance = values.length > 0 ? c.newInstance(values) : c.newInstance(new Object[]{}); InjectionUtils.invokeLifeCycleMethod(instance, postConstructMethod); return instance; } catch (InstantiationException ex) { String msg = "Resource class " + c.getDeclaringClass().getName() + " can not be instantiated"; throw ExceptionUtils.toInternalServerErrorException(null, serverError(msg)); } catch (IllegalAccessException ex) { String msg = "Resource class " + c.getDeclaringClass().getName() + " can not be instantiated" + " due to IllegalAccessException"; throw ExceptionUtils.toInternalServerErrorException(null, serverError(msg)); } catch (InvocationTargetException ex) { Response r = JAXRSUtils.convertFaultToResponse(ex.getCause(), m); if (r != null) { m.getExchange().put(Response.class, r); throw new WebApplicationException(); } String msg = "Resource class " + c.getDeclaringClass().getName() + " can not be instantiated" + " due to InvocationTargetException"; throw ExceptionUtils.toInternalServerErrorException(null, serverError(msg)); } }
public void init(Endpoint ep) { if (resourceInstance instanceof Constructor) { Constructor<?> c = (Constructor<?>)resourceInstance; Message m = new MessageImpl(); ExchangeImpl exchange = new ExchangeImpl(); exchange.put(Endpoint.class, ep); m.setExchange(exchange); Object[] values = ResourceUtils.createConstructorArguments(c, m, false, Collections.emptyMap()); try { resourceInstance = values.length > 0 ? c.newInstance(values) : c.newInstance(new Object[]{}); } catch (Exception ex) { throw new ServiceConstructionException(ex); } } if (callPostConstruct) { InjectionUtils.invokeLifeCycleMethod(resourceInstance, ResourceUtils.findPostConstructMethod(ClassHelper.getRealClass(resourceInstance))); } }
public Object getInstance(Message m) { //TODO -- This is not the BP way. ProviderInfo<?> application = m == null ? null : (ProviderInfo<?>)m.getExchange().getEndpoint().get(Application.class.getName()); Map<Class<?>, Object> mapValues = CastUtils.cast(application == null ? null : Collections.singletonMap(Application.class, application.getProvider())); Object[] values = ResourceUtils.createConstructorArguments(c, m, !isSingleton(), mapValues); //TODO Very springish... Object instance = values.length > 0 ? blueprintContainer.getComponentInstance(beanId) : blueprintContainer.getComponentInstance(beanId); if (!isSingleton() || m == null) { InjectionUtils.invokeLifeCycleMethod(instance, postConstructMethod); } return instance; }