Search in sources :

Example 1 with AbstractBuiltInBean

use of org.jboss.weld.bean.builtin.AbstractBuiltInBean in project core by weld.

the class JsonObjects method createBuiltInDependency.

/**
 * Built-in beans are identified by the set of types. Moreover, each bean deployment archive has its own instance.
 *
 * @param dependency
 * @param probe
 * @param beanManager
 * @param type
 * @return
 */
private static JsonObjectBuilder createBuiltInDependency(Dependency dependency, Probe probe, BeanManagerImpl beanManager, String type) {
    AbstractBuiltInBean<?> builtInBean = (AbstractBuiltInBean<?>) dependency.getBean();
    JsonObjectBuilder builtInDependency = createDependency(probe.getBean(Components.getBuiltinBeanId(builtInBean)), dependency, probe);
    if (builtInBean.getBeanClass().equals(InstanceImpl.class)) {
        // Special treatment of Instance<?>
        Bean<?> lazilyFetched = Components.getInstanceResolvedBean(beanManager, dependency.getInjectionPoint());
        if (lazilyFetched != null && !Components.isBuiltinBeanButNotExtension(lazilyFetched)) {
            JsonObjectBuilder lazilyFetchedDependency = createDependency(lazilyFetched, null, probe);
            lazilyFetchedDependency.add(REQUIRED_TYPE, Formats.formatType(Components.getFacadeType(dependency.getInjectionPoint()), false)).add(QUALIFIERS, createQualifiers(dependency.getInjectionPoint().getQualifiers(), false));
            lazilyFetchedDependency.add(INFO, INFO_FETCHING_LAZILY);
            lazilyFetchedDependency.add(IS_POTENTIAL, true);
            builtInDependency.add(type, Json.arrayBuilder().add(lazilyFetchedDependency));
        }
    }
    return builtInDependency;
}
Also used : AbstractBuiltInBean(org.jboss.weld.bean.builtin.AbstractBuiltInBean) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder)

Example 2 with AbstractBuiltInBean

use of org.jboss.weld.bean.builtin.AbstractBuiltInBean 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 3 with AbstractBuiltInBean

use of org.jboss.weld.bean.builtin.AbstractBuiltInBean in project core by weld.

the class Probe method init.

/**
 * @param beanManager
 */
void init(BeanManagerImpl beanManager) {
    ContextualStore contextualStore = beanManager.getServices().get(ContextualStore.class);
    bdaToManager.putAll(Container.instance(beanManager).beanDeploymentArchives());
    for (Entry<BeanDeploymentArchive, BeanManagerImpl> entry : bdaToManager.entrySet()) {
        ProbeLogger.LOG.processingBeanDeploymentArchive(entry.getKey().getId());
        BeanManagerImpl manager = entry.getValue();
        // Beans
        for (Bean<?> bean : manager.getBeans()) {
            // there's only one Instance bean though
            if (bean instanceof ExtensionBean) {
                // ExtensionBean does not include BeanManager in its BeanIdentifier
                ExtensionBean<?> extensionBean = (ExtensionBean<?>) bean;
                if (!idToBean.containsValue(extensionBean)) {
                    putBean(Components.getId(extensionBean.getIdentifier()), manager, extensionBean);
                }
            } else if (bean instanceof AbstractBuiltInBean<?>) {
                // Built-in beans are identified by the set of types
                String id = Components.getBuiltinBeanId((AbstractBuiltInBean<?>) bean);
                if (!idToBean.containsKey(id)) {
                    putBean(id, bean);
                }
            } else {
                if (manager.isBeanEnabled(bean)) {
                    // Make sure the bean is truly enabled
                    putBean(contextualStore, manager, bean);
                }
            }
        }
        // Interceptors
        for (Interceptor<?> interceptor : manager.getInterceptors()) {
            putBean(contextualStore, manager, interceptor);
        }
        // Decorators
        for (Decorator<?> decorator : manager.getDecorators()) {
            putBean(contextualStore, manager, decorator);
        }
        // Observers
        int customObservers = 0;
        for (ObserverMethod<?> observerMethod : manager.getObservers()) {
            if (observerMethod instanceof ObserverMethodImpl) {
                ObserverMethodImpl<?, ?> observerMethodImpl = (ObserverMethodImpl<?, ?>) observerMethod;
                putObserver(Components.getId(observerMethodImpl.getId()), observerMethodImpl);
            } else {
                // Custom observer methods
                putObserver(Components.getId("" + customObservers++), observerMethod);
            }
        }
    }
    // Find declared producers
    for (Bean<?> candidate : idToBean.values()) {
        BeanKind kind = BeanKind.from(candidate);
        if ((BeanKind.PRODUCER_FIELD.equals(kind) || BeanKind.PRODUCER_METHOD.equals(kind) || BeanKind.RESOURCE.equals(kind)) && candidate instanceof AbstractProducerBean) {
            AbstractProducerBean<?, ?, ?> producerBean = (AbstractProducerBean<?, ?, ?>) candidate;
            beanToDeclaredProducers.put(producerBean.getDeclaringBean(), producerBean);
        }
    }
    findUnusedBeans();
    initTs.set(System.currentTimeMillis());
}
Also used : AbstractBuiltInBean(org.jboss.weld.bean.builtin.AbstractBuiltInBean) ExtensionBean(org.jboss.weld.bean.builtin.ExtensionBean) AbstractProducerBean(org.jboss.weld.bean.AbstractProducerBean) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) ContextualStore(org.jboss.weld.serialization.spi.ContextualStore) ObserverMethodImpl(org.jboss.weld.event.ObserverMethodImpl) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) BeanKind(org.jboss.weld.probe.Components.BeanKind)

