[OLINGO-356] Rework EdmPrimitive Type exceptions

This commit is contained in:
Michael Bolz 2014-09-03 11:04:36 +02:00
parent f3289fb103
commit 3ece19c964
41 changed files with 273 additions and 450 deletions

View File

@ -18,7 +18,9 @@
*/ */
package org.apache.olingo.commons.api.edm; 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; private static final long serialVersionUID = -93578822384514620L;

View File

@ -112,8 +112,7 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum
} }
} }
if (memberValueLong == null) { if (memberValueLong == null) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
} }
result = result == null ? memberValueLong : result | memberValueLong; result = result == null ? memberValueLong : result | memberValueLong;
} }
@ -127,7 +126,7 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum
if (value == null) { if (value == null) {
if (isNullable != null && !isNullable) { if (isNullable != null && !isNullable) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED"); throw new EdmPrimitiveTypeException("The literal 'null' is not allowed.");
} }
return null; return null;
} }
@ -135,11 +134,10 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum
try { try {
return EdmInt64.convertNumber(parseEnumValue(value), returnType); return EdmInt64.convertNumber(parseEnumValue(value), returnType);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) { } catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
} }
} }
@ -159,8 +157,7 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum
} }
if (remaining != 0) { if (remaining != 0) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
return result.toString(); return result.toString();
} }
@ -171,15 +168,14 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum
if (value == null) { if (value == null) {
if (isNullable != null && !isNullable) { if (isNullable != null && !isNullable) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED"); throw new EdmPrimitiveTypeException("The value NULL is not allowed.");
} }
return null; return null;
} }
if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) { if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
return constructEnumValue(((Number) value).longValue()); return constructEnumValue(((Number) value).longValue());
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }
@ -199,7 +195,7 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum
&& literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) { && literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) {
return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length()); return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length());
} else { } else {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)"); throw new EdmPrimitiveTypeException("The literal '" + literal + "' has illegal content.");
} }
} }

View File

@ -67,7 +67,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
private Matcher getMatcher(final Pattern pattern, final String value) throws EdmPrimitiveTypeException { private Matcher getMatcher(final Pattern pattern, final String value) throws EdmPrimitiveTypeException {
final Matcher matcher = pattern.matcher(value); final Matcher matcher = pattern.matcher(value);
if (!matcher.matches()) { 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; Geospatial.Dimension _dimension = null;
@ -76,10 +76,10 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
_dimension = Geospatial.Dimension.valueOf(matcher.group(1).toUpperCase()); _dimension = Geospatial.Dimension.valueOf(matcher.group(1).toUpperCase());
_type = Geospatial.Type.valueOf(matcher.group(3).toUpperCase()); _type = Geospatial.Type.valueOf(matcher.group(3).toUpperCase());
} catch (IllegalArgumentException e) { } 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)) { 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; return matcher;
@ -91,7 +91,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final String[] pointCoo = StringUtils.split(point, ' '); final String[] pointCoo = StringUtils.split(point, ' ');
if (pointCoo == null || pointCoo.length != 2) { 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); final Point result = new Point(this.dimension, srid);
@ -309,8 +309,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (dimension != point.getDimension()) { if (dimension != point.getDimension()) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + point + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
return toStringBuilder(point.getSrid()). return toStringBuilder(point.getSrid()).
@ -325,8 +324,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (dimension != multiPoint.getDimension()) { if (dimension != multiPoint.getDimension()) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + multiPoint + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
final StringBuilder result = toStringBuilder(multiPoint.getSrid()). final StringBuilder result = toStringBuilder(multiPoint.getSrid()).
@ -365,8 +363,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (dimension != lineString.getDimension()) { if (dimension != lineString.getDimension()) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + lineString + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
return toStringBuilder(lineString.getSrid()). return toStringBuilder(lineString.getSrid()).
@ -380,8 +377,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (dimension != multiLineString.getDimension()) { if (dimension != multiLineString.getDimension()) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + multiLineString + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
final StringBuilder result = toStringBuilder(multiLineString.getSrid()). final StringBuilder result = toStringBuilder(multiLineString.getSrid()).
@ -428,8 +424,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (dimension != polygon.getDimension()) { if (dimension != polygon.getDimension()) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + polygon + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
return toStringBuilder(polygon.getSrid()). return toStringBuilder(polygon.getSrid()).
@ -443,8 +438,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (dimension != multiPolygon.getDimension()) { if (dimension != multiPolygon.getDimension()) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + multiPolygon + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
final StringBuilder result = toStringBuilder(multiPolygon.getSrid()). final StringBuilder result = toStringBuilder(multiPolygon.getSrid()).
@ -467,12 +461,10 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (dimension != collection.getDimension()) { if (dimension != collection.getDimension()) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + collection + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
final StringBuilder result = toStringBuilder(collection.getSrid()). StringBuilder result = toStringBuilder(collection.getSrid()).append("Collection(");
append("Collection(");
if (collection.iterator().hasNext()) { if (collection.iterator().hasNext()) {
final Geospatial item = collection.iterator().next(); final Geospatial item = collection.iterator().next();

View File

@ -62,7 +62,7 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType {
if (value == null) { if (value == null) {
if (isNullable != null && !isNullable) { if (isNullable != null && !isNullable) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED"); throw new EdmPrimitiveTypeException("The literal 'null' is not allowed.");
} }
return null; return null;
} }
@ -79,7 +79,7 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType {
final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (value == null) { if (value == null) {
if (isNullable != null && !isNullable) { if (isNullable != null && !isNullable) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED"); throw new EdmPrimitiveTypeException("The value NULL is not allowed.");
} }
return null; return null;
} }
@ -92,11 +92,8 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType {
@Override @Override
public String toUriLiteral(final String literal) { public String toUriLiteral(final String literal) {
return literal == null return literal == null ? null :
? null uriPrefix.isEmpty() && uriSuffix.isEmpty() ? literal : uriPrefix + literal + uriSuffix;
: uriPrefix.isEmpty() && uriSuffix.isEmpty()
? literal
: uriPrefix + literal + uriSuffix;
} }
@Override @Override
@ -110,7 +107,7 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType {
return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length()); return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length());
} else { } else {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)"); throw new EdmPrimitiveTypeException("The literal '" + literal + "' has illegal content.");
} }
} }

View File

@ -163,11 +163,10 @@ public class EdmBinary extends SingletonPrimitiveType {
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException { final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
if (value == null || !isBase64(value.getBytes(UTF_8))) { 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)) { if (!validateMaxLength(value, maxLength)) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
} }
final byte[] result = Base64.decodeBase64(value.getBytes(UTF_8)); final byte[] result = Base64.decodeBase64(value.getBytes(UTF_8));
@ -181,7 +180,7 @@ public class EdmBinary extends SingletonPrimitiveType {
} }
return returnType.cast(byteArray); return returnType.cast(byteArray);
} else { } 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(); byteArrayValue[i] = ((Byte[]) value)[i].byteValue();
} }
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
if (maxLength != null && byteArrayValue.length > maxLength) { if (maxLength != null && byteArrayValue.length > maxLength) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.");
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)");
} }
return new String(Base64.encodeBase64(byteArrayValue, false), UTF_8); return new String(Base64.encodeBase64(byteArrayValue, false), UTF_8);

