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;
}
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;
}
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;
}
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());
}
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;
}
Aggregations