summaryrefslogtreecommitdiff
path: root/eaaf_core/src/main/java/at/gv
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2020-06-10 13:39:57 +0200
committerThomas Lenz <thomas.lenz@egiz.gv.at>2020-06-10 13:39:57 +0200
commitc2d6fbd70a2a79396286eb3c3fc7101ff9bfd040 (patch)
tree07271299aa263aee6a60bed4336160bdf0572620 /eaaf_core/src/main/java/at/gv
parent4e4002c7e982218649f10349e634c17770d603d4 (diff)
downloadEAAF-Components-c2d6fbd70a2a79396286eb3c3fc7101ff9bfd040.tar.gz
EAAF-Components-c2d6fbd70a2a79396286eb3c3fc7101ff9bfd040.tar.bz2
EAAF-Components-c2d6fbd70a2a79396286eb3c3fc7101ff9bfd040.zip
Add new AttributeBuilder registration
Diffstat (limited to 'eaaf_core/src/main/java/at/gv')
-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();
+
+ }
+
+}