2222
2323package scalaxb .compiler
2424
25- import java .net .{URI }
26- import scala .xml .{Node , Elem , UnprefixedAttribute , NamespaceBinding }
27- import scala .xml .factory .{XMLLoader }
25+ import java .net .URI
26+
27+ import scala .xml .{Elem , NamespaceBinding , Node , UnprefixedAttribute }
28+ import scala .xml .factory .XMLLoader
2829import javax .xml .parsers .SAXParser
29- import java .io .{File , PrintWriter , Reader , BufferedReader }
30- import scala . collection . mutable
30+ import java .io .{BufferedReader , File , PrintWriter , Reader }
31+
3132import scala .collection .mutable .{ListBuffer , ListMap }
3233import ConfigEntry ._
34+ import scalaxb .compiler .xsd .ParserConfig
3335
3436object Snippet {
3537 def apply (snippets : Snippet * ): Snippet =
@@ -117,7 +119,7 @@ trait Module {
117119 def includeLocations : Seq [String ]
118120 def raw : RawSchema
119121 def location : URI
120- def toSchema (context : Context ): Schema
122+ def toSchema (context : Context , config : ParserConfig ): Schema
121123 def swapTargetNamespace (outerNamespace : Option [String ], n : Int ): Importable
122124 }
123125
@@ -201,26 +203,28 @@ trait Module {
201203
202204 def processReaders [From , To ](files : Seq [From ], config : Config )
203205 (implicit ev : CanBeRawSchema [From , RawSchema ], evTo : CanBeWriter [To ]): (CompileSource [From ], List [To ]) = {
204- val source = buildCompileSource(files)
206+ val source = buildCompileSource(files, config )
205207 (source, processCompileSource(source, config))
206208 }
207209
208- def buildCompileSource [From , To ](files : Seq [From ])
210+ def buildCompileSource [From , To ](files : Seq [From ], config : Config )
209211 (implicit ev : CanBeRawSchema [From , RawSchema ]): CompileSource [From ] = {
210212
211213 logger.debug(" %s" , files.toString())
212214 val context = buildContext
213215 val importables0 = ListMap [From , Importable ](files map { f =>
214216 f -> toImportable(ev.toURI(f), ev.toRawSchema(f))}: _* )
215217 val importables = ListBuffer [(Importable , From )](files map { f => importables0(f) -> f }: _* )
218+ val parserConfig = new ParserConfig
219+ parserConfig.useJavaTime = config.useJavaTime
216220 val schemas = ListMap [Importable , Schema ](importables map { case (importable, file) =>
217- val s = parse(importable, context)
221+ val s = parse(importable, context, parserConfig )
218222 (importable, s) } toSeq : _* )
219223
220224 val additionalImportables = ListMap .empty[Importable , File ]
221225
222226 // recursively add missing files
223- def addMissingFiles (): Unit = {
227+ def addMissingFiles (parserConfig : ParserConfig ): Unit = {
224228 val current = (importables map {_._1}) ++ additionalImportables.keysIterator.toList
225229 // check for all dependencies before proceeding.
226230 val missings = (current flatMap { importable =>
@@ -239,12 +243,12 @@ trait Module {
239243 added = true
240244 val importable = toImportable(implicitly[CanBeRawSchema [File , RawSchema ]].toURI(x),
241245 implicitly[CanBeRawSchema [File , RawSchema ]].toRawSchema(x))
242- val s = parse(importable, context)
246+ val s = parse(importable, context, parserConfig )
243247 schemas(importable) = s
244248 (importable, x) })
245- if (added) addMissingFiles()
249+ if (added) addMissingFiles(parserConfig )
246250 }
247- def processUnnamedIncludes (): Unit = {
251+ def processUnnamedIncludes (parserConfig : ParserConfig ): Unit = {
248252 logger.debug(" processUnnamedIncludes" )
249253 val all = (importables.toList map {_._1}) ++ (additionalImportables.toList map {_._1})
250254 val parents : ListBuffer [Importable ] = ListBuffer (all filter { ! _.includeLocations.isEmpty}: _* )
@@ -270,7 +274,7 @@ trait Module {
270274 logger.debug(" processUnnamedIncludes - setting %s's outer namespace to %s" , x.location, tnsstr)
271275 count += 1
272276 val swap = x.swapTargetNamespace(tns, count)
273- schemas(swap) = parse(swap, context)
277+ schemas(swap) = parse(swap, context, parserConfig )
274278 additionalImportables(swap) = new File (swap.location.getPath)
275279 used += x
276280 }
@@ -292,8 +296,8 @@ trait Module {
292296 }
293297 }
294298
295- addMissingFiles()
296- processUnnamedIncludes()
299+ addMissingFiles(parserConfig )
300+ processUnnamedIncludes(parserConfig )
297301 CompileSource (context, schemas, importables, additionalImportables,
298302 importables0(files.head).targetNamespace)
299303 }
@@ -426,11 +430,11 @@ trait Module {
426430
427431 def nodeToRawSchema (node : Node ): RawSchema
428432
429- def parse (importable : Importable , context : Context ): Schema
430- = importable.toSchema(context)
433+ def parse (importable : Importable , context : Context , config : ParserConfig ): Schema
434+ = importable.toSchema(context, config )
431435
432- def parse (location : URI , in : Reader ): Schema
433- = parse(toImportable(location, readerToRawSchema(in)), buildContext)
436+ def parse (location : URI , in : Reader , config : ParserConfig ): Schema
437+ = parse(toImportable(location, readerToRawSchema(in)), buildContext, config )
434438
435439 def printNodes (nodes : Seq [Node ], out : PrintWriter ): Unit = {
436440 import scala .xml ._
@@ -487,7 +491,7 @@ trait Module {
487491 NamespaceBinding (null , outerNamespace getOrElse null , scope)
488492 def fixSeq (ns : Seq [Node ]): Seq [Node ] =
489493 for { node <- ns } yield node match {
490- case elem : Elem =>
494+ case elem : Elem =>
491495 elem.copy(scope = fixScope(elem.scope),
492496 child = fixSeq(elem.child))
493497 case other => other
0 commit comments