Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » how to use primitiveTypes, OclAny, OclVoid(primitiveTypes, OclAny, OclVoid)
how to use primitiveTypes, OclAny, OclVoid [message #1104114] Sat, 07 September 2013 22:15 Go to next message
Tahar gh is currently offline Tahar ghFriend
Messages: 9
Registered: September 2012
Junior Member
Hi

When trying to realize a transformation from a meta-model PIMM to a meta-model PSMM, I've encoutred two difficulties:

1- how can I include and use primitivetypes in an ATL rule?

2- is there a general type (like Object in UML) that I can use in an ATL rule?


for the first question, I've done as follow :
----------------------


helper def : primitiveTypesPackage : PSMM!Package = OclUndefined;

-- I've created a package of primitivetypes

rule addPrimitiveTypesPackage() {
to
ptPac : PSMM!Package (
name <- 'PrimitiveTypes'
),

stringType : PSMM!PrimitiveType (-- -> (thisModule.primitiveTypesPackage.classifiers)(
name <- 'String'
),
integerType : PSMM!PrimitiveType (-- -> (thisModule.primitiveTypesPackage.classifiers)(
name <- 'Integer'
),
booleanType : PSMM!PrimitiveType (-- -> (thisModule.primitiveTypesPackage.classifiers)(
name <- 'Boolean'
),
commentType : PSMM!PrimitiveType (-- -> (thisModule.primitiveTypesPackage.classifiers)(
name <- 'Real'
),

do {
stringType.package <- thisModule.primitiveTypesPackage;
integerType.package <- thisModule.primitiveTypesPackage;
booleanType.package <- thisModule.primitiveTypesPackage;
commentType.package <- thisModule.primitiveTypesPackage;
}

}


And I've used them like this :

helper def : getPrimitiveType(typeName : String) : PSMM!PrimitiveType = PSMM!PrimitiveType.allInstances()->select(t | t.name=typeName)->first();

rule createProperties() {
to
prop: PSMM!Property(
name <- 'itsGroup',
lower <- 1,
upper <- 1,
visibility <- #public,
type <- thisModule.getPrimitiveType('String')
),

...

}

Is this correct? and how Can I indicate the following pathmaps:

'String' -> 'pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String'
'Integer' -> 'pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer'
'Boolean' -> 'pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Boolean'
'Comment' -> 'pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String'

in order to get in the xmi file representing the target model, an href value for any primitiveType used, for exemple if 'String' is used I'll get : href = 'pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String' in the definition of this type in the xmi file representing the tarhet model


NB: - Is it possible to import primitiveTypes and access to them, rather than creating them? if yes, how?:


- If I want to use OclVoid to indicate that some operation return no thing, the following helper is it correct?

helper def : OclVoid : PSMM!PrimitiveType = OclUndefined;



for the second question, I've done as follow :
-----------------------


rule createProperties() {
to
prop: PSMM!Property(
name <- 'valuesToReturn',
visibility <- #private,
lower <- 0,
upper <- -1,
type <- OclAny
),

...

}

however this is not acceptable and I get this error :
org.eclipse.m2m.atl.engine.emfvm.VMException: java.lang.Class cannot be cast to org.eclipse.uml2.uml.Type

How to affect a general type to a property, to indicate that it can receive any value?

Thank you in advance
Re: how to use primitiveTypes, OclAny, OclVoid [message #1105266 is a reply to message #1104114] Mon, 09 September 2013 15:56 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

Concerning your first question, ATL considers four different primitives types.
Attributes have a primitive type, references are referring to other types defined in your metamodel (i.e., by EClass).

Concerning your second question, it seems that your rule does not have a "from" pattern.
I don't know if your particular error comes from this, but I encourage you to check the structure of ATL matched rules (recommended style in ATL is declarative).

Best regards,


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: how to use primitiveTypes, OclAny, OclVoid [message #1105478 is a reply to message #1105266] Mon, 09 September 2013 23:19 Go to previous messageGo to next message
Tahar gh is currently offline Tahar ghFriend
Messages: 9
Registered: September 2012
Junior Member
Thank you Hugo

I've red the mentioned documents, but I have not found responses.

In this discussion, the source model is PIM and the target model is PSM.

Concerning my first question, my transformation take a PIM model conforms to PIMM and create a PSM model conforms to PSMM. In this transformation I fill, some attributes in PSM from PIM, but I create also other new attributes in PSM which do not exist in PIM! For these last ones (I mean the new created attributes), I need to specify their types. If I do not specify the type of these properties, it will not have their types (in the xmi file) and in the phase of code generation (from the xmi file) I'll not be able to know their types!? So it's important for me to specify the type of all properties in PSM model
To specify types of properties, we distinguish two cases:
- attributes to type with my proper types, this manner is direct and work well
- attributes to type with primitiveTypes, (I think there are two manners to specify theirs types):
* import primitiveType in the PSM model. I think I must choose this manner but I do not know how!. For example, I've used papyrus to graphically import primitiveTypes in the PIM model and with ATL I have integrated them in the PSM, like this:

rule models {
from
modelIn: PIMM!Model
to
modelOut: PSMM!Model (
name <- 'psm_model',
packageImport <- pi
),
pi : PSMM!PackageImport ( -- import the packages existing in PIM into PSM, thus primitivetypes also
importedPackage <- PIMM!PackageImport.allInstancesFrom('IN')->select(e|e.oclIsTypeOf(PIMM!PackageImport))->first()->getImportedPackage()
)

do {
thisModule.addPrimitiveTypesPackage(); -- add primitiveTypes
}
}

By applying this rule, I have obtained in the PSM model all primitiveTypes imported in the PIM. I recall that I've explicitly included primitiveTypes (graphically by Papyrus) in the PIM model, and then I've used ATL to pass them in the PSM model.
A question 1.1: is how to include primitiveTypes in the PSM model directly (I mean without including them in the PIM model, then transferring them by ATL into the PSM model)?
A question 1.2: When I import primitiveTypes into a model, How can I affect them to type of the created properties (I mean type <- ?? what is the syntax). As I have not found response to this question, I've tried the second manner (creating a package for primitiveTypes in the PSM model)

* create a package for primitiveTypes in the PSM model (may be this manner is not correct! but it work nicely, except for one detail)

helper def : primitiveTypesPackage : PSMM!Package = OclUndefined; -- the primitiveTypesPackage is set in the DO section of the "rule addPrimitiveTypesPackage"

rule addPrimitiveTypesPackage() { -- this rule do not contain a FROM section and is called from the DO section of "rule models" (see above)
to
ptPac : PSMM!Package (
name <- 'PrimitiveTypes'
),

stringType : PSMM!PrimitiveType (-- -> (thisModule.primitiveTypesPackage.classifiers)(
name <- 'String'
),
integerType : PSMM!PrimitiveType (-- -> (thisModule.primitiveTypesPackage.classifiers)(
name <- 'Integer'
),
booleanType : PSMM!PrimitiveType (-- -> (thisModule.primitiveTypesPackage.classifiers)(
name <- 'Boolean'
),
commentType : PSMM!PrimitiveType (-- -> (thisModule.primitiveTypesPackage.classifiers)(
name <- 'Real'
),

do {
thisModule.primitiveTypesPackage <- ptPac;
stringType.package <- thisModule.primitiveTypesPackage;
integerType.package <- thisModule.primitiveTypesPackage;
booleanType.package <- thisModule.primitiveTypesPackage;
commentType.package <- thisModule.primitiveTypesPackage;
}

}

and I've defined a helper to specify the desired type for each created property:

helper def : getPrimitiveType(typeName : String) : PSMM!PrimitiveType = PSMM!PrimitiveType.allInstances()->select(t | t.name=typeName)->first();

and I've used it to assign type to some created propreties:

rule createProperties() { -- this rule do not contain a FROM section and is called from the DO section of another rule
to
prop: PSMM!Property(
name <- 'itsGroup',
lower <- 1,
upper <- 1,
visibility <- #public,
type <- thisModule.getPrimitiveType('String')
),

...

}

Concerning my first question, this rule is correct and work nicely (we can define rules without FROM section, as this rule serve to create new properties in the target model from nothing in the source model)
rule createProperties() { -- this rule is called from the DO section off another rule
to

prop: PSMM!Property(

name <- 'valuesToReturn',
visibility <- #private,
lower <- 0,
upper <- -1,
type <- OclAny
),

...
}
Here I want to create a property 'valuesToReturn' which can contain a set of values, each one of a different type; in order to have at the code generation phase a vector of returned values (each one of a different type) of an operation. My question is how to realize this, knowing that with the syntax type <- OclAny I get the following error:
org.eclipse.m2m.atl.engine.emfvm.VMException: java.lang.Class cannot be cast to org.eclipse.uml2.uml.Type

A third question:
- As for properties, if I Create a new operation in PSM (this operation do not exist in the PIM) and I want to use OclVoid to indicate that this operation return nothing, is the following helper correct? If it is not correct, how can I specify in an ATL rule that an operation return void

helper def : OclVoid : PSMM!PrimitiveType = OclUndefined;
I use it like this:

rule createOtherMembersOfTheRole() { -- this rule is called from the DO section of another rule
to

become: PSMM!Operation (
name <- 'become',
visibility <- #public,
interface <- ownerInterfInPSM,
ownedParameter <- Set{}
)

do {

thisModule.createParameterForBecomeOfRole(become);
}
}


rule createParameterForBecomeOfRole(opPSM:PSMM!Operation) { -- this rule is called from the DO section of the "rule createOtherMembersOfTheRole"
to
paramPSMVoid: PSMM!Parameter(
name <- 'return',
direction <- #"return",
type <- thisModule.OclVoid,
lower <- 1,
upper <- 1
)

do {
opPSM.ownedParameter <- opPSM.ownedParameter->including(paramPSMVoid);
}
}

Thank you
Re: how to use primitiveTypes, OclAny, OclVoid [message #1105703 is a reply to message #1105478] Tue, 10 September 2013 07:25 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

Concerning your first error, you cannot do "type <- OclAny" as the type reference is waiting for an element of type "UML!Type".
Thus you have to provide it an element of this type or of a sub-type of this type (or "OclUndefined" if you don't want to set this reference, as you're doing in your second example).

Also, it seems that both your source and target metamodels are actually the same (i.e., UML).
So why don't you use an in-place transformation with the ATL Refining Mode?
This would avoid you having to manually copy all the not modified elements as you currently seem to do.

Best regards,


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: how to use primitiveTypes, OclAny, OclVoid [message #1105719 is a reply to message #1105703] Tue, 10 September 2013 07:45 Go to previous messageGo to next message
Javier García is currently offline Javier GarcíaFriend
Messages: 129
Registered: April 2013
Senior Member
If you're using UML this is what I used to make a property's type void:

type<-UML2!Type.allInstances() -> select(e | e.name = 'void').first();

I also generate code from it later and it works alright, I'm not sure it's the best solution but it works.
Re: how to use primitiveTypes, OclAny, OclVoid [message #1105745 is a reply to message #1105703] Tue, 10 September 2013 08:18 Go to previous messageGo to next message
Tahar gh is currently offline Tahar ghFriend
Messages: 9
Registered: September 2012
Junior Member
Thank you again Hugo

I cannot use atl refining mode for two raisons:
- the two metamodels PIMM(source) and PSMM (target) are entirely different (each one is a different profils, like for example when you make transformation from object Oriented conception to relational DB).
- I'm proposing an MDA approach to develop a kind of applications, so I must keep PIM unchanged and save it for an eventual projection on a futur runtime platform (as PSM can change over the time but not the PIM)

For OclAny I cannot replace it by OclUndefined, because I've used OclUndefined to represent a void type

Re: how to use primitiveTypes, OclAny, OclVoid [message #1105956 is a reply to message #1105745] Tue, 10 September 2013 13:46 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Be careful, a profile is not a metamodel: a profile is actually a model that conforms to the UML metamodel.
Thus, when working on a profiled UML model, you have to pass two UML models as input: the UML profile + the profiled UML model.
The same applies when dealing with profiled UML models as outputs of your transformations.
This is why I was saying that, in your case, the source and target metamodels are the same (i.e., UML).

Concerning the OclAny thing: the objective of an assignment is to assign a value/element to a given attribute/reference.
If you don't want to assign any, thus you can use OclUndefined (equivalent to null).
That's why trying to assign OclAny (that is a type, and not a value nor an element) to your reference cannot work.

Best regards,


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: how to use primitiveTypes, OclAny, OclVoid [message #1106088 is a reply to message #1105956] Tue, 10 September 2013 17:20 Go to previous messageGo to next message
Tahar gh is currently offline Tahar ghFriend
Messages: 9
Registered: September 2012
Junior Member
Thank you again Hugo

Yes it is exactly what I've done : my transformation has as input the PIM model profiled with PIMM and as output the PSM model profiled with PSMM. Each model has the applied profile attached to it in the representation (.uml) of the model.

Okay rather than using OclUndefined to indicate a void type, I'll use it to indicate that a property can take any type. However I must find another thing to indicate a void type! may be the proposal of Javier)

Thank you Javier

I've tried to use your proposal, however I think that you used UML2 as an input or an output metamodel!? which is not my case (Indeed, I've PIMM and PSMM) and thus the compiler of ATL do not recognize UML2 in my transformation!
I've added the line : -- @nsURI UML2=http://www.eclipse.org/uml2/3.0.0/UML
but it still does not recognize it! I will still test your proposal

Can you tell me what you see when you explore the properties' view of a property with a void type? do you see : 'void' or nothing (blank) in the Type cell?

Salutations
Re: how to use primitiveTypes, OclAny, OclVoid [message #1106490 is a reply to message #1106088] Wed, 11 September 2013 06:55 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

You see a blank in the property view's field when there is nothing set for a given attribute/reference.

Best regards,


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: how to use primitiveTypes, OclAny, OclVoid [message #1106580 is a reply to message #1106490] Wed, 11 September 2013 09:24 Go to previous message
Javier García is currently offline Javier GarcíaFriend
Messages: 129
Registered: April 2013
Senior Member
In my case UML2 is both my input and output metamodel so I guess in your case you should try PIMM!Type.AllinstancesFrom('IN') or something like that, assuming that type exists in your metamodel.

[Updated on: Fri, 13 September 2013 07:18]

Report message to a moderator

Previous Topic:Similarity Flooding ATL
Next Topic:Parse ATL transformation with Java
Goto Forum:
  


Current Time: Thu Apr 18 23:13:12 GMT 2024

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

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

Back to the top