Search in sources :

Example 1 with ObserverMethodImpl

use of org.jboss.weld.event.ObserverMethodImpl in project core by weld.

the class JsonObjects method createFullBeanJson.

/**
 * @param bean
 * @param transientDependencies
 * @param transientDependents
 * @param probe
 * @return the full bean representation
 */
static JsonObjectBuilder createFullBeanJson(Bean<?> bean, boolean transientDependencies, boolean transientDependents, BeanManagerImpl beanManager, Probe probe) {
    JsonObjectBuilder beanBuilder = createBasicBeanJson(bean, probe);
    // NAME
    if (bean.getName() != null) {
        beanBuilder.add(NAME, bean.getName());
    }
    // STEREOTYPES
    if (bean.getStereotypes() != null && !bean.getStereotypes().isEmpty()) {
        JsonArrayBuilder stereotypesBuilder = Json.arrayBuilder();
        for (Class<?> stereotype : Components.getSortedProbeComponetCandidates(bean.getStereotypes())) {
            stereotypesBuilder.add(Json.objectBuilder().add(CLASS, stereotype.getName()).add(PROBE_COMPONENT, Components.isProbeComponent(stereotype)));
        }
        beanBuilder.add(STEREOTYPES, stereotypesBuilder);
    }
    if (bean instanceof SessionBean) {
        // SESSION BEAN
        SessionBean<?> sessionBean = (SessionBean<?>) bean;
        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) {
        // PRODUCERS
        AbstractProducerBean<?, ?, ?> producerBean = (AbstractProducerBean<?, ?, ?>) bean;
        if (producerBean.getDeclaringBean() != null) {
            beanBuilder.add(DECLARING_BEAN, createSimpleBeanJson(producerBean.getDeclaringBean(), probe));
        }
        if (producerBean.getProducer() instanceof ProducerMethodProducer) {
            ProducerMethodProducer<?, ?> producer = (ProducerMethodProducer<?, ?>) producerBean.getProducer();
            if (producer.getDisposalMethod() != null) {
                beanBuilder.add(DISPOSAL_METHOD, annotatedMethodToString(producer.getDisposalMethod().getAnnotated(), bean.getBeanClass()));
            }
            beanBuilder.add(PRODUCER_METHOD, annotatedMethodToString((AnnotatedMethod<?>) producer.getAnnotated(), bean.getBeanClass()));
        } else if (producerBean.getProducer() instanceof ProducerFieldProducer) {
            ProducerFieldProducer<?, ?> producer = (ProducerFieldProducer<?, ?>) producerBean.getProducer();
            if (producer.getDisposalMethod() != null) {
                beanBuilder.add(DISPOSAL_METHOD, annotatedMethodToString(producer.getDisposalMethod().getAnnotated(), bean.getBeanClass()));
            }
            beanBuilder.add(PRODUCER_FIELD, annotatedFieldToString(producer.getAnnotated(), bean.getBeanClass()));
        }
    }
    // DEPENDENCIES
    JsonArrayBuilder dependencies = createDependencies(null, bean, probe, transientDependencies);
    if (dependencies != null) {
        beanBuilder.add(DEPENDENCIES, dependencies);
    }
    // DEPENDENTS
    JsonArrayBuilder dependents = createDependents(null, bean, probe, transientDependents);
    if (dependents != null) {
        beanBuilder.add(DEPENDENTS, dependents);
    }
    // DECLARED OBSERVERS
    JsonArrayBuilder declaredObservers = Json.arrayBuilder();
    for (ObserverMethod<?> observerMethod : probe.getObservers()) {
        if (observerMethod instanceof ObserverMethodImpl) {
            ObserverMethodImpl<?, ?> observerMethodImpl = (ObserverMethodImpl<?, ?>) observerMethod;
            if (bean.equals(observerMethodImpl.getDeclaringBean())) {
                JsonObjectBuilder observerBuilder = createSimpleObserverJson(observerMethodImpl, probe);
                observerBuilder.add(RECEPTION, observerMethodImpl.getReception().toString());
                observerBuilder.add(TX_PHASE, observerMethodImpl.getTransactionPhase().toString());
                observerBuilder.add(ANNOTATED_METHOD, annotatedMethodToString(observerMethodImpl.getMethod().getAnnotated(), bean.getBeanClass()));
                declaredObservers.add(observerBuilder);
            }
        }
    }
    beanBuilder.add(DECLARED_OBSERVERS, declaredObservers);
    // DECLARED PRODUCERS
    beanBuilder.add(DECLARED_PRODUCERS, createDeclaredProducers(bean, probe));
    // ENABLEMENT
    BeanKind kind = BeanKind.from(bean);
    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) {
            int priorityValue = annotationApi.getPriority(priority);
            enablementBuilder.add(PRIORITY, priorityValue);
            enablementBuilder.add(PRIORITY_RANGE, Components.PriorityRange.of(priorityValue).toString());
            if (!probe.getLocalEnablementOfBean(bean.getBeanClass()).isEmpty()) {
                enablementBuilder.add(WARNING, WARNING_CONFLICTING_ENABLEMENT);
                JsonArrayBuilder conflictingBdas = Json.arrayBuilder();
                for (String bdaId : probe.getLocalEnablementOfBean(bean.getBeanClass())) {
                    conflictingBdas.add(createSimpleBdaJson(bdaId));
                }
                enablementBuilder.add(CONFLICTS, conflictingBdas);
            }
        } else {
            JsonArrayBuilder bdasBuilder = Json.arrayBuilder();
            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()));
                }
            }
            enablementBuilder.add(BDAS, bdasBuilder);
        }
        beanBuilder.add(ENABLEMENT, enablementBuilder);
    }
    // INTERCEPTOR BINDINGS
    if (BeanKind.INTERCEPTOR.equals(kind)) {
        Interceptor<?> interceptor = (Interceptor<?>) bean;
        JsonArrayBuilder bindings = Json.arrayBuilder(true);
        for (Annotation binding : interceptor.getInterceptorBindings()) {
            bindings.add(binding.toString());
        }
        beanBuilder.add(BINDINGS, bindings);
    }
    // DECORATOR
    if (BeanKind.DECORATOR.equals(kind)) {
        Decorator<?> decorator = (Decorator<?>) bean;
        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));
        }
        beanBuilder.add(DECORATED_TYPES, decoratedTypes);
        // ASSOCIATED TO BEANS
        Set<Bean<?>> decoratedBeans = findDecoratedBeans(decorator, beanManager, probe);
        if (!decoratedBeans.isEmpty()) {
            JsonArrayBuilder decoratedBeansBuilder = Json.arrayBuilder();
            for (Bean<?> decoratedBean : decoratedBeans) {
                decoratedBeansBuilder.add(createSimpleBeanJson(decoratedBean, probe));
            }
            beanBuilder.add(ASSOCIATED_TO, decoratedBeansBuilder);
        }
    }
    if (bean instanceof AbstractClassBean) {
        AbstractClassBean<?> abstractClassBean = (AbstractClassBean<?>) bean;
        InterceptionModel interceptionModel = abstractClassBean.getInterceptors();
        // CLASS-LEVEL BINDINGS
        if (interceptionModel != null) {
            Set<Annotation> classInterceptorBindings = interceptionModel.getClassInterceptorBindings();
            if (!classInterceptorBindings.isEmpty()) {
                JsonArrayBuilder bindingsBuilder = Json.arrayBuilder();
                for (Annotation binding : Components.getSortedProbeComponetAnnotationCandidates(classInterceptorBindings)) {
                    bindingsBuilder.add(Json.objectBuilder().add(VALUE, binding.toString()).add(PROBE_COMPONENT, Components.isProbeAnnotation(binding)));
                }
                beanBuilder.add(CLASS_INTERCEPTOR_BINDINGS, bindingsBuilder);
            }
        }
        // ASSOCIATED DECORATORS
        List<Decorator<?>> decorators = abstractClassBean.getDecorators();
        if (!decorators.isEmpty()) {
            JsonArrayBuilder decoratorsBuilder = Json.arrayBuilder();
            for (Decorator<?> decorator : decorators) {
                decoratorsBuilder.add(createSimpleBeanJson(decorator, probe));
            }
            beanBuilder.add(DECORATORS, decoratorsBuilder);
        }
    }
    return beanBuilder;
}
Also used : AnnotationApiAbstraction(org.jboss.weld.util.AnnotationApiAbstraction) SessionBean(org.jboss.weld.bean.SessionBean) ProducerMethodProducer(org.jboss.weld.injection.producer.ProducerMethodProducer) SessionBean(org.jboss.weld.bean.SessionBean) AbstractClassBean(org.jboss.weld.bean.AbstractClassBean) AbstractBuiltInBean(org.jboss.weld.bean.builtin.AbstractBuiltInBean) AbstractProducerBean(org.jboss.weld.bean.AbstractProducerBean) Bean(javax.enterprise.inject.spi.Bean) ObserverMethodImpl(org.jboss.weld.event.ObserverMethodImpl) ProducerFieldProducer(org.jboss.weld.injection.producer.ProducerFieldProducer) AbstractClassBean(org.jboss.weld.bean.AbstractClassBean) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder) Interceptor(javax.enterprise.inject.spi.Interceptor) BeanKind(org.jboss.weld.probe.Components.BeanKind) ModuleEnablement(org.jboss.weld.bootstrap.enablement.ModuleEnablement) AbstractProducerBean(org.jboss.weld.bean.AbstractProducerBean) InterceptionModel(org.jboss.weld.interceptor.spi.model.InterceptionModel) Annotation(java.lang.annotation.Annotation) Decorator(javax.enterprise.inject.spi.Decorator) ParameterizedType(java.lang.reflect.ParameterizedType) EventType(org.jboss.weld.probe.BootstrapStats.EventType) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) ProcessSyntheticAnnotatedType(javax.enterprise.inject.spi.ProcessSyntheticAnnotatedType) Type(java.lang.reflect.Type) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) ProxyObject(org.jboss.weld.bean.proxy.ProxyObject)