View File

@ -57,12 +57,10 @@ public final class EdmBoolean extends SingletonPrimitiveType {
if (returnType.isAssignableFrom(Boolean.class)) { if (returnType.isAssignableFrom(Boolean.class)) {
return returnType.cast(Boolean.valueOf("true".equals(value))); return returnType.cast(Boolean.valueOf("true".equals(value)));
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
} }
} }
@ -74,8 +72,7 @@ public final class EdmBoolean extends SingletonPrimitiveType {
if (value instanceof Boolean) { if (value instanceof Boolean) {
return Boolean.toString((Boolean) value); return Boolean.toString((Boolean) value);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }
} }

View File

@ -54,22 +54,19 @@ public final class EdmByte extends SingletonPrimitiveType {
try { try {
valueShort = Short.parseShort(value); valueShort = Short.parseShort(value);
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
} }
if (valueShort < 0 || valueShort >= 1 << Byte.SIZE) { if (valueShort < 0 || valueShort >= 1 << Byte.SIZE) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
} }
try { try {
return EdmInt64.convertNumber(valueShort, returnType); return EdmInt64.convertNumber(valueShort, returnType);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) { } catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
} }
} }
@ -82,20 +79,17 @@ public final class EdmByte extends SingletonPrimitiveType {
if (((Number) value).longValue() >= 0 && ((Number) value).longValue() < 1 << Byte.SIZE) { if (((Number) value).longValue() >= 0 && ((Number) value).longValue() < 1 << Byte.SIZE) {
return value.toString(); return value.toString();
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
} else if (value instanceof BigInteger) { } else if (value instanceof BigInteger) {
if (((BigInteger) value).compareTo(BigInteger.ZERO) >= 0 if (((BigInteger) value).compareTo(BigInteger.ZERO) >= 0
&& ((BigInteger) value).compareTo(BigInteger.valueOf(1 << Byte.SIZE)) < 0) { && ((BigInteger) value).compareTo(BigInteger.valueOf(1 << Byte.SIZE)) < 0) {
return value.toString(); return value.toString();
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }
} }

View File

@ -53,7 +53,7 @@ public final class EdmDate extends SingletonPrimitiveType {
final Matcher matcher = PATTERN.matcher(value); final Matcher matcher = PATTERN.matcher(value);
if (!matcher.matches()) { if (!matcher.matches()) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
} }
dateTimeValue.set( dateTimeValue.set(
@ -64,11 +64,9 @@ public final class EdmDate extends SingletonPrimitiveType {
try { try {
return EdmDateTimeOffset.convertDateTime(dateTimeValue, 0, returnType); return EdmDateTimeOffset.convertDateTime(dateTimeValue, 0, returnType);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
} catch (final ClassCastException e) { } catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)", e);
} }
} }

View File

@ -61,7 +61,7 @@ public final class EdmDateTime extends SingletonPrimitiveType {
try { try {
date = DATE_FORMAT.get().parse(dateParts[0]); date = DATE_FORMAT.get().parse(dateParts[0]);
} catch (ParseException e) { } 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; TimeZone timezone = null;
@ -85,8 +85,7 @@ public final class EdmDateTime extends SingletonPrimitiveType {
if (decimals != null) { if (decimals != null) {
if (decimals.length() > (precision == null ? 0 : precision)) { if (decimals.length() > (precision == null ? 0 : precision)) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
} }
final String milliSeconds = decimals.length() > 3 final String milliSeconds = decimals.length() > 3
? decimals.substring(0, 3) ? decimals.substring(0, 3)
@ -105,8 +104,8 @@ public final class EdmDateTime extends SingletonPrimitiveType {
} else if (returnType.isAssignableFrom(Timestamp.class)) { } else if (returnType.isAssignableFrom(Timestamp.class)) {
return returnType.cast(timestamp); return returnType.cast(timestamp);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType)"); + "' cannot be converted to value type " + returnType + ".");
} }
} }
@ -130,7 +129,7 @@ public final class EdmDateTime extends SingletonPrimitiveType {
EdmDateTimeOffset.appendFractionalSeconds(result, fractionalSecs, precision); EdmDateTimeOffset.appendFractionalSeconds(result, fractionalSecs, precision);
return result.toString(); return result.toString();
} else { } else {
throw new EdmPrimitiveTypeException("EdmDateTime only supports conversion from Calendar and Timestamp"); throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
} }
} }
} }

