Package org.apache.webbeans.container

Examples of org.apache.webbeans.container.BeanManagerImpl


     * @return true if given class is configured as a managed bean
     */
    protected <T> boolean defineManagedBean(Class<T> clazz, ProcessAnnotatedTypeImpl<T> processAnnotatedEvent)
    {  
        //Bean manager
        BeanManagerImpl manager = BeanManagerImpl.getManager();
       
        //Create an annotated type
        AnnotatedType<T> annotatedType = processAnnotatedEvent.getAnnotatedType();
                               
        //Fires ProcessInjectionTarget event for Java EE components instances
        //That supports injections but not managed beans
        ProcessInjectionTargetImpl<T> processInjectionTargetEvent = null;
        if(WebBeansUtil.supportsJavaEeComponentInjections(clazz))
        {
            //Fires ProcessInjectionTarget
            processInjectionTargetEvent = WebBeansUtil.fireProcessInjectionTargetEventForJavaEeComponents(clazz);   
            WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessInjectionTarget event observers. Look at logs for further details");
           
            //Sets custom InjectionTarget instance
            if(processInjectionTargetEvent.isSet())
            {
                //Adding injection target
                manager.putInjectionTargetWrapperForJavaEeComponents(clazz, new InjectionTargetWrapper<T>(processInjectionTargetEvent.getInjectionTarget()));               
            }
           
            //Checks that not contains @Inject InjectionPoint
            OWBInjector.checkInjectionPointForInjectInjectionPoint(clazz);
        }
View Full Code Here


                return contextualInstance;
            }

            //Manager instance
            BeanManagerImpl manager = elContextStore.getBeanManager();

            //Get beans
            Set<Bean<?>> beans = manager.getBeans(name);

            //Found?
            if(beans != null && !beans.isEmpty())
            {
                //Managed bean
View Full Code Here

            interceptor = ownerCreationalContext.getDependentInterceptor(ownerInstance, this.webBeansInterceptor);
            // There is no define interceptor, define and add it into dependent
            if (interceptor == null)
            {
                BeanManagerImpl manager = BeanManagerImpl.getManager();

                WebBeansInterceptor<Object> actualInterceptor = (WebBeansInterceptor<Object>) this.webBeansInterceptor;
                CreationalContext<Object> creationalContext = manager.createCreationalContext(actualInterceptor);
                interceptor = manager.getReference(actualInterceptor, actualInterceptor.getBeanClass(), creationalContext);

                actualInterceptor.setInjections(interceptor, creationalContext);

                ownerCreationalContext.addDependent(ownerInstance, (WebBeansInterceptor<Object>) this.webBeansInterceptor, interceptor);
            }
View Full Code Here

        return ((OwbBean) bean).isDependent();
    }

    public static void inspectErrorStack(String logMessage)
    {
        BeanManagerImpl manager = BeanManagerImpl.getManager();
        //Looks for errors
        ErrorStack stack = manager.getErrorStack();
        try
        {
            if(stack.hasErrors())
            {
                stack.logErrors();
View Full Code Here


    public static <T> ManagedBean<T> defineManagedBean(ManagedBeanCreatorImpl<T> managedBeanCreator,
                                                       ProcessInjectionTarget<T> processInjectionTargetEvent)
    {
        BeanManagerImpl manager = BeanManagerImpl.getManager();

        //Annotated type
        AnnotatedType<T> annotatedType = processInjectionTargetEvent.getAnnotatedType();
        ManagedBean<T> managedBean = managedBeanCreator.getBean();
        Class<T> clazz = annotatedType.getJavaClass();

        managedBeanCreator.defineSerializable();

        //Define meta-data
        managedBeanCreator.defineStereoTypes();
        //Scope type
        managedBeanCreator.defineScopeType(logger.getTokenString(OWBLogConst.TEXT_MB_IMPL) + clazz.getName() +
                logger.getTokenString(OWBLogConst.TEXT_SAME_SCOPE));
        //Check for Enabled via Alternative
        WebBeansUtil.setInjectionTargetBeanEnableFlag(managedBean);

        managedBeanCreator.defineApiType();
        managedBeanCreator.checkCreateConditions();
        managedBeanCreator.defineQualifier();
        managedBeanCreator.defineName(WebBeansUtil.getManagedBeanDefaultName(clazz.getSimpleName()));
        managedBeanCreator.defineConstructor();
        Set<ProducerMethodBean<?>> producerMethods = managedBeanCreator.defineProducerMethods();
        Set<ProducerFieldBean<?>> producerFields = managedBeanCreator.defineProducerFields();
        managedBeanCreator.defineInjectedFields();
        managedBeanCreator.defineInjectedMethods();

        Set<ObserverMethod<?>> observerMethods = new HashSet<ObserverMethod<?>>();
        if(managedBean.isEnabled())
        {
            observerMethods = managedBeanCreator.defineObserverMethods();
        }

        //Put final InjectionTarget instance
        manager.putInjectionTargetWrapper(managedBean,
                new InjectionTargetWrapper(processInjectionTargetEvent.getInjectionTarget()));

        Map<ProducerMethodBean<?>,AnnotatedMethod<?>> annotatedMethods =
                new HashMap<ProducerMethodBean<?>, AnnotatedMethod<?>>();

        for(ProducerMethodBean<?> producerMethod : producerMethods)
        {
            AnnotatedMethod<?> method = AnnotatedElementFactory.getInstance().newAnnotatedMethod(producerMethod.getCreatorMethod(),
                                                                                   annotatedType);
            ProcessProducerImpl<?, ?> producerEvent = WebBeansUtil.fireProcessProducerEventForMethod(producerMethod,
                                                                                                    method);
            WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducer event observers for "
                                           + "ProducerMethods. Look at logs for further details");

            annotatedMethods.put(producerMethod, method);
            manager.putInjectionTargetWrapper(producerMethod, new InjectionTargetWrapper(producerEvent.getProducer()));

            producerEvent.setProducerSet(false);
        }

        Map<ProducerFieldBean<?>,AnnotatedField<?>> annotatedFields =
                new HashMap<ProducerFieldBean<?>, AnnotatedField<?>>();

        for(ProducerFieldBean<?> producerField : producerFields)
        {
            AnnotatedField<?> field = AnnotatedElementFactory.getInstance().newAnnotatedField(producerField.getCreatorField(),
                                                                                annotatedType);
            ProcessProducerImpl<?, ?> producerEvent = WebBeansUtil.fireProcessProducerEventForField(producerField,
                                                                                                    field);
            WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducer event observers for"
                                           + " ProducerFields. Look at logs for further details");

            annotatedFields.put(producerField, field);
            manager.putInjectionTargetWrapper(producerField, new InjectionTargetWrapper(producerEvent.getProducer()));

            producerEvent.setProducerSet(false);
        }

        Map<ObserverMethod<?>,AnnotatedMethod<?>> observerMethodsMap =
                new HashMap<ObserverMethod<?>, AnnotatedMethod<?>>();

        for(ObserverMethod<?> observerMethod : observerMethods)
        {
            ObserverMethodImpl<?> impl = (ObserverMethodImpl<?>)observerMethod;
            AnnotatedMethod<?> method = AnnotatedElementFactory.getInstance().newAnnotatedMethod(impl.getObserverMethod(),
                                                                                   annotatedType);

            observerMethodsMap.put(observerMethod, method);
        }

        BeanManagerImpl beanManager = BeanManagerImpl.getManager();

        //Fires ProcessManagedBean
        ProcessBeanImpl<T> processBeanEvent = new GProcessManagedBean(managedBean,annotatedType);
        beanManager.fireEvent(processBeanEvent, new Annotation[0]);
        WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessManagedBean event observers for " +
                "managed beans. Look at logs for further details");

        //Fires ProcessProducerMethod
        WebBeansUtil.fireProcessProducerMethodBeanEvent(annotatedMethods, annotatedType);
        WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducerMethod event observers for " +
                "producer method beans. Look at logs for further details");

        //Fires ProcessProducerField
        WebBeansUtil.fireProcessProducerFieldBeanEvent(annotatedFields);
        WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducerField event observers for " +
                "producer field beans. Look at logs for further details");

        //Fire ObservableMethods
        WebBeansUtil.fireProcessObservableMethodBeanEvent(observerMethodsMap);
        WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessObserverMethod event observers for " +
                "observer methods. Look at logs for further details");

        if(!WebBeansAnnotatedTypeUtil.isAnnotatedTypeDecoratorOrInterceptor(annotatedType))
        {
            beanManager.addBean(WebBeansUtil.createNewBean(managedBean));
            beanManager.addBean(managedBean);
            for (ProducerMethodBean<?> producerMethod : producerMethods)
            {
                // add them one after the other to enable serialization handling et al
                beanManager.addBean(producerMethod);
            }
            managedBeanCreator.defineDisposalMethods();//Define disposal method after adding producers
            for (ProducerFieldBean<?> producerField : producerFields)
            {
                // add them one after the other to enable serialization handling et al
                beanManager.addBean(producerField);
            }
        }

        return managedBean;
    }
