Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB - Can XJC compile appinfo into the class structure?

Tags:

xml

jaxb

xjc

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?

like image 551
S. R. Rankin Avatar asked Sep 16 '10 09:09

S. R. Rankin


People also ask

How do I use JAXB XJC?

Open a command prompt. Run the JAXB schema compiler, xjc command from the directory where the schema file is located. The xjc schema compiler tool is located in the app_server_root \bin\ directory. Use the generated JAXB objects within a Java application to manipulate XML content through the generated JAXB classes.

What is XJC Jaxb?

JAXB is an XML-to-Java binding technology that enables transformation between schema and Java objects and between XML instance documents and Java object instances. JAXB technology consists of a runtime API and accompanying tools that simplify access to XML documents.

What is XJC?

Compiles an XML schema file into fully annotated Java classes.

What is XJC simple?

XJC is a Java SE tool that compiles an XML schema file into fully annotated Java classes. It is distributed within the JDK package and is located at /bin/xjc path.


1 Answers

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(...) {}
like image 182
lexicore Avatar answered Sep 24 '22 06:09

lexicore