Class SchemaGenerator

java.lang.Object
org.jibx.binding.SchemaGenerator

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

    • CURRENT_VERSION

      private static String CURRENT_VERSION
      Generator version.
    • XSD_URI

      private static final String XSD_URI
      Schema namespace URI.
      See Also:
    • XML_URI

      public static final String XML_URI
      Fixed XML namespace.
      See Also:
    • XMLNS_URI

      public static final String XMLNS_URI
      Fixed XML namespace namespace.
      See Also:
    • s_objectTypeMap

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

      private static 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 String m_indentSequence
      Indentation sequence per level of nesting.
    • m_schemaMap

      private HashMap m_schemaMap
      Map from namespaces to schemas.
    • m_classLocator

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

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

    • SchemaGenerator

      public SchemaGenerator(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, 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 Details

    • 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 Element[] getSchemas()
      Get array of generated schemas.
      Returns:
      array of schema elements
    • indentForClose

      private void indentForClose(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(Element parent, String text)
      Add comment with appropriate indentation.
      Parameters:
      parent - element to contain indented child item
      text - comment text
    • addChildElement

      private Element addChildElement(Element parent, 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, Element egroup, 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, Element egroup, 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(ArrayList comps, Element egroup, 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 Element defineNestedStructure(ContainerElementBase container, 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 String simpleClassName(String cname)
      Get simple class name.
      Parameters:
      cname - class name with full package specification
      Returns:
      class name only
    • main

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