Example 4 with AbstractBuiltInBean

use of org.jboss.weld.bean.builtin.AbstractBuiltInBean in project core by weld.

the class Components method getDependencies.

/**
 * @param bean
 * @param beanManager
 * @param probe
 * @return the set of dependencies
 */
static Set<Dependency> getDependencies(Bean<?> bean, BeanManager beanManager, Probe probe) {
    Set<Dependency> dependencies = new HashSet<Dependency>();
    Set<InjectionPoint> injectionPoints = bean.getInjectionPoints();
    if (injectionPoints != null && !injectionPoints.isEmpty()) {
        for (InjectionPoint injectionPoint : injectionPoints) {
            if (injectionPoint.isDelegate()) {
                // Do not include delegate injection points
                continue;
            }
            Set<Bean<?>> beans = beanManager.getBeans(injectionPoint.getType(), injectionPoint.getQualifiers().toArray(new Annotation[injectionPoint.getQualifiers().size()]));
            if (beans.isEmpty()) {
                dependencies.add(Dependency.createUnsatisfied(injectionPoint, null));
            } else {
                try {
                    Bean<?> dependency = beanManager.resolve(beans);
                    if (isBuiltinBeanButNotExtension(dependency)) {
                        dependency = probe.getBean(Components.getBuiltinBeanId((AbstractBuiltInBean<?>) dependency));
                    }
                    dependencies.add(new Dependency(dependency, injectionPoint));
                } catch (AmbiguousResolutionException e) {
                    dependencies.add(Dependency.createAmbiguous(injectionPoint, null));
                }
            }
        }
    }
    return dependencies;
}
Also used : InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) AmbiguousResolutionException(javax.enterprise.inject.AmbiguousResolutionException) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet) SessionBean(org.jboss.weld.bean.SessionBean) ExtensionBean(org.jboss.weld.bean.builtin.ExtensionBean) ForwardingBean(org.jboss.weld.bean.ForwardingBean) ManagedBean(org.jboss.weld.bean.ManagedBean) AbstractBuiltInBean(org.jboss.weld.bean.builtin.AbstractBuiltInBean) Bean(javax.enterprise.inject.spi.Bean)

Example 5 with AbstractBuiltInBean

use of org.jboss.weld.bean.builtin.AbstractBuiltInBean in project core by weld.

the class ProxyFactory method createCompoundProxyName.

private static String createCompoundProxyName(String contextId, Bean<?> bean, TypeInfo typeInfo, StringBuilder name) {
    String className;
    final List<String> interfaces = new ArrayList<String>();
    for (Class<?> type : typeInfo.getInterfaces()) {
        interfaces.add(type.getSimpleName());
    }
    Collections.sort(interfaces);
    for (final String iface : interfaces) {
        name.append(iface);
        name.append('$');
    }
    // However, it is safe to share a proxy class for built-in beans of the same type (e.g. Event)
    if (bean != null && !(bean instanceof AbstractBuiltInBean)) {
        final BeanIdentifier id = Container.instance(contextId).services().get(ContextualStore.class).putIfAbsent(bean);
        int idHash = id.hashCode();
        name.append(Math.abs(idHash == Integer.MIN_VALUE ? 0 : idHash));
    }
    className = name.toString();
    return className;
}
Also used : AbstractBuiltInBean(org.jboss.weld.bean.builtin.AbstractBuiltInBean) ContextualStore(org.jboss.weld.serialization.spi.ContextualStore) BeanIdentifier(org.jboss.weld.serialization.spi.BeanIdentifier) ArrayList(java.util.ArrayList)

Aggregations

AbstractBuiltInBean (org.jboss.weld.bean.builtin.AbstractBuiltInBean)6 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)3 ExtensionBean (org.jboss.weld.bean.builtin.ExtensionBean)3 Annotation (java.lang.annotation.Annotation)2 HashSet (java.util.HashSet)2 AmbiguousResolutionException (javax.enterprise.inject.AmbiguousResolutionException)2 Bean (javax.enterprise.inject.spi.Bean)2 ForwardingBean (org.jboss.weld.bean.ForwardingBean)2 ManagedBean (org.jboss.weld.bean.ManagedBean)2 SessionBean (org.jboss.weld.bean.SessionBean)2 JsonObjectBuilder (org.jboss.weld.probe.Json.JsonObjectBuilder)2 ContextualStore (org.jboss.weld.serialization.spi.ContextualStore)2 ArrayList (java.util.ArrayList)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 AbstractProducerBean (org.jboss.weld.bean.AbstractProducerBean)1 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)1 ObserverMethodImpl (org.jboss.weld.event.ObserverMethodImpl)1 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)1 BeanKind (org.jboss.weld.probe.Components.BeanKind)1 Dependency (org.jboss.weld.probe.Components.Dependency)1