Example 2 with ObserverMethodImpl

use of org.jboss.weld.event.ObserverMethodImpl in project core by weld.

the class JsonObjects method createEventJson.

static JsonObjectBuilder createEventJson(EventInfo event, Probe probe) {
    JsonObjectBuilder builder = Json.objectBuilder();
    builder.add(TYPE, Formats.formatType(event.getType(), event.isContainerEvent()));
    builder.add(QUALIFIERS, createQualifiers(event.getQualifiers(), true));
    builder.add(EVENT_INFO, event.getEventString());
    builder.add(KIND, (event.isContainerEvent() ? CONTAINER : APPLICATION).toUpperCase());
    builder.add(TIMESTAMP, event.getTimestamp());
    JsonArrayBuilder observersBuilder = Json.arrayBuilder();
    for (ObserverMethod<?> observer : event.getObservers()) {
        JsonObjectBuilder b = createSimpleObserverJson(observer, probe);
        if (observer instanceof ObserverMethodImpl<?, ?>) {
            ObserverMethodImpl<?, ?> weldObserver = (ObserverMethodImpl<?, ?>) observer;
            AnnotatedMethod<?> method = weldObserver.getMethod().getAnnotated();
            b.add(METHOD, method.getJavaMember().getName());
        // b.add(METHOD, method.getJavaMember().getName() + Formats.formatAsFormalParameterList(method.getParameters()));
        }
        observersBuilder.add(b);
    }
    builder.add(OBSERVERS, observersBuilder);
    return builder;
}
Also used : ObserverMethodImpl(org.jboss.weld.event.ObserverMethodImpl) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder)

