JAXB Simplify plugin vs *.xjb

2.6k views Asked by At

I'm trying to use the Simplify plugin to replace a complex property with a set of simpler ones. I made it working following the plugin's manual. But I can't change the original schema, so I have to use an external bindings.xjb. And it gives me all sort of errors. Does somebody have a working example of a similar thing?

Original XSD:

<xs:schema id="messages"
    elementFormDefault="qualified"
    version="Exchange2010_SP2"
    xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:tns="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://schemas.microsoft.com/exchange/services/2006/messages">

<xs:import namespace="http://schemas.microsoft.com/exchange/services/2006/types" schemaLocation="types.xsd"/>

...

<xs:complexType name="ArrayOfResponseMessagesType">
    <xs:choice maxOccurs="unbounded">
        <xs:element name="CreateItemResponseMessage" type="m:ItemInfoResponseMessageType"/>
        <xs:element name="DeleteItemResponseMessage" type="m:ResponseMessageType"/>
        <xs:element name="GetItemResponseMessage" type="m:ItemInfoResponseMessageType"/>

        ...

    </xs:choice>
</xs:complexType>

Modified XSD that works for me:

<xs:schema id="messages"
    elementFormDefault="qualified"
    version="Exchange2010_SP2"
    xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:tns="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    jaxb:extensionBindingPrefixes="simplify"
    targetNamespace="http://schemas.microsoft.com/exchange/services/2006/messages">

<xs:import namespace="http://schemas.microsoft.com/exchange/services/2006/types" schemaLocation="types.xsd"/>

...

<xs:complexType name="ArrayOfResponseMessagesType">
    <xs:choice maxOccurs="unbounded">
        <xs:element name="CreateItemResponseMessage" type="m:ItemInfoResponseMessageType">
          <xs:annotation>
            <xs:appinfo>
              <simplify:as-element-property/>
            </xs:appinfo>
          </xs:annotation>
        </xs:element>
        <xs:element name="DeleteItemResponseMessage" type="m:ResponseMessageType"/>
        <xs:element name="GetItemResponseMessage" type="m:ItemInfoResponseMessageType"/>

        ...

    </xs:choice>
</xs:complexType>

My bindings.xjb (that I want to use instead of changing the schema):

<bindings version="2.1"
      xmlns="http://java.sun.com/xml/ns/jaxb"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
      extensionBindingPrefixes="simplify">
<bindings schemaLocation="../wsdl/messages.xsd" node="/xs:schema/xs:complexType[@name='ArrayOfResponseMessagesType']/xs:choice/xs:element[1]">
    <xs:annotation>
        <xs:appinfo>
            <simplify:as-element-property/>
        </xs:appinfo>
    </xs:annotation>
</bindings>
</bindings>

My current exception

org.xml.sax.SAXParseException: Unsupported binding namespace "http://www.w3.org/2001/XMLSchema". Perhaps you meant "http://java.sun.com/xml/ns/jaxb/xjc"?
1

There are 1 answers

0
Dmitriy Yefremov On BEST ANSWER

Ok, I figured this out. Here is the configuration that made it working:

<bindings version="2.1"
      xmlns="http://java.sun.com/xml/ns/jaxb"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
      extensionBindingPrefixes="simplify">


  <bindings schemaLocation="../wsdl/messages.xsd" node="/xs:schema/xs:complexType[@name='ArrayOfResponseMessagesType']/xs:choice/xs:element[1]">
    <simplify:as-element-property/>
  </bindings>

</bindings>

That simple.