it's going to be a long post, thank you for readying :-) This question is from a one level up "view" from this post:
Storing meta information to class properties
We have a XSD from which we are going to generate classes from (C#/Java). So the problem is split into two different parts: Define it in the XSD, then create the datamodel from it.
We want to have some elements in a complex type to carry meta information, but just in certain x-paths in the XSD. That means that when a type is reused as a element in another complex type we want to tell the user whether it is "relevant" for something (I called it security relevant in my other post). The relevance is denoted in several levels. (That explanation also applies for the datamodel in C#/Java ofcourse)
XSD Type Example:
<xs:complexType name="Core">
<xs:sequence>
<xs:element name="No" type="xs:int" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ComplexA">
<xs:sequence>
<xs:element name="Info" type="Core" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ComplexB">
<xs:sequence>
<xs:element name="Info" type="Core" />
</xs:sequence>
</xs:complexType>
The Core type has a property "No". This property can be relevant in other types. For example, it is supposed to be "relevant-level-1" in type ComplexA.Info
, in ComplexB.Info it's not.
We came up with two different ways to achieve this:
1: Introduce a attribute on type level:
<xs:complexType name="ComplexA">
<xs:sequence>
<xs:element name="Info" type="Core" />
</xs:sequence>
<xs:attribute name="Relevance.Info.No" type="RelevanceType" fixed="Relevance1"/>
</xs:complexType>
<xs:simpleType name="RelevanceType">
<xs:restriction base="xs:string">
<xs:enumeration value="Relevance1" />
<!-- Some more relevance values -->
</xs:restriction>
</xs:simpleType>
The attribute "Relevance.Info.No" basically tells that the property "No" in the member "Info" has the relevance type "Relevance1". This approach has obviously some drawbacks. The class generation is very complicated since we would have to manually process this attribute information. A solution for that is posted in the thread mentioned in the beginning.
2: Introduce another complex type for every property with a relevance level:
This will solve the way this "meta data" is attached to the properties, but will apperently produces a lot classes on XSD and C#/Java for every combination of relevance level within a type.
As you can imagine the problems for the creation of the datamodel on C# and Java side are very similar to the problems within the XSD. The best way would be to have XSD ready to automatically create the java classes (JaxB) and C# classes (XGen) without any other manipulation of the generated code (which I'm doing right now).
Do you see any other possibilities to achieve that?
Any help is appreciated!