/** * Returns {@link EnhancedAnnotatedType} for the EJB implementation class. Throws {@link IllegalStateException} if called after bootstrap. * * @param bean * @throws IllegalStateException if called after bootstrap * @return {@link EnhancedAnnotatedType} representation of this EJB's implementation class */ public static <T> EnhancedAnnotatedType<T> getEjbImplementationClass(SessionBean<T> bean) { return getEjbImplementationClass(bean.getEjbDescriptor(), bean.getBeanManager(), bean.getEnhancedAnnotated()); }
AnnotatedType<?> type = beanManager.createAnnotatedType(interceptor); @SuppressWarnings("rawtypes") InjectionTarget injectionTarget = beanManager.getInjectionTargetFactory(type).createInterceptorInjectionTarget(); interceptorInjections.put(interceptor, beanManager.fireProcessInjectionTarget(type, injectionTarget)); this.injectionTarget = sessionBean.getProducer(); return; beanManager.getServices().get(InjectionTargetService.class).validateProducer(injectionTarget);
if (sessionBean.getEjbDescriptor().getEjbName() != null) { beanBuilder.add(EJB_NAME, true); beanBuilder.add(SESSION_BEAN_TYPE, Components.getSessionBeanType(sessionBean.getEjbDescriptor()).toString()); } else if (bean instanceof AbstractProducerBean) { if (BeanKind.INTERCEPTOR.equals(kind) || BeanKind.DECORATOR.equals(kind) || bean.isAlternative()) { JsonObjectBuilder enablementBuilder = Json.objectBuilder(); AnnotationApiAbstraction annotationApi = beanManager.getServices().get(AnnotationApiAbstraction.class); Object priority = bean.getBeanClass().getAnnotation(annotationApi.PRIORITY_ANNOTATION_CLASS); if (priority != null) { Collection<BeanManagerImpl> beanManagers = Container.instance(beanManager).beanDeploymentArchives().values(); for (BeanManagerImpl manager : beanManagers) { ModuleEnablement enablement = manager.getEnabled(); if ((BeanKind.INTERCEPTOR.equals(kind) && enablement.isInterceptorEnabled(bean.getBeanClass())) || (BeanKind.DECORATOR.equals(kind) && enablement.isDecoratorEnabled(bean.getBeanClass())) || isSelectedAlternative(enablement, bean)) { bdasBuilder.add(createSimpleBdaJson(manager.getId())); beanBuilder.add(DELEGATE_TYPE, Formats.formatType(decorator.getDelegateType(), false)); beanBuilder.add(DELEGATE_QUALIFIERS, createQualifiers(decorator.getDelegateQualifiers(), false)); JsonArrayBuilder decoratedTypes = Json.arrayBuilder(true); for (Type type : decorator.getDecoratedTypes()) { decoratedTypes.add(Formats.formatType(type, false));
private void addBean(Bean<?> bean, List<Bean<?>> beanList, List<Bean<?>> transitiveBeans) { if (beanSet.add(bean)) { if (bean.isAlternative() && (!registry.isEnabledInAnyBeanDeployment(bean) && !(bean instanceof Prioritized)) && !isConfiguratorBeanWithPriority(bean)) { BootstrapLogger.LOG.foundDisabledAlternative(bean); } else if (registry.isSpecializedInAnyBeanDeployment(bean)) { BootstrapLogger.LOG.foundSpecializedBean(bean); } else if (bean instanceof AbstractProducerBean<?, ?, ?> && registry.isSpecializedInAnyBeanDeployment(((AbstractProducerBean<?, ?, ?>) bean).getDeclaringBean())) { BootstrapLogger.LOG.foundProducerOfSpecializedBean(bean); specializedBeans.add(bean); } else { BootstrapLogger.LOG.foundBean(bean); beanList.add(bean); if (bean instanceof SessionBean) { SessionBean<?> enterpriseBean = (SessionBean<?>) bean; enterpriseBeans.put(enterpriseBean.getEjbDescriptor(), enterpriseBean); } if (bean instanceof PassivationCapable) { getServices().get(ContextualStore.class).putIfAbsent(bean); } registerBeanNamespace(bean); // New beans (except for SessionBeans) and most built in beans aren't resolvable transitively if (bean instanceof ExtensionBean || bean instanceof SessionBean || (!(bean instanceof NewBean) && !(bean instanceof AbstractBuiltInBean<?>))) { transitiveBeans.add(bean); } } } }
@Override public <T> InjectionTarget<T> createInjectionTarget(EjbDescriptor<T> descriptor) { if (descriptor.isMessageDriven()) { AnnotatedType<T> type = Reflections.cast(createAnnotatedType(descriptor.getBeanClass())); return getLocalInjectionTargetFactory(type).createMessageDrivenInjectionTarget(descriptor); } else { InjectionTarget<T> injectionTarget = getBean(descriptor).getProducer(); return injectionTarget; } }
public SessionBeanType getSessionBeanType() { checkWithinObserverNotification(); if (getBean().getEjbDescriptor().isStateless()) { return SessionBeanType.STATELESS; } else if (getBean().getEjbDescriptor().isStateful()) { return SessionBeanType.STATEFUL; } else if (getBean().getEjbDescriptor().isSingleton()) { return SessionBeanType.SINGLETON; } else { throw BootstrapLogger.LOG.beanTypeNotEjb(getBean()); } }
public String getEjbName() { checkWithinObserverNotification(); return getBean().getEjbDescriptor().getEjbName(); }
private void checkDisposalMethod(EnhancedAnnotatedMethod<T, ? super X> enhancedAnnotatedMethod, AbstractClassBean<X> declaringBean) { if (enhancedAnnotatedMethod.getEnhancedParameters(Disposes.class).size() > 1) { throw BeanLogger.LOG .multipleDisposeParams(disposalMethodInjectionPoint, Formats.formatAsStackTraceElement(enhancedAnnotatedMethod.getJavaMember())); throw BeanLogger.LOG.inconsistentAnnotationsOnMethod("@Observes", DISPOSER_ANNOTATION, disposalMethodInjectionPoint, Formats.formatAsStackTraceElement(enhancedAnnotatedMethod.getJavaMember())); throw BeanLogger.LOG.inconsistentAnnotationsOnMethod("@Inject", DISPOSER_ANNOTATION, disposalMethodInjectionPoint, Formats.formatAsStackTraceElement(enhancedAnnotatedMethod.getJavaMember())); Set<MethodSignature> localBusinessMethodSignatures = sessionBean.getLocalBusinessMethodSignatures(); Set<MethodSignature> remoteBusinessMethodSignatures = sessionBean.getRemoteBusinessMethodSignatures(); if (!localBusinessMethodSignatures.contains(enhancedAnnotatedMethod.getSignature()) || remoteBusinessMethodSignatures .contains(enhancedAnnotatedMethod.getSignature())) {
protected void registerInterceptors() { InterceptionModel model = beanManager.getInterceptorModelRegistry().get(getAnnotated()); if (model != null) { getBeanManager().getServices().get(EjbServices.class).registerInterceptors(getEjbDescriptor().delegate(), new InterceptorBindingsAdapter(model)); } } }
@Override protected void checkType() { if (!isDependent() && getEnhancedAnnotated().isGeneric()) { throw BeanLogger.LOG.genericSessionBeanMustBeDependent(this); } boolean passivating = beanManager.getServices().get(MetaAnnotationStore.class).getScopeModel(getScope()).isPassivating(); if (passivating && !isPassivationCapableBean()) { throw BeanLogger.LOG.passivatingBeanNeedsSerializableImpl(this); } }
@Override public void initializeAfterBeanDiscovery(EnhancedAnnotatedType<T> annotatedType) { initializeInterceptionModel(annotatedType); List<Decorator<?>> decorators = beanManager.resolveDecorators(getBean().getTypes(), getBean().getQualifiers()); if (!decorators.isEmpty()) { Instantiator<T> instantiator = getInstantiator(); EnhancedAnnotatedType<T> implementationClass = SessionBeans.getEjbImplementationClass(getBean()); instantiator = SubclassedComponentInstantiator.forInterceptedDecoratedBean(implementationClass, getBean(), (AbstractInstantiator<T>) instantiator, beanManager); instantiator = new SubclassDecoratorApplyingInstantiator<T>(getBeanManager().getContextId(), instantiator, getBean(), decorators, implementationClass.getJavaClass()); setInstantiator(instantiator); } /* * We only take care of @AroundConstructor interception. The EJB container deals with the other types of interception. */ setupConstructorInterceptionInstantiator(beanManager.getInterceptorModelRegistry().get(getType())); }
public SessionObjectReference createReference() { try { SessionBeanInjectionPoint.registerContextualInstance(getEjbDescriptor()); return beanManager.getServices().get(EjbServices.class).resolveEjb(getEjbDescriptor().delegate()); } finally { SessionBeanInjectionPoint.unregisterContextualInstance(getEjbDescriptor()); } }
public AnnotatedType<Object> getAnnotatedBeanClass() { checkWithinObserverNotification(); return getBean().getAnnotated(); }
@Override public T newInstance(CreationalContext<T> ctx, BeanManagerImpl manager) { try { T instance = AccessController.doPrivileged(NewInstanceAction.of(proxyClass)); if (!bean.getScope().equals(Dependent.class)) { ctx.push(instance); } ProxyFactory.setBeanInstance(bean.getBeanManager().getContextId(), instance, createEnterpriseTargetBeanInstance(), bean); return instance; } catch (PrivilegedActionException e) { if (e.getCause() instanceof InstantiationException) { throw new WeldException(BeanLogger.LOG.proxyInstantiationFailed(this), e.getCause()); } else if (e.getCause() instanceof IllegalAccessException) { throw new WeldException(BeanLogger.LOG.proxyInstantiationBeanAccessFailed(this), e.getCause()); } else { throw new WeldException(e.getCause()); } } catch (Exception e) { throw BeanLogger.LOG.sessionBeanProxyInstantiationFailed(bean, proxyClass, e); } }
/** * Produces a factory for a specific bean implementation. * * @param proxiedBeanType the actual enterprise bean */ public EnterpriseProxyFactory(Class<T> proxiedBeanType, SessionBean<T> bean) { super(bean.getBeanManager().getContextId(), proxiedBeanType, ImmutableSet.<Type> builder().addAll(bean.getTypes()) .addAll(bean.getEjbDescriptor().getRemoteBusinessInterfacesAsClasses()).build(), bean); }
public static <T> SessionBeanInjectionTarget<T> of(EnhancedAnnotatedType<T> type, SessionBean<T> bean, BeanManagerImpl beanManager) { LifecycleCallbackInvoker<T> invoker = DefaultLifecycleCallbackInvoker.of(type); Injector<T> injector; if (bean.getEjbDescriptor().isStateless() || bean.getEjbDescriptor().isSingleton()) { injector = new DynamicInjectionPointInjector<T>(type, bean, beanManager); } else { injector = new DefaultInjector<T>(type, bean, beanManager); } return new SessionBeanInjectionTarget<T>(type, bean, beanManager, injector, invoker); }
public String getEjbName() { checkWithinObserverNotification(); return getBean().getEjbDescriptor().getEjbName(); }
@Override public String toString() { return "Session bean [" + getBeanClass() + " with qualifiers [" + Formats.formatAnnotations(getQualifiers()) + "]; local interfaces are [" + Formats.formatBusinessInterfaceDescriptors(getEjbDescriptor().getLocalBusinessInterfaces()) + "]"; }
private ProcessSessionBeanImpl(BeanManagerImpl beanManager, SessionBean<Object> bean) { super(beanManager, ProcessSessionBean.class, new Type[]{bean.getAnnotated().getBaseType()}, bean); }
/** * Constructor used directly by {@link #readResolve()}. * * @param bean the session bean * @param reference session object reference or {@code null} to create a new reference */ private EnterpriseBeanProxyMethodHandler(SessionBean<T> bean, SessionObjectReference reference) { this.bean = bean; this.manager = bean.getBeanManager(); this.beanId = bean.getIdentifier(); Map<Class<?>, Class<?>> typeToBusinessInterfaceMap = new HashMap<Class<?>, Class<?>>(); discoverBusinessInterfaces(typeToBusinessInterfaceMap, bean.getEjbDescriptor().getRemoteBusinessInterfacesAsClasses()); discoverBusinessInterfaces(typeToBusinessInterfaceMap, bean.getEjbDescriptor().getLocalBusinessInterfacesAsClasses()); this.typeToBusinessInterfaceMap = ImmutableMap.copyOf(typeToBusinessInterfaceMap); if (reference == null) { this.reference = bean.createReference(); BeanLogger.LOG.createdSessionBeanProxy(bean); } else { this.reference = reference; BeanLogger.LOG.activatedSessionBeanProxy(bean); } }