Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Validating a Model through Java(OCL )
Validating a Model through Java [message #1746818] Sat, 05 November 2016 00:41 Go to next message
Bugra M. Yildiz is currently offline Bugra M. YildizFriend
Messages: 105
Registered: July 2014
Senior Member
Hello,

I have a metamodel and OCL constraints are defined inside this metamodel using OCLinECore. What I want to achieve is, to write a Java program, that reads the model file and the metamodel; then validates the OCL constraints and if there are any violations, the user should be informed through a standard console output.

I have tried to understand the document http://download.eclipse.org/ocl/doc/5.0.0/ocl.pdf but I am not sure what I am looking for is there. I have generated the Java code of the metamodel by enabling "Operation Reflection". The validator class is generated but one needs to get all the EClass instances in the model and validate each instance through related Java method for validation. What I am looking for is a method that is behind the "Validate" button in the validation view of Eclipse that validates all the OCL constraints together.

Could you please help me with this issue?
Re: Validating a Model through Java [message #1746822 is a reply to message #1746818] Sat, 05 November 2016 06:52 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5585
Registered: July 2009
Senior Member
Hi

You are validating an EMF model so you use the standard EMF validation which the Diagnostician supervises.

If the default validation, using the OCL interpreter is too slow, you can enable the OCL2Java code generator.

Regards

Ed Willink
Re: Validating a Model through Java [message #1746834 is a reply to message #1746822] Sat, 05 November 2016 11:18 Go to previous messageGo to next message
Bugra M. Yildiz is currently offline Bugra M. YildizFriend
Messages: 105
Registered: July 2014
Senior Member
Sorry Ed, I don't get it well. I don't know what you refer by "default validation", "OCL interpreter being slow", "OCL2Java code generator". I already stated what I want to achieve, let me describe the steps that I followed:

- I have defined a metamodel using OCLinECore editor. So an example entity from this metamodel is as follows:

/*
	 * OCL Constraint: NoNullName
	 * The name attribute can't be null.
	 * 
	 */
	abstract class Nameable { interface }
	{
		attribute name : String[1];
		attribute description : String[?];
		invariant NoNullName: 
			self.name <> null and self.name.size() > 0;
	}


- I have generated genmodel of this metamodel and enabled "Operation Reflection" option of the genmodel.

- Then, I have generated the model code from this genmodel. I have one automatically generated class now that extends EObjectValidator. This class has all methods for validation, that validates both the structural properties of an ECore model and also OCL constraints. An example method is

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean validateNameable(Nameable nameable, DiagnosticChain diagnostics, Map<Object, Object> context) {
		if (!validate_NoCircularContainment(nameable, diagnostics, context)) return false;
		boolean result = validate_EveryMultiplicityConforms(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validate_EveryDataValueConforms(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validate_EveryReferenceIsContained(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validate_EveryBidirectionalReferenceIsPaired(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validate_EveryProxyResolves(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validate_UniqueID(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validate_EveryKeyUnique(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validate_EveryMapEntryUnique(nameable, diagnostics, context);
		if (result || diagnostics != null) result &= validateNameable_NoNullName(nameable, diagnostics, context);
		return result;
	} 


If you want to use this class this validation, you have to write some code that takes very element in your model and uses these methods for validation. Also, one needs to write their custom validation messages.

Is there any easier way like a validate method that can run only on the root of your model that traces all your model elements and returns the list of violations with default messages?
Re: Validating a Model through Java [message #1746994 is a reply to message #1746834] Tue, 08 November 2016 12:27 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5585
Registered: July 2009
Senior Member
Hi

I really have no idea what your problem is. Try https://wiki.eclipse.org/OCL/ForumNetiquette

Regards

Ed Willink
Previous Topic: problem string concat operation OclUndefined ?
Next Topic:OCL JARs
Goto Forum:
  


Current Time: Mon Jan 22 20:35:24 GMT 2018

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

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