public static <T> BeanInjectionTarget<T> createDefault(EnhancedAnnotatedType<T> type, Bean<T> bean, BeanManagerImpl beanManager) { return new BeanInjectionTarget<T>(type, bean, beanManager); }
protected void initializeInterceptionModel(EnhancedAnnotatedType<T> annotatedType) { AbstractInstantiator<T> instantiator = (AbstractInstantiator<T>) getInstantiator(); if (instantiator.getConstructorInjectionPoint() == null) { return; // this is a non-producible InjectionTarget (only created to inject existing instances) } if (isInterceptionCandidate() && !beanManager.getInterceptorModelRegistry().containsKey(getType())) { buildInterceptionModel(annotatedType, instantiator); } }
@Override public void initializeAfterBeanDiscovery(EnhancedAnnotatedType<T> annotatedType) { initializeInterceptionModel(annotatedType); if (isInterceptionCandidate()) { interceptionModel = beanManager.getInterceptorModelRegistry().get(getType()); if (getBean() != null && isInterceptionCandidate()) { decorators = beanManager.resolveDecorators(getBean().getTypes(), getBean().getQualifiers()); checkDecoratedMethods(annotatedType, decorators); if (!(getInstantiator() instanceof DefaultInstantiator<?>)) { throw new java.lang.IllegalStateException("Unexpected instantiator " + getInstantiator()); DefaultInstantiator<T> delegate = (DefaultInstantiator<T>) getInstantiator(); setInstantiator(SubclassedComponentInstantiator.forInterceptedDecoratedBean(annotatedType, getBean(), delegate, beanManager)); if (hasDecorators) { setInstantiator(new SubclassDecoratorApplyingInstantiator<T>(getBeanManager().getContextId(), getInstantiator(), getBean(), decorators)); setInstantiator(new InterceptorApplyingInstantiator<T>(getInstantiator(), interceptionModel, getType())); if (isInterceptionCandidate()) { setupConstructorInterceptionInstantiator(interceptionModel);
protected boolean isInterceptor() { return (getBean() instanceof Interceptor<?>) || getType().isAnnotationPresent(javax.interceptor.Interceptor.class); }
protected boolean isInterceptionCandidate() { return !isInterceptor() && !isDecorator() && !Modifier.isAbstract(getType().getJavaClass().getModifiers()); }
protected void checkDecoratedMethods(EnhancedAnnotatedType<T> type, List<Decorator<?>> decorators) { if (type.isFinal()) { throw BeanLogger.LOG.finalBeanClassWithDecoratorsNotAllowed(this); } checkNoArgsConstructor(type); for (Decorator<?> decorator : decorators) { EnhancedAnnotatedType<?> decoratorClass; if (decorator instanceof DecoratorImpl<?>) { DecoratorImpl<?> decoratorBean = (DecoratorImpl<?>) decorator; decoratorClass = decoratorBean.getBeanManager().getServices().get(ClassTransformer.class).getEnhancedAnnotatedType(decoratorBean.getAnnotated()); } else if (decorator instanceof CustomDecoratorWrapper<?>) { decoratorClass = ((CustomDecoratorWrapper<?>) decorator).getEnhancedAnnotated(); } else { throw BeanLogger.LOG.nonContainerDecorator(decorator); } for (EnhancedAnnotatedMethod<?, ?> decoratorMethod : decoratorClass.getEnhancedMethods()) { EnhancedAnnotatedMethod<?, ?> method = type.getEnhancedMethod(decoratorMethod.getSignature()); if (method != null && !method.isStatic() && !method.isPrivate() && method.isFinal()) { throw BeanLogger.LOG.finalBeanClassWithInterceptorsNotAllowed(this); } } } }
private BasicInjectionTarget<T> chooseInjectionTarget(EnhancedAnnotatedType<T> type, Bean<T> bean, boolean interceptor) { if (bean instanceof Decorator<?> || type.isAnnotationPresent(javax.decorator.Decorator.class)) { return new DecoratorInjectionTarget<T>(type, bean, manager); } NonProducibleInjectionTarget<T> nonProducible = InjectionTargets.createNonProducibleInjectionTarget(type, bean, manager); if (nonProducible != null) { return nonProducible; } if (bean instanceof SessionBean<?>) { return manager.getServices().get(EjbSupport.class).createSessionBeanInjectionTarget(type, (SessionBean<T>) bean, manager); } if (bean instanceof Interceptor<?> || type.isAnnotationPresent(javax.interceptor.Interceptor.class)) { return BeanInjectionTarget.forCdiInterceptor(type, bean, manager); } if (interceptor) { return BasicInjectionTarget.createNonCdiInterceptor(type, manager); } return BeanInjectionTarget.createDefault(type, bean, manager); }
protected void buildInterceptionModel(EnhancedAnnotatedType<T> annotatedType, AbstractInstantiator<T> instantiator) { new InterceptionModelInitializer<T>(beanManager, annotatedType, annotatedType.getDeclaredEnhancedConstructor(instantiator.getConstructorInjectionPoint().getSignature()), getBean()).init(); }
protected void setupConstructorInterceptionInstantiator(InterceptionModel interceptionModel) { if (interceptionModel != null && interceptionModel.hasExternalConstructorInterceptors()) { setInstantiator(new ConstructorInterceptionInstantiator<T>(getInstantiator(), interceptionModel, getType())); } }
private BasicInjectionTarget<T> chooseInjectionTarget(EnhancedAnnotatedType<T> type, Bean<T> bean, boolean interceptor) { if (bean instanceof Decorator<?> || type.isAnnotationPresent(javax.decorator.Decorator.class)) { return new DecoratorInjectionTarget<T>(type, bean, manager); } NonProducibleInjectionTarget<T> nonProducible = InjectionTargets.createNonProducibleInjectionTarget(type, bean, manager); if(nonProducible != null) { return nonProducible; } if (bean instanceof SessionBean<?>) { return SessionBeanInjectionTarget.of(type, (SessionBean<T>) bean, manager); } if (bean instanceof Interceptor<?> || type.isAnnotationPresent(javax.interceptor.Interceptor.class)) { return BeanInjectionTarget.forCdiInterceptor(type, bean, manager); } if (interceptor) { return BasicInjectionTarget.createNonCdiInterceptor(type, manager); } return BeanInjectionTarget.createDefault(type, bean, manager); }
protected void buildInterceptionModel(EnhancedAnnotatedType<T> annotatedType, AbstractInstantiator<T> instantiator) { new InterceptionModelInitializer<T>(beanManager, annotatedType, instantiator.getConstructorInjectionPoint().getAnnotated(), getBean()).init(); }
@Override public T produce(CreationalContext<T> ctx) { T instance = super.produce(ctx); if (bean != null && !bean.getScope().equals(Dependent.class) && !getInstantiator().hasDecoratorSupport()) { // This should be safe, but needs verification PLM // Without this, the chaining of decorators will fail as the // incomplete instance will be resolved ctx.push(instance); } return instance; }
protected void checkDecoratedMethods(EnhancedAnnotatedType<T> type, List<Decorator<?>> decorators) { if (type.isFinal()) { throw BeanLogger.LOG.finalBeanClassWithDecoratorsNotAllowed(this); } checkNoArgsConstructor(type); for (Decorator<?> decorator : decorators) { EnhancedAnnotatedType<?> decoratorClass; if (decorator instanceof DecoratorImpl<?>) { DecoratorImpl<?> decoratorBean = (DecoratorImpl<?>) decorator; decoratorClass = decoratorBean.getBeanManager().getServices().get(ClassTransformer.class).getEnhancedAnnotatedType(decoratorBean.getAnnotated()); } else if (decorator instanceof CustomDecoratorWrapper<?>) { decoratorClass = ((CustomDecoratorWrapper<?>) decorator).getEnhancedAnnotated(); } else { throw BeanLogger.LOG.nonContainerDecorator(decorator); } for (EnhancedAnnotatedMethod<?, ?> decoratorMethod : decoratorClass.getEnhancedMethods()) { EnhancedAnnotatedMethod<?, ?> method = type.getEnhancedMethod(decoratorMethod.getSignature()); if (method != null && !method.isStatic() && !method.isPrivate() && method.isFinal()) { throw BeanLogger.LOG.finalBeanClassWithInterceptorsNotAllowed(this); } } } }
private BasicInjectionTarget<T> chooseInjectionTarget(EnhancedAnnotatedType<T> type, Bean<T> bean, boolean interceptor) { if (bean instanceof Decorator<?> || type.isAnnotationPresent(javax.decorator.Decorator.class)) { return new DecoratorInjectionTarget<T>(type, bean, manager); } NonProducibleInjectionTarget<T> nonProducible = InjectionTargets.createNonProducibleInjectionTarget(type, bean, manager); if (nonProducible != null) { return nonProducible; } if (bean instanceof SessionBean<?>) { return manager.getServices().get(EjbSupport.class).createSessionBeanInjectionTarget(type, (SessionBean<T>) bean, manager); } if (bean instanceof Interceptor<?> || type.isAnnotationPresent(javax.interceptor.Interceptor.class)) { return BeanInjectionTarget.forCdiInterceptor(type, bean, manager); } if (interceptor) { return BasicInjectionTarget.createNonCdiInterceptor(type, manager); } return BeanInjectionTarget.createDefault(type, bean, manager); }
protected boolean isInterceptor() { return (getBean() instanceof Interceptor<?>) || getType().isAnnotationPresent(javax.interceptor.Interceptor.class); }
protected boolean isInterceptionCandidate() { return !isInterceptor() && !isDecorator() && !Modifier.isAbstract(getType().getJavaClass().getModifiers()); }
protected void buildInterceptionModel(EnhancedAnnotatedType<T> annotatedType, AbstractInstantiator<T> instantiator) { new InterceptionModelInitializer<T>(beanManager, annotatedType, annotatedType.getDeclaredEnhancedConstructor(instantiator.getConstructorInjectionPoint().getSignature()), getBean()).init(); }
protected void setupConstructorInterceptionInstantiator(InterceptionModel interceptionModel) { if (interceptionModel != null && interceptionModel.hasExternalConstructorInterceptors()) { setInstantiator(new ConstructorInterceptionInstantiator<T>(getInstantiator(), interceptionModel, getType())); } }
@Override public T produce(CreationalContext<T> ctx) { T instance = super.produce(ctx); if (bean != null && !bean.getScope().equals(Dependent.class) && !getInstantiator().hasDecoratorSupport()) { // This should be safe, but needs verification PLM // Without this, the chaining of decorators will fail as the // incomplete instance will be resolved ctx.push(instance); } return instance; }
@Override public void initializeAfterBeanDiscovery(EnhancedAnnotatedType<T> annotatedType) { initializeInterceptionModel(annotatedType); if (isInterceptionCandidate()) { interceptionModel = beanManager.getInterceptorModelRegistry().get(getType()); if (getBean() != null && isInterceptionCandidate()) { decorators = beanManager.resolveDecorators(getBean().getTypes(), getBean().getQualifiers()); checkDecoratedMethods(annotatedType, decorators); if (!(getInstantiator() instanceof DefaultInstantiator<?>)) { throw new java.lang.IllegalStateException("Unexpected instantiator " + getInstantiator()); DefaultInstantiator<T> delegate = (DefaultInstantiator<T>) getInstantiator(); setInstantiator(SubclassedComponentInstantiator.forInterceptedDecoratedBean(annotatedType, getBean(), delegate, beanManager)); if (hasDecorators) { setInstantiator(new SubclassDecoratorApplyingInstantiator<T>(getBeanManager().getContextId(), getInstantiator(), getBean(), decorators)); setInstantiator(new InterceptorApplyingInstantiator<T>(getInstantiator(), interceptionModel, getType())); if (isInterceptionCandidate()) { setupConstructorInterceptionInstantiator(interceptionModel);