Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Checking invariants (embedded in Metamodel) with Diagnostician
Checking invariants (embedded in Metamodel) with Diagnostician [message #856179] Wed, 25 April 2012 12:48 Go to next message
eclipsy eclipsy is currently offline eclipsy eclipsyFriend
Messages: 6
Registered: April 2012
Junior Member
Hello,

I am trying to validate invariants which are embedded in an ecore meta model.
The EMF Validation documentation advises to use the follwoing method:

public static boolean validateObject(EObject eObject)
 {
    Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
    return diagnostic.getSeverity() == Diagnostic.OK;
 }


This method works fine when checking multiplicities but not with my self-defined
invariants in my meta model.

Of course I have generated the model code and implemented the invariant (EOperation).
But my debugger doesn't pass this implemented method at all.

What am I doing wrong? Please help me Smile

PS: I have attached my plugins (MyExampleModel and testing.invariants).
Re: Checking invariants (embedded in Metamodel) with Diagnostician [message #856197 is a reply to message #856179] Wed, 25 April 2012 13:06 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It looks as if you are using a very very vintage approach incorrectly.

Your Ecore file has

<eAnnotations source="GenModel">
<details key="documentation" value="The properties of A are of kind x or
z.&#xD;&#xA;
property>forAll (p | p.kind = #x or p.kind = #z)"/>
</eAnnotations>

which is a documentation annotation that ends with something that might
be OCL except that ">" should be "->" and "#x" should be "KindEnum::x" etc.

If you use a Helios or later installation you can install the OCL
Examples and Editors to get an OCLinEcore editor that will allow you to
enter

/**
* The properties of A are of kind x or z.
*/
invariant property_kinds_are_x_or_z: property->forAll (p | p.kind =
KindEnum::x or p.kind = KindEnum::z);

Comments are not persisted until the Juno release.

Regards

Ed Willink

On 25/04/2012 13:48, eclipsy eclipsy wrote:
> Hello,
>
> I am trying to validate invariants which are embedded in an ecore meta model.
> The EMF Validation documentation advises to use the follwoing method:
>
> public static boolean validateObject(EObject eObject)
> {
> Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
> return diagnostic.getSeverity() == Diagnostic.OK;
> }
>
> This method works fine when checking multiplicities but not with my self-defined
> invariants in my meta model.
>
> Of course I have generated the model code and implemented the invariant (EOperation).
> But my debugger doesn't pass this implemented method at all.
>
> What am I doing wrong? Please help me :)
>
> PS: I have attached my plugins (MyExampleModel and testing.invariants).
Re: Checking invariants (embedded in Metamodel) with Diagnostician [message #856210 is a reply to message #856197] Wed, 25 April 2012 13:21 Go to previous messageGo to next message
eclipsy eclipsy is currently offline eclipsy eclipsyFriend
Messages: 6
Registered: April 2012
Junior Member
Thank you for your answer so far.

I am using Indigo and as far as I know, invariants can be defined

1. either as an OCL-Expression in an Annotation
2. or as an EOperation with the DiagnosticChain as input parameters etc.

See Step 2:
h..p://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.emf.doc%2Freferences%2Foverview%2FEMF.Validation.html

(adjust h..p to http)

I want to use the 2. variant. Ignore the annotation please.

I have implemented the EOperation property_kinds_are_x_or_z(DiagnosticChain diagnostics, Map<Object, Object> context)
in the generated source file: MyExampleModel\src\model\impl\AImpl.java

What am I doing wrong there?

[Updated on: Wed, 25 April 2012 13:22]

Report message to a moderator

Re: Checking invariants (embedded in Metamodel) with Diagnostician [message #856265 is a reply to message #856179] Wed, 25 April 2012 14:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Comments below.

On 25/04/2012 2:48 PM, eclipsy eclipsy wrote:
> Hello,
>
> I am trying to validate invariants which are embedded in an ecore meta model.
> The EMF Validation documentation advises to use the follwoing method:
>
> public static boolean validateObject(EObject eObject)
> {
> Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
> return diagnostic.getSeverity() == Diagnostic.OK;
> }
>
> This method works fine when checking multiplicities but not with my self-defined
> invariants in my meta model.
I see this in the generated validator

public boolean validateA_property_kinds_are_x_or_z(A a,
DiagnosticChain diagnostics, Map<Object, Object> context) {
return a.property_kinds_are_x_or_z(diagnostics, context);
}

>
> Of course I have generated the model code and implemented the invariant (EOperation).
> But my debugger doesn't pass this implemented method at all.
>
> What am I doing wrong? Please help me :)
Your test code is validating the Ecore model, not the instance. Note
that the diagnostician will walk the entire containment tree so you only
need to call validate on the root object in the resource.
>
> PS: I have attached my plugins (MyExampleModel and testing.invariants).


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Checking invariants (embedded in Metamodel) with Diagnostician [message #856367 is a reply to message #856265] Wed, 25 April 2012 15:49 Go to previous messageGo to next message
eclipsy eclipsy is currently offline eclipsy eclipsyFriend
Messages: 6
Registered: April 2012
Junior Member
Quote:

Your test code is validating the Ecore model, not the instance. Note
that the diagnostician will walk the entire containment tree so you only
need to call validate on the root object in the resource.


Yes, I actually wanted to iterate over the instance. That was typo and should be "...instance.getAllContents();"

Nevertheless, when I change that line the validation still doesn't work.

Even if I'm currently not validating only the model root there should at least
be a violation with the EObject of type A and one with the model root, I think.

My instance iteration looks now as follows (the "instanceof EOperation"-Check was
nonsense with the instance, i removed it):

Iterator<EObject> itM = instance.getAllContents();
while (itM.hasNext()) {
	EObject eObject = (EObject) itM.next();

	if(validateObject(eObject)==false) {
	  System.out.println("violated");
	}
}

[Updated on: Thu, 26 April 2012 05:51]

Report message to a moderator

Re: Checking invariants (embedded in Metamodel) with Diagnostician [message #857433 is a reply to message #856367] Thu, 26 April 2012 14:30 Go to previous messageGo to next message
eclipsy eclipsy is currently offline eclipsy eclipsyFriend
Messages: 6
Registered: April 2012
Junior Member
My problem is still not solved. Please take a look again!

The validation does not jump into property_kinds_are_x_or_z(diagnostics, context).

Why?
Re: Checking invariants (embedded in Metamodel) with Diagnostician [message #857504 is a reply to message #857433] Thu, 26 April 2012 15:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
I already told you that you that you're not iterating over the instance
but rather over the Ecore model. Did you change that?

On 26/04/2012 4:30 PM, eclipsy eclipsy wrote:
> My problem is still not solved. Please take a look again!
>
> The validation does not jump into
> property_kinds_are_x_or_z(diagnostics, context).
>
> Why?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Checking invariants (embedded in Metamodel) with Diagnostician [message #858736 is a reply to message #857504] Fri, 27 April 2012 09:16 Go to previous messageGo to next message
eclipsy eclipsy is currently offline eclipsy eclipsyFriend
Messages: 6
Registered: April 2012
Junior Member
Yes, I changed that. Here my iteration code again:

Iterator<EObject> itM = instance.getAllContents();
while (itM.hasNext()) {
EObject eObject = (EObject) itM.next();

if(validateObject(eObject)==false) {
System.out.println("violated");
}
}
Re: Checking invariants (embedded in Metamodel) with Diagnostician [message #865419 is a reply to message #858736] Mon, 30 April 2012 11:45 Go to previous messageGo to next message
eclipsy eclipsy is currently offline eclipsy eclipsyFriend
Messages: 6
Registered: April 2012
Junior Member
Can somebody please take a look and tell me what I am doing wrong?
Re: Checking invariants (embedded in Metamodel) with Diagnostician [message #865536 is a reply to message #865419] Mon, 30 April 2012 12:55 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
That's what debuggers are for. Step into the call and see where it goes.

On 30/04/2012 1:45 PM, eclipsy eclipsy wrote:
> Can somebody please take a look and tell me what I am doing wrong?


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO/Hibernate] java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
Next Topic:Texo: problems when one xsd use another one
Goto Forum:
  


Current Time: Thu Apr 25 04:26:41 GMT 2024

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

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

Back to the top