private void handleSystemQueryOptionSelect(final String selectStatement) throws UriSyntaxException,
UriNotMatchingException, EdmException {
ArrayList<SelectItem> select = new ArrayList<SelectItem>();
if (selectStatement.startsWith(",") || selectStatement.endsWith(",")) {
throw new UriSyntaxException(UriSyntaxException.EMPTYSEGMENT);
}
for (String selectItemString : selectStatement.split(",")) {
selectItemString = selectItemString.trim();
if ("".equals(selectItemString)) {
throw new UriSyntaxException(UriSyntaxException.EMPTYSEGMENT);
}
if (selectItemString.startsWith("/") || selectItemString.endsWith("/")) {
throw new UriSyntaxException(UriSyntaxException.EMPTYSEGMENT);
}
SelectItemImpl selectItem = new SelectItemImpl();
boolean exit = false;
EdmEntitySet fromEntitySet = uriResult.getTargetEntitySet();
for (String selectedPropertyName : selectItemString.split("/")) {
if ("".equals(selectedPropertyName)) {
throw new UriSyntaxException(UriSyntaxException.EMPTYSEGMENT);
}
if (exit) {
throw new UriSyntaxException(UriSyntaxException.INVALIDSEGMENT.addContent(selectItemString));
}
if ("*".equals(selectedPropertyName)) {
selectItem.setStar(true);
exit = true;
continue;
}
final EdmTyped property = fromEntitySet.getEntityType().getProperty(selectedPropertyName);
if (property == null) {
throw new UriNotMatchingException(UriNotMatchingException.PROPERTYNOTFOUND.addContent(selectedPropertyName));
}
switch (property.getType().getKind()) {
case SIMPLE:
case COMPLEX:
selectItem.setProperty((EdmProperty) property);
exit = true;
break;
case ENTITY: // navigation properties point to entities
final EdmNavigationProperty navigationProperty = (EdmNavigationProperty) property;
final EdmEntitySet targetEntitySet = fromEntitySet.getRelatedEntitySet(navigationProperty);
NavigationPropertySegmentImpl navigationPropertySegment = new NavigationPropertySegmentImpl();
navigationPropertySegment.setNavigationProperty(navigationProperty);
navigationPropertySegment.setTargetEntitySet(targetEntitySet);
selectItem.addNavigationPropertySegment(navigationPropertySegment);
fromEntitySet = targetEntitySet;
break;
default:
throw new UriSyntaxException(UriSyntaxException.INVALIDPROPERTYTYPE);
}
}
select.add(selectItem);
}
uriResult.setSelect(select);