From c2d6fbd70a2a79396286eb3c3fc7101ff9bfd040 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Wed, 10 Jun 2020 13:39:57 +0200 Subject: Add new AttributeBuilder registration --- .../idp/builder/AttributeBuilderRegistration.java | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/AttributeBuilderRegistration.java (limited to 'eaaf_core/src/main') diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/AttributeBuilderRegistration.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/AttributeBuilderRegistration.java new file mode 100644 index 00000000..135bd789 --- /dev/null +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/AttributeBuilderRegistration.java @@ -0,0 +1,88 @@ +package at.gv.egiz.eaaf.core.impl.idp.builder; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.ServiceLoader; + +import at.gv.egiz.eaaf.core.api.idp.IAttributeBuilder; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class AttributeBuilderRegistration { + + private static HashMap builders; + + private static ServiceLoader attributBuilderLoader = + ServiceLoader.load(IAttributeBuilder.class); + + private static void addBuilder(final IAttributeBuilder builder) { + builders.put(builder.getName(), builder); + } + + static { + builders = new HashMap<>(); + + log.info("Loading protocol attribut-builder modules:"); + if (attributBuilderLoader != null) { + final Iterator moduleLoaderInterator = attributBuilderLoader.iterator(); + while (moduleLoaderInterator.hasNext()) { + try { + final IAttributeBuilder modul = moduleLoaderInterator.next(); + log.info("Loading attribut-builder Modul Information: " + modul.getName()); + addBuilder(modul); + + } catch (final Throwable e) { + log.error("Check configuration! " + "Some attribute-builder modul" + + " is not a valid IAttributeBuilder", e); + } + } + } + + log.info("Loading attribute-builder modules done"); + + } + + /** + * Get a specific attribute builder. + * + * @param name Attribute-builder friendly name + * + * @return Attribute-builder with this name or null if builder does not exists + */ + public static IAttributeBuilder getAttributeBuilder(final String name) { + return builders.get(name); + + } + + /** + * Check if a specific attribute-builder is available. + * + * @param name Attribute-builder friendly name + * @return true if the builder is registered, otherwise false + */ + public static boolean containsBuilder(final String name) { + return builders.containsKey(name); + + } + + /** + * Get all registered attribute-builder. + * + * @return {@link Iterator} of all available builders + */ + public static Iterator getAllRegistratedBuilder() { + return builders.values().iterator(); + + } + + /** + * Get the number of currently register attribute builders. + * + * @return number of attribute builders + */ + public static int getNumberOfRegisteredBuilders() { + return builders.size(); + + } + +} -- cgit v1.2.3