Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » stereotype constraints
stereotype constraints [message #70256] Wed, 06 May 2009 12:43 Go to next message
Dennis Sluijsmans is currently offline Dennis SluijsmansFriend
Messages: 3
Registered: July 2009
Junior Member
Hi all,

I couldn't find a complete answer to my problem so I post it here.

I've build an UML profile with a stereotype called 'Flow' which extends
Association and a stereotype called 'Agent' which extends Class.
Now I want in a model with this profile applied to it, assure that every
class of stereotype Agent have an association of stereotype Flow attached
to it.

Here is what I made up so far for the constraint of stereotype Agent, but
on testing I still get an error.
Context Agent
inv: is_connected : attribute.association->exists(s |
s.extension_Flow->notEmpty())

Thanks in advance.

Dennis
Re: stereotype constraints [message #70298 is a reply to message #70256] Wed, 06 May 2009 12:57 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

--=-dnIB1MNrZhoGwa8xFh5X
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Dennis,

You're collecting the associations of all attributes of the Agent
stereotype instance. If Agent doesn't have a property named 'attribute'
then this won't work. You need the attributes of the base class. Try
this:

context Agent
inv is_connected:
base_Class.attribute.association->excluding(null)->exists(
extension_Flow->notEmpty())

taking measures also to strip out the nulls for attributes that aren't
association ends. Also, note the lower case 'c' in the context
declaration and the single colon in the "inv [name]" syntax.

HTH,

Christian

On Wed, 2009-05-06 at 12:43 +0000, Dennis Sluijsmans wrote:

> Hi all,
>
> I couldn't find a complete answer to my problem so I post it here.
>
> I've build an UML profile with a stereotype called 'Flow' which extends
> Association and a stereotype called 'Agent' which extends Class.
> Now I want in a model with this profile applied to it, assure that every
> class of stereotype Agent have an association of stereotype Flow attached
> to it.
>
> Here is what I made up so far for the constraint of stereotype Agent, but
> on testing I still get an error.
> Context Agent
> inv: is_connected : attribute.association->exists(s |
> s.extension_Flow->notEmpty())
>
> Thanks in advance.
>
> Dennis
>

--=-dnIB1MNrZhoGwa8xFh5X
Content-Type: text/html; charset="utf-8"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Dennis,<BR>
<BR>
You're collecting the associations of all attributes of the Agent stereotype instance.&nbsp; If Agent doesn't have a property named 'attribute' then this won't work.&nbsp; You need the attributes of the base class.&nbsp; Try this:<BR>
<BR>
context Agent<BR>
inv is_connected: base_Class.attribute.association-&gt;excluding(null)-&am p;gt;exists( <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; extension_Flow-&gt;notEmpty())<BR>
<BR>
taking measures also to strip out the nulls for attributes that aren't association ends.&nbsp; Also, note the lower case 'c' in the context declaration and the single colon in the &quot;inv [name]&quot; syntax.<BR>
<BR>
HTH,<BR>
<BR>
Christian<BR>
<BR>
On Wed, 2009-05-06 at 12:43 +0000, Dennis Sluijsmans wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Hi all,

I couldn't find a complete answer to my problem so I post it here.

I've build an UML profile with a stereotype called 'Flow' which extends
Association and a stereotype called 'Agent' which extends Class.
Now I want in a model with this profile applied to it, assure that every
class of stereotype Agent have an association of stereotype Flow attached
to it.

Here is what I made up so far for the constraint of stereotype Agent, but
on testing I still get an error.
Context Agent
inv: is_connected : attribute.association-&gt;exists(s |
s.extension_Flow-&gt;notEmpty())

Thanks in advance.

Dennis

</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-dnIB1MNrZhoGwa8xFh5X--
Re: stereotype constraints [message #70318 is a reply to message #70298] Wed, 06 May 2009 15:38 Go to previous messageGo to next message
Dennis Sluijsmans is currently offline Dennis SluijsmansFriend
Messages: 3
Registered: July 2009
Junior Member
Hi Christian,

Your solution works, thanks a lot!

Another thing, if I construct a new stereotype 'Connection' (as an
extension of Association) which is now a generalization of the stereotype
'Flow', the same constraint results in the following error:
"Parsing Error: Unrecognized variable:(extension_Flow)"

Any idea why?
Re: stereotype constraints [message #70377 is a reply to message #70318] Wed, 06 May 2009 21:08 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

--=-7pXAuGFk2DahhTq7PdkT
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Dennis,

Which of your stereotypes Flow and Connection has the metaclass
extension relationship to uml::Association? If it is Connection, then
your constraint must use extension_Connection.

Keep in mind that these "extension_Xyz" role names are nothing more nor
less than owned (and non-navigable) ends of the metaclass extensions.
They are, from an OCL perspective, in every way like ordinary Property
ends of Associations. So, if you have this:

Stereotype Connection
extends uml::Association

Stereotype Flow
specializes Connection

Then, in an Association context, you can do "self.extension_Connection"
but not "self.extension_Flow" because the latter is not define. If you
need to test that, in particular, the applied stereotype is a Flow, then
do "self.extension_Connection->any(oclIsKindOf(myprofile::Flow)) ".

Note that if you have, instead, this situation:

Stereotype Connection

Stereotype Flow
specializes Connection
extends uml::Association

then it is awkward to test whether an Association has any Connection
stereotype applied, as you would have to enumerate all of the
specializing stereotypes (such as Flow) that have metaclass extensions
to Association.

HTH,

Christian


On Wed, 2009-05-06 at 15:38 +0000, Dennis Sluijsmans wrote:

> Hi Christian,
>
> Your solution works, thanks a lot!
>
> Another thing, if I construct a new stereotype 'Connection' (as an
> extension of Association) which is now a generalization of the stereotype
> 'Flow', the same constraint results in the following error:
> "Parsing Error: Unrecognized variable:(extension_Flow)"
>
> Any idea why?
>

--=-7pXAuGFk2DahhTq7PdkT
Content-Type: text/html; charset="utf-8"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Dennis,<BR>
<BR>
Which of your stereotypes Flow and Connection has the metaclass extension relationship to uml::Association?&nbsp; If it is Connection, then your constraint must use extension_Connection.<BR>
<BR>
Keep in mind that these &quot;extension_Xyz&quot; role names are nothing more nor less than owned (and non-navigable) ends of the metaclass extensions.&nbsp; They are, from an OCL perspective, in every way like ordinary Property ends of Associations.&nbsp; So, if you have this:<BR>
<BR>
&nbsp; Stereotype Connection<BR>
&nbsp;&nbsp;&nbsp;&nbsp; extends uml::Association<BR>
<BR>
&nbsp; Stereotype Flow<BR>
&nbsp;&nbsp;&nbsp;&nbsp; specializes Connection<BR>
<BR>
Then, in an Association context, you can do &quot;self.extension_Connection&quot; but not &quot;self.extension_Flow&quot; because the latter is not define.&nbsp; If you need to test that, in particular, the applied stereotype is a Flow, then do &quot;self.extension_Connection-&gt;any(oclIsKindOf( myprofile::Flow))&quot;. <BR>
<BR>
Note that if you have, instead, this situation:<BR>
<BR>
&nbsp; Stereotype Connection<BR>
<BR>
&nbsp; Stereotype Flow<BR>
&nbsp;&nbsp;&nbsp; specializes Connection<BR>
&nbsp;&nbsp;&nbsp; extends uml::Association<BR>
<BR>
then it is awkward to test whether an Association has any Connection stereotype applied, as you would have to enumerate all of the specializing stereotypes (such as Flow) that have metaclass extensions to Association.<BR>
<BR>
HTH,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Wed, 2009-05-06 at 15:38 +0000, Dennis Sluijsmans wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Hi Christian,

Your solution works, thanks a lot!

Another thing, if I construct a new stereotype 'Connection' (as an
extension of Association) which is now a generalization of the stereotype
'Flow', the same constraint results in the following error:
&quot;Parsing Error: Unrecognized variable:(extension_Flow)&quot;

Any idea why?

</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-7pXAuGFk2DahhTq7PdkT--
Re: stereotype constraints [message #70478 is a reply to message #70377] Thu, 07 May 2009 12:44 Go to previous messageGo to next message
Dennis Sluijsmans is currently offline Dennis SluijsmansFriend
Messages: 3
Registered: July 2009
Junior Member
Hi Christian,

It is the myprofile::Connection stereotype that has the metaclass
extension relationship to uml::Association.

So the complete constraint for myprofile::Agent would be
context Agent
inv is_connected :
base_Class.attribute.association->excluding(null)->exists(extension_SuperFlow- >any(oclIsKindOf(Profile::Flow)))

Isn't there a much easier expression just for checking if a class has a
stereotype of uml::Association attached to it?

Thx,
Dennis
Re: stereotype constraints [message #70520 is a reply to message #70478] Thu, 07 May 2009 12:55 Go to previous message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

--=-3msf/srw4/KW0f2oD0vD
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Dennis,

OCL is quite a small language, and has a very tiny library. So, there's
not much convenience. Nonetheless, it can express a very wide range of
constructs. It also allows you to develop your own library of helper
operations (so-called "def" expressions) to simplify the structure of
constraints and to reuse expressions. In the MDT implementation, you
can even extend the environment with Java-defined operations, that can
do more complex and meta-level computations than would even be feasible
with OCL. The OCL Developer Guide has an example of this, showing how
to add a regexp-matching operation to the String primitive type.

Some of the operations provided by the MDT implementation of UML may
also help. For example, I think there's an operation that gets all of
the Associations in which a Type (not just Classifiers, which I find
odd) participates. This may help to simplify your OCL.

Cheers,

Christian

On Thu, 2009-05-07 at 12:44 +0000, Dennis Sluijsmans wrote:

> Hi Christian,
>
> It is the myprofile::Connection stereotype that has the metaclass
> extension relationship to uml::Association.
>
> So the complete constraint for myprofile::Agent would be
> context Agent
> inv is_connected :
> base_Class.attribute.association->excluding(null)->exists(extension_SuperFlow- >any(oclIsKindOf(Profile::Flow)))
>
> Isn't there a much easier expression just for checking if a class has a
> stereotype of uml::Association attached to it?
>
> Thx,
> Dennis
>

--=-3msf/srw4/KW0f2oD0vD
Content-Type: text/html; charset="utf-8"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Dennis,<BR>
<BR>
OCL is quite a small language, and has a very tiny library.&nbsp; So, there's not much convenience.&nbsp; Nonetheless, it can express a very wide range of constructs.&nbsp; It also allows you to develop your own library of helper operations (so-called &quot;def&quot; expressions) to simplify the structure of constraints and to reuse expressions.&nbsp; In the MDT implementation, you can even extend the environment with Java-defined operations, that can do more complex and meta-level computations than would even be feasible with OCL.&nbsp; The OCL Developer Guide has an example of this, showing how to add a regexp-matching operation to the String primitive type.<BR>
<BR>
Some of the operations provided by the MDT implementation of UML may also help.&nbsp; For example, I think there's an operation that gets all of the Associations in which a Type (not just Classifiers, which I find odd) participates.&nbsp; This may help to simplify your OCL.<BR>
<BR>
Cheers,<BR>
<BR>
Christian<BR>
<BR>
On Thu, 2009-05-07 at 12:44 +0000, Dennis Sluijsmans wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Hi Christian,

It is the myprofile::Connection stereotype that has the metaclass
extension relationship to uml::Association.

So the complete constraint for myprofile::Agent would be
context Agent
inv is_connected :
base_Class.attribute.association-&gt;excluding(null)-&am p;gt;exists(extension_SuperFlow-&gt;any(oclIsKindOf(Prof ile::Flow)))

Isn't there a much easier expression just for checking if a class has a
stereotype of uml::Association attached to it?

Thx,
Dennis

</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-3msf/srw4/KW0f2oD0vD--
Previous Topic:OCL and Ecore object relationships
Next Topic:Getting all instances from multiple resources
Goto Forum:
  


Current Time: Fri Mar 29 08:07:39 GMT 2024

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

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

Back to the top