Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: AndyJ on February 10, 2015, 03:13:34 pm

Title: How should Association Classes appear in an XSD?
Post by: AndyJ on February 10, 2015, 03:13:34 pm
One of my developers, has just generated an XSD from a class diagram.

He's scratching his head about association classes.  Associations are being rendered, but association classes are appearing as classes, with no relationship to any other class.

Is this working as intended?

Here's an example from a simple class diagram:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="Class1" type="Class1"/>
      <xs:complexType name="Class1">
            <xs:sequence>
                  <xs:element name="Class2" type="Class2" minOccurs="1" maxOccurs="1"/>
            </xs:sequence>
      </xs:complexType>
      <xs:element name="Class2" type="Class2"/>
      <xs:complexType name="Class2">
            <xs:sequence/>
      </xs:complexType>
      <xs:element name="Freddo" type="Freddo"/>
      <xs:complexType name="Freddo">
            <xs:sequence>
                  <xs:element name="chocolate" type="xs:int" minOccurs="1" maxOccurs="1"/>
            </xs:sequence>
      </xs:complexType>
      <xs:element name="Class3" type="Class3"/>
      <xs:complexType name="Class3">
            <xs:sequence/>
      </xs:complexType>
      <xs:element name="Class4" type="Class4"/>
      <xs:complexType name="Class4">
            <xs:sequence>
                  <xs:element name="Class3" type="Class3" minOccurs="1" maxOccurs="1"/>
            </xs:sequence>
      </xs:complexType>
</xs:schema>

(http://i932.photobucket.com/albums/ad164/AndyJ4Sparx/association%20class_zps1iu471ni.png)
Title: Re: How should Association Classes appear in an XS
Post by: Eve on February 10, 2015, 04:00:20 pm
I don't think I've ever seen this question relating to XSD, but I've seen it frequently relating to code engineering.

What you're seeing is that the XSD generation is completely disregarding that this is an association class. ie. Send in a Feature Request for handling of association classes in XSD generation if it's really important to you. Code engineering and transforms used to be the same. I can't remember to what extent that has changed.

I could probably answer your question from a theoretical point of view, it's probably more helpful to give the advice not to use them when modeling xsd.
Title: Re: How should Association Classes appear in an XS
Post by: AndyJ on February 10, 2015, 04:46:47 pm
Thanks Simon.

I'm off to confer with the Dev.
Title: Re: How should Association Classes appear in an XS
Post by: qwerty on February 10, 2015, 08:49:11 pm
Unfortunately XSD and UML do not have a 1:1 mapping. Therefore you need to obey a couple of constraints. There are some papers out there talking about those limits. Probably you hit one of them here.

q.
Title: Re: How should Association Classes appear in an XS
Post by: AndyJ on February 11, 2015, 08:06:34 am
We were expecting the classes to be present (they are)

And associations to be present between the association class, and each of the associated classes... (this part didn't happen).

I suspect that Simon is on the money here, the XSD generator just didn't notice (i.e. probably isn't checking) that a class is an association class.

Andy
Title: Re: How should Association Classes appear in an XS
Post by: MMA on February 11, 2015, 09:00:26 am
IMHO, that depends on who owns the association ends: the class or the association(association class is association with extra attributes).
for example, if one is class-owned, one is association-owned, the expected XSD might look like this:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xs:element name="Class1" type="Class1"/>
     <xs:complexType name="Class1">
           <xs:sequence>                        
                <xs:element name="Class2EndName" type="Class2" minOccurs="1" maxOccurs="1"/>
           </xs:sequence>
     </xs:complexType>
     <xs:element name="Class2" type="Class2"/>
     <xs:complexType name="Class2">
           <xs:sequence/>
     </xs:complexType>
     <xs:element name="Freddo" type="Freddo"/>
     <xs:complexType name="Freddo">
           <xs:sequence>
                 <xs:element name="chocolate" type="xs:int" minOccurs="1" maxOccurs="1"/>
                 <xs:element name="class1EndName" type="Class1" minOccurs="1" maxOccurs="1"/>
           </xs:sequence>
     </xs:complexType>  
</xs:schema>

In this example, you might need to put a dot at the end of Class2, however, explicit end-ownership notation is not mandatory.
Title: Re: How should Association Classes appear in an XS
Post by: AndyJ on February 11, 2015, 09:20:48 am
The developers have put their heads together and have come to the conclusion that they'd like this to work.

Feature request coming up.

 :)
Title: Re: How should Association Classes appear in an XSD?
Post by: RubenK on March 21, 2017, 06:56:09 pm
Hi Andy,

Did something happened with your feature request? Or do you have a workaround?

We are now facing the same issue.
Title: Re: How should Association Classes appear in an XSD?
Post by: AndyJ on March 28, 2017, 11:08:52 am
I've had a look around here, and I can't find any evidence that the Feature Request was created...

It's quite likely that I was dragged off onto something else.

 :-[