I have a XSD that defined various complex types, which contains another complex type. The issue is that the inner complex type are exactly the same, but they are not defined as separated type, and therefore I have an inner classes for each top level class. The XSD is as follows:
<xs:complexType name="DOCTRACKTCSCREATEType">
<xs:sequence>
<xs:element name="DESCRIPTION" type="xs:string" minOccurs="0"/>
<xs:element name="gATTRIBNAME" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="mATTRIBNAME" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="ATTRIBNAME" type="xs:string" minOccurs="0"/>
<xs:element name="ATTRIBVALUE" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="m" type="xs:positiveInteger"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="g" type="xs:positiveInteger"/>
</xs:complexType>
</xs:element>
<xs:attribute name="id" type="xs:string"/>
</xs:complexType>
<xs:complexType name="DOCTRACKType">
<xs:sequence>
<xs:element name="REFERENCE" type="xs:string" minOccurs="0"/>
<xs:element name="gATTRIBNAME" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="mATTRIBNAME" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="ATTRIBNAME" type="xs:string" minOccurs="0"/>
<xs:element name="ATTRIBVALUE" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="m" type="xs:positiveInteger"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="g" type="xs:positiveInteger"/>
</xs:complexType>
</xs:element>
<xs:attribute name="id" type="xs:string"/>
</xs:complexType>
So both define an identical type gATTRIBNAME. I cannot change the XSD, but is there any other way I can have them create the same java class?
It seems that JAXB makes this difficult, presumably because it considers the two anonymous complex types different and really doesn't want to let you map them to the same class, even with customized bindings.
Maybe you'd want to try something like having them both implement a common interface? Last I checked, this was only possible through various extensions and plugins, (but some of these are in the RI itself so availability shouldn't be an issue). Here's an older post for example, and you might find more recent ones.
If you do try to proceed with customized bindings, somehow, one other related thought.. you might find the setting
<jxb:globalBindings localScoping="toplevel"/> useful for generating top-level rather than inner classes. This opens up some other possibilities for collisions, so possibly not..but FYI.
Hope that helps.. would be interested to hear a better answer.
Related
In the Data.Word module, it provides types like Word8, Word16, etc.
Is there a way to implement my own Word type, such as Word4 (efficiently)?
SBV package has an example for it: Data.SBV.Examples.Misc.Word4.
In java and c# we have interfaces, what is the equivalent to that in a language like haskell or what is the concept called in functional programming?
There are things like typeclasses, as the other answers say, but even more than that, there's one pervasive interface: a function. Many, many places where an object-oriented program would need some custom interface, a similar functional program can just use a function. eg, map f xs in haskell uses f, where an object-oriented program might use a Strategy or whatever to accomplish the same task.
Haskell typeclasses fulfill some of the same roles as interfaces in object oriented languages.
data and newtype in Haskell are approximately equal to class in Java.
class in Haskell is approximately equal to interface in Java.
One can use GADT to express Existentially quantified types.
I see that GADT is more generic - data-type-extensions, paragraph section 7.4.7
When it's better to use Existentially quantified types then GADT? Are there any drawbacks using GADT compared to Existentially quantified types?
GADTs came along later than existentials, and they generalise them. I'm not aware of any drawbacks and would always use GADT syntax in new code as it's much clearer.
The documentation confirms this:
Notice that GADT-style syntax generalises existential types.
If you use the newest version of GHC, then there are no drawbacks I'm aware of. But in older versions you could combine GADTs and GeneralizedNewtypeDeriving in a type-unsafe way. I don't think the same was possible with ExistentialQuantification.
I am brand new to Haskell and am trying to answer this question? I don't want people to do it for me, but any pointers would be helpful because I don't really have a clue where to begin!
Depending on the situation, any of a -> a, [(a, a)], or Map a a can be an appropriate representation of a substitution cipher over the alphabet a.
I have a class (Class A) which contains objects of type Class B. Class B has three subclasses.
Should Class B actually be an interface and then I can draw an aggregation association between the interface and Class A (and the three subclasses implement the interface)
or
Should Class B, be an actual Class, have 3 sub-classes and all four of the classes (Class B + 3 subclasses) implement the interface (through Class B)?
I would say to ask yourself these questions:
1. Would you ever create an instance of Class B? If yes, then it should be a regular class. If not,
2. Should class B contain any functionality that the derived classes should be able to use? If yes you should create an abstract class that the other classes inherit, if no, make it an interface.
If Class A contains objects of type Class B that means that Class B is instantiated, therefore it can't be an interface.