[New] Added PolicyHandler.isPolicyDefAvailable()

This commit is contained in:
Robert von Burg 2019-01-16 17:25:57 +01:00
parent 368247726b
commit 8e3b22b3e3
2 changed files with 36 additions and 12 deletions

View File

@ -81,6 +81,7 @@ public class DefaultPolicyHandler extends StrolchComponent implements PolicyHand
@Override
public <T extends StrolchPolicy> T getPolicy(PolicyDef policyDef, StrolchTransaction tx) {
DBC.PRE.assertNotNull("policyDef must not be null!", policyDef);
DBC.PRE.assertNotNull("tx must not be null!", tx);
try {
@ -94,6 +95,19 @@ public class DefaultPolicyHandler extends StrolchComponent implements PolicyHand
}
}
@Override
public boolean isPolicyDefAvailable(PolicyDef policyDef) {
DBC.PRE.assertNotNull("policyDef must not be null!", policyDef);
if (policyDef instanceof KeyPolicyDef)
return this.classByTypeMap.containsElement(policyDef.getType(), policyDef.getValue());
if (policyDef instanceof JavaPolicyDef)
return true;
throw new IllegalArgumentException("Unhandled PolicyDev instance " + policyDef.getClass());
}
@Override
public <T> Class<T> visit(JavaPolicyDef policyDef) throws ClassNotFoundException {
String value = policyDef.getValue();

View File

@ -53,5 +53,15 @@ public interface PolicyHandler {
*
* @return the instantiated instance of the referenced policy
*/
public <T extends StrolchPolicy> T getPolicy(PolicyDef policyDef, StrolchTransaction tx);
<T extends StrolchPolicy> T getPolicy(PolicyDef policyDef, StrolchTransaction tx);
/**
* Returns true, if the policy definition is known
*
* @param policyDef
* the policy definition to check for
*
* @return true if the policy definition is known, false otherwise
*/
boolean isPolicyDefAvailable(PolicyDef policyDef);
}