2 Replies Latest reply: Aug 2, 2012 3:41 AM by 953216 RSS

    wsimport/xjc JDK 1.6: using schema-elements with underscores

    953216
      Hi,

      the jaxb-schema-compiler/the embedded schema-compiler used by wsimport eliminates underscores by default. You can set a binding file to influence this behavior in a special way since JAXB 2.1:

      <?xml version='1.0' encoding='UTF-8'?>
      <jaxb:bindings
      xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
      version="2.1">
      <jaxb:globalBindings underscoreBinding="asCharInWord"/>
      </jaxb:bindings>

      But the result using this additional binding is not correct for all cases:

      All letters up to the first underscore of the generated java identifier name for the jaxb element are converted to lowercase. All underscores in the element name are deleted and every first letter after these underscores is converted to uppercase. This is a suitable conversion for identifiers only if you use no uppercase letters.
      But if you use uppercase letters for the element you can get ambigous identifiers.

      examples:

      element-name:
      THIS_WHITEHOUSE
      causes
      JAXBElement-identifier:
      thisWHITEHOUSE

      element name:
      THIS_WHITE_HOUSE
      causes
      java identifier:
      thisWHITEHOUSE


      Possible solution:
      An additional jaxb binding parameter to get a correct behaviour for capital letters:

      This behaviour
      a.) All letters up to the first underscore are unchanged.
      b.) If the first letter after an underscore is a lowercase letter the xjc replaces this letter with an upper case letter and vice versa (=if this letter is an uppercase letter xjc replaces this letter with a lowercase letter).

      example:

      THIS_WHITEHOUSE -> THISwHITEHOUSE
      THIS_WHITE_HOUSE -> THISwHITEhOUSE
      this_whitehouse -> thisWhitehouse
      this_white_house -> thisWhiteHouse

      So all identifiers would be unambigously.

      G. Ranft
      Muenster, Germany
        • 1. Re: wsimport/xjc JDK 1.6: using schema-elements with underscores
          jtahlborn
          i can see your difficulty, however, i have to ask: why are you using identifiers which differ only in the number of underscores? that seems exceedingly ambiguous to start with.
          • 2. Re: wsimport/xjc JDK 1.6: using schema-elements with underscores
            953216
            Hi,

            well, for the most jaxb users it seems to be an uncommon problem. But we provide in our application more than 2000 web services with nearly 100.000 different elements. The identifiers of the elements are logical expressions used for financial applications. they are part of legacy applications so their names cannot be changed. And some identifiers differ only by the position of the underscore.


            A general question for me is why jaxb doesnt accept the undesorces. An when jaxb does not accept underscores why are the rules for calculating an identifier without underscores are ambigous.

            Best regards,

            Guido Ranft