// Guess the type of query based on the URI structure
switch (guessType(targetUri)) {
case TYPE_ENTITY_SET:
FeedContentHandler<T> feedContentHandler = new FeedContentHandler<T>(
entityClass, entityType, metadata, getLogger());
setFeed(new Feed(result, feedContentHandler));
this.count = feedContentHandler.getCount();
this.entities = feedContentHandler.getEntities();
break;
case TYPE_ENTITY:
EntryContentHandler<T> entryContentHandler = new EntryContentHandler<T>(
entityClass, entityType, metadata, getLogger());
Feed feed = new Feed();
feed.getEntries().add(
new Entry(result, entryContentHandler));
setFeed(feed);
entities = new ArrayList<T>();
if (entryContentHandler.getEntity() != null) {
entities.add(entryContentHandler.getEntity());
}
break;
case TYPE_UNKNOWN:
// Guess the type of query based on the returned
// representation
Representation rep = new StringRepresentation(result
.getText());
String string = rep.getText().substring(0,
Math.min(100, rep.getText().length()));
if (string.contains("<feed")) {
feedContentHandler = new FeedContentHandler<T>(
entityClass, entityType, metadata, getLogger());
setFeed(new Feed(rep, feedContentHandler));
this.count = feedContentHandler.getCount();
this.entities = feedContentHandler.getEntities();
} else if (string.contains("<entry")) {
entryContentHandler = new EntryContentHandler<T>(
entityClass, entityType, metadata, getLogger());
feed = new Feed();
feed.getEntries().add(
new Entry(rep, entryContentHandler));
setFeed(feed);
entities = new ArrayList<T>();
if (entryContentHandler.getEntity() != null) {
entities.add(entryContentHandler.getEntity());