2017-03-26 3 views
0

私はJAXBを初めて使用しています。 XSDファイルを右クリックしてEclipseの機能を組み込んだXSDファイルからJAXBクラスを作成しました。XSDファイルは、JAXBを使用してネストされた静的クラスを作成します。

しかし、結局のところ、入れ子になった静的な内部クラスを持つクラスです。

ここに問題があります:私はマーシャリングとXMLファイルを作成しようとしています。しかし、どうやって入れ子の内部クラスを外部クラスと一緒に渡すのですか?

public class OuterClass { 

String x = "None of the methods or variables are static in the inner our outer class"; 

public static class InnerClass{ 

} 

}

XMLは:終了タグもあり、この

<OuterClass RequestType="LogOn" ApplicationSender="Example" 
WorkstationID="001"> 
<InnerClass> 
    <TimeStamp>2 009-11-20T17:30:50</TimeStamp> 
    <InterfaceVersion>01.00</InterfaceVersion> 
</InnerClass> 

ようになっているはずですが、プレビューで、何らかの理由でそれが現れていません。ここでは、作成したクラスだ

<?xml version="1.0" encoding="utf-8"?> 

<!--IFSF POS-FDC Schema 23 November 2010--> 

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.02" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

<xs:include schemaLocation="FDC_Basic_Types.xsd"/> 
<xs:include schemaLocation="FDC_DR_CurrencyCode_Full.xsd"/> 

<xs:element name="ServiceRequest"> 
    <xs:complexType mixed="true"> 
     <xs:sequence> 
      <xs:element name="POSdata"> 
       <xs:complexType> 
        <xs:sequence> 
         <xs:element name="POSTimeStamp" type="specialtime"/> 
         <xs:element name="InterfaceVersion" type="InterfaceVersion"/> 
        </xs:sequence> 
       </xs:complexType> 
      </xs:element> 
     </xs:sequence> 
      <xs:attribute name="RequestType" type="RequestType" fixed="LogOn" use="required" /> 
      <xs:attribute name="ApplicationSender" type="ApplicationSender" use="required" />   
      <xs:attribute name="WorkstationID" type="WorkstationID" use="required" />  
      <xs:attribute name="RequestID" type="RequestID" use="required" />  
    </xs:complexType> 
    </xs:element> 
</xs:schema> 

は、ここで実際のXSDファイルです

<p>Java class for anonymous complex type. 
* 
* <p>The following schema fragment specifies the expected content contained within this class. 
* 
* <pre> 
* &lt;complexType> 
* &lt;complexContent> 
*  &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 
*  &lt;sequence> 
*   &lt;element name="POSdata"> 
*   &lt;complexType> 
*    &lt;complexContent> 
*    &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 
*     &lt;sequence> 
*     &lt;element name="POSTimeStamp" type="{}specialtime"/> 
*     &lt;element name="InterfaceVersion" type="{}InterfaceVersion"/> 
*     &lt;/sequence> 
*    &lt;/restriction> 
*    &lt;/complexContent> 
*   &lt;/complexType> 
*   &lt;/element> 
*  &lt;/sequence> 
*  &lt;attribute name="RequestType" use="required" type="{}RequestType" fixed="LogOn" /> 
*  &lt;attribute name="ApplicationSender" use="required" type="{}ApplicationSender" /> 
*  &lt;attribute name="WorkstationID" use="required" type="{}WorkstationID" /> 
*  &lt;attribute name="RequestID" use="required" type="{}RequestID" /> 
*  &lt;/restriction> 
* &lt;/complexContent> 
* &lt;/complexType> 
* </pre> 
* 
* 
*/ 
@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "", propOrder = { 
    "content" 
}) 
@XmlRootElement(name = "ServiceRequest") 
public class ServiceRequest { 

    @XmlElementRef(name = "POSdata", type = JAXBElement.class) 
    @XmlMixed 
    protected List<Serializable> content; 
    @XmlAttribute(name = "RequestType", required = true) 
    protected RequestType requestType; 
    @XmlAttribute(name = "ApplicationSender", required = true) 
    protected String applicationSender; 
    @XmlAttribute(name = "WorkstationID", required = true) 
    protected String workstationID; 
    @XmlAttribute(name = "RequestID", required = true) 
    protected String requestID; 

    /** 
    * Gets the value of the content property. 
    * 
    * <p> 
    * This accessor method returns a reference to the live list, 
    * not a snapshot. Therefore any modification you make to the 
    * returned list will be present inside the JAXB object. 
    * This is why there is not a <CODE>set</CODE> method for the content property. 
    * 
    * <p> 
    * For example, to add a new item, do as follows: 
    * <pre> 
    * getContent().add(newItem); 
    * </pre> 
    * 
    * 
    * <p> 
    * Objects of the following type(s) are allowed in the list 
    * {@link JAXBElement }{@code <}{@link ServiceRequest.POSdata }{@code >} 
    * {@link String } 
    * 
    * 
    */ 
    public List<Serializable> getContent() { 
     if (content == null) { 
      content = new ArrayList<Serializable>(); 
     } 
     return this.content; 
    } 

