Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » evaluates to invalid class
evaluates to invalid class [message #65667] Thu, 08 January 2009 19:51 Go to next message
Eclipse User
Originally posted by: jgreen.upb.de

Hi,
can anyone explain to me when an expression is evaluated to the dynamic object that is instance of the "Invalid_Class"?

Similar to the "Defining Global Variables" guide, I supply number of variables and their bindings to an environment.
Then I want to evaluate a query as for example

employee.company.name

"employee" in this case would be a variable that I supply a binding for beforehand. In the model, each employee is
associated with a company that has a name attribute. Thus, I'd expect my code below to give me the company's name value
as the result.

OCLExpression<EClassifier> expr = helper.createQuery("employee.company.name");
Query<EClassifier, EClass, EObject> eval = ocl.createQuery(expr);
Object result = eval.evaluate();

Any idea where the problem is or how I could approach it?

Thanks for helping

Joel
Re: evaluates to invalid class [message #65692 is a reply to message #65667] Thu, 08 January 2009 20:34 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.zeligsoft.com

Hi, Joel,

This evaluation result is the special token that used to be called
"OclInvalid" and then was renamed by OMG to "invalid" but which the MDT
implementation still calls "OclInvalid" (it being, then, an instance of
a type named "Invalid" which according to OMG should actually by
"OclInvalid").

Clear? ;-)

In any case, this value signals an evaluation failure (its type conforms
to all other types, like the type of null (OclVOid), which is another
problem of its own).

I don't see where, in your code snippet, you are binding a value to the
"employee" variable. For that matter, I don't see where you define the
variable. So, I can only guess that the problem is that, at evaluation
time, the "employee" variable either is unbound (resulting in an
IllegalArgumentException, surfaced as OclInvalid) or is null (resulting
also in OclInvalid, because OCL says that this is what you get when
attempting to access model features on the null object).

The likely cause is that the environment in which you defined these
variables is not the same as the environment in which you evaluated the
expression. The Query object has its own evaluation environment,
distinct from the evaluation environment of the OCL instance that
created it. So, either configure its evaluation environment, or
dispense with the Query and just use the OCL::evaluate(...) method.

HTH,

Christian


Joel Greenyer wrote:
> Hi,
> can anyone explain to me when an expression is evaluated to the dynamic
> object that is instance of the "Invalid_Class"?
>
> Similar to the "Defining Global Variables" guide, I supply number of
> variables and their bindings to an environment. Then I want to evaluate
> a query as for example
>
> employee.company.name
>
> "employee" in this case would be a variable that I supply a binding for
> beforehand. In the model, each employee is associated with a company
> that has a name attribute. Thus, I'd expect my code below to give me the
> company's name value as the result.
>
> OCLExpression<EClassifier> expr =
> helper.createQuery("employee.company.name");
> Query<EClassifier, EClass, EObject> eval = ocl.createQuery(expr);
> Object result = eval.evaluate();
>
> Any idea where the problem is or how I could approach it?
>
> Thanks for helping
>
> Joel
Re: evaluates to invalid class [message #65714 is a reply to message #65692] Fri, 09 January 2009 10:20 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------060502000207000208030004
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Hi Christian,

I'm sorry to barge in and "fork" this conversation, I'd like to use this
occasion though :).

In MTL, it happens for an evaluation to fail. As we generate text, we
almost always generate the String representation of that OclInvalid
Object. My question is : is there a way to have OCL log the error that
triggered this Object to be returned, or a way to programmatically
access the root exception?

Regards,

Laurent Goubet
Obeo

Christian W. Damus a
Re: evaluates to invalid class [message #65736 is a reply to message #65692] Fri, 09 January 2009 11:44 Go to previous messageGo to next message
Eclipse User
Originally posted by: jgreen.upb.de

Christian W. Damus wrote:
> Hi, Joel,
>
> This evaluation result is the special token that used to be called
> "OclInvalid" and then was renamed by OMG to "invalid" but which the MDT
> implementation still calls "OclInvalid" (it being, then, an instance of
> a type named "Invalid" which according to OMG should actually by
> "OclInvalid").
>
> Clear? ;-)
>
> In any case, this value signals an evaluation failure (its type conforms
> to all other types, like the type of null (OclVOid), which is another
> problem of its own).
>
> I don't see where, in your code snippet, you are binding a value to the
> "employee" variable. For that matter, I don't see where you define the
> variable. So, I can only guess that the problem is that, at evaluation
> time, the "employee" variable either is unbound (resulting in an
> IllegalArgumentException, surfaced as OclInvalid) or is null (resulting
> also in OclInvalid, because OCL says that this is what you get when
> attempting to access model features on the null object).
>
> The likely cause is that the environment in which you defined these
> variables is not the same as the environment in which you evaluated the
> expression. The Query object has its own evaluation environment,
> distinct from the evaluation environment of the OCL instance that
> created it. So, either configure its evaluation environment, or
> dispense with the Query and just use the OCL::evaluate(...) method.

Hi Christian,
that works! I am now doing the following:

OCLExpression<EClassifier> expr = helper.createQuery(myExpression);
Object evalresult = ocl.evaluate(null, expr);

Is it really okay to put null here?

Thanks

Joel


>
> HTH,
>
> Christian
>
>
> Joel Greenyer wrote:
>> Hi,
>> can anyone explain to me when an expression is evaluated to the
>> dynamic object that is instance of the "Invalid_Class"?
>>
>> Similar to the "Defining Global Variables" guide, I supply number of
>> variables and their bindings to an environment. Then I want to
>> evaluate a query as for example
>>
>> employee.company.name
>>
>> "employee" in this case would be a variable that I supply a binding
>> for beforehand. In the model, each employee is associated with a
>> company that has a name attribute. Thus, I'd expect my code below to
>> give me the company's name value as the result.
>>
>> OCLExpression<EClassifier> expr =
>> helper.createQuery("employee.company.name");
>> Query<EClassifier, EClass, EObject> eval = ocl.createQuery(expr);
>> Object result = eval.evaluate();
>>
>> Any idea where the problem is or how I could approach it?
>>
>> Thanks for helping
>>
>> Joel
Re: evaluates to invalid class [message #65757 is a reply to message #65736] Fri, 09 January 2009 19:33 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.zeligsoft.com

Joel Greenyer wrote:

----8<-----

> Hi Christian,
> that works! I am now doing the following:
>
> OCLExpression<EClassifier> expr = helper.createQuery(myExpression);
> Object evalresult = ocl.evaluate(null, expr);

Great!


> Is it really okay to put null here?

Absolutely. null is the sole instance of OclVoid, which conforms to all
other types. So, it can be used as the context element of any
constraint/expression evaluation.

So long, of course, as your expression doesn't need any of the
properties of the context element, as in your case.

cW


>
> Thanks
>
> Joel
>

----->8-----
Re: evaluates to invalid class [message #65777 is a reply to message #65714] Fri, 09 January 2009 19:36 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.zeligsoft.com

Hi, Laurent,

See some comments in-line, below.

Cheers,

Christian


laurent Goubet wrote:
> Hi Christian,
>
> I'm sorry to barge in and "fork" this conversation, I'd like to use this
> occasion though :).

Nah -- why should I mind? You're always welcome.


> In MTL, it happens for an evaluation to fail. As we generate text, we
> almost always generate the String representation of that OclInvalid

Useful, ain't it? ;-)


> Object. My question is : is there a way to have OCL log the error that
> triggered this Object to be returned, or a way to programmatically
> access the root exception?

That would be a useful enhancement to add. Care to contribute? :-P


> Regards,
>
> Laurent Goubet
> Obeo

-----8<-----
Re: evaluates to invalid class [message #65797 is a reply to message #65777] Mon, 12 January 2009 08:46 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------060308070504040709070201
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Hi Christian,

Well at least this answers my question : there currently is no way to
have OCL return us the root exception ^^.

I'll most likely have to add something like this in OCL, and have no
problem contributing if needed. Since I'd rather not re-implement the
whole EvaluationVisitor, the main question is : what would be the best
approach for this? Adding a reference "cause" to the OCLInvalid Object
would allow me to attach the exception to it (or so I think, with
"cause" being of type "EJavaObject"). You might already have something I
could use to store this exception though (a log in one of the visitors,
a shared context, ...)?

Laurent Goubet
Obeo

Christian W. Damus a
Re: evaluates to invalid class [message #65818 is a reply to message #65797] Mon, 12 January 2009 09:02 Go to previous message
Eclipse User
Originally posted by: cdamus.zeligsoft.com

Hi, Laurent,

The OclInvalid is specified as a singleton, so attaching anything to it
might be problematic.

My preferred approach would be to add a "problems : Diagnostic" property
to the EvaluationVisitor API, mirroring what is done in the OCL class
for reporting parsing problems. Probably this needs an optional
extension interface for compatibility, as we cannot add to the existing
EvaluationVisitor. Definitely the default visitor implementation can
add this property.

Then, the trick is to make this diagnostic accessible after the
evaluation ... perhaps through the OCLUtil as is done for parsing
problems? e.g., OCLUtil::getProblems(Query) for evaluation via query
objects, and OCLUtil::getEvaluationProblems(OCL) for evaluation via the
OCL object. I suppse the latter wouldn't be necessary, as OCL is a
class, so it could add "evaluationProblems : Diagnostic" property.

Cheers,

Christian

laurent Goubet wrote:
> Hi Christian,
>
> Well at least this answers my question : there currently is no way to
> have OCL return us the root exception ^^.
>
> I'll most likely have to add something like this in OCL, and have no
> problem contributing if needed. Since I'd rather not re-implement the
> whole EvaluationVisitor, the main question is : what would be the best
> approach for this? Adding a reference "cause" to the OCLInvalid Object
> would allow me to attach the exception to it (or so I think, with
> "cause" being of type "EJavaObject"). You might already have something I
> could use to store this exception though (a log in one of the visitors,
> a shared context, ...)?
>
> Laurent Goubet
> Obeo
>
> Christian W. Damus a écrit :
>> Hi, Laurent,
>>
>> See some comments in-line, below.
>>
>> Cheers,
>>
>> Christian
>>
>>
>> laurent Goubet wrote:
>>> Hi Christian,
>>>
>>> I'm sorry to barge in and "fork" this conversation, I'd like to use
>>> this occasion though :).
>>
>> Nah -- why should I mind? You're always welcome.
>>
>>
>>> In MTL, it happens for an evaluation to fail. As we generate text, we
>>> almost always generate the String representation of that OclInvalid
>>
>> Useful, ain't it? ;-)
>>
>>
>>> Object. My question is : is there a way to have OCL log the error
>>> that triggered this Object to be returned, or a way to
>>> programmatically access the root exception?
>>
>> That would be a useful enhancement to add. Care to contribute? :-P
>>
>>
>>> Regards,
>>>
>>> Laurent Goubet
>>> Obeo
>>
>> -----8<-----
>
Previous Topic:[Announce] MDT OCL 1.2.3 M200901070919 is available
Next Topic:[Announce] MDT OCL 1.3.0 I200901131906 is available
Goto Forum:
  


Current Time: Thu Aug 28 21:39:15 EDT 2014

Powered by FUDForum. Page generated in 0.09702 seconds