Castor XML bindings: Generating distinct types

DenisIzPerm

New Member
I'm encountering a problem using Castor to generate Java classes/unmarshallers for a moderately complex XSD that we're getting from a 3rd party (i.e. not under our control). The XSD maps MLB statistics, and the problem area has the structure of
  • \[code\]game_side\[/code\] (i.e. team)
    • \[code\]hitting\[/code\]\[code\]players\[/code\]: list of hitting_stats, element name \[code\]player\[/code\]
  • \[code\]pitching\[/code\]
    • \[code\]players\[/code\]: list of pitching_stats, element name \[code\]player\[/code\]
The problem is that the generated Java ends up producing the same type for the \[code\]players\[/code\] and \[code\]player\[/code\] elements, i.e. (very abbreviated)\[code\]class HittingElement { private PlayersElement _playersElement; // contains list of PlayerElement}class PitchingElement { private PlayersElement _playersElement; // contains list of PlayerElement}\[/code\]Thus, there's no distinction between pitching and hitting players (in fact, perhaps due to generation order, Castor represents a \[code\]PlayerElement\[/code\] as extending \[code\]Pitching_statsType\[/code\]. Clearly I need two player element types.Generally I'm using Castor's built-in facilities for collision resolution, but it doesn't seem to realise that this is a conflict, but assume that the two similar items called \[code\]players\[/code\] are of the same type. I've tried to resolve this in my bindings file, but to no effect whatsoever.castor-bindings.xml:\[code\]<?xml version="1.0" encoding="UTF-8"?><binding> <!-- Default conflict resolution stuff --> <namingXML> <elementName><suffix>Element</suffix></elementName> <complexTypeName><suffix>Type</suffix></complexTypeName> <propertyGroupName><suffix>ModelGroup</suffix></propertyGroupName> </namingXML></binding>\[/code\]XSD: \[code\] <xs:element name="statistics"> <xs:complexType> <xs:sequence> <xs:element name="visitor" type="mlb:game_side"/> <xs:element name="home" type="mlb:game_side"/> </xs:sequence> <xs:attribute name="id" use="required" type="mlb:entity_id"/> <xs:attribute name="status" use="required" type="mlb:event_status"/> </xs:complexType> </xs:element> <xs:complexType name="game_side"> <xs:sequence> <xs:element name="hitting"> <xs:complexType> <xs:sequence> <xs:element name="team" minOccurs="0" maxOccurs="1" type="mlb:hitting_stats"/> <xs:element name="players"> <xs:complexType> <xs:sequence> <xs:element name="player" minOccurs="0" maxOccurs="unbounded" type="mlb:hitting_stats"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="pitching"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" maxOccurs="1" name="team" type="mlb:pitching_stats"/> <xs:element name="players"> <xs:complexType> <xs:sequence> <xs:element name="player" minOccurs="0" maxOccurs="unbounded" type="mlb:pitching_stats"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="id" type="mlb:entity_id"/> </xs:complexType> <xs:complexType name="hitting_stats"> <xs:sequence> <xs:element name="onbase" type="mlb:common_onbase"/> <xs:element name="runs" type="mlb:common_runs"/> <xs:element name="outcome" type="mlb:common_outcome"/> <xs:element name="outs" type="mlb:common_outs"/> <xs:element name="steal" type="mlb:common_steal"/> <xs:element name="games" type="mlb:common_games"/> </xs:sequence> <xs:attributeGroup ref="mlb:hittingStatsAttributes"/> <xs:attribute name="id" type="mlb:entity_id"/> </xs:complexType> <xs:complexType name="pitching_stats"> <xs:sequence> <xs:element name="onbase" type="mlb:common_onbase"/> <xs:element name="runs" type="mlb:common_runs"/> <xs:element name="outcome" type="mlb:common_outcome"/> <xs:element name="outs" type="mlb:common_outs"/> <xs:element name="steal" type="mlb:common_steal"/> <xs:element name="games" type="mlb:common_games"/> </xs:sequence> <xs:attributeGroup ref="mlb:pitchingStatsAttributes"/> <xs:attribute name="id" type="mlb:entity_id"/> </xs:complexType></xs:schema>\[/code\]
 
Back
Top