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