[New] Added StrolchTransaction.getPolicy(PolicyContainer, Class<T>) to simplify getting policies

This commit is contained in:
Robert von Burg 2021-07-19 12:06:55 +02:00
parent 87804809f3
commit 7904bb45d7
2 changed files with 20 additions and 0 deletions

View File

@ -418,6 +418,12 @@ public abstract class AbstractTransaction implements StrolchTransaction {
return this.container;
}
@Override
public <T extends StrolchPolicy> T getPolicy(PolicyContainer element, Class<T> clazz) {
PolicyDef policyDef = element.getPolicyDef(clazz);
return getContainer().getComponent(PolicyHandler.class).getPolicy(policyDef, this);
}
@Override
@Deprecated
public <T extends StrolchPolicy> T getPolicy(PolicyDef policyDef) {

View File

@ -229,6 +229,20 @@ public interface StrolchTransaction extends AutoCloseable {
*/
ComponentContainer getContainer();
/**
* Instantiates the policy using the given {@link Class} to retrieve the {@link PolicyDef} from the given element
*
* @param element
* the element from which to retrieve the {@link PolicyDef
* @param <T>
* the type of policy to return
*
* @return the policy
* @param clazz
* the type of policy to return
*/
<T extends StrolchPolicy> T getPolicy(PolicyContainer element, Class<T> clazz);
/**
* Instantiates the policy using the given {@link PolicyDef}
*