So, I'm using an API that is somewhat unfriendly in a certain way. Basically, this API creates a resource that can be obtained later. This resource may or may not exist when we get to it later.
To extract a previously created resource, you must use the results directive as follows:
String resultKey = "12345";
PersistedResult r = mFactory.getPersistedResult(resultKey);
Now the hardest part is that it getPersistedResultDOES NOT throw an exception when called with an invalid director ... it PersistedResultis a lazy loader and will fail only when one of its methods is called (by calling the object to load).
So, to determine if the resource is really valid, I do the following:
PersistedResult r = null;
if (!StringUtils.isEmpty(resultKey)) {
try {
r = mFactory.getPersistedResult(resultKey);
r.getResultCount();
} catch (Exception e) {
}
}
getResultCount , ?
PersistedResult , .