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