Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Stephane B on May 06, 2013, 08:05:54 pm
-
How are the operation parameter types handled by EA ?
I'm writing model transformation templates and I'd like to have :
myOperation(param1:myClass1)
transformed into
myTransformedOperation(param1:myTransformedClass1)
Problem is, I can't figure out how to get a handle on the param type. There doesn't seem to be a connector involved.
As far as I know, the param type is just described as
Parameter {
...
type="myTransformedClass1"
...
}
in the Intermediary Language.
If I generate my transformed model like this, I can then check in the UI to understand what happens :
EA seems to be looking for a class named myTransformedClass1 anywhere in the project (goes upward in the model tree and stops at the first one it finds named accordingly).
How can I define precisely the parameter type, so as to have EA to point to the right class ? Is there a hidden Connector or a Classifier ?
Thanks in advance.
Stéphane
-
Stéphane,
Normally (=>if you have selected the type of the parameter and not just typed in something) there is a hard link between the parameter and the type.
I don't know anything about transformation templates, but I can show how it's implemented in my EA Add-in Framework (https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework).
From the ParameterWrapper.cs (https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/EAWrappers/ParameterWrapper.cs)
public override UML.Classes.Kernel.Type type {
get {
// for some strange reason the classifierid of the parameter is a
// string, where all other id the the EA API are integers.
int ClassifierID;
UML.Classes.Kernel.Type type = null;
if (int.TryParse(this.wrappedParameter.ClassifierID,out ClassifierID))
{
type = this.model.getElementWrapperByID(ClassifierID) as UML.Classes.Kernel.Type;
}
// check if the type is defined as an element in the model.
if( type == null ) {
// no element, create primitive type based on the name of the type
type = this.model.factory.createPrimitiveType
( this.wrappedParameter.Type );
}
return type;
}
set { throw new NotImplementedException(); }
}
Geert
-
Ok, thanks Geert,
Don't know yet if that'll help. I have to let it mature a bit ;-)
Indeed I was pretty sure that there was a hard link. It seems to be a Classifier.
In my template maybe it'll go like this :
Operation {
name = "myTransformedOperation"
Parameter {
name = "param1"
type = "myTransformedClass1"
Classifier {
namespace="<the transformation that gave myTransformedClass1>"
name="<the template that gave myTransformedClass1>"
source="<someGUID...don't have a clue>"
}
}
}
Anyone knowing if I'm getting close ?
Stephane
-
Seems to work with :
source=%qt%%paramClassifierGUID%%qt%
Now let's get a handle on the return type !
-
Now for the full answer :
Operation {
name = "myTransformedOperation"
type = "MyTransformedReturnType"
Classifier {
namespace="<the transformation that gave MyTransformedReturnType>"
name="<the template that gave MyTransformedReturnType>"
source=%qt%%opReturnClassifierGUID%%qt%
}
Parameter {
name = "param1"
type = "MyTransformedClass1"
Classifier {
namespace="<the transformation that gave MyTransformedClass1>"
name="<the template that gave MyTransformedClass1>"
source=%qt%%paramClassifierGUID%%qt%
}
}
}