Search in sources :

Example 6 with JsonArrayBuilder

use of org.jboss.weld.probe.Json.JsonArrayBuilder in project core by weld.

the class JsonObjects method createDependents.

/**
 * @param parent
 * @param bean
 * @param probe
 * @param isTransient
 * @return
 */
static JsonArrayBuilder createDependents(Bean<?> parent, Bean<?> bean, Probe probe, boolean isTransient) {
    JsonArrayBuilder dependentsBuilder = Json.arrayBuilder(true);
    for (Dependency dependent : Components.getDependents(bean, probe)) {
        // Workaround for built-in beans - these are identified by the set of types
        if (Components.isBuiltinBeanButNotExtension(dependent.getBean())) {
            dependentsBuilder.add(createDependency(probe.getBean(Components.getBuiltinBeanId((AbstractBuiltInBean<?>) dependent.getBean())), dependent, probe));
            continue;
        }
        // Handle circular dependencies
        if (dependent.getBean().equals(parent)) {
            dependentsBuilder.add(createDependency(dependent.getBean(), dependent, probe));
            continue;
        }
        JsonObjectBuilder dependency = createDependency(dependent.getBean(), dependent, probe);
        if (dependent.getInfo() != null) {
            dependency.add(INFO, dependent.getInfo());
            if (dependent.isPotential()) {
                dependency.add(IS_POTENTIAL, true);
            }
        }
        dependency.add(DECLARING_BEAN, createDeclaringBean(dependent.getBean(), probe));
        dependentsBuilder.add(dependency);
        if (isTransient) {
            dependency.add(DEPENDENTS, createDependents(bean, dependent.getBean(), probe, true));
        }
    }
    return dependentsBuilder.isEmpty() ? null : dependentsBuilder;
}
Also used : AbstractBuiltInBean(org.jboss.weld.bean.builtin.AbstractBuiltInBean) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) Dependency(org.jboss.weld.probe.Components.Dependency) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder)

Example 7 with JsonArrayBuilder

use of org.jboss.weld.probe.Json.JsonArrayBuilder 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 8 with JsonArrayBuilder

use of org.jboss.weld.probe.Json.JsonArrayBuilder in project core by weld.

the class JsonTest method testIgnoreEmptyBuilders.

@Test
public void testIgnoreEmptyBuilders() {
    assertEquals("[true]", Json.arrayBuilder(true).add(true).add(Json.objectBuilder(true).add("foo", Json.objectBuilder())).build());
    JsonObjectBuilder objectBuilder = Json.objectBuilder();
    JsonArrayBuilder arrayBuilder = Json.arrayBuilder().add(objectBuilder);
    objectBuilder.add("foo", "bar");
    assertEquals("[{\"foo\":\"bar\"}]", arrayBuilder.build());
}
Also used : JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder) Test(org.junit.Test)

Example 9 with JsonArrayBuilder

use of org.jboss.weld.probe.Json.JsonArrayBuilder in project core by weld.

the class JsonObjects method createDeclaredProducers.

/**
 * @param bean
 * @param probe
 * @return
 */
static JsonArrayBuilder createDeclaredProducers(Bean<?> bean, Probe probe) {
    JsonArrayBuilder declaredProducers = Json.arrayBuilder();
    for (AbstractProducerBean<?, ?, ?> producerBean : probe.getDeclaredProducers(bean)) {
        JsonObjectBuilder producerBuilder = createSimpleBeanJson(producerBean, probe);
        if (producerBean.getProducer() instanceof ProducerMethodProducer) {
            ProducerMethodProducer<?, ?> producer = (ProducerMethodProducer<?, ?>) producerBean.getProducer();
            producerBuilder.add(PRODUCER_INFO, annotatedMethodToString((AnnotatedMethod<?>) producer.getAnnotated(), bean.getBeanClass()));
        } else if (producerBean.getProducer() instanceof ProducerFieldProducer) {
            ProducerFieldProducer<?, ?> producer = (ProducerFieldProducer<?, ?>) producerBean.getProducer();
            producerBuilder.add(PRODUCER_INFO, annotatedFieldToString(producer.getAnnotated(), bean.getBeanClass()));
        }
        declaredProducers.add(producerBuilder);
    }
    return declaredProducers;
}
Also used : AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod) ProducerFieldProducer(org.jboss.weld.injection.producer.ProducerFieldProducer) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder) ProducerMethodProducer(org.jboss.weld.injection.producer.ProducerMethodProducer)

Example 10 with JsonArrayBuilder

use of org.jboss.weld.probe.Json.JsonArrayBuilder in project core by weld.

the class JsonObjects method createContextJson.

static JsonObjectBuilder createContextJson(String id, Class<? extends Annotation> scope, BeanManagerImpl beanManager, Probe probe, HttpServletRequest req) {
    JsonObjectBuilder builder = createSimpleContextJson(id, scope);
    builder.add(INSTANCES, inspectContext(scope, beanManager, probe));
    if (req != null && ConversationScoped.class.equals(scope)) {
        HttpSession session = req.getSession(false);
        if (session != null) {
            // Get all available conversation ids
            Object conversationsAttribute = session.getAttribute(AbstractConversationContext.CONVERSATIONS_ATTRIBUTE_NAME);
            if (conversationsAttribute != null && conversationsAttribute instanceof Map) {
                @SuppressWarnings("unchecked") Map<String, ManagedConversation> conversationsMap = (Map<String, ManagedConversation>) conversationsAttribute;
                if (!conversationsMap.isEmpty()) {
                    JsonArrayBuilder cidsBuilder = Json.arrayBuilder();
                    for (String cid : conversationsMap.keySet()) {
                        cidsBuilder.add(cid);
                    }
                    builder.add(CIDS, cidsBuilder);
                }
            }
        }
    }
    return builder;
}
Also used : ConversationScoped(javax.enterprise.context.ConversationScoped) HttpSession(javax.servlet.http.HttpSession) ProxyObject(org.jboss.weld.bean.proxy.ProxyObject) ManagedConversation(org.jboss.weld.context.ManagedConversation) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder) Map(java.util.Map)

Aggregations

JsonArrayBuilder (org.jboss.weld.probe.Json.JsonArrayBuilder)16 JsonObjectBuilder (org.jboss.weld.probe.Json.JsonObjectBuilder)16 ProxyObject (org.jboss.weld.bean.proxy.ProxyObject)5 AbstractBuiltInBean (org.jboss.weld.bean.builtin.AbstractBuiltInBean)3 ObserverMethodImpl (org.jboss.weld.event.ObserverMethodImpl)3 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)3 EventType (org.jboss.weld.probe.BootstrapStats.EventType)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 Annotation (java.lang.annotation.Annotation)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 ArrayList (java.util.ArrayList)2 AnnotatedMethod (javax.enterprise.inject.spi.AnnotatedMethod)2 Bean (javax.enterprise.inject.spi.Bean)2 ProcessAnnotatedType (javax.enterprise.inject.spi.ProcessAnnotatedType)2 ProcessSyntheticAnnotatedType (javax.enterprise.inject.spi.ProcessSyntheticAnnotatedType)2 AbstractClassBean (org.jboss.weld.bean.AbstractClassBean)2 AbstractProducerBean (org.jboss.weld.bean.AbstractProducerBean)2 SessionBean (org.jboss.weld.bean.SessionBean)2 ModuleEnablement (org.jboss.weld.bootstrap.enablement.ModuleEnablement)2