You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2013/08/28 16:02:13 UTC
[25/41] delete aggregated-sources directory which was created by
accident
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmBinary.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmBinary.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmBinary.java
deleted file mode 100644
index 77455f5..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmBinary.java
+++ /dev/null
@@ -1,148 +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.odata2.core.edm;
-
-import org.apache.commons.codec.DecoderException;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.codec.binary.Hex;
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-
-/**
- * Implementation of the EDM simple type Binary.
- *
- */
-public class EdmBinary extends AbstractSimpleType {
-
- private static final EdmBinary instance = new EdmBinary();
-
- public static EdmBinary getInstance() {
- return instance;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return byte[].class;
- }
-
- @Override
- public boolean validate(final String value, final EdmLiteralKind literalKind, final EdmFacets facets) {
- if (value == null) {
- return facets == null || facets.isNullable() == null || facets.isNullable();
- }
-
- if (literalKind == null) {
- return false;
- }
-
- return validateLiteral(value, literalKind) && validateMaxLength(value, literalKind, facets);
- }
-
- private static boolean validateLiteral(final String value, final EdmLiteralKind literalKind) {
- return literalKind == EdmLiteralKind.URI ?
- value.matches("(?:X|binary)'(?:\\p{XDigit}{2})*'") : Base64.isBase64(value);
- }
-
- private static boolean validateMaxLength(final String value, final EdmLiteralKind literalKind, final EdmFacets facets) {
- return facets == null || facets.getMaxLength() == null ? true :
- literalKind == EdmLiteralKind.URI ?
- // In URI representation, each byte is represented as two hexadecimal digits;
- // additionally, we have to account for the prefix and the surrounding "'"s.
- facets.getMaxLength() >= (value.length() - (value.startsWith("X") ? 3 : 8)) / 2
- :
- // In default representation, every three bytes are represented as four base-64 characters.
- // Additionally, there could be up to two padding "=" characters if the number of bytes is
- // not a multiple of three, and there could be carriage return/line feed combinations.
- facets.getMaxLength() >= value.length() * 3 / 4 - (value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0) - crlfLength(value);
- }
-
- private static int crlfLength(final String value) {
- int result = 0;
- int index = 0;
- while (index >= 0) {
- index = value.indexOf("\r\n", index);
- if (index > 0) {
- result++;
- index++;
- }
- }
- return result * 2;
- }
-
- @Override
- protected <T> T internalValueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- if (!validateLiteral(value, literalKind)) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
- if (!validateMaxLength(value, literalKind, facets)) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets));
- }
-
- byte[] result;
- if (literalKind == EdmLiteralKind.URI) {
- try {
- result = Hex.decodeHex(value.substring(value.startsWith("X") ? 2 : 7, value.length() - 1).toCharArray());
- } catch (final DecoderException e) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e);
- }
- } else {
- result = Base64.decodeBase64(value);
- }
-
- if (returnType.isAssignableFrom(byte[].class)) {
- return returnType.cast(result);
- } else if (returnType.isAssignableFrom(Byte[].class)) {
- Byte[] byteArray = new Byte[result.length];
- for (int i = 0; i < result.length; i++) {
- byteArray[i] = result[i];
- }
- return returnType.cast(byteArray);
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
- }
- }
-
- @Override
- protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- byte[] byteArrayValue;
- if (value instanceof byte[]) {
- byteArrayValue = (byte[]) value;
- } else if (value instanceof Byte[]) {
- final int length = ((Byte[]) value).length;
- byteArrayValue = new byte[length];
- for (int i = 0; i < length; i++) {
- byteArrayValue[i] = ((Byte[]) value)[i].byteValue();
- }
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
- }
-
- if (facets != null && facets.getMaxLength() != null && byteArrayValue.length > facets.getMaxLength()) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets));
- }
-
- return Base64.encodeBase64String(byteArrayValue);
- }
-
- @Override
- public String toUriLiteral(final String literal) throws EdmSimpleTypeException {
- return "binary'" + String.valueOf(Hex.encodeHex(Base64.decodeBase64(literal), false)) + "'";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmBoolean.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmBoolean.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmBoolean.java
deleted file mode 100644
index a325101..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmBoolean.java
+++ /dev/null
@@ -1,81 +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.odata2.core.edm;
-
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-
-/**
- * Implementation of the EDM simple type Boolean.
- *
- */
-public class EdmBoolean extends AbstractSimpleType {
-
- private static final EdmBoolean instance = new EdmBoolean();
-
- public static EdmBoolean getInstance() {
- return instance;
- }
-
- @Override
- public boolean isCompatible(final EdmSimpleType simpleType) {
- return simpleType instanceof Bit || simpleType instanceof EdmBoolean;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Boolean.class;
- }
-
- @Override
- public boolean validate(final String value, final EdmLiteralKind literalKind, final EdmFacets facets) {
- return value == null ?
- facets == null || facets.isNullable() == null || facets.isNullable() :
- validateLiteral(value);
- }
-
- private static boolean validateLiteral(final String value) {
- return "true".equals(value) || "1".equals(value)
- || "false".equals(value) || "0".equals(value);
- }
-
- @Override
- protected <T> T internalValueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- if (validateLiteral(value)) {
- if (returnType.isAssignableFrom(Boolean.class)) {
- return returnType.cast(Boolean.valueOf("true".equals(value) || "1".equals(value)));
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
- }
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
- }
-
- @Override
- protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- if (value instanceof Boolean) {
- return Boolean.toString((Boolean) value);
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmByte.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmByte.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmByte.java
deleted file mode 100644
index 909eef2..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmByte.java
+++ /dev/null
@@ -1,91 +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.odata2.core.edm;
-
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-
-/**
- * Implementation of the EDM simple type Byte.
- *
- */
-public class EdmByte extends AbstractSimpleType {
-
- private static final EdmByte instance = new EdmByte();
-
- public static EdmByte getInstance() {
- return instance;
- }
-
- @Override
- public boolean isCompatible(final EdmSimpleType simpleType) {
- return simpleType instanceof Bit
- || simpleType instanceof Uint7
- || simpleType instanceof EdmByte;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Short.class;
- }
-
- @Override
- protected <T> T internalValueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- Short valueShort;
- try {
- valueShort = Short.parseShort(value);
- } catch (final NumberFormatException e) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e);
- }
- if (valueShort < 0 || valueShort > 255) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
-
- if (returnType.isAssignableFrom(Short.class)) {
- return returnType.cast(valueShort);
- } else if (returnType.isAssignableFrom(Byte.class)) {
- if (valueShort <= Byte.MAX_VALUE) {
- return returnType.cast(valueShort.byteValue());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType));
- }
- } else if (returnType.isAssignableFrom(Integer.class)) {
- return returnType.cast(valueShort.intValue());
- } else if (returnType.isAssignableFrom(Long.class)) {
- return returnType.cast(valueShort.longValue());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
- }
- }
-
- @Override
- protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
- if (((Number) value).longValue() >= 0 && ((Number) value).longValue() <= 255) {
- return value.toString();
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
- }
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDateTime.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDateTime.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDateTime.java
deleted file mode 100644
index d1bfedd..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDateTime.java
+++ /dev/null
@@ -1,236 +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.odata2.core.edm;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.TimeZone;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-
-/**
- * Implementation of the EDM simple type DateTime.
- *
- */
-public class EdmDateTime extends AbstractSimpleType {
-
- private static final Pattern PATTERN = Pattern.compile(
- "(\\p{Digit}{1,4})-(\\p{Digit}{1,2})-(\\p{Digit}{1,2})"
- + "T(\\p{Digit}{1,2}):(\\p{Digit}{1,2})(?::(\\p{Digit}{1,2})(\\.(\\p{Digit}{0,3}?)0*)?)?");
- private static final Pattern JSON_PATTERN = Pattern.compile("/Date\\((-?\\p{Digit}+)\\)/");
- private static final EdmDateTime instance = new EdmDateTime();
-
- public static EdmDateTime getInstance() {
- return instance;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Calendar.class;
- }
-
- @Override
- protected <T> T internalValueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- // In JSON, we allow also the XML literal form, so there is on purpose
- // no exception if the JSON pattern does not match.
- if (literalKind == EdmLiteralKind.JSON) {
- final Matcher matcher = JSON_PATTERN.matcher(value);
- if (matcher.matches()) {
- long millis;
- try {
- millis = Long.parseLong(matcher.group(1));
- } catch (final NumberFormatException e) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e);
- }
- if (returnType.isAssignableFrom(Long.class)) {
- return returnType.cast(millis);
- } else if (returnType.isAssignableFrom(Date.class)) {
- return returnType.cast(new Date(millis));
- } else if (returnType.isAssignableFrom(Calendar.class)) {
- Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
- dateTimeValue.clear();
- dateTimeValue.setTimeInMillis(millis);
- return returnType.cast(dateTimeValue);
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
- }
- }
- }
-
- Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
- dateTimeValue.clear();
-
- if (literalKind == EdmLiteralKind.URI) {
- if (value.length() > 10 && value.startsWith("datetime'") && value.endsWith("'")) {
- parseLiteral(value.substring(9, value.length() - 1), facets, dateTimeValue);
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
- } else {
- parseLiteral(value, facets, dateTimeValue);
- }
-
- if (returnType.isAssignableFrom(Calendar.class)) {
- return returnType.cast(dateTimeValue);
- } else if (returnType.isAssignableFrom(Long.class)) {
- return returnType.cast(dateTimeValue.getTimeInMillis());
- } else if (returnType.isAssignableFrom(Date.class)) {
- return returnType.cast(dateTimeValue.getTime());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
- }
- }
-
- /**
- * Parses a formatted date/time value and sets the values of a
- * {@link Calendar} object accordingly.
- * @param value the formatted date/time value as String
- * @param facets additional constraints for parsing (optional)
- * @param dateTimeValue the Calendar object to be set to the parsed value
- * @throws EdmSimpleTypeException
- */
- protected static void parseLiteral(final String value, final EdmFacets facets, final Calendar dateTimeValue) throws EdmSimpleTypeException {
- final Matcher matcher = PATTERN.matcher(value);
- if (!matcher.matches()) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
-
- dateTimeValue.set(
- Short.parseShort(matcher.group(1)),
- Byte.parseByte(matcher.group(2)) - 1, // month is zero-based
- Byte.parseByte(matcher.group(3)),
- Byte.parseByte(matcher.group(4)),
- Byte.parseByte(matcher.group(5)),
- matcher.group(6) == null ? 0 : Byte.parseByte(matcher.group(6)));
-
- if (matcher.group(7) != null) {
- if (matcher.group(7).length() == 1 || matcher.group(7).length() > 8) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
- final String decimals = matcher.group(8);
- if (facets != null && facets.getPrecision() != null && facets.getPrecision() < decimals.length()) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets));
- }
- final String milliSeconds = decimals + "000".substring(decimals.length());
- dateTimeValue.set(Calendar.MILLISECOND, Short.parseShort(milliSeconds));
- }
-
- // The Calendar class does not check any values until a get method is called,
- // so we do just that to validate the fields set above, not because we want
- // to return something else. For strict checks, the lenient mode is switched
- // off temporarily.
- dateTimeValue.setLenient(false);
- try {
- dateTimeValue.get(Calendar.MILLISECOND);
- } catch (final IllegalArgumentException e) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e);
- }
- dateTimeValue.setLenient(true);
- }
-
- @Override
- protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- long timeInMillis;
- if (value instanceof Date) {
- timeInMillis = ((Date) value).getTime();
- } else if (value instanceof Calendar) {
- timeInMillis = ((Calendar) value).getTimeInMillis();
- } else if (value instanceof Long) {
- timeInMillis = ((Long) value).longValue();
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
- }
-
- if (literalKind == EdmLiteralKind.JSON) {
- return "/Date(" + timeInMillis + ")/";
- }
-
- Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
- dateTimeValue.setTimeInMillis(timeInMillis);
-
- StringBuilder result = new StringBuilder(23); // 23 characters are enough for millisecond precision.
- final int year = dateTimeValue.get(Calendar.YEAR);
- appendTwoDigits(result, year / 100);
- appendTwoDigits(result, year % 100);
- result.append('-');
- appendTwoDigits(result, dateTimeValue.get(Calendar.MONTH) + 1); // month is zero-based
- result.append('-');
- appendTwoDigits(result, dateTimeValue.get(Calendar.DAY_OF_MONTH));
- result.append('T');
- appendTwoDigits(result, dateTimeValue.get(Calendar.HOUR_OF_DAY));
- result.append(':');
- appendTwoDigits(result, dateTimeValue.get(Calendar.MINUTE));
- result.append(':');
- appendTwoDigits(result, dateTimeValue.get(Calendar.SECOND));
-
- try {
- appendMilliseconds(result, timeInMillis, facets);
- } catch (final IllegalArgumentException e) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets), e);
- }
-
- return result.toString();
- }
-
- /**
- * Appends the given number to the given string builder,
- * assuming that the number has at most two digits, performance-optimized.
- * @param result a {@link StringBuilder}
- * @param number an integer that must satisfy <code>0 <= number <= 99</code>
- */
- private static void appendTwoDigits(final StringBuilder result, final int number) {
- result.append((char) ('0' + number / 10));
- result.append((char) ('0' + number % 10));
- }
-
- protected static void appendMilliseconds(final StringBuilder result, final long milliseconds, final EdmFacets facets) throws IllegalArgumentException {
- final int digits = milliseconds % 1000 == 0 ? 0 : milliseconds % 100 == 0 ? 1 : milliseconds % 10 == 0 ? 2 : 3;
- if (digits > 0) {
- result.append('.');
- for (int d = 100; d > 0; d /= 10) {
- final byte digit = (byte) (milliseconds % (d * 10) / d);
- if (digit > 0 || milliseconds % d > 0) {
- result.append((char) ('0' + digit));
- }
- }
- }
-
- if (facets != null && facets.getPrecision() != null) {
- final int precision = facets.getPrecision();
- if (digits > precision) {
- throw new IllegalArgumentException();
- }
- if (digits == 0 && precision > 0) {
- result.append('.');
- }
- for (int i = digits; i < precision; i++) {
- result.append('0');
- }
- }
- }
-
- @Override
- public String toUriLiteral(final String literal) throws EdmSimpleTypeException {
- return "datetime'" + literal + "'";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java
deleted file mode 100644
index bb3295b..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java
+++ /dev/null
@@ -1,166 +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.odata2.core.edm;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.TimeZone;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-
-/**
- * Implementation of the EDM simple type DateTimeOffset.
- *
- * Details about parsing of time strings to {@link EdmDateTimeOffset} objects can be found in {@link org.apache.olingo.odata2.api.edm.EdmSimpleType} documentation.
- *
- *
- */
-public class EdmDateTimeOffset extends AbstractSimpleType {
-
- private static final Pattern PATTERN = Pattern.compile(
- "\\p{Digit}{1,4}-\\p{Digit}{1,2}-\\p{Digit}{1,2}"
- + "T\\p{Digit}{1,2}:\\p{Digit}{1,2}(?::\\p{Digit}{1,2}(?:\\.\\p{Digit}{1,7})?)?"
- + "(Z|([-+]\\p{Digit}{1,2}:\\p{Digit}{2}))?");
- private static final Pattern JSON_PATTERN = Pattern.compile(
- "/Date\\((-?\\p{Digit}+)(?:(\\+|-)(\\p{Digit}{1,4}))?\\)/");
- private static final EdmDateTimeOffset instance = new EdmDateTimeOffset();
-
- public static EdmDateTimeOffset getInstance() {
- return instance;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Calendar.class;
- }
-
- @Override
- protected <T> T internalValueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- if (literalKind == EdmLiteralKind.URI) {
- if (value.length() > 16 && value.startsWith("datetimeoffset'") && value.endsWith("'")) {
- return internalValueOfString(value.substring(15, value.length() - 1), EdmLiteralKind.DEFAULT, facets, returnType);
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
- }
-
- Calendar dateTimeValue = null;
-
- if (literalKind == EdmLiteralKind.JSON) {
- final Matcher matcher = JSON_PATTERN.matcher(value);
- if (matcher.matches()) {
- long millis;
- try {
- millis = Long.parseLong(matcher.group(1));
- } catch (final NumberFormatException e) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e);
- }
- String timeZone = "GMT";
- if (matcher.group(2) != null) {
- final int offsetInMinutes = Integer.parseInt(matcher.group(3));
- if (offsetInMinutes >= 24 * 60) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
- if (offsetInMinutes != 0) {
- timeZone += matcher.group(2) + String.valueOf(offsetInMinutes / 60)
- + ":" + String.format("%02d", offsetInMinutes % 60);
- // Convert the local-time milliseconds to UTC.
- millis -= (matcher.group(2).equals("+") ? 1 : -1) * offsetInMinutes * 60 * 1000;
- }
- }
- dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
- dateTimeValue.clear();
- dateTimeValue.setTimeInMillis(millis);
- }
- }
-
- if (dateTimeValue == null) {
- final Matcher matcher = PATTERN.matcher(value);
- if (!matcher.matches()) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
-
- final String timeZoneOffset = matcher.group(1) != null && matcher.group(2) != null && !matcher.group(2).matches("[-+]0+:0+") ? matcher.group(2) : null;
- dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT" + timeZoneOffset));
- if (dateTimeValue.get(Calendar.ZONE_OFFSET) == 0 && timeZoneOffset != null) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
- dateTimeValue.clear();
- EdmDateTime.parseLiteral(value.substring(0, matcher.group(1) == null ? value.length() : matcher.start(1)), facets, dateTimeValue);
- }
-
- if (returnType.isAssignableFrom(Calendar.class)) {
- return returnType.cast(dateTimeValue);
- } else if (returnType.isAssignableFrom(Long.class)) {
- return returnType.cast(dateTimeValue.getTimeInMillis());
- } else if (returnType.isAssignableFrom(Date.class)) {
- return returnType.cast(dateTimeValue.getTime());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
- }
- }
-
- @Override
- protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- Long milliSeconds; // number of milliseconds since 1970-01-01T00:00:00Z
- int offset; // offset in milliseconds from GMT to the requested time zone
- if (value instanceof Date) {
- milliSeconds = ((Date) value).getTime();
- // Although java.util.Date, as stated in its documentation,
- // "is intended to reflect coordinated universal time (UTC)",
- // its toString() method uses the default time zone. And so do we.
- Calendar dateTimeValue = Calendar.getInstance();
- dateTimeValue.setTime((Date) value);
- offset = dateTimeValue.get(Calendar.ZONE_OFFSET) + dateTimeValue.get(Calendar.DST_OFFSET);
- } else if (value instanceof Calendar) {
- final Calendar dateTimeValue = (Calendar) ((Calendar) value).clone();
- milliSeconds = dateTimeValue.getTimeInMillis();
- offset = dateTimeValue.get(Calendar.ZONE_OFFSET) + dateTimeValue.get(Calendar.DST_OFFSET);
- } else if (value instanceof Long) {
- milliSeconds = (Long) value;
- offset = 0;
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
- }
-
- milliSeconds += offset; // Convert from UTC to local time.
- final int offsetInMinutes = offset / 60 / 1000;
-
- if (literalKind == EdmLiteralKind.JSON) {
- return "/Date(" + milliSeconds + (offset == 0 ? "" : String.format("%+05d", offsetInMinutes)) + ")/";
-
- } else {
- final String localTimeString = EdmDateTime.getInstance().valueToString(milliSeconds, EdmLiteralKind.DEFAULT, facets);
- final int offsetHours = offsetInMinutes / 60;
- final int offsetMinutes = Math.abs(offsetInMinutes % 60);
- final String offsetString = offset == 0 ? "Z" : String.format("%+03d:%02d", offsetHours, offsetMinutes);
-
- return localTimeString + offsetString;
- }
- }
-
- @Override
- public String toUriLiteral(final String literal) throws EdmSimpleTypeException {
- return "datetimeoffset'" + literal + "'";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDecimal.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDecimal.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDecimal.java
deleted file mode 100644
index dfec75a..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDecimal.java
+++ /dev/null
@@ -1,199 +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.odata2.core.edm;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-
-/**
- * Implementation of the EDM simple type Decimal.
- *
- */
-public class EdmDecimal extends AbstractSimpleType {
-
- // value-range limitation according to the CSDL document
- private static final int MAX_DIGITS = 29;
-
- private static final Pattern PATTERN = Pattern.compile("(?:\\+|-)?(?:0*(\\p{Digit}{1,29}?))(?:\\.(\\p{Digit}{1,29}?)0*)?(M|m)?");
- private static final EdmDecimal instance = new EdmDecimal();
-
- public static EdmDecimal getInstance() {
- return instance;
- }
-
- @Override
- public boolean isCompatible(final EdmSimpleType simpleType) {
- return simpleType instanceof Bit
- || simpleType instanceof Uint7
- || simpleType instanceof EdmByte
- || simpleType instanceof EdmSByte
- || simpleType instanceof EdmInt16
- || simpleType instanceof EdmInt32
- || simpleType instanceof EdmInt64
- || simpleType instanceof EdmSingle
- || simpleType instanceof EdmDouble
- || simpleType instanceof EdmDecimal;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return BigDecimal.class;
- }
-
- @Override
- public boolean validate(final String value, final EdmLiteralKind literalKind, final EdmFacets facets) {
- if (value == null) {
- return facets == null || facets.isNullable() == null || facets.isNullable();
- }
-
- if (literalKind == null) {
- return false;
- }
-
- return validateLiteral(value, literalKind) && validatePrecisionAndScale(value, facets);
- }
-
- private static boolean validateLiteral(final String value, final EdmLiteralKind literalKind) {
- final Matcher matcher = PATTERN.matcher(value);
- return matcher.matches()
- && (literalKind == EdmLiteralKind.URI) != (matcher.group(3) == null);
- }
-
- private static final boolean validatePrecisionAndScale(final String value, final EdmFacets facets) {
- if (facets == null || facets.getPrecision() == null && facets.getScale() == null) {
- return true;
- }
-
- final Matcher matcher = PATTERN.matcher(value);
- matcher.matches();
- final int significantIntegerDigits = matcher.group(1).equals("0") ? 0 : matcher.group(1).length();
- final int decimals = matcher.group(2) == null ? 0 : matcher.group(2).length();
- return (facets.getPrecision() == null || facets.getPrecision() >= significantIntegerDigits + decimals)
- && (facets.getScale() == null || facets.getScale() >= decimals);
- }
-
- @Override
- protected <T> T internalValueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- if (!validateLiteral(value, literalKind)) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
- if (!validatePrecisionAndScale(value, facets)) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets));
- }
-
- final BigDecimal valueBigDecimal = new BigDecimal(
- literalKind == EdmLiteralKind.URI ? value.substring(0, value.length() - 1) : value);
-
- if (returnType.isAssignableFrom(BigDecimal.class)) {
- return returnType.cast(valueBigDecimal);
- } else if (returnType.isAssignableFrom(Double.class)) {
- if (BigDecimal.valueOf(valueBigDecimal.doubleValue()).compareTo(valueBigDecimal) == 0) {
- return returnType.cast(valueBigDecimal.doubleValue());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType));
- }
- } else if (returnType.isAssignableFrom(Float.class)) {
- if (BigDecimal.valueOf(valueBigDecimal.floatValue()).compareTo(valueBigDecimal) == 0) {
- return returnType.cast(valueBigDecimal.floatValue());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType));
- }
- } else {
- try {
- if (returnType.isAssignableFrom(BigInteger.class)) {
- return returnType.cast(valueBigDecimal.toBigIntegerExact());
- } else if (returnType.isAssignableFrom(Long.class)) {
- return returnType.cast(valueBigDecimal.longValueExact());
- } else if (returnType.isAssignableFrom(Integer.class)) {
- return returnType.cast(valueBigDecimal.intValueExact());
- } else if (returnType.isAssignableFrom(Short.class)) {
- return returnType.cast(valueBigDecimal.shortValueExact());
- } else if (returnType.isAssignableFrom(Byte.class)) {
- return returnType.cast(valueBigDecimal.byteValueExact());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
- }
- } catch (final ArithmeticException e) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e);
- }
- }
- }
-
- @Override
- protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- String result;
- if (value instanceof Long || value instanceof Integer || value instanceof Short || value instanceof Byte || value instanceof BigInteger) {
- result = value.toString();
- final int digits = result.startsWith("-") ? result.length() - 1 : result.length();
- if (digits > MAX_DIGITS) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
- }
- if (facets != null && facets.getPrecision() != null && facets.getPrecision() < digits) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets));
- }
-
- } else if (value instanceof Double || value instanceof Float || value instanceof BigDecimal) {
- BigDecimal bigDecimalValue;
- try {
- if (value instanceof Double) {
- bigDecimalValue = BigDecimal.valueOf((Double) value);
- } else if (value instanceof Float) {
- bigDecimalValue = BigDecimal.valueOf((Float) value);
- } else {
- bigDecimalValue = (BigDecimal) value;
- }
- } catch (final NumberFormatException e) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value), e);
- }
-
- if (bigDecimalValue.precision() - bigDecimalValue.scale() > MAX_DIGITS
- || bigDecimalValue.scale() > MAX_DIGITS) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
- }
-
- final int digits = bigDecimalValue.scale() >= 0 ?
- Math.max(bigDecimalValue.precision(), bigDecimalValue.scale()) :
- bigDecimalValue.precision() - bigDecimalValue.scale();
- if (facets == null
- || (facets.getPrecision() == null || facets.getPrecision() >= digits)
- && (facets.getScale() == null || facets.getScale() >= bigDecimalValue.scale())) {
- result = bigDecimalValue.toPlainString();
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets));
- }
-
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
- }
-
- return result;
- }
-
- @Override
- public String toUriLiteral(final String literal) throws EdmSimpleTypeException {
- return literal + "M";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDouble.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDouble.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDouble.java
deleted file mode 100644
index 824e1c5..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmDouble.java
+++ /dev/null
@@ -1,164 +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.odata2.core.edm;
-
-import java.math.BigDecimal;
-import java.util.Locale;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-
-/**
- * Implementation of the EDM simple type Double.
- *
- */
-public class EdmDouble extends AbstractSimpleType {
-
- // value-range limitations according to the CSDL document
- private static final int MAX_PRECISION = 15;
- private static final int MAX_SCALE = 308;
-
- private static final Pattern PATTERN = Pattern.compile(
- "(?:\\+|-)?\\p{Digit}{1,15}(?:\\.\\p{Digit}{1,15})?(?:(?:E|e)(?:\\+|-)?\\p{Digit}{1,3})?(D|d)?");
- private static final EdmDouble instance = new EdmDouble();
-
- public static EdmDouble getInstance() {
- return instance;
- }
-
- @Override
- public boolean isCompatible(final EdmSimpleType simpleType) {
- return simpleType instanceof Bit
- || simpleType instanceof Uint7
- || simpleType instanceof EdmByte
- || simpleType instanceof EdmSByte
- || simpleType instanceof EdmInt16
- || simpleType instanceof EdmInt32
- || simpleType instanceof EdmInt64
- || simpleType instanceof EdmSingle
- || simpleType instanceof EdmDouble;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Double.class;
- }
-
- @Override
- protected <T> T internalValueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- String valueString = value;
- Double result = null;
- // Handle special values first.
- if (value.equals("-INF")) {
- result = Double.NEGATIVE_INFINITY;
- } else if (value.equals("INF")) {
- result = Double.POSITIVE_INFINITY;
- } else if (value.equals("NaN")) {
- result = Double.NaN;
- } else {
- // Now only "normal" numbers remain.
- final Matcher matcher = PATTERN.matcher(value);
- if (!matcher.matches()
- || (literalKind == EdmLiteralKind.URI) == (matcher.group(1) == null)) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
-
- if (literalKind == EdmLiteralKind.URI) {
- valueString = value.substring(0, value.length() - 1);
- }
-
- // The number format is checked above, so we don't have to catch NumberFormatException.
- result = Double.valueOf(valueString);
- // "Real" infinite values have been treated already above, so we can throw an exception
- // if the conversion to a float results in an infinite value.
- if (result.isInfinite()) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
- }
-
- if (returnType.isAssignableFrom(Double.class)) {
- return returnType.cast(result);
- } else if (returnType.isAssignableFrom(Float.class)) {
- if (result.floatValue() == result) {
- return returnType.cast(result.floatValue());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType));
- }
- } else if (result.isInfinite() || result.isNaN()) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType));
- } else {
- try {
- final BigDecimal valueBigDecimal = new BigDecimal(valueString);
- if (returnType.isAssignableFrom(BigDecimal.class)) {
- return returnType.cast(valueBigDecimal);
- } else if (returnType.isAssignableFrom(Long.class)) {
- return returnType.cast(valueBigDecimal.longValueExact());
- } else if (returnType.isAssignableFrom(Integer.class)) {
- return returnType.cast(valueBigDecimal.intValueExact());
- } else if (returnType.isAssignableFrom(Short.class)) {
- return returnType.cast(valueBigDecimal.shortValueExact());
- } else if (returnType.isAssignableFrom(Byte.class)) {
- return returnType.cast(valueBigDecimal.byteValueExact());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
- }
-
- } catch (final ArithmeticException e) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e);
- }
- }
- }
-
- @Override
- protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- if (value instanceof Long) {
- if (Math.abs((Long) value) < Math.pow(10, MAX_PRECISION)) {
- return value.toString();
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
- }
- } else if (value instanceof Integer || value instanceof Short || value instanceof Byte) {
- return value.toString();
- } else if (value instanceof Double) {
- final String result = value.toString();
- return ((Double) value).isInfinite() ? result.toUpperCase(Locale.ROOT).substring(0, value.toString().length() - 5) : result;
- } else if (value instanceof Float) {
- final String result = value.toString();
- return ((Float) value).isInfinite() ? result.toUpperCase(Locale.ROOT).substring(0, value.toString().length() - 5) : result;
- } else if (value instanceof BigDecimal) {
- if (((BigDecimal) value).precision() <= MAX_PRECISION && Math.abs(((BigDecimal) value).scale()) <= MAX_SCALE) {
- return ((BigDecimal) value).toString();
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
- }
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
- }
- }
-
- @Override
- public String toUriLiteral(final String literal) {
- return literal.equals("-INF") || literal.equals("INF") || literal.equals("NaN") ?
- literal : literal + "D";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmGuid.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmGuid.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmGuid.java
deleted file mode 100644
index d60815a..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmGuid.java
+++ /dev/null
@@ -1,86 +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.odata2.core.edm;
-
-import java.util.UUID;
-
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-
-/**
- * Implementation of the EDM simple type Guid.
- *
- */
-public class EdmGuid extends AbstractSimpleType {
-
- private static final String PATTERN = "\\p{XDigit}{8}-\\p{XDigit}{4}-\\p{XDigit}{4}-\\p{XDigit}{4}-\\p{XDigit}{12}";
- private static final EdmGuid instance = new EdmGuid();
-
- public static EdmGuid getInstance() {
- return instance;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return UUID.class;
- }
-
- @Override
- public boolean validate(final String value, final EdmLiteralKind literalKind, final EdmFacets facets) {
- return value == null ?
- facets == null || facets.isNullable() == null || facets.isNullable() :
- validateLiteral(value, literalKind);
- }
-
- private boolean validateLiteral(final String value, final EdmLiteralKind literalKind) {
- return value.matches(literalKind == EdmLiteralKind.URI ? toUriLiteral(PATTERN) : PATTERN);
- }
-
- @Override
- protected <T> T internalValueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- UUID result;
- if (validateLiteral(value, literalKind)) {
- result = UUID.fromString(
- literalKind == EdmLiteralKind.URI ? value.substring(5, value.length() - 1) : value);
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
-
- if (returnType.isAssignableFrom(UUID.class)) {
- return returnType.cast(result);
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
- }
- }
-
- @Override
- protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- if (value instanceof UUID) {
- return ((UUID) value).toString();
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
- }
- }
-
- @Override
- public String toUriLiteral(final String literal) {
- return "guid'" + literal + "'";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmImpl.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmImpl.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmImpl.java
deleted file mode 100644
index 1de243e..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmImpl.java
+++ /dev/null
@@ -1,197 +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.odata2.core.edm;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.edm.Edm;
-import org.apache.olingo.odata2.api.edm.EdmAssociation;
-import org.apache.olingo.odata2.api.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.edm.EdmEntityContainer;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.edm.EdmServiceMetadata;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.exception.ODataException;
-
-/**
- *
- */
-public abstract class EdmImpl implements Edm {
-
- private Map<String, EdmEntityContainer> edmEntityContainers;
- private Map<FullQualifiedName, EdmEntityType> edmEntityTypes;
- private Map<FullQualifiedName, EdmComplexType> edmComplexTypes;
- private Map<FullQualifiedName, EdmAssociation> edmAssociations;
- private List<EdmEntitySet> edmEntitySets;
- private List<EdmFunctionImport> edmFunctionImports;
-
- protected EdmServiceMetadata edmServiceMetadata;
-
- public EdmImpl(final EdmServiceMetadata edmServiceMetadata) {
- edmEntityContainers = new HashMap<String, EdmEntityContainer>();
- edmEntityTypes = new HashMap<FullQualifiedName, EdmEntityType>();
- edmComplexTypes = new HashMap<FullQualifiedName, EdmComplexType>();
- edmAssociations = new HashMap<FullQualifiedName, EdmAssociation>();
- this.edmServiceMetadata = edmServiceMetadata;
- }
-
- @Override
- public EdmEntityContainer getEntityContainer(final String name) throws EdmException {
- if (edmEntityContainers.containsKey(name)) {
- return edmEntityContainers.get(name);
- }
-
- EdmEntityContainer edmEntityContainer = null;
-
- try {
- edmEntityContainer = createEntityContainer(name);
- if (edmEntityContainer != null) {
- if (name == null && edmEntityContainers.containsKey(edmEntityContainer.getName())) {
- //ensure that the same default entity container is stored in the HashMap under null and its name
- edmEntityContainer = edmEntityContainers.get(edmEntityContainer.getName());
- edmEntityContainers.put(name, edmEntityContainer);
- } else if (edmEntityContainers.containsKey(null) && edmEntityContainers.get(null) != null && name.equals(edmEntityContainers.get(null).getName())) {
- //ensure that the same default entity container is stored in the HashMap under null and its name
- edmEntityContainer = edmEntityContainers.get(null);
- edmEntityContainers.put(name, edmEntityContainer);
- } else {
- edmEntityContainers.put(name, edmEntityContainer);
- }
- }
- } catch (ODataException e) {
- throw new EdmException(EdmException.COMMON, e);
- }
-
- return edmEntityContainer;
- }
-
- @Override
- public EdmEntityType getEntityType(final String namespace, final String name) throws EdmException {
- FullQualifiedName fqName = new FullQualifiedName(namespace, name);
- if (edmEntityTypes.containsKey(fqName)) {
- return edmEntityTypes.get(fqName);
- }
-
- EdmEntityType edmEntityType = null;
-
- try {
- edmEntityType = createEntityType(fqName);
- if (edmEntityType != null) {
- edmEntityTypes.put(fqName, edmEntityType);
- }
- } catch (ODataException e) {
- throw new EdmException(EdmException.COMMON, e);
- }
-
- return edmEntityType;
- }
-
- @Override
- public EdmComplexType getComplexType(final String namespace, final String name) throws EdmException {
- FullQualifiedName fqName = new FullQualifiedName(namespace, name);
- if (edmComplexTypes.containsKey(fqName)) {
- return edmComplexTypes.get(fqName);
- }
-
- EdmComplexType edmComplexType = null;
-
- try {
- edmComplexType = createComplexType(fqName);
- if (edmComplexType != null) {
- edmComplexTypes.put(fqName, edmComplexType);
- }
- } catch (ODataException e) {
- throw new EdmException(EdmException.COMMON, e);
- }
-
- return edmComplexType;
- }
-
- @Override
- public EdmAssociation getAssociation(final String namespace, final String name) throws EdmException {
- FullQualifiedName fqName = new FullQualifiedName(namespace, name);
- if (edmAssociations.containsKey(fqName)) {
- return edmAssociations.get(fqName);
- }
-
- EdmAssociation edmAssociation = null;
-
- try {
- edmAssociation = createAssociation(fqName);
- if (edmAssociation != null) {
- edmAssociations.put(fqName, edmAssociation);
- }
- } catch (ODataException e) {
- throw new EdmException(EdmException.COMMON, e);
- }
-
- return edmAssociation;
- }
-
- @Override
- public EdmServiceMetadata getServiceMetadata() {
- return edmServiceMetadata;
- }
-
- @Override
- public EdmEntityContainer getDefaultEntityContainer() throws EdmException {
- return getEntityContainer(null);
- }
-
- @Override
- public List<EdmEntitySet> getEntitySets() throws EdmException {
- try {
- if (edmEntitySets == null) {
- edmEntitySets = createEntitySets();
- }
- } catch (ODataException e) {
- throw new EdmException(EdmException.COMMON, e);
- }
- return edmEntitySets;
- }
-
- @Override
- public List<EdmFunctionImport> getFunctionImports() throws EdmException {
- try {
- if (edmFunctionImports == null) {
- edmFunctionImports = createFunctionImports();
- }
- } catch (ODataException e) {
- throw new EdmException(EdmException.COMMON, e);
- }
- return edmFunctionImports;
- }
-
- protected abstract EdmEntityContainer createEntityContainer(String name) throws ODataException;
-
- protected abstract EdmEntityType createEntityType(FullQualifiedName fqName) throws ODataException;
-
- protected abstract EdmComplexType createComplexType(FullQualifiedName fqName) throws ODataException;
-
- protected abstract EdmAssociation createAssociation(FullQualifiedName fqName) throws ODataException;
-
- protected abstract List<EdmEntitySet> createEntitySets() throws ODataException;
-
- protected abstract List<EdmFunctionImport> createFunctionImports() throws ODataException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmInt16.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmInt16.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmInt16.java
deleted file mode 100644
index 4f81303..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmInt16.java
+++ /dev/null
@@ -1,92 +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.odata2.core.edm;
-
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-
-/**
- * Implementation of the EDM simple type Int16.
- *
- */
-public class EdmInt16 extends AbstractSimpleType {
-
- private static final EdmInt16 instance = new EdmInt16();
-
- public static EdmInt16 getInstance() {
- return instance;
- }
-
- @Override
- public boolean isCompatible(final EdmSimpleType simpleType) {
- return simpleType instanceof Bit
- || simpleType instanceof Uint7
- || simpleType instanceof EdmByte
- || simpleType instanceof EdmSByte
- || simpleType instanceof EdmInt16;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Short.class;
- }
-
- @Override
- protected <T> T internalValueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- Short valueShort;
- try {
- valueShort = Short.parseShort(value);
- } catch (final NumberFormatException e) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e);
- }
-
- if (returnType.isAssignableFrom(Short.class)) {
- return returnType.cast(valueShort);
- } else if (returnType.isAssignableFrom(Byte.class)) {
- if (valueShort >= Byte.MIN_VALUE && valueShort <= Byte.MAX_VALUE) {
- return returnType.cast(valueShort.byteValue());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType));
- }
- } else if (returnType.isAssignableFrom(Integer.class)) {
- return returnType.cast(valueShort.intValue());
- } else if (returnType.isAssignableFrom(Long.class)) {
- return returnType.cast(valueShort.longValue());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
- }
- }
-
- @Override
- protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- if (value instanceof Byte || value instanceof Short) {
- return value.toString();
- } else if (value instanceof Integer || value instanceof Long) {
- if (((Number) value).longValue() >= Short.MIN_VALUE && ((Number) value).longValue() <= Short.MAX_VALUE) {
- return value.toString();
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
- }
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmInt32.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmInt32.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmInt32.java
deleted file mode 100644
index ce2fcbd..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmInt32.java
+++ /dev/null
@@ -1,97 +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.odata2.core.edm;
-
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-
-/**
- * Implementation of the EDM simple type Int32.
- *
- */
-public class EdmInt32 extends AbstractSimpleType {
-
- private static final EdmInt32 instance = new EdmInt32();
-
- public static EdmInt32 getInstance() {
- return instance;
- }
-
- @Override
- public boolean isCompatible(final EdmSimpleType simpleType) {
- return simpleType instanceof Bit
- || simpleType instanceof Uint7
- || simpleType instanceof EdmByte
- || simpleType instanceof EdmSByte
- || simpleType instanceof EdmInt16
- || simpleType instanceof EdmInt32;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Integer.class;
- }
-
- @Override
- protected <T> T internalValueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- Integer valueInteger;
- try {
- valueInteger = Integer.parseInt(value);
- } catch (final NumberFormatException e) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e);
- }
-
- if (returnType.isAssignableFrom(Integer.class)) {
- return returnType.cast(valueInteger);
- } else if (returnType.isAssignableFrom(Byte.class)) {
- if (valueInteger >= Byte.MIN_VALUE && valueInteger <= Byte.MAX_VALUE) {
- return returnType.cast(valueInteger.byteValue());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType));
- }
- } else if (returnType.isAssignableFrom(Short.class)) {
- if (valueInteger >= Short.MIN_VALUE && valueInteger <= Short.MAX_VALUE) {
- return returnType.cast(valueInteger.shortValue());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType));
- }
- } else if (returnType.isAssignableFrom(Long.class)) {
- return returnType.cast(valueInteger.longValue());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
- }
- }
-
- @Override
- protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- if (value instanceof Byte || value instanceof Short || value instanceof Integer) {
- return value.toString();
- } else if (value instanceof Long) {
- if ((Long) value >= Integer.MIN_VALUE && (Long) value <= Integer.MAX_VALUE) {
- return value.toString();
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
- }
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmInt64.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmInt64.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmInt64.java
deleted file mode 100644
index ef3f0a1..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmInt64.java
+++ /dev/null
@@ -1,119 +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.odata2.core.edm;
-
-import java.math.BigInteger;
-
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-
-/**
- * Implementation of the EDM simple type Int64.
- *
- */
-public class EdmInt64 extends AbstractSimpleType {
-
- private static final EdmInt64 instance = new EdmInt64();
-
- public static EdmInt64 getInstance() {
- return instance;
- }
-
- @Override
- public boolean isCompatible(final EdmSimpleType simpleType) {
- return simpleType instanceof Bit
- || simpleType instanceof Uint7
- || simpleType instanceof EdmByte
- || simpleType instanceof EdmSByte
- || simpleType instanceof EdmInt16
- || simpleType instanceof EdmInt32
- || simpleType instanceof EdmInt64;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Long.class;
- }
-
- @Override
- protected <T> T internalValueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- Long valueLong;
- try {
- if (literalKind == EdmLiteralKind.URI) {
- if (value.endsWith("L") || value.endsWith("l")) {
- valueLong = Long.parseLong(value.substring(0, value.length() - 1));
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
- }
- } else {
- valueLong = Long.parseLong(value);
- }
- } catch (final NumberFormatException e) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e);
- }
-
- if (returnType.isAssignableFrom(Long.class)) {
- return returnType.cast(valueLong);
- } else if (returnType.isAssignableFrom(Byte.class)) {
- if (valueLong >= Byte.MIN_VALUE && valueLong <= Byte.MAX_VALUE) {
- return returnType.cast(valueLong.byteValue());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType));
- }
- } else if (returnType.isAssignableFrom(Short.class)) {
- if (valueLong >= Short.MIN_VALUE && valueLong <= Short.MAX_VALUE) {
- return returnType.cast(valueLong.shortValue());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType));
- }
- } else if (returnType.isAssignableFrom(Integer.class)) {
- if (valueLong >= Integer.MIN_VALUE && valueLong <= Integer.MAX_VALUE) {
- return returnType.cast(valueLong.intValue());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType));
- }
- } else if (returnType.isAssignableFrom(BigInteger.class)) {
- return returnType.cast(BigInteger.valueOf(valueLong));
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
- }
- }
-
- @Override
- protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
- return value.toString();
- } else if (value instanceof BigInteger) {
- if (((BigInteger) value).bitLength() < Long.SIZE) {
- return value.toString();
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
- }
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
- }
- }
-
- @Override
- public String toUriLiteral(final String literal) {
- return literal + "L";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmNull.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmNull.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmNull.java
deleted file mode 100644
index b33eb32..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmNull.java
+++ /dev/null
@@ -1,66 +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.odata2.core.edm;
-
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-
-/**
- * Implementation of the simple type Null.
- *
- */
-public class EdmNull extends AbstractSimpleType {
-
- private static final EdmNull instance = new EdmNull();
-
- public static EdmNull getInstance() {
- return instance;
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj || obj == null;
- }
-
- @Override
- public int hashCode() {
- return 0;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return null;
- }
-
- @Override
- protected <T> T internalValueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- return null;
- }
-
- @Override
- protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- return null;
- }
-
- @Override
- public String toUriLiteral(final String literal) {
- return "null";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/fece4008/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmSByte.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmSByte.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmSByte.java
deleted file mode 100644
index 78c040c..0000000
--- a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/core/edm/EdmSByte.java
+++ /dev/null
@@ -1,86 +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.odata2.core.edm;
-
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-
-/**
- * Implementation of the EDM simple type SByte.
- *
- */
-public class EdmSByte extends AbstractSimpleType {
-
- private static final EdmSByte instance = new EdmSByte();
-
- public static EdmSByte getInstance() {
- return instance;
- }
-
- @Override
- public boolean isCompatible(final EdmSimpleType simpleType) {
- return simpleType instanceof Bit
- || simpleType instanceof Uint7
- || simpleType instanceof EdmSByte;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Byte.class;
- }
-
- @Override
- protected <T> T internalValueOfString(final String value, final EdmLiteralKind literalKind, final EdmFacets facets, final Class<T> returnType) throws EdmSimpleTypeException {
- Byte valueByte;
- try {
- valueByte = Byte.parseByte(value);
- } catch (final NumberFormatException e) {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e);
- }
-
- if (returnType.isAssignableFrom(Byte.class)) {
- return returnType.cast(valueByte);
- } else if (returnType.isAssignableFrom(Short.class)) {
- return returnType.cast(valueByte.shortValue());
- } else if (returnType.isAssignableFrom(Integer.class)) {
- return returnType.cast(valueByte.intValue());
- } else if (returnType.isAssignableFrom(Long.class)) {
- return returnType.cast(valueByte.longValue());
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
- }
- }
-
- @Override
- protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets) throws EdmSimpleTypeException {
- if (value instanceof Byte) {
- return value.toString();
- } else if (value instanceof Short || value instanceof Integer || value instanceof Long) {
- if (((Number) value).longValue() >= Byte.MIN_VALUE && ((Number) value).longValue() <= Byte.MAX_VALUE) {
- return value.toString();
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
- }
- } else {
- throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
- }
- }
-}