JAXB - Can XJC compile appinfo into a class structure?

I have a circuit that is read by several different forms generation applications; one of them uses JAXB / XJC to compile its class structure. The schema contains appinfo information for friendly field names, for example:

<xs:element name="HomeAddress" type="xs:string">
  <xs:annotation>
    <xs:appinfo>Home address</xs:appinfo>
  </xs:annotation>
</xs:element>

Is there a way to get XJC to compile this information?

+5
source share
2 answers

You can use the Annotate plugin to add arbitrary Java annotations to your schema-based classes. With this plugin you can control the syntax, for example:

<xs:element name="HomeAddress" type="xs:string">
  <xs:annotation>
    <xs:appinfo>
      <ann:annotate xmlns:ann="http://annox.dev.java.net/com.acme.foo">
        <my:Label value="Home address"/>
      </ann:annotate>
    </xs:appinfo>
  </xs:annotation>
</xs:element>

And you get something like:

@Label("Home address") // FQCN is com.acme.foo.Label
public String getHomeAddress(...) {}
+5
source

All Articles