Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Using CompleteOCLEObjectValidator to validate Ecore model using OCL constraints defined in text file
Using CompleteOCLEObjectValidator to validate Ecore model using OCL constraints defined in text file [message #846082] Sun, 15 April 2012 14:50 Go to next message
Elvis Dowson is currently offline Elvis Dowson
Messages: 38
Registered: December 2011
Member
Hi,
I'm trying to enable OCL validation for my ecore based editor application, using the CompleteOCLEObjectValidator class. I have specified my OCL constraints in a separate text file.

Here are the steps that I followed, I think I might be missing something basic, since when I right click on the generated model, the constraints do not work.

Step 01.00: Create a new eclipse plugin project.

Project name: com.dowson.pcbdesignrules.validation

In the generated plugin.xml file, Overview tab:
Enable the This plug-in is a singleton option.

In the generated plugin.xml file, Dependencies tab:
Add com.dowson.pcbdesignrules

In the generated plugin.xml file, Runtime tab:
Add com.dowson.pcbdesignrules.validation

In the plugin.xml file, add the following sections:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension point="org.eclipse.emf.validation.constraintProviders">
			<constraintProvider class="org.eclipse.ocl.examples.xtext.completeocl.validation.CompleteOCLEObjectValidator">
			<package namespaceUri="http:///pcbdesignrules/1.0.0"/>
			</constraintProvider>
  </extension>
</plugin>


In the build.properties
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
               .,\
               plugin.xml
src.includes = src/,\
               constraints/


Step 02.00: Add support for loading an OCL constraints file using the CompleteOCLEObjectValidator class.

Step 02.01: Add the required package imports to add support for the CompleteOCLEObjectValidator class.
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EValidator; 
import org.eclipse.ocl.examples.xtext.completeocl.validation.CompleteOCLEObjectValidator;


public class Activator extends AbstractUIPlugin {

	// The URI to the OCL constraints file.
	private static final URI PCBDesignRulesOCLConstraintsURI = URI.createURI("platform:/plugin/com.dowson.pcbdesignrules.validation/constraints/pcbdesignrules.ocl");

}


Step 02.02: Add support for accessing an instance of the PCB Design Rules model package.
import com.dowson.pcbdesignrules.pcbdesignrulesPackage;


public class Activator extends AbstractUIPlugin {

	/**
	 * This caches an instance of the model package.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected pcbdesignrulesPackage _pcbdesignrulesPackage = pcbdesignrulesPackage.eINSTANCE;
}

Step 02.03: Register the EValidator using the CompleteOCLEObjectValidator class.
	public void start(BundleContext context) throws Exception {
		// Register EValidator
		EValidator.Registry.INSTANCE.put(
				_pcbdesignrulesPackage,
				new CompleteOCLEObjectValidator(_pcbdesignrulesPackage,PCBDesignRulesOCLConstraintsURI));

		super.start(context);
		plugin = this;
	}


Step 03.00 Specify the OCL constraints.

File pcbdesignrules.ocl
import 'http://www.eclipse.org/emf/2002/Ecore'
import 'http://www.eclipse.org/emf/2002/GenModel'
import 'platform:/plugin/com.dowson.dsl.pcbdesignrules/model/pcbdesignrules.ecore'

package pcbdesignrules

	context Project
		inv IsDesignRepository: designRepositories->forAll(oclIsKindOf(DesignRepository))
		
	context DesignFolder
		inv AtleastFiveLetters: name.size() >= 5

endpackage


The problem that I'm facing is that when I launch my debug eclipse instance, and create a model that violates the constraints, and right click on the model, and select the Validate option, it always validates successfully, even though the model violates the OCL constraints.

I put the initialization code for the CompleteOCLEObjectValidator in the Activator class start() method. The other examples created a separate class and inherited from IStartup. I didn;t use that approach because with Eclipse-4.2 Juno, it gave some warning about extending org.eclipse.ui.startup being depreciated.

I have attached a copy of the project in its current state. It doesn't contain all the necessary ecore models to run, I'm hoping just an inspection of the files contained in the project would be sufficient to point out what I'm doing wrong.

Best regards,

Elvis Dowson

[Updated on: Sun, 15 April 2012 15:01]

Report message to a moderator

Re: Using CompleteOCLEObjectValidator to validate Ecore model using OCL constraints defined in text [message #846705 is a reply to message #846082] Mon, 16 April 2012 05:03 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4035
Registered: July 2009
Senior Member
Hi

When validation doesn't work for me, I step through from
Diagnostician.validate to find out why the wrong path is taken. There
are numerous opportunities for erroneous registrations.

The EclipseCon presentation
http://eclipsecon.org/2011/sessions/?page=sessions&id=2271 has download
material that should give you a working example.

Regards

Ed Willink

On 15/04/2012 19:50, Elvis Dowson wrote:
> Hi,
> I'm trying to enable OCL validation for my ecore based editor application, using the CompleteOCLEObjectValidator class. I have specified my OCL constraints in a separate text file.
>
> Here are the steps that I followed, I think I might be missing something basic, since when I right click on the generated model, the constraints do not work.
>
> Step 01.00: Create a new eclipse plugin project.
>
> Project name: com.dowson.pcbdesignrules.validation
>
> In the generated plugin.xml file, Overview tab:
> Enable the This plug-in is a singleton option.
>
> In the generated plugin.xml file, Dependencies tab:
> Add com.dowson.pcbdesignrules
>
> In the generated plugin.xml file, Runtime tab:
> Add com.dowson.pcbdesignrules.validation
>
> In the plugin.xml file, add the following sections:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <?eclipse version="3.4"?>
> <plugin>
> <extension point="org.eclipse.emf.validation.constraintProviders">
> <constraintProvider class="org.eclipse.ocl.examples.xtext.completeocl.validation.CompleteOCLEObjectValidator">
> <package namespaceUri="http:///pcbdesignrules/1.0.0"/>
> </constraintProvider>
> </extension>
> </plugin>
>
>
> In the build.properties
>
> source.. = src/
> output.. = bin/
> bin.includes = META-INF/,\
> .,\
> plugin.xml
> src.includes = src/,\
> constraints/
>
>
> Step 02.00: Add support for loading an OCL constraints file using the CompleteOCLEObjectValidator class.
>
> Step 02.01: Add the required package imports to add support for the CompleteOCLEObjectValidator class.
>
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.EValidator;
> import org.eclipse.ocl.examples.xtext.completeocl.validation.CompleteOCLEObjectValidator;
>
>
> public class Activator extends AbstractUIPlugin {
>
> // The URI to the OCL constraints file.
> private static final URI PCBDesignRulesOCLConstraintsURI = URI.createURI("platform:/plugin/com.dowson.pcbdesignrules.validation/constraints/pcbdesignrules.ocl");
>
> }
> [/code]
>
> Step 02.02: Add support for accessing an instance of the PCB Design Rules model package.
>
> import com.dowson.pcbdesignrules.pcbdesignrulesPackage;
>
>
> public class Activator extends AbstractUIPlugin {
>
> /**
> * This caches an instance of the model package.
> *<!-- begin-user-doc -->
> *<!-- end-user-doc -->
> * @generated
> */
> protected pcbdesignrulesPackage _pcbdesignrulesPackage = pcbdesignrulesPackage.eINSTANCE;
> }
>
> Step 02.03: Register the EValidator using the CompleteOCLEObjectValidator class.
>
> public void start(BundleContext context) throws Exception {
> // Register EValidator
> EValidator.Registry.INSTANCE.put(
> _pcbdesignrulesPackage,
> new CompleteOCLEObjectValidator(_pcbdesignrulesPackage,PCBDesignRulesOCLConstraintsURI));
>
> super.start(context);
> plugin = this;
> }
>
>
> Step 03.00 Specify the OCL constraints.
>
> File pcbdesignrules.ocl
>
> import 'http://www.eclipse.org/emf/2002/Ecore'
> import 'http://www.eclipse.org/emf/2002/GenModel'
> import 'platform:/plugin/com.dowson.dsl.pcbdesignrules/model/pcbdesignrules.ecore'
>
> package pcbdesignrules
>
> context Project
> inv IsDesignRepository: designRepositories->forAll(oclIsKindOf(DesignRepository))
>
> context DesignFolder
> inv AtleastFiveLetters: name.size()>= 5
>
> endpackage
>
>
> The problem that I'm facing is that when I launch my debug eclipse instance, and create a model that violates the constraints, and right click on the model, and select the Validate option, it always validates successfully, even though the model violates the OCL constraints.
>
> I put the initialization code for the CompleteOCLEObjectValidator in the Activator class start() method. The other examples created a separate class and inherited from IStartup. I didn;t use that approach because with Eclipse-4.2 Juno, it gave some warning about extending org.eclipse.ui.startup being depreciated.
>
> I have attached a copy of the project in its current state. It doesn't contain all the necessary ecore models to run, I'm hoping just an inspection of the files contained in the project would be sufficient to point out what I'm doing wrong.
>
> Best regards,
>
> Elvis Dowson
>
Previous Topic:Access parent children relationship from a base class
Next Topic:How to make query operation visible for OCL
Goto Forum:
  


Current Time: Thu Aug 28 21:33:24 EDT 2014

Powered by FUDForum. Page generated in 0.01577 seconds