private void validateConstructorExists() { // only validate it here otherwise we'll fail for CDI injections constructor = ResourceUtils.findResourceConstructor(clazz, true); if (constructor == null) { throw new RuntimeException("Resource class " + clazz + " has no valid constructor"); } }
public static Object createProviderInstance(Class<?> cls) { try { Constructor<?> c = ResourceUtils.findResourceConstructor(cls, false); if (c != null && c.getParameterTypes().length == 0) { return c.newInstance(); } return c; } catch (Throwable ex) { throw new RuntimeException("Provider " + cls.getName() + " can not be created", ex); } }
public static Feature createFeatureInstance(Class<? extends Feature> cls) { try { Constructor<?> c = ResourceUtils.findResourceConstructor(cls, false); if (c == null) { throw new RuntimeException("No valid constructor found for " + cls.getName()); } return (Feature) c.newInstance(); } catch (Throwable ex) { throw new RuntimeException("Feature " + cls.getName() + " can not be created", ex); } }
public PerRequestResourceProvider(Class<?> clazz) { c = ResourceUtils.findResourceConstructor(clazz, true); if (c == null) { throw new RuntimeException("Resource class " + clazz + " has no valid constructor"); } params = c.getParameterTypes(); anns = c.getParameterAnnotations(); genericTypes = c.getGenericParameterTypes(); postConstructMethod = ResourceUtils.findPostConstructMethod(clazz); preDestroyMethod = ResourceUtils.findPreDestroyMethod(clazz); }
@Override public Object invoke(Object proxy, Method method, Object[] parameters) throws Throwable { Object result = null; Class<?> returnType = method.getReturnType(); if (!returnType.isAssignableFrom(Void.class)) { // create a instance to return if (returnType.isInterface()) { // create a new proxy for it result = Proxy.newProxyInstance(returnType.getClassLoader(), new Class[] {returnType}, new SubResourceClassInvocationHandler()); } else { // get the constructor and create a new instance Constructor<?> c = ResourceUtils.findResourceConstructor(returnType, true); result = c.newInstance(new Object[] {}); } } return result; }
public PerRequestResourceProvider(Class<?> clazz) { c = ResourceUtils.findResourceConstructor(clazz, true); if (c == null) { throw new RuntimeException("Resource class " + clazz + " has no valid constructor"); } postConstructMethod = ResourceUtils.findPostConstructMethod(clazz); preDestroyMethod = ResourceUtils.findPreDestroyMethod(clazz); }
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());
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());
private void init() { Class<?> type = ClassHelper.getRealClassFromClass(ac.getType(beanId)); if (Proxy.isProxyClass(type)) { type = ClassHelper.getRealClass(ac.getBean(beanId)); } c = ResourceUtils.findResourceConstructor(type, !isSingleton()); if (c == null) { throw new RuntimeException("Resource class " + type + " has no valid constructor"); } postConstructMethod = ResourceUtils.findPostConstructMethod(type, postConstructMethodName); preDestroyMethod = ResourceUtils.findPreDestroyMethod(type, preDestroyMethodName); isSingleton = ac.isSingleton(beanId); if (!isSingleton) { isPrototype = ac.isPrototype(beanId); } }
private void init() { type = ClassHelper.getRealClassFromClass(ac.getType(beanId)); if (Proxy.isProxyClass(type)) { type = ClassHelper.getRealClass(ac.getBean(beanId)); } isSingleton = ac.isSingleton(beanId); postConstructMethod = ResourceUtils.findPostConstructMethod(type, postConstructMethodName); preDestroyMethod = ResourceUtils.findPreDestroyMethod(type, preDestroyMethodName); if (isSingleton()) { try { singletonInstance = ac.getBean(beanId); } catch (BeansException ex) { // ignore for now, try resolving resource constructor later } if (singletonInstance != null) { return; } } else { isPrototype = ac.isPrototype(beanId); } c = ResourceUtils.findResourceConstructor(type, !isSingleton()); if (c == null) { throw new RuntimeException("Resource class " + type + " has no valid constructor"); } }
private void init() { Class<?> type = ClassHelper.getRealClassFromClass(blueprintContainer.getComponentInstance(beanId) .getClass()); if (Proxy.isProxyClass(type)) { type = ClassHelper.getRealClass(blueprintContainer.getComponentInstance(beanId)); } c = ResourceUtils.findResourceConstructor(type, !isSingleton()); if (c == null) { throw new RuntimeException("Resource class " + type + " has no valid constructor"); } postConstructMethod = ResourceUtils.findPostConstructMethod(type); preDestroyMethod = ResourceUtils.findPreDestroyMethod(type); Object component = blueprintContainer.getComponentMetadata(beanId); if (component instanceof BeanMetadata) { BeanMetadata local = (BeanMetadata) component; isSingleton = BeanMetadata.SCOPE_SINGLETON.equals(local.getScope()) || (local.getScope() == null && local.getId() != null); } }
private void init() { Class<?> type = ClassHelper.getRealClassFromClass(blueprintContainer.getComponentInstance(beanId) .getClass()); if (Proxy.isProxyClass(type)) { type = ClassHelper.getRealClass(blueprintContainer.getComponentInstance(beanId)); } c = ResourceUtils.findResourceConstructor(type, !isSingleton()); if (c == null) { throw new RuntimeException("Resource class " + type + " has no valid constructor"); } postConstructMethod = ResourceUtils.findPostConstructMethod(type); preDestroyMethod = ResourceUtils.findPreDestroyMethod(type); Object component = blueprintContainer.getComponentMetadata(beanId); if (component instanceof BeanMetadata) { BeanMetadata local = (BeanMetadata) component; isSingleton = BeanMetadata.SCOPE_SINGLETON.equals(local.getScope()) || (local.getScope() == null && local.getId() != null); } }