diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeKind.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeKind.java index ecac05581..7bd3e14be 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeKind.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeKind.java @@ -18,6 +18,10 @@ */ package org.apache.olingo.commons.api.edm; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + /** * Enumeration of all primitive type kinds. */ @@ -57,6 +61,26 @@ public enum EdmPrimitiveTypeKind { GeometryMultiPolygon, GeometryCollection; + private static Map VALUES_BY_NAME; + + static { + Map valuesByName = new HashMap(); + for (EdmPrimitiveTypeKind value : values()) { + valuesByName.put(value.name(), value); + } + VALUES_BY_NAME = Collections.unmodifiableMap(valuesByName); + } + + /** + * Get a type kind by name. + * + * @param name The name. + * @return The type kind or null if it does not exist. + */ + public static EdmPrimitiveTypeKind getByName(String name) { + return VALUES_BY_NAME.get(name); + } + /** * Checks if is a geospatial type. * diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java index b196b840a..46c63615c 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java @@ -109,11 +109,8 @@ public class EdmTypeInfo { fullQualifiedName = new FullQualifiedName(namespace, typeName); - try { - primitiveType = EdmPrimitiveTypeKind.valueOf(typeName); - } catch (final IllegalArgumentException e) { - primitiveType = null; - } + primitiveType = EdmPrimitiveTypeKind.getByName(typeName); + if (primitiveType == null && edm != null) { typeDefinition = edm.getTypeDefinition(fullQualifiedName); if (typeDefinition == null) {