Example 3 with ObserverMethodImpl

use of org.jboss.weld.event.ObserverMethodImpl in project core by weld.

the class Probe method init.

/**
 * @param beanManager
 */
void init(BeanManagerImpl beanManager) {
    ContextualStore contextualStore = beanManager.getServices().get(ContextualStore.class);
    bdaToManager.putAll(Container.instance(beanManager).beanDeploymentArchives());
    for (Entry<BeanDeploymentArchive, BeanManagerImpl> entry : bdaToManager.entrySet()) {
        ProbeLogger.LOG.processingBeanDeploymentArchive(entry.getKey().getId());
        BeanManagerImpl manager = entry.getValue();
        // Beans
        for (Bean<?> bean : manager.getBeans()) {
            // there's only one Instance bean though
            if (bean instanceof ExtensionBean) {
                // ExtensionBean does not include BeanManager in its BeanIdentifier
                ExtensionBean<?> extensionBean = (ExtensionBean<?>) bean;
                if (!idToBean.containsValue(extensionBean)) {
                    putBean(Components.getId(extensionBean.getIdentifier()), manager, extensionBean);
                }
            } else if (bean instanceof AbstractBuiltInBean<?>) {
                // Built-in beans are identified by the set of types
                String id = Components.getBuiltinBeanId((AbstractBuiltInBean<?>) bean);
                if (!idToBean.containsKey(id)) {
                    putBean(id, bean);
                }
            } else {
                if (manager.isBeanEnabled(bean)) {
                    // Make sure the bean is truly enabled
                    putBean(contextualStore, manager, bean);
                }
            }
        }
        // Interceptors
        for (Interceptor<?> interceptor : manager.getInterceptors()) {
            putBean(contextualStore, manager, interceptor);
        }
        // Decorators
        for (Decorator<?> decorator : manager.getDecorators()) {
            putBean(contextualStore, manager, decorator);
        }
        // Observers
        int customObservers = 0;
        for (ObserverMethod<?> observerMethod : manager.getObservers()) {
            if (observerMethod instanceof ObserverMethodImpl) {
                ObserverMethodImpl<?, ?> observerMethodImpl = (ObserverMethodImpl<?, ?>) observerMethod;
                putObserver(Components.getId(observerMethodImpl.getId()), observerMethodImpl);
            } else {
                // Custom observer methods
                putObserver(Components.getId("" + customObservers++), observerMethod);
            }
        }
    }
    // Find declared producers
    for (Bean<?> candidate : idToBean.values()) {
        BeanKind kind = BeanKind.from(candidate);
        if ((BeanKind.PRODUCER_FIELD.equals(kind) || BeanKind.PRODUCER_METHOD.equals(kind) || BeanKind.RESOURCE.equals(kind)) && candidate instanceof AbstractProducerBean) {
            AbstractProducerBean<?, ?, ?> producerBean = (AbstractProducerBean<?, ?, ?>) candidate;
            beanToDeclaredProducers.put(producerBean.getDeclaringBean(), producerBean);
        }
    }
    findUnusedBeans();
    initTs.set(System.currentTimeMillis());
}
Also used : AbstractBuiltInBean(org.jboss.weld.bean.builtin.AbstractBuiltInBean) ExtensionBean(org.jboss.weld.bean.builtin.ExtensionBean) AbstractProducerBean(org.jboss.weld.bean.AbstractProducerBean) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) ContextualStore(org.jboss.weld.serialization.spi.ContextualStore) ObserverMethodImpl(org.jboss.weld.event.ObserverMethodImpl) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) BeanKind(org.jboss.weld.probe.Components.BeanKind)

