Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » GMF mapping Audit Rules
GMF mapping Audit Rules [message #217202] Wed, 04 February 2009 12:05 Go to next message
Achilleas is currently offline AchilleasFriend
Messages: 88
Registered: July 2009
Member
Hi,

I will like to ask if it is possible to compare two attributes using one
audit rule;one constraint.

For instance if i have the following metamodel

Root (aggregates classes1,classes2)
Class1(includes EAttribute value1) Class2(includes EAttribute value2)

Usually when a constraint is written it will be of the form:

Domain Element Target: |Class1::EClass
Class1.allInstances()->forAll( c1, c2 | c1 <> c2 implies c1.value1 <>
c2.value1 )


What if I want to compare the values of instances of the Class1 with
instances of the Class2? Is there a way to define two Domain Element
Targets? Could it be done directly from the Root class specifying this as
the Domain Element Target?

Thanks,

Achilleas
Re: GMF mapping Audit Rules [message #217219 is a reply to message #217202] Wed, 04 February 2009 13:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Achilleas,

You can, in the context of any classifier, use allInstances() to access
all instances of any other classifier. So, for example:

context Class1
inv:
Class2.allInstances()->forAll(c2 | self.value1 <> c2.value2)

However, this may be over-constrained. I see from your sketch of your
model that Class1 and Class2 are aggregated in a root. So, you might
rather do:

context Root
inv:
classes1->product(classes2)->forAll(pair |
pair.first.value1 <> pair.second.value2)

which would scope the constraint to the context of each individual Root
element.

HTH,

Christian


Achilleas wrote:
> Hi,
>
> I will like to ask if it is possible to compare two attributes using one
> audit rule;one constraint.
>
> For instance if i have the following metamodel
>
> Root (aggregates classes1,classes2)
> Class1(includes EAttribute value1) Class2(includes EAttribute value2)
>
> Usually when a constraint is written it will be of the form:
>
> Domain Element Target: |Class1::EClass
> Class1.allInstances()->forAll( c1, c2 | c1 <> c2 implies c1.value1
> <> c2.value1 )
>
>
> What if I want to compare the values of instances of the Class1 with
> instances of the Class2? Is there a way to define two Domain Element
> Targets? Could it be done directly from the Root class specifying this
> as the Domain Element Target?
>
> Thanks,
>
> Achilleas
Re: GMF mapping Audit Rules [message #217226 is a reply to message #217219] Wed, 04 February 2009 13:42 Go to previous messageGo to next message
Achilleas is currently offline AchilleasFriend
Messages: 88
Registered: July 2009
Member
Hi Christian,

I did it as follows:

context Class1:
inv:
Root.allInstances()->forAll(e | e.classes2->exists(c | c.value = self.value))

But i believe both of your ways are better!

I thought that only for the Root class we can use the allInstances() when
the context (domain element target) is set to another class.

Your 2nd example is even more expressive and resolves the problem I have,
where the error is depicted on all instances of the element,e.g. when i
impose the constraint:

context Class:
inv:
Class.allInstances()->forAll( c1, c2 | c1 <> c2 implies c1.id <> c2.id )

This produces an error that appears on all instances. I believe with your
2nd constraint this is contained only to the two specific instances that
have the same "id"??? Anyway I will try it out to see if that's the case!

Thanks,

Achilleas
Re: GMF mapping Audit Rules [message #217245 is a reply to message #217226] Wed, 04 February 2009 15:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Achilleas,

I'm glad that it looks like a resolution to your problem is in sight!

My second suggestion would result only in a problem marker on the
particular Root instance that contained conflicting Class1 and Class2
instances. Unfortunately, it would be difficult in that case to
actually present the user with useful error messages: how to indicate
*which* Class1 and Class2 instances are at fault?

My first suggestion is slightly better, because at least it puts a
problem marker on each violating Class1 instance. However, it doesn't
allow a Class1 to have the same attribute value as a Class2 in some
other Root than the one containing the Class1 in question.

Assuming you have a back-reference to the containing Root element in a
Class1, you could do:

context Class1
inv:
self.root.classes2->forAll(value2 <> self.value1)

Lacking the back-reference, you could do this which is actually quite
similar to what you already had:

context Class1
inv:
let root : Root = Root.allInstances()->any(classes1->includes(self)
in
root.classes2->forAll(value2 <> self.value1)

I think this gets you as close as possible, given the current EMF
Validation / GMF Audits implementation.

cW


Achilleas wrote:
> Hi Christian,
>
> I did it as follows:
>
> context Class1:
> inv:
> Root.allInstances()->forAll(e | e.classes2->exists(c | c.value =
> self.value))
>
> But i believe both of your ways are better!
> I thought that only for the Root class we can use the allInstances()
> when the context (domain element target) is set to another class.
> Your 2nd example is even more expressive and resolves the problem I
> have, where the error is depicted on all instances of the element,e.g.
> when i impose the constraint:
>
> context Class:
> inv:
> Class.allInstances()->forAll( c1, c2 | c1 <> c2 implies c1.id <> c2.id )
>
> This produces an error that appears on all instances. I believe with
> your 2nd constraint this is contained only to the two specific instances
> that have the same "id"??? Anyway I will try it out to see if that's the
> case!
>
> Thanks,
>
> Achilleas
>
Re: GMF mapping Audit Rules [message #217261 is a reply to message #217245] Wed, 04 February 2009 15:57 Go to previous messageGo to next message
Achilleas is currently offline AchilleasFriend
Messages: 88
Registered: July 2009
Member
Hi Christian,

You are always a step ahead with your answers:))..Since I tried your
second suggestion and my next question was going to be: "Why the problem
marker does not display the message assigned in the corresponding Audit
Rule?" I rather gives a custom message that denotes the problem.

Your clarifications are very helpful and give me an insight when I should
use each constraint to fit my needs.

I have another question for you though:), if you please could provide me
with an answer!

Lets assume that I have two metamodels that are defined as follows:

Metamodel 1:
Root1(aggregates classes1)
Class1(includes value1)
Value1

Metamodel 2:
Root2(aggregates classes2)
Class2(includes value2)
Value2

Is it possible to load into the gmfmap model of Metamodel 1 the resource
(i.e. ecore,gmfmap) that points to Metamodel 2 so that I can check if
there two instances with equal values (value1,value2)???--- in this case I
require them to be equal!

Can it be done in a single audit rule similar to the one below (that you
originally provided)?

context Class1
inv:
Class2.allInstances()->forAll(c2 | self.value1 <> c2.value2)

Thanks,

Achilleas
Re: GMF mapping Audit Rules [message #217310 is a reply to message #217261] Wed, 04 February 2009 19:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Achilleas,

From the OCL perspective, accessing the types in other models is just
as easy as qualifying their names. So, assuming that your metamodels
are named mm1 and mm2, respectively, you can do in the context of the
mm1::Class1 metaclass:

context Class1:
mm2::Class2.allInstances()->exists(c2 | self.value1 = c2.value2)

This assumes, of course, that both the mm1::Class1::value1 and
mm2::Class2::value2 properties have the same type, probably from some
other metamodel mm3 (or, perhaps, ecore if it's one of the Ecore
standard data types, for example).

Concerning how to develop GMF models based on multiple metamodels, I
have no expertise to offer. I'm quite certain, though, that the subject
has been raised several times in this newsgroup, before. A search
should turn something up.

Cheers,

Christian


Achilleas wrote:
> Hi Christian,
>
> You are always a step ahead with your answers:))..Since I tried your
> second suggestion and my next question was going to be: "Why the problem
> marker does not display the message assigned in the corresponding Audit
> Rule?" I rather gives a custom message that denotes the problem.
>
> Your clarifications are very helpful and give me an insight when I
> should use each constraint to fit my needs.
>
> I have another question for you though:), if you please could provide me
> with an answer!
>
> Lets assume that I have two metamodels that are defined as follows:
>
> Metamodel 1:
> Root1(aggregates classes1)
> Class1(includes value1)
> Value1
>
> Metamodel 2:
> Root2(aggregates classes2)
> Class2(includes value2)
> Value2
>
> Is it possible to load into the gmfmap model of Metamodel 1 the resource
> (i.e. ecore,gmfmap) that points to Metamodel 2 so that I can check if
> there two instances with equal values (value1,value2)???--- in this case
> I require them to be equal!
>
> Can it be done in a single audit rule similar to the one below (that you
> originally provided)?
>
> context Class1
> inv:
> Class2.allInstances()->forAll(c2 | self.value1 <> c2.value2)
>
> Thanks,
>
> Achilleas
>
Re: GMF mapping Audit Rules [message #217397 is a reply to message #217310] Thu, 05 February 2009 16:01 Go to previous messageGo to next message
Achilleas is currently offline AchilleasFriend
Messages: 88
Registered: July 2009
Member
Hi Christian,

I have followed your recommendation for qualifying names and it worked,
although the gmfmap validation was showing errors. Luckily I discovered
another post of another guy that you adviced him to ignore the validation
errors and run an instance of the editor.

I did that and altough the validation errors on .gmfmap exist the
constraint runs ok. Although it always gives me a constraint validation
even if the two values are equal.

Let's say that I have two instances: one of the Metamodel A---Model
A---Value A and one of the Metamodel B---Model B---ValueB.

What I don't understand is how does it know, when I am running the
validation on the editor of Model A, that it should check also Model B. My
guess is that it does not know and therefore it cannot check the Value A
of Model A against the Value B of Model B. That's why it the constraint
check fails each time.

Do you agree on this? Is there a way to resolve this so I can get it
working?

Thanks,

Achilleas
Re: GMF mapping Audit Rules [message #217487 is a reply to message #217397] Fri, 06 February 2009 13:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Achilleas,

GMF validation evaluates the constraints that are defined in the context
of the particular EClass of each element in your model, in turn. There
is nothing that attempts to discover related elements and validate them,
too (although extension points are available that sort-of allow for this).

So, basically, validation doesn't know that it should also check model B
when checking model A, unless some constraint in model A seeks out
elements in model B for itself and checks them.

As far as I understand the generic description of your constraint, you
have attributes ValueA from one metamodel and ValueB from another
metamodel. I would never consider their values to be comparable if
their *types* are from these different metamodels. Unless they are both
typed by the same Ecore primitive type, say, like EString.

Perhaps getting a little more concrete in your description of what you
are trying to achieve would help me to understand the nature of the problem.

Cheers,

Christian

Achilleas wrote:
> Hi Christian,
>
> I have followed your recommendation for qualifying names and it worked,
> although the gmfmap validation was showing errors. Luckily I discovered
> another post of another guy that you adviced him to ignore the
> validation errors and run an instance of the editor.
>
> I did that and altough the validation errors on .gmfmap exist the
> constraint runs ok. Although it always gives me a constraint validation
> even if the two values are equal.
>
> Let's say that I have two instances: one of the Metamodel A---Model
> A---Value A and one of the Metamodel B---Model B---ValueB.
> What I don't understand is how does it know, when I am running the
> validation on the editor of Model A, that it should check also Model B.
> My guess is that it does not know and therefore it cannot check the
> Value A of Model A against the Value B of Model B. That's why it the
> constraint check fails each time.
>
> Do you agree on this? Is there a way to resolve this so I can get it
> working?
>
> Thanks,
>
> Achilleas
>
Re: GMF mapping Audit Rules [message #217507 is a reply to message #217487] Fri, 06 February 2009 14:25 Go to previous messageGo to next message
Achilleas is currently offline AchilleasFriend
Messages: 88
Registered: July 2009
Member
Hi Christian,

I have two metamodels, process metamodel and an E-R metamodel. The first
metamodel contains an EClass named "OExpression" with an EAttribute named
"model" that is set to be of type EString. Similarly the second metamodel
contains an EClass named "Entity" with an EAttribute "type" that is also
set to be of the same type EString.

Therefore the type (datatype) of the two attributes ("model" and "type")
is comparable since they are both set to EString.

The problem is that when evaluating the process model within its GMF
editor, I am trying to check its "model" attribute against the E-R model's
"type" attribute. But there is no reference or extension point (like you
said) to know which E-R model should be used to evaluate the constraint. I
loaded both models using there individual GMF editors to try that but that
was an unfortunate assumption:)

The constraint i am using is:
context OExpression
inv: cml::Entity.allInstances()->exists(e2 | self.model = e2.type)

Do you have any idea how I can refer to the E-R model when validating the
process model?

Thanks,

Achilleas
Re: GMF mapping Audit Rules [message #217517 is a reply to message #217507] Fri, 06 February 2009 14:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Achilleas,

Thanks for the additional information. It is much clearer, now, what
you are attempting to do.

The default implementation of allInstances() has two limitations that
are at play in your situation:

- it is scoped to the current resource, assuming that as the "model"
- in any case, it would not "see" models in other editing domains
or that are not yet loaded

The second isn't really an OCL allInstances() limitation, it's a fact of
EMF life. Editing domains are intended to be treated as closed
universes, and by default GMF editors all use distinct editing domains
(I think?).

The first problem is easier to address, though it would require some
enhancement in GMF to make it work. The EvaluationEnvironment by
default creates a LazyExtentMap that searches only in the scope of the
current resource, not across the entire resource set. However, a client
can supply its own extent-map implementation that, for example, searches
the resource set. This is where GMF enhancements would come into play,
to allow the tooling model to specify the desired allInstances() scope
and plug in a suitable implementation. Of course, MDT OCL could assist
that by making the LazyExtentMap easier to customize ...

HTH,

Christian


Achilleas wrote:
> Hi Christian,
>
> I have two metamodels, process metamodel and an E-R metamodel. The first
> metamodel contains an EClass named "OExpression" with an EAttribute
> named "model" that is set to be of type EString. Similarly the second
> metamodel contains an EClass named "Entity" with an EAttribute "type"
> that is also set to be of the same type EString.
>
> Therefore the type (datatype) of the two attributes ("model" and "type")
> is comparable since they are both set to EString.
>
> The problem is that when evaluating the process model within its GMF
> editor, I am trying to check its "model" attribute against the E-R
> model's "type" attribute. But there is no reference or extension point
> (like you said) to know which E-R model should be used to evaluate the
> constraint. I loaded both models using there individual GMF editors to
> try that but that was an unfortunate assumption:)
>
> The constraint i am using is:
> context OExpression
> inv: cml::Entity.allInstances()->exists(e2 | self.model = e2.type)
>
> Do you have any idea how I can refer to the E-R model when validating
> the process model?
>
> Thanks,
>
> Achilleas
>
Re: GMF mapping Audit Rules [message #217521 is a reply to message #217517] Fri, 06 February 2009 15:36 Go to previous message
Achilleas is currently offline AchilleasFriend
Messages: 88
Registered: July 2009
Member
Hi Christian,

Sorry for overwhelming you with questions. I presume from you answer I
will need to extend the GMF work in order to address the ocl
allInstances() issue, in order to extend the scope outside the current
resource (the model).

I will try to resolve this using the information you provided me.

Thanks,

Achilleas
Previous Topic:Ocl question- check string is an integer similar to Integer.parseInt(myString)?
Next Topic:[Announce] GMF 2.2.0 I200902071249 is available
Goto Forum:
  


Current Time: Sat Apr 20 12:49:58 GMT 2024

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

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

Back to the top