Date: Fri, 29 Mar 2024 16:53:58 +0100 (CET) Message-ID: <429294710.2264.1711727638466@nm-docs> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_2263_1208756274.1711727638466" ------=_Part_2263_1208756274.1711727638466 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
The OCL2.0 validation rule describes the validation logic using OCL2.0.<= /p>
To create the OCL2.0 validation rule
The OCL2.0 validation rule can be used in an active validation suite. In= this case the validation rule will be executed on any change of constraine= d elements that are from the validation scope. Executing of the validation = rule might be triggered even if no properties important to the validat= ion rule actually changed and this can slow down the active validating spee= d. In order to avoid degradation of the performance you can create a binary= validation rule that uses the OCL2.0 expression to validate model elements= but also provides additional information for the modeling tool that allows= to optimize triggering of executing after model elements change. For examp= le, we want to check whether all classes have names. This can be done= by creating the OCL2.0 validation rule and specifying the OLC2.0 expressio= n:
name <> =E2=80=98=E2=80=99
The problem is that such validation rule actually is interested in a cla= ss property name value change but it will be executed on every property val= ue of a class change. How we can fix this problem and inform the modeling t= ool to execute the validation rule only on the class property name change:<= /p>
= public Map<Class<? extends Element>, Collection<SmartListenerC= onfig>> getListenerConfigurations() { Map<Class<? extends Element>, Collection<SmartListe= nerConfig>> configs =3D=20 =09=09=09=09=09=09new HashMap<Class<? extends Element>, Collection= <SmartListenerConfig>>(); Collection<SmartListenerConfig> configsForClass =3D new A= rrayList<SmartListenerConfig>(); configsForClass.add(SmartListenerConfig.NAME_CONFIG); configs.put(com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Cla= ss.class, configsForClass); return configs; }
9. Specify the validation rule=E2=80=99s implementation pr= operty value - a qualified name of the class
10. Add/import the created validation rule to a validation= suite
See the MyOCLBasedValidationRuleImpl.java example in the <= em><program installation directory>\openapi\examples\validation = directory.
The implementation class must be in the classpath of the modeling tool o= r if the implementation class is in a plugin then the plugin=E2=80=99s clas= sloader must be registered to the validation system (see Binary validation rule in = the plugin).