Example 4 with ObserverMethodImpl

use of org.jboss.weld.event.ObserverMethodImpl in project core by weld.

the class JsonObjects method createBasicObserverJson.

@SuppressFBWarnings(value = "BC_VACUOUS_INSTANCEOF", justification = "WELD-2452, with CDI 1.2 API, this doesn't need to be true.")
static JsonObjectBuilder createBasicObserverJson(ObserverMethod<?> observerMethod, Probe probe) {
    JsonObjectBuilder observerBuilder = createSimpleObserverJson(observerMethod, probe);
    observerBuilder.add(RECEPTION, observerMethod.getReception().toString());
    observerBuilder.add(TX_PHASE, observerMethod.getTransactionPhase().toString());
    if (!observerMethod.getObservedQualifiers().isEmpty()) {
        JsonArrayBuilder qualifiersBuilder = Json.arrayBuilder();
        for (Annotation qualifier : observerMethod.getObservedQualifiers()) {
            qualifiersBuilder.add(qualifier.toString());
        }
        observerBuilder.add(QUALIFIERS, qualifiersBuilder);
    }
    if (observerMethod instanceof ObserverMethodImpl) {
        ObserverMethodImpl<?, ?> observerMethodImpl = (ObserverMethodImpl<?, ?>) observerMethod;
        observerBuilder.add(DECLARING_BEAN, createSimpleBeanJson(observerMethodImpl.getDeclaringBean(), probe));
    }
    if (isUnrestrictedProcessAnnotatedTypeObserver(observerMethod)) {
        observerBuilder.add(DESCRIPTION, WARNING_UNRESTRICTED_PAT_OBSERVER);
    }
    // WELD-2452 to be removed once WFLY is EE 8 certified
    if (observerMethod instanceof Prioritized) {
        // Every OM is now instance of Prioritized
        final int priority = Prioritized.class.cast(observerMethod).getPriority();
        observerBuilder.add(PRIORITY, priority);
        observerBuilder.add(PRIORITY_RANGE, Components.PriorityRange.of(priority).toString());
    }
    return observerBuilder;
}
Also used : Prioritized(javax.enterprise.inject.spi.Prioritized) ObserverMethodImpl(org.jboss.weld.event.ObserverMethodImpl) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder) Annotation(java.lang.annotation.Annotation) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 5 with ObserverMethodImpl

use of org.jboss.weld.event.ObserverMethodImpl in project core by weld.

the class JsonObjects method createFullObserverJson.

/**
 * @param observerMethod
 * @param probe
 * @return
 */
static JsonObjectBuilder createFullObserverJson(ObserverMethod<?> observerMethod, Probe probe) {
    JsonObjectBuilder observerBuilder = createBasicObserverJson(observerMethod, probe);
    if (observerMethod instanceof ObserverMethodImpl) {
        ObserverMethodImpl<?, ?> observerMethodImpl = (ObserverMethodImpl<?, ?>) observerMethod;
        observerBuilder.add(ANNOTATED_METHOD, annotatedMethodToString(observerMethodImpl.getMethod().getAnnotated(), observerMethodImpl.getBeanClass()));
    }
    return observerBuilder;
}
Also used : ObserverMethodImpl(org.jboss.weld.event.ObserverMethodImpl) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder)

Aggregations

ObserverMethodImpl (org.jboss.weld.event.ObserverMethodImpl)6 JsonObjectBuilder (org.jboss.weld.probe.Json.JsonObjectBuilder)4 Annotation (java.lang.annotation.Annotation)3 JsonArrayBuilder (org.jboss.weld.probe.Json.JsonArrayBuilder)3 AbstractProducerBean (org.jboss.weld.bean.AbstractProducerBean)2 AbstractBuiltInBean (org.jboss.weld.bean.builtin.AbstractBuiltInBean)2 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)2 BeanKind (org.jboss.weld.probe.Components.BeanKind)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Bean (javax.enterprise.inject.spi.Bean)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 Decorator (javax.enterprise.inject.spi.Decorator)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 Interceptor (javax.enterprise.inject.spi.Interceptor)1 Prioritized (javax.enterprise.inject.spi.Prioritized)1 ProcessAnnotatedType (javax.enterprise.inject.spi.ProcessAnnotatedType)1 ProcessSyntheticAnnotatedType (javax.enterprise.inject.spi.ProcessSyntheticAnnotatedType)1 AbstractClassBean (org.jboss.weld.bean.AbstractClassBean)1