jaxb
  1. jaxb
  2. JAXB-829

schemagen and xjc should add 'if-exists' to bindings when generating an episode file

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.3u1
    • Fix Version/s: None
    • Component/s: schemagen
    • Labels:
      None

      Description

      When schemagen or xjc generates an episode file (via the -episode command-line argument; or in the case of the schemagen ant task, the episode attribute), the resultant file should set the 'if-exists' attribute on the 2nd-level bindings element.

      Rationale: When generating an episode file, you may be generating bindings for multiple namespaces at once (especially if you're using schemagen and adding the episode file to your META-INF section of a jar file). If you then try to consume that bindings file via xjc (as documented at http://weblogs.java.net/blog/2006/09/05/separate-compilation-jaxb-ri-21), it will fail if your input schema doesn't have references to all of the namespaces included in the episode file. At least, it will fail if you're using the Ant xjc task, I haven't tried from the command line.

      However, if the bindings had 'if-exists' set on them, the xjc task would simply keep going (the code that checks for this attribute is in SCDBasedBindingSet::Target::apply).

      Concise example:

      Output is currently generated like this:

      <bindings version="2.1" xmlns="http://java.sun.com/xml/ns/jaxb">
      <bindings scd="x-schema::tns" xmlns:tns="http://example.com/SomeSampleNamespace/">
      <schemaBindings map="false"/>
      <bindings scd="tns:SampleElement">
      <class ref="com.example.sample.SampleElement"/>
      </bindings>
      /.../
      </bindings>
      </bindings>

      If it was instead this (note the if-exists on the bindings with scd attribute):

      <bindings version="2.1" xmlns="http://java.sun.com/xml/ns/jaxb">
      <bindings scd="x-schema::tns" xmlns:tns="http://example.com/SomeSampleNamespace/" if-exists="">
      <schemaBindings map="false"/>
      <bindings scd="tns:SampleElement">
      <class ref="com.example.sample.SampleElement"/>
      </bindings>
      /.../
      </bindings>
      </bindings>

      Then the xjc task would ignore any unused bindings when processing it with the -b or from a jar file's META-INF. I think this would be the desired action when using bindings generated as an episode file.

        Activity

        Hide
        famod added a comment -

        I too stumbled upon this issue.

        We have multiple xsd-files with individual namespaces that are used by multiple wsdl files that also have individual namespaces. Each wsdl is using only a subset of the xsd files.
        In that scenario I tried using the generated episode file for wsdl2java (via maven) and failed because of this issue.

        I ended up creating my own bindings-file with if-exists in place.

        Btw: Finding "if-exists" in the code (SCDBasedBindingSet) was the last resort for me. I did not find this feature in the Jaxb documentation.

        Show
        famod added a comment - I too stumbled upon this issue. We have multiple xsd-files with individual namespaces that are used by multiple wsdl files that also have individual namespaces. Each wsdl is using only a subset of the xsd files. In that scenario I tried using the generated episode file for wsdl2java (via maven) and failed because of this issue. I ended up creating my own bindings-file with if-exists in place. Btw: Finding "if-exists" in the code (SCDBasedBindingSet) was the last resort for me. I did not find this feature in the Jaxb documentation.
        Hide
        cpalm added a comment -

        +1 for this.
        Without the if-exists attribute episodes are pretty much useless for most non-trivial use cases.

        Show
        cpalm added a comment - +1 for this. Without the if-exists attribute episodes are pretty much useless for most non-trivial use cases.
        Hide
        bdrx added a comment -

        Any progress on this feature?

        Show
        bdrx added a comment - Any progress on this feature?

          People

          • Assignee:
            Martin Grebac
            Reporter:
            matunos
          • Votes:
            20 Vote for this issue
            Watchers:
            14 Start watching this issue

            Dates

            • Created:
              Updated: