private void ensureReferencedTypeNotNull(final EdmStructuredType referencedType) throws UriParserException { if (referencedType == null) { throw new UriParserSemanticException("The referenced part is not typed.", UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS, "select"); } }
public static ODataServerError createServerErrorObject(final UriParserSemanticException e, final Locale requestedLocale) { ODataServerError serverError = basicTranslatedError(e, requestedLocale); if (UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND.equals(e.getMessageKey()) || UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE.equals(e.getMessageKey())) { serverError.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode()); } else if (UriParserSemanticException.MessageKeys.NOT_IMPLEMENTED.equals(e.getMessageKey())) { serverError.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode()); } else { serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode()); } return serverError; }
private void ensureReferencedTypeNotNull(final EdmStructuredType referencedType) throws UriParserException { if (referencedType == null) { throw new UriParserSemanticException("The referenced part is not typed.", UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS, "select"); } }
public static ODataServerError createServerErrorObject(final UriParserSemanticException e, final Locale requestedLocale) { ODataServerError serverError = basicTranslatedError(e, requestedLocale); if (UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND.equals(e.getMessageKey()) || UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE.equals(e.getMessageKey())) { serverError.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode()); } else if (UriParserSemanticException.MessageKeys.NOT_IMPLEMENTED.equals(e.getMessageKey())) { serverError.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode()); } else { serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode()); } return serverError; }
private void requireTyped(final UriResource previous, final String forWhat) throws UriParserException { if (!(previous instanceof UriResourcePartTyped)) { throw new UriParserSemanticException("Path segment before '" + forWhat + "' is not typed.", UriParserSemanticException.MessageKeys.PREVIOUS_PART_NOT_TYPED, forWhat); } }
private void requireTyped(final UriResource previous, final String forWhat) throws UriParserException { if (!(previous instanceof UriResourcePartTyped)) { throw new UriParserSemanticException("Path segment before '" + forWhat + "' is not typed.", UriParserSemanticException.MessageKeys.PREVIOUS_PART_NOT_TYPED, forWhat); } }
private void checkNoCollection(final Expression expression) throws UriParserException { if (expression instanceof Member && ((Member) expression).isCollection()) { throw new UriParserSemanticException("Collection not allowed.", UriParserSemanticException.MessageKeys.COLLECTION_NOT_ALLOWED); } }
private void checkNoCollection(final Expression expression) throws UriParserException { if (expression instanceof Member && ((Member) expression).isCollection()) { throw new UriParserSemanticException("Collection not allowed.", UriParserSemanticException.MessageKeys.COLLECTION_NOT_ALLOWED); } }
private EdmEnumType getEnumType(final String primitiveValueLiteral) throws UriParserException { final String enumTypeName = primitiveValueLiteral.substring(0, primitiveValueLiteral.indexOf('\'')); final EdmEnumType type = edm.getEnumType(new FullQualifiedName(enumTypeName)); if (type == null) { throw new UriParserSemanticException("Unknown Enum type '" + enumTypeName + "'.", UriParserSemanticException.MessageKeys.UNKNOWN_TYPE, enumTypeName); } return type; }
private EdmEnumType getEnumType(final String primitiveValueLiteral) throws UriParserException { final String enumTypeName = primitiveValueLiteral.substring(0, primitiveValueLiteral.indexOf('\'')); final EdmEnumType type = edm.getEnumType(new FullQualifiedName(enumTypeName)); if (type == null) { throw new UriParserSemanticException("Unknown Enum type '" + enumTypeName + "'.", UriParserSemanticException.MessageKeys.UNKNOWN_TYPE, enumTypeName); } return type; }
private Enumeration createEnumExpression(final String primitiveValueLiteral) throws UriParserException { final EdmEnumType enumType = getEnumType(primitiveValueLiteral); // The Enumeration interface could be extended to handle the value as a whole, in line with the primitive type. try { return new EnumerationImpl(enumType, Arrays.asList(enumType.fromUriLiteral(primitiveValueLiteral).split(","))); } catch (final EdmPrimitiveTypeException e) { // This part should not be reached, so a general error message key can be re-used. throw new UriParserSemanticException("Wrong enumeration value '" + primitiveValueLiteral + "'.", e, UriParserSemanticException.MessageKeys.UNKNOWN_PART, primitiveValueLiteral); } }
private Enumeration createEnumExpression(final String primitiveValueLiteral) throws UriParserException { final EdmEnumType enumType = getEnumType(primitiveValueLiteral); // The Enumeration interface could be extended to handle the value as a whole, in line with the primitive type. try { return new EnumerationImpl(enumType, Arrays.asList(enumType.fromUriLiteral(primitiveValueLiteral).split(","))); } catch (final EdmPrimitiveTypeException e) { // This part should not be reached, so a general error message key can be re-used. throw new UriParserSemanticException("Wrong enumeration value '" + primitiveValueLiteral + "'.", e, UriParserSemanticException.MessageKeys.UNKNOWN_PART, primitiveValueLiteral); } }
private void checkType(final Expression expression, final EdmPrimitiveTypeKind... kinds) throws UriParserException { final EdmType type = getType(expression); if (!isType(type, kinds)) { throw new UriParserSemanticException("Incompatible types.", UriParserSemanticException.MessageKeys.TYPES_NOT_COMPATIBLE, type == null ? "" : type.getFullQualifiedName().getFullQualifiedNameAsString(), Arrays.deepToString(kinds)); } }
private void checkStructuredTypeFilter(final EdmType type, final EdmType filterType) throws UriParserException { if (!(filterType instanceof EdmStructuredType && ((EdmStructuredType) filterType).compatibleTo(type))) { throw new UriParserSemanticException("Incompatible type filter.", UriParserSemanticException.MessageKeys.INCOMPATIBLE_TYPE_FILTER, filterType.getFullQualifiedName().getFullQualifiedNameAsString()); } } }
private void checkType(final Expression expression, final EdmPrimitiveTypeKind... kinds) throws UriParserException { final EdmType type = getType(expression); if (!isType(type, kinds)) { throw new UriParserSemanticException("Incompatible types.", UriParserSemanticException.MessageKeys.TYPES_NOT_COMPATIBLE, type == null ? "" : type.getFullQualifiedName().getFullQualifiedNameAsString(), Arrays.deepToString(kinds)); } }
private void checkStructuredTypeFilter(final EdmType type, final EdmType filterType) throws UriParserException { if (!(filterType instanceof EdmStructuredType && ((EdmStructuredType) filterType).compatibleTo(type))) { throw new UriParserSemanticException("Incompatible type filter.", UriParserSemanticException.MessageKeys.INCOMPATIBLE_TYPE_FILTER, filterType.getFullQualifiedName().getFullQualifiedNameAsString()); } } }
throw new UriParserSemanticException("Too many key properties.", UriParserSemanticException.MessageKeys.WRONG_NUMBER_OF_KEY_PROPERTIES, Integer.toString(parameters.size()), Integer.toString(parameters.size() + 1));
throw new UriParserSemanticException("Too many key properties.", UriParserSemanticException.MessageKeys.WRONG_NUMBER_OF_KEY_PROPERTIES, Integer.toString(parameters.size()), Integer.toString(parameters.size() + 1));
private UriResource ref(final UriResource previous) throws UriParserException { ParserHelper.requireTokenEnd(tokenizer); requireTyped(previous, "$ref"); if (((UriResourcePartTyped) previous).getType() instanceof EdmEntityType) { return new UriResourceRefImpl(); } else { throw new UriParserSemanticException("$ref is only allowed on entity types.", UriParserSemanticException.MessageKeys.ONLY_FOR_ENTITY_TYPES, "$ref"); } }
private UriResource count(final UriResource previous) throws UriParserException { ParserHelper.requireTokenEnd(tokenizer); requireTyped(previous, "$count"); if (((UriResourcePartTyped) previous).isCollection()) { return new UriResourceCountImpl(); } else { throw new UriParserSemanticException("$count is only allowed on collections.", UriParserSemanticException.MessageKeys.ONLY_FOR_COLLECTIONS, "$count"); } }