if (adapter == null) {
return ProviderHelper.notfound(
request);
}
Transactional transaction =
adapter instanceof Transactional ?
(Transactional)adapter : null;
ResponseContext response = null;
try {
if (transaction != null) transaction.start(request);
if (type == TargetType.TYPE_CATEGORIES) {
if (method.equalsIgnoreCase("GET"))
response = adapter.getCategories(request);
} else if (type == TargetType.TYPE_COLLECTION) {
if (method.equalsIgnoreCase("GET"))
response = adapter.getFeed(request);
else if (method.equalsIgnoreCase("POST")) {
response = ProviderHelper.isAtom(request) ?
adapter.postEntry(request) :
adapter instanceof MediaCollectionAdapter ?
((MediaCollectionAdapter)adapter).postMedia(request) :
ProviderHelper.notsupported(request);
}
} else if (type == TargetType.TYPE_ENTRY) {
if (method.equalsIgnoreCase("GET"))
response = adapter.getEntry(request);
else if (method.equalsIgnoreCase("PUT"))
response = adapter.putEntry(request);
else if (method.equalsIgnoreCase("DELETE"))
response = adapter.deleteEntry(request);
else if (method.equalsIgnoreCase("HEAD"))
response = adapter.headEntry(request);
else if (method.equalsIgnoreCase("OPTIONS"))
response = adapter.optionsEntry(request);
} else if (type == TargetType.TYPE_MEDIA) {
if (adapter instanceof MediaCollectionAdapter) {
MediaCollectionAdapter mcadapter =
(MediaCollectionAdapter) adapter;
if (method.equalsIgnoreCase("GET"))
response = mcadapter.getMedia(request);
else if (method.equalsIgnoreCase("PUT"))
response = mcadapter.putMedia(request);
else if (method.equalsIgnoreCase("DELETE"))
response = mcadapter.deleteMedia(request);
else if (method.equalsIgnoreCase("HEAD"))
response = mcadapter.headMedia(request);
else if (method.equalsIgnoreCase("OPTIONS"))
response = mcadapter.optionsMedia(request);
} else {
response = ProviderHelper.notsupported(request);
}
} else if (type == TargetType.TYPE_NOT_FOUND) {
response = ProviderHelper.notfound(request);
} else {
response = adapter.extensionRequest(request);
}
if (response == null)
response = ProviderHelper.notsupported(request);
return response;
} catch (Throwable e) {
log.error(e);
if (transaction != null)
transaction.compensate(request,e);
response = ProviderHelper.servererror(request, e);
return response;
} finally {
if (transaction != null)
transaction.end(request, response);
}
}