Class SchemaGenerator


  • public class SchemaGenerator
    extends java.lang.Object
    Binding generator. This loads the specified input classes and processes them to generate a default binding definition.
    Author:
    Dennis M. Sosnoski
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String CURRENT_VERSION
      Generator version.
      private IClassLocator m_classLocator
      Locator for finding classes referenced by binding.
      private org.w3c.dom.Document m_document
      Document used for all schema definitions.
      private java.lang.String m_indentSequence
      Indentation sequence per level of nesting.
      private boolean m_isAttributeQualified
      Use qualified attributes default in schema flag.
      private boolean m_isElementQualified
      Use qualified elements default in schema flag.
      private java.util.HashMap m_schemaMap
      Map from namespaces to schemas.
      private ObjectStack m_structureStack
      Stack of structure definitions in progress (used to detect cycles).
      private boolean m_verbose
      Show verbose output flag.
      private static java.util.HashMap s_objectTypeMap
      Set of object types mapped to schema types.
      private static java.util.HashMap s_primitiveTypeMap
      Set of primitive types mapped to schema types.
      static java.lang.String XML_URI
      Fixed XML namespace.
      static java.lang.String XMLNS_URI
      Fixed XML namespace namespace.
      private static java.lang.String XSD_URI
      Schema namespace URI.
    • Constructor Summary

      Constructors 
      Constructor Description
      SchemaGenerator​(boolean verbose, boolean equal, boolean aqual, java.util.ArrayList paths)
      Constructor with settings specified.
      SchemaGenerator​(java.util.ArrayList paths)
      Constructor with only paths supplied.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private org.w3c.dom.Element addChildElement​(org.w3c.dom.Element parent, java.lang.String name)
      Add child element with appropriate indentation.
      private void addComment​(org.w3c.dom.Element parent, java.lang.String text)
      Add comment with appropriate indentation.
      private void defineEmptyStructureComponent​(StructureElementBase comp, org.w3c.dom.Element egroup, org.w3c.dom.Element agroup)
      Process a structure component (structure or collection element) with no name and no child components.
      private void defineList​(java.util.ArrayList comps, org.w3c.dom.Element egroup, org.w3c.dom.Element agroup, boolean mult)
      Create the schema definition list for a binding component list.
      private org.w3c.dom.Element defineNestedStructure​(ContainerElementBase container, org.w3c.dom.Element parent)
      Create the schema definition for a nested structure.
      private void defineStructureComponent​(StructureElementBase comp, org.w3c.dom.Element egroup, org.w3c.dom.Element agroup, boolean mult)
      Process a structure component (structure or collection element) within a list of child components.
      void generate​(BindingElement binding)
      Process a binding definition for schema generation.
      private void generateSchema​(BindingElement binding)
      Generate a schema from a binding using supplied classpaths.
      DefinitionContext getDefinitions()
      Get innermost containing definition context.
      org.w3c.dom.Element[] getSchemas()
      Get array of generated schemas.
      private void indentForClose​(org.w3c.dom.Element parent)
      Generate indentation to proper depth for current item.
      static void main​(java.lang.String[] args)
      Main method for running compiler as application.
      void setAttributeQualified​(boolean qual)
      Set control flag for attribute qualified default schema.
      void setElementQualified​(boolean qual)
      Set control flag for element qualified default schema.
      void setVerbose​(boolean verbose)
      Set control flag for verbose processing reports.
      private java.lang.String simpleClassName​(java.lang.String cname)
      Get simple class name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CURRENT_VERSION

        private static java.lang.String CURRENT_VERSION
        Generator version.
      • XSD_URI

        private static final java.lang.String XSD_URI
        Schema namespace URI.
        See Also:
        Constant Field Values
      • XML_URI

        public static final java.lang.String XML_URI
        Fixed XML namespace.
        See Also:
        Constant Field Values
      • XMLNS_URI

        public static final java.lang.String XMLNS_URI
        Fixed XML namespace namespace.
        See Also:
        Constant Field Values
      • s_objectTypeMap

        private static java.util.HashMap s_objectTypeMap
        Set of object types mapped to schema types.
      • s_primitiveTypeMap

        private static java.util.HashMap s_primitiveTypeMap
        Set of primitive types mapped to schema types.
      • m_verbose

        private boolean m_verbose
        Show verbose output flag.
      • m_isElementQualified

        private boolean m_isElementQualified
        Use qualified elements default in schema flag.
      • m_isAttributeQualified

        private boolean m_isAttributeQualified
        Use qualified attributes default in schema flag.
      • m_indentSequence

        private java.lang.String m_indentSequence
        Indentation sequence per level of nesting.
      • m_schemaMap

        private java.util.HashMap m_schemaMap
        Map from namespaces to schemas.
      • m_classLocator

        private IClassLocator m_classLocator
        Locator for finding classes referenced by binding.
      • m_document

        private org.w3c.dom.Document m_document
        Document used for all schema definitions.
      • m_structureStack

        private ObjectStack m_structureStack
        Stack of structure definitions in progress (used to detect cycles).
    • Constructor Detail

      • SchemaGenerator

        public SchemaGenerator​(java.util.ArrayList paths)
        Constructor with only paths supplied. This just initializes all other options disabled.
        Parameters:
        paths - class paths to be checked for classes referenced by bindings
      • SchemaGenerator

        public SchemaGenerator​(boolean verbose,
                               boolean equal,
                               boolean aqual,
                               java.util.ArrayList paths)
        Constructor with settings specified.
        Parameters:
        verbose - report binding details and results
        equal - use element form default qualified flag
        aqual - use attribute form default qualified flag
        paths - class paths to be checked for classes referenced by bindings
    • Method Detail

      • setVerbose

        public void setVerbose​(boolean verbose)
        Set control flag for verbose processing reports.
        Parameters:
        verbose - report verbose information in processing bindings flag
      • setElementQualified

        public void setElementQualified​(boolean qual)
        Set control flag for element qualified default schema.
        Parameters:
        qual - element qualified default schemas flag
      • setAttributeQualified

        public void setAttributeQualified​(boolean qual)
        Set control flag for attribute qualified default schema.
        Parameters:
        qual - attribute qualified default schemas flag
      • getSchemas

        public org.w3c.dom.Element[] getSchemas()
        Get array of generated schemas.
        Returns:
        array of schema elements
      • indentForClose

        private void indentForClose​(org.w3c.dom.Element parent)
        Generate indentation to proper depth for current item. This creates the indentation text and appends it to the supplied parent. The generated indentation is appropriate for the close tag of the parent element; if a child element is to be added following this indentation it needs to use an additional leading indent.
        Parameters:
        parent - element to contain indented child item
      • addComment

        private void addComment​(org.w3c.dom.Element parent,
                                java.lang.String text)
        Add comment with appropriate indentation.
        Parameters:
        parent - element to contain indented child item
        text - comment text
      • addChildElement

        private org.w3c.dom.Element addChildElement​(org.w3c.dom.Element parent,
                                                    java.lang.String name)
        Add child element with appropriate indentation. This generates and returns the child element after adding it to the supplied parent, allowing further modification of the new child element.
        Parameters:
        parent - element to contain indented child item
        name - child element name
      • getDefinitions

        public DefinitionContext getDefinitions()
        Get innermost containing definition context.
        Returns:
        innermost definition context containing this element
      • defineEmptyStructureComponent

        private void defineEmptyStructureComponent​(StructureElementBase comp,
                                                   org.w3c.dom.Element egroup,
                                                   org.w3c.dom.Element agroup)
        Process a structure component (structure or collection element) with no name and no child components. This adds the appropriate type of element or any definition to the container schema element.
        Parameters:
        comp - structure component to be processed
        egroup - schema element to contain element definitions
        agroup - schema element to contain attribute definitions
      • defineStructureComponent

        private void defineStructureComponent​(StructureElementBase comp,
                                              org.w3c.dom.Element egroup,
                                              org.w3c.dom.Element agroup,
                                              boolean mult)
        Process a structure component (structure or collection element) within a list of child components. This adds the appropriate type of element or any definition to the container, if necessary calling other methods for recursive handling of nested child components.
        Parameters:
        comp - structure component to be processed
        egroup - schema element to contain element definitions
        agroup - schema element to contain attribute definitions
        mult - allow any number of occurrences of components flag
      • defineList

        private void defineList​(java.util.ArrayList comps,
                                org.w3c.dom.Element egroup,
                                org.w3c.dom.Element agroup,
                                boolean mult)
        Create the schema definition list for a binding component list. This builds the sequence of elements and attributes defined by the binding components, including nested complex types for elements with structure.
        Parameters:
        comps - binding component list
        egroup - schema element to contain element definitions
        agroup - schema element to contain attribute definitions
        mult - allow any number of occurrences of components flag
      • defineNestedStructure

        private org.w3c.dom.Element defineNestedStructure​(ContainerElementBase container,
                                                          org.w3c.dom.Element parent)
        Create the schema definition for a nested structure. This defines a complex type, if necessary calling itself recursively for elements which are themselves complex types. In the special case where the container element is a mapping which extends an abstract base class this generates the complex type as an extension of the base class complex type.
        Parameters:
        container - binding definition element containing nested structure
        parent - schema element to hold the definition
        Returns:
        constructed complex type
      • generateSchema

        private void generateSchema​(BindingElement binding)
        Generate a schema from a binding using supplied classpaths. If the schema for the binding namespace (or default namespace) already exists the definitions from this binding are added to the existing schema; otherwise a new schema is created and added to the collection defined.
        Parameters:
        binding - root element of binding
      • generate

        public void generate​(BindingElement binding)
                      throws JiBXException
        Process a binding definition for schema generation. This first validates the binding definition, and if it is valid then handles schema generation from the binding.
        Parameters:
        binding - root element of binding
        Throws:
        JiBXException - if error in generating the schema
      • simpleClassName

        private java.lang.String simpleClassName​(java.lang.String cname)
        Get simple class name.
        Parameters:
        cname - class name with full package specification
        Returns:
        class name only
      • main

        public static void main​(java.lang.String[] args)
        Main method for running compiler as application.
        Parameters:
        args - command line arguments