users@jaxb.java.net

schemagen and xsd documentation annotations

From: Naz Quadri <Nazeem.Quadri_at_morganstanley.com>
Date: Tue, 05 Jun 2007 17:32:08 +0100

Hi,
 
I have a set of Java classes which are being used to create an xml
schema using schemagen, or more specifically
JAXBContext.generateSchema(). I would like to be able to add comments to
my classes as annotations if possible and have these injected into the
generated schema as documentation annotations. I'm pretty certain there
is no Java annotation to do this but see below for how it might look
with an invented annotation.
 
If this is not possible is there any other way ? Would it be possible to
write the class and field comments into an xml file and hook into the
schemagen process and inject the comments into the schema by using a
plugin of some kind ?
 
Thoughts ?
 
Thanks
 
 
 
*Java class :-*
 
@XMLDocumentation("*Defines a Person*")
public class Person
{

  @XMLDocumentation("*Age of Person*")
  public int age;
 
  @XMLDocumentation("*Name of Person*")
  public String name;
 
}

*Generated Schema :-*

    <xs:complexType name="Person">
        <xs:annotation>
            <xs:documentation>*Defines a Person*</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="age" type="xs:int">
                <xs:annotation>
                    <xs:documentation>*Age of the person*</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="name" type="xs:string">
                <xs:annotation>
                    <xs:documentation>*Name of the
person*</xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>