String reference = uri;
Object cacheKey = getCacheKey(reference);
if (cacheKey == null)
return null;
CMDocument doc = (CMDocument) getDocuments().get(cacheKey);
if (doc == null) {
long lastModified = getModificationStamp(reference);
/*
* If hasn't been moved into the local table, do so and increment
* the count. A local URI reference can be different depending on
* the file from which it was referenced. Use a computed key to
* keep them straight.
*/
Object o = getSharedDocumentCache().get(cacheKey);
if (o != null) {
if (o instanceof TLDCacheEntry) {
TLDCacheEntry entry = (TLDCacheEntry) o;
if (_debugCache) {
System.out.println("TLDCMDocument cache hit on " + cacheKey);
}
if (entry != null && entry.modificationStamp != IResource.NULL_STAMP && entry.modificationStamp >= lastModified) {
doc = entry.document;
entry.referenceCount++;
}
else {
getSharedDocumentCache().remove(cacheKey);
}
}
else if (o instanceof Reference) {
TLDCacheEntry entry = (TLDCacheEntry) ((Reference) o).get();
if (entry != null) {
if (entry.modificationStamp != IResource.NULL_STAMP && entry.modificationStamp >= lastModified) {
doc = entry.document;
entry.referenceCount = 1;
getSharedDocumentCache().put(cacheKey, entry);
}
}
else {
getSharedDocumentCache().remove(cacheKey);
}
}
}
/* No document was found cached, create a new one and share it */
if (doc == null) {
if (_debugCache) {
System.out.println("TLDCMDocument cache miss on " + cacheKey);
}
CMDocument document = loadTaglib(reference);
if (document != null) {
TLDCacheEntry entry = new TLDCacheEntry();
doc = entry.document = document;
entry.referenceCount = 1;
entry.modificationStamp = lastModified;