public Object invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException {
IParser parser = createAppropriateParserForParsingResponse(theResponseMimeType, theResponseReader, theResponseStatusCode);
switch (getReturnType()) {
case BUNDLE: {
Bundle bundle;
if (myResourceType != null) {
bundle = parser.parseBundle(myResourceType, theResponseReader);
} else {
bundle = parser.parseBundle(theResponseReader);
}
switch (getMethodReturnType()) {
case BUNDLE:
return bundle;
case LIST_OF_RESOURCES:
List<IResource> listOfResources;
if (myResourceListCollectionType != null) {
listOfResources = new ArrayList<IResource>();
for (IResource next : bundle.toListOfResources()) {
if (!myResourceListCollectionType.isAssignableFrom(next.getClass())) {
ourLog.debug("Not returning resource of type {} because it is not a subclass or instance of {}", next.getClass(), myResourceListCollectionType);
continue;
}
listOfResources.add(next);
}
} else {
listOfResources = bundle.toListOfResources();
}
return listOfResources;
case RESOURCE:
List<IResource> list = bundle.toListOfResources();
if (list.size() == 0) {
return null;
} else if (list.size() == 1) {
return list.get(0);
} else {