public BeansModel build()

in cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/BeansModelBuilder.java [51:103]


	public BeansModel build() {
		List<URL> beanDescriptorURLs = new ArrayList<URL>();
		Map<String, Object> attributes = getAttributes();

		List<String> beanDescriptorPaths = cast(attributes.get(REQUIREMENT_DESCRIPTOR_ATTRIBUTE));

		if (beanDescriptorPaths == null) {
			beanDescriptorPaths = new ArrayList<>();
		}

		if (beanDescriptorPaths.isEmpty()) {
			beanDescriptorPaths.add("META-INF/beans.xml");
		}

		if (beanDescriptorPaths != null) {
			for (String descriptorPath : beanDescriptorPaths) {
				URL url = getResource(descriptorPath);

				if (url != null) {
					beanDescriptorURLs.add(url);
				}
			}
		}

		@SuppressWarnings("unchecked")
		List<String> beanClassNames = Optional.ofNullable(
			_attributes.get(REQUIREMENT_BEANS_ATTRIBUTE)
		).map(v -> (List<String>)v).orElse(Collections.emptyList());

		Map<String, OSGiBean> beans = new HashMap<>();

		for (String beanClassName : beanClassNames) {
			try {
				Class<?> clazz = _aggregateClassLoader.loadClass(beanClassName);
				if (clazz.isAnnotationPresent(Vetoed.class) ||
						// should be recursive but at the end this is generally enough and faster
						(clazz.getPackage() != null && clazz.getPackage().isAnnotationPresent(Vetoed.class))) {
					continue;
				}

				beans.put(beanClassName, new OSGiBean.Builder(_containerState.containerLogs(), clazz).build());

				_log.debug(l -> l.debug("CCR found bean {} on {}", beanClassName, _containerState.bundle()));
			}
			catch (Throwable t) {
				_log.error(l -> l.error("CCR Error loading class {} on {}", beanClassName, _containerState.bundle(), t));

				_containerState.error(t);
			}
		}

		return new BeansModel(beans, beanDescriptorURLs);
	}