Package org.jibx.schema.codegen
Class Refactory
- java.lang.Object
-
- org.jibx.schema.codegen.Refactory
-
public class Refactory extends java.lang.Object
Schema refactoring tool. Although many of the methods in this class usepublic
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 themain(String[])
method with an appropriate argument list.- Author:
- Dennis M. Sosnoski
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Refactory.SchemaNameFilter
File name pattern matcher.
-
Field Summary
Fields Modifier and Type Field Description private static long
BLOCK_NAME_INHERIT_MASK
Mask for schema elements which block name inheritance downward.private static QName[]
DEFAULT_REPLACEMENTS
Default type replacements applied.private BindingOrganizer
m_bindingDirectory
Directory for constructed bindings.private java.util.ArrayList
m_definitions
Definitions to be generated (may be global schema definitions, or reused nested components with classes).private SchemasetCustom
m_global
Code generation customizations.private java.io.File
m_schemaDir
Root directory for schemas.private java.net.URL
m_schemaRoot
Root URL for schemas.private java.io.File
m_targetDir
Target directory for code generation.private ValidationContext
m_validationContext
Context for loading and processing schemas.private static Logger
s_logger
Logger for class.private static long
TYPE_DEFINE_MASK
Mask for schema elements which define a type.private static long
TYPE_DERIVE_MASK
Mask for schema elements which derive from a type.
-
Constructor Summary
Constructors Constructor Description Refactory(SchemasetCustom custom, ValidationContext vctx)
Constructor used by tests.Refactory(RefactoryCommandLine parms)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
addCustomizedSchemas(java.net.URL base, java.io.File dir, SchemasetCustom custom, InsertionOrderedSet fileset)
Add the schemas specified by customizations to the set to be loaded.void
applyAndNormalize()
Apply extensions and normalize all schemas.boolean
customizeSchemas()
Validate and apply customizations to loaded schemas.private SchemasetCustom
findSchemaset(SchemaElement schema, SchemasetCustom custom)
Find the most specific schemaset owning a schema.private SchemaElement[]
load(java.util.List list)
Load and validate the root schema list.static void
main(java.lang.String[] args)
Run the schema refactoring using command line parameters.private boolean
processExtensions()
Process substitutions and deletions defined by extensions.void
pruneDefinitions()
Processes the schemas to remove unused global definitions.private static boolean
reportProblems(ValidationContext vctx)
Report problems using console output.void
validateSchemas(SchemaElement[] schemas)
Validate the schemas.private void
writeSchemas(java.io.File destdir)
Write schema definitions to file system.
-
-
-
Field Detail
-
s_logger
private static final Logger s_logger
Logger for class.
-
DEFAULT_REPLACEMENTS
private static final QName[] DEFAULT_REPLACEMENTS
Default type replacements applied.
-
TYPE_DERIVE_MASK
private static final long TYPE_DERIVE_MASK
Mask for schema elements which derive from a type.
-
TYPE_DEFINE_MASK
private static final long TYPE_DEFINE_MASK
Mask for schema elements which define a type.
-
BLOCK_NAME_INHERIT_MASK
private static final long BLOCK_NAME_INHERIT_MASK
Mask for schema elements which block name inheritance downward.
-
m_global
private final SchemasetCustom m_global
Code generation customizations.
-
m_schemaRoot
private final java.net.URL m_schemaRoot
Root URL for schemas.
-
m_schemaDir
private final java.io.File m_schemaDir
Root directory for schemas.
-
m_targetDir
private final java.io.File m_targetDir
Target directory for code generation.
-
m_validationContext
private final ValidationContext m_validationContext
Context for loading and processing schemas.
-
m_definitions
private java.util.ArrayList m_definitions
Definitions to be generated (may be global schema definitions, or reused nested components with classes).
-
m_bindingDirectory
private BindingOrganizer m_bindingDirectory
Directory for constructed bindings.
-
-
Constructor Detail
-
Refactory
public Refactory(RefactoryCommandLine parms)
Constructor.- Parameters:
parms
- command line parameters
-
Refactory
public Refactory(SchemasetCustom custom, ValidationContext vctx)
Constructor used by tests. This uses supplied schemas and skips writing to the file system.- Parameters:
custom
-vctx
-
-
-
Method Detail
-
findSchemaset
private SchemasetCustom findSchemaset(SchemaElement schema, SchemasetCustom custom)
Find the most specific schemaset owning a schema. If multiple matches are found which are not in line of containment the first match is returned and the conflict is reported as an error.- Parameters:
schema
-custom
- schema set customization- Returns:
- owning schemaset,
null
if none
-
validateSchemas
public void validateSchemas(SchemaElement[] schemas)
Validate the schemas.- Parameters:
schemas
- schemas to be validated
-
load
private SchemaElement[] load(java.util.List list) throws JiBXException, java.io.IOException
Load and validate the root schema list.- Parameters:
list
- resolvers for schemas to be loaded- Returns:
- schemas in validation order
- Throws:
JiBXException
- on unrecoverable error in schemasjava.io.IOException
- on error reading schemas
-
customizeSchemas
public boolean customizeSchemas()
Validate and apply customizations to loaded schemas.- Returns:
true
if successful,false
if error
-
processExtensions
private boolean processExtensions()
Process substitutions and deletions defined by extensions. This builds the cross-reference information for the global definition components of the schemas while removing references to deleted components.- Returns:
true
if any changes to the schemas,false
if not
-
applyAndNormalize
public void applyAndNormalize()
Apply extensions and normalize all schemas. This may be a multipass process, since applying extensions may create the opportunity for further normalizations and vice versa.
-
pruneDefinitions
public void pruneDefinitions()
Processes the schemas to remove unused global definitions.
-
writeSchemas
private void writeSchemas(java.io.File destdir) throws JiBXException, java.io.IOException
Write schema definitions to file system.- Parameters:
destdir
- destination directory- Throws:
JiBXException
- on error in marshallingjava.io.IOException
- on error writing
-
reportProblems
private static boolean reportProblems(ValidationContext vctx)
Report problems using console output. This clears the problem list after they've been reported, to avoid multiple reports of the same problems.- Parameters:
vctx
-- Returns:
true
if one or more errors,false
if not
-
addCustomizedSchemas
private static void addCustomizedSchemas(java.net.URL base, java.io.File dir, SchemasetCustom custom, InsertionOrderedSet fileset) throws java.net.MalformedURLException
Add the schemas specified by customizations to the set to be loaded.- Parameters:
base
- root URL for schemasdir
- root directory for schemascustom
- schema set customizationfileset
- set of schema files to be loaded- Throws:
java.net.MalformedURLException
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception
Run the schema refactoring using command line parameters.- Parameters:
args
-- Throws:
java.lang.Exception
-
-