Class Refactory


  • public class Refactory
    extends java.lang.Object
    Schema refactoring tool. Although many of the methods in this class use 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.
    Author:
    Dennis M. Sosnoski
    • 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 schemas
        java.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 marshalling
        java.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 schemas
        dir - root directory for schemas
        custom - schema set customization
        fileset - 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