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 |
Tahar gh 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 |
Hugo Bruneliere 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 |
Tahar gh 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 |
Hugo Bruneliere 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 #1105956 is a reply to message #1105745] |
Tue, 10 September 2013 13:46 |
Hugo Bruneliere 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
--------------------------------------------------------
|
|
| | | |
Goto Forum:
Current Time: Wed Sep 25 11:45:02 GMT 2024
Powered by FUDForum. Page generated in 0.05073 seconds
|