CodeGen Examples

# CodeGen Examples |

JiBX Basics Overview Getting Started Binding Compiler Binding on Load Runtime Extras Building JiBX Maven Contributing License News and Status Support FAQ Mailing Lists Bugs User Comments Sponsors Start from Code Start from Code BindGen Example Code Example 1 Example 2 Example 3 Example 4 Customizations Reference SchemaGen Jibx2Wsdl Examples Customizations Start from Schema Start from Schema CodeGen Schema Datatype Handling Example Code Default Generation Simple Customizations More Customizations Modular Generation Customizations Reference Extensions Reference Binding Definition Binding Tutorial A basic binding Binding extras Structure mapping Collections and arrays Using mappings Advanced binding Method hooks Custom code Precompiled Bindings Definition details Definition contexts Conversions Date/time conversions XML summary <binding> element <include> element <format> element <namespace> element <mapping> element <value> element <structure> element <collection> element Attribute groups Usage API Runtime JavaDocs Subprojects Eclipse Plug-in Introduction Install Usage JiBX/WS Axis2 Usage JiBX/OTA Schema Library | ### CodeGen example schema The /examples/codegen directory of the JiBX distribution contains some samples for demonstrating the use of CodeGen. The samples use a subset of schema definitions from the OpenTravel Alliance, an organization developing open standards for use in electronic message exchange. The OTA definitions consist of hundreds of schemas in total, but the subset used for these samples includes just seven schemas from the OTA2007A distribution, representing a request-response pair of messages: OTA_AirLowFareSearchRQ and OTA_AirLowFareSearchRS. As a sample of the structure, here are simplified listings of these main message schemas (with most of the annoations and some of the structure detail eliminated):
    <xs:schema xmlns="http://www.opentravel.org/OTA/2003/05"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.opentravel.org/OTA/2003/05"
        elementFormDefault="qualified" version="2.007" id="OTA2007A">
    	<xs:include schemaLocation="OTA_AirCommonTypes.xsd"/>
    	<xs:include schemaLocation="OTA_AirPreferences.xsd"/>
    	<xs:element name="OTA_AirLowFareSearchRQ">
    		<xs:annotation>
    			<xs:documentation xml:lang="en">
    	The Low Fare Search Request message requests priced itinerary options for
      flights between specific city pairs on specific dates for specific 	numbers and
      types of passengers. Optional request information can include:
    	- Time / Time Window
    	- Connecting cities.
    	- Client Preferences (airlines, cabin, flight types etc.)
    	The Low Fare Search request contains similar information to a Low Fare Search
      entry on an airline CRS or GDS.
    			</xs:documentation>
    		</xs:annotation>
    		<xs:complexType>
    			<xs:sequence>
    				<xs:element name="POS" type="POS_Type">
    					<xs:annotation>
    						<xs:documentation xml:lang="en">Point of sale object.
                </xs:documentation>
    					</xs:annotation>
    				</xs:element>
    				<xs:element name="ProcessingInfo" minOccurs="0">
    					<xs:annotation>
    						<xs:documentation xml:lang="en">A collection of information that
                specifies how the message processing should occur or how the data
                should be returned.</xs:documentation>
    					</xs:annotation>
    					<xs:complexType>
    						<xs:attributeGroup ref="AirProcessingInfoGroup"/>
    					</xs:complexType>
    				</xs:element>
    				<xs:element name="OriginDestinationInformation" maxOccurs="10">
    					<xs:annotation>
    						<xs:documentation xml:lang="en">Origin and Destination location,
                and time information for the Air Low Fare Search request.
                </xs:documentation>
    					</xs:annotation>
    					<xs:complexType>
    						<xs:complexContent>
    							<xs:extension base="OriginDestinationInformationType">
    								<xs:sequence>
    									<xs:element name="AlternateLocationInfo" minOccurs="0">
    										...
    										<xs:complexType>
    											<xs:attribute name="OriginLocation"
                              type="ListOfStringLength1to8" use="optional">
    												...
    											</xs:attribute>
    											<xs:attribute name="DestinationLocation"
                              type="ListOfStringLength1to8" use="optional">
    												...
    											</xs:attribute>
    										</xs:complexType>
    									</xs:element>
    									<xs:element ref="TPA_Extensions" minOccurs="0"/>
    								</xs:sequence>
    								<xs:attribute name="RPH" type="RPH_Type" use="optional">
                      ...
    								</xs:attribute>
    								<xs:attribute name="RefNumber" type="Numeric1to99"
                        use="optional">
    									...
    								</xs:attribute>
    							</xs:extension>
    						</xs:complexContent>
    					</xs:complexType>
    				</xs:element>
    				<xs:element name="SpecificFlightInfo" type="SpecificFlightInfoType"
                minOccurs="0">
    					...
    				</xs:element>
    				<xs:element name="TravelPreferences" minOccurs="0" maxOccurs="10">
    					...
    					<xs:complexType>
    						<xs:complexContent>
    							<xs:extension base="AirSearchPrefsType">
    								<xs:attribute name="FlexDatePref" use="optional">
    									...
    								</xs:attribute>
    								...
    							</xs:extension>
    						</xs:complexContent>
    					</xs:complexType>
    				</xs:element>
    				<xs:element name="TravelerInfoSummary">
    					...
    					<xs:complexType>
    						<xs:complexContent>
    							<xs:extension base="TravelerInfoSummaryType">
    								<xs:attribute name="TicketingCountryCode" type="ISO3166"
                        use="optional">
    									...
    								</xs:attribute>
    								<xs:attribute name="SpecificPTC_Indicator" type="xs:boolean"
                        use="optional">
    									...
    								</xs:attribute>
    							</xs:extension>
    						</xs:complexContent>
    					</xs:complexType>
    				</xs:element>
    			</xs:sequence>
    			<xs:attributeGroup ref="OTA_PayloadStdAttributes"/>
    			<xs:attributeGroup ref="MaxResponsesGroup"/>
    			<xs:attribute name="DirectFlightsOnly" type="xs:boolean" use="optional"
              default="false">
    				...
    			</xs:attribute>
    			<xs:attribute name="AvailableFlightsOnly" type="xs:boolean"
              use="optional">
    				...
    			</xs:attribute>
    		</xs:complexType>
    	</xs:element>
    </xs:schema>

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns="http://www.opentravel.org/OTA/2003/05"
        targetNamespace="http://www.opentravel.org/OTA/2003/05"
        elementFormDefault="qualified" version="5.000" id="OTA2007A">
    	<xs:include schemaLocation="OTA_AirCommonTypes.xsd"/>
    	...
    	<xs:element name="OTA_AirLowFareSearchRS">
    		<xs:annotation>
    			<xs:documentation xml:lang="en">
    	The Low Fare Search Response message contains a number of 'Priced Itinerary'
      options. Each includes:
    	- A set of available flights matching the client's request.
    	- Pricing information including taxes and full fare breakdown for each
        passenger type
    	- Ticketing information
    	- Fare Basis Codes and the information necessary to make a rules entry.
    	This message contains similar information to a standard airline CRS or GDS Low
      Fare Search Response message.
    			</xs:documentation>
    		</xs:annotation>
    		<xs:complexType>
    			<xs:sequence>
    				<xs:choice>
    					<xs:sequence>
    						<xs:element name="Success" type="SuccessType">
    							<xs:annotation>
    								<xs:documentation xml:lang="en">Success
     Standard way to indicate successful processing of an OTA message. Returning an
     empty element of this type indicates success.</xs:documentation>
    							</xs:annotation>
    						</xs:element>
    						<xs:element name="Warnings" type="WarningsType" minOccurs="0">
    							<xs:annotation>
    								<xs:documentation xml:lang="en"> Standard way to indicate
    successful processing of an OTA message, but one in which warnings are generated.
    </xs:documentation>
    							</xs:annotation>
    						</xs:element>
    						<xs:element name="PricedItineraries" type="PricedItinerariesType">
    							<xs:annotation>
    								<xs:documentation xml:lang="en">Successfull Low Fare priced
                    itineraries in response to a Low Fare Search request.
                    </xs:documentation>
    							</xs:annotation>
    						</xs:element>
    					</xs:sequence>
    					<xs:element name="Errors" type="ErrorsType">
    						<xs:annotation>
    							<xs:documentation xml:lang="en"> A collection of errors that
                  occurred during the processing of a message.</xs:documentation>
    						</xs:annotation>
    					</xs:element>
    				</xs:choice>
    			</xs:sequence>
    			<xs:attributeGroup ref="OTA_PayloadStdAttributes">
    				<xs:annotation>
    					<xs:documentation xml:lang="en"> The OTA_PayloadStdAttributes
              defines the standard attributes that appear on the root element for all
              OTA payloads.</xs:documentation>
    				</xs:annotation>
    			</xs:attributeGroup>
    		</xs:complexType>
    	</xs:element>
    </xs:schema>