View File

@ -63,15 +63,14 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
final Matcher matcher = PATTERN.matcher(value); final Matcher matcher = PATTERN.matcher(value);
if (!matcher.matches()) { 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 final String timeZoneOffset = matcher.group(9) == null || matcher.group(10) == null
|| matcher.group(10).matches("[-+]0+:0+") ? null : matcher.group(10); || matcher.group(10).matches("[-+]0+:0+") ? null : matcher.group(10);
final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT" + timeZoneOffset)); final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT" + timeZoneOffset));
if (dateTimeValue.get(Calendar.ZONE_OFFSET) == 0 && timeZoneOffset != null) { if (dateTimeValue.get(Calendar.ZONE_OFFSET) == 0 && timeZoneOffset != null) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
} }
dateTimeValue.clear(); dateTimeValue.clear();
@ -86,13 +85,11 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
int nanoSeconds = 0; int nanoSeconds = 0;
if (matcher.group(7) != null) { if (matcher.group(7) != null) {
if (matcher.group(7).length() == 1 || matcher.group(7).length() > 13) { if (matcher.group(7).length() == 1 || matcher.group(7).length() > 13) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
} }
final String decimals = matcher.group(8); final String decimals = matcher.group(8);
if (decimals.length() > (precision == null ? 0 : precision)) { if (decimals.length() > (precision == null ? 0 : precision)) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
} }
if (returnType.isAssignableFrom(Timestamp.class)) { if (returnType.isAssignableFrom(Timestamp.class)) {
if (!decimals.isEmpty()) { if (!decimals.isEmpty()) {
@ -110,11 +107,9 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
try { try {
return convertDateTime(dateTimeValue, nanoSeconds, returnType); return convertDateTime(dateTimeValue, nanoSeconds, returnType);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
} catch (final ClassCastException e) { } catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)", e);
} }
} }
@ -196,8 +191,7 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
appendMilliseconds(result, fractionalSecs, precision); appendMilliseconds(result, fractionalSecs, precision);
} }
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.", e);
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)", e);
} }
final int offsetInMinutes = (dateTimeValue.get(Calendar.ZONE_OFFSET) 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 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
dateTimeValue.setTimeInMillis((Long) value); dateTimeValue.setTimeInMillis((Long) value);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(" + value.getClass().getName() + ")");
} }
return dateTimeValue; return dateTimeValue;
} }

View File

@ -89,21 +89,19 @@ public final class EdmDecimal extends SingletonPrimitiveType {
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException { final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
if (!validateLiteral(value)) { 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)) { if (!validatePrecisionAndScale(value, precision, scale)) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
} }
try { try {
return convertDecimal(new BigDecimal(value), returnType); return convertDecimal(new BigDecimal(value), returnType);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) { } catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
} }
} }
@ -168,8 +166,7 @@ public final class EdmDecimal extends SingletonPrimitiveType {
result = value.toString(); result = value.toString();
final int digits = result.startsWith("-") ? result.length() - 1 : result.length(); final int digits = result.startsWith("-") ? result.length() - 1 : result.length();
if (precision != null && precision < digits) { if (precision != null && precision < digits) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.");
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)");
} }
} else if (value instanceof Double || value instanceof Float || value instanceof BigDecimal) { } 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) bigDecimalValue = value instanceof Double ? BigDecimal.valueOf((Double) value)
: value instanceof Float ? BigDecimal.valueOf((Float) value) : (BigDecimal) value; : value instanceof Float ? BigDecimal.valueOf((Float) value) : (BigDecimal) value;
} catch (final NumberFormatException e) { } 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 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))) { if ((precision == null || precision >= digits) && (bigDecimalValue.scale() <= (scale == null ? 0 : scale))) {
result = bigDecimalValue.toPlainString(); result = bigDecimalValue.toPlainString();
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.");
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)");
} }
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
return result; return result;

View File

@ -78,7 +78,7 @@ public final class EdmDouble extends SingletonPrimitiveType {
} else { } else {
// Now only "normal" numbers remain. // Now only "normal" numbers remain.
if (!PATTERN.matcher(value).matches()) { 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. // 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 // "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 the conversion to a double results in an infinite value.
if (result.isInfinite() || BigDecimal.valueOf(result).compareTo(bigDecimalValue) != 0) { 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)) { if (returnType.isAssignableFrom(Float.class)) {
return returnType.cast(result.floatValue()); return returnType.cast(result.floatValue());
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType)"); + "' cannot be converted to value type " + returnType + ".");
} }
} else { } else {
try { try {
return EdmDecimal.convertDecimal(bigDecimalValue, returnType); return EdmDecimal.convertDecimal(bigDecimalValue, returnType);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) { } catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
} }
} }
} }
@ -121,7 +120,7 @@ public final class EdmDouble extends SingletonPrimitiveType {
if (Math.abs((Long) value) < 1L << 51) { if (Math.abs((Long) value) < 1L << 51) {
return value.toString(); return value.toString();
} else { } 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) { } else if (value instanceof Integer || value instanceof Short || value instanceof Byte) {
return value.toString(); return value.toString();
@ -136,11 +135,10 @@ public final class EdmDouble extends SingletonPrimitiveType {
if (!Double.isInfinite(doubleValue) && BigDecimal.valueOf(doubleValue).compareTo((BigDecimal) value) == 0) { if (!Double.isInfinite(doubleValue) && BigDecimal.valueOf(doubleValue).compareTo((BigDecimal) value) == 0) {
return ((BigDecimal) value).toString(); return ((BigDecimal) value).toString();
} else { } else {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
} }
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }
} }

View File

@ -56,8 +56,7 @@ public class EdmDuration extends SingletonPrimitiveType {
if (!matcher.matches() if (!matcher.matches()
|| matcher.group(1) == null && matcher.group(2) == null && matcher.group(3) == null || matcher.group(1) == null && matcher.group(2) == null && matcher.group(3) == null
&& matcher.group(4) == null) { && matcher.group(4) == null) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)");
} }
BigDecimal result = (matcher.group(1) == null ? BigDecimal.ZERO BigDecimal result = (matcher.group(1) == null ? BigDecimal.ZERO
@ -71,18 +70,16 @@ public class EdmDuration extends SingletonPrimitiveType {
if (result.scale() <= (precision == null ? 0 : precision)) { if (result.scale() <= (precision == null ? 0 : precision)) {
result = value.charAt(0) == '-' ? result.negate() : result; result = value.charAt(0) == '-' ? result.negate() : result;
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(literal, facets)");
} }
try { try {
return EdmDecimal.convertDecimal(result, returnType); return EdmDecimal.convertDecimal(result, returnType);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) { } catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
} }
} }
@ -99,13 +96,11 @@ public class EdmDuration extends SingletonPrimitiveType {
} else if (value instanceof BigInteger) { } else if (value instanceof BigInteger) {
valueDecimal = new BigDecimal((BigInteger) value); valueDecimal = new BigDecimal((BigInteger) value);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
if (valueDecimal.scale() > (precision == null ? 0 : precision)) { if (valueDecimal.scale() > (precision == null ? 0 : precision)) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.");
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)");
} }
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();

View File

