Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » oclIsTypeOf and Interfaces
oclIsTypeOf and Interfaces [message #490149] Wed, 07 October 2009 14:08 Go to next message
Eclipse User
Originally posted by: formatzeh.gmx.de

I have the following constraint:

self.pointcut.source.oclIsTypeOf(self.advice.target)

I want to make sure that the type of source is the same as the type of
target. The point is that I get the error:

Cannot find operation (oclIsKindOf(IAdaptable)) for the type (IAdaptable)

Both, source and target, are references to the interface IAdaptable.
Can't I do the oclIsTypeOf check with interfaces?
Re: oclIsTypeOf and Interfaces [message #490318 is a reply to message #490149] Thu, 08 October 2009 10:41 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4086
Registered: July 2009
Senior Member
Hi Gilbert

We are working to solve a variety of type conformance issues for the
next release including the OCL 2.1 evolution to have OclAny as the
bottom 'Object' type.

What you have written should then work.

For now there may be a workaround using something like

ParsingOptions.setOption(ocl.getEnvironment(),
ParsingOptions.implicitRootClass(ocl.getEnvironment()),
EcorePackage.Literals.EOBJECT);

and ensuring that your interfaces all inherit from a root class.

Maybe Christian can be more help.

Regards

Ed Willink


Gilbert Mirenque wrote:
> I have the following constraint:
>
> self.pointcut.source.oclIsTypeOf(self.advice.target)
>
> I want to make sure that the type of source is the same as the type of
> target. The point is that I get the error:
>
> Cannot find operation (oclIsKindOf(IAdaptable)) for the type (IAdaptable)
>
> Both, source and target, are references to the interface IAdaptable.
> Can't I do the oclIsTypeOf check with interfaces?
Re: oclIsTypeOf and Interfaces [message #490370 is a reply to message #490149] Thu, 08 October 2009 13:28 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 801
Registered: July 2009
Senior Member
--=-27p637cGUjlfrOCLB3Rz
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Gilbert,

Since you're talking of interfaces, I assume you're dealing with a UML
model? If so, the UMLEnvironment should be interpreting them as OCL
types and parsing oclIsTypeOf(...) successfully when the argument is an
interface. As Ed indicates, the oclIs{Kind,Type}Of operations are
defined by OclAny which is the implicit ancestor of all non-collection
types in the OCL 2.0 spec.

One of the quirks of interfaces in UML is that, although they are
classifiers, they generally don't work well with type-conformance
queries such as oclIsKindOf() because interface implementation is not a
generalization relationship. A Class the "implements" an interface in
UML does not specialize it an any real terms; it only promises to
manifest the same features of the interface in some form that is
actually a "semantic variation point" (an example in the UML spec
suggests a Java profile in which a class might choose to manifest an
interface property as a pair of get/set operations!)

For these reasons, I generally suggest that for modeling Java software
with UML, one stereotype Classes as <<interface>> rather than use
interfaces, so that one gets real type conformance. This also removes
the problem of being unable to specify template parameters that can be
substituted by either a class or interface, which is impossible in UML
terms.

HTH, and sorry for the rant,

Christian


On Wed, 2009-10-07 at 16:08 +0200, Gilbert Mirenque wrote:

> I have the following constraint:
>
> self.pointcut.source.oclIsTypeOf(self.advice.target)
>
> I want to make sure that the type of source is the same as the type of
> target. The point is that I get the error:
>
> Cannot find operation (oclIsKindOf(IAdaptable)) for the type (IAdaptable)
>
> Both, source and target, are references to the interface IAdaptable.
> Can't I do the oclIsTypeOf check with interfaces?

--=-27p637cGUjlfrOCLB3Rz
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, Gilbert,<BR>
<BR>
Since you're talking of interfaces, I assume you're dealing with a UML model?&nbsp; If so, the UMLEnvironment should be interpreting them as OCL types and parsing oclIsTypeOf(...) successfully when the argument is an interface.&nbsp; As Ed indicates, the oclIs{Kind,Type}Of operations are defined by OclAny which is the implicit ancestor of all non-collection types in the OCL 2.0 spec.<BR>
<BR>
One of the quirks of interfaces in UML is that, although they are classifiers, they generally don't work well with type-conformance queries such as oclIsKindOf() because interface implementation is not a generalization relationship.&nbsp; A Class the &quot;implements&quot; an interface in UML does not specialize it an any real terms; it only promises to manifest the same features of the interface in some form that is actually a &quot;semantic variation point&quot;&nbsp; (an example in the UML spec suggests a Java profile in which a class might choose to manifest an interface property as a pair of get/set operations!)<BR>
<BR>
For these reasons, I generally suggest that for modeling Java software with UML, one stereotype Classes as &lt;&lt;interface&gt;&gt; rather than use interfaces, so that one gets real type conformance.&nbsp; This also removes the problem of being unable to specify template parameters that can be substituted by either a class or interface, which is impossible in UML terms.<BR>
<BR>
HTH, and sorry for the rant,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Wed, 2009-10-07 at 16:08 +0200, Gilbert Mirenque wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
I have the following constraint:

self.pointcut.source.oclIsTypeOf(self.advice.target)

I want to make sure that the type of source is the same as the type of
target. The point is that I get the error:

Cannot find operation (oclIsKindOf(IAdaptable)) for the type (IAdaptable)

Both, source and target, are references to the interface IAdaptable.
Can't I do the oclIsTypeOf check with interfaces?
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-27p637cGUjlfrOCLB3Rz--
Re: oclIsTypeOf and Interfaces [message #490385 is a reply to message #490370] Thu, 08 October 2009 13:55 Go to previous messageGo to next message
Eclipse User
Originally posted by: formatzeh.gmx.de

Thanks to you both,
> Since you're talking of interfaces, I assume you're dealing with a UML
> model?
No, I have an ecore model.

But as I suggest from Ed's post my expression is at least valid OCL?
That would be enough for me.
Re: oclIsTypeOf and Interfaces [message #490390 is a reply to message #490385] Thu, 08 October 2009 14:14 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 801
Registered: July 2009
Senior Member
--=-PSVddRKoEruspa2HCzEi
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Gilbert,

Sorry ... I completely missed the real problem the first time. Your
expression is not valid OCL.

In OCL 2.0, we have the following OclAny operations that do reflection:

oclIsKindOf(OclType) : Boolean
oclIsTypeOf(OclType) : Boolean
oclAsType(OclType) : T

Note the OclType argument. OCL 2.0 has a special class OclType
(metaclass TypeType) that provides an enumeration of the types available
in the OCL environment. An IAdaptable is not an OclType, so it cannot
be used as the orgument to oclIsKindOf or oclIsTypeOf.

What you would want to be able to do, and will be able to do under the
OCL 2.1 spec, is

self.pointcut.source.oclIsTypeOf(self.advice.target.oclType( ))

to use the OclAny::oclType() reflection operation to get the the
target's type, which you can pass to oclIsTypeOf.

The inability to query the actual type of an object is a serious problem
in OCL 2.0, and the OclType mechanism is rather awkward. Situations
like yours are the major motivation behind the (re-)introduction of
oclType() and supplanting OclType by Classifier (UML) and Type (EMOF).

You cannot formulate your expression using compliant OCL 2.0. You can
only do it using MDT OCL's Ecore-based "back door" that Ed pointed out:
set EObject as the "implicit root class" and then do this:

self.pointcut.source.eClass() = self.advice.target.eClass()

Cheers,

Christian

On Thu, 2009-10-08 at 15:55 +0200, Gilbert Mirenque wrote:

> Thanks to you both,
> > Since you're talking of interfaces, I assume you're dealing with a UML
> > model?
> No, I have an ecore model.
>
> But as I suggest from Ed's post my expression is at least valid OCL?
> That would be enough for me.

--=-PSVddRKoEruspa2HCzEi
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, Gilbert,<BR>
<BR>
Sorry ... I completely missed the real problem the first time.&nbsp; Your expression is not valid OCL.<BR>
<BR>
In OCL 2.0, we have the following OclAny operations that do reflection:<BR>
<BR>
&nbsp; oclIsKindOf(OclType) : Boolean<BR>
&nbsp; oclIsTypeOf(OclType) : Boolean<BR>
&nbsp; oclAsType(OclType) : T<BR>
<BR>
Note the OclType argument.&nbsp; OCL 2.0 has a special class OclType (metaclass TypeType) that provides an enumeration of the types available in the OCL environment.&nbsp; An IAdaptable is not an OclType, so it cannot be used as the orgument to oclIsKindOf or oclIsTypeOf.<BR>
<BR>
What you would want to be able to do, and will be able to do under the OCL 2.1 spec, is<BR>
<BR>
&nbsp; <TT><FONT COLOR="#000000">self.pointcut.source.oclIsTypeOf(self.advice.target </FONT></TT><TT>.oclType()</TT><TT><FONT COLOR="#000000">)</FONT></TT><BR>
<BR>
to use the OclAny::oclType() reflection operation to get the the target's type, which you can pass to oclIsTypeOf.<BR>
<BR>
The inability to query the actual type of an object is a serious problem in OCL 2.0, and the OclType mechanism is rather awkward.&nbsp; Situations like yours are the major motivation behind the (re-)introduction of oclType() and supplanting OclType by Classifier (UML) and Type (EMOF).<BR>
<BR>
You cannot formulate your expression using compliant OCL 2.0.&nbsp; You can only do it using MDT OCL's Ecore-based &quot;back door&quot; that Ed pointed out:&nbsp; set EObject as the &quot;implicit root class&quot; and then do this:<BR>
<BR>
<TT>&nbsp; </TT><TT><FONT COLOR="#000000">self.pointcut.source.</FONT></TT><TT>eClass() = </TT><TT><FONT COLOR="#000000">self.advice.target</FONT></TT><TT>.eClass() </TT><BR>
<BR>
Cheers,<BR>
<BR>
Christian<BR>
<BR>
On Thu, 2009-10-08 at 15:55 +0200, Gilbert Mirenque wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Thanks to you both,
&gt; Since you're talking of interfaces, I assume you're dealing with a UML
&gt; model?
No, I have an ecore model.

But as I suggest from Ed's post my expression is at least valid OCL?
That would be enough for me.
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-PSVddRKoEruspa2HCzEi--
Re: oclIsTypeOf and Interfaces [message #490412 is a reply to message #490390] Thu, 08 October 2009 14:57 Go to previous message
Eclipse User
Originally posted by: formatzeh.gmx.de

Thanks Christian,
that's enough for my concerns. I'll do the eClass() check now.

best regards,
Gilbert

Christian W. Damus wrote:
> Hi, Gilbert,
>
> Sorry ... I completely missed the real problem the first time. Your
> expression is not valid OCL.
>
> In OCL 2.0, we have the following OclAny operations that do reflection:
>
> oclIsKindOf(OclType) : Boolean
> oclIsTypeOf(OclType) : Boolean
> oclAsType(OclType) : T
>
> Note the OclType argument. OCL 2.0 has a special class OclType
> (metaclass TypeType) that provides an enumeration of the types available
> in the OCL environment. An IAdaptable is not an OclType, so it cannot
> be used as the orgument to oclIsKindOf or oclIsTypeOf.
>
> What you would want to be able to do, and will be able to do under the
> OCL 2.1 spec, is
>
> self.pointcut.source.oclIsTypeOf(self.advice.target.oclType( ))
>
> to use the OclAny::oclType() reflection operation to get the the
> target's type, which you can pass to oclIsTypeOf.
>
> The inability to query the actual type of an object is a serious problem
> in OCL 2.0, and the OclType mechanism is rather awkward. Situations
> like yours are the major motivation behind the (re-)introduction of
> oclType() and supplanting OclType by Classifier (UML) and Type (EMOF).
>
> You cannot formulate your expression using compliant OCL 2.0. You can
> only do it using MDT OCL's Ecore-based "back door" that Ed pointed out:
> set EObject as the "implicit root class" and then do this:
>
> self.pointcut.source.eClass() = self.advice.target.eClass()
Previous Topic:FOR-loop in OCL
Next Topic:N00b OCL expression question to compare URI
Goto Forum:
  


Current Time: Tue Oct 21 09:03:43 GMT 2014

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

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