membrane/soa-model — pull request #189 by ithena (2013-12-12 14:23:56+00:00)
Title: #168 Refactoring to support reuse of parsed Schema's for multiple WSDL's

We refactored the AbstractParserContext and the cache for imported Schema's so that it becomes possible to reuse the Schema cache when parsing multiple WSDL definitions.

I tried to avoid any changes in the parsing behavior for the standard scenario. The client code needs to explicitly reuse the ParserImportedSchemaCache when parsing multiple WSDL definitions. Otherwise the parser behavior should not be different as before.

One minor difference might be that ParserImportedSchemaCache does not cache Schema's without a targetNamespace. Before, when a map was used for caching, Schema's without a targetNamespace would be cached with an empty String as key.

The refactoring makes the ParserContext responsible for choosing an appropriate cache key, and adding and retrieving Schema's from the cache. This allows for custom cache key strategies, e.g. baseDir + targetNamespace, by subclassing one of the parser context implementations.

To reuse the parsed Schema's for different WSDLs the client needs to explicitly reuse the ParserImportedSchemaCache as shown in the snippet below. When the client does this, only one instance of each Schema will be in memory.

```groovy
List wsdlFileList = [..., ..., ...]
final ParserImportedSchemaCache schemaCache = new ParserImportedSchemaCache()
wsdlFileList.each { wsdlFile ->
Definitions definitions = new WSDLParser().parse(
new WSDLParserContext(importedSchemaCache: schemaCache, input: wsdlFile.absolutePath))
}
```