Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Kezia on May 15, 2009, 05:07:42 pm

Title: Failed creating element with type XSDSimpleType
Post by: Kezia on May 15, 2009, 05:07:42 pm
Hi all,

I created an element with stereotype XSDSimpleType with code below:

Code: [Select]
EA.Element newElement = (EA.Element)this.selectedPackage.Elements.AddNew("myElement3", "Class");
newElement.Stereotype = "XSDSimpleType";
newElement.Type = "string";
newElement.Update();
newElement.Refresh();
 

The code ran successfully and in project browser it showed only the name of element (without stereotype before the name).
when I double-clicked on the newly created element, element's name disappear and then it showed only the stereotype <<XSDSimpleType>> and no property dialog pops up.
And the other weird thing is, when I closed the project, and then opened it again, the element disapper. But by using code, I know the element is there but don't show up.

I have no idea what the problem is. When creating element which is NOT "XSDSimpleType" stereotyped, the code and the result will be ok.

Anyone can help me to figure out what is wrong? or did I miss something in the code?


Cheers,
Kristina
Title: Re: Failed creating element with type XSDSimpleTyp
Post by: Eve on May 18, 2009, 08:53:20 am
You probably need to save your new object (by calling Update) before setting the stereotype.
Title: Re: Failed creating element with type XSDSimpleTyp
Post by: «Midnight» on May 19, 2009, 09:04:43 am
(I think) You can sometimes set a stereotype before you call Update(), but what Simon suggests is good EA programming practice.

The call to Refresh() looks odd. You should only refresh collections, not individual elements.

Update() is actually a function that returns a Boolean result; a return value of true indicates that the Update() was successful. It might be worth testing the result of this call. If false is returned you can use other calls--check the documentation--to learn more about the error.
Title: Re: Failed creating element with type XSDSimpleTyp
Post by: Kezia on May 25, 2009, 02:09:18 pm
Unfortunately, your suggestion doesn't work.
- I've tried to Update() the new element before setting stereoype.  
- Ok, the Refresh() method looks odd, I've removed it.
- Both Update() method were successful, it returned true.
But the error symptom is still the same..

Code: [Select]
EA.Element newElement = (EA.Element)this.selectedPackage.Elements.AddNew("myElement4", "Class");
bool x = newElement.Update();
newElement.Stereotype = "XSDSimpleType";
newElement.Type = "string";
bool y = newElement.Update();

Unfortunately again, I can't find any documentation on EA Help related to setting XSDSimpleType stereotype on an element.
Title: Re: Failed creating element with type XSDSimpleTyp
Post by: RoyC on May 25, 2009, 03:00:41 pm
Does this page help you at all? XSDsimpleType is the third option in the list, and the third table in the topic.

http://www.sparxsystems.com/uml_tool_guide/xml_technologies/uml_profile_for_xsd.html

Perhaps also check whether case sensitivity is a problem - in your call, Simple should be simple?
Title: Re: Failed creating element with type XSDSimpleTyp
Post by: Neocortex on May 25, 2009, 03:35:18 pm
Hi Kristina,

Remove the line (newElement.Type = "string")

Best,
Neo

Title: Re: Failed creating element with type XSDSimpleTyp
Post by: Neocortex on May 25, 2009, 03:45:12 pm
Hi Kristina,

Also include the line:

newElement.Genlinks = "Parent=String;"


so the final code would be

            EA.Element newElement = (EA.Element)repository.GetTreeSelectedPackage().Elements.AddNew("myElement3", "Class");
            newElement.Stereotype = "XSDSimpleType";
            newElement.Genlinks = "Parent=string;";
            newElement.Update();


Best,
Neo
Title: Re: Failed creating element with type XSDSimpleTyp
Post by: Kezia on May 25, 2009, 05:18:55 pm
Hi Neo..
Perfect..!!  ;D
I guess the "Parent=string" is for setting the type of XSDSimpleType..
Thank you very much for your help !! :)


== Finally I got the answer ==
Kristina