private void checkNoArgsConstructor(EnhancedAnnotatedType<T> type) { if (!beanManager.getServices().get(ProxyInstantiator.class).isUsingConstructor()) { return; } EnhancedAnnotatedConstructor<T> constructor = type.getNoArgsEnhancedConstructor(); if (constructor == null) { throw BeanLogger.LOG.decoratedHasNoNoargsConstructor(this); } else if (constructor.isPrivate()) { throw BeanLogger.LOG .decoratedNoargsConstructorIsPrivate(this, Formats.formatAsStackTraceElement(constructor.getJavaMember())); } }
/** * Creates a new constructor injection point suitable for Jersey components. * * @param constructor resolved constructor that can be injected using Jersey. * @param bean bean descriptor dedicated to the parent class. * @param manager current bean manager. * @param resolvers all registered resolvers. */ public JerseyConstructorInjectionPoint(EnhancedAnnotatedConstructor<T> constructor, Bean<T> bean, BeanManagerImpl manager, Collection<InjectionResolver> resolvers) { super(constructor, null, constructor.getJavaClass(), InjectionPointFactory.instance(), manager); List<InjecteeToSupplier> valueSuppliers = createValueSuppliers(constructor.getJavaMember(), getParameterInjectionPoints(), resolvers); /* * Caches either created proxies if the component class is not RequestScoped or caches the supplier that just create * values every component creates. */ if (proxyResolver.isPrixiable(bean.getScope())) { this.cachedProxies = generateProxies(valueSuppliers); } else { this.cachedSuppliers = valueSuppliers.stream() .map(is -> is.supplier) .collect(Collectors.toList()); } }
public static <T> EnhancedAnnotatedConstructor<T> getBeanConstructor(EnhancedAnnotatedType<T> type) { Collection<EnhancedAnnotatedConstructor<T>> initializerAnnotatedConstructors = type .getEnhancedConstructors(Inject.class); BeanLogger.LOG.foundInjectableConstructors(initializerAnnotatedConstructors, type); EnhancedAnnotatedConstructor<T> constructor = null; if (initializerAnnotatedConstructors.size() > 1) { throw UtilLogger.LOG.ambiguousConstructor(type, initializerAnnotatedConstructors); } else if (initializerAnnotatedConstructors.size() == 1) { constructor = initializerAnnotatedConstructors.iterator().next(); BeanLogger.LOG.foundOneInjectableConstructor(constructor, type); } else if (type.getNoArgsEnhancedConstructor() != null) { constructor = type.getNoArgsEnhancedConstructor(); BeanLogger.LOG.foundDefaultConstructor(constructor, type); } if (constructor != null) { if (!constructor.getEnhancedParameters(Disposes.class).isEmpty()) { throw BeanLogger.LOG.parameterAnnotationNotAllowedOnConstructor("@Disposes", constructor, Formats.formatAsStackTraceElement(constructor.getJavaMember())); } if (!constructor.getEnhancedParameters(Observes.class).isEmpty()) { throw BeanLogger.LOG.parameterAnnotationNotAllowedOnConstructor("@Observes", constructor, Formats.formatAsStackTraceElement(constructor.getJavaMember())); } if (!constructor.getEnhancedParameters(ObservesAsync.class).isEmpty()) { throw BeanLogger.LOG.parameterAnnotationNotAllowedOnConstructor("@ObservesAsync", constructor, Formats.formatAsStackTraceElement(constructor.getJavaMember())); } } return constructor; }
if ((superclass != null) && (superclass.getJavaClass() != Object.class)) { fieldsTemp = Sets.union(fieldsTemp, Reflections.<Set<EnhancedAnnotatedField<?, ? super T>>>cast(superclass.getFields())); EnhancedAnnotatedConstructor<T> weldConstructor = EnhancedAnnotatedConstructorImpl.of(constructor, this, classTransformer); this.constructors.add(weldConstructor); this.declaredConstructorsBySignature.put(weldConstructor.getSignature(), weldConstructor); if (superclass != null) { EnhancedAnnotatedType<?> current = superclass; while (current.getJavaClass() != Object.class) { Set<EnhancedAnnotatedMethod<?, ? super T>> superClassMethods = Reflections.cast(current.getDeclaredEnhancedMethods()); methodsTemp.addAll(superClassMethods);
public void init() { initTargetClassInterceptors(); businessMethods = Beans.getInterceptableMethods(annotatedType); initEjbInterceptors(); initCdiInterceptors(); InterceptionModel interceptionModel = builder.build(); if (interceptionModel.getAllInterceptors().size() > 0 || hasSerializationOrInvocationInterceptorMethods) { if (annotatedType.isFinal()) { throw BeanLogger.LOG.finalBeanClassWithInterceptorsNotAllowed(annotatedType.getJavaClass()); } if (Reflections.isPrivate(constructor.getJavaMember())) { throw new DeploymentException(ValidatorLogger.LOG.notProxyablePrivateConstructor(annotatedType.getJavaClass().getName(), constructor, annotatedType.getJavaClass())); } manager.getInterceptorModelRegistry().put(annotatedType.slim(), interceptionModel); } }
/** * The overridden equals operation * * @param other The instance to compare to * @return True if equal, false otherwise */ @Override public boolean equals(Object other) { if (super.equals(other) && other instanceof EnhancedAnnotatedConstructor<?>) { EnhancedAnnotatedConstructor<?> that = (EnhancedAnnotatedConstructor<?>) other; return this.getJavaMember().equals(that.getJavaMember()) && this.getEnhancedParameters().equals(that.getEnhancedParameters()); } return false; }
public static <T> SubclassedComponentInstantiator<T> forSubclassedEjb(EnhancedAnnotatedType<T> componentType, EnhancedAnnotatedType<T> subclass, Bean<T> bean, BeanManagerImpl manager) { final EnhancedAnnotatedConstructor<T> componentConstructor = Beans.getBeanConstructor(componentType); final EnhancedAnnotatedConstructor<T> subclassConstructor = findMatchingConstructor(componentConstructor.getSignature(), subclass); final ConstructorInjectionPoint<T> cip = InjectionPointFactory.instance().createConstructorInjectionPoint(bean, componentType.getJavaClass(), subclassConstructor, manager); return new SubclassedComponentInstantiator<T>(cip, componentConstructor.getJavaMember()); }
protected ConstructorInjectionPoint(EnhancedAnnotatedConstructor<T> constructor, Bean<T> declaringBean, Class<?> declaringComponentClass, InjectionPointFactory factory, BeanManagerImpl manager) { super(constructor, declaringBean, declaringComponentClass, false, factory, manager); this.constructor = constructor.slim(); this.signature = constructor.getSignature(); this.accessibleConstructor = AccessController.doPrivileged(new GetAccessibleCopyOfMember<Constructor<T>>(constructor.getJavaMember())); }
/** * Gets constructors with given annotation type * * @param annotationType The annotation type to match * @return A set of abstracted constructors with given annotation type. If * the constructors set is empty, initialize it first. Returns an * empty set if there are no matches. * @see org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType#getEnhancedConstructors(Class) */ @Override public Collection<EnhancedAnnotatedConstructor<T>> getEnhancedConstructors(Class<? extends Annotation> annotationType) { Set<EnhancedAnnotatedConstructor<T>> ret = new HashSet<EnhancedAnnotatedConstructor<T>>(); for (EnhancedAnnotatedConstructor<T> constructor : constructors) { if (constructor.isAnnotationPresent(annotationType)) { ret.add(constructor); } } return ret; }
public ConstructorSignatureImpl(EnhancedAnnotatedConstructor<?> method) { this.parameterTypes = new String[method.getEnhancedParameters().size()]; for (int i = 0; i < method.getEnhancedParameters().size(); i++) { parameterTypes[i] = method.getEnhancedParameters().get(i).getJavaClass().getName(); } }
private void initCdiConstructorInterceptors(Multimap<Class<? extends Annotation>, Annotation> classBindingAnnotations) { Set<Annotation> constructorBindings = getMemberBindingAnnotations(classBindingAnnotations, constructor.getMetaAnnotations(InterceptorBinding.class)); if (constructorBindings.isEmpty()) { return; } initLifeCycleInterceptor(InterceptionType.AROUND_CONSTRUCT, this.constructor, constructorBindings); }
public Constructor<T> getJavaMember() { return delegate().getJavaMember(); }
@Override public AnnotatedConstructor<T> slim() { return delegate().slim(); } }
public ConstructorSignature getSignature() { return delegate().getSignature(); }
public static <T> EnhancedAnnotatedConstructor<T> getBeanConstructor(EnhancedAnnotatedType<T> type) { Collection<EnhancedAnnotatedConstructor<T>> initializerAnnotatedConstructors = type .getEnhancedConstructors(Inject.class); BeanLogger.LOG.foundInjectableConstructors(initializerAnnotatedConstructors, type); EnhancedAnnotatedConstructor<T> constructor = null; if (initializerAnnotatedConstructors.size() > 1) { throw UtilLogger.LOG.ambiguousConstructor(type, initializerAnnotatedConstructors); } else if (initializerAnnotatedConstructors.size() == 1) { constructor = initializerAnnotatedConstructors.iterator().next(); BeanLogger.LOG.foundOneInjectableConstructor(constructor, type); } else if (type.getNoArgsEnhancedConstructor() != null) { constructor = type.getNoArgsEnhancedConstructor(); BeanLogger.LOG.foundDefaultConstructor(constructor, type); } if (constructor != null) { if (!constructor.getEnhancedParameters(Disposes.class).isEmpty()) { throw BeanLogger.LOG.parameterAnnotationNotAllowedOnConstructor("@Disposes", constructor, Formats.formatAsStackTraceElement(constructor.getJavaMember())); } if (!constructor.getEnhancedParameters(Observes.class).isEmpty()) { throw BeanLogger.LOG.parameterAnnotationNotAllowedOnConstructor("@Observes", constructor, Formats.formatAsStackTraceElement(constructor.getJavaMember())); } if (!constructor.getEnhancedParameters(ObservesAsync.class).isEmpty()) { throw BeanLogger.LOG.parameterAnnotationNotAllowedOnConstructor("@ObservesAsync", constructor, Formats.formatAsStackTraceElement(constructor.getJavaMember())); } } return constructor; }
if ((superclass != null) && (superclass.getJavaClass() != Object.class)) { fieldsTemp = Sets.union(fieldsTemp, Reflections.<Set<EnhancedAnnotatedField<?, ? super T>>>cast(superclass.getFields())); EnhancedAnnotatedConstructor<T> weldConstructor = EnhancedAnnotatedConstructorImpl.of(constructor, this, classTransformer); this.constructors.add(weldConstructor); this.declaredConstructorsBySignature.put(weldConstructor.getSignature(), weldConstructor); if (superclass != null) { EnhancedAnnotatedType<?> current = superclass; while (current.getJavaClass() != Object.class) { Set<EnhancedAnnotatedMethod<?, ? super T>> superClassMethods = Reflections.cast(current.getDeclaredEnhancedMethods()); methodsTemp.addAll(superClassMethods);
public void init() { initTargetClassInterceptors(); businessMethods = Beans.getInterceptableMethods(annotatedType); initEjbInterceptors(); initCdiInterceptors(); InterceptionModel interceptionModel = builder.build(); if (interceptionModel.getAllInterceptors().size() > 0 || hasSerializationOrInvocationInterceptorMethods) { if (annotatedType.isFinal()) { throw BeanLogger.LOG.finalBeanClassWithInterceptorsNotAllowed(annotatedType.getJavaClass()); } if (Reflections.isPrivate(constructor.getJavaMember())) { throw new DeploymentException(ValidatorLogger.LOG.notProxyablePrivateConstructor(annotatedType.getJavaClass().getName(), constructor, annotatedType.getJavaClass())); } manager.getInterceptorModelRegistry().put(annotatedType.slim(), interceptionModel); } }
/** * The overridden equals operation * * @param other The instance to compare to * @return True if equal, false otherwise */ @Override public boolean equals(Object other) { if (super.equals(other) && other instanceof EnhancedAnnotatedConstructor<?>) { EnhancedAnnotatedConstructor<?> that = (EnhancedAnnotatedConstructor<?>) other; return this.getJavaMember().equals(that.getJavaMember()) && this.getEnhancedParameters().equals(that.getEnhancedParameters()); } return false; }
public static <T> SubclassedComponentInstantiator<T> forSubclassedEjb(EnhancedAnnotatedType<T> componentType, EnhancedAnnotatedType<T> subclass, Bean<T> bean, BeanManagerImpl manager) { final EnhancedAnnotatedConstructor<T> componentConstructor = Beans.getBeanConstructor(componentType); final EnhancedAnnotatedConstructor<T> subclassConstructor = findMatchingConstructor(componentConstructor.getSignature(), subclass); final ConstructorInjectionPoint<T> cip = InjectionPointFactory.instance().createConstructorInjectionPoint(bean, componentType.getJavaClass(), subclassConstructor, manager); return new SubclassedComponentInstantiator<T>(cip, componentConstructor.getJavaMember()); }
protected ConstructorInjectionPoint(EnhancedAnnotatedConstructor<T> constructor, Bean<T> declaringBean, Class<?> declaringComponentClass, InjectionPointFactory factory, BeanManagerImpl manager) { super(constructor, declaringBean, declaringComponentClass, false, factory, manager); this.constructor = constructor.slim(); this.signature = constructor.getSignature(); this.accessibleConstructor = AccessController.doPrivileged(new GetAccessibleCopyOfMember<Constructor<T>>(constructor.getJavaMember())); }