com.predic8.ParserImportedSchemaCache.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of soa-model-core Show documentation
Show all versions of soa-model-core Show documentation
Membrane SOA Model is an open-source toolkit and Java API for WSDL and XML Schema, licensed under ASF 2.0. that can:
Parse, create or modify a WSDL or XML Schema Document from Java
Compare two WSDL or XML Schema Documents
Create a SOAP Request or Template
Analyze a WSDL or Schema document and generate an HMTL report
package com.predic8
import com.predic8.schema.Schema
import groovy.transform.Synchronized
/**
* Thread safe imported Schema cache to be used in the {@link com.predic8.soamodel.AbstractParserContext}s
*/
class ParserImportedSchemaCache {
@SuppressWarnings("GroovyUnusedDeclaration")
Object importedSchemasLock = new Object()
final Map importedSchemas = [:]
@Synchronized('importedSchemasLock')
Schema addSchema (Schema schema, String schemaKey = null) {
String key = schemaKey ?: schema?.targetNamespace
// Do not try to cache schema's without a meaningful key
if (!key) { return schema }
if (!importedSchemas[key]) {
importedSchemas[key] = schema
}
importedSchemas[key]
}
@Synchronized('importedSchemasLock')
Schema addSchema (Closure lazySchema, String schemaKey = null) {
String key = schemaKey
if (!schemaKey) {
// Schema needs to be parsed to determine the cache key
return addSchema((Schema)lazySchema.call())
}
if (!importedSchemas[key]) {
importedSchemas[key] = (Schema) lazySchema.call()
}
importedSchemas[key]
}
@Synchronized('importedSchemasLock')
synchronized Schema getSchema (String key) {
importedSchemas[key]
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy