Author Topic: How should Association Classes appear in an XSD?  (Read 2195 times)

AndyJ

  • EA User
  • **
  • Posts: 332
  • Karma: +5/-2
  • It's only a model
    • View Profile
How should Association Classes appear in an XSD?
« 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>

« Last Edit: February 10, 2015, 03:24:27 pm by novaphile »
Sun Tzu: "If you sit by the river long enough, eventually the body of MS Visio floats past."

Simon M

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 6354
  • Karma: +54/-5
    • View Profile
Re: How should Association Classes appear in an XS
« Reply #1 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.
Simon

support@sparxsystems.com

AndyJ

  • EA User
  • **
  • Posts: 332
  • Karma: +5/-2
  • It's only a model
    • View Profile
Re: How should Association Classes appear in an XS
« Reply #2 on: February 10, 2015, 04:46:47 pm »
Thanks Simon.

I'm off to confer with the Dev.
Sun Tzu: "If you sit by the river long enough, eventually the body of MS Visio floats past."

qwerty

  • EA Guru
  • *****
  • Posts: 9432
  • Karma: +150/-138
  • I'm no guru at all
    • View Profile
Re: How should Association Classes appear in an XS
« Reply #3 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.

AndyJ

  • EA User
  • **
  • Posts: 332
  • Karma: +5/-2
  • It's only a model
    • View Profile
Re: How should Association Classes appear in an XS
« Reply #4 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
Sun Tzu: "If you sit by the river long enough, eventually the body of MS Visio floats past."

MMA

  • EA User
  • **
  • Posts: 63
  • Karma: +3/-0
    • View Profile
Re: How should Association Classes appear in an XS
« Reply #5 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.
« Last Edit: February 11, 2015, 09:01:22 am by milesma »

AndyJ

  • EA User
  • **
  • Posts: 332
  • Karma: +5/-2
  • It's only a model
    • View Profile
Re: How should Association Classes appear in an XS
« Reply #6 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.

 :)
Sun Tzu: "If you sit by the river long enough, eventually the body of MS Visio floats past."

RubenK

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: How should Association Classes appear in an XSD?
« Reply #7 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.

AndyJ

  • EA User
  • **
  • Posts: 332
  • Karma: +5/-2
  • It's only a model
    • View Profile
Re: How should Association Classes appear in an XSD?
« Reply #8 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.

 :-[
Sun Tzu: "If you sit by the river long enough, eventually the body of MS Visio floats past."