private Asset createAssetFromResource(Resource resource) { // The class of the resource is derived from the class of the base resource. // So we can then use the class of the resource as a key to locate the correct asset // factory. try { upgradeReadLockToWriteLock(); // Check for competing thread beat us to it (not very likely!): Asset result = TapestryInternalUtils.getAndDeref(cache, resource); if (result != null) { return result; } Class resourceClass = resource.getClass(); AssetFactory factory = registry.get(resourceClass); return factory.createAsset(resource); } finally { downgradeWriteLockToReadLock(); } }
private Asset getAssetForResource(Resource resource) { try { acquireReadLock(); Asset result = TapestryInternalUtils.getAndDeref(cache, resource); if (result == null) { result = createAssetFromResource(resource); cache.put(resource, new SoftReference(result)); } return result; } finally { releaseReadLock(); } }