BAEL-707 Introduction to JiBX (#1340)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Customer.java 06.06.2008
|
||||
*
|
||||
* Copyright 2008 Stefan Jäger
|
||||
*
|
||||
*/
|
||||
package com.baeldung.xml.jibx;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
public class Customer {
|
||||
private Person person;
|
||||
private String city;
|
||||
|
||||
private Phone homePhone;
|
||||
private Phone officePhone;
|
||||
|
||||
public Person getPerson() {
|
||||
return person;
|
||||
}
|
||||
|
||||
public void setPerson(Person person) {
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public Phone getHomePhone() {
|
||||
return homePhone;
|
||||
}
|
||||
|
||||
public void setHomePhone(Phone homePhone) {
|
||||
this.homePhone = homePhone;
|
||||
}
|
||||
|
||||
public Phone getOfficePhone() {
|
||||
return officePhone;
|
||||
}
|
||||
|
||||
public void setOfficePhone(Phone officePhone) {
|
||||
this.officePhone = officePhone;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.xml.jibx;
|
||||
|
||||
public class Identity {
|
||||
|
||||
long customerId;
|
||||
|
||||
public long getCustomerId() {
|
||||
return customerId;
|
||||
}
|
||||
|
||||
public void setCustomerId(long customerId) {
|
||||
this.customerId = customerId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Person.java 06.06.2008
|
||||
*
|
||||
* Copyright 2008 Stefan Jäger
|
||||
*
|
||||
*/
|
||||
package com.baeldung.xml.jibx;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
public class Person extends Identity {
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.xml.jibx;
|
||||
|
||||
public class Phone {
|
||||
|
||||
private String countryCode;
|
||||
private String networkPrefix;
|
||||
private String number;
|
||||
|
||||
public String getCountryCode() {
|
||||
return countryCode;
|
||||
}
|
||||
|
||||
public void setCountryCode(String countryCode) {
|
||||
this.countryCode = countryCode;
|
||||
}
|
||||
|
||||
public String getNetworkPrefix() {
|
||||
return networkPrefix;
|
||||
}
|
||||
|
||||
public void setNetworkPrefix(String networkPrefix) {
|
||||
this.networkPrefix = networkPrefix;
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(String number) {
|
||||
this.number = number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<xs:schema attributeFormDefault="unqualified"
|
||||
elementFormDefault="qualified" targetNamespace="http://www.jibx.xml.baeldung.com/"
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<xs:element name="Order">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="Address" maxOccurs="unbounded"
|
||||
minOccurs="0">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element type="xs:string" name="Name" />
|
||||
<xs:element type="xs:string" name="Street" />
|
||||
<xs:element type="xs:string" name="City" />
|
||||
<xs:element type="xs:string" name="State" />
|
||||
<xs:element type="xs:int" name="Zip" />
|
||||
<xs:element type="xs:string" name="Country" />
|
||||
</xs:sequence>
|
||||
<xs:attribute type="xs:string" name="Type" use="optional" />
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element type="xs:string" name="DeliveryNotes" />
|
||||
<xs:element name="Items">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="Item" maxOccurs="unbounded"
|
||||
minOccurs="0">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element type="xs:string" name="ProductName" />
|
||||
<xs:element type="xs:byte" name="Quantity" />
|
||||
<xs:element type="xs:float" name="USPrice" />
|
||||
<xs:element type="xs:string" name="Comment"
|
||||
minOccurs="0" />
|
||||
<xs:element type="xs:date" name="ShipDate"
|
||||
minOccurs="0" />
|
||||
</xs:sequence>
|
||||
<xs:attribute type="xs:string" name="PartNumber"
|
||||
use="optional" />
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
<xs:attribute type="xs:int" name="OrderNumber" />
|
||||
<xs:attribute type="xs:date" name="OrderDate" />
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<binding>
|
||||
<mapping class="com.baeldung.xml.jibx.Identity" abstract="true">
|
||||
<value name="customer-id" field="customerId" />
|
||||
</mapping>
|
||||
|
||||
<mapping name="customer" class="com.baeldung.xml.jibx.Customer">
|
||||
<structure field="person" />
|
||||
<structure name="home-phone" field="homePhone" usage="optional" />
|
||||
<structure name="office-phone" field="officePhone" usage="optional" />
|
||||
<value name="city" field="city" />
|
||||
</mapping>
|
||||
|
||||
<mapping name="person" class="com.baeldung.xml.jibx.Person"
|
||||
extends="com.baeldung.xml.jibx.Identity">
|
||||
<structure map-as="com.baeldung.xml.jibx.Identity" />
|
||||
<value name="first-name" field="firstName" />
|
||||
<value name="last-name" field="lastName" />
|
||||
|
||||
</mapping>
|
||||
|
||||
<mapping class="com.baeldung.xml.jibx.Phone" abstract="true">
|
||||
<value name="country-code" field="countryCode" />
|
||||
<value name="network-prefix" field="networkPrefix" />
|
||||
<value name="number" field="number" />
|
||||
</mapping>
|
||||
|
||||
|
||||
</binding>
|
||||
Reference in New Issue
Block a user