Package org.jibx.schema.generator
Class SchemaGen
- java.lang.Object
-
- org.jibx.schema.generator.SchemaGen
-
public class SchemaGen extends java.lang.ObjectSchema generator from binding definition. Although many of the methods in this class usepublicaccess, they are intended for use only by the JiBX developers and may change from one release to the next. To make use of this class from your own code, call themain(String[])method with an appropriate argument list.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Mapm_classSimpletypesMap from fully-qualified class name to qualified simple type name.private ValidationContextm_contextValidation context for bindings.private GlobalCustomm_customBinding customization information.private DetailDirectorym_detailDirectoryDetails for mappings and enum usages.private FormatterCachem_formatCacheJavaDoc formatter instance cache.private IClassLocatorm_locatorLocator for class information (nullif none).private java.util.Mapm_uriNamesMap from namespace to schema file name.private java.util.Mapm_uriSchemasMap from namespace to schema holder.
-
Constructor Summary
Constructors Constructor Description SchemaGen(IClassLocator loc, GlobalCustom custom, java.util.Map urinames)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static voidaddCompositorPart(CommonCompositorDefinition part, CommonCompositorDefinition comp)Add a compositor as a particle in another compositor.private voidaddDocumentation(IClass info, AnnotatedBase root)Add class-level documentation to a schema component.private voidaddItemDocumentation(StructureElementBase struct, AnnotatedBase elem)Add documentation for a particular field or property.private voidaddItemDocumentation(ValueElement value, AnnotatedBase elem)Add documentation for a particular field or property.private voidaddMapping(MappingDetail detail)Add mapping to schema definitions.private ComplexTypeElementbuildComplexType(MappingDetail detail, SchemaHolder hold)Build the complex type definition for a mapping.private CommonCompositorDefinitionbuildCompositor(ContainerElementBase cont, int offset, boolean repeat, SchemaHolder hold)Build compositor for type definition.private ElementElementbuildElement(IComponent comp, boolean repeat, SchemaHolder hold)Build a schema element description from a binding content component.java.util.ArrayListbuildSchemas(java.util.List bindings)Generate a list of schemas from a list of bindings.private SimpleTypeElementbuildSimpleType(IComponent comp)Convenience method to create the simple type definition for the type of a component.private SimpleTypeElementbuildSimpleType(IClass type)Create the simple type definition for a type.private voidcheckDependency(QName qname, SchemaHolder hold)Check for dependency on another schema.private voidfillAttributes(ContainerElementBase cont, int offset, java.util.AbstractList attrs, SchemaHolder hold)Build attributes as part of complex type definition.SchemaHolderfindSchema(java.lang.String uri)Find the schema to be used for a particular namespace.java.util.ArrayListfinishSchemas(java.util.Collection exists)Finish the construction of schemas, setting links between the schemas and validating the schemas.java.util.Listgenerate(java.util.List bindings)Generate a list of schemas from a list of bindings.MappingDetailgetMappingDetail(MappingElement map)Get details of schema handling of a mapping.private QNamegetSimpleTypeQName(IComponent comp)Get the qualified name of the simple type used for a component, if a named simple type.private static booleanisComplexContent(ContainerElementBase cont)Check if a container element of the binding represents complex content.private static booleanisDifferentSchema(QName qname, SchemaHolder hold)Check if a name references a different schema.private static booleanisEqual(java.lang.Object a, java.lang.Object b)General object comparison method.static voidmain(java.lang.String[] args)Run the schema generation using command line parameters.private voidsetAttributeType(QName qname, AttributeElement elem, SchemaHolder hold)Set attribute type, adding schema reference if necessary.private voidsetComplexExtensionBase(QName qname, ComplexExtensionElement ext, SchemaHolder hold)Set the base for a complex extension type.private voidsetDocumentation(IClassItem item, AnnotatedBase elem)Set the documentation for a schema component matching a class member.private voidsetElementRef(QName qname, ElementElement elem, SchemaHolder hold)Set element reference, adding schema reference if necessary.voidsetElementType(QName qname, ElementElement elem, SchemaHolder hold)Set element type, adding schema reference if necessary.private voidsetGroupRef(QName qname, AttributeGroupRefElement group, SchemaHolder hold)Set group reference, adding schema reference if necessary.private voidsetGroupRef(QName qname, GroupRefElement group, SchemaHolder hold)Set group reference, adding schema reference if necessary.private voidsetSimpleExtensionBase(QName qname, SimpleExtensionElement ext, SchemaHolder hold)Set the base for a simple extension type.private voidsetSubstitutionGroup(QName qname, ElementElement elem, SchemaHolder hold)Set element substitution group, adding schema reference if necessary.static voidwriteSchemas(java.io.File dir, java.util.Collection schemas)Write a collection of schemas to a target directory.
-
-
-
Field Detail
-
m_locator
private final IClassLocator m_locator
Locator for class information (nullif none).
-
m_custom
private final GlobalCustom m_custom
Binding customization information.
-
m_classSimpletypes
private final java.util.Map m_classSimpletypes
Map from fully-qualified class name to qualified simple type name.
-
m_uriNames
private final java.util.Map m_uriNames
Map from namespace to schema file name.
-
m_uriSchemas
private final java.util.Map m_uriSchemas
Map from namespace to schema holder.
-
m_formatCache
private final FormatterCache m_formatCache
JavaDoc formatter instance cache.
-
m_context
private final ValidationContext m_context
Validation context for bindings.
-
m_detailDirectory
private final DetailDirectory m_detailDirectory
Details for mappings and enum usages.
-
-
Constructor Detail
-
SchemaGen
public SchemaGen(IClassLocator loc, GlobalCustom custom, java.util.Map urinames)
Constructor.- Parameters:
loc- locator for class information (nullif none)custom- binding customization information (used for creating names as needed)urinames- map from namespace URI to schema file name
-
-
Method Detail
-
findSchema
public SchemaHolder findSchema(java.lang.String uri)
Find the schema to be used for a particular namespace. If this is the first time a particular namespace was requested, a new schema will be created for that namespace and returned.- Parameters:
uri- namespace URI (nullif no namespace)- Returns:
- schema holder
-
getSimpleTypeQName
private QName getSimpleTypeQName(IComponent comp)
Get the qualified name of the simple type used for a component, if a named simple type. If this returnsnull, thebuildSimpleType(IComponent)method needs to be able to construct the appropriate simple type definition.- Parameters:
comp-- Returns:
- qualified type name,
nullif inline definition needed
-
addDocumentation
private void addDocumentation(IClass info, AnnotatedBase root)
Add class-level documentation to a schema component.- Parameters:
info- class information (nullif not available)root-
-
setDocumentation
private void setDocumentation(IClassItem item, AnnotatedBase elem)
Set the documentation for a schema component matching a class member.- Parameters:
item-elem-
-
addItemDocumentation
private void addItemDocumentation(StructureElementBase struct, AnnotatedBase elem)
Add documentation for a particular field or property.- Parameters:
struct-elem-
-
addItemDocumentation
private void addItemDocumentation(ValueElement value, AnnotatedBase elem)
Add documentation for a particular field or property.- Parameters:
value-elem-
-
buildSimpleType
private SimpleTypeElement buildSimpleType(IClass type)
Create the simple type definition for a type. This is only used for cases wheregetSimpleTypeQName(IComponent)returnsnull. The current implementation only supports Java 5 Enum types, but in the future should be extended to support <format>-type conversions with supplied schema definitions. This code requires a Java 5+ JVM to execute, but uses reflection to allow this class to be loaded on older JVMs.- Parameters:
type-- Returns:
- type definition
-
buildSimpleType
private SimpleTypeElement buildSimpleType(IComponent comp)
Convenience method to create the simple type definition for the type of a component.- Parameters:
comp-- Returns:
- type definition
-
isEqual
private static boolean isEqual(java.lang.Object a, java.lang.Object b)General object comparison method. Don't know why Sun hasn't seen fit to include this somewhere, but at least it's easy to write (over and over again).- Parameters:
a- first object to be comparedb- second object to be compared- Returns:
trueif both objects arenull, or ifa.equals(b);falseotherwise
-
isDifferentSchema
private static boolean isDifferentSchema(QName qname, SchemaHolder hold)
Check if a name references a different schema.- Parameters:
qname- name to be checkedhold- schema holder- Returns:
trueif different,falseif the same
-
checkDependency
private void checkDependency(QName qname, SchemaHolder hold)
Check for dependency on another schema. This creates an import for the target schema, and assigns a prefix for referencing the target schema namespace.- Parameters:
qname- name referenced by this schemahold- schema holder
-
buildElement
private ElementElement buildElement(IComponent comp, boolean repeat, SchemaHolder hold)
Build a schema element description from a binding content component.- Parameters:
comp- source componentrepeat- repeated element flaghold-- Returns:
- element
-
addCompositorPart
private static void addCompositorPart(CommonCompositorDefinition part, CommonCompositorDefinition comp)
Add a compositor as a particle in another compositor. If the compositor being added has only one particle, the particle is directly added to the containing compositor.- Parameters:
part- compositor being added as a particlecomp- target compositor for add
-
buildCompositor
private CommonCompositorDefinition buildCompositor(ContainerElementBase cont, int offset, boolean repeat, SchemaHolder hold)
Build compositor for type definition. This creates and returns the appropriate form of compositor for the container, populated with particles matching the child element components of the binding container.- Parameters:
cont- container element defining structureoffset- offset for first child component to processrepeat- repeated item flaghold- holder for schema under construction- Returns:
- constructed compositor
-
setGroupRef
private void setGroupRef(QName qname, AttributeGroupRefElement group, SchemaHolder hold)
Set group reference, adding schema reference if necessary.- Parameters:
qname- reference namegroup-hold- schema holder
-
setGroupRef
private void setGroupRef(QName qname, GroupRefElement group, SchemaHolder hold)
Set group reference, adding schema reference if necessary.- Parameters:
qname- reference namegroup-hold- schema holder
-
setElementRef
private void setElementRef(QName qname, ElementElement elem, SchemaHolder hold)
Set element reference, adding schema reference if necessary.- Parameters:
qname- reference nameelem-hold- schema holder
-
setAttributeType
private void setAttributeType(QName qname, AttributeElement elem, SchemaHolder hold)
Set attribute type, adding schema reference if necessary.- Parameters:
qname- type nameelem-hold- schema holder
-
setElementType
public void setElementType(QName qname, ElementElement elem, SchemaHolder hold)
Set element type, adding schema reference if necessary.- Parameters:
qname- type nameelem-hold- schema holder
-
setSubstitutionGroup
private void setSubstitutionGroup(QName qname, ElementElement elem, SchemaHolder hold)
Set element substitution group, adding schema reference if necessary.- Parameters:
qname- substitution group element nameelem-hold- schema holder
-
fillAttributes
private void fillAttributes(ContainerElementBase cont, int offset, java.util.AbstractList attrs, SchemaHolder hold)
Build attributes as part of complex type definition.- Parameters:
cont- container element defining structureoffset- offset for first child component to processattrs- complex type attribute listhold- holder for schema under construction
-
isComplexContent
private static boolean isComplexContent(ContainerElementBase cont)
Check if a container element of the binding represents complex content.- Parameters:
cont-- Returns:
trueif complex content,falseif not
-
buildComplexType
private ComplexTypeElement buildComplexType(MappingDetail detail, SchemaHolder hold)
Build the complex type definition for a mapping.- Parameters:
detail- mapping detailhold- target schema for definition- Returns:
- constructed complex type
-
setComplexExtensionBase
private void setComplexExtensionBase(QName qname, ComplexExtensionElement ext, SchemaHolder hold)
Set the base for a complex extension type.- Parameters:
qname-ext-hold-
-
setSimpleExtensionBase
private void setSimpleExtensionBase(QName qname, SimpleExtensionElement ext, SchemaHolder hold)
Set the base for a simple extension type.- Parameters:
qname-ext-hold-
-
addMapping
private void addMapping(MappingDetail detail)
Add mapping to schema definitions. This generates the appropriate schema representation for the mapping based on the detail flags, which may include group and/or attributeGroup, complexType, and element definitions.- Parameters:
detail-
-
buildSchemas
public java.util.ArrayList buildSchemas(java.util.List bindings)
Generate a list of schemas from a list of bindings. The two lists are not necessarily in any particular relationship to each other.- Parameters:
bindings- list ofBindingElement- Returns:
- list of
SchemaHolder
-
finishSchemas
public java.util.ArrayList finishSchemas(java.util.Collection exists)
Finish the construction of schemas, setting links between the schemas and validating the schemas.- Parameters:
exists- existing schemas potentially referenced (by name, rather than id) from constructed schemas- Returns:
- list of
SchemaHolder
-
generate
public java.util.List generate(java.util.List bindings)
Generate a list of schemas from a list of bindings. The two lists are not necessarily in any particular relationship to each other. This method is provided for backward compatibility; it just combines a call tobuildSchemas(List)with a call tofinishSchemas(Collection)with an empty list of existing schemas.- Parameters:
bindings- list ofBindingElement- Returns:
- list of
SchemaHolder
-
getMappingDetail
public MappingDetail getMappingDetail(MappingElement map)
Get details of schema handling of a mapping.- Parameters:
map-- Returns:
- mapping details
-
writeSchemas
public static void writeSchemas(java.io.File dir, java.util.Collection schemas) throws JiBXException, java.io.IOExceptionWrite a collection of schemas to a target directory.- Parameters:
dir- target directoryschemas- list ofSchemaHolder- Throws:
JiBXExceptionjava.io.IOException
-
main
public static void main(java.lang.String[] args) throws JiBXException, java.io.IOExceptionRun the schema generation using command line parameters.- Parameters:
args-- Throws:
JiBXExceptionjava.io.IOException
-
-