Package org.apache.webbeans.config

Examples of org.apache.webbeans.config.DefinitionUtil


                if (bean instanceof InjectionTargetBean) {
                    //Decorators not applied to interceptors/decorators/@NewBean
                    if (!(bean instanceof Decorator) &&
                            !(bean instanceof javax.enterprise.inject.spi.Interceptor) &&
                            !(bean instanceof NewBean)) {
                        new DefinitionUtil(webBeansContext).defineDecoratorStack((AbstractInjectionTargetBean<Object>) bean);
                    }

                    //If intercepted marker
                    if (bean instanceof InterceptedMarker) {
                      new DefinitionUtil(webBeansContext).defineBeanInterceptorStack((AbstractInjectionTargetBean<Object>) bean);
                    }
                }

                //Check passivation scope
                checkPassivationScope(bean);
View Full Code Here


        final AnnotatedElementFactory annotatedElementFactory = webBeansContext.getAnnotatedElementFactory();

        final AnnotatedType<T> annotatedType = annotatedElementFactory.newAnnotatedType(clazz);

        final DefinitionUtil util = webBeansContext.getDefinitionUtil();

        final Set<ProducerMethodBean<?>> producerMethodBeans = util.defineProducerMethods(ejbBean, clazz);

        final Set<ProducerFieldBean<?>> producerFieldBeans = util.defineProducerFields(ejbBean, clazz);

        checkProducerMethods(producerMethodBeans, ejbBean);

        // PRODUCER METHODS
        Map<ProducerMethodBean<?>, AnnotatedMethod<?>> annotatedMethods = new HashMap<ProducerMethodBean<?>, AnnotatedMethod<?>>();
        for(ProducerMethodBean<?> producerMethod : producerMethodBeans)
        {
            AnnotatedMethod<?> method = annotatedElementFactory.newAnnotatedMethod(producerMethod.getCreatorMethod(), annotatedType);

            ProcessProducerImpl<?, ?> producerEvent = webBeansContext.getWebBeansUtil().fireProcessProducerEventForMethod(producerMethod, method);

            webBeansContext.getWebBeansUtil().inspectErrorStack(String.format(message, "ProcessProducer", "ProducerMethods"));

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

        // PRODUCER FIELDS
        Map<ProducerFieldBean<?>, AnnotatedField<?>> annotatedFields = new HashMap<ProducerFieldBean<?>, AnnotatedField<?>>();
        for(ProducerFieldBean<?> producerField : producerFieldBeans)
        {
            AnnotatedField<?> field = annotatedElementFactory.newAnnotatedField(producerField.getCreatorField(), annotatedType);

            ProcessProducerImpl<?, ?> producerEvent = webBeansContext.getWebBeansUtil().fireProcessProducerEventForField(producerField, field);

            webBeansContext.getWebBeansUtil().inspectErrorStack(String.format(message, "ProcessProducer", "ProducerFields"));

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

        //Fires ProcessProducerMethod
        webBeansContext.getWebBeansUtil().fireProcessProducerMethodBeanEvent(annotatedMethods, annotatedType);
        webBeansContext.getWebBeansUtil().inspectErrorStack(String.format(message, "ProcessProducerMethod", "producer method beans"));

        //Fires ProcessProducerField
        webBeansContext.getWebBeansUtil().fireProcessProducerFieldBeanEvent(annotatedFields);
        webBeansContext.getWebBeansUtil().inspectErrorStack(String.format(message, "ProcessProducerField", "producer field beans"));

        // Let the plugin handle adding the new bean instance as it knows more about its EJB Bean

        manager.getBeans().addAll(producerMethodBeans);
        manager.getBeans().addAll(producerFieldBeans);

        util.defineDisposalMethods(ejbBean, clazz);

    }
View Full Code Here

   
   
    @SuppressWarnings("unchecked")
    public <X> Set<ProducerFieldBean<?>> defineProducerFields(InjectionTargetBean<X> bean, AnnotatedType<X> annotatedType)
    {
        DefinitionUtil definitionUtil = webBeansContext.getDefinitionUtil();
        Set<ProducerFieldBean<?>> producerBeans = new HashSet<ProducerFieldBean<?>>();
        Set<AnnotatedField<? super X>> annotatedFields = annotatedType.getFields();       
        for(AnnotatedField<? super X> annotatedField: annotatedFields)
        {
            if(annotatedField.isAnnotationPresent(Produces.class))
            {
                Type genericType = annotatedField.getBaseType();
               
                if(ClassUtil.isParametrizedType(genericType))
                {
                    if(!ClassUtil.checkParametrizedType((ParameterizedType)genericType))
                    {
                        throw new WebBeansConfigurationException("Producer annotated field : " + annotatedField + " can not be Wildcard type or Type variable");
                    }
                }
               
                Annotation[] anns = AnnotationUtil.getAnnotationsFromSet(annotatedField.getAnnotations());
                Field field = annotatedField.getJavaMember();
               
                //Producer field for resource
                Annotation resourceAnnotation = AnnotationUtil.hasOwbInjectableResource(anns);               
                //Producer field for resource
                if(resourceAnnotation != null)
                {                   
                    //Check for valid resource annotation
                    //WebBeansUtil.checkForValidResources(annotatedField.getDeclaringType().getJavaClass(), field.getType(), field.getName(), anns);
                    if(!Modifier.isStatic(field.getModifiers()))
                    {
                        ResourceReference<X,Annotation> resourceRef = new ResourceReference<X, Annotation>(bean.getBeanClass(), field.getName(),
                                                                                                           (Class<X>)field.getType(), resourceAnnotation);
                       
                        //Can not define EL name
                        if(annotatedField.isAnnotationPresent(Named.class))
                        {
                            throw new WebBeansConfigurationException("Resource producer annotated field : " + annotatedField + " can not define EL name");
                        }
                       
                        ResourceBean<X,Annotation> resourceBean = new ResourceBean((Class<X>)field.getType(),bean, resourceRef);
                       
                        resourceBean.getTypes().addAll(annotatedField.getTypeClosure());
                        definitionUtil.defineQualifiers(resourceBean, anns);
                        resourceBean.setImplScopeType(new DependentScopeLiteral());
                        resourceBean.setProducerField(field);
                       
                        producerBeans.add(resourceBean);                                           
                    }
                }
                else
                {
                    ProducerFieldBean<X> producerFieldBean = new ProducerFieldBean<X>(bean, (Class<X>)ClassUtil.getClass(annotatedField.getBaseType()));
                    producerFieldBean.setProducerField(field);
                   
                    if (ClassUtil.getClass(annotatedField.getBaseType()).isPrimitive())
                    {
                        producerFieldBean.setNullable(false);
                    }                   

                    definitionUtil.defineSerializable(producerFieldBean);
                    definitionUtil.defineStereoTypes(producerFieldBean, anns);
                    webBeansContext.getWebBeansUtil().setBeanEnableFlagForProducerBean(bean,
                                                                                                      producerFieldBean,
                                                                                                      anns);
                    Set<Type> types = annotatedField.getTypeClosure();
                    producerFieldBean.getTypes().addAll(types);
                    definitionUtil.defineScopeType(producerFieldBean, anns, "Annotated producer field: " + annotatedField +  "must declare default @Scope annotation", false);
                    webBeansContext.getWebBeansUtil().checkUnproxiableApiType(producerFieldBean,
                                                                                             producerFieldBean.getScope());
                    WebBeansUtil.checkProducerGenericType(producerFieldBean,annotatedField.getJavaMember());
                    definitionUtil.defineQualifiers(producerFieldBean, anns);
                    definitionUtil.defineName(producerFieldBean, anns, WebBeansUtil.getProducerDefaultName(annotatedField.getJavaMember().getName()));
                   
                    producerBeans.add(producerFieldBean);
                }
            }
        }
View Full Code Here

   
   
    @SuppressWarnings("unchecked")
    public <X> Set<ProducerMethodBean<?>> defineProducerMethods(InjectionTargetBean<X> bean, AnnotatedType<X> annotatedType)
    {
        DefinitionUtil definitionUtil = webBeansContext.getDefinitionUtil();
        Set<ProducerMethodBean<?>> producerBeans = new HashSet<ProducerMethodBean<?>>();
        Set<AnnotatedMethod<? super X>> annotatedMethods = annotatedType.getMethods();
       
        for(AnnotatedMethod<? super X> annotatedMethod: annotatedMethods)
        {
            if(annotatedMethod.isAnnotationPresent(Produces.class))
            {
                checkProducerMethodForDeployment(annotatedMethod);
                boolean specialize = false;
                if(annotatedMethod.isAnnotationPresent(Specializes.class))
                {
                    if (annotatedMethod.isStatic())
                    {
                        throw new WebBeansConfigurationException("Specializing annotated producer method : " + annotatedMethod + " can not be static");
                    }
                   
                    specialize = true;
                }
               
                ProducerMethodBean<X> producerMethodBean = new ProducerMethodBean<X>(bean, (Class<X>)ClassUtil.getClass(annotatedMethod.getBaseType()));
                producerMethodBean.setCreatorMethod(annotatedMethod.getJavaMember());
               
                if(specialize)
                {
                    configureProducerSpecialization(producerMethodBean, (AnnotatedMethod<X>)annotatedMethod);
                }
               
                if (ClassUtil.getClass(annotatedMethod.getBaseType()).isPrimitive())
                {
                    producerMethodBean.setNullable(false);
                }
               
                definitionUtil.defineSerializable(producerMethodBean);
                definitionUtil.defineStereoTypes(producerMethodBean, AnnotationUtil.getAnnotationsFromSet(annotatedMethod.getAnnotations()));
                webBeansContext.getWebBeansUtil().setBeanEnableFlagForProducerBean(bean,
                                                                                   producerMethodBean,
                                                                                   AnnotationUtil.getAnnotationsFromSet(annotatedMethod.getAnnotations()));

                Set<Type> types = annotatedMethod.getTypeClosure();
                producerMethodBean.getTypes().addAll(types);
                definitionUtil.defineScopeType(producerMethodBean,
                                               AnnotationUtil.getAnnotationsFromSet(annotatedMethod.getAnnotations()),
                                                                                    "Annotated producer method : " + annotatedMethod +  "must declare default @Scope annotation",
                                                                                    false);
                webBeansContext.getWebBeansUtil().checkUnproxiableApiType(producerMethodBean,
                                                                                         producerMethodBean.getScope());
                WebBeansUtil.checkProducerGenericType(producerMethodBean,annotatedMethod.getJavaMember());
                definitionUtil.defineQualifiers(producerMethodBean, AnnotationUtil.getAnnotationsFromSet(annotatedMethod.getAnnotations()));
                definitionUtil.defineName(producerMethodBean,
                                          AnnotationUtil.getAnnotationsFromSet(annotatedMethod.getAnnotations()),
                                                                               WebBeansUtil.getProducerDefaultName(annotatedMethod.getJavaMember().getName()));
               
                addMethodInjectionPointMetaData(producerMethodBean, annotatedMethod);
                producerBeans.add(producerMethodBean);
View Full Code Here

        managedBeanCreator.defineProducerFields();
        managedBeanCreator.defineInjectedFields();
        managedBeanCreator.defineInjectedMethods();
        managedBeanCreator.defineObserverMethods();

        DefinitionUtil definitionUtil = webBeansContext.getDefinitionUtil();
        definitionUtil.defineDecoratorStack(managedBean);
        definitionUtil.defineBeanInterceptorStack(managedBean);

        managedBeanCreator.defineDisposalMethods();//Define disposal method after adding producers

        return managedBean;
    }
View Full Code Here

    public <T> NewManagedBean<T> createNewComponent(Class<T> clazz, Type apiType)
    {
        Asserts.nullCheckForClass(clazz);

        NewManagedBean<T> comp;
        DefinitionUtil definitionUtil = webBeansContext.getDefinitionUtil();


        if (webBeansContext.getManagedBeanConfigurator().isManagedBean(clazz))
        {
            comp = new NewManagedBean<T>(clazz, WebBeansType.MANAGED, webBeansContext);
            comp.setImplScopeType(new DependentScopeLiteral());
            comp.setConstructor(defineConstructor(clazz));
            definitionUtil.addConstructorInjectionPointMetaData(comp, comp.getConstructor());

            definitionUtil.defineInjectedFields(comp);
            definitionUtil.defineInjectedMethods(comp);
        }
        else if (EJBWebBeansConfigurator.isSessionBean(clazz, webBeansContext))
        {
            comp = new NewManagedBean<T>(clazz, WebBeansType.ENTERPRISE, webBeansContext);
            comp.setImplScopeType(new DependentScopeLiteral());
View Full Code Here

        ExtensionBean<T> comp = null;
        comp = new ExtensionBean<T>(clazz, webBeansContext);
        comp.setEnabled(true);

        DefinitionUtil definitionUtil = webBeansContext.getDefinitionUtil();
        definitionUtil.defineApiTypes(comp, clazz);

        comp.setImplScopeType(new ApplicationScopeLiteral());
        comp.addQualifier(new DefaultLiteral());

        definitionUtil.defineObserverMethods(comp, clazz);

        return comp;
    }
View Full Code Here

        constructor = webBeansUtil.defineConstructor(returnType);

        if (constructor == null) throw new NullPointerException("constructor");

        final DefinitionUtil definitionUtil = getWebBeansContext().getDefinitionUtil();

        if (definitionUtil == null) throw new NullPointerException("definitionUtil");

        definitionUtil.addConstructorInjectionPointMetaData(this, constructor);
    }
View Full Code Here

    }

    public ConstructorInjectionBean<T> complete() {
        // these are not used immediately in createInstance()
        try {
            final DefinitionUtil definitionUtil = getWebBeansContext().getDefinitionUtil();
            definitionUtil.defineInjectedFields(this);
            definitionUtil.defineInjectedMethods(this);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return this;
View Full Code Here

                if (bean instanceof InjectionTargetBean) {
                    //Decorators not applied to interceptors/decorators/@NewBean
                    if (!(bean instanceof Decorator) &&
                            !(bean instanceof javax.enterprise.inject.spi.Interceptor) &&
                            !(bean instanceof NewBean)) {
                        new DefinitionUtil(webBeansContext).defineDecoratorStack((AbstractInjectionTargetBean<Object>) bean);
                    }

                    //If intercepted marker
                    if (bean instanceof InterceptedMarker) {
                      new DefinitionUtil(webBeansContext).defineBeanInterceptorStack((AbstractInjectionTargetBean<Object>) bean);
                    }
                }

                //Check passivation scope
                checkPassivationScope(bean);
View Full Code Here

TOP

Related Classes of org.apache.webbeans.config.DefinitionUtil

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.