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:
baljeet20 2017-03-16 14:32:00 +05:30 committed by maibin
parent d1233d0437
commit de29f6af4b
6 changed files with 9 additions and 71 deletions

View File

@ -9,23 +9,14 @@ package com.baeldung.xml.jibx;
import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringBuilder;
public class Person extends Identity { public class Person extends Identity {
private String firstName; private String name;
private String lastName;
public String getFirstName() { public String getName() {
return firstName; return name;
} }
public void setFirstName(String firstName) { public void setName(String name) {
this.firstName = firstName; this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
} }
public String toString() { public String toString() {

View File

@ -2,26 +2,8 @@ package com.baeldung.xml.jibx;
public class Phone { public class Phone {
private String countryCode;
private String networkPrefix;
private String number; 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() { public String getNumber() {
return number; return number;
} }

View File

@ -13,29 +13,6 @@
<xs:attribute type="xs:string" name="Type" use="optional" /> <xs:attribute type="xs:string" name="Type" use="optional" />
</xs:complexType> </xs:complexType>
</xs:element> </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:sequence>
<xs:attribute type="xs:int" name="OrderNumber" /> <xs:attribute type="xs:int" name="OrderNumber" />
<xs:attribute type="xs:date" name="OrderDate" /> <xs:attribute type="xs:date" name="OrderDate" />

View File

@ -14,14 +14,11 @@
<mapping name="person" class="com.baeldung.xml.jibx.Person" <mapping name="person" class="com.baeldung.xml.jibx.Person"
extends="com.baeldung.xml.jibx.Identity"> extends="com.baeldung.xml.jibx.Identity">
<structure map-as="com.baeldung.xml.jibx.Identity" /> <structure map-as="com.baeldung.xml.jibx.Identity" />
<value name="first-name" field="firstName" /> <value name="name" field="name" />
<value name="last-name" field="lastName" />
</mapping> </mapping>
<mapping class="com.baeldung.xml.jibx.Phone" abstract="true"> <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" /> <value name="number" field="number" />
</mapping> </mapping>

View File

@ -6,7 +6,6 @@ import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException; import org.jibx.runtime.JiBXException;
import org.junit.Test; import org.junit.Test;
import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.InputStream; import java.io.InputStream;
@ -22,8 +21,7 @@ public class CustomerTest {
InputStream inputStream = classLoader.getResourceAsStream("Customer1.xml"); InputStream inputStream = classLoader.getResourceAsStream("Customer1.xml");
Customer customer = (Customer) uctx.unmarshalDocument(inputStream, null); Customer customer = (Customer) uctx.unmarshalDocument(inputStream, null);
assertEquals("Stefan", customer.getPerson().getFirstName()); assertEquals("Stefan Jaegar", customer.getPerson().getName());
assertEquals("Jaeger", customer.getPerson().getLastName());
assertEquals("Davos Dorf", customer.getCity()); assertEquals("Davos Dorf", customer.getCity());
} }
@ -48,8 +46,6 @@ public class CustomerTest {
InputStream inputStream = classLoader.getResourceAsStream("Customer1.xml"); InputStream inputStream = classLoader.getResourceAsStream("Customer1.xml");
Customer customer = (Customer) uctx.unmarshalDocument(inputStream, null); Customer customer = (Customer) uctx.unmarshalDocument(inputStream, null);
assertEquals("1", customer.getHomePhone().getCountryCode());
assertEquals("234", customer.getHomePhone().getNetworkPrefix());
assertEquals("234678", customer.getHomePhone().getNumber()); assertEquals("234678", customer.getHomePhone().getNumber());
} }

View File

@ -2,18 +2,13 @@
<customer> <customer>
<person> <person>
<customer-id>12345</customer-id> <customer-id>12345</customer-id>
<first-name>Stefan</first-name> <name>Stefan Jaeger</name>
<last-name>Jaeger</last-name>
</person> </person>
<home-phone> <home-phone>
<country-code>1</country-code>
<network-prefix>234</network-prefix>
<number>234678</number> <number>234678</number>
</home-phone> </home-phone>
<office-phone> <office-phone>
<country-code>1</country-code>
<network-prefix>234</network-prefix>
<number>234678</number> <number>234678</number>
</office-phone> </office-phone>
<city>Davos Dorf</city> <city>Davos Dorf</city>