Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Property derivation using If then else
Property derivation using If then else [message #665409] Thu, 14 April 2011 14:40 Go to next message
zineek  is currently offline zineek Friend
Messages: 4
Registered: April 2011
Junior Member
Hello,

I have a question about MDT/OCL3.0.0.

I am bothered by the if-then-else when I want to create a derivation for one of the class property.
In reality, I don't want to do anything in the else case.

This was my try:

class DataTask
{
property dataSubprocess : DataSubProcess[?];
property inputSets#dataTask : InputSet[*] { composes }
{
derivation:
-- no inputSet for DataInput task
if self.taskType = TaskType::DataInput then OrderedSet{null}
else OrderedSet{InputSet}
endif;
}

property outputSets#dataTask : OutputSet[*] { composes };
attribute taskType : TaskType[?];
property dataEvents : DataEvent[*] { composes };
property dataProcess : DataProcess[1];
attribute name : String[?];
}


When I create an instance of my DataTask class, I get this strange error !!
An error has occurred. See error log for more details.
Initial or derived value expression type (OrderedSet(InputSet)) does not conform to property "inputSets" type (OrderedSet(InputSet))

Have you any idea ?

Many thanks

Zineek
Re: Property derivation using If then else [message #665446 is a reply to message #665409] Thu, 14 April 2011 16:02 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

OCL is not an imperative language; you have to provide a value on each
path; if you don't want to do anything because it cannot happen you can
use invalid.

OrderedSet{InputSet} is a singleton colletion of the InputSet type,
whereas inputSets is a collection of InputSet values.

Do you mean to do enumeration testing. Perhaps oclIsKindOf woyld be better.

Regards

Ed Willink


On 14/04/2011 15:40, zineek wrote:
> Hello,
>
> I have a question about MDT/OCL3.0.0.
> I am bothered by the if-then-else when I want to create a derivation
> for one of the class property.
> In reality, I don't want to do anything in the else case.
>
> This was my try:
>
> class DataTask
> {
> property dataSubprocess : DataSubProcess[?];
> property inputSets#dataTask : InputSet[*] { composes }
> {
> derivation:
> -- no inputSet for DataInput task
> if self.taskType = TaskType::DataInput then OrderedSet{null}
> else OrderedSet{InputSet}
> endif;
> } property outputSets#dataTask : OutputSet[*] { composes };
> attribute taskType : TaskType[?];
> property dataEvents : DataEvent[*] { composes };
> property dataProcess : DataProcess[1];
> attribute name : String[?];
> }
>
>
> When I create an instance of my DataTask class, I get this strange
> error !!
> An error has occurred. See error log for more details.
> Initial or derived value expression type (OrderedSet(InputSet)) does
> not conform to property "inputSets" type (OrderedSet(InputSet))
>
> Have you any idea ?
>
> Many thanks
>
> Zineek
Re: Property derivation using If then else [message #665453 is a reply to message #665446] Thu, 14 April 2011 16:34 Go to previous messageGo to next message
zineek  is currently offline zineek Friend
Messages: 4
Registered: April 2011
Junior Member
Thanks Edward for your quick reply.

Edward Willink wrote on Thu, 14 April 2011 12:02
Hi

OCL is not an imperative language; you have to provide a value on each
path; if you don't want to do anything because it cannot happen you can
use invalid.



Yes, this may happen, and I want in this case to let the definition of inputSets later to the user.

Edward Willink wrote on Thu, 14 April 2011 12:02

OrderedSet{InputSet} is a singleton colletion of the InputSet type,
whereas inputSets is a collection of InputSet values.


Ok, but how can I create a OrderedSet of many inputSets?

Edward Willink wrote on Thu, 14 April 2011 12:02

Do you mean to do enumeration testing. Perhaps oclIsKindOf woyld be better.



Ok I'll change this. But even like this, it is working.

Thanks a lot

Zineek


Re: Property derivation using If then else [message #665475 is a reply to message #665453] Thu, 14 April 2011 17:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi
> Ok, but how can I create a OrderedSet of many inputSets?
>
???? manyInputSets->asOrderedSet() ????

Regards

Ed Willink
Re: Property derivation using If then else [message #665577 is a reply to message #665475] Fri, 15 April 2011 07:20 Go to previous messageGo to next message
zineek  is currently offline zineek Friend
Messages: 4
Registered: April 2011
Junior Member
Thank you Ed again for your quick reply.

As I am investigating the MDT/OCL3 project, I've tried now to make a derivation of a reference property; For each particular case, I have to retype my property to a specific type.

These types are subclasses of the property class.

Here is my code, which generates a java.lang.StackOverflowError

class Expression
{
attribute name : String[?];
property parameterSet#expression : ParameterSet[?] { composes }
{
derivation:
if (self.outputSet.dataTask.taskType = TaskType::VariableDerivation)
then parameterSet.oclAsType(VDParameters)
-- name = 'VariableDerivationExpression'
else if (self.outputSet.dataTask.taskType = TaskType::VariablGeneration)
then parameterSet.oclAsType(VGParameters)
else parameterSet.oclAsType(ParameterSet)
endif
endif;
}

}

VDParameters and VGParameters are subclasses of ParameterSet.

Is this type of constraints allowed by MDT/OCL3?

Thanks in advance,

Zineek
Re: Property derivation using If then else [message #665617 is a reply to message #665577] Fri, 15 April 2011 09:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Should be ok.

The Helios editor only does syntax checking.
The Indigo editor provides semantic checking and hover context.

Your structure is a bit odd; the derivation is castiong to a nrrow type
that gets broadened again on usage.

It might be more senbsible to have invariants:

invariant VariableDerivationIsVGParameters:
outputSet.dataTask.taskType = TaskType::VariableDerivation implies
parameterSet.oclIsKindOf(VDParameters);
invariant VariableGenerationIsParameterSet:
outputSet.dataTask.taskType = TaskType::VariableGeneration implies
parameterSet.oclIsKindOf(ParameterSet);

so that you don't need a derivation at all.

Regards

Ed Willink


On 15/04/2011 08:20, zineek wrote:
> Thank you Ed again for your quick reply.
>
> As I am investigating the MDT/OCL3 project, I've tried now to make a
> derivation of a reference property; For each particular case, I have
> to retype my property to a specific type.
>
> These types are subclasses of the property class.
> Here is my code, which generates a java.lang.StackOverflowError
>
> class Expression
> {
> attribute name : String[?];
> property parameterSet#expression : ParameterSet[?] { composes }
> {
> derivation: if
> (self.outputSet.dataTask.taskType = TaskType::VariableDerivation)
> then parameterSet.oclAsType(VDParameters)
> -- name = 'VariableDerivationExpression'
> else if (self.outputSet.dataTask.taskType =
> TaskType::VariablGeneration) then
> parameterSet.oclAsType(VGParameters)
> else parameterSet.oclAsType(ParameterSet)
> endif
> endif;
> }
> }
>
> VDParameters and VGParameters are subclasses of ParameterSet.
>
> Is this type of constraints allowed by MDT/OCL3?
>
> Thanks in advance,
>
> Zineek
Re: Property derivation using If then else [message #665916 is a reply to message #665617] Mon, 18 April 2011 07:24 Go to previous message
zineek  is currently offline zineek Friend
Messages: 4
Registered: April 2011
Junior Member
That was very helpfull.

At the end, I am trying in my examples to apply dynamic validations during the creation of models, by using the OCL constraints on the metamodel.

This does not seem to be the best way to do it.

Many thanks

Zineek
Previous Topic:[Complete OCL] Change OCL file for validation per editor instance?
Next Topic:Unresolved operation '<' for 'Ecore::ecore::EInt' (double entry: no text)
Goto Forum:
  


Current Time: Sat Apr 20 03:58:19 GMT 2024

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

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

Back to the top