Search in sources :

Example 1 with ServiceModel

use of org.apache.aries.cdi.container.internal.model.ServiceModel in project aries by apache.

the class Phase_Publish method processRequirementDefinedServices.

private void processRequirementDefinedServices(BeanManagerImpl beanManagerImpl) {
    Collection<ServiceModel> serviceModels = _bc.getServiceModels();
    for (ServiceModel serviceModel : serviceModels) {
        try {
            Class<?> beanClass = _bc.loadClass(serviceModel.getBeanClass());
            Set<Bean<?>> beans = beanManagerImpl.getBeans(beanClass, AnyLiteral.INSTANCE);
            if (beans.isEmpty()) {
                _log.error("CDIe - MANIFEST service processing cannot find bean for class {}", serviceModel.getBeanClass());
                continue;
            }
            Bean<?> bean = beanManagerImpl.resolve(beans);
            CreationalContext<?> creationalContext = beanManagerImpl.createCreationalContext(bean);
            List<String> provides = serviceModel.getProvides();
            List<Class<?>> interfaces = new ArrayList<>();
            for (String provide : provides) {
                try {
                    interfaces.add(_bc.loadClass(provide));
                } catch (Exception e) {
                    _log.error("CDIe - Failure loading provided interface for service {}", provide);
                }
            }
            ServiceDeclaration serviceDeclaration = new ServiceDeclaration(ServiceLiteral.from(interfaces.toArray(new Class<?>[interfaces.size()]), serviceModel.getProperties()), bean, creationalContext);
            processServiceDeclaration(serviceDeclaration);
        } catch (ClassNotFoundException cnfe) {
            _log.error("CDIe - MANIFEST service processing cannot load class {}", serviceModel.getBeanClass(), cnfe);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ReferenceBean(org.apache.aries.cdi.container.internal.bean.ReferenceBean) ConfigurationBean(org.apache.aries.cdi.container.internal.bean.ConfigurationBean) Bean(javax.enterprise.inject.spi.Bean) ServiceModel(org.apache.aries.cdi.container.internal.model.ServiceModel)

Aggregations

ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Bean (javax.enterprise.inject.spi.Bean)1 ConfigurationBean (org.apache.aries.cdi.container.internal.bean.ConfigurationBean)1 ReferenceBean (org.apache.aries.cdi.container.internal.bean.ReferenceBean)1 ServiceModel (org.apache.aries.cdi.container.internal.model.ServiceModel)1