Package org.jibx.binding
Class SchemaGenerator
java.lang.Object
org.jibx.binding.SchemaGenerator
Binding generator. This loads the specified input classes and processes them
to generate a default binding definition.
- Author:
- Dennis M. Sosnoski
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static String
Generator version.private IClassLocator
Locator for finding classes referenced by binding.private Document
Document used for all schema definitions.private String
Indentation sequence per level of nesting.private boolean
Use qualified attributes default in schema flag.private boolean
Use qualified elements default in schema flag.private HashMap
Map from namespaces to schemas.private ObjectStack
Stack of structure definitions in progress (used to detect cycles).private boolean
Show verbose output flag.private static HashMap
Set of object types mapped to schema types.private static HashMap
Set of primitive types mapped to schema types.static final String
Fixed XML namespace.static final String
Fixed XML namespace namespace.private static final String
Schema namespace URI. -
Constructor Summary
ConstructorsConstructorDescriptionSchemaGenerator
(boolean verbose, boolean equal, boolean aqual, ArrayList paths) Constructor with settings specified.SchemaGenerator
(ArrayList paths) Constructor with only paths supplied. -
Method Summary
Modifier and TypeMethodDescriptionprivate Element
addChildElement
(Element parent, String name) Add child element with appropriate indentation.private void
addComment
(Element parent, String text) Add comment with appropriate indentation.private void
defineEmptyStructureComponent
(StructureElementBase comp, Element egroup, Element agroup) Process a structure component (structure or collection element) with no name and no child components.private void
defineList
(ArrayList comps, Element egroup, Element agroup, boolean mult) Create the schema definition list for a binding component list.private Element
defineNestedStructure
(ContainerElementBase container, Element parent) Create the schema definition for a nested structure.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.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.Get innermost containing definition context.Element[]
Get array of generated schemas.private void
indentForClose
(Element parent) Generate indentation to proper depth for current item.static void
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 String
simpleClassName
(String cname) Get simple class name.
-
Field Details
-
CURRENT_VERSION
Generator version. -
XSD_URI
Schema namespace URI.- See Also:
-
XML_URI
Fixed XML namespace.- See Also:
-
XMLNS_URI
Fixed XML namespace namespace.- See Also:
-
s_objectTypeMap
Set of object types mapped to schema types. -
s_primitiveTypeMap
Set of primitive types mapped to schema types. -
m_verbose
private boolean m_verboseShow verbose output flag. -
m_isElementQualified
private boolean m_isElementQualifiedUse qualified elements default in schema flag. -
m_isAttributeQualified
private boolean m_isAttributeQualifiedUse qualified attributes default in schema flag. -
m_indentSequence
Indentation sequence per level of nesting. -
m_schemaMap
Map from namespaces to schemas. -
m_classLocator
Locator for finding classes referenced by binding. -
m_document
Document used for all schema definitions. -
m_structureStack
Stack of structure definitions in progress (used to detect cycles).
-
-
Constructor Details
-
SchemaGenerator
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
Constructor with settings specified.- Parameters:
verbose
- report binding details and resultsequal
- use element form default qualified flagaqual
- use attribute form default qualified flagpaths
- 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
Get array of generated schemas.- Returns:
- array of schema elements
-
indentForClose
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
Add comment with appropriate indentation.- Parameters:
parent
- element to contain indented child itemtext
- comment text
-
addChildElement
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 itemname
- child element name
-
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 processedegroup
- schema element to contain element definitionsagroup
- 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 processedegroup
- schema element to contain element definitionsagroup
- schema element to contain attribute definitionsmult
- allow any number of occurrences of components flag
-
defineList
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 listegroup
- schema element to contain element definitionsagroup
- schema element to contain attribute definitionsmult
- allow any number of occurrences of components flag
-
defineNestedStructure
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 structureparent
- schema element to hold the definition- Returns:
- constructed complex type
-
generateSchema
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
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
Get simple class name.- Parameters:
cname
- class name with full package specification- Returns:
- class name only
-
main
Main method for running compiler as application.- Parameters:
args
- command line arguments
-