2014-09-08 2 views
1

@XmlPath не работает.@XmlPath не работает

Customer.java

import org.eclipse.persistence.oxm.annotations.XmlPath; 

@XmlRootElement(name= "Customer") 

public class Customer { 

    private String CustomerId; 
    private String organizationCode;  
    private Extn extn; 
    private String organizationName; 
    private int reset; 
    private CustomerSchedulingPreferences customerSchedulingPreferences; 
    private ArrayList<RestrictedState> restrictedStateList; 

    @XmlAttribute 
    public String getCustomerId() { 
     return CustomerId; 
    } 
    public void setCustomerId(String customerId) { 
     CustomerId = customerId; 
    } 
    @XmlAttribute 
    public String getOrganizationCode() { 
     return organizationCode; 
    } 
    public void setOrganizationCode(String organizationCode) { 
     this.organizationCode = organizationCode; 
    } 
    @XmlElement(name="Extn")  
    public Extn getExtn() { 
     return extn; 
    } 
    public void setExtn(Extn extn) { 
     this.extn = extn; 
    }  
    @XmlPath("BuyerOrganization/@OrganizationName") 
    public String getOrganizationName() { 
     return organizationName; 
    } 
    public void setOrganizationName(String organizationName) { 
     this.organizationName = organizationName; 
    } 
    @XmlPath("BuyerOrganization/Extn/USSCORestrictedStateList") 
    @XmlElement(name = "USSCORestrictedState") 
    public ArrayList<RestrictedState> getRestrictedStateList() { 
     return restrictedStateList; 
    } 
    public void setRestrictedStateList(ArrayList<RestrictedState> restrictedStateList) { 
     this.restrictedStateList = restrictedStateList; 
    } 

    @XmlPath("BuyerOrganization/Extn/USSCORestrictedStateList/@Reset") 
    public int getReset() { 
     return reset; 
    } 
    public void setReset(int reset) { 
     this.reset = reset; 
    } 
    @XmlElement(name="CustomerSchedulingPreferences") 
    public CustomerSchedulingPreferences getCustomerSchedulingPreferences() { 
     return customerSchedulingPreferences; 
    } 
    public void setCustomerSchedulingPreferences(
      CustomerSchedulingPreferences customerSchedulingPreferences) { 
     this.customerSchedulingPreferences = customerSchedulingPreferences; 
    } 

} 

Client.java

import javax.xml.transform.stream.StreamResult; 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import org.springframework.oxm.Marshaller; 


public class Client 
{ 
    public static void main(String[] args)throws IOException 
    { 
     ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); 
     Marshaller marshaller = (Marshaller)context.getBean("jaxbMarshallerBean"); 

     Customer customer=new Customer(); 

     customer.setCustomerId("12345"); 
     customer.setOrganizationCode("SUPPLY"); 

     Extn extn = new Extn(); 
     extn.setExtnBillCreditCode("000"); 
     extn.setExtnBillSubscriptionId("132131"); 
     customer.setExtn(extn); 



     RestrictedState resState1= new RestrictedState(); 
     resState1.setOrgCode("952121"); 
     resState1.setRestrictedStateCode("IN"); 

     RestrictedState resState2= new RestrictedState(); 
     resState2.setOrgCode("60325"); 
     resState2.setRestrictedStateCode("IL"); 

     ArrayList<RestrictedState> restrictedStateList = new ArrayList<RestrictedState>(); 
     restrictedStateList.add(resState1); 
     restrictedStateList.add(resState2); 



     CustomerSchedulingPreferences custSchedPref = new CustomerSchedulingPreferences(); 
     custSchedPref.setIsLineShipComplete("Y"); 
     custSchedPref.setIsLineShipSingleNode("N"); 
     custSchedPref.setOptimizationType("03"); 

     customer.setCustomerSchedulingPreferences(custSchedPref); 
     customer.setRestrictedStateList(restrictedStateList); 

     marshaller.marshal(customer, new StreamResult(new FileWriter("customer.xml"))); 

     System.out.println("XML Created Sucessfully"); 

    } 
} 

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:oxm="http://www.springframework.org/schema/oxm" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/oxm 
     http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd"> 

     <oxm:jaxb2-marshaller id="jaxbMarshallerBean"> 
      <oxm:class-to-be-bound name="com.javatpoint.Customer"/> 
     </oxm:jaxb2-marshaller> 

</beans> 

Структура производства необходимы:

<Customer CustomerID="952121" OrganizationCode="SUPPLY" > 
    <Extn ExtnBillCreditCode="000" ExtnBillSubscriptionID="952121" /> 
    <BuyerOrganization OrganizationName="Buy.com1" > 
    <Extn> 
     <USSCORestrictedStateList Reset="Y"> 
     <USSCORestrictedState OrganizationCode="952121" RestrictedStateCode="IN"/> 
     </USSCORestrictedStateList> 
    </Extn> 
    </BuyerOrganization> 
    <CustomerSchedulingPreferences IsLineShipComplete="" IsLineShipSingleNode="" /> 
</Customer> 

====================================================================================================================== ================================

Пожалуйста, помогите мне в решении этого:

в настоящее время я являюсь получение вывода, как показано ниже:

<Customer organizationCode="SUPPLY" customerId="12345"> 
<CustomerSchedulingPreferences IsLineShipSingleNode="N" IsLineShipComplete="Y"/> 
<Extn ExtnBillSubscriptionID="132131" ExtnBillCreditCode="000"/> 
<reset>0</reset> 
<USSCORestrictedState restrictedStateCode="IN" OrganizationCode="952121"/> 
<USSCORestrictedState restrictedStateCode="IL" OrganizationCode="60325"/> 
</Customer> 

ответ

0

чтобы эффективно использовать @XmlPath расширение, которое нужно использовать EclipseLink Moxy в качестве поставщика JAXB.

Ниже ссылку, которая поможет установить это значение:

+1

спасибо. Это сработало для меня – user3035087