@SuppressWarnings("unchecked") private void checkAbstractMethods(EnhancedAnnotatedType<T> type) { if(!type.isAbstract()) { return; } Set<Type> decoratedTypes = null; Bean<?> bean = getBean(); if(bean != null && (bean instanceof DecoratorImpl)) { decoratedTypes = ((DecoratorImpl<T>)bean).getDecoratedTypes(); } Decorators.checkAbstractMethods(decoratedTypes, type, beanManager); } }
protected void initDelegateInjectionPoint() { // TODO: findDelegateInjectionPoint() is called also from DecoratorInjectionTarget. Try to avoid calling the method multiple times this.delegateInjectionPoint = Decorators.findDelegateInjectionPoint(getEnhancedAnnotated(), getInjectionPoints()); }
DecoratedMethods(BeanManagerImpl manager, WeldDecorator<?> decorator) { this.decoratedTypeMethods = Decorators.getDecoratorMethods(manager, decorator); this.cache = new ConcurrentHashMap<Method, Object>(); }
protected void validateDecorator(Decorator<?> decorator, Collection<CommonBean<?>> specializedBeans, BeanManagerImpl manager) { if (decorator.getDecoratedTypes().isEmpty()) { throw ValidatorLogger.LOG.noDecoratedTypes(decorator); if (!decorator.getScope().equals(Dependent.class)) { throw ValidatorLogger.LOG.interceptorOrDecoratorMustBeDependent(decorator); Decorators.checkDelegateType(decorator); Type delegateType = decorator.getDelegateType(); if (delegateType instanceof ParameterizedType) { ParameterizedType parameterizedDelegateType = (ParameterizedType) delegateType; if (!Decorators.isPassivationCapable(decorator)) { if (Instance.class.equals(parameterizedDelegateType.getRawType()) || Provider.class.equals(parameterizedDelegateType.getRawType())) { throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, Instance.class.getName()); EnhancedAnnotatedType<?> annotated = ((WeldDecorator<?>) decorator).getEnhancedAnnotated(); validateRIBean((CommonBean<?>) decorator, manager, specializedBeans); throw ValidatorLogger.LOG.decoratorsCannotHaveObserverMethods(decorator); if (!annotated.getDeclaredEnhancedFields(Produces.class).isEmpty()) { throw ValidatorLogger.LOG.decoratorsCannotHaveProducerFields(decorator); validateGeneralBean(decorator, manager); Decorators.findDelegateInjectionPoint(annotated, decorator.getInjectionPoints());
private void validateDecorators(BeanManagerImpl beanManager, DecorableBean<?> bean) { if (!(beanManager.isPassivatingScope(bean.getScope()) || bean instanceof AbstractDecorableBuiltInBean<?>)) { return; } List<Decorator<?>> decorators = bean.getDecorators(); if (decorators.isEmpty()) { return; } for (Decorator<?> decorator : decorators) { if (!Decorators.isPassivationCapable(decorator)) { if (bean instanceof AbstractDecorableBuiltInBean<?>) { throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, bean); } else { throw ValidatorLogger.LOG.passivatingBeanWithNonserializableDecorator(bean, decorator); } } if (decorator instanceof DecoratorImpl) { beanManager = ((DecoratorImpl<?>) decorator).getBeanManager(); } for (InjectionPoint ij : decorator.getInjectionPoints()) { if (!ij.isDelegate()) { Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(ij)); validateInterceptorDecoratorInjectionPointPassivationCapable(ij, resolvedBean, beanManager, bean); } } } }
/** * Determines the set of {@link InvokableAnnotatedMethod}s representing decorated methods of the specified decorator. A decorated method * is any method declared by a decorated type which is implemented by the decorator. * * @param beanManager the bean manager * @param decorator the specified decorator * @return the set of {@link InvokableAnnotatedMethod}s representing decorated methods of the specified decorator */ public static Set<InvokableAnnotatedMethod<?>> getDecoratorMethods(BeanManagerImpl beanManager, WeldDecorator<?> decorator) { ImmutableSet.Builder<InvokableAnnotatedMethod<?>> builder = ImmutableSet.builder(); for (Type type : decorator.getDecoratedTypes()) { EnhancedAnnotatedType<?> weldClass = getEnhancedAnnotatedTypeOfDecoratedType(beanManager, type); for (EnhancedAnnotatedMethod<?, ?> method : weldClass.getDeclaredEnhancedMethods()) { if (decorator.getEnhancedAnnotated().getEnhancedMethod(method.getSignature()) != null) { builder.add(InvokableAnnotatedMethod.of(method.slim())); } } } return builder.build(); }
@Override protected Instantiator<T> initInstantiator(EnhancedAnnotatedType<T> type, Bean<T> bean, BeanManagerImpl beanManager, Set<InjectionPoint> injectionPoints) { if (type.isAbstract()) { ConstructorInjectionPoint<T> originalConstructor = InjectionPointFactory.instance().createConstructorInjectionPoint(bean, type, beanManager); injectionPoints.addAll(originalConstructor.getParameterInjectionPoints()); final WeldInjectionPointAttributes<?, ?> delegateInjectionPoint = Decorators.findDelegateInjectionPoint(type, injectionPoints); return new SubclassedComponentInstantiator<T>(type, bean, originalConstructor, beanManager) { @Override protected Class<T> createEnhancedSubclass(EnhancedAnnotatedType<T> type, Bean<?> bean, BeanManagerImpl manager) { return new DecoratorProxyFactory<T>(manager.getContextId(), type.getJavaClass(), delegateInjectionPoint, bean).getProxyClass(); } }; } else { DefaultInstantiator<T> instantiator = new DefaultInstantiator<T>(type, bean, beanManager); injectionPoints.addAll(instantiator.getConstructorInjectionPoint().getParameterInjectionPoints()); return instantiator; } }
public DecoratorInjectionTarget(EnhancedAnnotatedType<T> type, Bean<T> bean, BeanManagerImpl beanManager) { super(type, bean, beanManager); this.delegateInjectionPoint = Decorators.findDelegateInjectionPoint(type, getInjectionPoints()); if (delegateInjectionPoint instanceof FieldInjectionPoint<?, ?>) { FieldInjectionPoint<?, ?> fip = (FieldInjectionPoint<?, ?>) delegateInjectionPoint; this.accessibleField = AccessController.doPrivileged(new GetAccessibleCopyOfMember<Field>(fip.getAnnotated().getJavaMember())); } else { this.accessibleField = null; } checkAbstractMethods(type); }
private Decorator<?> getFirstNonPassivationCapableDecorator() { for (Decorator<?> decorator : getDecorators()) { if (!Decorators.isPassivationCapable(decorator)) { return decorator; } } return null; }
@Override public T create(CreationalContext<T> creationalContext) { InjectionPoint ip = getInjectionPoint(cip); List<Decorator<?>> decorators = getDecorators(ip); T instance = newInstance(ip, creationalContext); if (decorators == null) { decorators = beanManager.resolveDecorators(Collections.singleton(ip.getType()), getQualifiers()); } if (decorators.isEmpty()) { return instance; } return Decorators.getOuterDelegate(this, instance, creationalContext, getProxyClass(), cip.peek(), getBeanManager(), decorators); }
protected void validateDecorator(Decorator<?> decorator, Collection<CommonBean<?>> specializedBeans, BeanManagerImpl manager) { if (decorator.getDecoratedTypes().isEmpty()) { throw ValidatorLogger.LOG.noDecoratedTypes(decorator); if (!decorator.getScope().equals(Dependent.class)) { throw ValidatorLogger.LOG.interceptorOrDecoratorMustBeDependent(decorator); Decorators.checkDelegateType(decorator); Type delegateType = decorator.getDelegateType(); if (delegateType instanceof ParameterizedType) { ParameterizedType parameterizedDelegateType = (ParameterizedType) delegateType; if (!Decorators.isPassivationCapable(decorator)) { if (Instance.class.equals(parameterizedDelegateType.getRawType()) || Provider.class.equals(parameterizedDelegateType.getRawType())) { throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, Instance.class.getName()); EnhancedAnnotatedType<?> annotated = ((WeldDecorator<?>) decorator).getEnhancedAnnotated(); validateRIBean((CommonBean<?>) decorator, manager, specializedBeans); throw ValidatorLogger.LOG.decoratorsCannotHaveObserverMethods(decorator); if (!annotated.getDeclaredEnhancedFields(Produces.class).isEmpty()) { throw ValidatorLogger.LOG.decoratorsCannotHaveProducerFields(decorator); validateGeneralBean(decorator, manager); Decorators.findDelegateInjectionPoint(annotated, decorator.getInjectionPoints());
private void validateDecorators(BeanManagerImpl beanManager, DecorableBean<?> bean) { if (!(beanManager.isPassivatingScope(bean.getScope()) || bean instanceof AbstractDecorableBuiltInBean<?>)) { return; } List<Decorator<?>> decorators = bean.getDecorators(); if (decorators.isEmpty()) { return; } for (Decorator<?> decorator : decorators) { if (!Decorators.isPassivationCapable(decorator)) { if (bean instanceof AbstractDecorableBuiltInBean<?>) { throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, bean); } else { throw ValidatorLogger.LOG.passivatingBeanWithNonserializableDecorator(bean, decorator); } } if (decorator instanceof DecoratorImpl) { beanManager = ((DecoratorImpl<?>) decorator).getBeanManager(); } for (InjectionPoint ij : decorator.getInjectionPoints()) { if (!ij.isDelegate()) { Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(ij)); validateInterceptorDecoratorInjectionPointPassivationCapable(ij, resolvedBean, beanManager, bean); } } } }
/** * Determines the set of {@link InvokableAnnotatedMethod}s representing decorated methods of the specified decorator. A decorated method * is any method declared by a decorated type which is implemented by the decorator. * * @param beanManager the bean manager * @param decorator the specified decorator * @return the set of {@link InvokableAnnotatedMethod}s representing decorated methods of the specified decorator */ public static Set<InvokableAnnotatedMethod<?>> getDecoratorMethods(BeanManagerImpl beanManager, WeldDecorator<?> decorator) { ImmutableSet.Builder<InvokableAnnotatedMethod<?>> builder = ImmutableSet.builder(); for (Type type : decorator.getDecoratedTypes()) { EnhancedAnnotatedType<?> weldClass = getEnhancedAnnotatedTypeOfDecoratedType(beanManager, type); for (EnhancedAnnotatedMethod<?, ?> method : weldClass.getDeclaredEnhancedMethods()) { if (decorator.getEnhancedAnnotated().getEnhancedMethod(method.getSignature()) != null) { builder.add(InvokableAnnotatedMethod.of(method.slim())); } } } return builder.build(); }
@Override protected Instantiator<T> initInstantiator(EnhancedAnnotatedType<T> type, Bean<T> bean, BeanManagerImpl beanManager, Set<InjectionPoint> injectionPoints) { if (type.isAbstract()) { ConstructorInjectionPoint<T> originalConstructor = InjectionPointFactory.instance().createConstructorInjectionPoint(bean, type, beanManager); injectionPoints.addAll(originalConstructor.getParameterInjectionPoints()); final WeldInjectionPointAttributes<?, ?> delegateInjectionPoint = Decorators.findDelegateInjectionPoint(type, injectionPoints); return new SubclassedComponentInstantiator<T>(type, bean, originalConstructor, beanManager) { @Override protected Class<T> createEnhancedSubclass(EnhancedAnnotatedType<T> type, Bean<?> bean, BeanManagerImpl manager) { return new DecoratorProxyFactory<T>(manager.getContextId(), type.getJavaClass(), delegateInjectionPoint, bean).getProxyClass(); } }; } else { DefaultInstantiator<T> instantiator = new DefaultInstantiator<T>(type, bean, beanManager); injectionPoints.addAll(instantiator.getConstructorInjectionPoint().getParameterInjectionPoints()); return instantiator; } }
public DecoratorInjectionTarget(EnhancedAnnotatedType<T> type, Bean<T> bean, BeanManagerImpl beanManager) { super(type, bean, beanManager); this.delegateInjectionPoint = Decorators.findDelegateInjectionPoint(type, getInjectionPoints()); if (delegateInjectionPoint instanceof FieldInjectionPoint<?, ?>) { FieldInjectionPoint<?, ?> fip = (FieldInjectionPoint<?, ?>) delegateInjectionPoint; this.accessibleField = AccessController.doPrivileged(new GetAccessibleCopyOfMember<Field>(fip.getAnnotated().getJavaMember())); } else { this.accessibleField = null; } checkAbstractMethods(type); }
private Decorator<?> getFirstNonPassivationCapableDecorator() { for (Decorator<?> decorator : getDecorators()) { if (!Decorators.isPassivationCapable(decorator)) { return decorator; } } return null; }
@Override public T create(CreationalContext<T> creationalContext) { InjectionPoint ip = getInjectionPoint(cip); List<Decorator<?>> decorators = getDecorators(ip); T instance = newInstance(ip, creationalContext); if (decorators == null) { decorators = beanManager.resolveDecorators(Collections.singleton(ip.getType()), getQualifiers()); } if (decorators.isEmpty()) { return instance; } return Decorators.getOuterDelegate(this, instance, creationalContext, getProxyClass(), cip.peek(), getBeanManager(), decorators); }
protected void validateDecorator(Decorator<?> decorator, Collection<CommonBean<?>> specializedBeans, BeanManagerImpl manager) { if (decorator.getDecoratedTypes().isEmpty()) { throw ValidatorLogger.LOG.noDecoratedTypes(decorator); if (!decorator.getScope().equals(Dependent.class)) { throw ValidatorLogger.LOG.interceptorOrDecoratorMustBeDependent(decorator); Decorators.checkDelegateType(decorator); Type delegateType = decorator.getDelegateType(); if (delegateType instanceof ParameterizedType) { ParameterizedType parameterizedDelegateType = (ParameterizedType) delegateType; if (!Decorators.isPassivationCapable(decorator)) { if (Instance.class.equals(parameterizedDelegateType.getRawType()) || Provider.class.equals(parameterizedDelegateType.getRawType())) { throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, Instance.class.getName()); EnhancedAnnotatedType<?> annotated = ((WeldDecorator<?>) decorator).getEnhancedAnnotated(); validateRIBean((CommonBean<?>) decorator, manager, specializedBeans); throw ValidatorLogger.LOG.decoratorsCannotHaveObserverMethods(decorator); if (!annotated.getDeclaredEnhancedFields(Produces.class).isEmpty()) { throw ValidatorLogger.LOG.decoratorsCannotHaveProducerFields(decorator); validateGeneralBean(decorator, manager); Decorators.findDelegateInjectionPoint(annotated, decorator.getInjectionPoints());
private void validateDecorators(BeanManagerImpl beanManager, DecorableBean<?> bean) { if (!(beanManager.isPassivatingScope(bean.getScope()) || bean instanceof AbstractDecorableBuiltInBean<?>)) { return; } List<Decorator<?>> decorators = bean.getDecorators(); if (decorators.isEmpty()) { return; } for (Decorator<?> decorator : decorators) { if (!Decorators.isPassivationCapable(decorator)) { if (bean instanceof AbstractDecorableBuiltInBean<?>) { throw ValidatorLogger.LOG.builtinBeanWithNonserializableDecorator(decorator, bean); } else { throw ValidatorLogger.LOG.passivatingBeanWithNonserializableDecorator(bean, decorator); } } if (decorator instanceof DecoratorImpl) { beanManager = ((DecoratorImpl<?>) decorator).getBeanManager(); } for (InjectionPoint ij : decorator.getInjectionPoints()) { if (!ij.isDelegate()) { Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(ij)); validateInterceptorDecoratorInjectionPointPassivationCapable(ij, resolvedBean, beanManager, bean); } } } }
/** * Determines the set of {@link InvokableAnnotatedMethod}s representing decorated methods of the specified decorator. A decorated method * is any method declared by a decorated type which is implemented by the decorator. * * @param beanManager the bean manager * @param decorator the specified decorator * @return the set of {@link InvokableAnnotatedMethod}s representing decorated methods of the specified decorator */ public static Set<InvokableAnnotatedMethod<?>> getDecoratorMethods(BeanManagerImpl beanManager, WeldDecorator<?> decorator) { ImmutableSet.Builder<InvokableAnnotatedMethod<?>> builder = ImmutableSet.builder(); for (Type type : decorator.getDecoratedTypes()) { EnhancedAnnotatedType<?> weldClass = getEnhancedAnnotatedTypeOfDecoratedType(beanManager, type); for (EnhancedAnnotatedMethod<?, ?> method : weldClass.getDeclaredEnhancedMethods()) { if (decorator.getEnhancedAnnotated().getEnhancedMethod(method.getSignature()) != null) { builder.add(InvokableAnnotatedMethod.of(method.slim())); } } } return builder.build(); }