JAXB - флаг 'required' из XmlAttribute игнорируется для примитивных типов

У меня возникла проблема при попытке использовать инструмент schemagen из библиотеки JAXB для создания схемы для моего проекта. Проблема в том, что аннотация @XmlAttribute не разбирается должным образом.

- src
 - teste
  - entity

Итак, проблема в том, что для некоторых классов флаг required в XmlAttribute полностью игнорируется задачей schemagen.

Я вставлю сюда несколько примеров классов и сгенерированной схемы, чтобы вы могли понять, что происходит

package teste.entity;

import javax.xml.bind.annotation.XmlAttribute;

public abstract class Class2 {

    @XmlAttribute(required=false)
    public String stringNotRequired;

    @XmlAttribute(required=true)
    public String stringRequired;

    @XmlAttribute(required=false)
    public int anotherIntNotRequired;

    @XmlAttribute(required=true)
    public int anotherIntRequired;

}

package teste.entity;

import javax.xml.bind.annotation.XmlAttribute;

public class Class1 extends Class2 {

    @XmlAttribute(required=true)
    public Integer integerRequired;

    @XmlAttribute(required=false)
    public Integer integerNotRequired;

    @XmlAttribute(required=false)
    public int intNotRequired;

    @XmlAttribute(required=true)
    public int intRequired;

    public Class1() {
    }
}

Мой package-info.java

@XmlSchema(xmlns = @XmlNs(prefix = "t", namespaceURI = "http://test.com"),
namespace = "http://test.com",
elementFormDefault = XmlNsForm.UNQUALIFIED,
attributeFormDefault = XmlNsForm.UNQUALIFIED)
package teste.entity;

import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;

Когда я запустил задачу schemagen, я получил такой результат:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" version="1.0" targetNamespace="http://test.com" xmlns:t="http://test.com" xmlns:tns="http://test.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:complexType name="class1">
    <xs:complexContent>
      <xs:extension base="tns:class2">
        <xs:sequence/>
        <xs:attribute name="integerRequired" type="xs:int" use="required"/>
        <xs:attribute name="integerNotRequired" type="xs:int"/>
        <xs:attribute name="intNotRequired" type="xs:int" use="required"/>
        <xs:attribute name="intRequired" type="xs:int" use="required"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="class2" abstract="true">
    <xs:sequence/>
    <xs:attribute name="stringNotRequired" type="xs:string"/>
    <xs:attribute name="stringRequired" type="xs:string" use="required"/>
    <xs:attribute name="anotherIntNotRequired" type="xs:int" use="required"/>
    <xs:attribute name="anotherIntRequired" type="xs:int" use="required"/>
  </xs:complexType>
</xs:schema>

Вот моя Ant Task

<target name="generate-schema" >
    <path id="mycp">
        <fileset dir="lib/jaxb/lib\">
            <include name="*.jar"/>
        </fileset>
        <fileset dir="lib" >
            <include name="*.jar"/>
        </fileset>
        <fileset dir="dist" >
            <include name="*.jar"/>
        </fileset>
    </path>

    <taskdef name="schemagen" classname="com.sun.tools.jxc.SchemaGenTask">
        <classpath refid="mycp"/>
    </taskdef>

    <mkdir dir="schema"/>

    <schemagen srcdir="src/teste/entity" destdir="schema" >
        <classpath refid="mycp"/>
        <schema namespace="http://test.com" file="full.xsd" />            
    </schemagen>
</target>
11
задан SHiRKiT 10 January 2012 в 17:26
поделиться