### Sample documents The /examples/codegen/samples directory contains the OTA_AirLowFareSearchRQ and OTA_AirLowFareSearchRS sample documents from the OTA distribution (two documents of each type). Here's one of the sample requests, and an edited version of the sample response:
    <OTA_AirLowFareSearchRQ EchoToken="50987" TimeStamp="2003-11-19T19:44:10-05:00"
      Target="Production" SequenceNmbr="1"
      xmlns="http://www.opentravel.org/OTA/2003/05"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05
      OTA_AirLowFareSearchRQ.xsd" Version="2.001">
    	<POS>
    		<Source>
    			<RequestorID Type="13" ID="01235"/>
    		</Source>
    	</POS>
    	<OriginDestinationInformation>
    		<DepartureDateTime>2004-06-05T10:00:00-05:00</DepartureDateTime>
    		<OriginLocation LocationCode="IAD"/>
    		<DestinationLocation LocationCode="FLG"/>
    	</OriginDestinationInformation>
    	<OriginDestinationInformation>
    		<DepartureDateTime>2004-06-27T10:00:00-05:00</DepartureDateTime>
    		<OriginLocation LocationCode="FLG"/>
    		<DestinationLocation LocationCode="IAD"/>
    	</OriginDestinationInformation>
    	<TravelPreferences>
    		<FareRestrictPref>
    			<AdvResTicketing AdvTicketingInd="false">
    				<AdvTicketing/>
    			</AdvResTicketing>
    			<StayRestrictions StayRestrictionsInd="true">
    			       <MinimumStay />
    				<MaximumStay MaxStay="14" StayUnit="Days"/>
    			</StayRestrictions>
    		</FareRestrictPref>
    	</TravelPreferences>
    	<TravelerInfoSummary>
    		<AirTravelerAvail>
    				<PassengerTypeQuantity Code="ADT" Quantity="1"/>
    		</AirTravelerAvail>
    	</TravelerInfoSummary>
    </OTA_AirLowFareSearchRQ>

    <OTA_AirLowFareSearchRS EchoToken="53468" TimeStamp="2003-11-19T19:44:17-05:00"
      Target="Production" SequenceNmbr="1"
      xmlns="http://www.opentravel.org/OTA/2003/05"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05
      OTA_AirLowFareSearchRS.xsd" Version="2.001">
    	<Success/>
    	<PricedItineraries>
    		<PricedItinerary SequenceNumber="1">
    			<AirItineraryPricingInfo>
    				<ItinTotalFare>
    					<BaseFare Amount="256.75" CurrencyCode="USD"/>
    					<TotalFare Amount="285.00" CurrencyCode="USD"/>
    				</ItinTotalFare>
    				<FareInfos>
    					<FareInfo>
    						<FareReference> "K"</FareReference>
    						<RuleInfo>
    							<ResTicketingRules>
    								<AdvResTicketing AdvTicketingInd="true">
    									<AdvTicketing FromDepartPeriod="21" FromDepartUnit="Days"/>
    								</AdvResTicketing>
    							</ResTicketingRules>
    							<LengthOfStayRules>
    								<MinimumStay MinStay="14" StayUnit="Days"/>
    								<MaximumStay ReturnType="C" MaxStay="30" StayUnit="Days"/>
    							</LengthOfStayRules>
    							<ChargesRules>
    								<VoluntaryChanges VolChangeInd="true">
    									<Penalty Percent="100"/>
    								</VoluntaryChanges>
    							</ChargesRules>
    						</RuleInfo>
    						<FilingAirline>HP</FilingAirline>
    						<DepartureAirport LocationCode="IAD"/>
    						<ArrivalAirport LocationCode="FLG"/>
    					</FareInfo>
    					...
    				</FareInfos>
    			</AirItineraryPricingInfo>
    		</PricedItinerary>
    		<PricedItinerary SequenceNumber="2">
    			<AirItineraryPricingInfo>
    				<ItinTotalFare>
    					<BaseFare Amount="337.46" CurrencyCode="USD" />
    					<TotalFare Amount="375.00" CurrencyCode="USD" />
    				</ItinTotalFare>
    				<FareInfos>
    					<FareInfo>
    						<FareReference> "Q"</FareReference>
    						<RuleInfo>
    							<ResTicketingRules>
    								<AdvResTicketing AdvTicketingInd="true">
    									<AdvTicketing FromDepartPeriod="14" FromDepartUnit="Days"/>
    								</AdvResTicketing>
    							</ResTicketingRules>
    							<LengthOfStayRules>
    								<MinimumStay MinStay="7" StayUnit="Days"/>
    								<MaximumStay ReturnType="C" MaxStay="14" StayUnit="Days"/>
    							</LengthOfStayRules>
    							<ChargesRules>
    								<VoluntaryChanges VolChangeInd="true">
    									<Penalty Percent="50"/>
    								</VoluntaryChanges>
    							</ChargesRules>
    						</RuleInfo>
    						<FilingAirline>NW</FilingAirline>
    						<DepartureAirport LocationCode="IAD"/>
    						<ArrivalAirport LocationCode="FLG"/>
    					</FareInfo>
    					...
    				</FareInfos>
    			</AirItineraryPricingInfo>
    		</PricedItinerary>
    		<PricedItinerary SequenceNumber="3">
    			<AirItineraryPricingInfo>
    				<ItinTotalFare>
    					<BaseFare Amount="681.75" CurrencyCode="USD" />
    					<TotalFare Amount="757.00" CurrencyCode="USD" />
    				</ItinTotalFare>
    				<FareInfos>
    					<FareInfo>
    						<FareReference> "Y"</FareReference>
    						<RuleInfo>
    							<ResTicketingRules>
    								<AdvResTicketing AdvTicketingInd="false"/>
    							</ResTicketingRules>
    							<ChargesRules>
    								<VoluntaryChanges VolChangeInd="true"/>
    							</ChargesRules>
    						</RuleInfo>
    						<FilingAirline>UA</FilingAirline>
    						<DepartureAirport LocationCode="IAD"/>
    						<ArrivalAirport LocationCode="FLG"/>
    					</FareInfo>
    					...
    				</FareInfos>
    			</AirItineraryPricingInfo>
    		</PricedItinerary>
    	</PricedItineraries>
    </OTA_AirLowFareSearchRS>
### Examples The examples using these schemas and sample documents demonstrate using CodeGen with increasingly sophisticated levels of customization. One of the common complaints about code generation from schema is that it results in extremely complex data models with a large number of classes, so simplifying the data model using customizations is a main focus of the first three examples (which go from 412 classes in the data model, including inner classes, down to 50 classes). The final example demonstrates modular code generation from schemas, where some of the base schemas are initially generated on their own, then the generated base classes and binding are reused when generating the remaining schemas. 'codegen' target - default generation, including all schema components 'custgen1' target - generating only selected global definitions to eliminate unneeded classes 'custgen2' target - customizing names and types, eliminating unused parts of schema definitions 'custgen3a/custgen3b' targets - modular code generation from schema (base and extension code and bindings)