Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: DAHLing on November 22, 2012, 01:24:46 am
-
Hi,
We use the interface with java and have now the problem that we don't know how we can get the name or alias from the endpoint of an association. We use the function "Link to element feature."
For example: We have a mask (first name, last name, save button) and for this a business object with first name, last name. The input field from the mask has the association to first name from business object and last name from mask has also an association to last name attribute from business object. Now we want write a script that automatically looks for the business attribute for an input field from a mask. But we have no idea how we have to do it. We tried it with some methods from Connector, but without any successful results....
I hope my description is understandable... ;)
thanks
Markus
-
Each connector has the object id of the connected elements (ClientID and SupplierID). Use these to get according elements via Repository.GetElementByID. There you can retrieve the Attributes collections.
Further I'd recommend my book Scripting EA.
q.
-
Hi qwerty,
thanks for your fast answer.
Unfortunately I don't have much experience in java programming, so I hope you can help me one more time please.
When I try the code below, it seems that "connector" is empty, because there is no output of "Endtarget:".
Is the code not correct or could it be there is something wrong in the model?
void writeTestScript(Repository repository, String gUID)
{
Package eaPackage = null;
eaPackage = repository.GetPackageByGuid(gUID);
Iterator <Connector> connector = eaPackage.GetConnectors().iterator();
while (connector.hasNext()){
Connector conn = connector.next();
String endTarget = repository.GetElementByID(conn.GetSupplierID()).GetName();
System.out.println("Endtarget: "+endTarget);
}
}
Thanks,
Markus
-
Sorry Markus, but my java knowledge is very little. To me the code looks okay. I'd try to put more trace into it. E.g.: Name the connectors of the package in EA and print the names of the connectors. Somethig like
System.out.println("Conn name: "+conn.GetName());
So you see you have the right connectors at all.
q.
-
The problem is that connector seems to be empty and the program will not go into the while-loop.
Should it work for an association and "Link to Element Feature"?
Wir können auch über PM deutsch schreiben, wenn es für Sie okay ist ;)
-
Ah, I see, you are asking for the connector of the package.
You should be iterating the connectors of the elements in the package.
The "link to element feature" associations are also regular associations. There's somewhere one or more topics in this forum that explain how to get the details for the linked feature. (Use the top left search button, and check the search options)
Geert
-
Yes, you are right. Thanks so much!
-
I can not find a topic about how to get the details for the linked feature.
Can you help again please? Sorry... :-/
-
I'd guess this information is deep in EA's guts. Likely it's in the table t_xref. I can't remember having searched for this yet.
q.
[edit] No. It's in the Note's PDATA. PDATA1="ElementNote" (or whatever you used); PDATA2=element-id of object. Its more complicated for linked attributes. For that I did not find the referring element-id.
-
Nope, can't find it either.
I don't really have time now to investigate it myself.
Here's what I would do to figure it out:
Start an empty model, make only two classes, one attribute and one connector and link to that attribute.
The open the database and search each table.
Pay special attention to pdata, style, styleEx columns and the t_xref table.
Then, if you have figured out how things are connected, use Repository.SQLQuery() to execute a query to get the id of the attribute, and use Repository.GetAttributeByID() to get the attribute object.
Geert
-
It's in the connector's StyleEx field. It might contain something like "LFEP=<TargetGUID>R;LFSP=<SourceGUID>L;". Use the GUIDs to look up the linked features in either the attributes table or the operations table.
-
It's in the connector's StyleEx field. It might contain something like "LFEP=<TargetGUID>R;LFSP=<SourceGUID>L;". Use the GUIDs to look up the linked features in either the attributes table or the operations table.
I should have read my own book (page 40) :-X
q.
-
Thanks, I'll check it today.
-
Hi,
thank you all, it works:
void getConnector(Element pElement, Repository repository){
Iterator <Connector> connector = pElement.GetConnectors().iterator();
System.out.println("Element: "+pElement.GetName());
while (connector.hasNext()){
Connector conn = connector.next();
String endTarget = conn.GetStyleEx();
System.out.println("Endtarget: "+repository.GetAttributeByGuid(endTarget.substring(5,43)).GetName());
}
}