Package org.jibx.schema.codegen
Class Refactory
- java.lang.Object
-
- org.jibx.schema.codegen.Refactory
-
public class Refactory extends java.lang.ObjectSchema refactoring tool. 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classRefactory.SchemaNameFilterFile name pattern matcher.
-
Field Summary
Fields Modifier and Type Field Description private static longBLOCK_NAME_INHERIT_MASKMask for schema elements which block name inheritance downward.private static QName[]DEFAULT_REPLACEMENTSDefault type replacements applied.private BindingOrganizerm_bindingDirectoryDirectory for constructed bindings.private java.util.ArrayListm_definitionsDefinitions to be generated (may be global schema definitions, or reused nested components with classes).private SchemasetCustomm_globalCode generation customizations.private java.io.Filem_schemaDirRoot directory for schemas.private java.net.URLm_schemaRootRoot URL for schemas.private java.io.Filem_targetDirTarget directory for code generation.private ValidationContextm_validationContextContext for loading and processing schemas.private static Loggers_loggerLogger for class.private static longTYPE_DEFINE_MASKMask for schema elements which define a type.private static longTYPE_DERIVE_MASKMask 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 voidaddCustomizedSchemas(java.net.URL base, java.io.File dir, SchemasetCustom custom, InsertionOrderedSet fileset)Add the schemas specified by customizations to the set to be loaded.voidapplyAndNormalize()Apply extensions and normalize all schemas.booleancustomizeSchemas()Validate and apply customizations to loaded schemas.private SchemasetCustomfindSchemaset(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 voidmain(java.lang.String[] args)Run the schema refactoring using command line parameters.private booleanprocessExtensions()Process substitutions and deletions defined by extensions.voidpruneDefinitions()Processes the schemas to remove unused global definitions.private static booleanreportProblems(ValidationContext vctx)Report problems using console output.voidvalidateSchemas(SchemaElement[] schemas)Validate the schemas.private voidwriteSchemas(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,
nullif 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:
trueif successful,falseif 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:
trueif any changes to the schemas,falseif 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.IOExceptionWrite 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:
trueif one or more errors,falseif not
-
addCustomizedSchemas
private static void addCustomizedSchemas(java.net.URL base, java.io.File dir, SchemasetCustom custom, InsertionOrderedSet fileset) throws java.net.MalformedURLExceptionAdd 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.ExceptionRun the schema refactoring using command line parameters.- Parameters:
args-- Throws:
java.lang.Exception
-
-