use of org.jboss.weld.bootstrap.enablement.ModuleEnablement 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;
}
use of org.jboss.weld.bootstrap.enablement.ModuleEnablement in project core by weld.
the class BeanDeployment method createEnablement.
/**
* Initializes module enablement.
*
* @see ModuleEnablement
*/
public void createEnablement() {
GlobalEnablementBuilder builder = beanManager.getServices().get(GlobalEnablementBuilder.class);
ModuleEnablement enablement = builder.createModuleEnablement(this);
beanManager.setEnabled(enablement);
if (BootstrapLogger.LOG.isDebugEnabled()) {
BootstrapLogger.LOG.enabledAlternatives(this.beanManager, WeldCollections.toMultiRowString(enablement.getAllAlternatives()));
BootstrapLogger.LOG.enabledDecorators(this.beanManager, WeldCollections.toMultiRowString(enablement.getDecorators()));
BootstrapLogger.LOG.enabledInterceptors(this.beanManager, WeldCollections.toMultiRowString(enablement.getInterceptors()));
}
}
use of org.jboss.weld.bootstrap.enablement.ModuleEnablement in project core by weld.
the class JsonObjects method createDeploymentJson.
/**
* @param beanManager
* @return the root resource representation
*/
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "We want to catch all exceptions, runtime included.")
static String createDeploymentJson(BeanManagerImpl beanManager, Probe probe) {
Map<BeanDeploymentArchive, BeanManagerImpl> beanDeploymentArchivesMap = Container.instance(beanManager).beanDeploymentArchives();
AnnotationApiAbstraction annotationApi = beanManager.getServices().get(AnnotationApiAbstraction.class);
JsonObjectBuilder deploymentBuilder = Json.objectBuilder();
// INIT TS
deploymentBuilder.add(INIT_TS, probe.getInitTs());
// CONTEXT ID
deploymentBuilder.add(CONTEXT_ID, beanManager.getContextId());
// WELD VERSION
deploymentBuilder.add(VERSION, Formats.getSimpleVersion());
// BEAN DEPLOYMENT ARCHIVES
JsonArrayBuilder bdasBuilder = Json.arrayBuilder();
List<BeanDeploymentArchive> bdas = new ArrayList<BeanDeploymentArchive>(beanDeploymentArchivesMap.keySet());
Collections.sort(bdas, probe.getBdaComparator());
for (BeanDeploymentArchive bda : bdas) {
JsonObjectBuilder bdaBuilder = createSimpleBdaJson(bda.getId());
// If beans.xml is not found it's likely an implicit bean archive
BeansXml beansXml = bda.getBeansXml();
bdaBuilder.add(BEAN_DISCOVERY_MODE, beansXml != null ? beansXml.getBeanDiscoveryMode().toString() : BeanDiscoveryMode.ANNOTATED.toString());
// beans.xml
if (beansXml != null) {
JsonObjectBuilder beansXmlBuilder = Json.objectBuilder();
if (beansXml.equals(BeansXml.EMPTY_BEANS_XML)) {
beansXmlBuilder.add(MARKER, Boolean.TRUE);
} else {
beansXmlBuilder.add(Strings.URL, beansXml.getUrl() != null ? beansXml.getUrl().toString() : EMPTY);
beansXmlBuilder.add(VERSION, beansXml.getVersion() != null ? beansXml.getVersion().toString() : EMPTY);
beansXmlBuilder.add(TRIMMED, beansXml.isTrimmed());
if (beansXml.getScanning() != null && (!beansXml.getScanning().getExcludes().isEmpty() || !beansXml.getScanning().getExcludes().isEmpty())) {
JsonArrayBuilder scanBuilder = Json.arrayBuilder();
createMetadataArrayJson(scanBuilder, beansXml.getScanning().getExcludes(), EXCLUDE);
createMetadataArrayJson(scanBuilder, beansXml.getScanning().getIncludes(), INCLUDE);
beansXmlBuilder.add(SCAN, scanBuilder);
}
}
bdaBuilder.add(Strings.BEANS_XML, beansXmlBuilder);
}
// Enablement - interceptors, decorators, alternatives
JsonObjectBuilder enablementBuilder = Json.objectBuilder(true);
ModuleEnablement enablement = beanDeploymentArchivesMap.get(bda).getEnabled();
JsonArrayBuilder interceptors = Json.arrayBuilder();
for (Class<?> interceptor : Components.getSortedProbeComponetCandidates(enablement.getInterceptors())) {
Bean<?> interceptorBean = findEnabledBean(interceptor, BeanKind.INTERCEPTOR, probe);
if (interceptorBean != null) {
JsonObjectBuilder builder = decorateProbeComponent(interceptor, createSimpleBeanJson(interceptorBean, probe));
if (beansXml != null) {
for (Metadata<String> meta : beansXml.getEnabledInterceptors()) {
if (meta.getValue().equals(interceptorBean.getBeanClass().getName())) {
// Locally enabled
builder.add(BEANS_XML, true);
}
}
}
Object priority = interceptorBean.getBeanClass().getAnnotation(annotationApi.PRIORITY_ANNOTATION_CLASS);
if (priority != null) {
builder.add(PRIORITY, annotationApi.getPriority(priority));
}
if (builder.has(PRIORITY) && builder.has(BEANS_XML)) {
builder.add(CONFLICTS, true);
}
interceptors.add(builder);
}
}
enablementBuilder.add(INTERCEPTORS, interceptors);
JsonArrayBuilder decorators = Json.arrayBuilder();
for (Class<?> decorator : enablement.getDecorators()) {
Bean<?> decoratorBean = findEnabledBean(decorator, BeanKind.DECORATOR, probe);
if (decoratorBean != null) {
JsonObjectBuilder builder = createSimpleBeanJson(decoratorBean, probe);
if (beansXml != null) {
for (Metadata<String> meta : beansXml.getEnabledDecorators()) {
if (meta.getValue().equals(decoratorBean.getBeanClass().getName())) {
// Locally enabled
builder.add(BEANS_XML, true);
}
}
}
Object priority = decoratorBean.getBeanClass().getAnnotation(annotationApi.PRIORITY_ANNOTATION_CLASS);
if (priority != null) {
builder.add(PRIORITY, annotationApi.getPriority(priority));
}
if (builder.has(PRIORITY) && builder.has(BEANS_XML)) {
builder.add(CONFLICTS, true);
}
decorators.add(builder);
}
}
enablementBuilder.add(DECORATORS, decorators);
JsonArrayBuilder alternatives = Json.arrayBuilder();
for (Class<?> clazz : Sets.union(enablement.getAlternativeClasses(), enablement.getGlobalAlternatives())) {
Bean<?> alternativeBean = findAlternativeBean(clazz, probe);
if (alternativeBean != null) {
JsonObjectBuilder builder = createSimpleBeanJson(alternativeBean, probe);
if (enablement.getAlternativeClasses().contains(clazz)) {
builder.add(BEANS_XML, true);
}
if (enablement.getGlobalAlternatives().contains(clazz)) {
Object priority = clazz.getAnnotation(annotationApi.PRIORITY_ANNOTATION_CLASS);
if (priority != null) {
builder.add(PRIORITY, annotationApi.getPriority(priority));
}
}
alternatives.add(builder);
}
}
for (Class<? extends Annotation> stereotype : enablement.getAlternativeStereotypes()) {
Set<Bean<?>> beans = findAlternativeStereotypeBeans(stereotype, probe);
if (!beans.isEmpty()) {
for (Bean<?> bean : beans) {
JsonObjectBuilder builder = createSimpleBeanJson(bean, probe);
builder.add(BEANS_XML, true);
alternatives.add(builder);
}
}
}
enablementBuilder.add(ALTERNATIVES, alternatives);
bdaBuilder.add(ENABLEMENT, enablementBuilder);
// Accessible BDAs
BeanManagerImpl manager = beanDeploymentArchivesMap.get(bda);
JsonArrayBuilder accesibleBdasBuilder = Json.arrayBuilder();
for (BeanManagerImpl accesible : manager.getAccessibleManagers()) {
accesibleBdasBuilder.add(Components.getId(accesible.getId()));
}
bdaBuilder.add(ACCESSIBLE_BDAS, accesibleBdasBuilder);
bdaBuilder.add(BEANS, Components.getNumberOfEnabledBeans(manager));
bdasBuilder.add(bdaBuilder);
}
deploymentBuilder.add(BDAS, bdasBuilder);
// CONFIGURATION
JsonArrayBuilder configBuilder = Json.arrayBuilder();
WeldConfiguration configuration = beanManager.getServices().get(WeldConfiguration.class);
for (ConfigurationKey key : Reports.getSortedConfigurationKeys()) {
Object defaultValue = key.getDefaultValue();
String desc = Reports.getDesc(key);
if (desc == null) {
// Don't show config options without description
continue;
}
Object value = Reports.getValue(key, configuration);
if (value == null) {
// Unsupported property type
continue;
}
configBuilder.add(Json.objectBuilder().add(NAME, key.get()).add(DEFAULT_VALUE, defaultValue.toString()).add(VALUE, value.toString()).add(DESCRIPTION, desc));
}
deploymentBuilder.add(CONFIGURATION, configBuilder);
// INSPECTABLE CONTEXTS
deploymentBuilder.add(CONTEXTS, createContextsJson(beanManager, probe));
// DASHBOARD DATA
JsonObjectBuilder dashboardBuilder = Json.objectBuilder();
// Application
JsonObjectBuilder appBuilder = Json.objectBuilder();
appBuilder.add(BEANS, probe.getApplicationBeansCount());
appBuilder.add(OBSERVERS, probe.getApplicationObserversCount());
dashboardBuilder.add(APPLICATION, appBuilder);
// Bootstrap
dashboardBuilder.add(BOOSTRAP_STATS, createBootstrapStatsJson(probe));
deploymentBuilder.add(DASHBOARD, dashboardBuilder);
return deploymentBuilder.build();
}
Aggregations