@Override public ContextHandle createContextHandle() { final BeanManagerImpl beanManager = getBeanManager(); return () -> { if (beanManager == null || beanManager.isContextActive(RequestScoped.class)) { return () -> { }; } final RequestContext requestContext = beanManager.instance().select(RequestContext.class, UnboundLiteral.INSTANCE).get(); requestContext.activate(); return () -> { requestContext.invalidate(); requestContext.deactivate(); }; }; }
interceptionModel = beanManager.getInterceptorModelRegistry().get(getType()); decorators = beanManager.resolveDecorators(getBean().getTypes(), getBean().getQualifiers()); getBeanManager().getContextId(), getInstantiator(), getBean(), decorators));
private 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 InterceptorBindings getInterceptorBindings(final String ejbName, final BeanManagerImpl manager) { InterceptorBindings retVal = null; if (ejbName != null) { retVal = interceptorSupport.getInterceptorBindings(ejbName, manager); } else { // This is a managed bean SlimAnnotatedType<?> type = (SlimAnnotatedType<?>) manager.createAnnotatedType(componentClass); if (!manager.getInterceptorModelRegistry().containsKey(type)) { EnhancedAnnotatedType<?> enhancedType = manager.getServices().get(ClassTransformer.class).getEnhancedAnnotatedType(type); InterceptionModelInitializer.of(manager, enhancedType, null).init(); } InterceptionModel model = manager.getInterceptorModelRegistry().get(type); if (model != null) { retVal = new InterceptorBindingsAdapter(manager.getInterceptorModelRegistry().get(type)); } } return retVal != null ? retVal : NullInterceptorBindings.INSTANCE; }
private void addInterceptorInstance(Interceptor<Object> interceptor, BeanManagerImpl beanManager, Map<String, SerializableContextualInstance<Interceptor<Object>, Object>> instances, final CreationalContext<Object> creationalContext) { Object instance = beanManager.getReference(interceptor, interceptor.getBeanClass(), creationalContext, true); SerializableContextualInstance<Interceptor<Object>, Object> serializableContextualInstance = beanManager.getServices().get(ContextualStore.class).<Interceptor<Object>, Object>getSerializableContextualInstance(interceptor, instance, creationalContext); instances.put(interceptor.getBeanClass().getName(), serializableContextualInstance); }
@Override T get(Bean<T> bean, BeanManagerImpl manager, CreationalContext<?> ctx) { Context context = manager.getContext(bean.getScope()); T instance = context.get(bean); if (instance == null) { if (ctx == null) { ctx = manager.createCreationalContext(bean); } instance = context.get(bean, Reflections.<CreationalContext<T>> cast(ctx)); } return instance; }
private InjectionTarget getInjectionTarget(Class<?> clazz) { InjectionTarget<?> target = injectionTargets.get(clazz); if (target != null) { return target; } final BeanManagerImpl beanManager = BeanManagerProxy.unwrap(beanManagerSupplier.get()); Bean<?> bean = null; Set<Bean<?>> beans = new HashSet<>(beanManager.getBeans(clazz, Any.Literal.INSTANCE)); Iterator<Bean<?>> it = beans.iterator(); //we may have resolved some sub-classes //go through and remove them from the bean set while (it.hasNext()) { Bean<?> b = it.next(); if(b.getBeanClass() != clazz) { it.remove(); } } if(beans.size() == 1) { bean = beans.iterator().next(); } InjectionTarget<?> newTarget = InjectionTargets.createInjectionTarget(clazz, bean, beanManager, true); target = injectionTargets.putIfAbsent(clazz, newTarget); if (target == null) { return newTarget; } else { return target; } }
Set<Bean<?>> beans = beanManager.getBeans(beanClass, new AnnotationLiteral<Any>() {}); if (bean.getBeanClass().isInterface()) { continue; LOGGER.debug("Skipping bean redefinition. Bean '{}' signature was not changed.", bean.getBeanClass().getName()); continue; if (!eat.isAbstract() || !eat.getJavaClass().isInterface()) { // injectionTargetCannotBeCreatedForInterface ((AbstractClassBean)bean).setProducer(beanManager.getLocalInjectionTargetFactory(eat).createInjectionTarget(eat, bean, false)); if (isReinjectingContext(bean)) { doReloadAbstractClassBean(beanManager, (AbstractClassBean) bean, oldSignatures, reloadStrategy); LOGGER.debug("Bean reloaded '{}'", bean.getBeanClass().getName()); continue;
private CustomDecoratorWrapper(Decorator<T> delegate, BeanManagerImpl beanManager) { this.delegate = delegate; this.weldClass = beanManager.getServices().get(ClassTransformer.class).getEnhancedAnnotatedType(Reflections.<Class<T>>cast(delegate.getBeanClass()), beanManager.getId()); this.decoratedMethods = new DecoratedMethods(beanManager, this); }
protected AnnotatedTypeLoader createAnnotatedTypeLoader() { if (classFileServices != null) { // Since FastProcessAnnotatedTypeResolver is installed after BeanDeployers are created, we need to query deploymentManager's services instead of the manager of this deployer final FastProcessAnnotatedTypeResolver resolver = Container.instance(getManager()).deploymentManager().getServices() .get(FastProcessAnnotatedTypeResolver.class); if (resolver != null) { return new FastAnnotatedTypeLoader(getManager(), classTransformer, classFileServices, containerLifecycleEvents, resolver); } } // if FastProcessAnnotatedTypeResolver is not available, fall back to AnnotatedTypeLoader return new AnnotatedTypeLoader(getManager(), classTransformer, containerLifecycleEvents); }
public void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager beanManager) { BeanManagerImpl weldManager = BeanManagerProxy.unwrap(beanManager); String exclude = weldManager.getServices().get(WeldConfiguration.class).getStringProperty(ConfigurationKey.PROBE_EVENT_MONITOR_EXCLUDE_TYPE); event.addObserverMethod(new ProbeObserver(weldManager, exclude.isEmpty() ? null : Pattern.compile(exclude), probe)); addContainerLifecycleEvent(event, null, beanManager); }
public InjectionTargetService(BeanManagerImpl beanManager) { this.validator = beanManager.getServices().get(Validator.class); this.producersToValidate = new ConcurrentLinkedQueue<Producer<?>>(); this.injectionTargetsToInitialize = new ConcurrentLinkedQueue<InjectionTargetInitializationContext<?>>(); this.container = Container.instance(beanManager); this.beanManager = beanManager; }
public T call() throws Exception { if (instance == null) { Contextual<T> contextual = getBeanManager().getServices().get(ContextualStore.class).<Contextual<T>, T>getContextual(beanId); if (contextual instanceof EEResourceProducerField<?, ?>) { this.instance = Reflections.<EEResourceProducerField<?, T>>cast(contextual).createUnderlying(creationalContext); } else { throw BeanLogger.LOG.beanNotEeResourceProducer(contextual); } } return instance; }
@Override public void addQualifier(Class<? extends Annotation> bindingType) { checkWithinObserverNotification(); getTypeStore().add(bindingType, QualifierLiteral.INSTANCE); getBeanManager().getServices().get(ClassTransformer.class).clearAnnotationData(bindingType); getBeanManager().getServices().get(MetaAnnotationStore.class).clearAnnotationData(bindingType); BootstrapLogger.LOG.addQualifierCalled(getReceiver(), bindingType); }
private <A extends Annotation> void addSyntheticAnnotation(AnnotatedType<A> annotation, Annotation requiredMetaAnnotation) { if (requiredMetaAnnotation != null && !annotation.isAnnotationPresent(requiredMetaAnnotation.annotationType())) { // Add required meta annotation annotation = new AnnotatedTypeWrapper<A>(annotation, requiredMetaAnnotation); } getBeanManager().getServices().get(ClassTransformer.class).addSyntheticAnnotation(annotation, getBeanManager().getId()); getBeanManager().getServices().get(MetaAnnotationStore.class).clearAnnotationData(annotation.getJavaClass()); } }
protected EnhancedAnnotatedConstructor<T> initEnhancedSubclass(BeanManagerImpl manager, EnhancedAnnotatedType<T> type, Bean<?> bean, ConstructorInjectionPoint<T> originalConstructorInjectionPoint) { ClassTransformer transformer = manager.getServices().get(ClassTransformer.class); EnhancedAnnotatedType<T> enhancedSubclass = transformer.getEnhancedAnnotatedType(createEnhancedSubclass(type, bean, manager), type.slim().getIdentifier().getBdaId()); return findMatchingConstructor(originalConstructorInjectionPoint.getSignature(), enhancedSubclass); }
final ClassTransformer transformer = beanManager.getServices().get(ClassTransformer.class); @SuppressWarnings("unchecked") final Class<T> clazz = (Class<T>) componentClass; EnhancedAnnotatedType<T> type = transformer.getEnhancedAnnotatedType(clazz, beanManager.getId()); if (!type.getJavaClass().equals(componentClass)) { final String bdaId = beanManager.getId() + classLoader.hashCode(); type = transformer.getEnhancedAnnotatedType(clazz, bdaId); return beanManager.getInjectionTargetFactory(type).createNonProducibleInjectionTarget(); WeldInjectionTargetBuilder<T> builder = beanManager.createInjectionTargetBuilder(type); builder.setBean(bean); builder.setResourceInjectionEnabled(false); // because these are all EE components where resource injection is not handled by Weld
AnnotatedType<?> type = beanManager.createAnnotatedType(interceptor); @SuppressWarnings("rawtypes") InjectionTarget injectionTarget = beanManager.getInjectionTargetFactory(type).createInterceptorInjectionTarget(); interceptorInjections.put(interceptor, beanManager.fireProcessInjectionTarget(type, injectionTarget)); EjbDescriptor<Object> descriptor = beanManager.getEjbDescriptor(ejbName); bean = beanManager.getBean(descriptor); beanManager.getServices().get(InjectionTargetService.class).validateProducer(injectionTarget);
private RequestContext getUnboundRequestContext() { final Bean<?> bean = beanManager.resolve(beanManager.getBeans(RequestContext.class, UnboundLiteral.INSTANCE)); final CreationalContext<?> ctx = beanManager.createCreationalContext(bean); return (RequestContext) beanManager.getReference(bean, RequestContext.class, ctx); }
InjectionPointPropagatingEnterpriseTargetBeanInstance(Class<?> baseType, MethodHandler methodHandler, BeanManagerImpl manager) { super(baseType, methodHandler); this.contextId = manager.getContextId(); this.currentInvocationInjectionPoint = manager.getServices().get(CurrentInvocationInjectionPoint.class); InjectionPoint ip = manager.getServices().get(CurrentInjectionPoint.class).peek(); if (ip != null) { this.injectionPointHolder = new InjectionPointHolder(manager.getContextId(), ip); } else { this.injectionPointHolder = null; } }