[New] Added IActivityElement.findPolicy()

This commit is contained in:
Robert von Burg 2020-02-14 16:22:59 +01:00
parent d06cce1bb9
commit 83a947e04b
4 changed files with 86 additions and 5 deletions

View File

@ -343,6 +343,27 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
return parameter;
}
@Override
public PolicyDef findPolicy(Class<?> clazz, PolicyDef defaultDef) throws StrolchModelException {
return findPolicy(clazz.getSimpleName(), defaultDef);
}
@Override
public PolicyDef findPolicy(String className, PolicyDef defaultDef) throws StrolchModelException {
if (hasPolicyDef(className))
return getPolicyDef(className);
if (this.parent == null) {
if (defaultDef != null)
return defaultDef;
String msg = "The PolicyDef {0} does not exist";
throw new StrolchModelException(MessageFormat.format(msg, className));
}
return this.parent.findPolicy(className, defaultDef);
}
@Override
public <T> T accept(StrolchElementVisitor<T> visitor) {
return visitor.visitAction(this);

View File

@ -601,6 +601,27 @@ public class Activity extends AbstractStrolchRootElement
return parameter;
}
@Override
public PolicyDef findPolicy(Class<?> clazz, PolicyDef defaultDef) throws StrolchModelException {
return findPolicy(clazz.getSimpleName(), defaultDef);
}
@Override
public PolicyDef findPolicy(String className, PolicyDef defaultDef) throws StrolchModelException {
if (hasPolicyDef(className))
return getPolicyDef(className);
if (this.parent == null) {
if (defaultDef != null)
return defaultDef;
String msg = "The PolicyDef {0} does not exist";
throw new StrolchModelException(MessageFormat.format(msg, className));
}
return this.parent.findPolicy(className, defaultDef);
}
@Override
public void setParent(Activity activity) {
assertNotReadonly();

View File

@ -20,6 +20,7 @@ import li.strolch.model.GroupedParameterizedElement;
import li.strolch.model.State;
import li.strolch.model.StrolchElement;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.policy.PolicyDef;
import li.strolch.model.visitor.StrolchElementVisitor;
/**
@ -83,14 +84,52 @@ public interface IActivityElement extends StrolchElement {
* </p>
*
* <p>
* If the parameter does not exist and {@code assertExists} is true, then an
* If the parameter does not exist and {@code assertExists} is true, then a {@link StrolchModelException} is thrown
* </p>
*
* @see GroupedParameterizedElement#getParameter(String, String, boolean)
*/
<U, T extends Parameter<U>> T findParameter(String bagKey, String paramKey, boolean assertExists)
throws StrolchModelException;
/**
* <p>
* Checks if this element contains the {@link PolicyDef}, or otherwise queries its parent, until the root element is
* reached.
* </p>
*
* <p>
* If the policy def does not exist and no default policy is passed, then a {@link StrolchModelException} is thrown
* </p>
*
* @param className
* the class name of the policy to find
* @param defaultDef
* default {@link PolicyDef} to return if not found
*
* @throws StrolchModelException
* if no default policy, and policy not found
*/
PolicyDef findPolicy(String className, PolicyDef defaultDef) throws StrolchModelException;
/**
* <p>
* Checks if this element contains the {@link PolicyDef}, or otherwise queries its parent, until the root element is
* reached.
* </p>
*
* <p>
* If the policy def does not exist and no default policy is passed, then a {@link StrolchModelException} is thrown
* </p>
*
* @param clazz
* the class of the policy to find
* @param defaultDef
* default {@link PolicyDef} to return if not found
*
* @throws StrolchModelException
* if no default policy, and policy not found
*/
PolicyDef findPolicy(Class<?> clazz, PolicyDef defaultDef) throws StrolchModelException;
@Override
Activity getParent();

View File

@ -2,7 +2,7 @@ package li.strolch.model.activity;
public interface TimeOrderingVisitor {
public void visitSeries(Activity activity);
void visitSeries(Activity activity);
public void visitParallel(Activity activity);
void visitParallel(Activity activity);
}