2015-03-12 2 views
3

Я должен использовать схему, которая содержит следующий фрагмент, где дублируется имя object.JaxB переименовать класс с дублирующимся именем

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <xs:complexType name="param_object_type"> 
     <xs:sequence> 
      <xs:element name="object" minOccurs="0" maxOccurs="unbounded"> 
      <xs:complexType> 
       <xs:sequence> 
        <xs:element name="object" minOccurs="0" maxOccurs="unbounded"> 
       </xs:sequence> 
      </xs:complexType> 
     </xs:sequence> 
    </xs:complexType> 

</xs:schema> 

JAXB первоначально был счастлив импортировать, но будет не в состоянии собрать источники, так как класс объекта был дважды объявлен.

Я добавил globalBindings вариант localScoping="toplevel" и это приводит теперь к следующей компиляции ошибки времени:

org.xml.sax.SAXParseException; systemId: A class/interface with the same name "jaxb.Object" is already in use. Use a class customization to resolve this conflict.

Так что я попытался добавить пользовательские привязки переименовать один из объектов, jaxb:class и jaxb:property. Оба имеют ту же ошибку.

Если это помогает, вот подадут привязки:

<jaxb:bindings version="2.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <jaxb:bindings> 
     <jaxb:globalBindings generateElementProperty="false" fixedAttributeAsConstantProperty="true" choiceContentProperty="true" localScoping="toplevel"/> 
    </jaxb:bindings> 
    <jaxb:bindings schemaLocation="../xsd/NodeSchema.xsd" node="/xs:schema"> 
     <jaxb:bindings node="/xs:schema/xs:complexType[@name='param_object_type']/xs:sequence/xs:element[@name='object']"> 
      <jaxb:class name="object2"/> 
     </jaxb:bindings> 
    </jaxb:bindings> 
</jaxb:bindings> 

Как я могу убедиться, что один из этих случаев получает переименовано, а другие остаются нетронутыми?

+0

Вы решили эту проблему? Если вы решите его, как вы это сделали? – Xstian

+0

Исправлено, используя ответ ниже. Огромное спасибо. – nwb

ответ

2

правый сложный тип .. пропавшие закрывающий тег для xs:element

XSD

<xs:complexType name="param_object_type"> 
    <xs:sequence> 
     <xs:element name="object" minOccurs="0" maxOccurs="unbounded"> 
      <xs:complexType> 
       <xs:sequence> 
        <xs:element name="object" minOccurs="0" maxOccurs="unbounded" /> 
       </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
    </xs:sequence> 
</xs:complexType> 

Наручники

<jxb:bindings node="//xs:schema//xs:complexType[@name='param_object_type']//xs:sequence//xs:element[@name='object']//xs:complexType//xs:sequence//xs:element[@name='object']"> 
    <jxb:class name="object2" /> 
</jxb:bindings> 

ParamObjectType.java

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "param_object_type", propOrder = { 
    "object" 
}) 
public class ParamObjectType 
    implements Serializable 
{ 

    private final static long serialVersionUID = 2L; 
    protected List<ParamObjectType.Object> object; 

    /** 
    * Gets the value of the object 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 object property. 
    * 
    * <p> 
    * For example, to add a new item, do as follows: 
    * <pre> 
    * getObject().add(newItem); 
    * </pre> 
    * 
    * 
    * <p> 
    * Objects of the following type(s) are allowed in the list 
    * {@link ParamObjectType.Object } 
    * 
    * 
    */ 
    public List<ParamObjectType.Object> getObject() { 
     if (object == null) { 
      object = new ArrayList<ParamObjectType.Object>(); 
     } 
     return this.object; 
    } 


    /** 
    * <p>Classe Java per anonymous complex type. 
    * 
    * <p>Il seguente frammento di schema specifica il contenuto previsto contenuto in questa classe. 
    * 
    * <pre> 
    * &lt;complexType> 
    * &lt;complexContent> 
    *  &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 
    *  &lt;sequence> 
    *   &lt;element name="object" type="{http://www.w3.org/2001/XMLSchema}anyType" maxOccurs="unbounded" minOccurs="0"/> 
    *  &lt;/sequence> 
    *  &lt;/restriction> 
    * &lt;/complexContent> 
    * &lt;/complexType> 
    * </pre> 
    * 
    * 
    */ 
    @XmlAccessorType(XmlAccessType.FIELD) 
    @XmlType(name = "", propOrder = { 
     "object" 
    }) 
    public static class Object 
     implements Serializable 
    { 

     private final static long serialVersionUID = 2L; 
     @XmlElementRef(name = "object", type = ParamObjectType.Object.Object2 .class, required = false) 
     protected List<ParamObjectType.Object.Object2> object; 

     /** 
     * Gets the value of the object 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 object property. 
     * 
     * <p> 
     * For example, to add a new item, do as follows: 
     * <pre> 
     * getObject().add(newItem); 
     * </pre> 
     * 
     * 
     * <p> 
     * Objects of the following type(s) are allowed in the list 
     * {@link ParamObjectType.Object.Object2 } 
     * 
     * 
     */ 
     public List<ParamObjectType.Object.Object2> getObject() { 
      if (object == null) { 
       object = new ArrayList<ParamObjectType.Object.Object2>(); 
      } 
      return this.object; 
     } 

     public static class Object2 
      extends JAXBElement<java.lang.Object> 
     { 

      protected final static QName NAME = new QName("", "object"); 

      public Object2(java.lang.Object value) { 
       super(NAME, ((Class) java.lang.Object.class), ParamObjectType.Object.class, value); 
      } 

      public Object2() { 
       super(NAME, ((Class) java.lang.Object.class), ParamObjectType.Object.class, null); 
      } 

     } 

    } 

} 
Смежные вопросы