|
|
Re: [EMF] Custom model validation constraints are not invoked [message #997652 is a reply to message #997387] |
Mon, 07 January 2013 14:06 |
|
Hi,
As Ed indicated, the extended EMF Validation Framework provides a
different API for invoking validation. You need an action that asks
the ModelValidationService to run a "batch" validation of the selected
object(s).
You shouldn't need to define constraint bindings if the "default
context" is sufficient for your needs. Client contexts and bindings
enable some fairly complex mix-and-match scenarios where different
"applications" hosted together in a workbench needs to apply different
constraints to the same models. The complexity of that is definitely
manifest in the API. ;-)
It is fairly simple to bridge the intrinsic Ecore validation with this
framework by plugging an EValidator into the diagnostician that
delegates to the ModelValidationService and converts resulting
IConstraintStatus objects to Diagnostics. It can additionally do the
usual EValidator thing, too, of course. The best place to do that is
in your generated Editor's validate action.
HTH,
Christian
On 2013-01-07 09:28:08 +0000, D. Spiridenok said:
> Dear people,
>
> I've created the following rather simple EMF meta-model:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="eventprovider"
> nsURI="eventprovider/1.0" nsPrefix="eventprovider">
> <eClassifiers xsi:type="ecore:EClass" name="EventProvider">
> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="human_readable_name" lowerBound="1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="module_name"
> lowerBound="1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="root_node"
> lowerBound="1"
> eType="#//Node" containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="class_name"
> lowerBound="1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="fullconst"
> lowerBound="1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EBoolean"
> defaultValueLiteral="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Node">
> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="human_readable_name" lowerBound="1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
> lowerBound="1" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="child_nodes"
> upperBound="-1"
> eType="#//Node" containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="properties"
> upperBound="-1"
> eType="#//Property" containment="true"/>
> </eClassifiers>
> </ecore:EPackage>
>
>
> then I instantiated this metamodel:
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <eventprovider:EventProvider xmi:version="2.0"
> xmlns:eventprovider="eventprovider/1.0" human_readable_name="b"
> module_name="c" unique_abbreviation="d" class_name="a">
> <root_node id="BLA"/>
> </eventprovider:EventProvider>
>
>
> Next to that i created a validation plugin, plugin.xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <?eclipse version="3.4"?>
> <plugin>
> <extension
> id="com.asml.dndm_event_provider.validation"
> name="DNDM Event Provider Validation"
> point="org.eclipse.emf.validation.constraintProviders">
> <category
> id="com.asml.dndm_event_provider.validations.category"
> name="DNDM EP Category">
> </category>
> <constraintProvider
> cache="true">
> <package
> namespaceUri="eventprovider/1.0">
> </package>
> <constraints
> categories="com.asml.dndm_event_provider.validations.category">
> <constraint
> id="FilledInNodeConstraint"
> isEnabledByDefault="true"
> lang="OCL"
> mode="Batch"
> name="Node must be filled in"
> severity="ERROR"
> statusCode="1">
> <message>
> Node {0} properties are not fully filled in
> </message>
> <description>
> For all nodes all properties must be filled in
> </description>
> <target class="Node"/>
> <![CDATA[
> false
> ]]>
> </constraint>
> <constraint
> class="constraints.JavaContraint"
> id="com.asml.dndm_event_provider.validations.constraint2"
> isEnabledByDefault="true"
> lang="Java"
> mode="Batch"
> name="JavaConstraint"
> severity="ERROR"
> statusCode="2">
> <message>
> message body text
> </message>
> <target class="EventProvider"/>
> </constraint>
> </constraints>
> </constraintProvider>
> </extension>
> </plugin>
>
>
> Both the OCL and the Java validations actually fail (OCL returns
> 'false' and Java implementation returns ctx.createFailureStatus() ).
>
> When i start another Eclipse instance from my developement Eclipse
> application i do see the added constrains in the New
> Eclipse->Window->Preferences->Model Validation->Constraints window.
>
> However if i execute the model validations (by clicking on the
> EventProvider element and selecting "Validate" in the menu) i get only
> "Validation completed successfully" when i expect the validation to
> fail because of my failing constraints. I get no other errors/warnings.
> Also a break point in my contraint Java class does not get hit during a
> validation run.
>
> So my questions:
> 1. Is it mandatory to create a contraint binding in this situation or
> should it also work without that?
> 2. What do i do wrong and why are my validation constraints not invoken
> on my model?
> 3. How can i debug this situation to get more information about the
> cause of the problem?
> Software configuration: Eclipse Indigo + Modeling package, Windows 7,
> Intel Centrino Dual Core CPU, Java 6 RE.
>
> Thank you in advance for help!
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03435 seconds