6

I have a schema which is read by a few different applications for form generation; one of them uses JAXB/XJC to compile its class structure. The schema contains appinfo information for friendly names of fields, eg:

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

Is there some way to get XJC to compile this information in?

  • In what way? What is your desired result in your example? – musiKk Sep 16 '10 at 09:51
  • It doesn't really matter, as long as I can access it at runtime from Java. By annotation (which I could grab with reflection) or by static member seem like the easiest. – S. R. Rankin Sep 16 '10 at 10:00

2 Answers2

7

You can use the Annotate plugin to add arbitrary Java annotations into your schema-derived classes. With this plugin you can manage a syntax like:

<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>

An you'll get something like:

@Label("Home address") // FQCN is com.acme.foo.Label
public String getHomeAddress(...) {}
Daniel Arthur
  • 456
  • 7
  • 17
lexicore
  • 42,748
  • 17
  • 132
  • 221
  • @lexicore : and if you can NOT modify schema because it's provided by 3rd party? – Artem Oboturov Apr 06 '12 at 08:15
  • @Artem Oboturov: You can do the same thing with binding files (`*.xjb`) without modifying the schema. – lexicore Apr 06 '12 at 11:46
  • @lexicore: yes you right. I clarified a bit more what I was thinking of in [http://stackoverflow.com/questions/10041393/can-i-configure-xjc-compiler-to-consume-custom-xml-bindings-for-inline-customiza](http://stackoverflow.com/questions/10041393/can-i-configure-xjc-compiler-to-consume-custom-xml-bindings-for-inline-customiza). Do you want to try that one? – Artem Oboturov Apr 06 '12 at 12:00
0

I am not aware of a way to do this using the XJC tool that comes with the JAXB reference implementation. However, XJC does allow you to create custom plugins that may let you do need to:

bdoughan
  • 147,609
  • 23
  • 300
  • 400