public class SchemaGen
extends java.lang.Object
public
access,
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 the main(String[])
method with an appropriate argument list.Modifier and Type | Field and Description |
---|---|
private java.util.Map |
m_classSimpletypes
Map from fully-qualified class name to qualified simple type name.
|
private ValidationContext |
m_context
Validation context for bindings.
|
private GlobalCustom |
m_custom
Binding customization information.
|
private DetailDirectory |
m_detailDirectory
Details for mappings and enum usages.
|
private FormatterCache |
m_formatCache
JavaDoc formatter instance cache.
|
private IClassLocator |
m_locator
Locator for class information (
null if none). |
private java.util.Map |
m_uriNames
Map from namespace to schema file name.
|
private java.util.Map |
m_uriSchemas
Map from namespace to schema holder.
|
Constructor and Description |
---|
SchemaGen(IClassLocator loc,
GlobalCustom custom,
java.util.Map urinames)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private static void |
addCompositorPart(CommonCompositorDefinition part,
CommonCompositorDefinition comp)
Add a compositor as a particle in another compositor.
|
private void |
addDocumentation(IClass info,
AnnotatedBase root)
Add class-level documentation to a schema component.
|
private void |
addItemDocumentation(StructureElementBase struct,
AnnotatedBase elem)
Add documentation for a particular field or property.
|
private void |
addItemDocumentation(ValueElement value,
AnnotatedBase elem)
Add documentation for a particular field or property.
|
private void |
addMapping(MappingDetail detail)
Add mapping to schema definitions.
|
private ComplexTypeElement |
buildComplexType(MappingDetail detail,
SchemaHolder hold)
Build the complex type definition for a mapping.
|
private CommonCompositorDefinition |
buildCompositor(ContainerElementBase cont,
int offset,
boolean repeat,
SchemaHolder hold)
Build compositor for type definition.
|
private ElementElement |
buildElement(IComponent comp,
boolean repeat,
SchemaHolder hold)
Build a schema element description from a binding content component.
|
java.util.ArrayList |
buildSchemas(java.util.List bindings)
Generate a list of schemas from a list of bindings.
|
private SimpleTypeElement |
buildSimpleType(IClass type)
Create the simple type definition for a type.
|
private SimpleTypeElement |
buildSimpleType(IComponent comp)
Convenience method to create the simple type definition for the type of a component.
|
private void |
checkDependency(QName qname,
SchemaHolder hold)
Check for dependency on another schema.
|
private void |
fillAttributes(ContainerElementBase cont,
int offset,
java.util.AbstractList attrs,
SchemaHolder hold)
Build attributes as part of complex type definition.
|
SchemaHolder |
findSchema(java.lang.String uri)
Find the schema to be used for a particular namespace.
|
java.util.ArrayList |
finishSchemas(java.util.Collection exists)
Finish the construction of schemas, setting links between the schemas and validating the schemas.
|
java.util.List |
generate(java.util.List bindings)
Generate a list of schemas from a list of bindings.
|
MappingDetail |
getMappingDetail(MappingElement map)
Get details of schema handling of a mapping.
|
private QName |
getSimpleTypeQName(IComponent comp)
Get the qualified name of the simple type used for a component, if a named simple type.
|
private static boolean |
isComplexContent(ContainerElementBase cont)
Check if a container element of the binding represents complex content.
|
private static boolean |
isDifferentSchema(QName qname,
SchemaHolder hold)
Check if a name references a different schema.
|
private static boolean |
isEqual(java.lang.Object a,
java.lang.Object b)
General object comparison method.
|
static void |
main(java.lang.String[] args)
Run the schema generation using command line parameters.
|
private void |
setAttributeType(QName qname,
AttributeElement elem,
SchemaHolder hold)
Set attribute type, adding schema reference if necessary.
|
private void |
setComplexExtensionBase(QName qname,
ComplexExtensionElement ext,
SchemaHolder hold)
Set the base for a complex extension type.
|
private void |
setDocumentation(IClassItem item,
AnnotatedBase elem)
Set the documentation for a schema component matching a class member.
|
private void |
setElementRef(QName qname,
ElementElement elem,
SchemaHolder hold)
Set element reference, adding schema reference if necessary.
|
void |
setElementType(QName qname,
ElementElement elem,
SchemaHolder hold)
Set element type, adding schema reference if necessary.
|
private void |
setGroupRef(QName qname,
AttributeGroupRefElement group,
SchemaHolder hold)
Set group reference, adding schema reference if necessary.
|
private void |
setGroupRef(QName qname,
GroupRefElement group,
SchemaHolder hold)
Set group reference, adding schema reference if necessary.
|
private void |
setSimpleExtensionBase(QName qname,
SimpleExtensionElement ext,
SchemaHolder hold)
Set the base for a simple extension type.
|
private void |
setSubstitutionGroup(QName qname,
ElementElement elem,
SchemaHolder hold)
Set element substitution group, adding schema reference if necessary.
|
static void |
writeSchemas(java.io.File dir,
java.util.Collection schemas)
Write a collection of schemas to a target directory.
|
private final IClassLocator m_locator
null
if none).private final GlobalCustom m_custom
private final java.util.Map m_classSimpletypes
private final java.util.Map m_uriNames
private final java.util.Map m_uriSchemas
private final FormatterCache m_formatCache
private final ValidationContext m_context
private final DetailDirectory m_detailDirectory
public SchemaGen(IClassLocator loc, GlobalCustom custom, java.util.Map urinames)
loc
- locator for class information (null
if none)custom
- binding customization information (used for creating names as needed)urinames
- map from namespace URI to schema file namepublic SchemaHolder findSchema(java.lang.String uri)
uri
- namespace URI (null
if no namespace)private QName getSimpleTypeQName(IComponent comp)
null
, the buildSimpleType(IComponent)
method needs to be able to construct the
appropriate simple type definition.comp
- null
if inline definition neededprivate void addDocumentation(IClass info, AnnotatedBase root)
info
- class information (null
if not available)root
- private void setDocumentation(IClassItem item, AnnotatedBase elem)
item
- elem
- private void addItemDocumentation(StructureElementBase struct, AnnotatedBase elem)
struct
- elem
- private void addItemDocumentation(ValueElement value, AnnotatedBase elem)
value
- elem
- private SimpleTypeElement buildSimpleType(IClass type)
getSimpleTypeQName(IComponent)
returns null
. 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.type
- private SimpleTypeElement buildSimpleType(IComponent comp)
comp
- private static boolean isEqual(java.lang.Object a, java.lang.Object b)
a
- first object to be comparedb
- second object to be comparedtrue
if both objects are null
, or if a.equals(b)
;
false
otherwiseprivate static boolean isDifferentSchema(QName qname, SchemaHolder hold)
qname
- name to be checkedhold
- schema holdertrue
if different, false
if the sameprivate void checkDependency(QName qname, SchemaHolder hold)
qname
- name referenced by this schemahold
- schema holderprivate ElementElement buildElement(IComponent comp, boolean repeat, SchemaHolder hold)
comp
- source componentrepeat
- repeated element flaghold
- private static void addCompositorPart(CommonCompositorDefinition part, CommonCompositorDefinition comp)
part
- compositor being added as a particlecomp
- target compositor for addprivate CommonCompositorDefinition buildCompositor(ContainerElementBase cont, int offset, boolean repeat, SchemaHolder hold)
cont
- container element defining structureoffset
- offset for first child component to processrepeat
- repeated item flaghold
- holder for schema under constructionprivate void setGroupRef(QName qname, AttributeGroupRefElement group, SchemaHolder hold)
qname
- reference namegroup
- hold
- schema holderprivate void setGroupRef(QName qname, GroupRefElement group, SchemaHolder hold)
qname
- reference namegroup
- hold
- schema holderprivate void setElementRef(QName qname, ElementElement elem, SchemaHolder hold)
qname
- reference nameelem
- hold
- schema holderprivate void setAttributeType(QName qname, AttributeElement elem, SchemaHolder hold)
qname
- type nameelem
- hold
- schema holderpublic void setElementType(QName qname, ElementElement elem, SchemaHolder hold)
qname
- type nameelem
- hold
- schema holderprivate void setSubstitutionGroup(QName qname, ElementElement elem, SchemaHolder hold)
qname
- substitution group element nameelem
- hold
- schema holderprivate void fillAttributes(ContainerElementBase cont, int offset, java.util.AbstractList attrs, SchemaHolder hold)
cont
- container element defining structureoffset
- offset for first child component to processattrs
- complex type attribute listhold
- holder for schema under constructionprivate static boolean isComplexContent(ContainerElementBase cont)
cont
- true
if complex content, false
if notprivate ComplexTypeElement buildComplexType(MappingDetail detail, SchemaHolder hold)
detail
- mapping detailhold
- target schema for definitionprivate void setComplexExtensionBase(QName qname, ComplexExtensionElement ext, SchemaHolder hold)
qname
- ext
- hold
- private void setSimpleExtensionBase(QName qname, SimpleExtensionElement ext, SchemaHolder hold)
qname
- ext
- hold
- private void addMapping(MappingDetail detail)
detail
- public java.util.ArrayList buildSchemas(java.util.List bindings)
bindings
- list of BindingElement
SchemaHolder
public java.util.ArrayList finishSchemas(java.util.Collection exists)
exists
- existing schemas potentially referenced (by name, rather than id) from constructed schemasSchemaHolder
public java.util.List generate(java.util.List bindings)
buildSchemas(List)
with a call to finishSchemas(Collection)
with an empty list of existing
schemas.bindings
- list of BindingElement
SchemaHolder
public MappingDetail getMappingDetail(MappingElement map)
map
- public static void writeSchemas(java.io.File dir, java.util.Collection schemas) throws JiBXException, java.io.IOException
dir
- target directoryschemas
- list of SchemaHolder
JiBXException
java.io.IOException
public static void main(java.lang.String[] args) throws JiBXException, java.io.IOException
args
- JiBXException
java.io.IOException