Home » Modeling » OCL » setInstanceContext() method
setInstanceContext() method [message #26406] |
Sat, 02 June 2007 00:30 |
Eclipse User |
|
|
|
Originally posted by: asma.charfi.com
Hi Christian,
concerning the bug 189981,I changed
helper.setInstanceContext((Classifier)classifiers.get(0));
but parsing did not succed. here is the exeption :(Cannot find operation
(getAllAttributes()) for the type (OclAny))
here is the value of helper.getContextClassifier()
"org.eclipse.ocl.uml.impl.AnyTypeImpl@1eac903 (name: <unset>, visibility:
<unset>) (isLeaf: false, visibility: public, isAbstract: false)"
So I added the "helper.setContext((Classifier)classifiers.get(0))"
the value of helper.getContextClassifier() is
"org.eclipse.uml2.uml.internal.impl.StereotypeImpl@f9d4f7 (name: Client,
visibility: <unset>) (isLeaf: false, visibility: public, isAbstract: false)
(isActive: false, isAbstract: false)"
but the same problem persist: ERROR in (operationCallExpCS): (Cannot find
operation (getAllAttributes()) for the type (Client)).
(isLeaf:
what sould I do?
thanks
asma
|
|
|
Re: setInstanceContext() method [message #26444 is a reply to message #26406] |
Fri, 01 June 2007 16:17 |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Asma,
That's bizarre. When I change the test_parseStereotypeConstraint() method
of the ProfilesTest class (in the org.eclipse.ocl.uml.tests plug-in) to
look like the following:
public void test_parseStereotypeConstraint() {
helper.setInstanceContext(testStereotype); // a Stereotype
try {
Constraint constraint = helper.createInvariant(
"self.getAllAttributes()->exists(name = 'yesno')");
// the 'Stereo1' Stereotype has an attribute named 'yesno'
assertTrue(ocl.check(testStereotype, constraint));
} catch (Exception e) {
fail("Failed to parse or evaluate: " + e.getLocalizedMessage());
}
}
it works just fine. So, I'm not sure what is different in your situation.
If you can send me a ZIPped up Eclipse project with an example of your code
that doesn't work, then I may be better able to figure out what's going
wrong.
Cheers,
Christian
charfi asma wrote:
> Hi Christian,
>
> concerning the bug 189981,I changed
> helper.setInstanceContext((Classifier)classifiers.get(0));
> but parsing did not succed. here is the exeption :(Cannot find operation
> (getAllAttributes()) for the type (OclAny))
> here is the value of helper.getContextClassifier()
> "org.eclipse.ocl.uml.impl.AnyTypeImpl@1eac903 (name: <unset>, visibility:
> <unset>) (isLeaf: false, visibility: public, isAbstract: false)"
>
> So I added the "helper.setContext((Classifier)classifiers.get(0))"
> the value of helper.getContextClassifier() is
> "org.eclipse.uml2.uml.internal.impl.StereotypeImpl@f9d4f7 (name: Client,
> visibility: <unset>) (isLeaf: false, visibility: public, isAbstract:
> false) (isActive: false, isAbstract: false)"
> but the same problem persist: ERROR in (operationCallExpCS): (Cannot find
> operation (getAllAttributes()) for the type (Client)).
> (isLeaf:
> what sould I do?
> thanks
> asma
|
|
|
Re: setInstanceContext() method [message #26639 is a reply to message #26406] |
Mon, 04 June 2007 18:05 |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Asma,
Testing this with your code that you sent me (thanks) revealed what I should
have seen sooner: that the stereotype constraint was attempting to access
the getAllAttributes() operation in the Client stereotype (which does not
exist) instead of in the Class metaclass that Client extends. It had
nothing to do with requiring setInstanceContext() which, actually, is not
correct; sorry about that.
So, you need the following:
self.base_Class.getAllAttributes()->select(name->exists(name='adresse'))- >size()>0
instead of
self.getAllAttributes()->select(name->exists(name='adresse'))- >size()>0
Then, everything should work as you expect. The constraint *seemed* to work
using the Ecore environment because it was looking at the metamodel: the
Stereotype EClass, which does defined a getAllAttributes() operation
(inherited from Classifier). It would pass because Client, itself, defines
an "adresse" attribute). However, the stereotype constraint needs to be
parsed at the model level because a profile is a UML model, so
setInstanceContext() is appropriate (as you tried, below). Just include
the navigation of the base_Class extension end and all should be well.
Cheers,
Christian
charfi asma wrote:
> Hi Christian,
>
> concerning the bug 189981,I changed
> helper.setInstanceContext((Classifier)classifiers.get(0));
> but parsing did not succed. here is the exeption :(Cannot find operation
> (getAllAttributes()) for the type (OclAny))
> here is the value of helper.getContextClassifier()
> "org.eclipse.ocl.uml.impl.AnyTypeImpl@1eac903 (name: <unset>, visibility:
> <unset>) (isLeaf: false, visibility: public, isAbstract: false)"
>
> So I added the "helper.setContext((Classifier)classifiers.get(0))"
> the value of helper.getContextClassifier() is
> "org.eclipse.uml2.uml.internal.impl.StereotypeImpl@f9d4f7 (name: Client,
> visibility: <unset>) (isLeaf: false, visibility: public, isAbstract:
> false) (isActive: false, isAbstract: false)"
> but the same problem persist: ERROR in (operationCallExpCS): (Cannot find
> operation (getAllAttributes()) for the type (Client)).
> (isLeaf:
> what sould I do?
> thanks
> asma
|
|
|
Re: setInstanceContext() method [message #26678 is a reply to message #26639] |
Tue, 05 June 2007 07:53 |
Eclipse User |
|
|
|
Originally posted by: asma.charfi.com
Hi Christian,
thank you very much the constraint is parsed very well!
but when I try to evaluate it using
ocl.evaluate(helper.getContextClassifier(),parsed);
or ocl.check((helper.getContextClassifier(),parsed) evaluation did not work
:((
the exeption is "no such property base_Class) but the stereotype Client has
a base_Class property !!!
the value of helper.getcontexteClassifier() is
"org.eclipse.uml2.uml.internal.impl.StereotypeImpl@b1be82 (name: Client,
visibility: <unset>) (isLeaf: false, visibility: public, isAbstract: false)
(isActive: false, isAbstract: false)[OCL] variableExpCS: Variable
Expression: self"
thank you Christian
"Christian W. Damus" <cdamus@ca.ibm.com> a
|
|
|
Re: setInstanceContext() method [message #26803 is a reply to message #26678] |
Tue, 05 June 2007 13:41 |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Asma,
Have a look at the update of your project that I sent you.
When you evaluate an OCL constraint on a model element, you must evaluate it
on that element, not its metaclass.
Try this:
ocl.evaluate(<selected element>, parsed);
ocl.check(<selected element>, parsed);
Cheers,
Christian
charfi asma wrote:
> Hi Christian,
> thank you very much the constraint is parsed very well!
> but when I try to evaluate it using
> ocl.evaluate(helper.getContextClassifier(),parsed);
> or ocl.check((helper.getContextClassifier(),parsed) evaluation did not
> work
> :((
> the exeption is "no such property base_Class) but the stereotype Client
> has a base_Class property !!!
> the value of helper.getcontexteClassifier() is
> "org.eclipse.uml2.uml.internal.impl.StereotypeImpl@b1be82 (name: Client,
> visibility: <unset>) (isLeaf: false, visibility: public, isAbstract:
> false) (isActive: false, isAbstract: false)[OCL] variableExpCS: Variable
> Expression: self"
>
> thank you Christian
> "Christian W. Damus" <cdamus@ca.ibm.com> a �rit dans le message de news:
> f41k9l$6lk$1@build.eclipse.org...
<snip>
|
|
|
Re: setInstanceContext() method [message #27159 is a reply to message #26803] |
Fri, 08 June 2007 00:02 |
Eclipse User |
|
|
|
Originally posted by: asma.charfi.com
Hi christian,
thank you very much. it works but only when I write this:
constraint parsed=null;
parsed=helper.createrInvariant(body);
a=ocl.check(objectselected,parsed) it works perfectly!
but when I change to:
org.eclipse.ocl.uml.OCLExpression parsed=null;
parsed = helper.createQuery(body);
a=ocl.check(objectselected, parsed);
it always return false and here is my console:
[OCL] Result : org.eclipse.uml2.uml.internal.impl.ClassImpl@adb3f (name:
Client1, visibility: <unset>) (isLeaf: false, visibility: public,
isAbstract: false) (isActive: false, isAbstract: false)
[OCL] Evaluate: self.base_Class.getAllAttributes()->select(temp1 : Property
| Set {temp1.name}->exists(temp2 : String |
temp1.name.=('adresse')))->size().>(0)
[OCL] Result : OclInvalid
thank you very much!
"Christian W. Damus" <cdamus@ca.ibm.com> a
|
|
|
Re: setInstanceContext() method [message #27199 is a reply to message #27159] |
Thu, 07 June 2007 15:32 |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Asma,
You would want to use the helper.createInvariant(body) method, anyway, if
you're dealing with constraints, because it validates the well-formedness
of the constraint (including that it is a boolean-valued expression,
doesn't use @pre, etc.)
The query expression doesn't work for you because the helper returns an
OCLExpression that isn't contained by an ExpressionInOCL, which is required
in order to determine the context classifier and whether that classifier is
a stereotype. The consequence of this is that the query is evaluated on
the base Element (which doesn't make sense, resulting in OclInvalid)
instead of on the stereotype instance.
Cheers,
Christian
charfi asma wrote:
> Hi christian,
>
> thank you very much. it works but only when I write this:
>
> constraint parsed=null;
> parsed=helper.createrInvariant(body);
> a=ocl.check(objectselected,parsed) it works perfectly!
> but when I change to:
>
> org.eclipse.ocl.uml.OCLExpression parsed=null;
> parsed = helper.createQuery(body);
> a=ocl.check(objectselected, parsed);
>
> it always return false and here is my console:
> [OCL] Result : org.eclipse.uml2.uml.internal.impl.ClassImpl@adb3f (name:
> Client1, visibility: <unset>) (isLeaf: false, visibility: public,
> isAbstract: false) (isActive: false, isAbstract: false)
> [OCL] Evaluate: self.base_Class.getAllAttributes()->select(temp1 :
> [Property
> | Set {temp1.name}->exists(temp2 : String |
> temp1.name.=('adresse')))->size().>(0)
> [OCL] Result : OclInvalid
>
> thank you very much!
>
>
>
> "Christian W. Damus" <cdamus@ca.ibm.com> a �rit dans le message de news:
> f43p4k$kj$1@build.eclipse.org...
>> Hi, Asma,
>>
>> Have a look at the update of your project that I sent you.
>>
>> When you evaluate an OCL constraint on a model element, you must evaluate
>> it
>> on that element, not its metaclass.
>>
>> Try this:
>>
>> ocl.evaluate(<selected element>, parsed);
>> ocl.check(<selected element>, parsed);
>>
>> Cheers,
>>
>> Christian
>>
>>
>> charfi asma wrote:
>>
>>> Hi Christian,
>>> thank you very much the constraint is parsed very well!
>>> but when I try to evaluate it using
>>> ocl.evaluate(helper.getContextClassifier(),parsed);
>>> or ocl.check((helper.getContextClassifier(),parsed) evaluation did not
>>> work
>>> :((
>>> the exeption is "no such property base_Class) but the stereotype Client
>>> has a base_Class property !!!
>>> the value of helper.getcontexteClassifier() is
>>> "org.eclipse.uml2.uml.internal.impl.StereotypeImpl@b1be82 (name: Client,
>>> visibility: <unset>) (isLeaf: false, visibility: public, isAbstract:
>>> false) (isActive: false, isAbstract: false)[OCL] variableExpCS: Variable
>>> Expression: self"
>>>
>>> thank you Christian
>>> "Christian W. Damus" <cdamus@ca.ibm.com> a ?rit dans le message de news:
>>> f41k9l$6lk$1@build.eclipse.org...
>>
>> <snip>
|
|
| |
Goto Forum:
Current Time: Tue Apr 23 17:44:12 GMT 2024
Powered by FUDForum. Page generated in 0.03948 seconds
|