You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by fm...@apache.org on 2013/07/26 13:22:16 UTC
[11/51] [partial] initial commit
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ff2b0a0e/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
new file mode 100644
index 0000000..f437ace
--- /dev/null
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
@@ -0,0 +1,843 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.core.uri;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.olingo.odata2.api.commons.InlineCount;
+import org.apache.olingo.odata2.api.edm.Edm;
+import org.apache.olingo.odata2.api.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.edm.EdmEntityContainer;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.edm.EdmLiteral;
+import org.apache.olingo.odata2.api.edm.EdmLiteralException;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.EdmParameter;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeFacade;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTyped;
+import org.apache.olingo.odata2.api.exception.MessageReference;
+import org.apache.olingo.odata2.api.exception.ODataBadRequestException;
+import org.apache.olingo.odata2.api.exception.ODataMessageException;
+import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
+import org.apache.olingo.odata2.api.uri.PathSegment;
+import org.apache.olingo.odata2.api.uri.SelectItem;
+import org.apache.olingo.odata2.api.uri.UriInfo;
+import org.apache.olingo.odata2.api.uri.UriNotMatchingException;
+import org.apache.olingo.odata2.api.uri.UriParser;
+import org.apache.olingo.odata2.api.uri.UriSyntaxException;
+import org.apache.olingo.odata2.api.uri.expression.ExpressionParserException;
+import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
+import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
+import org.apache.olingo.odata2.core.commons.Decoder;
+import org.apache.olingo.odata2.core.edm.EdmSimpleTypeFacadeImpl;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+import org.apache.olingo.odata2.core.uri.expression.FilterParserImpl;
+import org.apache.olingo.odata2.core.uri.expression.OrderByParserImpl;
+
+/**
+ * Parser for the OData part of the URL.
+ * @author SAP AG
+ */
+public class UriParserImpl extends UriParser {
+
+ private static final Pattern INITIAL_SEGMENT_PATTERN = Pattern.compile("(?:([^.()]+)\\.)?([^.()]+)(?:\\((.+)\\)|(\\(\\)))?");
+ private static final Pattern NAVIGATION_SEGMENT_PATTERN = Pattern.compile("([^()]+)(?:\\((.+)\\)|(\\(\\)))?");
+ private static final Pattern NAMED_VALUE_PATTERN = Pattern.compile("(?:([^=]+)=)?([^=]+)");
+
+ private final Edm edm;
+ private final EdmSimpleTypeFacade simpleTypeFacade;
+ private List<String> pathSegments;
+ private String currentPathSegment;
+ private UriInfoImpl uriResult;
+ private Map<SystemQueryOption, String> systemQueryOptions;
+ private Map<String, String> otherQueryParameters;
+
+ public UriParserImpl(final Edm edm) {
+ this.edm = edm;
+ simpleTypeFacade = new EdmSimpleTypeFacadeImpl();
+ }
+
+ /**
+ * Parse the URI part after an OData service root,
+ * already splitted into path segments and query parameters.
+ * @param pathSegments the {@link PathSegment}s of the resource path,
+ * potentially percent-encoded
+ * @param queryParameters the query parameters, already percent-decoded
+ * @return a {@link UriInfoImpl} instance containing the parsed information
+ */
+ @Override
+ public UriInfo parse(final List<PathSegment> pathSegments, final Map<String, String> queryParameters) throws UriSyntaxException, UriNotMatchingException, EdmException {
+ this.pathSegments = copyPathSegmentList(pathSegments);
+ systemQueryOptions = new HashMap<SystemQueryOption, String>();
+ otherQueryParameters = new HashMap<String, String>();
+ uriResult = new UriInfoImpl();
+
+ preparePathSegments();
+
+ handleResourcePath();
+
+ distributeQueryParameters(queryParameters);
+ checkSystemQueryOptionsCompatibility();
+ handleSystemQueryOptions();
+ handleOtherQueryParameters();
+
+ return uriResult;
+ }
+
+ private void preparePathSegments() throws UriSyntaxException {
+ // Remove an empty path segment at the start of the OData part of the resource path.
+ if (!pathSegments.isEmpty() && pathSegments.get(0).equals("")) {
+ pathSegments.remove(0);
+ }
+
+ // Remove an empty path segment at the end of the resource path,
+ // although there is nothing in the OData specification that would allow that.
+ if (!pathSegments.isEmpty() && pathSegments.get(pathSegments.size() - 1).equals("")) {
+ pathSegments.remove(pathSegments.size() - 1);
+ }
+
+ // Intermediate empty path segments are an error, however.
+ for (String pathSegment : pathSegments) {
+ if (pathSegment.equals("")) {
+ throw new UriSyntaxException(UriSyntaxException.EMPTYSEGMENT);
+ }
+ }
+ }
+
+ private void handleResourcePath() throws UriSyntaxException, UriNotMatchingException, EdmException {
+ if (pathSegments.isEmpty()) {
+ uriResult.setUriType(UriType.URI0);
+ } else {
+
+ currentPathSegment = pathSegments.remove(0);
+
+ if ("$metadata".equals(currentPathSegment)) {
+ ensureLastSegment();
+ uriResult.setUriType(UriType.URI8);
+
+ } else if ("$batch".equals(currentPathSegment)) {
+ ensureLastSegment();
+ uriResult.setUriType(UriType.URI9);
+
+ } else {
+ handleNormalInitialSegment();
+ }
+ }
+ }
+
+ private void handleNormalInitialSegment() throws UriSyntaxException, UriNotMatchingException, EdmException {
+ final Matcher matcher = INITIAL_SEGMENT_PATTERN.matcher(currentPathSegment);
+ if (!matcher.matches()) {
+ throw new UriNotMatchingException(UriNotMatchingException.MATCHPROBLEM.addContent(currentPathSegment));
+ }
+
+ final String entityContainerName = percentDecode(matcher.group(1));
+ final String segmentName = percentDecode(matcher.group(2));
+ final String keyPredicate = matcher.group(3);
+ final String emptyParentheses = matcher.group(4);
+
+ final EdmEntityContainer entityContainer =
+ entityContainerName == null ? edm.getDefaultEntityContainer() : edm.getEntityContainer(entityContainerName);
+ if (entityContainer == null) {
+ throw new UriNotMatchingException(UriNotMatchingException.CONTAINERNOTFOUND.addContent(entityContainerName));
+ }
+ uriResult.setEntityContainer(entityContainer);
+
+ final EdmEntitySet entitySet = entityContainer.getEntitySet(segmentName);
+ if (entitySet != null) {
+ uriResult.setStartEntitySet(entitySet);
+ handleEntitySet(entitySet, keyPredicate);
+ } else {
+ final EdmFunctionImport functionImport = entityContainer.getFunctionImport(segmentName);
+ if (functionImport == null) {
+ throw new UriNotMatchingException(UriNotMatchingException.NOTFOUND.addContent(segmentName));
+ }
+ uriResult.setFunctionImport(functionImport);
+ handleFunctionImport(functionImport, emptyParentheses, keyPredicate);
+ }
+ }
+
+ private void handleEntitySet(final EdmEntitySet entitySet, final String keyPredicate) throws UriSyntaxException, UriNotMatchingException, EdmException {
+ final EdmEntityType entityType = entitySet.getEntityType();
+
+ uriResult.setTargetType(entityType);
+ uriResult.setTargetEntitySet(entitySet);
+
+ if (keyPredicate == null) {
+ if (pathSegments.isEmpty()) {
+ uriResult.setUriType(UriType.URI1);
+ } else {
+ currentPathSegment = pathSegments.remove(0);
+ checkCount();
+ if (uriResult.isCount()) {
+ uriResult.setUriType(UriType.URI15);
+ } else {
+ throw new UriSyntaxException(UriSyntaxException.ENTITYSETINSTEADOFENTITY.addContent(entitySet.getName()));
+ }
+ }
+ } else {
+ uriResult.setKeyPredicates(parseKey(keyPredicate, entityType));
+ if (pathSegments.isEmpty()) {
+ uriResult.setUriType(UriType.URI2);
+ } else {
+ handleNavigationPathOptions();
+ }
+ }
+ }
+
+ private void handleNavigationPathOptions() throws UriSyntaxException, UriNotMatchingException, EdmException {
+ currentPathSegment = pathSegments.remove(0);
+
+ checkCount();
+ if (uriResult.isCount()) {
+ uriResult.setUriType(UriType.URI16); // Count of multiple entities is handled elsewhere
+
+ } else if ("$value".equals(currentPathSegment)) {
+ if (uriResult.getTargetEntitySet().getEntityType().hasStream()) {
+ ensureLastSegment();
+ uriResult.setUriType(UriType.URI17);
+ uriResult.setValue(true);
+ } else {
+ throw new UriSyntaxException(UriSyntaxException.NOMEDIARESOURCE);
+ }
+
+ } else if ("$links".equals(currentPathSegment)) {
+ uriResult.setLinks(true);
+ if (pathSegments.isEmpty()) {
+ throw new UriSyntaxException(UriSyntaxException.MUSTNOTBELASTSEGMENT.addContent(currentPathSegment));
+ }
+ currentPathSegment = pathSegments.remove(0);
+ handleNavigationProperties();
+
+ } else {
+ handleNavigationProperties();
+ }
+ }
+
+ private void handleNavigationProperties() throws UriSyntaxException, UriNotMatchingException, EdmException {
+
+ final Matcher matcher = NAVIGATION_SEGMENT_PATTERN.matcher(currentPathSegment);
+ if (!matcher.matches()) {
+ throw new UriNotMatchingException(UriNotMatchingException.MATCHPROBLEM.addContent(currentPathSegment));
+ }
+
+ final String navigationPropertyName = percentDecode(matcher.group(1));
+ final String keyPredicateName = matcher.group(2);
+ final String emptyParentheses = matcher.group(3);
+
+ final EdmTyped property = uriResult.getTargetEntitySet().getEntityType().getProperty(navigationPropertyName);
+ if (property == null) {
+ throw new UriNotMatchingException(UriNotMatchingException.PROPERTYNOTFOUND.addContent(navigationPropertyName));
+ }
+
+ switch (property.getType().getKind()) {
+ case SIMPLE:
+ case COMPLEX:
+ if (keyPredicateName != null || emptyParentheses != null) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDSEGMENT.addContent(currentPathSegment));
+ }
+ if (uriResult.isLinks()) {
+ throw new UriSyntaxException(UriSyntaxException.NONAVIGATIONPROPERTY.addContent(property));
+ }
+
+ handlePropertyPath((EdmProperty) property);
+ break;
+
+ case ENTITY: // navigation properties point to entities
+ final EdmNavigationProperty navigationProperty = (EdmNavigationProperty) property;
+ if (keyPredicateName != null || emptyParentheses != null) {
+ if (navigationProperty.getMultiplicity() != EdmMultiplicity.MANY) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDSEGMENT.addContent(currentPathSegment));
+ }
+ }
+
+ addNavigationSegment(keyPredicateName, navigationProperty);
+
+ boolean many = false;
+ if (navigationProperty.getMultiplicity() == EdmMultiplicity.MANY) {
+ many = keyPredicateName == null;
+ }
+
+ if (pathSegments.isEmpty()) {
+ if (many) {
+ if (uriResult.isLinks()) {
+ uriResult.setUriType(UriType.URI7B);
+ } else {
+ uriResult.setUriType(UriType.URI6B);
+ }
+ } else if (uriResult.isLinks()) {
+ uriResult.setUriType(UriType.URI7A);
+ } else {
+ uriResult.setUriType(UriType.URI6A);
+ }
+ } else if (many || uriResult.isLinks()) {
+ currentPathSegment = pathSegments.remove(0);
+ checkCount();
+ if (!uriResult.isCount()) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDSEGMENT.addContent(currentPathSegment));
+ }
+ if (many) {
+ if (uriResult.isLinks()) {
+ uriResult.setUriType(UriType.URI50B);
+ } else {
+ uriResult.setUriType(UriType.URI15);
+ }
+ } else {
+ uriResult.setUriType(UriType.URI50A);
+ }
+ } else {
+ handleNavigationPathOptions();
+ }
+ break;
+
+ default:
+ throw new UriSyntaxException(UriSyntaxException.INVALIDPROPERTYTYPE.addContent(property.getType().getKind()));
+ }
+ }
+
+ private void addNavigationSegment(final String keyPredicateName, final EdmNavigationProperty navigationProperty) throws UriSyntaxException, EdmException {
+ final EdmEntitySet targetEntitySet = uriResult.getTargetEntitySet().getRelatedEntitySet(navigationProperty);
+ final EdmEntityType targetEntityType = targetEntitySet.getEntityType();
+ uriResult.setTargetEntitySet(targetEntitySet);
+ uriResult.setTargetType(targetEntityType);
+
+ NavigationSegmentImpl navigationSegment = new NavigationSegmentImpl();
+ navigationSegment.setEntitySet(targetEntitySet);
+ navigationSegment.setNavigationProperty(navigationProperty);
+ if (keyPredicateName != null) {
+ navigationSegment.setKeyPredicates(parseKey(keyPredicateName, targetEntityType));
+ }
+ uriResult.addNavigationSegment(navigationSegment);
+ }
+
+ private void handlePropertyPath(final EdmProperty property) throws UriSyntaxException, UriNotMatchingException, EdmException {
+ uriResult.addProperty(property);
+ final EdmType type = property.getType();
+
+ if (pathSegments.isEmpty()) {
+ if (type.getKind() == EdmTypeKind.SIMPLE) {
+ if (uriResult.getPropertyPath().size() == 1) {
+ uriResult.setUriType(UriType.URI5);
+ } else {
+ uriResult.setUriType(UriType.URI4);
+ }
+ } else if (type.getKind() == EdmTypeKind.COMPLEX) {
+ uriResult.setUriType(UriType.URI3);
+ } else {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDPROPERTYTYPE.addContent(type.getKind()));
+ }
+ uriResult.setTargetType(type);
+ } else {
+
+ currentPathSegment = percentDecode(pathSegments.remove(0));
+ switch (type.getKind()) {
+ case SIMPLE:
+ if ("$value".equals(currentPathSegment)) {
+ ensureLastSegment();
+ uriResult.setValue(true);
+ if (uriResult.getPropertyPath().size() == 1) {
+ uriResult.setUriType(UriType.URI5);
+ } else {
+ uriResult.setUriType(UriType.URI4);
+ }
+ } else {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDSEGMENT.addContent(currentPathSegment));
+ }
+ uriResult.setTargetType(type);
+ break;
+
+ case COMPLEX:
+ final EdmProperty nextProperty = (EdmProperty) ((EdmComplexType) type).getProperty(currentPathSegment);
+ if (nextProperty == null) {
+ throw new UriNotMatchingException(UriNotMatchingException.PROPERTYNOTFOUND.addContent(currentPathSegment));
+ }
+
+ handlePropertyPath(nextProperty);
+ break;
+
+ default:
+ throw new UriSyntaxException(UriSyntaxException.INVALIDPROPERTYTYPE.addContent(type.getKind()));
+ }
+ }
+ }
+
+ private void ensureLastSegment() throws UriSyntaxException {
+ if (!pathSegments.isEmpty()) {
+ throw new UriSyntaxException(UriSyntaxException.MUSTBELASTSEGMENT.addContent(currentPathSegment));
+ }
+ }
+
+ private void checkCount() throws UriSyntaxException {
+ if ("$count".equals(currentPathSegment)) {
+ if (pathSegments.isEmpty()) {
+ uriResult.setCount(true);
+ } else {
+ throw new UriSyntaxException(UriSyntaxException.MUSTBELASTSEGMENT.addContent(currentPathSegment));
+ }
+ }
+ }
+
+ private ArrayList<KeyPredicate> parseKey(final String keyPredicate, final EdmEntityType entityType) throws UriSyntaxException, EdmException {
+ final List<EdmProperty> keyProperties = entityType.getKeyProperties();
+ ArrayList<EdmProperty> parsedKeyProperties = new ArrayList<EdmProperty>();
+ ArrayList<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
+
+ for (final String key : keyPredicate.split(",", -1)) {
+
+ final Matcher matcher = NAMED_VALUE_PATTERN.matcher(key);
+ if (!matcher.matches()) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDKEYPREDICATE.addContent(keyPredicate));
+ }
+
+ String name = percentDecode(matcher.group(1));
+ final String value = percentDecode(matcher.group(2));
+
+ if (name == null) {
+ if (keyProperties.size() == 1) {
+ name = keyProperties.get(0).getName();
+ } else {
+ throw new UriSyntaxException(UriSyntaxException.MISSINGKEYPREDICATENAME.addContent(key));
+ }
+ }
+
+ EdmProperty keyProperty = null;
+ for (final EdmProperty testKeyProperty : keyProperties) {
+ if (testKeyProperty.getName().equals(name)) {
+ keyProperty = testKeyProperty;
+ break;
+ }
+ }
+ if (keyProperty == null) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDKEYPREDICATE.addContent(keyPredicate));
+ }
+ if (parsedKeyProperties.contains(keyProperty)) {
+ throw new UriSyntaxException(UriSyntaxException.DUPLICATEKEYNAMES.addContent(keyPredicate));
+ }
+ parsedKeyProperties.add(keyProperty);
+
+ final EdmLiteral uriLiteral = parseLiteral(value, (EdmSimpleType) keyProperty.getType());
+ keyPredicates.add(new KeyPredicateImpl(uriLiteral.getLiteral(), keyProperty));
+ }
+
+ if (parsedKeyProperties.size() != keyProperties.size()) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDKEYPREDICATE.addContent(keyPredicate));
+ }
+
+ return keyPredicates;
+ }
+
+ private void handleFunctionImport(final EdmFunctionImport functionImport, final String emptyParentheses, final String keyPredicate) throws UriSyntaxException, UriNotMatchingException, EdmException {
+ final EdmTyped returnType = functionImport.getReturnType();
+ final EdmType type = returnType.getType();
+ final boolean isCollection = returnType.getMultiplicity() == EdmMultiplicity.MANY;
+
+ if (type.getKind() == EdmTypeKind.ENTITY && isCollection) {
+ handleEntitySet(functionImport.getEntitySet(), keyPredicate);
+ return;
+ }
+
+ if (emptyParentheses != null) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDSEGMENT.addContent(emptyParentheses));
+ }
+
+ uriResult.setTargetType(type);
+ switch (type.getKind()) {
+ case SIMPLE:
+ uriResult.setUriType(isCollection ? UriType.URI13 : UriType.URI14);
+ break;
+ case COMPLEX:
+ uriResult.setUriType(isCollection ? UriType.URI11 : UriType.URI12);
+ break;
+ case ENTITY:
+ uriResult.setUriType(UriType.URI10);
+ break;
+ default:
+ throw new UriSyntaxException(UriSyntaxException.INVALIDRETURNTYPE.addContent(type.getKind()));
+ }
+
+ if (!pathSegments.isEmpty()) {
+ if (uriResult.getUriType() == UriType.URI14) {
+ currentPathSegment = pathSegments.remove(0);
+ if ("$value".equals(currentPathSegment)) {
+ uriResult.setValue(true);
+ } else {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDSEGMENT.addContent(currentPathSegment));
+ }
+ }
+ }
+ ensureLastSegment();
+ }
+
+ private void distributeQueryParameters(final Map<String, String> queryParameters) throws UriSyntaxException {
+ for (final String queryOptionString : queryParameters.keySet()) {
+ final String value = queryParameters.get(queryOptionString);
+ if (queryOptionString.startsWith("$")) {
+ SystemQueryOption queryOption;
+ try {
+ queryOption = SystemQueryOption.valueOf(queryOptionString);
+ } catch (IllegalArgumentException e) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDSYSTEMQUERYOPTION.addContent(queryOptionString), e);
+ }
+ if ("".equals(value)) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDNULLVALUE.addContent(queryOptionString));
+ } else {
+ systemQueryOptions.put(queryOption, value);
+ }
+ } else {
+ otherQueryParameters.put(queryOptionString, value);
+ }
+ }
+ }
+
+ private void checkSystemQueryOptionsCompatibility() throws UriSyntaxException {
+ final UriType uriType = uriResult.getUriType();
+
+ for (SystemQueryOption queryOption : systemQueryOptions.keySet()) {
+
+ if (queryOption == SystemQueryOption.$format && (uriType == UriType.URI4 || uriType == UriType.URI5) && uriResult.isValue()) {
+ throw new UriSyntaxException(UriSyntaxException.INCOMPATIBLESYSTEMQUERYOPTION.addContent(queryOption));
+ }
+
+ if (!uriType.isCompatible(queryOption)) {
+ throw new UriSyntaxException(UriSyntaxException.INCOMPATIBLESYSTEMQUERYOPTION.addContent(queryOption));
+ }
+ }
+ }
+
+ private void handleSystemQueryOptions() throws UriSyntaxException, UriNotMatchingException, EdmException {
+
+ for (SystemQueryOption queryOption : systemQueryOptions.keySet()) {
+ switch (queryOption) {
+ case $format:
+ handleSystemQueryOptionFormat(systemQueryOptions.get(SystemQueryOption.$format));
+ break;
+ case $filter:
+ handleSystemQueryOptionFilter(systemQueryOptions.get(SystemQueryOption.$filter));
+ break;
+ case $inlinecount:
+ handleSystemQueryOptionInlineCount(systemQueryOptions.get(SystemQueryOption.$inlinecount));
+ break;
+ case $orderby:
+ handleSystemQueryOptionOrderBy(systemQueryOptions.get(SystemQueryOption.$orderby));
+ break;
+ case $skiptoken:
+ handleSystemQueryOptionSkipToken(systemQueryOptions.get(SystemQueryOption.$skiptoken));
+ break;
+ case $skip:
+ handleSystemQueryOptionSkip(systemQueryOptions.get(SystemQueryOption.$skip));
+ break;
+ case $top:
+ handleSystemQueryOptionTop(systemQueryOptions.get(SystemQueryOption.$top));
+ break;
+ case $expand:
+ handleSystemQueryOptionExpand(systemQueryOptions.get(SystemQueryOption.$expand));
+ break;
+ case $select:
+ handleSystemQueryOptionSelect(systemQueryOptions.get(SystemQueryOption.$select));
+ break;
+ default:
+ throw new ODataRuntimeException("Invalid System Query Option " + queryOption);
+ }
+ }
+ }
+
+ private void handleSystemQueryOptionFormat(final String format) throws UriSyntaxException {
+ uriResult.setFormat(format);
+ }
+
+ private void handleSystemQueryOptionFilter(final String filter) throws UriSyntaxException {
+ final EdmType targetType = uriResult.getTargetType();
+ if (targetType instanceof EdmEntityType) {
+ try {
+ uriResult.setFilter(new FilterParserImpl((EdmEntityType) targetType).parseFilterString(filter, true));
+ } catch (ExpressionParserException e) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDFILTEREXPRESSION.addContent(filter), e);
+ } catch (ODataMessageException e) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDFILTEREXPRESSION.addContent(filter), e);
+ }
+ }
+ }
+
+ private void handleSystemQueryOptionOrderBy(final String orderBy) throws UriSyntaxException {
+ final EdmType targetType = uriResult.getTargetType();
+ if (targetType instanceof EdmEntityType) {
+ try {
+ uriResult.setOrderBy(parseOrderByString((EdmEntityType) targetType, orderBy));
+ } catch (ExpressionParserException e) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDORDERBYEXPRESSION.addContent(orderBy), e);
+ } catch (ODataMessageException e) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDORDERBYEXPRESSION.addContent(orderBy), e);
+ }
+ }
+ }
+
+ private void handleSystemQueryOptionInlineCount(final String inlineCount) throws UriSyntaxException {
+ if ("allpages".equals(inlineCount)) {
+ uriResult.setInlineCount(InlineCount.ALLPAGES);
+ } else if ("none".equals(inlineCount)) {
+ uriResult.setInlineCount(InlineCount.NONE);
+ } else {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDVALUE.addContent(inlineCount));
+ }
+ }
+
+ private void handleSystemQueryOptionSkipToken(final String skiptoken) throws UriSyntaxException {
+ uriResult.setSkipToken(skiptoken);
+ }
+
+ private void handleSystemQueryOptionSkip(final String skip) throws UriSyntaxException {
+ try {
+ uriResult.setSkip(Integer.valueOf(skip));
+ } catch (NumberFormatException e) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDVALUE.addContent(skip), e);
+ }
+
+ if (skip.startsWith("-")) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDNEGATIVEVALUE.addContent(skip));
+ } else if (skip.startsWith("+")) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDVALUE.addContent(skip));
+ }
+ }
+
+ private void handleSystemQueryOptionTop(final String top) throws UriSyntaxException {
+ try {
+ uriResult.setTop(Integer.valueOf(top));
+ } catch (NumberFormatException e) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDVALUE.addContent(top), e);
+ }
+
+ if (top.startsWith("-")) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDNEGATIVEVALUE.addContent(top));
+ } else if (top.startsWith("+")) {
+ throw new UriSyntaxException(UriSyntaxException.INVALIDVALUE.addContent(top));
+ }
+ }
+
+ private void handleSystemQueryOptionExpand(final String expandStatement) throws UriSyntaxException, UriNotMatchingException, EdmException {
+ ArrayList<ArrayList<NavigationPropertySegment>> expand = new ArrayList<ArrayList<NavigationPropertySegment>>();
+
+ if (expandStatement.startsWith(",") || expandStatement.endsWith(",")) {
+ throw new UriSyntaxException(UriSyntaxException.EMPTYSEGMENT);
+ }
+
+ for (String expandItemString : expandStatement.split(",")) {
+ expandItemString = expandItemString.trim();
+ if ("".equals(expandItemString)) {
+ throw new UriSyntaxException(UriSyntaxException.EMPTYSEGMENT);
+ }
+ if (expandItemString.startsWith("/") || expandItemString.endsWith("/")) {
+ throw new UriSyntaxException(UriSyntaxException.EMPTYSEGMENT);
+ }
+
+ ArrayList<NavigationPropertySegment> expandNavigationProperties = new ArrayList<NavigationPropertySegment>();
+ EdmEntitySet fromEntitySet = uriResult.getTargetEntitySet();
+
+ for (String expandPropertyName : expandItemString.split("/")) {
+ if ("".equals(expandPropertyName)) {
+ throw new UriSyntaxException(UriSyntaxException.EMPTYSEGMENT);
+ }
+
+ final EdmTyped property = fromEntitySet.getEntityType().getProperty(expandPropertyName);
+ if (property == null) {
+ throw new UriNotMatchingException(UriNotMatchingException.PROPERTYNOTFOUND.addContent(expandPropertyName));
+ }
+ if (property.getType().getKind() == EdmTypeKind.ENTITY) {
+ final EdmNavigationProperty navigationProperty = (EdmNavigationProperty) property;
+ fromEntitySet = fromEntitySet.getRelatedEntitySet(navigationProperty);
+ NavigationPropertySegmentImpl propertySegment = new NavigationPropertySegmentImpl();
+ propertySegment.setNavigationProperty(navigationProperty);
+ propertySegment.setTargetEntitySet(fromEntitySet);
+ expandNavigationProperties.add(propertySegment);
+ } else {
+ throw new UriSyntaxException(UriSyntaxException.NONAVIGATIONPROPERTY.addContent(expandPropertyName));
+ }
+ }
+ expand.add(expandNavigationProperties);
+ }
+ uriResult.setExpand(expand);
+ }
+
+ 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);
+ }
+
+ private void handleOtherQueryParameters() throws UriSyntaxException, EdmException {
+ final EdmFunctionImport functionImport = uriResult.getFunctionImport();
+ if (functionImport != null) {
+ for (final String parameterName : functionImport.getParameterNames()) {
+ final EdmParameter parameter = functionImport.getParameter(parameterName);
+ final String value = otherQueryParameters.remove(parameterName);
+
+ if (value == null) {
+ if (parameter.getFacets() == null || parameter.getFacets().isNullable()) {
+ continue;
+ } else {
+ throw new UriSyntaxException(UriSyntaxException.MISSINGPARAMETER);
+ }
+ }
+
+ EdmLiteral uriLiteral = parseLiteral(value, (EdmSimpleType) parameter.getType());
+ uriResult.addFunctionImportParameter(parameterName, uriLiteral);
+ }
+ }
+
+ uriResult.setCustomQueryOptions(otherQueryParameters);
+ }
+
+ private EdmLiteral parseLiteral(final String value, final EdmSimpleType expectedType) throws UriSyntaxException {
+ EdmLiteral literal;
+ try {
+ literal = simpleTypeFacade.parseUriLiteral(value);
+ } catch (EdmLiteralException e) {
+ throw convertEdmLiteralException(e);
+ }
+
+ if (expectedType.isCompatible(literal.getType())) {
+ return literal;
+ } else {
+ throw new UriSyntaxException(UriSyntaxException.INCOMPATIBLELITERAL.addContent(value, expectedType));
+ }
+ }
+
+ private static UriSyntaxException convertEdmLiteralException(final EdmLiteralException e) {
+ final MessageReference messageReference = e.getMessageReference();
+
+ if (EdmLiteralException.LITERALFORMAT.equals(messageReference)) {
+ return new UriSyntaxException(UriSyntaxException.LITERALFORMAT.addContent(messageReference.getContent()), e);
+ } else if (EdmLiteralException.NOTEXT.equals(messageReference)) {
+ return new UriSyntaxException(UriSyntaxException.NOTEXT.addContent(messageReference.getContent()), e);
+ } else if (EdmLiteralException.UNKNOWNLITERAL.equals(messageReference)) {
+ return new UriSyntaxException(UriSyntaxException.UNKNOWNLITERAL.addContent(messageReference.getContent()), e);
+ } else {
+ return new UriSyntaxException(ODataBadRequestException.COMMON, e);
+ }
+ }
+
+ private static List<String> copyPathSegmentList(final List<PathSegment> source) {
+ List<String> copy = new ArrayList<String>();
+
+ for (final PathSegment segment : source) {
+ copy.add(segment.getPath());
+ }
+
+ return copy;
+ }
+
+ private static String percentDecode(final String value) throws UriSyntaxException {
+ try {
+ return Decoder.decode(value);
+ } catch (RuntimeException e) {
+ throw new UriSyntaxException(UriSyntaxException.URISYNTAX, e);
+ }
+ }
+
+ @Override
+ public FilterExpression parseFilterString(final EdmEntityType entityType, final String expression) throws ExpressionParserException, ODataMessageException {
+ return new FilterParserImpl(entityType).parseFilterString(expression);
+ }
+
+ @Override
+ public OrderByExpression parseOrderByString(final EdmEntityType entityType, final String expression) throws ExpressionParserException, ODataMessageException {
+ return new OrderByParserImpl(entityType).parseOrderByString(expression);
+ }
+
+ @Override
+ public ExpandSelectTreeNode buildExpandSelectTree(final List<SelectItem> select, final List<ArrayList<NavigationPropertySegment>> expand) throws EdmException {
+ return new ExpandSelectTreeCreator(select, expand).create();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ff2b0a0e/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriType.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriType.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriType.java
new file mode 100644
index 0000000..ffe4279
--- /dev/null
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriType.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.core.uri;
+
+import java.util.ArrayList;
+
+/**
+ * @author SAP AG
+ */
+public enum UriType {
+ /**
+ * Service document
+ */
+ URI0(SystemQueryOption.$format),
+ /**
+ * Entity set
+ */
+ URI1(SystemQueryOption.$format, SystemQueryOption.$filter, SystemQueryOption.$inlinecount, SystemQueryOption.$orderby, SystemQueryOption.$skiptoken, SystemQueryOption.$skip, SystemQueryOption.$top, SystemQueryOption.$expand, SystemQueryOption.$select),
+ /**
+ * Entity set with key predicate
+ */
+ URI2(SystemQueryOption.$format, SystemQueryOption.$filter, SystemQueryOption.$expand, SystemQueryOption.$select),
+ /**
+ * Complex property of an entity
+ */
+ URI3(SystemQueryOption.$format),
+ /**
+ * Simple property of a complex property of an entity
+ */
+ URI4(SystemQueryOption.$format),
+ /**
+ * Simple property of an entity
+ */
+ URI5(SystemQueryOption.$format),
+ /**
+ * Navigation property of an entity with target multiplicity '1' or '0..1'
+ */
+ URI6A(SystemQueryOption.$format, SystemQueryOption.$filter, SystemQueryOption.$expand, SystemQueryOption.$select),
+ /**
+ * Navigation property of an entity with target multiplicity '*'
+ */
+ URI6B(SystemQueryOption.$format, SystemQueryOption.$filter, SystemQueryOption.$inlinecount, SystemQueryOption.$orderby, SystemQueryOption.$skiptoken, SystemQueryOption.$skip, SystemQueryOption.$top, SystemQueryOption.$expand, SystemQueryOption.$select),
+ /**
+ * Link to a single entity
+ */
+ URI7A(SystemQueryOption.$format, SystemQueryOption.$filter),
+ /**
+ * Link to multiple entities
+ */
+ URI7B(SystemQueryOption.$format, SystemQueryOption.$filter, SystemQueryOption.$inlinecount, SystemQueryOption.$orderby, SystemQueryOption.$skiptoken, SystemQueryOption.$skip, SystemQueryOption.$top),
+ /**
+ * Metadata document
+ */
+ URI8(),
+ /**
+ * Batch request
+ */
+ URI9(),
+ /**
+ * Function import returning a single instance of an entity type
+ */
+ URI10(SystemQueryOption.$format),
+ /**
+ * Function import returning a collection of complex-type instances
+ */
+ URI11(SystemQueryOption.$format),
+ /**
+ * Function import returning a single instance of a complex type
+ */
+ URI12(SystemQueryOption.$format),
+ /**
+ * Function import returning a collection of primitive-type instances
+ */
+ URI13(SystemQueryOption.$format),
+ /**
+ * Function import returning a single instance of a primitive type
+ */
+ URI14(SystemQueryOption.$format),
+ /**
+ * Count of an entity set
+ */
+ URI15(SystemQueryOption.$filter, SystemQueryOption.$orderby, SystemQueryOption.$skip, SystemQueryOption.$top),
+ /**
+ * Count of a single entity
+ */
+ URI16(SystemQueryOption.$filter),
+ /**
+ * Media resource of an entity
+ */
+ URI17(SystemQueryOption.$format, SystemQueryOption.$filter),
+ /**
+ * Count of link to a single entity
+ */
+ URI50A(SystemQueryOption.$filter),
+ /**
+ * Count of links to multiple entities
+ */
+ URI50B(SystemQueryOption.$filter, SystemQueryOption.$orderby, SystemQueryOption.$skip, SystemQueryOption.$top);
+
+ private ArrayList<SystemQueryOption> whiteList = new ArrayList<SystemQueryOption>();
+
+ private UriType(final SystemQueryOption... compatibleQueryOptions) {
+ for (SystemQueryOption queryOption : compatibleQueryOptions) {
+ whiteList.add(queryOption);
+ }
+ }
+
+ public boolean isCompatible(final SystemQueryOption queryOption) {
+ return whiteList.contains(queryOption);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ff2b0a0e/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/ActualBinaryOperator.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/ActualBinaryOperator.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/ActualBinaryOperator.java
new file mode 100644
index 0000000..aa73a06
--- /dev/null
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/ActualBinaryOperator.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.core.uri.expression;
+
+public class ActualBinaryOperator {
+ final protected InfoBinaryOperator operator;
+ final protected Token token;
+
+ public ActualBinaryOperator(final InfoBinaryOperator operatorInfo, final Token token) {
+ if (operatorInfo == null) {
+ throw new IllegalArgumentException("operatorInfo parameter must not be null");
+ }
+
+ operator = operatorInfo;
+ this.token = token;
+ }
+
+ public Token getToken() {
+ return token;
+ }
+
+ public InfoBinaryOperator getOP() {
+ return operator;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ff2b0a0e/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/BinaryExpressionImpl.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/BinaryExpressionImpl.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/BinaryExpressionImpl.java
new file mode 100644
index 0000000..f2e8af9
--- /dev/null
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/BinaryExpressionImpl.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.core.uri.expression;
+
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.uri.expression.BinaryExpression;
+import org.apache.olingo.odata2.api.uri.expression.BinaryOperator;
+import org.apache.olingo.odata2.api.uri.expression.CommonExpression;
+import org.apache.olingo.odata2.api.uri.expression.ExceptionVisitExpression;
+import org.apache.olingo.odata2.api.uri.expression.ExpressionKind;
+import org.apache.olingo.odata2.api.uri.expression.ExpressionVisitor;
+
+/**
+ * @author SAP AG
+ */
+public class BinaryExpressionImpl implements BinaryExpression {
+ final protected InfoBinaryOperator operatorInfo;
+ final protected CommonExpression leftSide;
+ final protected CommonExpression rightSide;
+ final protected Token token;
+ protected EdmType edmType;
+
+ public BinaryExpressionImpl(final InfoBinaryOperator operatorInfo, final CommonExpression leftSide, final CommonExpression rightSide, final Token token) {
+ this.operatorInfo = operatorInfo;
+ this.leftSide = leftSide;
+ this.rightSide = rightSide;
+ this.token = token;
+ edmType = null;
+ }
+
+ @Override
+ public BinaryOperator getOperator() {
+ return operatorInfo.getOperator();
+ }
+
+ @Override
+ public CommonExpression getLeftOperand() {
+ return leftSide;
+ }
+
+ @Override
+ public CommonExpression getRightOperand() {
+ return rightSide;
+ }
+
+ @Override
+ public EdmType getEdmType() {
+ return edmType;
+ }
+
+ @Override
+ public CommonExpression setEdmType(final EdmType edmType) {
+ this.edmType = edmType;
+ return this;
+ }
+
+ @Override
+ public ExpressionKind getKind() {
+ return ExpressionKind.BINARY;
+ }
+
+ @Override
+ public String getUriLiteral() {
+ return operatorInfo.getSyntax();
+ }
+
+ @Override
+ public Object accept(final ExpressionVisitor visitor) throws ExceptionVisitExpression, ODataApplicationException {
+ Object retLeftSide = leftSide.accept(visitor);
+ Object retRightSide = rightSide.accept(visitor);
+
+ return visitor.visitBinary(this, operatorInfo.getOperator(), retLeftSide, retRightSide);
+ }
+
+ public Token getToken() {
+ return token;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ff2b0a0e/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/ExpressionParserInternalError.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/ExpressionParserInternalError.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/ExpressionParserInternalError.java
new file mode 100644
index 0000000..76033f9
--- /dev/null
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/ExpressionParserInternalError.java
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.core.uri.expression;
+
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.exception.MessageReference;
+import org.apache.olingo.odata2.api.exception.ODataMessageException;
+import org.apache.olingo.odata2.api.uri.expression.CommonExpression;
+
+/**
+ * Internal error in the expression parser.
+ * @author SAP AG
+ */
+public class ExpressionParserInternalError extends ODataMessageException {
+
+ static final long serialVersionUID = 77L;
+ public static final MessageReference ERROR_PARSING_METHOD = createMessageReference(ExpressionParserInternalError.class, "ERROR_PARSING_METHOD");
+ public static final MessageReference ERROR_PARSING_PARENTHESIS = createMessageReference(ExpressionParserInternalError.class, "ERROR_PARSING_PARENTHESIS");
+ public static final MessageReference ERROR_ACCESSING_EDM = createMessageReference(ExpressionParserInternalError.class, "ERROR_ACCESSING_EDM");
+ public static final MessageReference INVALID_TYPE_COUNT = createMessageReference(ExpressionParserInternalError.class, "INVALID_TYPE_COUNT");;
+ public static final MessageReference INVALID_TOKEN_AT = createMessageReference(ExpressionParserInternalError.class, "INVALID_TOKEN_AT");
+ public static final MessageReference INVALID_TOKENKIND_AT = createMessageReference(ExpressionParserInternalError.class, "INVALID_TOKENKIND_AT");
+
+ CommonExpression parenthesisExpression = null;
+
+ public ExpressionParserInternalError(final MessageReference messageReference) {
+ super(messageReference);
+ }
+
+ public ExpressionParserInternalError(final MessageReference messageReference, final Throwable cause) {
+ super(messageReference, cause);
+ }
+
+ public ExpressionParserInternalError(final MessageReference messageReference, final TokenizerExpectError cause) {
+ super(messageReference, cause);
+ }
+
+ public ExpressionParserInternalError(final MessageReference messageReference, final EdmException cause) {
+ super(messageReference, cause);
+ }
+
+ public ExpressionParserInternalError setExpression(final CommonExpression parenthesisExpression) {
+ this.parenthesisExpression = parenthesisExpression;
+ return this;
+ }
+
+ public static ExpressionParserInternalError createERROR_PARSING_METHOD(final TokenizerExpectError cause) {
+ return new ExpressionParserInternalError(ERROR_PARSING_METHOD, cause);
+ }
+
+ public static ExpressionParserInternalError createERROR_PARSING_PARENTHESIS(final TokenizerExpectError cause) {
+ return new ExpressionParserInternalError(ERROR_PARSING_PARENTHESIS, cause);
+ }
+
+ public static ExpressionParserInternalError createERROR_PARSING_PARENTHESIS(final CommonExpression parenthesisExpression, final TokenizerExpectError cause) {
+ return new ExpressionParserInternalError(ERROR_PARSING_PARENTHESIS, cause).setExpression(parenthesisExpression);
+ }
+
+ public static ExpressionParserInternalError createERROR_ACCESSING_EDM(final EdmException cause) {
+ return new ExpressionParserInternalError(ERROR_ACCESSING_EDM, cause);
+ }
+
+ public static ExpressionParserInternalError createCOMMON() {
+ return new ExpressionParserInternalError(COMMON);
+ }
+
+ public static ExpressionParserInternalError createCOMMON(final Throwable e) {
+ return new ExpressionParserInternalError(COMMON, e);
+ }
+
+ public static ExpressionParserInternalError createINVALID_TYPE_COUNT() {
+ return new ExpressionParserInternalError(INVALID_TYPE_COUNT);
+ }
+
+ public static ExpressionParserInternalError createERROR_ACCESSING_EDM() {
+ return new ExpressionParserInternalError(ERROR_ACCESSING_EDM);
+ }
+
+ public static ExpressionParserInternalError createINVALID_TOKEN_AT(final String expectedToken, final Token actualToken) {
+ MessageReference msgRef = ExpressionParserInternalError.INVALID_TOKEN_AT.create();
+
+ msgRef.addContent(expectedToken);
+ msgRef.addContent(actualToken.getUriLiteral());
+ msgRef.addContent(actualToken.getPosition());
+
+ return new ExpressionParserInternalError(msgRef);
+ }
+
+ public static ExpressionParserInternalError createINVALID_TOKENKIND_AT(final TokenKind expectedTokenKind, final Token actualToken) {
+ MessageReference msgRef = ExpressionParserInternalError.INVALID_TOKEN_AT.create();
+
+ msgRef.addContent(expectedTokenKind.toString());
+ msgRef.addContent(actualToken.getKind().toString());
+ msgRef.addContent(actualToken.getUriLiteral());
+ msgRef.addContent(actualToken.getPosition());
+
+ return new ExpressionParserInternalError(msgRef);
+ }
+
+ public static ExpressionParserInternalError createNO_TOKEN_AVAILABLE(final String expectedToken) {
+ MessageReference msgRef = ExpressionParserInternalError.INVALID_TOKEN_AT.create();
+
+ msgRef.addContent(expectedToken);
+
+ return new ExpressionParserInternalError(msgRef);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ff2b0a0e/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterExpressionImpl.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterExpressionImpl.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterExpressionImpl.java
new file mode 100644
index 0000000..dcec62e
--- /dev/null
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterExpressionImpl.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.core.uri.expression;
+
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.uri.expression.CommonExpression;
+import org.apache.olingo.odata2.api.uri.expression.ExceptionVisitExpression;
+import org.apache.olingo.odata2.api.uri.expression.ExpressionKind;
+import org.apache.olingo.odata2.api.uri.expression.ExpressionVisitor;
+import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
+
+/**
+ * @author SAP AG
+ */
+public class FilterExpressionImpl implements FilterExpression {
+ private final String filterString;
+ private EdmType edmType;
+ private CommonExpression commonExpression;
+
+ public FilterExpressionImpl(final String filterExpression) {
+ filterString = filterExpression;
+ }
+
+ public FilterExpressionImpl(final String filterExpression, final CommonExpression childExpression) {
+ filterString = filterExpression;
+ commonExpression = childExpression;
+ }
+
+ @Override
+ public String getExpressionString() {
+ return filterString;
+ }
+
+ @Override
+ public CommonExpression getExpression() {
+ return commonExpression;
+ }
+
+ @Override
+ public Object accept(final ExpressionVisitor visitor) throws ExceptionVisitExpression, ODataApplicationException {
+ Object retCommonExpression = commonExpression.accept(visitor);
+
+ return visitor.visitFilterExpression(this, filterString, retCommonExpression);
+ }
+
+ @Override
+ public CommonExpression setEdmType(final EdmType edmType) {
+ this.edmType = edmType;
+ return this;
+ }
+
+ @Override
+ public EdmType getEdmType() {
+ return edmType;
+ }
+
+ @Override
+ public ExpressionKind getKind() {
+ return ExpressionKind.FILTER;
+ }
+
+ @Override
+ public String getUriLiteral() {
+ return getExpressionString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ff2b0a0e/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParser.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParser.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParser.java
new file mode 100644
index 0000000..6697b6c
--- /dev/null
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParser.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.core.uri.expression;
+
+import org.apache.olingo.odata2.api.exception.ODataMessageException;
+import org.apache.olingo.odata2.api.uri.expression.ExpressionParserException;
+import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
+
+/**
+ * Interface which defines a method for parsing a $filter expression to allow different parser implementations
+ * <p>
+ * The current expression parser supports expressions as defined in the OData specification 2.0 with the following restrictions
+ * - the methods "cast", "isof" and "replace" are not supported
+ *
+ * The expression parser can be used with providing an Entity Data Model (EDM) an without providing it.
+ * <p>When a EDM is provided the expression parser will be as strict as possible. That means:
+ * <li>All properties used in the expression must be defined inside the EDM</li>
+ * <li>The types of EDM properties will be checked against the lists of allowed type per method, binary- and unary operator</li>
+ * </p>
+ * <p>If no EDM is provided the expression parser performs a lax validation
+ * <li>The properties used in the expression are not looked up inside the EDM and the type of the expression node representing the
+ * property will be "null"</li>
+ * <li>Expression node with EDM-types which are "null" are not considered during the parameter type validation, to the return type of the parent expression node will
+ * also become "null"</li>
+ *
+ * @author SAP AG
+ */
+public interface FilterParser {
+ /**
+ * Parses a $filter expression string and creates an $orderby expression tree.
+ * @param expression
+ * The $filter expression string ( for example "city eq 'Sydney'" ) to be parsed
+ * @return
+ * Expression tree which can be traversed with help of the interfaces {@link org.apache.olingo.odata2.api.uri.expression.ExpressionVisitor} and {@link org.apache.olingo.odata2.api.uri.expression.Visitable}
+ * @throws ExpressionParserException
+ * Exception thrown due to errors while parsing the $filter expression string
+ * @throws ODataMessageException
+ * Used for extensibility
+ **/
+ FilterExpression parseFilterString(String expression) throws ExpressionParserException, ODataMessageException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ff2b0a0e/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParserExceptionImpl.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParserExceptionImpl.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParserExceptionImpl.java
new file mode 100644
index 0000000..c3df6d7
--- /dev/null
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/expression/FilterParserExceptionImpl.java
@@ -0,0 +1,289 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.core.uri.expression;
+
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmStructuralType;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.exception.MessageReference;
+import org.apache.olingo.odata2.api.exception.ODataBadRequestException;
+import org.apache.olingo.odata2.api.uri.expression.BinaryOperator;
+import org.apache.olingo.odata2.api.uri.expression.CommonExpression;
+import org.apache.olingo.odata2.api.uri.expression.ExpressionParserException;
+import org.apache.olingo.odata2.api.uri.expression.PropertyExpression;
+
+/**
+ * This class is used to create exceptions of type FilterParserException.
+ * Because this class lies inside org.apache.olingo.odata2.core it is possible to define better/more detailed
+ * input parameters for inserting into the exception text.<br>
+ * The exception {@link ExpressionParserException} does not know the org.apache.olingo.odata2.core content
+ *
+ * @author SAP AG
+ */
+public class FilterParserExceptionImpl extends ExpressionParserException {
+ private static final long serialVersionUID = 77L;
+
+ static public ExpressionParserException createCOMMON() {
+ return new ExpressionParserException(ODataBadRequestException.COMMON);
+ }
+
+ static public ExpressionParserException createERROR_IN_TOKENIZER(final TokenizerException exceptionTokenizer, final String expression) {
+ Token token = exceptionTokenizer.getToken();
+ MessageReference msgRef = ExpressionParserException.ERROR_IN_TOKENIZER.create();
+
+ msgRef.addContent(token.getUriLiteral());
+ msgRef.addContent(Integer.toString(token.getPosition() + 1));
+ msgRef.addContent(expression);
+
+ return new ExpressionParserException(msgRef, exceptionTokenizer);
+ }
+
+ static public ExpressionParserException createINVALID_TRAILING_TOKEN_DETECTED_AFTER_PARSING(final Token token, final String expression) {
+ MessageReference msgRef = ExpressionParserException.INVALID_TRAILING_TOKEN_DETECTED_AFTER_PARSING.create();
+
+ msgRef.addContent(token.getUriLiteral());
+ msgRef.addContent(Integer.toString(token.getPosition() + 1));
+ msgRef.addContent(expression);
+
+ return new ExpressionParserException(msgRef);
+ }
+
+ static public ExpressionParserException createEXPRESSION_EXPECTED_AFTER_POS(final Token token, final String expression) {
+ MessageReference msgRef = ExpressionParserException.EXPRESSION_EXPECTED_AFTER_POS.create();
+
+ msgRef.addContent(Integer.toString(token.getPosition() + 1));
+ msgRef.addContent(expression);
+
+ return new ExpressionParserException(msgRef);
+ }
+
+ static public ExpressionParserException createEXPRESSION_EXPECTED_AFTER_POS(final int position, final String expression) {
+ MessageReference msgRef = ExpressionParserException.EXPRESSION_EXPECTED_AFTER_POS.create();
+
+ msgRef.addContent(position);
+ msgRef.addContent(expression);
+
+ return new ExpressionParserException(msgRef);
+ }
+
+ static public ExpressionParserException createCOMMA_OR_END_EXPECTED_AT_POS(final Token token, final String expression) {
+ MessageReference msgRef = ExpressionParserException.COMMA_OR_END_EXPECTED_AT_POS.create();
+
+ msgRef.addContent(Integer.toString(token.getPosition() + 1));
+ msgRef.addContent(expression);
+
+ return new ExpressionParserException(msgRef);
+ }
+
+ static public ExpressionParserException createEXPRESSION_EXPECTED_AT_POS(final Token token, final String expression) {
+ MessageReference msgRef = ExpressionParserException.EXPRESSION_EXPECTED_AT_POS.create();
+
+ msgRef.addContent(Integer.toString(token.getPosition() + 1));
+ msgRef.addContent(expression);
+
+ return new ExpressionParserException(msgRef);
+ }
+
+ static public ExpressionParserException createCOMMA_OR_CLOSING_PHARENTHESIS_EXPECTED_AFTER_POS(final Token token, final String expression) {
+ MessageReference msgRef = ExpressionParserException.COMMA_OR_CLOSING_PHARENTHESIS_EXPECTED_AFTER_POS.create();
+
+ msgRef.addContent(Integer.toString(token.getPosition() + token.getUriLiteral().length()));
+ msgRef.addContent(expression);
+
+ return new ExpressionParserException(msgRef);
+ }
+
+ public static ExpressionParserException createMETHOD_WRONG_ARG_COUNT(final MethodExpressionImpl methodExpression, final Token token, final String expression) {
+ MessageReference msgRef = null;
+ int minParam = methodExpression.getMethodInfo().getMinParameter();
+ int maxParam = methodExpression.getMethodInfo().getMaxParameter();
+
+ if ((minParam == -1) && (maxParam == -1)) {
+ //no exception thrown in this case
+ } else if ((minParam != -1) && (maxParam == -1)) {
+ //Tested with TestParserExceptions.TestPMreadParameters CASE 7-1
+ msgRef = ExpressionParserException.METHOD_WRONG_ARG_X_OR_MORE.create();
+ msgRef.addContent(methodExpression.getMethod().toUriLiteral());
+ msgRef.addContent(token.getPosition() + 1);
+ msgRef.addContent(expression);
+ msgRef.addContent(minParam);
+ } else if ((minParam == -1) && (maxParam != -1)) {
+ //Tested with TestParserExceptions.TestPMreadParameters CASE 8-2
+ msgRef = ExpressionParserException.METHOD_WRONG_ARG_X_OR_LESS.create();
+ msgRef.addContent(methodExpression.getMethod().toUriLiteral());
+ msgRef.addContent(token.getPosition() + 1);
+ msgRef.addContent(expression);
+ msgRef.addContent(maxParam);
+ } else if ((minParam != -1) && (maxParam != -1)) {
+ if (minParam == maxParam) {
+ //Tested with TestParserExceptions.TestPMreadParameters CASE 11-1
+ msgRef = ExpressionParserException.METHOD_WRONG_ARG_EXACT.create();
+ msgRef.addContent(methodExpression.getMethod().toUriLiteral());
+ msgRef.addContent(token.getPosition() + 1);
+ msgRef.addContent(expression);
+ msgRef.addContent(minParam);
+ } else {
+ //Tested with TestParserExceptions.TestPMreadParameters CASE 10-1
+ msgRef = ExpressionParserException.METHOD_WRONG_ARG_BETWEEN.create();
+ msgRef.addContent(methodExpression.getMethod().toUriLiteral());
+ msgRef.addContent(token.getPosition() + 1);
+ msgRef.addContent(expression);
+ msgRef.addContent(minParam);
+ msgRef.addContent(maxParam);
+ }
+ }
+
+ return new ExpressionParserException(msgRef);
+ }
+
+ public static ExpressionParserException createMETHOD_WRONG_INPUT_TYPE(final MethodExpressionImpl methodExpression, final Token token, final String expression) {
+ MessageReference msgRef = null;
+
+ //Tested with TestParserExceptions.TestPMreadParameters CASE 7-1
+ msgRef = ExpressionParserException.METHOD_WRONG_INPUT_TYPE.create();
+ msgRef.addContent(methodExpression.getMethod().toUriLiteral());
+ msgRef.addContent(token.getPosition() + 1);
+ msgRef.addContent(expression);
+
+ return new ExpressionParserException(msgRef);
+ }
+
+ public static ExpressionParserException createLEFT_SIDE_NOT_A_PROPERTY(final Token token, final String expression) throws ExpressionParserInternalError {
+ MessageReference msgRef = ExpressionParserException.LEFT_SIDE_NOT_A_PROPERTY.create();
+
+ msgRef.addContent(token.getPosition() + 1);
+ msgRef.addContent(expression);
+
+ return new ExpressionParserException(msgRef);
+ }
+
+ public static ExpressionParserException createLEFT_SIDE_NOT_STRUCTURAL_TYPE(final EdmType parentType, final PropertyExpressionImpl property, final Token token, final String expression) throws ExpressionParserInternalError {
+ MessageReference msgRef = ExpressionParserException.LEFT_SIDE_NOT_STRUCTURAL_TYPE.create();
+
+ try {
+ msgRef.addContent(property.getUriLiteral());
+ msgRef.addContent(parentType.getNamespace() + "." + parentType.getName());
+ msgRef.addContent(token.getPosition() + 1);
+ msgRef.addContent(expression);
+ } catch (EdmException e) {
+ throw ExpressionParserInternalError.createERROR_ACCESSING_EDM(e);
+ }
+
+ return new ExpressionParserException(msgRef);
+ }
+
+ public static ExpressionParserException createPROPERTY_NAME_NOT_FOUND_IN_TYPE(final EdmStructuralType parentType, final PropertyExpression property, final Token token, final String expression) throws ExpressionParserInternalError {
+ MessageReference msgRef = ExpressionParserException.PROPERTY_NAME_NOT_FOUND_IN_TYPE.create();
+
+ try {
+ msgRef.addContent(property.getUriLiteral());
+ msgRef.addContent(parentType.getNamespace() + "." + parentType.getName());
+ msgRef.addContent(token.getPosition() + 1);
+ msgRef.addContent(expression);
+ } catch (EdmException e) {
+ throw ExpressionParserInternalError.createERROR_ACCESSING_EDM(e);
+ }
+
+ return new ExpressionParserException(msgRef);
+ }
+
+ public static ExpressionParserException createTOKEN_UNDETERMINATED_STRING(final int position, final String expression) {
+ MessageReference msgRef = ExpressionParserException.TOKEN_UNDETERMINATED_STRING.create();
+
+ msgRef.addContent(position + 1);
+ msgRef.addContent(expression);
+
+ return new ExpressionParserException(msgRef);
+ }
+
+ public static ExpressionParserException createINVALID_TYPES_FOR_BINARY_OPERATOR(final BinaryOperator op, final EdmType left, final EdmType right, final Token token, final String expression) {
+ MessageReference msgRef = ExpressionParserException.INVALID_TYPES_FOR_BINARY_OPERATOR.create();
+
+ msgRef.addContent(op.toUriLiteral());
+
+ try {
+ msgRef.addContent(left.getNamespace() + "." + left.getName());
+ } catch (EdmException e) {
+ msgRef.addContent("");
+ }
+ try {
+ msgRef.addContent(right.getNamespace() + "." + right.getName());
+ } catch (EdmException e) {
+ msgRef.addContent("");
+ }
+ msgRef.addContent(token.getPosition() + 1);
+ msgRef.addContent(expression);
+
+ return new ExpressionParserException(msgRef);
+ }
+
+ public static ExpressionParserException createMISSING_CLOSING_PHARENTHESIS(final int position, final String expression, final TokenizerExpectError e) {
+ MessageReference msgRef = ExpressionParserException.MISSING_CLOSING_PHARENTHESIS.create();
+
+ msgRef.addContent(position + 1);
+ msgRef.addContent(expression);
+
+ return new ExpressionParserException(msgRef, e);
+ }
+
+ public static ExpressionParserException createINVALID_SORT_ORDER(final Token token, final String expression) {
+ MessageReference msgRef = ExpressionParserException.INVALID_SORT_ORDER.create();
+ msgRef.addContent(token.getPosition() + 1);
+ msgRef.addContent(expression);
+
+ return new ExpressionParserException(msgRef);
+ }
+
+ public static ExpressionParserException createINVALID_METHOD_CALL(final CommonExpression leftNode, final Token prevToken, final String expression) {
+ final MessageReference msgRef = ExpressionParserException.INVALID_METHOD_CALL.create();
+
+ msgRef.addContent(leftNode.getUriLiteral());
+ msgRef.addContent(prevToken.getPosition() + 1);
+ msgRef.addContent(expression);
+
+ return new ExpressionParserException(msgRef);
+
+ }
+
+ public static ExpressionParserException createTYPE_EXPECTED_AT(final EdmType expectedType, final EdmType actualType, final int position, final String expression) {
+ final MessageReference msgRef = ExpressionParserException.TYPE_EXPECTED_AT.create();
+
+ try {
+ msgRef.addContent(expectedType.getNamespace() + '.' + expectedType.getName());
+ } catch (EdmException e) {
+ msgRef.addContent("");
+ }
+
+ msgRef.addContent(position);
+ msgRef.addContent(expression);
+
+ if (actualType != null) {
+ try {
+ msgRef.addContent(actualType.getNamespace() + '.' + actualType.getName());
+ } catch (EdmException e) {
+ msgRef.addContent("");
+ }
+ } else {
+ msgRef.addContent("null");
+ }
+
+ return new ExpressionParserException(msgRef);
+
+ }
+}