/* Prepare a key, and try to get the cached copy of the schema */
String uri = source.getURI();
String key = this.getClass().getName() + "[" + parser.getClass().getName()
+ ":" + grammar + "]@" + source.getURI();
Schema schema = null;
SourceValidity validity = null;
schema = (Schema) this.store.get(key);
/* If the schema was found verify its validity and optionally clear */
if (schema != null) {
validity = schema.getValidity();
if (validity == null) {
/* Why did we cache it in the first place? */
this.logger.warn("Cached schema " + uri + " has null validity");
this.store.remove(key);
schema = null;
} else if (validity.isValid() != SourceValidity.VALID) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Cached schema " + uri + " no longer valid");
}
this.store.remove(key);
schema = null;
} else if (this.logger.isDebugEnabled()) {
this.logger.debug("Valid cached schema found for " + uri);
}
} else if (this.logger.isDebugEnabled()) {
this.logger.debug("Schema " + uri + " not found in cache");
}
/* If the schema was not cached or was cleared, parse and cache it */
if (schema == null) {
schema = super.getSchema(parser, source, grammar);
validity = schema.getValidity();
if (validity != null) {
if (validity.isValid() == SourceValidity.VALID) {
this.store.store(key, schema);
}
}