private static Type bestType(Bean<?> bean) { if (bean == null) { return Object.class; } Class<?> bc = bean.getBeanClass(); if (bc != null) { return bc; } if (OwbBean.class.isInstance(bean)) { return OwbBean.class.cast(bean).getReturnType(); } return Object.class; }
@Override public String getId() { return ((OwbBean<?>) bean).getId(); }
private boolean isPassivationCapable(Bean<?> bean) { return bean instanceof OwbBean? ((OwbBean<?>)bean).isPassivationCapable(): bean instanceof PassivationCapable; }
/** * New WebBeans component class. * * @return the new component */ public <T> NewManagedBean<T> createNewComponent(OwbBean<T> bean, Class<T> type) { Asserts.assertNotNull(bean, "bean"); if (!EnumSet.of(WebBeansType.MANAGED, WebBeansType.ENTERPRISE, WebBeansType.PRODUCERMETHOD, WebBeansType.PRODUCERFIELD).contains(bean.getWebBeansType())) { throw new WebBeansConfigurationException("@New annotation on type : " + bean.getBeanClass() + " must defined as a simple or an enterprise web bean"); } AnnotatedType<T> annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(type); BeanAttributesImpl<T> newBeanAttributes = new BeanAttributesImpl<>(bean.getTypes(), Collections.<Annotation>singleton(new NewLiteral(type))); NewManagedBean<T> newBean = new NewManagedBean<>(bean.getWebBeansContext(), bean.getWebBeansType(), annotatedType, newBeanAttributes, type, bean.getInjectionPoints()); //TODO XXX set producer return newBean; }
if (bean instanceof OwbBean && !((OwbBean) bean).isEnabled()) if (proxyable != null) AbstractProducer producer = AbstractProducer.class.cast(OwbBean.class.cast(bean).getProducer()); AnnotatedType<?> annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(proxyable); producer.defineInterceptorStack(bean, annotatedType, webBeansContext); if (producer == null && owbBean.getProducer() instanceof AbstractProducer) producer = (AbstractProducer<T>) owbBean.getProducer(); annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(owbBean.getReturnType());
if (webBeansContext.getBeanManagerImpl().isNormalScope(bean.getScope())) Class<?> beanClass = bean.getReturnType();
@Override public boolean accept(final Bean<?> bean) { if (BuiltInOwbBean.class.isInstance(bean) || ExtensionBean.class.isInstance(bean)) { return false; } if (OwbBean.class.isInstance(bean)) { final OwbBean owbBean = OwbBean.class.cast(bean); if (owbBean.isPassivationCapable()) { if (hasBean(owbBean.getId())) { return false; } } } else if (PassivationCapable.class.isInstance(bean)) { if (hasBean(PassivationCapable.class.cast(bean).getId())) { return false; } } final Set<Annotation> qualifiers = bean.getQualifiers(); return beanManager.getBeans( bean.getBeanClass(), qualifiers.isEmpty() ? EMPTY_ANNOTATIONS : qualifiers.toArray(new Annotation[qualifiers.size()])).isEmpty(); }
/** * If bean is passivation capable, it validate all of its dependencies. * @throws org.apache.webbeans.exception.WebBeansConfigurationException if not satisfy passivation dependencies */ public <T> void validatePassivationCapable(OwbBean<T> bean) { if (isPassivationCapable(bean)) { if (EnterpriseBeanMarker.class.isInstance(bean)) { validatePassivationCapableDependencies(bean, bean.getInjectionPoints()); if (BeanInterceptorInfoProvider.class.isInstance(bean)) { validatePassivationCapableInterceptorInfo(bean, BeanInterceptorInfoProvider.class.cast(bean).interceptorInfo()); } return; } if (!(bean instanceof ProducerMethodBean)) { validatePassivationCapableDependencies(bean, bean.getInjectionPoints()); } if (bean.getProducer() instanceof InjectionTargetImpl) { InjectionTargetImpl<T> injectionTarget = (InjectionTargetImpl<T>)bean.getProducer(); BeanInterceptorInfo interceptorInfo = injectionTarget.getInterceptorInfo(); validatePassivationCapableInterceptorInfo(bean, interceptorInfo); } } }
private void initiateBeanBag(OwbBean<Object> bean, CreationalContext<Object> creationalContext) { Context webbeansContext = BeanManagerImpl.getManager().getContext(bean.getScope()); if (webbeansContext instanceof AbstractContext) { AbstractContext owbContext = (AbstractContext)webbeansContext; owbContext.initContextualBag(bean, creationalContext); } }
if (bean instanceof OwbBean) Producer<?> producer = ((OwbBean<?>)bean).getProducer(); if (producer instanceof AbstractProducer)
final Class<?> beanClass = OwbBean.class.isInstance(bean) ? OwbBean.class.cast(bean).getReturnType() : bean.getBeanClass();
public void addDecorator(Decorator decorator) { webBeansDecorators.add(decorator); if (decorator instanceof OwbBean) { OwbBean<?> owbBean = (OwbBean<?>)decorator; if(owbBean.isPassivationCapable()) { webBeansContext.getBeanManagerImpl().addPassivationInfo(decorator); } } }
/** * Check if the bean is has a passivation id and add it to the id store. * * @param bean * @throws DefinitionException if the id is not unique. */ public void addPassivationInfo(Bean<?> bean) throws DefinitionException { String id = null; if (bean instanceof OwbBean<?>) { id = ((OwbBean) bean).getId(); } if (id == null && bean instanceof PassivationCapable) { id = ((PassivationCapable) bean).getId(); } if(id != null) { Bean<?> oldBean = passivationBeans.putIfAbsent(id, bean); if (oldBean != null) { throw new DuplicateDefinitionException("PassivationCapable bean id is not unique: " + id + " bean:" + bean + ", existing: " + oldBean); } } }
final Class<?> beanClass = OwbBean.class.isInstance(bean) ? OwbBean.class.cast(bean).getReturnType() : bean.getBeanClass();
else if (OwbBean.class.isInstance(bean) && OwbBean.class.cast(bean).getReturnType() != null) classLoader = getProxyClassLoader(OwbBean.class.cast(bean).getReturnType()); if (bean instanceof OwbBean) classToProxy = ((OwbBean<T>) bean).getReturnType();
beanType = ((OwbBean) bean).getReturnType();