From b6e9fb6b991b3083d55ec2a2382a4e1a627331e4 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 18 Jun 2019 12:38:18 +0200 Subject: [PATCH] [New] Added PolicyHandler.getPolicyTypes() and .getPolicyKeysByType() --- .../strolch/policy/DefaultPolicyHandler.java | 21 ++++++++++++++ .../java/li/strolch/policy/PolicyHandler.java | 29 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/li.strolch.agent/src/main/java/li/strolch/policy/DefaultPolicyHandler.java b/li.strolch.agent/src/main/java/li/strolch/policy/DefaultPolicyHandler.java index fe8099752..3b3869d9c 100644 --- a/li.strolch.agent/src/main/java/li/strolch/policy/DefaultPolicyHandler.java +++ b/li.strolch.agent/src/main/java/li/strolch/policy/DefaultPolicyHandler.java @@ -19,7 +19,10 @@ import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; import java.text.MessageFormat; +import java.util.Collections; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.StrolchComponent; @@ -71,6 +74,24 @@ public class DefaultPolicyHandler extends StrolchComponent implements PolicyHand super.initialize(configuration); } + public Set getPolicyTypes() { + return new HashSet<>(this.classByTypeMap.keySet()); + } + + public Set getPolicyKeysByType(String type) { + Map> byType = this.classByTypeMap.getMap(type); + if (byType == null) + return Collections.emptySet(); + return new HashSet<>(byType.keySet()); + } + + public Set getPolicyKeysByType(Class clazz) { + Map> byType = this.classByTypeMap.getMap(clazz.getSimpleName()); + if (byType == null) + return Collections.emptySet(); + return new HashSet<>(byType.keySet()); + } + @Override public T getPolicy(PolicyDef policyDef, StrolchTransaction tx) { DBC.PRE.assertNotNull("policyDef must not be null!", policyDef); diff --git a/li.strolch.agent/src/main/java/li/strolch/policy/PolicyHandler.java b/li.strolch.agent/src/main/java/li/strolch/policy/PolicyHandler.java index 33fd8751b..59b6b3602 100644 --- a/li.strolch.agent/src/main/java/li/strolch/policy/PolicyHandler.java +++ b/li.strolch.agent/src/main/java/li/strolch/policy/PolicyHandler.java @@ -15,6 +15,8 @@ */ package li.strolch.policy; +import java.util.Set; + import li.strolch.model.policy.PolicyDef; import li.strolch.model.policy.PolicyDefVisitor; import li.strolch.persistence.api.StrolchTransaction; @@ -32,6 +34,33 @@ import li.strolch.persistence.api.StrolchTransaction; */ public interface PolicyHandler { + /** + * The type of policies known by this {@link PolicyHandler} + * + * @return types of policies known by this {@link PolicyHandler} + */ + Set getPolicyTypes(); + + /** + * Returns the keys defined for the given policy type + * + * @param type + * the type of policy for which to return the keys + * + * @return the keys defined for the given policy type + */ + Set getPolicyKeysByType(Class type); + + /** + * Returns the keys defined for the given policy type + * + * @param type + * the type of policy for which to return the keys + * + * @return the keys defined for the given policy type + */ + Set getPolicyKeysByType(String type); + /** * Instantiates the actual policy by resolving the {@link PolicyDef} using a {@link PolicyDefVisitor} *