membrane / soa-model

Toolkit and Java API for WSDL, WADL and XML Schema.
http://www.membrane-soa.org/soa-model/
Apache License 2.0
93 stars 73 forks source link

#168 Refactoring to support reuse of parsed Schema's for multiple WSDL's #189

Closed ithena closed 10 years ago

ithena commented 10 years ago

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.

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

Currently Schema Includes are also not cached, only Schema imports.

predic8 commented 10 years ago

I just looked over the modifications. Looks pretty good! Good coding practises and style. There are lot of modifications so we need some time for the pull.

ithena commented 10 years ago

Thomas, I assume the Include construct should also cause the Schema to be added to the cache. Could you confirm this?

keshavarzi commented 10 years ago

@ithena Dear Ruben, would you send us a new pull request with the latest changes? Thanks