Skip to content
Snippets Groups Projects
Commit abd250ec authored by Florian Hölzl's avatar Florian Hölzl
Browse files

fixed constraint extension point

added recursive and non-recursive check methods to constraint service
parent b80b560c
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
</documentation> </documentation>
</annotation> </annotation>
<include schemaLocation="modelElement.exsd"/>
<element name="extension"> <element name="extension">
<annotation> <annotation>
<appinfo> <appinfo>
...@@ -18,6 +20,7 @@ ...@@ -18,6 +20,7 @@
</annotation> </annotation>
<complexType> <complexType>
<sequence> <sequence>
<element ref="modelElementConstraintChecker" minOccurs="1" maxOccurs="unbounded"/>
</sequence> </sequence>
<attribute name="point" type="string" use="required"> <attribute name="point" type="string" use="required">
<annotation> <annotation>
...@@ -46,7 +49,22 @@ ...@@ -46,7 +49,22 @@
</complexType> </complexType>
</element> </element>
<element name="modelElementConstraintChecker" type="string"> <element name="modelElementConstraintChecker">
<complexType>
<sequence>
<element ref="modelElementClass" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
<attribute name="checker" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.fortiss.tooling.kernel.interfaces.IConstraintChecker"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element> </element>
<annotation> <annotation>
......
...@@ -38,8 +38,8 @@ public interface IConstraintChecker<C extends EObject> extends IEObjectAware<C> ...@@ -38,8 +38,8 @@ public interface IConstraintChecker<C extends EObject> extends IEObjectAware<C>
* Determines whether the constraint checker is applicable to the given * Determines whether the constraint checker is applicable to the given
* model element. * model element.
*/ */
boolean isApplicable(EObject modelElement); boolean isApplicable(C modelElement);
/** Applies the constraint checker to the given model element. */ /** Applies the constraint checker to the given model element. */
IConstraintViolation<EObject> apply(EObject modelElement); IConstraintViolation<EObject> apply(C modelElement);
} }
...@@ -17,6 +17,7 @@ $Id$ ...@@ -17,6 +17,7 @@ $Id$
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.internal; package org.fortiss.tooling.kernel.internal;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
...@@ -35,8 +36,8 @@ import org.fortiss.tooling.kernel.services.IConstraintService; ...@@ -35,8 +36,8 @@ import org.fortiss.tooling.kernel.services.IConstraintService;
* @ConQAT.Rating RED Hash: 9E0D8411A1525AA3989DED2C0DC7A033 * @ConQAT.Rating RED Hash: 9E0D8411A1525AA3989DED2C0DC7A033
*/ */
public class ConstraintService extends public class ConstraintService extends
EObjectAwareServiceBase<IConstraintChecker<? extends EObject>> EObjectAwareServiceBase<IConstraintChecker<EObject>> implements
implements IConstraintService { IConstraintService {
/** The compositor extension point ID. */ /** The compositor extension point ID. */
private static final String EXTENSION_POINT_NAME = "org.fortiss.tooling.kernel.modelElementConstraintChecker"; private static final String EXTENSION_POINT_NAME = "org.fortiss.tooling.kernel.modelElementConstraintChecker";
...@@ -48,24 +49,49 @@ public class ConstraintService extends ...@@ -48,24 +49,49 @@ public class ConstraintService extends
private static final String HANDLER_CLASS_ATTRIBUTE_NAME = "checker"; private static final String HANDLER_CLASS_ATTRIBUTE_NAME = "checker";
/** {@inheritDoc} */ /** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override @Override
public List<IConstraintViolation<? extends EObject>> performAllConstraintChecks( public List<IConstraintViolation<EObject>> performAllConstraintChecksRecursively(
EObject modelElement) { EObject modelElement) {
List<IConstraintViolation<? extends EObject>> result = new LinkedList<IConstraintViolation<? extends EObject>>(); List<IConstraintViolation<EObject>> result = new LinkedList<IConstraintViolation<EObject>>();
for (IConstraintChecker<? extends EObject> checker : getRegisteredHandlers(modelElement performConstraintCheck(modelElement, result);
for (Iterator<EObject> iter = modelElement.eAllContents(); iter
.hasNext();) {
performConstraintCheck(iter.next(), result);
}
return result;
}
/** {@inheritDoc} */
@Override
public List<IConstraintViolation<EObject>> performAllConstraintChecks(
EObject modelElement) {
List<IConstraintViolation<EObject>> result = new LinkedList<IConstraintViolation<EObject>>();
performConstraintCheck(modelElement, result);
return result;
}
/**
* Performs all constraint checks on the given model element. Violations are
* added to the given list. Constraint checks on content elements are not
* considered.
*/
private void performConstraintCheck(EObject modelElement,
List<IConstraintViolation<EObject>> violationList) {
for (IConstraintChecker<EObject> checker : getRegisteredHandlers(modelElement
.getClass())) { .getClass())) {
if (checker.isApplicable(modelElement)) { if (checker.isApplicable(modelElement)) {
result.add(checker.apply(modelElement)); IConstraintViolation<EObject> violation = checker
.apply(modelElement);
if (violation != null) {
violationList.add(violation);
}
} }
} }
return result;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override @Override
public List<IConstraintChecker<? extends EObject>> getAllConstraintCheckers( public List<IConstraintChecker<EObject>> getAllConstraintCheckers(
EObject modelElement) { EObject modelElement) {
return getRegisteredHandlers(modelElement.getClass()); return getRegisteredHandlers(modelElement.getClass());
} }
......
...@@ -39,8 +39,16 @@ public interface IConstraintService { ...@@ -39,8 +39,16 @@ public interface IConstraintService {
public static final IConstraintService INSTANCE = new ConstraintService(); public static final IConstraintService INSTANCE = new ConstraintService();
/** /**
* Performs all constraint checks on the given model element and returns the * Performs all constraint checks on the given model element and recursively
* check results. * its content and returns the check results. Note, that this method can be
* time-consuming for large model element trees.
*/
<T extends EObject> List<IConstraintViolation<T>> performAllConstraintChecksRecursively(
T modelElement);
/**
* Performs all constraint checks only on the given model element and
* returns the check results.
*/ */
<T extends EObject> List<IConstraintViolation<T>> performAllConstraintChecks( <T extends EObject> List<IConstraintViolation<T>> performAllConstraintChecks(
T modelElement); T modelElement);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment