[New] Added convenience methods to PolicyDefs

This commit is contained in:
Robert von Burg 2021-10-20 18:16:31 +02:00
parent e03fcacdd6
commit 48ac70ed21
5 changed files with 43 additions and 26 deletions

View File

@ -160,7 +160,7 @@ public class Order extends AbstractStrolchRootElement implements StrolchRootElem
}
@Override
public PolicyDefs getPolicyDefs() throws StrolchPolicyException {
public PolicyDefs getPolicyDefs() {
if (this.policyDefs == null)
throw new StrolchPolicyException(getLocator() + " has no Policies defined!");
return this.policyDefs;
@ -168,7 +168,7 @@ public class Order extends AbstractStrolchRootElement implements StrolchRootElem
@Override
public PolicyDef getPolicyDef(Class<?> clazz) {
return getPolicyDefs().getPolicyDef(clazz.getSimpleName());
return getPolicyDefs().getPolicyDef(clazz);
}
@Override
@ -180,7 +180,7 @@ public class Order extends AbstractStrolchRootElement implements StrolchRootElem
public PolicyDef getPolicyDef(Class<?> clazz, PolicyDef defaultDef) {
if (!hasPolicyDefs())
return defaultDef;
return getPolicyDefs().getPolicyDef(clazz.getSimpleName(), defaultDef);
return getPolicyDefs().getPolicyDef(clazz, defaultDef);
}
@Override
@ -197,12 +197,12 @@ public class Order extends AbstractStrolchRootElement implements StrolchRootElem
@Override
public boolean hasPolicyDef(String type) {
return this.policyDefs != null && policyDefs.hasPolicyDef(type);
return this.policyDefs != null && this.policyDefs.hasPolicyDef(type);
}
@Override
public boolean hasPolicyDef(Class<?> clazz) {
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz.getSimpleName());
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz);
}
@Override

View File

@ -245,7 +245,7 @@ public class Resource extends AbstractStrolchRootElement implements StrolchRootE
@Override
public PolicyDef getPolicyDef(Class<?> clazz) {
return getPolicyDefs().getPolicyDef(clazz.getSimpleName());
return getPolicyDefs().getPolicyDef(clazz);
}
@Override
@ -257,7 +257,7 @@ public class Resource extends AbstractStrolchRootElement implements StrolchRootE
public PolicyDef getPolicyDef(Class<?> clazz, PolicyDef defaultDef) {
if (!hasPolicyDefs())
return defaultDef;
return getPolicyDefs().getPolicyDef(clazz.getSimpleName(), defaultDef);
return getPolicyDefs().getPolicyDef(clazz, defaultDef);
}
@Override
@ -279,7 +279,7 @@ public class Resource extends AbstractStrolchRootElement implements StrolchRootE
@Override
public boolean hasPolicyDef(Class<?> clazz) {
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz.getSimpleName());
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz);
}
@Override

View File

@ -247,26 +247,21 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
return this.policyDefs;
}
@Override
public PolicyDef getPolicyDef(Class<?> clazz) {
return getPolicyDefs().getPolicyDef(clazz);
}
@Override
public PolicyDef getPolicyDef(String type) {
return getPolicyDefs().getPolicyDef(type);
}
@Override
public boolean hasPolicyDefs() {
return this.policyDefs != null;
}
@Override
public PolicyDef getPolicyDef(Class<?> clazz) {
return getPolicyDefs().getPolicyDef(clazz.getSimpleName());
}
@Override
public PolicyDef getPolicyDef(Class<?> clazz, PolicyDef defaultDef) {
if (!hasPolicyDefs())
return defaultDef;
return getPolicyDefs().getPolicyDef(clazz.getSimpleName(), defaultDef);
return getPolicyDefs().getPolicyDef(clazz, defaultDef);
}
@Override
@ -276,14 +271,19 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
return getPolicyDefs().getPolicyDef(type, defaultDef);
}
@Override
public boolean hasPolicyDefs() {
return this.policyDefs != null;
}
@Override
public boolean hasPolicyDef(String type) {
return this.policyDefs != null && policyDefs.hasPolicyDef(type);
return this.policyDefs != null && this.policyDefs.hasPolicyDef(type);
}
@Override
public boolean hasPolicyDef(Class<?> clazz) {
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz.getSimpleName());
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz);
}
@Override

View File

@ -599,7 +599,7 @@ public class Activity extends AbstractStrolchRootElement
@Override
public PolicyDef getPolicyDef(Class<?> clazz) {
return getPolicyDefs().getPolicyDef(clazz.getSimpleName());
return getPolicyDefs().getPolicyDef(clazz);
}
@Override
@ -611,7 +611,7 @@ public class Activity extends AbstractStrolchRootElement
public PolicyDef getPolicyDef(Class<?> clazz, PolicyDef defaultDef) {
if (!hasPolicyDefs())
return defaultDef;
return getPolicyDefs().getPolicyDef(clazz.getSimpleName(), defaultDef);
return getPolicyDefs().getPolicyDef(clazz, defaultDef);
}
@Override
@ -628,12 +628,12 @@ public class Activity extends AbstractStrolchRootElement
@Override
public boolean hasPolicyDef(String type) {
return this.policyDefs != null && policyDefs.hasPolicyDef(type);
return this.policyDefs != null && this.policyDefs.hasPolicyDef(type);
}
@Override
public boolean hasPolicyDef(Class<?> clazz) {
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz.getSimpleName());
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz);
}
@Override

View File

@ -34,7 +34,7 @@ import li.strolch.utils.dbc.DBC;
public class PolicyDefs {
private StrolchElement parent;
private Map<String, PolicyDef> policyDefMap;
private final Map<String, PolicyDef> policyDefMap;
private boolean readOnly;
public PolicyDefs() {
@ -58,6 +58,10 @@ public class PolicyDefs {
return getPolicyDef(type, null);
}
public PolicyDef getPolicyDef(Class<?> clazz) {
return getPolicyDef(clazz.getSimpleName(), null);
}
public PolicyDef getPolicyDef(String type, PolicyDef defaultDef) {
if (!this.policyDefMap.containsKey(type)) {
if (defaultDef != null)
@ -69,10 +73,18 @@ public class PolicyDefs {
return this.policyDefMap.get(type);
}
public PolicyDef getPolicyDef(Class<?> clazz, PolicyDef defaultDef) {
return getPolicyDef(clazz.getSimpleName(), defaultDef);
}
public boolean hasPolicyDef(String type) {
return this.policyDefMap.containsKey(type);
}
public boolean hasPolicyDef(Class<?> clazz) {
return this.policyDefMap.containsKey(clazz.getSimpleName());
}
public boolean hasPolicyDefs() {
return !this.policyDefMap.isEmpty();
}
@ -88,6 +100,11 @@ public class PolicyDefs {
this.policyDefMap.remove(type);
}
public void remove(Class<?> clazz) {
assertNotReadonly();
this.policyDefMap.remove(clazz.getSimpleName());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();