@ -38,16 +38,12 @@ public final class EdmGeography extends AbstractGeospatialType<Geospatial> {
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength, protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType) final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType)
throws EdmPrimitiveTypeException { throws EdmPrimitiveTypeException {
throw new EdmPrimitiveTypeException("Not implemented!");
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
@Override @Override
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength, protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
throw new EdmPrimitiveTypeException("Not implemented!");
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -45,8 +45,7 @@ public final class EdmGeographyCollection extends AbstractGeospatialType<Geospat
if (returnType.isAssignableFrom(GeospatialCollection.class)) { if (returnType.isAssignableFrom(GeospatialCollection.class)) {
return returnType.cast(collection); return returnType.cast(collection);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -58,7 +57,6 @@ public final class EdmGeographyCollection extends AbstractGeospatialType<Geospat
return toString((GeospatialCollection) value, isNullable, maxLength, precision, scale, isUnicode); return toString((GeospatialCollection) value, isNullable, maxLength, precision, scale, isUnicode);
} }
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -44,8 +44,7 @@ public final class EdmGeographyLineString extends AbstractGeospatialType<LineStr
if (returnType.isAssignableFrom(LineString.class)) { if (returnType.isAssignableFrom(LineString.class)) {
return returnType.cast(lineString); return returnType.cast(lineString);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -57,7 +56,6 @@ public final class EdmGeographyLineString extends AbstractGeospatialType<LineStr
return toString((LineString) value, isNullable, maxLength, precision, scale, isUnicode); return toString((LineString) value, isNullable, maxLength, precision, scale, isUnicode);
} }
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -45,8 +45,7 @@ public final class EdmGeographyMultiLineString extends AbstractGeospatialType<Mu
if (returnType.isAssignableFrom(MultiLineString.class)) { if (returnType.isAssignableFrom(MultiLineString.class)) {
return returnType.cast(multiLineString); return returnType.cast(multiLineString);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -58,7 +57,6 @@ public final class EdmGeographyMultiLineString extends AbstractGeospatialType<Mu
return toString((MultiLineString) value, isNullable, maxLength, precision, scale, isUnicode); return toString((MultiLineString) value, isNullable, maxLength, precision, scale, isUnicode);
} }
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -44,8 +44,7 @@ public final class EdmGeographyMultiPoint extends AbstractGeospatialType<MultiPo
if (returnType.isAssignableFrom(MultiPoint.class)) { if (returnType.isAssignableFrom(MultiPoint.class)) {
return returnType.cast(point); return returnType.cast(point);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -58,8 +57,7 @@ public final class EdmGeographyMultiPoint extends AbstractGeospatialType<MultiPo
return toString((MultiPoint) value, isNullable, maxLength, precision, scale, isUnicode); return toString((MultiPoint) value, isNullable, maxLength, precision, scale, isUnicode);
} }
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -44,8 +44,7 @@ public final class EdmGeographyMultiPolygon extends AbstractGeospatialType<Multi
if (returnType.isAssignableFrom(MultiPolygon.class)) { if (returnType.isAssignableFrom(MultiPolygon.class)) {
return returnType.cast(multiPolygon); return returnType.cast(multiPolygon);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -57,7 +56,6 @@ public final class EdmGeographyMultiPolygon extends AbstractGeospatialType<Multi
return toString((MultiPolygon) value, isNullable, maxLength, precision, scale, isUnicode); return toString((MultiPolygon) value, isNullable, maxLength, precision, scale, isUnicode);
} }
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -44,8 +44,7 @@ public final class EdmGeographyPoint extends AbstractGeospatialType<Point> {
if (returnType.isAssignableFrom(Point.class)) { if (returnType.isAssignableFrom(Point.class)) {
return returnType.cast(point); return returnType.cast(point);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -57,8 +56,7 @@ public final class EdmGeographyPoint extends AbstractGeospatialType<Point> {
return toString((Point) value, isNullable, maxLength, precision, scale, isUnicode); return toString((Point) value, isNullable, maxLength, precision, scale, isUnicode);
} }
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -44,8 +44,7 @@ public final class EdmGeographyPolygon extends AbstractGeospatialType<Polygon> {
if (returnType.isAssignableFrom(Polygon.class)) { if (returnType.isAssignableFrom(Polygon.class)) {
return returnType.cast(polygon); return returnType.cast(polygon);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -57,7 +56,6 @@ public final class EdmGeographyPolygon extends AbstractGeospatialType<Polygon> {
return toString((Polygon) value, isNullable, maxLength, precision, scale, isUnicode); return toString((Polygon) value, isNullable, maxLength, precision, scale, isUnicode);
} }
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -38,16 +38,12 @@ public final class EdmGeometry extends AbstractGeospatialType<Geospatial> {
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength, protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType) final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType)
throws EdmPrimitiveTypeException { throws EdmPrimitiveTypeException {
throw new EdmPrimitiveTypeException("Not implemented!");
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
@Override @Override
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength, protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
throw new EdmPrimitiveTypeException("Not implemented!");
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -45,8 +45,7 @@ public final class EdmGeometryCollection extends AbstractGeospatialType<Geospati
if (returnType.isAssignableFrom(GeospatialCollection.class)) { if (returnType.isAssignableFrom(GeospatialCollection.class)) {
return returnType.cast(collection); return returnType.cast(collection);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -58,7 +57,6 @@ public final class EdmGeometryCollection extends AbstractGeospatialType<Geospati
return toString((GeospatialCollection) value, isNullable, maxLength, precision, scale, isUnicode); return toString((GeospatialCollection) value, isNullable, maxLength, precision, scale, isUnicode);
} }
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -44,8 +44,7 @@ public final class EdmGeometryLineString extends AbstractGeospatialType<LineStri
if (returnType.isAssignableFrom(LineString.class)) { if (returnType.isAssignableFrom(LineString.class)) {
return returnType.cast(lineString); return returnType.cast(lineString);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -57,7 +56,6 @@ public final class EdmGeometryLineString extends AbstractGeospatialType<LineStri
return toString((LineString) value, isNullable, maxLength, precision, scale, isUnicode); return toString((LineString) value, isNullable, maxLength, precision, scale, isUnicode);
} }
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -45,8 +45,7 @@ public final class EdmGeometryMultiLineString extends AbstractGeospatialType<Mul
if (returnType.isAssignableFrom(MultiLineString.class)) { if (returnType.isAssignableFrom(MultiLineString.class)) {
return returnType.cast(multiLineString); return returnType.cast(multiLineString);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -58,7 +57,6 @@ public final class EdmGeometryMultiLineString extends AbstractGeospatialType<Mul
return toString((MultiLineString) value, isNullable, maxLength, precision, scale, isUnicode); return toString((MultiLineString) value, isNullable, maxLength, precision, scale, isUnicode);
} }
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -44,10 +44,8 @@ public final class EdmGeometryMultiPoint extends AbstractGeospatialType<MultiPoi
if (returnType.isAssignableFrom(MultiPoint.class)) { if (returnType.isAssignableFrom(MultiPoint.class)) {
return returnType.cast(point); return returnType.cast(point);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@Override @Override
@ -58,7 +56,6 @@ public final class EdmGeometryMultiPoint extends AbstractGeospatialType<MultiPoi
return toString((MultiPoint) value, isNullable, maxLength, precision, scale, isUnicode); return toString((MultiPoint) value, isNullable, maxLength, precision, scale, isUnicode);
} }
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -45,8 +45,7 @@ public final class EdmGeometryMultiPolygon extends AbstractGeospatialType<MultiP
if (returnType.isAssignableFrom(MultiPolygon.class)) { if (returnType.isAssignableFrom(MultiPolygon.class)) {
return returnType.cast(multiPolygon); return returnType.cast(multiPolygon);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -58,7 +57,6 @@ public final class EdmGeometryMultiPolygon extends AbstractGeospatialType<MultiP
return toString((MultiPolygon) value, isNullable, maxLength, precision, scale, isUnicode); return toString((MultiPolygon) value, isNullable, maxLength, precision, scale, isUnicode);
} }
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -44,8 +44,7 @@ public final class EdmGeometryPoint extends AbstractGeospatialType<Point> {
if (returnType.isAssignableFrom(Point.class)) { if (returnType.isAssignableFrom(Point.class)) {
return returnType.cast(point); return returnType.cast(point);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -57,7 +56,6 @@ public final class EdmGeometryPoint extends AbstractGeospatialType<Point> {
return toString((Point) value, isNullable, maxLength, precision, scale, isUnicode); return toString((Point) value, isNullable, maxLength, precision, scale, isUnicode);
} }
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -44,8 +44,7 @@ public final class EdmGeometryPolygon extends AbstractGeospatialType<Polygon> {
if (returnType.isAssignableFrom(Polygon.class)) { if (returnType.isAssignableFrom(Polygon.class)) {
return returnType.cast(polygon); return returnType.cast(polygon);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -57,7 +56,6 @@ public final class EdmGeometryPolygon extends AbstractGeospatialType<Polygon> {
return toString((Polygon) value, isNullable, maxLength, precision, scale, isUnicode); return toString((Polygon) value, isNullable, maxLength, precision, scale, isUnicode);
} }
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }

View File

@ -61,15 +61,13 @@ public final class EdmGuid extends SingletonPrimitiveType {
if (validateLiteral(value)) { if (validateLiteral(value)) {
result = UUID.fromString(value); result = UUID.fromString(value);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
} }
if (returnType.isAssignableFrom(UUID.class)) { if (returnType.isAssignableFrom(UUID.class)) {
return returnType.cast(result); return returnType.cast(result);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -81,8 +79,7 @@ public final class EdmGuid extends SingletonPrimitiveType {
if (value instanceof UUID) { if (value instanceof UUID) {
return ((UUID) value).toString(); return ((UUID) value).toString();
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }
} }

View File

@ -55,18 +55,16 @@ public final class EdmInt16 extends SingletonPrimitiveType {
try { try {
valueShort = Short.parseShort(value); valueShort = Short.parseShort(value);
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
} }
try { try {
return EdmInt64.convertNumber(valueShort, returnType); return EdmInt64.convertNumber(valueShort, returnType);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) { } catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
} }
} }
@ -81,19 +79,16 @@ public final class EdmInt16 extends SingletonPrimitiveType {
&& ((Number) value).longValue() <= Short.MAX_VALUE) { && ((Number) value).longValue() <= Short.MAX_VALUE) {
return value.toString(); return value.toString();
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
} else if (value instanceof BigInteger) { } else if (value instanceof BigInteger) {
if (((BigInteger) value).bitLength() < Short.SIZE) { if (((BigInteger) value).bitLength() < Short.SIZE) {
return value.toString(); return value.toString();
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }
} }

View File

@ -57,17 +57,16 @@ public final class EdmInt32 extends SingletonPrimitiveType {
try { try {
valueInteger = Integer.parseInt(value); valueInteger = Integer.parseInt(value);
} catch (final NumberFormatException e) { } 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 { try {
return EdmInt64.convertNumber(valueInteger, returnType); return EdmInt64.convertNumber(valueInteger, returnType);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) { } catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
} }
} }
@ -82,19 +81,16 @@ public final class EdmInt32 extends SingletonPrimitiveType {
if ((Long) value >= Integer.MIN_VALUE && (Long) value <= Integer.MAX_VALUE) { if ((Long) value >= Integer.MIN_VALUE && (Long) value <= Integer.MAX_VALUE) {
return value.toString(); return value.toString();
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
} else if (value instanceof BigInteger) { } else if (value instanceof BigInteger) {
if (((BigInteger) value).bitLength() < Integer.SIZE) { if (((BigInteger) value).bitLength() < Integer.SIZE) {
return value.toString(); return value.toString();
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }
} }

View File

@ -58,18 +58,16 @@ public final class EdmInt64 extends SingletonPrimitiveType {
try { try {
valueLong = Long.parseLong(value); valueLong = Long.parseLong(value);
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
} }
try { try {
return convertNumber(valueLong, returnType); return convertNumber(valueLong, returnType);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) { } catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
} }
} }
@ -124,12 +122,10 @@ public final class EdmInt64 extends SingletonPrimitiveType {
if (((BigInteger) value).bitLength() < Long.SIZE) { if (((BigInteger) value).bitLength() < Long.SIZE) {
return value.toString(); return value.toString();
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }
} }

View File

@ -54,15 +54,13 @@ public final class EdmSByte extends SingletonPrimitiveType {
try { try {
valueByte = Byte.parseByte(value); valueByte = Byte.parseByte(value);
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
} }
try { try {
return EdmInt64.convertNumber(valueByte, returnType); return EdmInt64.convertNumber(valueByte, returnType);
} catch (final ClassCastException e) { } catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
} }
} }
@ -77,19 +75,16 @@ public final class EdmSByte extends SingletonPrimitiveType {
if (((Number) value).longValue() >= Byte.MIN_VALUE && ((Number) value).longValue() <= Byte.MAX_VALUE) { if (((Number) value).longValue() >= Byte.MIN_VALUE && ((Number) value).longValue() <= Byte.MAX_VALUE) {
return value.toString(); return value.toString();
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
} else if (value instanceof BigInteger) { } else if (value instanceof BigInteger) {
if (((BigInteger) value).bitLength() < Byte.SIZE) { if (((BigInteger) value).bitLength() < Byte.SIZE) {
return value.toString(); return value.toString();
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
} }
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }
} }

View File

@ -71,7 +71,7 @@ public final class EdmSingle extends SingletonPrimitiveType {
} else { } else {
// Now only "normal" numbers remain. // Now only "normal" numbers remain.
if (!PATTERN.matcher(value).matches()) { 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. // 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 // "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 the conversion to a float results in an infinite value.
if (result.isInfinite() || bigDecimalValue.compareTo(new BigDecimal(result.toString())) != 0) { 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)) { if (returnType.isAssignableFrom(Double.class)) {
return returnType.cast(result.doubleValue()); return returnType.cast(result.doubleValue());
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType)"); + "' cannot be converted to value type " + returnType + ".");
} }
} else { } else {
try { try {
return EdmDecimal.convertDecimal(bigDecimalValue, returnType); return EdmDecimal.convertDecimal(bigDecimalValue, returnType);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) { } catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
} }
} }
} }
@ -115,7 +114,7 @@ public final class EdmSingle extends SingletonPrimitiveType {
if (Math.abs(((Number) value).longValue()) < 1L << 22) { if (Math.abs(((Number) value).longValue()) < 1L << 22) {
return value.toString(); return value.toString();
} else { } 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) { } else if (value instanceof Short || value instanceof Byte) {
return value.toString(); return value.toString();
@ -127,7 +126,7 @@ public final class EdmSingle extends SingletonPrimitiveType {
if (floatString.equals(((Double) value).toString())) { if (floatString.equals(((Double) value).toString())) {
return floatString; return floatString;
} else { } else {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
} }
} }
} else if (value instanceof Float) { } 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) { if (!Float.isInfinite(floatValue) && BigDecimal.valueOf(floatValue).compareTo((BigDecimal) value) == 0) {
return ((BigDecimal) value).toString(); return ((BigDecimal) value).toString();
} else { } else {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
} }
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }
} }

