diff --git a/src/main/java/eu/europa/ted/eforms/sdk/component/SdkComponentDescriptor.java b/src/main/java/eu/europa/ted/eforms/sdk/component/SdkComponentDescriptor.java index 6964bfa..ffb44a4 100644 --- a/src/main/java/eu/europa/ted/eforms/sdk/component/SdkComponentDescriptor.java +++ b/src/main/java/eu/europa/ted/eforms/sdk/component/SdkComponentDescriptor.java @@ -114,7 +114,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) return false; SdkComponentDescriptor other = (SdkComponentDescriptor) obj; - return componentType == other.componentType + return componentType == other.componentType && Objects.equals(sdkVersion, other.sdkVersion) && Objects.equals(qualifier, other.qualifier) && Objects.equals(implType, other.implType); diff --git a/src/main/java/eu/europa/ted/eforms/sdk/component/SdkComponentFactory.java b/src/main/java/eu/europa/ted/eforms/sdk/component/SdkComponentFactory.java index c544773..5c91764 100644 --- a/src/main/java/eu/europa/ted/eforms/sdk/component/SdkComponentFactory.java +++ b/src/main/java/eu/europa/ted/eforms/sdk/component/SdkComponentFactory.java @@ -4,7 +4,9 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; import java.util.stream.Stream; @@ -78,6 +80,12 @@ private void populateComponents() { .map(Package::getName) .toArray(String[]::new); + if (logger.isTraceEnabled()) { + final List packages = Arrays.asList(availablePackages); + packages.stream().sorted() + .forEach(p -> logger.trace(p)); + } + new Reflections(ConfigurationBuilder.build().forPackages(availablePackages)) .getTypesAnnotatedWith(annotationType).stream() .forEach((Class clazz) -> { @@ -126,22 +134,39 @@ protected T getComponentImpl(String sdkVersion, final SdkComponentType compo } protected T getComponentImpl(String sdkVersion, final SdkComponentType componentType, - final String qualifier, final Class intf, Object... initArgs) throws InstantiationException { + final String qualifier, final Class intf, Object... initArgs) + throws InstantiationException { String normalizedVersion = normalizeVersion(sdkVersion); ComponentSelector selector = new ComponentSelector(componentType, qualifier); + Map> map = + Optional.ofNullable(componentsMap.get(normalizedVersion)) + .orElseGet(Collections::emptyMap); + + if (logger.isTraceEnabled()) { + logger.trace("Looking for component with version=[{}], componentType=[{}], qualifier=[{}]", + normalizedVersion, selector.componentType, selector.qualifier); + for (Entry> entry : map.entrySet()) { + logger.trace( + "Available component for this version: " + + "componentType=[{}], qualifier=[{}], value=[{}]", + entry.getKey().componentType, + entry.getKey().qualifier, + entry.getValue().getImplType().getName()); + } + } + @SuppressWarnings("unchecked") SdkComponentDescriptor descriptor = - (SdkComponentDescriptor) Optional.ofNullable(componentsMap.get(normalizedVersion)) - .orElseGet(Collections::emptyMap).get(selector); + (SdkComponentDescriptor) map.get(selector); if (descriptor == null) { logger.error("Failed to load required components of SDK [{}]", sdkVersion); throw new IllegalArgumentException( MessageFormat.format( - "No implementation found for SDK [{0}], component type [{1}] and qualifier '{2}'.", + "No implementation found for SDK [{0}], component type [{1}] and qualifier [{2}].", sdkVersion, componentType, qualifier)); }