return getTrueObject(objHandle, arguments);
}
private Object getTrueObject(final CacheObject objHandle, final Object arguments) {
if (objHandle.needsLoading(arguments)) {
Attributes attribs = objHandle.getAttributes();
CacheLoader loader = attribs.getLoader();
Object retrievedObject;
try {
retrievedObject = loader.load(objHandle, arguments);
if (retrievedObject == null) {
throw new ObjectNotFoundException("The returned object from the CacheLoader " + loader.getClass().getName() + " was null.");
}
if (retrievedObject instanceof CacheOutputStream) {
/*
* a CacheLoader has created an OutputStream, and loaded the
* object. Get the owner object for the stream, and return
* the corresponding InputStream. The StreamObjects are
* created in the CacheLoader, but the regular memory
* objects are created below, is this correct? And a double
* creation is also done... once before the load, and once
* further down, but this is not called as we have multiple
* return points in this method.... well, if it works, dont
* touch it! Refactor when we are moving towards a
* production release.
*
*/
return ((CacheOutputStream) retrievedObject).getStreamObject().getInputStream();
} else if (retrievedObject instanceof File) {
/*
* The object was a DiskObject, return the path to the
* diskfile.
*/
return ((File) retrievedObject).getAbsolutePath();
}
attribs.setCreateTime(System.currentTimeMillis());
} catch (CacheException e) {
this.lastException = e.getClass();
this.lastMessage = e.getMessage();
return null;
}