summaryrefslogtreecommitdiff
path: root/eaaf_core/src/main
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2020-06-10 13:41:02 +0200
committerThomas Lenz <thomas.lenz@egiz.gv.at>2020-06-10 13:41:02 +0200
commite3097f723fb9c7b7dda9a1c56f86af0c922651b0 (patch)
treec5652066c288e664faf2d8df26f861e6c0853755 /eaaf_core/src/main
parent9db3b30a4ee0fd6a60672352b033dc48f43b901f (diff)
parent60317229269fa1764b5ff261dd42384c80d66161 (diff)
downloadEAAF-Components-e3097f723fb9c7b7dda9a1c56f86af0c922651b0.tar.gz
EAAF-Components-e3097f723fb9c7b7dda9a1c56f86af0c922651b0.tar.bz2
EAAF-Components-e3097f723fb9c7b7dda9a1c56f86af0c922651b0.zip
Merge branch 'nightlyBuild' of gitlab.iaik.tugraz.at:egiz/eaaf_components into nightlyBuild
Diffstat (limited to 'eaaf_core/src/main')
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/AttributeBuilderRegistration.java88
1 files changed, 88 insertions, 0 deletions
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<String, IAttributeBuilder> builders;
+
+ private static ServiceLoader<IAttributeBuilder> 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<IAttributeBuilder> 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 <code>true</code> if the builder is registered, otherwise <code>false</code>
+ */
+ 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<IAttributeBuilder> 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();
+
+ }
+
+}