[New] Added convenience methods to PolicyDefs
This commit is contained in:
parent
e03fcacdd6
commit
48ac70ed21
|
@ -160,7 +160,7 @@ public class Order extends AbstractStrolchRootElement implements StrolchRootElem
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PolicyDefs getPolicyDefs() throws StrolchPolicyException {
|
public PolicyDefs getPolicyDefs() {
|
||||||
if (this.policyDefs == null)
|
if (this.policyDefs == null)
|
||||||
throw new StrolchPolicyException(getLocator() + " has no Policies defined!");
|
throw new StrolchPolicyException(getLocator() + " has no Policies defined!");
|
||||||
return this.policyDefs;
|
return this.policyDefs;
|
||||||
|
@ -168,7 +168,7 @@ public class Order extends AbstractStrolchRootElement implements StrolchRootElem
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PolicyDef getPolicyDef(Class<?> clazz) {
|
public PolicyDef getPolicyDef(Class<?> clazz) {
|
||||||
return getPolicyDefs().getPolicyDef(clazz.getSimpleName());
|
return getPolicyDefs().getPolicyDef(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -180,7 +180,7 @@ public class Order extends AbstractStrolchRootElement implements StrolchRootElem
|
||||||
public PolicyDef getPolicyDef(Class<?> clazz, PolicyDef defaultDef) {
|
public PolicyDef getPolicyDef(Class<?> clazz, PolicyDef defaultDef) {
|
||||||
if (!hasPolicyDefs())
|
if (!hasPolicyDefs())
|
||||||
return defaultDef;
|
return defaultDef;
|
||||||
return getPolicyDefs().getPolicyDef(clazz.getSimpleName(), defaultDef);
|
return getPolicyDefs().getPolicyDef(clazz, defaultDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -197,12 +197,12 @@ public class Order extends AbstractStrolchRootElement implements StrolchRootElem
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPolicyDef(String type) {
|
public boolean hasPolicyDef(String type) {
|
||||||
return this.policyDefs != null && policyDefs.hasPolicyDef(type);
|
return this.policyDefs != null && this.policyDefs.hasPolicyDef(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPolicyDef(Class<?> clazz) {
|
public boolean hasPolicyDef(Class<?> clazz) {
|
||||||
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz.getSimpleName());
|
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -245,7 +245,7 @@ public class Resource extends AbstractStrolchRootElement implements StrolchRootE
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PolicyDef getPolicyDef(Class<?> clazz) {
|
public PolicyDef getPolicyDef(Class<?> clazz) {
|
||||||
return getPolicyDefs().getPolicyDef(clazz.getSimpleName());
|
return getPolicyDefs().getPolicyDef(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -257,7 +257,7 @@ public class Resource extends AbstractStrolchRootElement implements StrolchRootE
|
||||||
public PolicyDef getPolicyDef(Class<?> clazz, PolicyDef defaultDef) {
|
public PolicyDef getPolicyDef(Class<?> clazz, PolicyDef defaultDef) {
|
||||||
if (!hasPolicyDefs())
|
if (!hasPolicyDefs())
|
||||||
return defaultDef;
|
return defaultDef;
|
||||||
return getPolicyDefs().getPolicyDef(clazz.getSimpleName(), defaultDef);
|
return getPolicyDefs().getPolicyDef(clazz, defaultDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -279,7 +279,7 @@ public class Resource extends AbstractStrolchRootElement implements StrolchRootE
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPolicyDef(Class<?> clazz) {
|
public boolean hasPolicyDef(Class<?> clazz) {
|
||||||
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz.getSimpleName());
|
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -247,26 +247,21 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
|
||||||
return this.policyDefs;
|
return this.policyDefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PolicyDef getPolicyDef(Class<?> clazz) {
|
||||||
|
return getPolicyDefs().getPolicyDef(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PolicyDef getPolicyDef(String type) {
|
public PolicyDef getPolicyDef(String type) {
|
||||||
return getPolicyDefs().getPolicyDef(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
|
@Override
|
||||||
public PolicyDef getPolicyDef(Class<?> clazz, PolicyDef defaultDef) {
|
public PolicyDef getPolicyDef(Class<?> clazz, PolicyDef defaultDef) {
|
||||||
if (!hasPolicyDefs())
|
if (!hasPolicyDefs())
|
||||||
return defaultDef;
|
return defaultDef;
|
||||||
return getPolicyDefs().getPolicyDef(clazz.getSimpleName(), defaultDef);
|
return getPolicyDefs().getPolicyDef(clazz, defaultDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -276,14 +271,19 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
|
||||||
return getPolicyDefs().getPolicyDef(type, defaultDef);
|
return getPolicyDefs().getPolicyDef(type, defaultDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPolicyDefs() {
|
||||||
|
return this.policyDefs != null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPolicyDef(String type) {
|
public boolean hasPolicyDef(String type) {
|
||||||
return this.policyDefs != null && policyDefs.hasPolicyDef(type);
|
return this.policyDefs != null && this.policyDefs.hasPolicyDef(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPolicyDef(Class<?> clazz) {
|
public boolean hasPolicyDef(Class<?> clazz) {
|
||||||
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz.getSimpleName());
|
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -599,7 +599,7 @@ public class Activity extends AbstractStrolchRootElement
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PolicyDef getPolicyDef(Class<?> clazz) {
|
public PolicyDef getPolicyDef(Class<?> clazz) {
|
||||||
return getPolicyDefs().getPolicyDef(clazz.getSimpleName());
|
return getPolicyDefs().getPolicyDef(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -611,7 +611,7 @@ public class Activity extends AbstractStrolchRootElement
|
||||||
public PolicyDef getPolicyDef(Class<?> clazz, PolicyDef defaultDef) {
|
public PolicyDef getPolicyDef(Class<?> clazz, PolicyDef defaultDef) {
|
||||||
if (!hasPolicyDefs())
|
if (!hasPolicyDefs())
|
||||||
return defaultDef;
|
return defaultDef;
|
||||||
return getPolicyDefs().getPolicyDef(clazz.getSimpleName(), defaultDef);
|
return getPolicyDefs().getPolicyDef(clazz, defaultDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -628,12 +628,12 @@ public class Activity extends AbstractStrolchRootElement
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPolicyDef(String type) {
|
public boolean hasPolicyDef(String type) {
|
||||||
return this.policyDefs != null && policyDefs.hasPolicyDef(type);
|
return this.policyDefs != null && this.policyDefs.hasPolicyDef(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPolicyDef(Class<?> clazz) {
|
public boolean hasPolicyDef(Class<?> clazz) {
|
||||||
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz.getSimpleName());
|
return this.policyDefs != null && this.policyDefs.hasPolicyDef(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -34,7 +34,7 @@ import li.strolch.utils.dbc.DBC;
|
||||||
public class PolicyDefs {
|
public class PolicyDefs {
|
||||||
|
|
||||||
private StrolchElement parent;
|
private StrolchElement parent;
|
||||||
private Map<String, PolicyDef> policyDefMap;
|
private final Map<String, PolicyDef> policyDefMap;
|
||||||
private boolean readOnly;
|
private boolean readOnly;
|
||||||
|
|
||||||
public PolicyDefs() {
|
public PolicyDefs() {
|
||||||
|
@ -58,6 +58,10 @@ public class PolicyDefs {
|
||||||
return getPolicyDef(type, null);
|
return getPolicyDef(type, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PolicyDef getPolicyDef(Class<?> clazz) {
|
||||||
|
return getPolicyDef(clazz.getSimpleName(), null);
|
||||||
|
}
|
||||||
|
|
||||||
public PolicyDef getPolicyDef(String type, PolicyDef defaultDef) {
|
public PolicyDef getPolicyDef(String type, PolicyDef defaultDef) {
|
||||||
if (!this.policyDefMap.containsKey(type)) {
|
if (!this.policyDefMap.containsKey(type)) {
|
||||||
if (defaultDef != null)
|
if (defaultDef != null)
|
||||||
|
@ -69,10 +73,18 @@ public class PolicyDefs {
|
||||||
return this.policyDefMap.get(type);
|
return this.policyDefMap.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PolicyDef getPolicyDef(Class<?> clazz, PolicyDef defaultDef) {
|
||||||
|
return getPolicyDef(clazz.getSimpleName(), defaultDef);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasPolicyDef(String type) {
|
public boolean hasPolicyDef(String type) {
|
||||||
return this.policyDefMap.containsKey(type);
|
return this.policyDefMap.containsKey(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasPolicyDef(Class<?> clazz) {
|
||||||
|
return this.policyDefMap.containsKey(clazz.getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasPolicyDefs() {
|
public boolean hasPolicyDefs() {
|
||||||
return !this.policyDefMap.isEmpty();
|
return !this.policyDefMap.isEmpty();
|
||||||
}
|
}
|
||||||
|
@ -88,6 +100,11 @@ public class PolicyDefs {
|
||||||
this.policyDefMap.remove(type);
|
this.policyDefMap.remove(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void remove(Class<?> clazz) {
|
||||||
|
assertNotReadonly();
|
||||||
|
this.policyDefMap.remove(clazz.getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
Loading…
Reference in New Issue