    /** 
    * Gets the value of the requestType property. 
    * 
    * @return 
    *  possible object is 
    *  {@link RequestType } 
    *  
    */ 
    public RequestType getRequestType() { 
     if (requestType == null) { 
      return RequestType.LOG_ON; 
     } else { 
      return requestType; 
     } 
    } 

    /** 
    * Sets the value of the requestType property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link RequestType } 
    *  
    */ 
    public void setRequestType(RequestType value) { 
     this.requestType = value; 
    } 

    /** 
    * Gets the value of the applicationSender property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getApplicationSender() { 
     return applicationSender; 
    } 

    /** 
    * Sets the value of the applicationSender property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setApplicationSender(String value) { 
     this.applicationSender = value; 
    } 

    /** 
    * Gets the value of the workstationID property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getWorkstationID() { 
     return workstationID; 
    } 

    /** 
    * Sets the value of the workstationID property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setWorkstationID(String value) { 
     this.workstationID = value; 
    } 

    /** 
    * Gets the value of the requestID property. 
    * 
    * @return 
    *  possible object is 
    *  {@link String } 
    *  
    */ 
    public String getRequestID() { 
     return requestID; 
    } 

    /** 
    * Sets the value of the requestID property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link String } 
    *  
    */ 
    public void setRequestID(String value) { 
     this.requestID = value; 
    } 


    /** 
    * <p>Java class for anonymous complex type. 
    * 
    * <p>The following schema fragment specifies the expected content contained within this class. 
    * 
    * <pre> 
    * &lt;complexType> 
    * &lt;complexContent> 
    *  &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 
    *  &lt;sequence> 
    *   &lt;element name="POSTimeStamp" type="{}specialtime"/> 
    *   &lt;element name="InterfaceVersion" type="{}InterfaceVersion"/> 
    *  &lt;/sequence> 
    *  &lt;/restriction> 
    * &lt;/complexContent> 
    * &lt;/complexType> 
    * </pre> 
    * 
    * 
    */ 
    @XmlAccessorType(XmlAccessType.FIELD) 
    @XmlType(name = "", propOrder = { 
     "posTimeStamp", 
     "interfaceVersion" 
    }) 
    public static class POSdata { 

     @XmlElement(name = "POSTimeStamp", required = true) 
     protected String posTimeStamp; 
     @XmlElement(name = "InterfaceVersion", required = true) 
     protected String interfaceVersion; 

     /** 
     * Gets the value of the posTimeStamp property. 
     * 
     * @return 
     *  possible object is 
     *  {@link String } 
     *  
     */ 
     public String getPOSTimeStamp() { 
      return posTimeStamp; 
     } 

     /** 
     * Sets the value of the posTimeStamp property. 
     * 
     * @param value 
     *  allowed object is 
     *  {@link String } 
     *  
     */ 
     public void setPOSTimeStamp(String value) { 
      this.posTimeStamp = value; 
     } 

     /** 
     * Gets the value of the interfaceVersion property. 
     * 
     * @return 
     *  possible object is 
     *  {@link String } 
     *  
     */ 
     public String getInterfaceVersion() { 
      return interfaceVersion; 
     } 

     /** 
     * Sets the value of the interfaceVersion property. 
     * 
     * @param value 
     *  allowed object is 
     *  {@link String } 
     *  
     */ 
     public void setInterfaceVersion(String value) { 
      this.interfaceVersion = value; 
     } 

    } 

} 

答えて

0

コンプリート編集:

あなたはにJAXBElementのに包まれたインスタンスを追加することになっていますcontentリスト

ラップされたJAXBElemen<POSdata>インスタンスを作成するには、その中にファクトリメソッドを使用するか、使用する必要があります。ObjectFactory

したがって、このような何か:

ServiceRequest.POSdata pos = new ServiceRequest.POSdata(); 
// fill in some data 
JAXBElement<POSdata> posElement = new ObjectFactory().createPOSdataElement(pos); // I might be a bit off with the method name, there should be one with that signature. 

request.getContent().add(posElement); 
+0

私はそれを行うことがしたいです。しかし、内部クラスを設定する外部クラスにはメソッドがありません。また、私は自動生成されたクラスを編集したくありません。 – Saurin

+0

実際のコードとそのコードを生成するために使用された実際のxsdを貼り付けてください。 –

+0

元の投稿を編集してコードを追加しました。ありがとう – Saurin

関連する問題