Search in sources :

Example 1 with ReferenceBean

use of org.apache.aries.cdi.container.internal.bean.ReferenceBean in project aries by apache.

the class Phase_Publish method processReferenceDependencies.

private void processReferenceDependencies(BeanManagerImpl beanManagerImpl) {
    Map<ServiceReference<?>, Set<ReferenceBean>> beans = new HashMap<>();
    for (ReferenceDependency referenceDependency : _bc.getReferences()) {
        for (ServiceReference<?> matchingReference : referenceDependency.getMatchingReferences()) {
            Set<ReferenceBean> set = beans.get(matchingReference);
            if (set == null) {
                set = new HashSet<>();
                beans.put(matchingReference, set);
            }
            ReferenceBean existingBean = null;
            for (ReferenceBean bean : set) {
                if (bean.getBindType() == referenceDependency.getBindType() && bean.getBeanClass().equals(referenceDependency.getBeanClass()) && bean.getTypes().contains(referenceDependency.getInjectionPointType())) {
                    existingBean = bean;
                }
            }
            if (existingBean != null) {
                existingBean.addQualifier(referenceDependency.getReference());
                existingBean.addQualifiers(referenceDependency.getInjectionPoint().getQualifiers());
            } else {
                ReferenceBean bean = new ReferenceBean(beanManagerImpl, _bc.getBundleContext(), referenceDependency.getInjectionPointType(), referenceDependency.getBeanClass(), referenceDependency.getBindType(), matchingReference);
                bean.addQualifier(referenceDependency.getReference());
                bean.addQualifiers(referenceDependency.getInjectionPoint().getQualifiers());
                set.add(bean);
                beanManagerImpl.addBean(bean);
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ReferenceBean(org.apache.aries.cdi.container.internal.bean.ReferenceBean) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ReferenceBean (org.apache.aries.cdi.container.internal.bean.ReferenceBean)1 ServiceReference (org.osgi.framework.ServiceReference)1