[Minor] Added PolicyContainer.getPolicyDef(Class)

This commit is contained in:
Robert von Burg 2018-01-12 16:15:39 +01:00
parent a7a33e4e0c
commit d385025609
5 changed files with 94 additions and 61 deletions

View File

@ -129,6 +129,11 @@ public class Order extends AbstractStrolchRootElement implements StrolchRootElem
return this.policyDefs; return this.policyDefs;
} }
@Override
public PolicyDef getPolicyDef(Class<?> clazz) {
return getPolicyDefs().getPolicyDef(clazz.getSimpleName());
}
@Override @Override
public PolicyDef getPolicyDef(String type) { public PolicyDef getPolicyDef(String type) {
return getPolicyDefs().getPolicyDef(type); return getPolicyDefs().getPolicyDef(type);

View File

@ -47,6 +47,16 @@ public interface PolicyContainer {
*/ */
public PolicyDef getPolicyDef(String type); public PolicyDef getPolicyDef(String type);
/**
* Returns the {@link PolicyDef} for the given class
*
* @param clazz
* the type of policy def to return
*
* @return the policy def of the given class
*/
public PolicyDef getPolicyDef(Class<?> clazz);
/** /**
* Set the reference to the {@link PolicyDefs} * Set the reference to the {@link PolicyDefs}
* *

View File

@ -162,6 +162,11 @@ public class Resource extends AbstractStrolchRootElement implements StrolchRootE
return this.policyDefs; return this.policyDefs;
} }
@Override
public PolicyDef getPolicyDef(Class<?> clazz) {
return getPolicyDefs().getPolicyDef(clazz.getSimpleName());
}
@Override @Override
public PolicyDef getPolicyDef(String type) { public PolicyDef getPolicyDef(String type) {
return getPolicyDefs().getPolicyDef(type); return getPolicyDefs().getPolicyDef(type);

View File

@ -122,6 +122,7 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
/** /**
* @param resourceType * @param resourceType
* the resource type
*/ */
public void setResourceType(String resourceType) { public void setResourceType(String resourceType) {
this.resourceType = resourceType; this.resourceType = resourceType;
@ -137,7 +138,7 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
} }
/** /**
* @param add * @param change
* <code>IValueChange</code> to be applied to the <code>Resource</code> * <code>IValueChange</code> to be applied to the <code>Resource</code>
* *
* @return <tt>true</tt> (as specified by {@link Collection#add}) * @return <tt>true</tt> (as specified by {@link Collection#add})
@ -158,7 +159,7 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
public Iterator<IValueChange<? extends IValue<?>>> changesIterator() { public Iterator<IValueChange<? extends IValue<?>>> changesIterator() {
if (this.changes == null) if (this.changes == null)
return Collections.<IValueChange<? extends IValue<?>>> emptyList().iterator(); return Collections.<IValueChange<? extends IValue<?>>>emptyList().iterator();
return this.changes.iterator(); return this.changes.iterator();
} }
@ -212,6 +213,11 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
return this.policyDefs != null; return this.policyDefs != null;
} }
@Override
public PolicyDef getPolicyDef(Class<?> clazz) {
return getPolicyDefs().getPolicyDef(clazz.getSimpleName());
}
@Override @Override
public boolean hasPolicyDef(String type) { public boolean hasPolicyDef(String type) {
return this.policyDefs != null && policyDefs.hasPolicyDef(type); return this.policyDefs != null && policyDefs.hasPolicyDef(type);

View File

@ -15,6 +15,11 @@
*/ */
package li.strolch.model.activity; package li.strolch.model.activity;
import java.text.MessageFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Stream;
import li.strolch.exception.StrolchException; import li.strolch.exception.StrolchException;
import li.strolch.exception.StrolchModelException; import li.strolch.exception.StrolchModelException;
import li.strolch.exception.StrolchPolicyException; import li.strolch.exception.StrolchPolicyException;
@ -27,11 +32,6 @@ import li.strolch.model.visitor.IActivityElementVisitor;
import li.strolch.model.visitor.StrolchElementVisitor; import li.strolch.model.visitor.StrolchElementVisitor;
import li.strolch.utils.dbc.DBC; import li.strolch.utils.dbc.DBC;
import java.text.MessageFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Stream;
/** /**
* Parameterized object grouping a collection of {@link Activity} and {@link Action} objects defining the process to be * Parameterized object grouping a collection of {@link Activity} and {@link Action} objects defining the process to be
* scheduled * scheduled
@ -143,6 +143,7 @@ public class Activity extends AbstractStrolchRootElement
* add an activity element to the <code>LinkedHashMap</code> of <code>IActivityElements</code> * add an activity element to the <code>LinkedHashMap</code> of <code>IActivityElements</code>
* *
* @param activityElement * @param activityElement
*
* @return the element added * @return the element added
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -186,6 +187,7 @@ public class Activity extends AbstractStrolchRootElement
* *
* @param id * @param id
* the id of the <code>IActivityElement</code> * the id of the <code>IActivityElement</code>
*
* @return IActivityElement * @return IActivityElement
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -366,7 +368,7 @@ public class Activity extends AbstractStrolchRootElement
*/ */
public Iterator<Entry<String, IActivityElement>> elementIterator() { public Iterator<Entry<String, IActivityElement>> elementIterator() {
if (this.elements == null) if (this.elements == null)
return Collections.<String, IActivityElement> emptyMap().entrySet().iterator(); return Collections.<String, IActivityElement>emptyMap().entrySet().iterator();
return this.elements.entrySet().iterator(); return this.elements.entrySet().iterator();
} }
@ -375,7 +377,7 @@ public class Activity extends AbstractStrolchRootElement
*/ */
public Stream<Entry<String, IActivityElement>> elementStream() { public Stream<Entry<String, IActivityElement>> elementStream() {
if (this.elements == null) if (this.elements == null)
return Collections.<String, IActivityElement> emptyMap().entrySet().stream(); return Collections.<String, IActivityElement>emptyMap().entrySet().stream();
return this.elements.entrySet().stream(); return this.elements.entrySet().stream();
} }
@ -419,6 +421,11 @@ public class Activity extends AbstractStrolchRootElement
return this.policyDefs; return this.policyDefs;
} }
@Override
public PolicyDef getPolicyDef(Class<?> clazz) {
return getPolicyDefs().getPolicyDef(clazz.getSimpleName());
}
@Override @Override
public PolicyDef getPolicyDef(String type) { public PolicyDef getPolicyDef(String type) {
return getPolicyDefs().getPolicyDef(type); return getPolicyDefs().getPolicyDef(type);