开发者

Need to generate JAXB annotions in package-info.java from binding file

I have an annotation for an XmlAdapter that I need to put in package-info.java.. The problem is, our p开发者_如何转开发ackage-info.java is automatically generated from XJC. Is there a way to use the JAXB binding file to automatically add this annotation to package-info.java when it is generated?

@javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters
({
    @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(value=Adapter.class,type=Original.class)
})

Thanks for your help!


Unfortunatelly the elegant syntax above does not work when defining customization elements in external binding files. Annotate Plugin provide you a way to read annotations from XJC binding customizations and add automatically in your XmlAdapter Classes. Therefore, your adapters classes will be added to your package-info.java.

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

  <jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
    ...
    <jaxb:bindings node="xs:complexType[@name='...']/xs:sequence/xs:element[@name='name']">
      <annox:annotate>
        <annox:annotate
          annox:class="org.hibernate.search.annotations.FieldBridge"
          impl="com.acme.foo.MyFieldBridge">
          <annox:annotate annox:field="params">
            <annox:annotate annox:class="org.hibernate.search.annotations.Parameter"
              name="foo"
              value="bar"/>
          </annox:annotate>
        </annox:annotate>
      </annox:annotate>
    </jaxb:bindings>
    ...
  </jaxb:bindings>

</jaxb:bindings>

Produces:

@FieldBridge(impl = com.acme.foo.MyFieldBridge.class, params = {
  @Parameter(name = "foo", value = "bar")
})

The other way is to add bindings to your schema: directly in schema files :

see Annotate Plugin

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