Package org.infinispan.cdi.util

Examples of org.infinispan.cdi.util.Synthetic


    <X> void processAnnotatedType(@Observes ProcessAnnotatedType<X> event, BeanManager beanManager) {
        boolean defaultBean = false;
        AnnotatedType<X> tp = event.getAnnotatedType();
        AnnotatedTypeBuilder<X> builder = null;
        Synthetic declaringBeanSyntheticQualifier = null;
        Set<Annotation> declaringBeanQualifiers = null;
        if (event.getAnnotatedType().isAnnotationPresent(DefaultBean.class)) {
            Set<Annotation> qualifiers = new HashSet<Annotation>();
            defaultBean = true;
            builder = new AnnotatedTypeBuilder<X>().readFromType(tp);
            for (Annotation a : tp.getAnnotations()) {
                // remove the qualifiers
                if (beanManager.isQualifier(a.annotationType())) {
                    qualifiers.add(a);
                    builder.removeFromClass(a.annotationType());
                }
            }
            postProcessQualifierSet(qualifiers);
            builder.addToClass(new DefaultBeanInformation.Literal(qualifiers));
            declaringBeanQualifiers = new HashSet<Annotation>(qualifiers);
            declaringBeanSyntheticQualifier = syntheticProvider.get();
            // store the qualifiers for later
            beanTypeInformation.put(declaringBeanSyntheticQualifier, new DefaultBeanType(qualifiers, tp.getAnnotation(DefaultBean.class).value()));
            builder.addToClass(declaringBeanSyntheticQualifier);
        }
        final Set<Synthetic> producers = new HashSet<Synthetic>();
        // now look for producer methods
        // if this bean is a default bean then all producers are default beans
        // otherwise the annotation needs to be present
        for (AnnotatedMethod<? super X> m : tp.getMethods()) {
            if (m.isAnnotationPresent(Produces.class) && (defaultBean || m.isAnnotationPresent(DefaultBean.class))) {
                if (declaringBeanQualifiers == null) {
                    declaringBeanQualifiers = new HashSet<Annotation>(Reflections.getQualifiers(beanManager, tp.getAnnotations()));
                    if (declaringBeanQualifiers.isEmpty()) {
                        declaringBeanQualifiers.add(DefaultLiteral.INSTANCE);
                    }
                }
                if (builder == null) {
                    builder = new AnnotatedTypeBuilder<X>().readFromType(tp);
                }
                Set<Annotation> qualifiers = new HashSet<Annotation>();
                for (Annotation a : m.getAnnotations()) {
                    // remove the qualifiers
                    if (beanManager.isQualifier(a.annotationType())) {
                        qualifiers.add(a);
                        builder.removeFromMethod(m, a.annotationType());
                    }
                }
                postProcessQualifierSet(qualifiers);
                builder.addToMethod(m, new DefaultBeanInformation.Literal(qualifiers));
                Synthetic syntheticQualifier = producerSyntheticProvider.get();
                // store the qualifiers for later
                Type type = null;
                // if the type is not explicity set then we infer it
                if (m.isAnnotationPresent(DefaultBean.class)) {
                    type = m.getAnnotation(DefaultBean.class).value();
                } else {
                    type = m.getJavaMember().getGenericReturnType();
                }
                beanTypeInformation.put(syntheticQualifier, new DefaultBeanType(qualifiers, type));
                builder.addToMethod(m, syntheticQualifier);
                producerToDeclaringDefaultBean.put(syntheticQualifier, new DefaultBeanQualifiers(declaringBeanSyntheticQualifier, declaringBeanQualifiers));
                producers.add(syntheticQualifier);
            }
        }

        //now look for disposer methods
        if (!producers.isEmpty()) {

            for (AnnotatedMethod<? super X> m : tp.getMethods()) {
                for (AnnotatedParameter<? super X> p : m.getParameters()) {
                    if (p.isAnnotationPresent(Disposes.class)) {
                        Set<Type> type = p.getTypeClosure();
                        Set<Annotation> qualifiers = new HashSet<Annotation>();
                        for (final Annotation annotation : p.getAnnotations()) {
                            if (beanManager.isQualifier(annotation.annotationType())) {
                                qualifiers.add(annotation);
                            }
                        }
                        postProcessQualifierSet(qualifiers);

                        for (final Synthetic producer : producers) {
                            final DefaultBeanType beanType = beanTypeInformation.get(producer);
                            Set<Type> types = new HierarchyDiscovery(beanType.getType()).getTypeClosure();
                            if (Reflections.matches(type, types)) {
                                if (beanType.getQualifiers().equals(qualifiers)) {
                                    for (final Annotation annotation : p.getAnnotations()) {
                                        if (beanManager.isQualifier(annotation.annotationType())) {
                                            builder.removeFromMethodParameter(m.getJavaMember(), p.getPosition(), annotation.annotationType());
                                        }
                                    }
                                    builder.addToMethodParameter(m.getJavaMember(), p.getPosition(), producer);
                                }
                            }
                        }
                    }
                }
            }
        }

        for (AnnotatedField<? super X> f : tp.getFields()) {
            if (f.isAnnotationPresent(Produces.class) && (defaultBean || f.isAnnotationPresent(DefaultBean.class))) {
                if (declaringBeanQualifiers == null) {
                    declaringBeanQualifiers = new HashSet<Annotation>(Reflections.getQualifiers(beanManager, tp.getAnnotations()));
                    if (declaringBeanQualifiers.isEmpty()) {
                        declaringBeanQualifiers.add(DefaultLiteral.INSTANCE);
                    }
                }
                // we do not support producer fields on normal scoped beans
                // as proxies prevent us from reading the fields
                for (Annotation i : tp.getAnnotations()) {
                    if (beanManager.isNormalScope(i.annotationType())) {
                        deploymentProblems.add(new RuntimeException("Default producer fields are not supported on normal scoped beans. Field: " + f + " Declaring Bean: " + tp));
                    }
                }
                if (builder == null) {
                    builder = new AnnotatedTypeBuilder<X>().readFromType(tp);
                }
                Set<Annotation> qualifiers = new HashSet<Annotation>();
                for (Annotation a : f.getAnnotations()) {
                    // remove the qualifiers
                    if (beanManager.isQualifier(a.annotationType())) {
                        qualifiers.add(a);
                        builder.removeFromField(f, a.annotationType());
                    }
                }
                postProcessQualifierSet(qualifiers);
                builder.addToField(f, new DefaultBeanInformation.Literal(qualifiers));
                Synthetic syntheticQualifier = producerSyntheticProvider.get();
                // store the qualifiers for later
                Type type = null;
                if (f.isAnnotationPresent(DefaultBean.class)) {
                    type = f.getAnnotation(DefaultBean.class).value();
                } else {
View Full Code Here


        if (beanDiscoveryOver) {
            return;
        }
        Bean<X> b = event.getBean();
        processedBeans.add(b);
        Synthetic qualifier = null;
        for (Annotation a : b.getQualifiers()) {
            if (a instanceof Synthetic) {
                Synthetic sa = (Synthetic) a;
                if (sa.namespace().equals(QUALIFIER_NAMEPSACE)) {
                    qualifier = sa;
                    break;
                }
            }
        }
View Full Code Here

    <T, X> void processProducer(@Observes ProcessProducerMethod<T, X> event) {
        if (beanDiscoveryOver) {
            return;
        }
        Bean<X> b = event.getBean();
        Synthetic qualifier = handleProducerBean(b);
        if (qualifier != null) {
            // store producer method information
            defaultProducerMethods.put(qualifier, event.getBean());
            AnnotatedMethod<T> method = event.getAnnotatedProducerMethod();
            AnnotatedMethod<T> disposerMethod = null;
View Full Code Here

    <T, X> void processProducer(@Observes ProcessProducerField<T, X> event) {
        if (beanDiscoveryOver) {
            return;
        }
        Bean<X> b = event.getBean();
        Synthetic qualifier = handleProducerBean(b);
        if (qualifier != null) {
            defaultProducerFields.put(qualifier, event.getBean());
            producerAnnotatedFields.put(qualifier, event.getAnnotatedProducerField());
        }
    }
View Full Code Here

            producerAnnotatedFields.put(qualifier, event.getAnnotatedProducerField());
        }
    }

    <X> Synthetic handleProducerBean(Bean<X> b) {
        Synthetic qualifier = null;
        for (Annotation a : b.getQualifiers()) {
            if (a instanceof Synthetic) {
                Synthetic sa = (Synthetic) a;
                if (sa.namespace().equals(PRODUCER_QUALIFIER_NAMEPSACE)) {
                    qualifier = sa;
                    break;
                }
            }
        }
View Full Code Here

            for (Bean<?> processedBean : processedBeans) {
                Iterator<Entry<Synthetic, DefaultBeanType>> it = beanTypeInformation.entrySet().iterator();
                while (it.hasNext()) {
                    Entry<Synthetic, DefaultBeanType> definition = it.next();
                    if (definition.getValue().matches(processedBean)) {
                        Synthetic qual = definition.getKey();
                        Bean<?> bean = null;
                        // remove the default bean from the beans to be installed
                        bean = defaultManagedBeans.remove(qual);
                        if (bean == null) {
                            bean = defaultProducerMethods.remove(qual);
                        }
                        if (bean == null) {
                            bean = defaultProducerFields.remove(qual);
                        }
                        log.info("Preventing install of default bean " + bean);
                        it.remove();
                    }
                }
            }
        }
        Set<Synthetic> allDefaultBeanQualifiers = new HashSet<Synthetic>(defaultManagedBeans.keySet());
        allDefaultBeanQualifiers.addAll(defaultProducerFields.keySet());
        allDefaultBeanQualifiers.addAll(defaultProducerMethods.keySet());

        for (Synthetic qual : allDefaultBeanQualifiers) {
            final DefaultBeanType beanInfo = beanTypeInformation.get(qual);
            final HashSet<Type> types = new HashSet<Type>();
            types.add(Object.class);
            types.add(beanInfo.getType());
            final Set<Annotation> qualifiers = new HashSet<Annotation>(beanInfo.getQualifiers());
            if (defaultManagedBeans.containsKey(qual)) {
                Bean<?> db = DefaultManagedBean.of(defaultManagedBeans.get(qual), beanInfo.getType(), types, qualifiers, manager);
                log.debug("Installing default managed bean " + db);
                event.addBean(db);
                fireBeanInstalledEvent(db, manager);
            } else if (defaultProducerMethods.containsKey(qual)) {
                Synthetic declaringDefaultBean = this.producerToDeclaringDefaultBean.get(qual).getSyntheticQualifier();
                Set<Annotation> declaringBeanQualifiers;
                if (declaringDefaultBean != null && !beanTypeInformation.containsKey(declaringDefaultBean)) {
                    // this is a default producer method that was declared on a
                    // default bean that has been replaced
                    declaringBeanQualifiers = Collections.singleton((Annotation) declaringDefaultBean);
                } else {
                    declaringBeanQualifiers = this.producerToDeclaringDefaultBean.get(qual).getQualifiers();
                }
                DefaultProducerMethodInfo<?> info = producerAnnotatedMethods.get(qual);
                Bean<?> db = createDefaultProducerMethod(defaultProducerMethods.get(qual), qual, beanInfo, types, qualifiers, declaringBeanQualifiers, info, manager);
                log.debug("Installing default producer bean " + db);
                event.addBean(db);
                fireBeanInstalledEvent(db, manager);
            } else if (defaultProducerFields.containsKey(qual)) {
                Synthetic declaringDefaultBean = this.producerToDeclaringDefaultBean.get(qual).getSyntheticQualifier();
                Set<Annotation> declaringBeanQualifiers;
                if (declaringDefaultBean != null && !beanTypeInformation.containsKey(declaringDefaultBean)) {
                    // this is a default producer method that was declared on a
                    // default bean that has been replaced
                    declaringBeanQualifiers = Collections.singleton((Annotation) declaringDefaultBean);
View Full Code Here

TOP

Related Classes of org.infinispan.cdi.util.Synthetic

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.