Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Referring to all attributes of a class/element.
Referring to all attributes of a class/element. [message #32086] Fri, 06 July 2007 15:05 Go to next message
Juan Pedro Silva is currently offline Juan Pedro Silva
Messages: 258
Registered: July 2009
Senior Member
Hi everybody.
I am trying to refer to all attributes of a class, to see if one is
present. Something like "This element must have an attribute with name =
'size'."

I looked in OCL specification and found nothing. Tried using /attribute
from UML::Classifier, but didn't work (I tried self.attribute and
self./attribute). I found on the Internet
(http://www.zurich.ibm.com/~wah/doc/emf-ocl/) an example using
"self.attributes->forAll(not isPublic())" to test for public attributes,
but self.attributes didn't work either. I tried searching in Eclipse EMF
API reference for some method like "getAllAttributes()" with no luck.

Could anybody give me a hand with this?.
Is there a way to do it?.
Thank you in advance.
See you.
Re: Referring to all attributes of a class/element. [message #32122 is a reply to message #32086] Fri, 06 July 2007 15:31 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Juan Pedro,

Something like the following should work:

context Classifier
inv has_size: self.attribute->exists(name = 'size')

Note that the "/" in "/attribute" is just a notation indicating that the
property is derived; the name of this Classifier property is simply
"attribute". In the UML metamodel, all properties are named in the
singular even if they have many multiplicity.

What is the error message that you are getting from the OCL parser? What
are you using as the context classifier of your constraint? Which
environment implementation? I suspect that, perhaps, you are trying to
cross meta-levels, here (attempting to parse in the context of a classifier
in your model rather than a metaclass in the metamodel).

More information is needed to diagnose this problem.

Cheers,

Christian


Juan Pedro Silva wrote:

> Hi everybody.
> I am trying to refer to all attributes of a class, to see if one is
> present. Something like "This element must have an attribute with name =
> 'size'."
>
> I looked in OCL specification and found nothing. Tried using /attribute
> from UML::Classifier, but didn't work (I tried self.attribute and
> self./attribute). I found on the Internet
> (http://www.zurich.ibm.com/~wah/doc/emf-ocl/) an example using
> "self.attributes->forAll(not isPublic())" to test for public attributes,
> but self.attributes didn't work either. I tried searching in Eclipse EMF
> API reference for some method like "getAllAttributes()" with no luck.
>
> Could anybody give me a hand with this?.
> Is there a way to do it?.
> Thank you in advance.
> See you.
Re: Referring to all attributes of a class/element. [message #32262 is a reply to message #32122] Fri, 06 July 2007 18:34 Go to previous messageGo to next message
Juan Pedro Silva is currently offline Juan Pedro Silva
Messages: 258
Registered: July 2009
Senior Member
Hi Christian, long time don't see, uh? ;-)
I had writing a thorough email, until I got news from IBM's
developerworks forum (I'm using RSA 7). The answer in the forum was:
"You do not need context statement. Actually, it would create a syntax
error if you tried to write one. The context is implied - it is the
owner of the constraint.", so I'm quite limited here, aren't I?.

I will try asking in developerworks, but my hopes of getting help on
this are none whatsoever.

If your are still interested, I'm leaving my "thorough email" below.
Thank you very much, Christian.
Regards,
Juan Pedro

I don't
Ok, let's see (I will tell you my situation step by step, as it has
suddenly become more complicated):

-Just by typing self.attribute->exists(name='size'), I get a "Parsing
Error: ERROR in (variableExpCS): (Unrecognized variable: (attribute)).
The (implicit) context in which I was is a stereotype that extends
Connector (I then navigated towards the component at one end).

-If I type ONLY "context Classifier inv has_size:" I get a "Parsing
Error: 1:32:1:32 "oclExpressionCS" expected after ":"" (an error which
is completely understandable because I'm missing a piece, but which I
wanted to check due to the next error)

-and finally, if I type "context Classifier inv has_size:
self.attribute->exists(name = 'size')" I get a completely unexpected
"Parsing Error: Invalid OCL". How's that?

What I was trying to check was the presence of a property defined in a
stereotype, which has multiplicity 0..1.

Regarding my environment: I'm using IBM's Rational SDP 7 (RSA 7). I am
also not making OCL constraints files and compiling, I'm writting
constraints through the IDE and it provides real time validation from
the parser.



Christian W. Damus escribió:
> Hi, Juan Pedro,
>
> Something like the following should work:
>
> context Classifier
> inv has_size: self.attribute->exists(name = 'size')
>
> Note that the "/" in "/attribute" is just a notation indicating that the
> property is derived; the name of this Classifier property is simply
> "attribute". In the UML metamodel, all properties are named in the
> singular even if they have many multiplicity.
>
> What is the error message that you are getting from the OCL parser? What
> are you using as the context classifier of your constraint? Which
> environment implementation? I suspect that, perhaps, you are trying to
> cross meta-levels, here (attempting to parse in the context of a classifier
> in your model rather than a metaclass in the metamodel).
>
> More information is needed to diagnose this problem.
>
> Cheers,
>
> Christian
>
>
> Juan Pedro Silva wrote:
>
>> Hi everybody.
>> I am trying to refer to all attributes of a class, to see if one is
>> present. Something like "This element must have an attribute with name =
>> 'size'."
>>
>> I looked in OCL specification and found nothing. Tried using /attribute
>> from UML::Classifier, but didn't work (I tried self.attribute and
>> self./attribute). I found on the Internet
>> (http://www.zurich.ibm.com/~wah/doc/emf-ocl/) an example using
>> "self.attributes->forAll(not isPublic())" to test for public attributes,
>> but self.attributes didn't work either. I tried searching in Eclipse EMF
>> API reference for some method like "getAllAttributes()" with no luck.
>>
>> Could anybody give me a hand with this?.
>> Is there a way to do it?.
>> Thank you in advance.
>> See you.
>
Re: Referring to all attributes of a class/element. [message #32297 is a reply to message #32262] Fri, 06 July 2007 19:01 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Juan Pedro,

I see, now, that you are dealing with constraints in UML Profiles. That's a
pretty tricky area :-)

First, your DeveloperWorks contact is correct about the concrete syntax for
context declarations: it is not used when embedding OCL expressions or
constraints in models, because the OpaqueExpression provides all of the
relevant context via its placement in the model (with the help of the
Constraint element for constraints, via the constrainedElement, context,
and other properties).

Since your constraint is owned by a Stereotype, that Stereotype is your
context classifier. If your Stereotype extends the Classifier metaclass
(or some specialization thereof, such as Class), then you can do:

self.base_Classifier.attribute->exists(name='size')

or

self.base_Class.attribute->exists(name='size')

according to the extended metaclass.

What you cannot (easily) do in RSA is to define a constraint that checks the
stereotype, itself. Your constraints can only check instances of the
stereotype (i.e., stereotype applications in a model), the element to which
the stereotype is applied, and anything else reachable from that element.

If this is what you need to do, then you can try the following:

- let P be your profile containing the stereotype S that you want to
constrain to have a 'size' property
- define a profile Q with a stereotype T that extends the Stereotype
metaclass
- create a Constraint on T that looks like:
self.base_Stereotype.attribute->exists(name='size')
- apply the profile Q to the profile P
- apply the stereotype T to your stereotype S, so that you get
"<<t>> S"
- validate your profile P to see what it reports about S's adherence
to your constraint

I don't know whether RSA supports this; you might check with your support
representative. For that matter, I'm not even entirely sure that the UML
specification permits the stereotyping of stereotypes. I don't see why not
....

HTH,

Christian


Juan Pedro Silva wrote:

> Hi Christian, long time don't see, uh? ;-)
> I had writing a thorough email, until I got news from IBM's
> developerworks forum (I'm using RSA 7). The answer in the forum was:
> "You do not need context statement. Actually, it would create a syntax
> error if you tried to write one. The context is implied - it is the
> owner of the constraint.", so I'm quite limited here, aren't I?.
>
> I will try asking in developerworks, but my hopes of getting help on
> this are none whatsoever.
>
> If your are still interested, I'm leaving my "thorough email" below.
> Thank you very much, Christian.
> Regards,
> Juan Pedro
>
> I don't
> Ok, let's see (I will tell you my situation step by step, as it has
> suddenly become more complicated):
>
> -Just by typing self.attribute->exists(name='size'), I get a "Parsing
> Error: ERROR in (variableExpCS): (Unrecognized variable: (attribute)).
> The (implicit) context in which I was is a stereotype that extends
> Connector (I then navigated towards the component at one end).
>
> -If I type ONLY "context Classifier inv has_size:" I get a "Parsing
> Error: 1:32:1:32 "oclExpressionCS" expected after ":"" (an error which
> is completely understandable because I'm missing a piece, but which I
> wanted to check due to the next error)
>
> -and finally, if I type "context Classifier inv has_size:
> self.attribute->exists(name = 'size')" I get a completely unexpected
> "Parsing Error: Invalid OCL". How's that?
>
> What I was trying to check was the presence of a property defined in a
> stereotype, which has multiplicity 0..1.
>
> Regarding my environment: I'm using IBM's Rational SDP 7 (RSA 7). I am
> also not making OCL constraints files and compiling, I'm writting
> constraints through the IDE and it provides real time validation from
> the parser.
>

<snip>
Re: Referring to all attributes of a class/element. [message #32367 is a reply to message #32297] Sat, 07 July 2007 19:05 Go to previous messageGo to next message
Juan Pedro Silva is currently offline Juan Pedro Silva
Messages: 258
Registered: July 2009
Senior Member
Ok, now my mistake is clear to me: my stereotype is applied to 'Port',
so when I wanted to get port's 'owner', I got an 'Element', which off
course had no 'attribute' property, to start with.

However, I feel now that I might be able to do what I was trying to do
in the first place: standing on stereotype 'S' on a 'Port', I would
navigate to the 'owner' Component. I may check if stereotype 'C' is
applied on this 'Component' and, if so, check if that stereotype
instance 'C' has the appropriate attribute, as 'Stereotype' is
generalizes 'Class', which in turn generalizes 'Classifier', which is
the metaclass providing the 'attribute' attribute (jeje, kind of messy).
Am I right this time?.

I think I got it right (I'm no longer getting error messages from the
parser). I'm skipping the if clause to shorten it:

self.base_Port.owner.getAppliedStereotypes()->select(name='serviceProvider')- >forAll
(
s : Stereotype | s.attribute->exists(name = 'allowedBindings')
and s.attribute->select(name = 'allowedBindings')->forAll(not
oclIsUndefined())
)

I think that is right. Is valid at least.
I hold for your feedback.
Thank you... again!!. ;-)




Christian W. Damus escribió:
> Hi, Juan Pedro,
>
> I see, now, that you are dealing with constraints in UML Profiles. That's a
> pretty tricky area :-)
>
> First, your DeveloperWorks contact is correct about the concrete syntax for
> context declarations: it is not used when embedding OCL expressions or
> constraints in models, because the OpaqueExpression provides all of the
> relevant context via its placement in the model (with the help of the
> Constraint element for constraints, via the constrainedElement, context,
> and other properties).
>
> Since your constraint is owned by a Stereotype, that Stereotype is your
> context classifier. If your Stereotype extends the Classifier metaclass
> (or some specialization thereof, such as Class), then you can do:
>
> self.base_Classifier.attribute->exists(name='size')
>
> or
>
> self.base_Class.attribute->exists(name='size')
>
> according to the extended metaclass.
>
> What you cannot (easily) do in RSA is to define a constraint that checks the
> stereotype, itself. Your constraints can only check instances of the
> stereotype (i.e., stereotype applications in a model), the element to which
> the stereotype is applied, and anything else reachable from that element.
>
> If this is what you need to do, then you can try the following:
>
> - let P be your profile containing the stereotype S that you want to
> constrain to have a 'size' property
> - define a profile Q with a stereotype T that extends the Stereotype
> metaclass
> - create a Constraint on T that looks like:
> self.base_Stereotype.attribute->exists(name='size')
> - apply the profile Q to the profile P
> - apply the stereotype T to your stereotype S, so that you get
> "<<t>> S"
> - validate your profile P to see what it reports about S's adherence
> to your constraint
>
> I don't know whether RSA supports this; you might check with your support
> representative. For that matter, I'm not even entirely sure that the UML
> specification permits the stereotyping of stereotypes. I don't see why not
> ...
>
> HTH,
>
> Christian
>
>
> Juan Pedro Silva wrote:
>
>> Hi Christian, long time don't see, uh? ;-)
>> I had writing a thorough email, until I got news from IBM's
>> developerworks forum (I'm using RSA 7). The answer in the forum was:
>> "You do not need context statement. Actually, it would create a syntax
>> error if you tried to write one. The context is implied - it is the
>> owner of the constraint.", so I'm quite limited here, aren't I?.
>>
>> I will try asking in developerworks, but my hopes of getting help on
>> this are none whatsoever.
>>
>> If your are still interested, I'm leaving my "thorough email" below.
>> Thank you very much, Christian.
>> Regards,
>> Juan Pedro
>>
>> I don't
>> Ok, let's see (I will tell you my situation step by step, as it has
>> suddenly become more complicated):
>>
>> -Just by typing self.attribute->exists(name='size'), I get a "Parsing
>> Error: ERROR in (variableExpCS): (Unrecognized variable: (attribute)).
>> The (implicit) context in which I was is a stereotype that extends
>> Connector (I then navigated towards the component at one end).
>>
>> -If I type ONLY "context Classifier inv has_size:" I get a "Parsing
>> Error: 1:32:1:32 "oclExpressionCS" expected after ":"" (an error which
>> is completely understandable because I'm missing a piece, but which I
>> wanted to check due to the next error)
>>
>> -and finally, if I type "context Classifier inv has_size:
>> self.attribute->exists(name = 'size')" I get a completely unexpected
>> "Parsing Error: Invalid OCL". How's that?
>>
>> What I was trying to check was the presence of a property defined in a
>> stereotype, which has multiplicity 0..1.
>>
>> Regarding my environment: I'm using IBM's Rational SDP 7 (RSA 7). I am
>> also not making OCL constraints files and compiling, I'm writting
>> constraints through the IDE and it provides real time validation from
>> the parser.
>>
>
> <snip>
Re: Referring to all attributes of a class/element. [message #32471 is a reply to message #32367] Mon, 09 July 2007 15:13 Go to previous message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Juan Pedro,

Yes, that looks like it should do what you described. However, the

and s.attribute->select(name = 'allowedBindings')->forAll(
not oclIsUndefined())

clause is redundant. None of the attributes whose name is 'allowedBindings'
can possibly be undefined because neither "null" nor "OclInvalid" would
ever match the "name = 'allowedBindings'" condition.

Cheers,

Christian


Juan Pedro Silva wrote:

> Ok, now my mistake is clear to me: my stereotype is applied to 'Port',
> so when I wanted to get port's 'owner', I got an 'Element', which off
> course had no 'attribute' property, to start with.
>
> However, I feel now that I might be able to do what I was trying to do
> in the first place: standing on stereotype 'S' on a 'Port', I would
> navigate to the 'owner' Component. I may check if stereotype 'C' is
> applied on this 'Component' and, if so, check if that stereotype
> instance 'C' has the appropriate attribute, as 'Stereotype' is
> generalizes 'Class', which in turn generalizes 'Classifier', which is
> the metaclass providing the 'attribute' attribute (jeje, kind of messy).
> Am I right this time?.
>
> I think I got it right (I'm no longer getting error messages from the
> parser). I'm skipping the if clause to shorten it:
>
>
self.base_Port.owner.getAppliedStereotypes()->select(name='serviceProvider')- >forAll
> (
> s : Stereotype | s.attribute->exists(name = 'allowedBindings')
> and s.attribute->select(name = 'allowedBindings')->forAll(not
> oclIsUndefined())
> )
>
> I think that is right. Is valid at least.
> I hold for your feedback.
> Thank you... again!!. ;-)
>

<snip>
Previous Topic:regex/ocl
Next Topic:Customizing ocl environnement
Goto Forum:
  


Current Time: Thu Oct 30 19:07:06 GMT 2014

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

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