PurchaseOrder.java - JAXB Java Example Class

Q

What would the Java class look like, if I want to map the PurchaseOrder.xsd XML schema to Java data objects based on JAXB API?

✍: FYIcenter.com

A

If you apply the mapping rules given in the JAXB API specification on the PurchaseOrder.xsd XML schema given in the previous tutorial, you will get a Java class similar to the following:

import javax.xml.datatype.XMLGregorianCalendar; 
import java.util.List;
public class PurchaseOrderType {
   USAddress getShipTo(){...} 
   void setShipTo(USAddress){...}
   USAddress getBillTo(){...} 
   void setBillTo(USAddress){...}
   String getComment(){...} 
   void setComment(String){...}
   Items getItems(){...} 
   void setItems(Items){...}
   XMLGregorianCalendar getOrderDate() 
   void setOrderDate(XMLGregorianCalendar)
};
public class USAddress {
   String getName(){...} 
   void setName(String){...}
   String getStreet(){...} 
   void setStreet(String){...}
   String getCity(){...} 
   void setCity(String){...}
   String getState(){...} 
   void setState(String){...}
   int getZip(){...} 
   void setZip(int){...}
   static final String COUNTRY=”USA”;
};
public class Items {
   public class ItemType {
      String getProductName(){...}
      void setProductName(String){...}
      int getQuantity(){...} 
      void setQuantity(int){...}
      float getUSPrice(){...} 
      void setUSPrice(float){...}
      String getComment(){...}
      void setComment(String){...}
      XMLGregorianCalendar getShipDate();
      void setShipDate(XMLGregorianCalendar);
      String getPartNum(){...} 
      void setPartNum(String){...}
   };
   List<Items.ItemType> getItem(){...}
}
public class ObjectFactory {
   Object newInstance(Class javaInterface){...}
   PurchaseOrderType createPurchaseOrderType(){...}
   USAddress createUSAddress(){...}
   Items createItems(){...}
   Items.ItemType createItemsItemType(){...}
   JAXBElement<PurchaseOrderType> createPurchaseOrder(PurchaseOrderType){...}
   JAXBElement<String> createComment(String value){...}
}

 

Examples for JAXB (Java Architecture for XML Binding)

⇒⇒FAQ for jaxb-*.jar - Java Architecture for XML Binding

2018-05-19, 223👍, 0💬