public static void generate ( GenerationConfig config ) throws IOException { Annotator annotator = getAnnotator ( config ) ; RuleFactory ruleFactory = createRuleFactory ( config ) ; ruleFactory . setAnnotator ( annotator ) ; ruleFactory . setGenerationConfig ( config ) ; ruleFactory . setSchemaStore ( new SchemaStore ( createContentResolver ( config ) ) ) ; SchemaMapper mapper = new SchemaMapper ( ruleFactory , createSchemaGenerator ( config ) ) ; JCodeModel codeModel = new JCodeModel ( ) ; if ( config . isRemoveOldOutput ( ) ) { removeOldOutput ( config . getTargetDirectory ( ) ) ; } for ( Iterator < URL > sources = config . getSource ( ) ; sources . hasNext ( ) ; ) { URL source = sources . next ( ) ; if ( URLUtil . parseProtocol ( source . toString ( ) ) == URLProtocol . FILE && URLUtil . getFileFromURL ( source ) . isDirectory ( ) ) { generateRecursive ( config , mapper , codeModel , defaultString ( config . getTargetPackage ( ) ) , Arrays . asList ( URLUtil . getFileFromURL ( source ) . listFiles ( config . getFileFilter ( ) ) ) ) ; } else { mapper . generate ( codeModel , getNodeName ( source , config ) , defaultString ( config . getTargetPackage ( ) ) , source ) ; } } if ( config . getTargetDirectory ( ) . exists ( ) || config . getTargetDirectory ( ) . mkdirs ( ) ) { if ( config . getTargetLanguage ( ) == Language . SCALA ) { CodeWriter sourcesWriter = new ScalaFileCodeWriter ( config . getTargetDirectory ( ) , config . getOutputEncoding ( ) ) ; CodeWriter resourcesWriter = new FileCodeWriterWithEncoding ( config . getTargetDirectory ( ) , config . getOutputEncoding ( ) ) ; codeModel . build ( sourcesWriter , resourcesWriter ) ; } else { CodeWriter sourcesWriter = new FileCodeWriterWithEncoding ( config . getTargetDirectory ( ) , config . getOutputEncoding ( ) ) ; CodeWriter resourcesWriter = new FileCodeWriterWithEncoding ( config . getTargetDirectory ( ) , config . getOutputEncoding ( ) ) ; codeModel . build ( sourcesWriter , resourcesWriter ) ; } } else { throw new GenerationException ( "Could not create or access target directory " + config . getTargetDirectory ( ) . getAbsolutePath ( ) ) ; } }
Reads the contents of the given source and initiates schema generation .