summaryrefslogtreecommitdiff
path: root/eaaf_core/src
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_core/src')
-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();
+
+ }
+
+}