From 3ece19c964bdefb7cee68d6ffd7d959f59238655 Mon Sep 17 00:00:00 2001 From: Michael Bolz Date: Wed, 3 Sep 2014 11:04:36 +0200 Subject: [PATCH] [OLINGO-356] Rework EdmPrimitive Type exceptions --- .../api/edm/EdmPrimitiveTypeException.java | 4 +- .../commons/core/edm/AbstractEdmEnumType.java | 22 ++-- .../primitivetype/AbstractGeospatialType.java | 32 ++--- .../primitivetype/AbstractPrimitiveType.java | 13 +- .../core/edm/primitivetype/EdmBinary.java | 13 +- .../core/edm/primitivetype/EdmBoolean.java | 9 +- .../core/edm/primitivetype/EdmByte.java | 22 ++-- .../core/edm/primitivetype/EdmDate.java | 8 +- .../core/edm/primitivetype/EdmDateTime.java | 11 +- .../edm/primitivetype/EdmDateTimeOffset.java | 23 ++-- .../core/edm/primitivetype/EdmDecimal.java | 23 ++-- .../core/edm/primitivetype/EdmDouble.java | 22 ++-- .../core/edm/primitivetype/EdmDuration.java | 19 ++- .../core/edm/primitivetype/EdmGeography.java | 8 +- .../primitivetype/EdmGeographyCollection.java | 6 +- .../primitivetype/EdmGeographyLineString.java | 6 +- .../EdmGeographyMultiLineString.java | 6 +- .../primitivetype/EdmGeographyMultiPoint.java | 6 +- .../EdmGeographyMultiPolygon.java | 6 +- .../edm/primitivetype/EdmGeographyPoint.java | 6 +- .../primitivetype/EdmGeographyPolygon.java | 6 +- .../core/edm/primitivetype/EdmGeometry.java | 8 +- .../primitivetype/EdmGeometryCollection.java | 6 +- .../primitivetype/EdmGeometryLineString.java | 6 +- .../EdmGeometryMultiLineString.java | 6 +- .../primitivetype/EdmGeometryMultiPoint.java | 7 +- .../EdmGeometryMultiPolygon.java | 6 +- .../edm/primitivetype/EdmGeometryPoint.java | 6 +- .../edm/primitivetype/EdmGeometryPolygon.java | 6 +- .../core/edm/primitivetype/EdmGuid.java | 9 +- .../core/edm/primitivetype/EdmInt16.java | 19 ++- .../core/edm/primitivetype/EdmInt32.java | 18 ++- .../core/edm/primitivetype/EdmInt64.java | 16 +-- .../core/edm/primitivetype/EdmSByte.java | 15 +-- .../core/edm/primitivetype/EdmSingle.java | 24 ++-- .../core/edm/primitivetype/EdmStream.java | 8 +- .../core/edm/primitivetype/EdmString.java | 9 +- .../core/edm/primitivetype/EdmTimeOfDay.java | 16 +-- .../primitivetype/PrimitiveTypeBaseTest.java | 44 ++++--- .../server/core/edm/provider/EdmEnumTest.java | 106 ++++++++++++---- .../edm/provider/PrimitiveTypeBaseTest.java | 117 ------------------ 41 files changed, 273 insertions(+), 450 deletions(-) delete mode 100644 lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/PrimitiveTypeBaseTest.java diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeException.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeException.java index fb59ec151..e6cc3191d 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeException.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeException.java @@ -18,7 +18,9 @@ */ package org.apache.olingo.commons.api.edm; -public class EdmPrimitiveTypeException extends Exception { +import org.apache.olingo.commons.api.ODataException; + +public class EdmPrimitiveTypeException extends ODataException { private static final long serialVersionUID = -93578822384514620L; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEnumType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEnumType.java index 4790deade..01726072c 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEnumType.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEnumType.java @@ -112,8 +112,7 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum } } if (memberValueLong == null) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } result = result == null ? memberValueLong : result | memberValueLong; } @@ -127,7 +126,7 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum if (value == null) { if (isNullable != null && !isNullable) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED"); + throw new EdmPrimitiveTypeException("The literal 'null' is not allowed."); } return null; } @@ -135,11 +134,10 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum try { return EdmInt64.convertNumber(parseEnumValue(value), returnType); } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + throw new EdmPrimitiveTypeException("The literal '" + value + + "' cannot be converted to value type " + returnType + ".", e); } catch (final ClassCastException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e); } } @@ -159,8 +157,7 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum } if (remaining != 0) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } return result.toString(); } @@ -171,15 +168,14 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum if (value == null) { if (isNullable != null && !isNullable) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED"); + throw new EdmPrimitiveTypeException("The value NULL is not allowed."); } return null; } if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) { return constructEnumValue(((Number) value).longValue()); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } @@ -199,7 +195,7 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum && literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) { return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length()); } else { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)"); + throw new EdmPrimitiveTypeException("The literal '" + literal + "' has illegal content."); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractGeospatialType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractGeospatialType.java index afdb4ebbd..96ab23653 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractGeospatialType.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractGeospatialType.java @@ -67,7 +67,7 @@ public abstract class AbstractGeospatialType extends Singl private Matcher getMatcher(final Pattern pattern, final String value) throws EdmPrimitiveTypeException { final Matcher matcher = pattern.matcher(value); if (!matcher.matches()) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } Geospatial.Dimension _dimension = null; @@ -76,10 +76,10 @@ public abstract class AbstractGeospatialType extends Singl _dimension = Geospatial.Dimension.valueOf(matcher.group(1).toUpperCase()); _type = Geospatial.Type.valueOf(matcher.group(3).toUpperCase()); } catch (IllegalArgumentException e) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e); } if (_dimension != this.dimension || (!pattern.equals(COLLECTION_PATTERN) && _type != this.type)) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } return matcher; @@ -91,7 +91,7 @@ public abstract class AbstractGeospatialType extends Singl final String[] pointCoo = StringUtils.split(point, ' '); if (pointCoo == null || pointCoo.length != 2) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + point + "' has illegal content."); } final Point result = new Point(this.dimension, srid); @@ -309,8 +309,7 @@ public abstract class AbstractGeospatialType extends Singl final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (dimension != point.getDimension()) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + point + "' is not valid."); } return toStringBuilder(point.getSrid()). @@ -325,8 +324,7 @@ public abstract class AbstractGeospatialType extends Singl final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (dimension != multiPoint.getDimension()) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + multiPoint + "' is not valid."); } final StringBuilder result = toStringBuilder(multiPoint.getSrid()). @@ -365,8 +363,7 @@ public abstract class AbstractGeospatialType extends Singl final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (dimension != lineString.getDimension()) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + lineString + "' is not valid."); } return toStringBuilder(lineString.getSrid()). @@ -380,8 +377,7 @@ public abstract class AbstractGeospatialType extends Singl final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (dimension != multiLineString.getDimension()) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + multiLineString + "' is not valid."); } final StringBuilder result = toStringBuilder(multiLineString.getSrid()). @@ -428,8 +424,7 @@ public abstract class AbstractGeospatialType extends Singl final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (dimension != polygon.getDimension()) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + polygon + "' is not valid."); } return toStringBuilder(polygon.getSrid()). @@ -443,8 +438,7 @@ public abstract class AbstractGeospatialType extends Singl final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (dimension != multiPolygon.getDimension()) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + multiPolygon + "' is not valid."); } final StringBuilder result = toStringBuilder(multiPolygon.getSrid()). @@ -467,12 +461,10 @@ public abstract class AbstractGeospatialType extends Singl final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (dimension != collection.getDimension()) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + collection + "' is not valid."); } - final StringBuilder result = toStringBuilder(collection.getSrid()). - append("Collection("); + StringBuilder result = toStringBuilder(collection.getSrid()).append("Collection("); if (collection.iterator().hasNext()) { final Geospatial item = collection.iterator().next(); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractPrimitiveType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractPrimitiveType.java index 79d7bb551..4928d1751 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractPrimitiveType.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractPrimitiveType.java @@ -62,7 +62,7 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType { if (value == null) { if (isNullable != null && !isNullable) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED"); + throw new EdmPrimitiveTypeException("The literal 'null' is not allowed."); } return null; } @@ -79,7 +79,7 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType { final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (value == null) { if (isNullable != null && !isNullable) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED"); + throw new EdmPrimitiveTypeException("The value NULL is not allowed."); } return null; } @@ -92,11 +92,8 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType { @Override public String toUriLiteral(final String literal) { - return literal == null - ? null - : uriPrefix.isEmpty() && uriSuffix.isEmpty() - ? literal - : uriPrefix + literal + uriSuffix; + return literal == null ? null : + uriPrefix.isEmpty() && uriSuffix.isEmpty() ? literal : uriPrefix + literal + uriSuffix; } @Override @@ -110,7 +107,7 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType { return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length()); } else { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)"); + throw new EdmPrimitiveTypeException("The literal '" + literal + "' has illegal content."); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java index 4c1be3297..8e1c95e1e 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java @@ -163,11 +163,10 @@ public class EdmBinary extends SingletonPrimitiveType { final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { if (value == null || !isBase64(value.getBytes(UTF_8))) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } if (!validateMaxLength(value, maxLength)) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints."); } final byte[] result = Base64.decodeBase64(value.getBytes(UTF_8)); @@ -181,7 +180,7 @@ public class EdmBinary extends SingletonPrimitiveType { } return returnType.cast(byteArray); } else { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported."); } } @@ -200,13 +199,11 @@ public class EdmBinary extends SingletonPrimitiveType { byteArrayValue[i] = ((Byte[]) value)[i].byteValue(); } } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } if (maxLength != null && byteArrayValue.length > maxLength) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints."); } return new String(Base64.encodeBase64(byteArrayValue, false), UTF_8); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBoolean.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBoolean.java index 776d5f185..b009a659d 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBoolean.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBoolean.java @@ -57,12 +57,10 @@ public final class EdmBoolean extends SingletonPrimitiveType { if (returnType.isAssignableFrom(Boolean.class)) { return returnType.cast(Boolean.valueOf("true".equals(value))); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported."); } } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } } @@ -74,8 +72,7 @@ public final class EdmBoolean extends SingletonPrimitiveType { if (value instanceof Boolean) { return Boolean.toString((Boolean) value); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmByte.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmByte.java index e13a8eff8..68d1e1bfe 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmByte.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmByte.java @@ -54,22 +54,19 @@ public final class EdmByte extends SingletonPrimitiveType { try { valueShort = Short.parseShort(value); } catch (final NumberFormatException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e); } if (valueShort < 0 || valueShort >= 1 << Byte.SIZE) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } try { return EdmInt64.convertNumber(valueShort, returnType); } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + throw new EdmPrimitiveTypeException("The literal '" + value + + "' cannot be converted to value type " + returnType + ".", e); } catch (final ClassCastException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e); } } @@ -82,20 +79,17 @@ public final class EdmByte extends SingletonPrimitiveType { if (((Number) value).longValue() >= 0 && ((Number) value).longValue() < 1 << Byte.SIZE) { return value.toString(); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } } else if (value instanceof BigInteger) { if (((BigInteger) value).compareTo(BigInteger.ZERO) >= 0 && ((BigInteger) value).compareTo(BigInteger.valueOf(1 << Byte.SIZE)) < 0) { return value.toString(); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDate.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDate.java index 437ed1846..71b747fb0 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDate.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDate.java @@ -53,7 +53,7 @@ public final class EdmDate extends SingletonPrimitiveType { final Matcher matcher = PATTERN.matcher(value); if (!matcher.matches()) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } dateTimeValue.set( @@ -64,11 +64,9 @@ public final class EdmDate extends SingletonPrimitiveType { try { return EdmDateTimeOffset.convertDateTime(dateTimeValue, 0, returnType); } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e); } catch (final ClassCastException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)", e); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTime.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTime.java index dd5d0ec60..68624844a 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTime.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTime.java @@ -61,7 +61,7 @@ public final class EdmDateTime extends SingletonPrimitiveType { try { date = DATE_FORMAT.get().parse(dateParts[0]); } catch (ParseException e) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e); } TimeZone timezone = null; @@ -85,8 +85,7 @@ public final class EdmDateTime extends SingletonPrimitiveType { if (decimals != null) { if (decimals.length() > (precision == null ? 0 : precision)) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints."); } final String milliSeconds = decimals.length() > 3 ? decimals.substring(0, 3) @@ -105,8 +104,8 @@ public final class EdmDateTime extends SingletonPrimitiveType { } else if (returnType.isAssignableFrom(Timestamp.class)) { return returnType.cast(timestamp); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType)"); + throw new EdmPrimitiveTypeException("The literal '" + value + + "' cannot be converted to value type " + returnType + "."); } } @@ -130,7 +129,7 @@ public final class EdmDateTime extends SingletonPrimitiveType { EdmDateTimeOffset.appendFractionalSeconds(result, fractionalSecs, precision); return result.toString(); } else { - throw new EdmPrimitiveTypeException("EdmDateTime only supports conversion from Calendar and Timestamp"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java index c3b4bcc24..6646c83bf 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java @@ -63,15 +63,14 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType { final Matcher matcher = PATTERN.matcher(value); if (!matcher.matches()) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } final String timeZoneOffset = matcher.group(9) == null || matcher.group(10) == null || matcher.group(10).matches("[-+]0+:0+") ? null : matcher.group(10); final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT" + timeZoneOffset)); if (dateTimeValue.get(Calendar.ZONE_OFFSET) == 0 && timeZoneOffset != null) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } dateTimeValue.clear(); @@ -86,13 +85,11 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType { int nanoSeconds = 0; if (matcher.group(7) != null) { if (matcher.group(7).length() == 1 || matcher.group(7).length() > 13) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } final String decimals = matcher.group(8); if (decimals.length() > (precision == null ? 0 : precision)) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints."); } if (returnType.isAssignableFrom(Timestamp.class)) { if (!decimals.isEmpty()) { @@ -110,11 +107,9 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType { try { return convertDateTime(dateTimeValue, nanoSeconds, returnType); } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e); } catch (final ClassCastException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)", e); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e); } } @@ -196,8 +191,7 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType { appendMilliseconds(result, fractionalSecs, precision); } } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)", e); + throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.", e); } final int offsetInMinutes = (dateTimeValue.get(Calendar.ZONE_OFFSET) @@ -231,8 +225,7 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType { dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT")); dateTimeValue.setTimeInMillis((Long) value); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(" + value.getClass().getName() + ")"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } return dateTimeValue; } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDecimal.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDecimal.java index f67caf93a..b9e390420 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDecimal.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDecimal.java @@ -89,21 +89,19 @@ public final class EdmDecimal extends SingletonPrimitiveType { final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { if (!validateLiteral(value)) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } if (!validatePrecisionAndScale(value, precision, scale)) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints."); } try { return convertDecimal(new BigDecimal(value), returnType); } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + throw new EdmPrimitiveTypeException("The literal '" + value + + "' cannot be converted to value type " + returnType + ".", e); } catch (final ClassCastException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e); } } @@ -168,8 +166,7 @@ public final class EdmDecimal extends SingletonPrimitiveType { result = value.toString(); final int digits = result.startsWith("-") ? result.length() - 1 : result.length(); if (precision != null && precision < digits) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints."); } } else if (value instanceof Double || value instanceof Float || value instanceof BigDecimal) { @@ -178,7 +175,7 @@ public final class EdmDecimal extends SingletonPrimitiveType { bigDecimalValue = value instanceof Double ? BigDecimal.valueOf((Double) value) : value instanceof Float ? BigDecimal.valueOf((Float) value) : (BigDecimal) value; } catch (final NumberFormatException e) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)", e); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.", e); } final int digits = bigDecimalValue.scale() >= 0 @@ -187,13 +184,11 @@ public final class EdmDecimal extends SingletonPrimitiveType { if ((precision == null || precision >= digits) && (bigDecimalValue.scale() <= (scale == null ? 0 : scale))) { result = bigDecimalValue.toPlainString(); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints."); } } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } return result; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDouble.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDouble.java index b085d956f..be9b5a917 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDouble.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDouble.java @@ -78,7 +78,7 @@ public final class EdmDouble extends SingletonPrimitiveType { } else { // Now only "normal" numbers remain. if (!PATTERN.matcher(value).matches()) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } // The number format is checked above, so we don't have to catch NumberFormatException. @@ -87,7 +87,7 @@ public final class EdmDouble extends SingletonPrimitiveType { // "Real" infinite values have been treated already above, so we can throw an exception // if the conversion to a double results in an infinite value. if (result.isInfinite() || BigDecimal.valueOf(result).compareTo(bigDecimalValue) != 0) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } } @@ -97,18 +97,17 @@ public final class EdmDouble extends SingletonPrimitiveType { if (returnType.isAssignableFrom(Float.class)) { return returnType.cast(result.floatValue()); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType)"); + throw new EdmPrimitiveTypeException("The literal '" + value + + "' cannot be converted to value type " + returnType + "."); } } else { try { return EdmDecimal.convertDecimal(bigDecimalValue, returnType); } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + throw new EdmPrimitiveTypeException("The literal '" + value + + "' cannot be converted to value type " + returnType + ".", e); } catch (final ClassCastException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e); } } } @@ -121,7 +120,7 @@ public final class EdmDouble extends SingletonPrimitiveType { if (Math.abs((Long) value) < 1L << 51) { return value.toString(); } else { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } } else if (value instanceof Integer || value instanceof Short || value instanceof Byte) { return value.toString(); @@ -136,11 +135,10 @@ public final class EdmDouble extends SingletonPrimitiveType { if (!Double.isInfinite(doubleValue) && BigDecimal.valueOf(doubleValue).compareTo((BigDecimal) value) == 0) { return ((BigDecimal) value).toString(); } else { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDuration.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDuration.java index f350b5619..b0de82020 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDuration.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDuration.java @@ -56,8 +56,7 @@ public class EdmDuration extends SingletonPrimitiveType { if (!matcher.matches() || matcher.group(1) == null && matcher.group(2) == null && matcher.group(3) == null && matcher.group(4) == null) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } BigDecimal result = (matcher.group(1) == null ? BigDecimal.ZERO @@ -71,18 +70,16 @@ public class EdmDuration extends SingletonPrimitiveType { if (result.scale() <= (precision == null ? 0 : precision)) { result = value.charAt(0) == '-' ? result.negate() : result; } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(literal, facets)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints."); } try { return EdmDecimal.convertDecimal(result, returnType); } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + throw new EdmPrimitiveTypeException("The literal '" + value + + "' cannot be converted to value type " + returnType + ".", e); } catch (final ClassCastException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e); } } @@ -99,13 +96,11 @@ public class EdmDuration extends SingletonPrimitiveType { } else if (value instanceof BigInteger) { valueDecimal = new BigDecimal((BigInteger) value); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } if (valueDecimal.scale() > (precision == null ? 0 : precision)) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints."); } final StringBuilder result = new StringBuilder(); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeography.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeography.java index 53d6d97cc..16db86dd8 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeography.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeography.java @@ -38,16 +38,12 @@ public final class EdmGeography extends AbstractGeospatialType { protected T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { - - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); + throw new EdmPrimitiveTypeException("Not implemented!"); } @Override protected String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { - - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("Not implemented!"); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeographyCollection.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeographyCollection.java index e32fb0ec6..4ee35a2ec 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeographyCollection.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeographyCollection.java @@ -45,8 +45,7 @@ public final class EdmGeographyCollection extends AbstractGeospatialType { if (returnType.isAssignableFrom(Point.class)) { return returnType.cast(point); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported."); } } @@ -57,8 +56,7 @@ public final class EdmGeographyPoint extends AbstractGeospatialType { return toString((Point) value, isNullable, maxLength, precision, scale, isUnicode); } - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeographyPolygon.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeographyPolygon.java index 994ac099a..a9ccbfa94 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeographyPolygon.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeographyPolygon.java @@ -44,8 +44,7 @@ public final class EdmGeographyPolygon extends AbstractGeospatialType { if (returnType.isAssignableFrom(Polygon.class)) { return returnType.cast(polygon); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported."); } } @@ -57,7 +56,6 @@ public final class EdmGeographyPolygon extends AbstractGeospatialType { return toString((Polygon) value, isNullable, maxLength, precision, scale, isUnicode); } - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeometry.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeometry.java index 64160dd0f..12e3994ba 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeometry.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeometry.java @@ -38,16 +38,12 @@ public final class EdmGeometry extends AbstractGeospatialType { protected T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { - - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); + throw new EdmPrimitiveTypeException("Not implemented!"); } @Override protected String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { - - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("Not implemented!"); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeometryCollection.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeometryCollection.java index 510d24aa1..a03fb5f6c 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeometryCollection.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeometryCollection.java @@ -45,8 +45,7 @@ public final class EdmGeometryCollection extends AbstractGeospatialType { if (returnType.isAssignableFrom(Point.class)) { return returnType.cast(point); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported."); } } @@ -57,7 +56,6 @@ public final class EdmGeometryPoint extends AbstractGeospatialType { return toString((Point) value, isNullable, maxLength, precision, scale, isUnicode); } - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeometryPolygon.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeometryPolygon.java index 68ff5152a..12924fc1c 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeometryPolygon.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGeometryPolygon.java @@ -44,8 +44,7 @@ public final class EdmGeometryPolygon extends AbstractGeospatialType { if (returnType.isAssignableFrom(Polygon.class)) { return returnType.cast(polygon); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported."); } } @@ -57,7 +56,6 @@ public final class EdmGeometryPolygon extends AbstractGeospatialType { return toString((Polygon) value, isNullable, maxLength, precision, scale, isUnicode); } - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGuid.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGuid.java index c62ea3153..e188b5d28 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGuid.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmGuid.java @@ -61,15 +61,13 @@ public final class EdmGuid extends SingletonPrimitiveType { if (validateLiteral(value)) { result = UUID.fromString(value); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } if (returnType.isAssignableFrom(UUID.class)) { return returnType.cast(result); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported."); } } @@ -81,8 +79,7 @@ public final class EdmGuid extends SingletonPrimitiveType { if (value instanceof UUID) { return ((UUID) value).toString(); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmInt16.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmInt16.java index a34d1e1bc..eecbe735e 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmInt16.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmInt16.java @@ -55,18 +55,16 @@ public final class EdmInt16 extends SingletonPrimitiveType { try { valueShort = Short.parseShort(value); } catch (final NumberFormatException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e); } try { return EdmInt64.convertNumber(valueShort, returnType); } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + throw new EdmPrimitiveTypeException("The literal '" + value + + "' cannot be converted to value type " + returnType + ".", e); } catch (final ClassCastException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e); } } @@ -81,19 +79,16 @@ public final class EdmInt16 extends SingletonPrimitiveType { && ((Number) value).longValue() <= Short.MAX_VALUE) { return value.toString(); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } } else if (value instanceof BigInteger) { if (((BigInteger) value).bitLength() < Short.SIZE) { return value.toString(); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmInt32.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmInt32.java index eeadac9f2..6fef25920 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmInt32.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmInt32.java @@ -57,17 +57,16 @@ public final class EdmInt32 extends SingletonPrimitiveType { try { valueInteger = Integer.parseInt(value); } catch (final NumberFormatException e) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e); } try { return EdmInt64.convertNumber(valueInteger, returnType); } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + throw new EdmPrimitiveTypeException("The literal '" + value + + "' cannot be converted to value type " + returnType + ".", e); } catch (final ClassCastException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e); } } @@ -82,19 +81,16 @@ public final class EdmInt32 extends SingletonPrimitiveType { if ((Long) value >= Integer.MIN_VALUE && (Long) value <= Integer.MAX_VALUE) { return value.toString(); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } } else if (value instanceof BigInteger) { if (((BigInteger) value).bitLength() < Integer.SIZE) { return value.toString(); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmInt64.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmInt64.java index c2e9d9a8f..20d20e67d 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmInt64.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmInt64.java @@ -58,18 +58,16 @@ public final class EdmInt64 extends SingletonPrimitiveType { try { valueLong = Long.parseLong(value); } catch (final NumberFormatException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e); } try { return convertNumber(valueLong, returnType); } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + throw new EdmPrimitiveTypeException("The literal '" + value + + "' cannot be converted to value type " + returnType + ".", e); } catch (final ClassCastException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e); } } @@ -124,12 +122,10 @@ public final class EdmInt64 extends SingletonPrimitiveType { if (((BigInteger) value).bitLength() < Long.SIZE) { return value.toString(); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmSByte.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmSByte.java index 0aacc013c..42514d53f 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmSByte.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmSByte.java @@ -54,15 +54,13 @@ public final class EdmSByte extends SingletonPrimitiveType { try { valueByte = Byte.parseByte(value); } catch (final NumberFormatException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e); } try { return EdmInt64.convertNumber(valueByte, returnType); } catch (final ClassCastException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e); } } @@ -77,19 +75,16 @@ public final class EdmSByte extends SingletonPrimitiveType { if (((Number) value).longValue() >= Byte.MIN_VALUE && ((Number) value).longValue() <= Byte.MAX_VALUE) { return value.toString(); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } } else if (value instanceof BigInteger) { if (((BigInteger) value).bitLength() < Byte.SIZE) { return value.toString(); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmSingle.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmSingle.java index 984bb720d..398768c56 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmSingle.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmSingle.java @@ -71,7 +71,7 @@ public final class EdmSingle extends SingletonPrimitiveType { } else { // Now only "normal" numbers remain. if (!PATTERN.matcher(value).matches()) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } // The number format is checked above, so we don't have to catch NumberFormatException. @@ -80,7 +80,7 @@ public final class EdmSingle extends SingletonPrimitiveType { // "Real" infinite values have been treated already above, so we can throw an exception // if the conversion to a float results in an infinite value. if (result.isInfinite() || bigDecimalValue.compareTo(new BigDecimal(result.toString())) != 0) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } } @@ -90,18 +90,17 @@ public final class EdmSingle extends SingletonPrimitiveType { if (returnType.isAssignableFrom(Double.class)) { return returnType.cast(result.doubleValue()); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType)"); + throw new EdmPrimitiveTypeException("The literal '" + value + + "' cannot be converted to value type " + returnType + "."); } } else { try { return EdmDecimal.convertDecimal(bigDecimalValue, returnType); } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + throw new EdmPrimitiveTypeException("The literal '" + value + + "' cannot be converted to value type " + returnType + ".", e); } catch (final ClassCastException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e); } } } @@ -115,7 +114,7 @@ public final class EdmSingle extends SingletonPrimitiveType { if (Math.abs(((Number) value).longValue()) < 1L << 22) { return value.toString(); } else { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } } else if (value instanceof Short || value instanceof Byte) { return value.toString(); @@ -127,7 +126,7 @@ public final class EdmSingle extends SingletonPrimitiveType { if (floatString.equals(((Double) value).toString())) { return floatString; } else { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } } } else if (value instanceof Float) { @@ -138,11 +137,10 @@ public final class EdmSingle extends SingletonPrimitiveType { if (!Float.isInfinite(floatValue) && BigDecimal.valueOf(floatValue).compareTo((BigDecimal) value) == 0) { return ((BigDecimal) value).toString(); } else { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid."); } } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmStream.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmStream.java index fa25e954a..91611d042 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmStream.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmStream.java @@ -64,14 +64,13 @@ public final class EdmStream extends SingletonPrimitiveType { try { stream = new URI(value); } catch (final URISyntaxException e) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e); } if (returnType.isAssignableFrom(URI.class)) { return returnType.cast(stream); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported."); } } @@ -83,8 +82,7 @@ public final class EdmStream extends SingletonPrimitiveType { if (value instanceof URI) { return ((URI) value).toASCIIString(); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported."); } } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmString.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmString.java index 14a1772bb..cb130636e 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmString.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmString.java @@ -52,15 +52,13 @@ public final class EdmString extends SingletonPrimitiveType { if (isUnicode != null && !isUnicode && !PATTERN_ASCII.matcher(value).matches() || maxLength != null && maxLength < value.length()) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints."); } if (returnType.isAssignableFrom(String.class)) { return returnType.cast(value); } else { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported."); } } @@ -73,8 +71,7 @@ public final class EdmString extends SingletonPrimitiveType { if (isUnicode != null && !isUnicode && !PATTERN_ASCII.matcher(result).matches() || maxLength != null && maxLength < result.length()) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); + throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints."); } return result; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDay.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDay.java index 21b7c2f51..fb10e02cb 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDay.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDay.java @@ -49,7 +49,7 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType { final Matcher matcher = PATTERN.matcher(value); if (!matcher.matches()) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT")); @@ -61,12 +61,11 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType { int nanoSeconds = 0; if (matcher.group(4) != null) { if (matcher.group(4).length() == 1 || matcher.group(4).length() > 13) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content."); } final String decimals = matcher.group(5); if (decimals.length() > (precision == null ? 0 : precision)) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); + throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints."); } final String milliSeconds = decimals.length() > 3 ? decimals.substring(0, 3) : @@ -82,11 +81,9 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType { try { return EdmDateTimeOffset.convertDateTime(dateTimeValue, nanoSeconds, returnType); } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e); } catch (final ClassCastException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)", e); + throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e); } } @@ -121,8 +118,7 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType { EdmDateTimeOffset.appendMilliseconds(result, fractionalSecs, precision); } } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)", e); + throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.", e); } return result.toString(); diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java index 9761dc991..e4a75a64b 100644 --- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java +++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java @@ -18,93 +18,91 @@ */ package org.apache.olingo.commons.core.edm.primitivetype; +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - public abstract class PrimitiveTypeBaseTest { private void expectErrorInValueToString(final EdmPrimitiveType instance, final Object value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, - final String messageReferenceString) { + final String message) { try { instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode); fail("Expected exception not thrown"); } catch (final EdmPrimitiveTypeException e) { assertNotNull(e.getLocalizedMessage()); - assertTrue(e.getLocalizedMessage().startsWith(messageReferenceString)); + assertThat(e.getLocalizedMessage(), containsString(message)); } } - private void expectErrorInValueToString(final EdmPrimitiveType instance, final Object value, - final String messageReference) { - expectErrorInValueToString(instance, value, null, null, null, null, null, messageReference); + private void expectErrorInValueToString(final EdmPrimitiveType instance, final Object value, final String message) { + expectErrorInValueToString(instance, value, null, null, null, null, null, message); } protected void expectTypeErrorInValueToString(final EdmPrimitiveType instance, final Object value) { - expectErrorInValueToString(instance, value, "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED"); + expectErrorInValueToString(instance, value, "value type"); } protected void expectContentErrorInValueToString(final EdmPrimitiveType instance, final Object value) { - expectErrorInValueToString(instance, value, "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT"); + expectErrorInValueToString(instance, value, "' is not valid."); } protected void expectFacetsErrorInValueToString(final EdmPrimitiveType instance, final Object value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) { expectErrorInValueToString(instance, value, isNullable, maxLength, precision, scale, isUnicode, - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED"); + "facets' constraints"); } protected void expectNullErrorInValueToString(final EdmPrimitiveType instance) { - expectErrorInValueToString(instance, null, false, null, null, null, null, - "EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED"); + expectErrorInValueToString(instance, null, false, null, null, null, null, "The value NULL is not allowed."); } private void expectErrorInValueOfString(final EdmPrimitiveType instance, final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final Class returnType, - final String messageReferenceString) { + final String message) { try { instance.valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType); fail("Expected exception not thrown"); } catch (final EdmPrimitiveTypeException e) { assertNotNull(e.getLocalizedMessage()); - assertTrue(e.getLocalizedMessage().startsWith(messageReferenceString)); + assertThat(e.getLocalizedMessage(), containsString(message)); } } protected void expectTypeErrorInValueOfString(final EdmPrimitiveType instance, final String value) { expectErrorInValueOfString(instance, value, null, null, null, null, null, Class.class, - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED"); + "The value type class java.lang.Class is not supported."); } protected void expectUnconvertibleErrorInValueOfString(final EdmPrimitiveType instance, final String value, final Class type) { - expectErrorInValueOfString(instance, value, null, null, null, null, null, type, - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE"); + expectErrorInValueOfString(instance, value, null, null, null, null, null, type, "cannot be converted to"); } protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) { expectErrorInValueOfString(instance, value, null, null, null, null, null, instance.getDefaultType(), - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT"); + "illegal content"); } protected void expectFacetsErrorInValueOfString(final EdmPrimitiveType instance, final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) { expectErrorInValueOfString(instance, value, isNullable, maxLength, precision, scale, isUnicode, - instance.getDefaultType(), "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED"); + instance.getDefaultType(), "facets' constraints"); } protected void expectNullErrorInValueOfString(final EdmPrimitiveType instance) { expectErrorInValueOfString(instance, null, false, null, null, null, null, instance.getDefaultType(), - "EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED"); + "The literal 'null' is not allowed."); } protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value) { @@ -113,7 +111,7 @@ public abstract class PrimitiveTypeBaseTest { fail("Expected exception not thrown"); } catch (final EdmPrimitiveTypeException e) { assertNotNull(e.getLocalizedMessage()); - assertTrue(e.getLocalizedMessage().startsWith("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT")); + assertThat(e.getLocalizedMessage(), containsString("' has illegal content.")); } } } diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java index e95b24542..091a55bfc 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java @@ -19,6 +19,8 @@ package org.apache.olingo.server.core.edm.provider; import org.apache.olingo.commons.api.edm.EdmEnumType; +import org.apache.olingo.commons.api.edm.EdmPrimitiveType; +import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.constants.EdmTypeKind; @@ -27,47 +29,39 @@ import org.apache.olingo.server.api.edm.provider.EnumMember; import org.apache.olingo.server.api.edm.provider.EnumType; import org.junit.Test; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; -public class EdmEnumTest extends PrimitiveTypeBaseTest { +public class EdmEnumTest { private final EdmEnumType instance; private final EdmEnumType nonFlagsInstance; public EdmEnumTest() { - List memberList = new ArrayList(); - memberList.add(new EnumMember().setName("first").setValue("1")); - memberList.add(new EnumMember().setName("second").setValue("64")); + final List memberList = Arrays.asList( + new EnumMember().setName("first").setValue("1"), + new EnumMember().setName("second").setValue("64")); - EnumType enumType = - new EnumType().setName("name").setMembers(memberList).setFlags(true).setUnderlyingType( - EdmPrimitiveTypeKind.SByte.getFullQualifiedName()); + final FullQualifiedName enumName = new FullQualifiedName("namespace", "name"); - FullQualifiedName enumName = new FullQualifiedName("namespace", "name"); - instance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName, enumType); + instance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName, + new EnumType().setName("name").setMembers(memberList).setFlags(true) + .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName())); - EnumType enumType2 = new EnumType().setName("name").setMembers(memberList).setFlags(false).setUnderlyingType( - EdmPrimitiveTypeKind.SByte.getFullQualifiedName()); - nonFlagsInstance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName, enumType2); - -// EdmMember member1 = mock(EdmMember.class); -// when(member1.getName()).thenReturn("first"); -// when(member1.getValue()).thenReturn("1"); -// EdmMember member2 = mock(EdmMember.class); -// when(member2.getName()).thenReturn("second"); -// when(member2.getValue()).thenReturn("64"); -// instance = new EdmEnumImpl("namespace", "name", -// EdmPrimitiveTypeKind.SByte), -// Arrays.asList(member1, member2), -// true); + nonFlagsInstance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName, + new EnumType().setName("name").setMembers(memberList).setFlags(false) + .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName())); } @Test @@ -175,4 +169,68 @@ public class EdmEnumTest extends PrimitiveTypeBaseTest { expectContentErrorInValueOfString(instance, ",1"); expectTypeErrorInValueOfString(instance, "1"); } + + protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value) { + try { + instance.fromUriLiteral(value); + fail("Expected exception not thrown"); + } catch (final EdmPrimitiveTypeException e) { + assertNotNull(e.getLocalizedMessage()); + assertThat(e.getLocalizedMessage(), containsString("' has illegal content.")); + } + } + + private void expectErrorInValueToString(final EdmPrimitiveType instance, + final Object value, final Boolean isNullable, final Integer maxLength, + final Integer precision, final Integer scale, final Boolean isUnicode, + final String message) { + try { + instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode); + fail("Expected exception not thrown"); + } catch (final EdmPrimitiveTypeException e) { + assertNotNull(e.getLocalizedMessage()); + assertThat(e.getLocalizedMessage(), containsString(message)); + } + } + + protected void expectNullErrorInValueToString(final EdmPrimitiveType instance) { + expectErrorInValueToString(instance, null, false, null, null, null, null, "The value NULL is not allowed."); + } + + protected void expectTypeErrorInValueToString(final EdmPrimitiveType instance, final Object value) { + expectErrorInValueToString(instance, value, null, null, null, null, null, "value type"); + } + + protected void expectContentErrorInValueToString(final EdmPrimitiveType instance, final Object value) { + expectErrorInValueToString(instance, value, null, null, null, null, null, "' is not valid."); + } + + private void expectErrorInValueOfString(final EdmPrimitiveType instance, + final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType, + final String message) { + + try { + instance.valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType); + fail("Expected exception not thrown"); + } catch (final EdmPrimitiveTypeException e) { + assertNotNull(e.getLocalizedMessage()); + assertThat(e.getLocalizedMessage(), containsString(message)); + } + } + + protected void expectTypeErrorInValueOfString(final EdmPrimitiveType instance, final String value) { + expectErrorInValueOfString(instance, value, null, null, null, null, null, Class.class, + "The value type class java.lang.Class is not supported."); + } + + protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) { + expectErrorInValueOfString(instance, value, null, null, null, null, null, instance.getDefaultType(), + "illegal content"); + } + + protected void expectNullErrorInValueOfString(final EdmPrimitiveType instance) { + expectErrorInValueOfString(instance, null, false, null, null, null, null, instance.getDefaultType(), + "The literal 'null' is not allowed."); + } } diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/PrimitiveTypeBaseTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/PrimitiveTypeBaseTest.java deleted file mode 100644 index 3c58455f4..000000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/PrimitiveTypeBaseTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * 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.server.core.edm.provider; - -import org.apache.olingo.commons.api.edm.EdmPrimitiveType; -import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -public abstract class PrimitiveTypeBaseTest { - - private void expectErrorInValueToString(final EdmPrimitiveType instance, - final Object value, final Boolean isNullable, final Integer maxLength, - final Integer precision, final Integer scale, final Boolean isUnicode, - final String messageReferenceString) { - try { - instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode); - fail("Expected exception not thrown"); - } catch (final EdmPrimitiveTypeException e) { - assertNotNull(e.getLocalizedMessage()); - assertTrue(e.getLocalizedMessage().startsWith(messageReferenceString)); - } - } - - private void expectErrorInValueToString(final EdmPrimitiveType instance, final Object value, - final String messageReference) { - expectErrorInValueToString(instance, value, null, null, null, null, null, messageReference); - } - - protected void expectTypeErrorInValueToString(final EdmPrimitiveType instance, final Object value) { - expectErrorInValueToString(instance, value, "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED"); - } - - protected void expectContentErrorInValueToString(final EdmPrimitiveType instance, final Object value) { - expectErrorInValueToString(instance, value, "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT"); - } - - protected void expectFacetsErrorInValueToString(final EdmPrimitiveType instance, final Object value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) { - expectErrorInValueToString(instance, value, isNullable, maxLength, precision, scale, isUnicode, - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED"); - } - - protected void expectNullErrorInValueToString(final EdmPrimitiveType instance) { - expectErrorInValueToString(instance, null, false, null, null, null, null, - "EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED"); - } - - private void expectErrorInValueOfString(final EdmPrimitiveType instance, - final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType, final String messageReferenceString) { - try { - instance.valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType); - fail("Expected exception not thrown"); - } catch (final EdmPrimitiveTypeException e) { - assertNotNull(e.getLocalizedMessage()); - assertTrue(e.getLocalizedMessage().startsWith(messageReferenceString)); - } - } - - protected void expectTypeErrorInValueOfString(final EdmPrimitiveType instance, final String value) { - expectErrorInValueOfString(instance, value, null, null, null, null, null, Class.class, - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED"); - } - - protected void expectUnconvertibleErrorInValueOfString(final EdmPrimitiveType instance, final String value, - final Class type) { - expectErrorInValueOfString(instance, value, null, null, null, null, null, type, - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE"); - } - - protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) { - expectErrorInValueOfString(instance, value, null, null, null, null, null, instance.getDefaultType(), - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT"); - } - - protected void expectFacetsErrorInValueOfString(final EdmPrimitiveType instance, final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) { - expectErrorInValueOfString(instance, value, isNullable, maxLength, precision, scale, isUnicode, - instance.getDefaultType(), "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED"); - } - - protected void expectNullErrorInValueOfString(final EdmPrimitiveType instance) { - expectErrorInValueOfString(instance, null, false, null, null, null, null, instance.getDefaultType(), - "EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED"); - } - - protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value) { - try { - instance.fromUriLiteral(value); - fail("Expected exception not thrown"); - } catch (final EdmPrimitiveTypeException e) { - assertNotNull(e.getLocalizedMessage()); - assertTrue(e.getLocalizedMessage().startsWith("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT")); - } - } -}