Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF] Custom model validation constraints are not invoked
[EMF] Custom model validation constraints are not invoked [message #997387] Mon, 07 January 2013 09:28 Go to next message
Dmitry Spiridenok is currently offline Dmitry SpiridenokFriend
Messages: 12
Registered: August 2011
Junior Member
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!
Re: [EMF] Custom model validation constraints are not invoked [message #997651 is a reply to message #997387] Mon, 07 January 2013 09:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Comments below.

On 07/01/2013 10:28 AM, D. Spiridenok wrote:
> 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.
Is this in an EMF generated editor? That action only executes
org.eclipse.emf.edit.ui.action.ValidateAction.run() which only validates
the built-in constraints. The extended validation framework must
provide something you're supposed to use to invoke the extended
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!
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF] Custom model validation constraints are not invoked [message #997652 is a reply to message #997387] Mon, 07 January 2013 14:06 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

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!
Re: [EMF] Custom model validation constraints are not invoked [message #997654 is a reply to message #997652] Mon, 07 January 2013 14:25 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Christian
> 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.
I'm sure it's simple, but I don't know how to do it yet. Should it be on
http://wiki.eclipse.org/EMF-Validation-FAQ?

Regards

Ed Willink
Re: [EMF] Custom model validation constraints are not invoked [message #998051 is a reply to message #997652] Wed, 09 January 2013 09:14 Go to previous message
Dmitry Spiridenok is currently offline Dmitry SpiridenokFriend
Messages: 12
Registered: August 2011
Junior Member
Christian W. Damus wrote on Mon, 07 January 2013 15: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. Wink

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


Guys,

This sounds exactly what I want: extend the default Ecore validations with my own validations listed in my original post.

Unfortunately I'm not familiar with EValidators and "Diagnosticians" in Eclipse. I guess this is not the first time somebody wants to add own EMF constraints, so i hope some information on how to do that is already available somewhere...

- Could you please provide me with more information on what needs to be done?
- Do you have any example implementations for functionality?

I'll also stop my attempts to create constraint binding if it's not strictly needed. The reason for that is exactly what you mention - seems pretty complex to a newbee like me to get it right.

Thanks in advance!
Previous Topic:[Teneo] [EMF] I get a stackoverflow when i try to do a datastore.initialize
Next Topic:How to extend a model and create the editor
Goto Forum:
  


Current Time: Fri Mar 29 09:24:36 GMT 2024

Powered by FUDForum. Page generated in 0.03435 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top