Search in sources :

Example 6 with JsonObjectBuilder

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

the class JsonObjects method createBasicBeanJson.

/**
 * The basic representation consists of the simple representation plus the scope, bean types and qualifiers.
 *
 * @param bean
 * @param probe
 * @return the basic bean representation
 */
static JsonObjectBuilder createBasicBeanJson(Bean<?> bean, Probe probe) {
    JsonObjectBuilder beanBuilder = createSimpleBeanJson(bean, probe);
    // SCOPE
    beanBuilder.add(SCOPE, simplifiedScope(bean.getScope()));
    // BEAN TYPES
    JsonArrayBuilder typesBuilder = Json.arrayBuilder();
    for (Type type : sortTypes(bean.getTypes())) {
        // Omit java.lang.Object
        if (Object.class.equals(type)) {
            continue;
        }
        typesBuilder.add(Formats.formatType(type, false));
    }
    beanBuilder.add(TYPES, typesBuilder);
    // QUALIFIERS
    if (bean.getQualifiers() != null && !bean.getQualifiers().isEmpty()) {
        beanBuilder.add(QUALIFIERS, createQualifiers(bean.getQualifiers(), true));
    }
    // ALTERNATIVE
    if (bean.isAlternative()) {
        beanBuilder.add(IS_ALTERNATIVE, true);
    }
    // UNUSED
    if (probe.isUnused(bean)) {
        beanBuilder.add(UNUSED, true);
    }
    return beanBuilder;
}
Also used : 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) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder)

Example 7 with JsonObjectBuilder

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

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

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

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

the class JsonObjects method createSimpleObserverJson.

static JsonObjectBuilder createSimpleObserverJson(ObserverMethod<?> observerMethod, Probe probe) {
    JsonObjectBuilder observerBuilder = Json.objectBuilder();
    observerBuilder.add(ID, probe.getObserverId(observerMethod));
    observerBuilder.add(BEAN_CLASS, observerMethod.getBeanClass().getName());
    observerBuilder.add(OBSERVED_TYPE, Formats.formatType(observerMethod.getObservedType(), false));
    return observerBuilder;
}
Also used : JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder)

Aggregations

JsonObjectBuilder (org.jboss.weld.probe.Json.JsonObjectBuilder)25 JsonArrayBuilder (org.jboss.weld.probe.Json.JsonArrayBuilder)16 ProxyObject (org.jboss.weld.bean.proxy.ProxyObject)5 AbstractBuiltInBean (org.jboss.weld.bean.builtin.AbstractBuiltInBean)4 ObserverMethodImpl (org.jboss.weld.event.ObserverMethodImpl)4 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)4 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