BALE-707 Refactoring changes (#1418)
* BAEL-707 Add the changes as per review comment * BAEL-707 Refactored the code as per review comments
This commit is contained in:
parent
d1233d0437
commit
de29f6af4b
|
@ -9,23 +9,14 @@ package com.baeldung.xml.jibx;
|
|||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
public class Person extends Identity {
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String name;
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
|
|
@ -2,26 +2,8 @@ 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;
|
||||
}
|
||||
|
|
|
@ -13,29 +13,6 @@
|
|||
<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" />
|
||||
|
|
|
@ -14,14 +14,11 @@
|
|||
<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" />
|
||||
<value name="name" field="name" />
|
||||
|
||||
</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>
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.jibx.runtime.IUnmarshallingContext;
|
|||
import org.jibx.runtime.JiBXException;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
||||
|
@ -22,8 +21,7 @@ public class CustomerTest {
|
|||
InputStream inputStream = classLoader.getResourceAsStream("Customer1.xml");
|
||||
Customer customer = (Customer) uctx.unmarshalDocument(inputStream, null);
|
||||
|
||||
assertEquals("Stefan", customer.getPerson().getFirstName());
|
||||
assertEquals("Jaeger", customer.getPerson().getLastName());
|
||||
assertEquals("Stefan Jaegar", customer.getPerson().getName());
|
||||
assertEquals("Davos Dorf", customer.getCity());
|
||||
|
||||
}
|
||||
|
@ -47,9 +45,7 @@ public class CustomerTest {
|
|||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
InputStream inputStream = classLoader.getResourceAsStream("Customer1.xml");
|
||||
Customer customer = (Customer) uctx.unmarshalDocument(inputStream, null);
|
||||
|
||||
assertEquals("1", customer.getHomePhone().getCountryCode());
|
||||
assertEquals("234", customer.getHomePhone().getNetworkPrefix());
|
||||
|
||||
assertEquals("234678", customer.getHomePhone().getNumber());
|
||||
|
||||
}
|
||||
|
|
|
@ -2,18 +2,13 @@
|
|||
<customer>
|
||||
<person>
|
||||
<customer-id>12345</customer-id>
|
||||
<first-name>Stefan</first-name>
|
||||
<last-name>Jaeger</last-name>
|
||||
<name>Stefan Jaeger</name>
|
||||
</person>
|
||||
<home-phone>
|
||||
<country-code>1</country-code>
|
||||
<network-prefix>234</network-prefix>
|
||||
<number>234678</number>
|
||||
</home-phone>
|
||||
|
||||
<office-phone>
|
||||
<country-code>1</country-code>
|
||||
<network-prefix>234</network-prefix>
|
||||
<number>234678</number>
|
||||
</office-phone>
|
||||
<city>Davos Dorf</city>
|
||||
|
|
Loading…
Reference in New Issue