[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 @Override
public <T extends StrolchPolicy> T getPolicy(PolicyDef policyDef, StrolchTransaction tx) { 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); DBC.PRE.assertNotNull("tx must not be null!", tx);
try { 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 @Override
public <T> Class<T> visit(JavaPolicyDef policyDef) throws ClassNotFoundException { public <T> Class<T> visit(JavaPolicyDef policyDef) throws ClassNotFoundException {
String value = policyDef.getValue(); String value = policyDef.getValue();

View File

@ -47,11 +47,21 @@ public interface PolicyHandler {
* Instantiates the actual policy by resolving the {@link PolicyDef} using a {@link PolicyDefVisitor} * Instantiates the actual policy by resolving the {@link PolicyDef} using a {@link PolicyDefVisitor}
* *
* @param policyDef * @param policyDef
* the {@link PolicyDef} referencing a concrete policy * the {@link PolicyDef} referencing a concrete policy
* @param tx * @param tx
* the current transaction for which the policy is instantiated * the current transaction for which the policy is instantiated
* *
* @return the instantiated instance of the referenced policy * @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);
} }