View File

@ -64,14 +64,13 @@ public final class EdmStream extends SingletonPrimitiveType {
try { try {
stream = new URI(value); stream = new URI(value);
} catch (final URISyntaxException e) { } 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)) { if (returnType.isAssignableFrom(URI.class)) {
return returnType.cast(stream); return returnType.cast(stream);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -83,8 +82,7 @@ public final class EdmStream extends SingletonPrimitiveType {
if (value instanceof URI) { if (value instanceof URI) {
return ((URI) value).toASCIIString(); return ((URI) value).toASCIIString();
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
} }
} }
} }

View File

@ -52,15 +52,13 @@ public final class EdmString extends SingletonPrimitiveType {
if (isUnicode != null && !isUnicode && !PATTERN_ASCII.matcher(value).matches() if (isUnicode != null && !isUnicode && !PATTERN_ASCII.matcher(value).matches()
|| maxLength != null && maxLength < value.length()) { || maxLength != null && maxLength < value.length()) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
} }
if (returnType.isAssignableFrom(String.class)) { if (returnType.isAssignableFrom(String.class)) {
return returnType.cast(value); return returnType.cast(value);
} else { } else {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
} }
} }
@ -73,8 +71,7 @@ public final class EdmString extends SingletonPrimitiveType {
if (isUnicode != null && !isUnicode && !PATTERN_ASCII.matcher(result).matches() if (isUnicode != null && !isUnicode && !PATTERN_ASCII.matcher(result).matches()
|| maxLength != null && maxLength < result.length()) { || maxLength != null && maxLength < result.length()) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.");
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)");
} }
return result; return result;