View Full Code Here

       
    }
       
    public static <T> void fireEvents(Class<T> clazz, BaseEjbBean<T> ejbBean,ProcessAnnotatedType<T> event)
    {
        BeanManagerImpl manager = BeanManagerImpl.getManager();
        AnnotatedElementFactory annotatedElementFactory = AnnotatedElementFactory.getInstance();

        AnnotatedType<T> annotatedType = annotatedElementFactory.newAnnotatedType(clazz);
       
        //Fires ProcessAnnotatedType
        ProcessAnnotatedTypeImpl<T> processAnnotatedEvent = (ProcessAnnotatedTypeImpl<T>)event;            
        EjbBeanCreatorImpl<T> ejbBeanCreator = new EjbBeanCreatorImpl<T>(ejbBean);
        ejbBeanCreator.checkCreateConditions();
       
        if(processAnnotatedEvent.isVeto())
        {
            return;
        }
       
        if(processAnnotatedEvent.isSet())
        {
            ejbBeanCreator.setMetaDataProvider(MetaDataProvider.THIRDPARTY);
        }
       
        //Define meta-data
        ejbBeanCreator.defineSerializable();
        ejbBeanCreator.defineStereoTypes();
        ejbBeanCreator.defineApiType();
        ejbBeanCreator.defineScopeType("Session Bean implementation class : " + clazz.getName() + " stereotypes must declare same @ScopeType annotations");
        ejbBeanCreator.defineQualifier();
        ejbBeanCreator.defineName(WebBeansUtil.getManagedBeanDefaultName(clazz.getSimpleName()));           
        Set<ProducerMethodBean<?>> producerMethodBeans = ejbBeanCreator.defineProducerMethods();       
        checkProducerMethods(producerMethodBeans, ejbBean);
        Set<ProducerFieldBean<?>> producerFieldBeans = ejbBeanCreator.defineProducerFields();          
        ejbBeanCreator.defineInjectedFields();
        ejbBeanCreator.defineInjectedMethods();
        Set<ObserverMethod<?>> observerMethods = ejbBeanCreator.defineObserverMethods();       
       
        //Fires ProcessInjectionTarget
        ProcessInjectionTargetImpl<T> processInjectionTargetEvent = WebBeansUtil.fireProcessInjectionTargetEvent(ejbBean);    
        WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessInjectionTarget event observers. Look at logs for further details");
        //Put final InjectionTarget instance
        manager.putInjectionTargetWrapper(ejbBean, new InjectionTargetWrapper(processInjectionTargetEvent.getInjectionTarget()));
       
        Map<ProducerMethodBean<?>,AnnotatedMethod<?>> annotatedMethods = new HashMap<ProducerMethodBean<?>, AnnotatedMethod<?>>();
        for(ProducerMethodBean<?> producerMethod : producerMethodBeans)
        {
            AnnotatedMethod<?> method = annotatedElementFactory.newAnnotatedMethod(producerMethod.getCreatorMethod(), annotatedType);
            ProcessProducerImpl<?, ?> producerEvent = WebBeansUtil.fireProcessProducerEventForMethod(producerMethod,method);
            WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducer event observers for ProducerMethods. Look at logs for further details");

            annotatedMethods.put(producerMethod, method);
            manager.putInjectionTargetWrapper(producerMethod, new InjectionTargetWrapper(producerEvent.getProducer()));
           
            producerEvent.setProducerSet(false);
        }
       
        Map<ProducerFieldBean<?>,AnnotatedField<?>> annotatedFields = new HashMap<ProducerFieldBean<?>, AnnotatedField<?>>();
        for(ProducerFieldBean<?> producerField : producerFieldBeans)
        {
            AnnotatedField<?> field = annotatedElementFactory.newAnnotatedField(producerField.getCreatorField(), annotatedType);
            ProcessProducerImpl<?, ?> producerEvent = WebBeansUtil.fireProcessProducerEventForField(producerField, field);
            WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducer event observers for ProducerFields. Look at logs for further details");
           
            annotatedFields.put(producerField, field);
            manager.putInjectionTargetWrapper(producerField, new InjectionTargetWrapper(producerEvent.getProducer()));

           
            producerEvent.setProducerSet(false);
        }
       
        Map<ObserverMethod<?>,AnnotatedMethod<?>> observerMethodsMap = new HashMap<ObserverMethod<?>, AnnotatedMethod<?>>();
        for(ObserverMethod<?> observerMethod : observerMethods)
        {
            ObserverMethodImpl<?> impl = (ObserverMethodImpl<?>)observerMethod;
            AnnotatedMethod<?> method = annotatedElementFactory.newAnnotatedMethod(impl.getObserverMethod(), annotatedType);
           
            observerMethodsMap.put(observerMethod, method);
        }       

        //Fires ProcessManagedBean
        ProcessSessionBeanImpl<T> processBeanEvent = new GProcessSessionBean((Bean<Object>)ejbBean,annotatedType,ejbBean.getEjbName(),ejbBean.getEjbType());           
        BeanManagerImpl.getManager().fireEvent(processBeanEvent, new Annotation[0]);
        WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessSessionBean event observers for managed beans. Look at logs for further details");
       
       
        //Fires ProcessProducerMethod
        WebBeansUtil.fireProcessProducerMethodBeanEvent(annotatedMethods, annotatedType);
        WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducerMethod event observers for producer method beans. Look at logs for further details");
       
        //Fires ProcessProducerField
        WebBeansUtil.fireProcessProducerFieldBeanEvent(annotatedFields);
        WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducerField event observers for producer field beans. Look at logs for further details");
       
        //Fire ObservableMethods
        WebBeansUtil.fireProcessObservableMethodBeanEvent(observerMethodsMap);
        WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessObserverMethod event observers for observer methods. Look at logs for further details");

        manager.addBean(ejbBean);
        try
        {
            manager.addBean(WebBeansUtil.createNewBean(ejbBean));
        }
        catch (DuplicateDefinitionException ignore)
        {
        }
       
       
        manager.getBeans().addAll(producerMethodBeans);
        ejbBeanCreator.defineDisposalMethods();
        manager.getBeans().addAll(producerFieldBeans);
    }
