Class XsdEnumerationAnnotationProcessor

  • All Implemented Interfaces:
    NodeProcessor

    public class XsdEnumerationAnnotationProcessor
    extends Object
    implements NodeProcessor

    Node processor that injects XSD documentation annotations consisting of JavaDoc harvested Java source code into SimpleTypes, Elements and Attributes typically produced by SchemaGen when generate XSDs for Java Enumerations. The documentation is injected as follows:

    1. SimpleType: Class-level JavaDoc from the corresponding type is injected as an annotation directly inside the SimpleType.
    2. Element: Field-level JavaDoc (or getter Method-level JavaDoc, in case the Field does not contain a JavaDoc annotation) from the corresponding member is injected as an annotation directly inside the element.
    3. Attribute: Field-level JavaDoc (or getter Method-level JavaDoc, in case the Field does not contain a JavaDoc annotation) from the corresponding member is injected as an annotation directly inside the element.

    Thus, the following 'vanilla'-generated XSD:

         
               <xs:simpleType name="foodPreference">
                   <xs:restriction base="xs:string">
                       <xs:enumeration value="NONE"/>
                       <xs:enumeration value="VEGAN"/>
                       <xs:enumeration value="LACTO_VEGETARIAN"/>
                   </xs:restriction>
               </xs:simpleType>
         
     

    ... will be converted in a manner similar to the one below:

         
             <xs:simpleType name="foodPreference">
                 <xs:annotation>
                     <xs:documentation><![CDATA[Simple enumeration example defining some Food preferences.]]></xs:documentation>
                 </xs:annotation>
                 <xs:restriction base="xs:string">
                     <xs:enumeration value="LACTO_VEGETARIAN">
                         <xs:annotation>
                             <xs:documentation><![CDATA[Vegetarian who will not eat meats, but drinks milk.]]></xs:documentation>
                         </xs:annotation>
                     </xs:enumeration>
                     <xs:enumeration value="NONE">
                         <xs:annotation>
                             <xs:documentation><![CDATA[No special food preferences; eats everything.]]></xs:documentation>
                         </xs:annotation>
                     </xs:enumeration>
                     <xs:enumeration value="VEGAN">
                         <xs:annotation>
                             <xs:documentation><![CDATA[Vegan who will neither eat meats nor drink milk.]]></xs:documentation>
                         </xs:annotation>
                     </xs:enumeration>
                 </xs:restriction>
             </xs:simpleType>
         
     

    ... given that the Java class FoodPreference has JavaDoc on its class and fields corresponding to the injected XSD annotation/documentation elements.

    Author:
    Lennart Jörelid, jGuru Europe AB
    • Constructor Detail

      • XsdEnumerationAnnotationProcessor

        public XsdEnumerationAnnotationProcessor​(SearchableDocumentation docs,
                                                 JavaDocRenderer renderer)
        Creates an XsdEnumerationAnnotationProcessor that uses the supplied/generated SearchableDocumentation to read all JavaDoc structures and the supplied JavaDocRenderer to render JavaDocs into XSD documentation annotations.
        Parameters:
        docs - A non-null SearchableDocumentation, produced from the source code of the JAXB compilation unit.
        renderer - A non-null JavaDocRenderer, used to render the JavaDocData within the SearchableDocumentation.
    • Method Detail

      • accept

        public boolean accept​(Node aNode)

        Only accept simpleTypes which are restrictions to either xs:string or xs:integer. The former is generated by JAXB when the Java Enum uses String values, and the latter is used for ordinal values.

        Defines if this visitor should process the provided node.
        Specified by:
        accept in interface NodeProcessor
        Parameters:
        aNode - The DOM node to process.
        Returns:
        true if the provided Node should be processed by this NodeProcessor.
      • process

        public void process​(Node aNode)
        Processes the provided DOM Node.
        Specified by:
        process in interface NodeProcessor
        Parameters:
        aNode - The DOM Node to process.