if (r == null) {
return null;
}
// if not a ParameterizedDataResource, it is an error
if (!(r instanceof ParameterizedDataResource)) {
throw new ResourceAccessException(ResourceAccessException.PARAMETERS_NOT_ALLOWED,
new Object[] { aName });
}
ParameterizedDataResource pdr = (ParameterizedDataResource) r;
// get a particular DataResource instance for the specified parameters
DataResource dr;
try {
dr = pdr.getDataResource(aParams);
} catch (ResourceInitializationException e) {
throw new ResourceAccessException(e);
}
// see if we've already encountered this DataResource under this resource name
ArrayList<Object> nameAndResource = new ArrayList<Object>();
nameAndResource.add(aName);
nameAndResource.add(dr);
Object resourceInstance = mParameterizedResourceInstanceMap.get(nameAndResource);
if (resourceInstance != null) {
return resourceInstance;
}
// We haven't encountered this before. See if we need to instantiate a
// SharedResourceObject
Class<?> sharedResourceObjectClass = mParameterizedResourceImplClassMap.get(aName);
if (sharedResourceObjectClass != null) {
try {
SharedResourceObject sro = (SharedResourceObject) sharedResourceObjectClass.newInstance();
sro.load(dr);
mParameterizedResourceInstanceMap.put(nameAndResource, sro);
return sro;
} catch (InstantiationException e) {
throw new ResourceAccessException(e);
} catch (IllegalAccessException e) {
throw new ResourceAccessException(e);
} catch (ResourceInitializationException e) {
throw new ResourceAccessException(e);
}
} else
// no impl. class - just return the DataResource
{
mParameterizedResourceInstanceMap.put(nameAndResource, dr);