View Full Code Here

    {
        Exception ex = null;
        try
        {
            startContainer(Collections.<Class<?>> emptyList());
            final BeanManagerImpl manager = BeanManagerImpl.getManager();
            AnnotatedType<CustomTarget> annotatedType = manager.createAnnotatedType(CustomTarget.class);
            InjectionTarget<CustomTarget> injectionTarget = manager.createInjectionTarget(annotatedType);
            CreationalContext<CustomTarget> context = manager.createCreationalContext(null);
            try
            {
                injectionTarget.produce(context);
            }
            catch (Exception e)
View Full Code Here

   
    @Test
    public void testInjecDependenciesTargetWithNoConstructor()
    {
        Exception ex = null;
        final BeanManagerImpl manager;
        CreationalContext<CustomTarget> context =null;
        CustomTarget instance = null;
        try
        {
            startContainer(Collections.<Class<?>> emptyList());
            manager = BeanManagerImpl.getManager();
            context = manager.createCreationalContext(null);
            AnnotatedType<CustomTarget> annotatedType = manager.createAnnotatedType(CustomTarget.class);
            InjectionTarget<CustomTarget> injectionTarget = manager.createInjectionTarget(annotatedType);
            try
            {
                instance = new CustomTarget("Hiho");
                injectionTarget.inject(instance, context);
               
View Full Code Here

    @Override
    @SuppressWarnings("unchecked")
    public Object getValue(ELContext context, Object obj, Object property) throws NullPointerException, PropertyNotFoundException, ELException
    {
        //Manager instance
        BeanManagerImpl manager = BeanManagerImpl.getManager();
       
        //Bean instance
        Object object = null;
       
        //Managed bean
        Bean<Object> bean = null;
       
        //Creational context for creating instance
        CreationalContext<Object> creationalContext = null;
       
        //Local store, set by the OwbELContextListener
        ELContextStore store = ELContextStore.localContext.get();
        if (obj == null)
        {                     
            //Name of the bean
            String name = (String) property;
            //Get beans
            Set<Bean<?>> beans = manager.getBeans(name);
           
            //Found?
            if(beans != null && !beans.isEmpty())
            {
                bean = (Bean<Object>)beans.iterator().next();
                creationalContext = manager.createCreationalContext(bean);                   
                //Already registered in store
                if(bean.getScope().equals(Dependent.class))
                {
                    object = store.getDependent(bean);
                }                   
            }
           
            //If no object found on the store
            if(object == null)
            {
                //Getting object
                object = manager.getInstanceByName(name,creationalContext);               
                if (object != null)
                {                   
                    context.setPropertyResolved(true);  
                    //Adding into store
                    store.addDependent(bean, object, creationalContext);
View Full Code Here

                //Invoke Method
                this.observerMethod.invoke(object, args);
            }
            else
            {
                BeanManagerImpl manager = BeanManagerImpl.getManager();
                specializedComponent = (AbstractOwbBean<Object>)WebBeansUtil.getMostSpecializedBean(manager, baseComponent);       
                Context context = null;
                try
                {
                    context = manager.getContext(specializedComponent.getScope());
                }
                catch (ContextNotActiveException cnae)
                {
                    // this may happen if we try to e.g. send an event to a @ConversationScoped bean from a ServletListener
                    logger.info(OWBLogConst.INFO_0010, bean);
                    return;
                }
               
                creationalContext = manager.createCreationalContext(specializedComponent);
               
                // on Reception.IF_EXISTS: ignore this bean if a the contextual instance doesn't already exist
                if (ifExist && context.get(specializedComponent) == null)
                {
                    return;
                }
               
                // on Reception.ALWAYS we must get a contextual reference if we didn't find the contextual instance
                object = manager.getReference(specializedComponent, specializedComponent.getBeanClass(), creationalContext);
               
                if (object != null)
                {
                    //Invoke Method
                    this.observerMethod.invoke(object, args);
View Full Code Here

TOP

Related Classes of org.apache.webbeans.container.BeanManagerImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.