View File

@ -49,7 +49,7 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType {
final Matcher matcher = PATTERN.matcher(value); final Matcher matcher = PATTERN.matcher(value);
if (!matcher.matches()) { 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")); final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
@ -61,12 +61,11 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType {
int nanoSeconds = 0; int nanoSeconds = 0;
if (matcher.group(4) != null) { if (matcher.group(4) != null) {
if (matcher.group(4).length() == 1 || matcher.group(4).length() > 13) { 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); final String decimals = matcher.group(5);
if (decimals.length() > (precision == null ? 0 : precision)) { if (decimals.length() > (precision == null ? 0 : precision)) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
} }
final String milliSeconds = decimals.length() > 3 ? final String milliSeconds = decimals.length() > 3 ?
decimals.substring(0, 3) : decimals.substring(0, 3) :
@ -82,11 +81,9 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType {
try { try {
return EdmDateTimeOffset.convertDateTime(dateTimeValue, nanoSeconds, returnType); return EdmDateTimeOffset.convertDateTime(dateTimeValue, nanoSeconds, returnType);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
} catch (final ClassCastException e) { } catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)", e);
} }
} }
@ -121,8 +118,7 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType {
EdmDateTimeOffset.appendMilliseconds(result, fractionalSecs, precision); EdmDateTimeOffset.appendMilliseconds(result, fractionalSecs, precision);
} }
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException( throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.", e);
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)", e);
} }
return result.toString(); return result.toString();

View File

