Author Topic: Failed creating element with type XSDSimpleType  (Read 4811 times)

Kezia

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Failed creating element with type XSDSimpleType
« 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

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: Failed creating element with type XSDSimpleTyp
« Reply #1 on: May 18, 2009, 08:53:20 am »
You probably need to save your new object (by calling Update) before setting the stereotype.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Failed creating element with type XSDSimpleTyp
« Reply #2 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.
« Last Edit: May 19, 2009, 09:06:40 am by Midnight »
No, you can't have it!

Kezia

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Failed creating element with type XSDSimpleTyp
« Reply #3 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.

RoyC

  • EA Administrator
  • EA Practitioner
  • *****
  • Posts: 1297
  • Karma: +21/-4
  • Read The Help!
    • View Profile
Re: Failed creating element with type XSDSimpleTyp
« Reply #4 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?
« Last Edit: May 25, 2009, 03:18:11 pm by RoyC »
Best Regards, Roy

Neocortex

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
  • &quot;There is no I in Team America&quot;
    • View Profile
Re: Failed creating element with type XSDSimpleTyp
« Reply #5 on: May 25, 2009, 03:35:18 pm »
Hi Kristina,

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

Best,
Neo

« Last Edit: May 25, 2009, 03:36:29 pm by simon.leserve »

Neocortex

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
  • &quot;There is no I in Team America&quot;
    • View Profile
Re: Failed creating element with type XSDSimpleTyp
« Reply #6 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
« Last Edit: May 25, 2009, 03:49:08 pm by simon.leserve »

Kezia

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Failed creating element with type XSDSimpleTyp
« Reply #7 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