Skip to content

Commit

Permalink
ComponentFactory: Improve SymbolResolver creation (TEDEFO-3286)
Browse files Browse the repository at this point in the history
Allow creating SymbolResolver implementations with constructors that
take different parameters.
A SymbolResolver does not necessarily need the path to SDK files,
so add a method overload that takes a varargs to allow any kind of
constructor parameters.
  • Loading branch information
bertrand-lorentz committed Apr 18, 2024
1 parent 718e8c8 commit 9b8a7de
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,30 @@ public static SymbolResolver getSymbolResolver(final String sdkVersion, final Pa
*/
public static SymbolResolver getSymbolResolver(final String sdkVersion, final String qualifier,
final Path sdkRootPath) throws InstantiationException {
return getSymbolResolver(sdkVersion, qualifier, sdkRootPath);
}

/**
* Gets the single instance containing the symbols defined in the given version of the eForms SDK.
*
* @param sdkVersion Version of the SDK
* @param qualifier Qualifier to choose between several implementations
* @param parameters Array of objects to be passed as arguments to the constructor of the
* SymbolResolver implementation
* @return The single instance containing the symbols defined in the given version of the eForms
* SDK.
* @throws InstantiationException If the SDK version is not supported.
*/
public static SymbolResolver getSymbolResolver(final String sdkVersion, final String qualifier,
Object... parameters) throws InstantiationException {

VersionQualifier key = ComponentFactory.INSTANCE.new VersionQualifier(sdkVersion, qualifier);

return instances.computeIfAbsent(key, k -> {
try {
return ComponentFactory.INSTANCE.getComponentImpl(sdkVersion,
SdkComponentType.SYMBOL_RESOLVER, qualifier, SymbolResolver.class, sdkVersion,
sdkRootPath);
parameters);
} catch (InstantiationException e) {
throw new RuntimeException(MessageFormat.format(
"Failed to instantiate SDK Symbol Resolver for SDK version [{0}]", sdkVersion), e);
Expand Down

0 comments on commit 9b8a7de

Please sign in to comment.