@ -18,93 +18,91 @@
*/ */
package org.apache.olingo.commons.core.edm.primitivetype; 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.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; 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 { public abstract class PrimitiveTypeBaseTest {
private void expectErrorInValueToString(final EdmPrimitiveType instance, private void expectErrorInValueToString(final EdmPrimitiveType instance,
final Object value, final Boolean isNullable, final Integer maxLength, final Object value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode, final Integer precision, final Integer scale, final Boolean isUnicode,
final String messageReferenceString) { final String message) {
try { try {
instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode); instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
fail("Expected exception not thrown"); fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) { } catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage()); assertNotNull(e.getLocalizedMessage());
assertTrue(e.getLocalizedMessage().startsWith(messageReferenceString)); assertThat(e.getLocalizedMessage(), containsString(message));
} }
} }
private void expectErrorInValueToString(final EdmPrimitiveType instance, final Object value, private void expectErrorInValueToString(final EdmPrimitiveType instance, final Object value, final String message) {
final String messageReference) { expectErrorInValueToString(instance, value, null, null, null, null, null, message);
expectErrorInValueToString(instance, value, null, null, null, null, null, messageReference);
} }
protected void expectTypeErrorInValueToString(final EdmPrimitiveType instance, final Object value) { 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) { 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, protected void expectFacetsErrorInValueToString(final EdmPrimitiveType instance, final Object value,
final Boolean isNullable, final Integer maxLength, final Integer precision, final Boolean isNullable, final Integer maxLength, final Integer precision,
final Integer scale, final Boolean isUnicode) { final Integer scale, final Boolean isUnicode) {
expectErrorInValueToString(instance, value, isNullable, maxLength, precision, scale, isUnicode, expectErrorInValueToString(instance, value, isNullable, maxLength, precision, scale, isUnicode,
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED"); "facets' constraints");
} }
protected void expectNullErrorInValueToString(final EdmPrimitiveType instance) { protected void expectNullErrorInValueToString(final EdmPrimitiveType instance) {
expectErrorInValueToString(instance, null, false, null, null, null, null, expectErrorInValueToString(instance, null, false, null, null, null, null, "The value NULL is not allowed.");
"EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED");
} }
private void expectErrorInValueOfString(final EdmPrimitiveType instance, private void expectErrorInValueOfString(final EdmPrimitiveType instance,
final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, final String value, final Boolean isNullable, final Integer maxLength, final Integer precision,
final Integer scale, final Boolean isUnicode, final Class<?> returnType, final Integer scale, final Boolean isUnicode, final Class<?> returnType,
final String messageReferenceString) { final String message) {
try { try {
instance.valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType); instance.valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
fail("Expected exception not thrown"); fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) { } catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage()); assertNotNull(e.getLocalizedMessage());
assertTrue(e.getLocalizedMessage().startsWith(messageReferenceString)); assertThat(e.getLocalizedMessage(), containsString(message));
} }
} }
protected void expectTypeErrorInValueOfString(final EdmPrimitiveType instance, final String value) { protected void expectTypeErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
expectErrorInValueOfString(instance, value, null, null, null, null, null, Class.class, 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, protected void expectUnconvertibleErrorInValueOfString(final EdmPrimitiveType instance, final String value,
final Class<?> type) { final Class<?> type) {
expectErrorInValueOfString(instance, value, null, null, null, null, null, type, expectErrorInValueOfString(instance, value, null, null, null, null, null, type, "cannot be converted to");
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE");
} }
protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) { protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
expectErrorInValueOfString(instance, value, null, null, null, null, null, instance.getDefaultType(), 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, protected void expectFacetsErrorInValueOfString(final EdmPrimitiveType instance, final String value,
final Boolean isNullable, final Integer maxLength, final Integer precision, final Boolean isNullable, final Integer maxLength, final Integer precision,
final Integer scale, final Boolean isUnicode) { final Integer scale, final Boolean isUnicode) {
expectErrorInValueOfString(instance, value, isNullable, maxLength, precision, scale, 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) { protected void expectNullErrorInValueOfString(final EdmPrimitiveType instance) {
expectErrorInValueOfString(instance, null, false, null, null, null, null, instance.getDefaultType(), 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) { protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value) {
@ -113,7 +111,7 @@ public abstract class PrimitiveTypeBaseTest {
fail("Expected exception not thrown"); fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) { } catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage()); assertNotNull(e.getLocalizedMessage());
assertTrue(e.getLocalizedMessage().startsWith("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT")); assertThat(e.getLocalizedMessage(), containsString("' has illegal content."));
} }
} }
} }

View File

@ -19,6 +19,8 @@
package org.apache.olingo.server.core.edm.provider; package org.apache.olingo.server.core.edm.provider;
import org.apache.olingo.commons.api.edm.EdmEnumType; 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.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind; 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.apache.olingo.server.api.edm.provider.EnumType;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
public class EdmEnumTest extends PrimitiveTypeBaseTest { public class EdmEnumTest {
private final EdmEnumType instance; private final EdmEnumType instance;
private final EdmEnumType nonFlagsInstance; private final EdmEnumType nonFlagsInstance;
public EdmEnumTest() { public EdmEnumTest() {
List<EnumMember> memberList = new ArrayList<EnumMember>(); final List<EnumMember> memberList = Arrays.asList(
memberList.add(new EnumMember().setName("first").setValue("1")); new EnumMember().setName("first").setValue("1"),
memberList.add(new EnumMember().setName("second").setValue("64")); new EnumMember().setName("second").setValue("64"));
EnumType enumType = final FullQualifiedName enumName = new FullQualifiedName("namespace", "name");
new EnumType().setName("name").setMembers(memberList).setFlags(true).setUnderlyingType(
EdmPrimitiveTypeKind.SByte.getFullQualifiedName());
FullQualifiedName enumName = new FullQualifiedName("namespace", "name"); instance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName,
instance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName, enumType); new EnumType().setName("name").setMembers(memberList).setFlags(true)
.setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
EnumType enumType2 = new EnumType().setName("name").setMembers(memberList).setFlags(false).setUnderlyingType( nonFlagsInstance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName,
EdmPrimitiveTypeKind.SByte.getFullQualifiedName()); new EnumType().setName("name").setMembers(memberList).setFlags(false)
nonFlagsInstance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName, enumType2); .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
// 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);
} }
@Test @Test
@ -175,4 +169,68 @@ public class EdmEnumTest extends PrimitiveTypeBaseTest {
expectContentErrorInValueOfString(instance, ",1"); expectContentErrorInValueOfString(instance, ",1");
expectTypeErrorInValueOfString(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.");
}
} }

View File

@ -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"));
}
}
}