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