Can I configure XJC compiler to consume custom XML bindings for inline customization?

夙愿已清 提交于 2019-12-25 08:34:04

问题


For JAXB we could use Inline Customization to adjust schema compiler in some way. This could be done via Schema Binding Declarations (<jxb:schemaBindings/>).

Any way to make other XML tags (e.g. ActualType, EnumerationValue in example below) work with standard XJC compiler to affect generated classes?

<xs:simpleType name="SomeType">
  <xs:annotation>
    <xs:appinfo>
      <ActualType Name="unsignedInt" />
    </xs:appinfo>
  </xs:annotation>
  <xs:restriction base="xs:string">
    <xs:enumeration value="PredefinedEnumValue">
      <xs:annotation>
        <xs:appinfo>
          <EnumerationValue>10000</EnumerationValue>
        </xs:appinfo>
      </xs:annotation>
    </xs:enumeration>
  </xs:restriction>
</xs:simpleType>

回答1:


For enumeration value you need to use <jaxb:typesafeEnumMember value="10000" /> (check example here) and for simple type conversion you need to use <jaxb:baseType name="int" /> (check example there).

P.S. Java does not support unsigned ints. Also don't forget to define jaxb namespace xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" in your <xsd:schema>.



来源:https://stackoverflow.com/questions/10041393/can-i-configure-xjc-compiler-to-consume-custom-xml-bindings-for-inline-customiza

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!