[New] Added tx.getPolicyDef(PolicyDef, PolicyDef)
This commit is contained in:
parent
786b8d0df4
commit
2332c6d0b3
|
@ -385,6 +385,11 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
|||
return getContainer().getComponent(PolicyHandler.class).getPolicy(policyDef, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends StrolchPolicy> T getPolicy(PolicyDef policyDef, PolicyDef defaultDef) {
|
||||
return getContainer().getComponent(PolicyHandler.class).getPolicy(policyDef, defaultDef, this);
|
||||
}
|
||||
|
||||
private void assertQueryAllowed(StrolchQuery query) {
|
||||
try {
|
||||
getPrivilegeContext().validateAction(query);
|
||||
|
|
|
@ -184,6 +184,20 @@ public interface StrolchTransaction extends AutoCloseable {
|
|||
*/
|
||||
<T extends StrolchPolicy> T getPolicy(PolicyDef policyDef);
|
||||
|
||||
/**
|
||||
* Instantiates the policy using the given {@link PolicyDef}, or if not available, the default policy
|
||||
*
|
||||
* @param policyDef
|
||||
* the policy definition
|
||||
* @param defaultDef
|
||||
* the default policy definition if the given policy definition is unavailable
|
||||
* @param <T>
|
||||
* the type of policy to return
|
||||
*
|
||||
* @return the policy
|
||||
*/
|
||||
<T extends StrolchPolicy> T getPolicy(PolicyDef policyDef, PolicyDef defaultDef);
|
||||
|
||||
/**
|
||||
* Returns the currently set {@link TransactionCloseStrategy}
|
||||
*
|
||||
|
|
|
@ -94,11 +94,21 @@ public class DefaultPolicyHandler extends StrolchComponent implements PolicyHand
|
|||
|
||||
@Override
|
||||
public <T extends StrolchPolicy> T getPolicy(PolicyDef policyDef, StrolchTransaction tx) {
|
||||
return getPolicy(policyDef, null, tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends StrolchPolicy> T getPolicy(PolicyDef policyDef, PolicyDef defaultDef, StrolchTransaction tx) {
|
||||
DBC.PRE.assertNotNull("policyDef must not be null!", policyDef);
|
||||
DBC.PRE.assertNotNull("tx must not be null!", tx);
|
||||
try {
|
||||
|
||||
Class<T> clazz = policyDef.accept(this);
|
||||
Class<T> clazz;
|
||||
if (defaultDef != null && !isPolicyDefAvailable(policyDef))
|
||||
clazz = defaultDef.accept(this);
|
||||
else
|
||||
clazz = policyDef.accept(this);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Constructor<T> constructor = (Constructor<T>) getConstructorForPolicy(clazz);
|
||||
if (constructor.getParameterCount() == 1)
|
||||
|
|
|
@ -73,6 +73,21 @@ public interface PolicyHandler {
|
|||
*/
|
||||
<T extends StrolchPolicy> T getPolicy(PolicyDef policyDef, StrolchTransaction tx);
|
||||
|
||||
/**
|
||||
* Instantiates the actual policy by resolving the {@link PolicyDef} using a {@link PolicyDefVisitor}, or if not
|
||||
* available, using the default policy definition
|
||||
*
|
||||
* @param policyDef
|
||||
* the {@link PolicyDef} referencing a concrete policy
|
||||
* @param defaultDef
|
||||
* the default {@link PolicyDef} to use if the other is not available
|
||||
* @param tx
|
||||
* the current transaction for which the policy is instantiated
|
||||
*
|
||||
* @return the instantiated instance of the referenced policy
|
||||
*/
|
||||
<T extends StrolchPolicy> T getPolicy(PolicyDef policyDef, PolicyDef defaultDef, StrolchTransaction tx);
|
||||
|
||||
/**
|
||||
* Returns true, if the policy definition is known
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue