From 8442ea8f78c0be5fea85ea73877fb6e7af78cbc4 Mon Sep 17 00:00:00 2001 From: Michael Bolz Date: Wed, 16 Jul 2014 14:22:33 +0200 Subject: [PATCH] [OLINGO-317] Simplified version dependent constants --- .../olingo/client/core/v3/JSONTest.java | 61 +++-- .../olingo/client/core/v4/JSONTest.java | 55 +++-- .../apache/olingo/commons/api/Constants.java | 55 +---- .../olingo/commons/api/domain/ODataLink.java | 6 +- .../commons/api/domain/ODataLinkType.java | 2 +- .../edm/constants/ODataServiceVersion.java | 212 +++++++----------- .../olingo/commons/core/edm/EdmTypeInfo.java | 8 +- .../serialization/AbstractAtomDealer.java | 96 +++----- .../core/serialization/AtomDeserializer.java | 15 +- .../core/serialization/AtomSerializer.java | 63 ++---- .../core/serialization/JsonDeserializer.java | 38 ++-- .../serialization/JsonEntityDeserializer.java | 2 +- .../serialization/JsonEntitySerializer.java | 12 +- .../JsonEntitySetSerializer.java | 8 +- .../serialization/JsonPropertySerializer.java | 2 +- .../core/serialization/JsonSerializer.java | 10 +- pom.xml | 12 +- 17 files changed, 247 insertions(+), 410 deletions(-) diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/JSONTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/JSONTest.java index d37334447..3a3ae600c 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/JSONTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/JSONTest.java @@ -50,47 +50,44 @@ public class JSONTest extends AtomTest { } private void cleanup(final ObjectNode node) { + final ODataServiceVersion version = getClient().getServiceVersion(); if (node.has(Constants.JSON_METADATA)) { node.remove(Constants.JSON_METADATA); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.TYPE))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.TYPE)); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.EDIT_LINK))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.EDIT_LINK)); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_READ_LINK))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_READ_LINK)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.READ_LINK))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.READ_LINK)); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK)); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_READ_LINK))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_READ_LINK)); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_CONTENT_TYPE))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_CONTENT_TYPE)); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_NEXT_LINK))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_NEXT_LINK)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.NEXT_LINK))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.NEXT_LINK)); } final List toRemove = new ArrayList(); for (final Iterator> itor = node.fields(); itor.hasNext();) { final Map.Entry field = itor.next(); - if (field.getKey().charAt(0) == '#' - || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE)) - || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK)) - || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE)) - || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK)) - || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_ETAG))) { + final String key = field.getKey(); + if (key.charAt(0) == '#' + || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.TYPE)) + || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK)) + || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_CONTENT_TYPE)) + || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.ASSOCIATION_LINK)) + || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_ETAG))) { - toRemove.add(field.getKey()); + toRemove.add(key); } else if (field.getValue().isObject()) { cleanup((ObjectNode) field.getValue()); } else if (field.getValue().isArray()) { @@ -107,12 +104,12 @@ public class JSONTest extends AtomTest { @Override protected void assertSimilar(final String filename, final String actual) throws Exception { - final JsonNode expected = OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream(filename)). - replace("Categories" + getClient().getServiceVersion().getJSONMap(). - get(ODataServiceVersion.JSON_NAVIGATION_LINK), - "Categories" + Constants.JSON_BIND_LINK_SUFFIX). - replace("\"Products(0)/Categories\"", "[\"Products(0)/Categories\"]"). - replace(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK), + final JsonNode expected = OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream(filename)) + .replace("Categories" + + getClient().getServiceVersion().getJsonName(ODataServiceVersion.JsonKey.NAVIGATION_LINK), + "Categories" + Constants.JSON_BIND_LINK_SUFFIX) + .replace("\"Products(0)/Categories\"", "[\"Products(0)/Categories\"]") + .replace(getClient().getServiceVersion().getJsonName(ODataServiceVersion.JsonKey.NAVIGATION_LINK), Constants.JSON_BIND_LINK_SUFFIX)); cleanup((ObjectNode) expected); final ObjectNode actualNode = (ObjectNode) OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes())); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java index 4cfae6f5b..fc1b69d07 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java @@ -61,50 +61,47 @@ public class JSONTest extends AbstractTest { } private void cleanup(final ObjectNode node) { + final ODataServiceVersion version = getClient().getServiceVersion(); if (node.has(Constants.JSON_CONTEXT)) { node.remove(Constants.JSON_CONTEXT); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_ETAG))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_ETAG)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.ETAG))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.ETAG)); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.TYPE))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.TYPE)); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.EDIT_LINK))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.EDIT_LINK)); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_READ_LINK))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_READ_LINK)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.READ_LINK))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.READ_LINK)); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK)); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_READ_LINK))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_READ_LINK)); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_CONTENT_TYPE))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_CONTENT_TYPE)); } - if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_COUNT))) { - node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_COUNT)); + if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.COUNT))) { + node.remove(version.getJsonName(ODataServiceVersion.JsonKey.COUNT)); } final List toRemove = new ArrayList(); for (final Iterator> itor = node.fields(); itor.hasNext();) { final Map.Entry field = itor.next(); - if (field.getKey().charAt(0) == '#' - || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE)) - || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK)) - || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE)) - || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK)) - || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_ETAG))) { + final String key = field.getKey(); + if (key.charAt(0) == '#' + || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.TYPE)) + || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK)) + || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_CONTENT_TYPE)) + || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.ASSOCIATION_LINK)) + || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_ETAG))) { - toRemove.add(field.getKey()); + toRemove.add(key); } else if (field.getValue().isObject()) { cleanup((ObjectNode) field.getValue()); } else if (field.getValue().isArray()) { @@ -121,7 +118,7 @@ public class JSONTest extends AbstractTest { protected void assertSimilar(final String filename, final String actual) throws Exception { final JsonNode expected = OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream(filename)). - replace(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK), + replace(getClient().getServiceVersion().getJsonName(ODataServiceVersion.JsonKey.NAVIGATION_LINK), Constants.JSON_BIND_LINK_SUFFIX)); cleanup((ObjectNode) expected); final ObjectNode actualNode = (ObjectNode) OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes())); diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java index 80e56963d..075ebd7ec 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java @@ -32,74 +32,52 @@ public interface Constants { public final static String METADATA = "$metadata"; public final static Integer DEFAULT_PRECISION = 40; - public final static Integer DEFAULT_SCALE = 25; public final static String PROXY_TERM_CLASS_LIST = "org.apache.olingo.ext.proxy.term"; - public final static String PROXY_ENUM_CLASS_LIST = "org.apache.olingo.ext.proxy.enum"; - public final static String PROXY_COMPLEX_CLASS_LIST = "org.apache.olingo.ext.proxy.complex"; // XML namespaces and prefixes public final static String NS_ATOM = "http://www.w3.org/2005/Atom"; - public static final String NS_GEORSS = "http://www.georss.org/georss"; - public static final String NS_GML = "http://www.opengis.net/gml"; - public static final String NS_ATOM_TOMBSTONE = "http://purl.org/atompub/tombstones/1.0"; public static final String PREFIX_DATASERVICES = "d"; - public static final String PREFIX_METADATA = "m"; - public static final String PREFIX_GEORSS = "georss"; - public static final String PREFIX_GML = "gml"; public final static String SRS_URLPREFIX = "http://www.opengis.net/def/crs/EPSG/0/"; // Link rel(s) public static final String EDIT_LINK_REL = "edit"; - public static final String SELF_LINK_REL = "self"; - public static final String EDITMEDIA_LINK_REL = "edit-media"; - public static final String NEXT_LINK_REL = "next"; - public static final String DELTA_LINK_REL = "http://docs.oasis-open.org/odata/ns/delta"; - // XML elements and attributes public static final String PROPERTIES = "properties"; public static final String ELEM_ELEMENT = "element"; public final static String ATTR_TYPE = "type"; - public final static String ATTR_NULL = "null"; public static final String ATTR_XML_BASE = "base"; - public static final QName QNAME_ATTR_XML_BASE = new QName(XMLConstants.XML_NS_URI, ATTR_XML_BASE); public static final String CONTEXT = "context"; public static final String ATTR_REL = "rel"; - public static final String ATTR_TITLE = "title"; - public static final String ATTR_METADATA = "metadata"; - public static final String ATTR_HREF = "href"; - public static final String ATTR_REF = "ref"; - public static final String ATTR_TARGET = "target"; public static final String ATTR_SRSNAME = "srsName"; - public static final QName QNAME_ATTR_SRSNAME = new QName(NS_GML, ATTR_SRSNAME); public static final String ELEM_POINT = "Point"; @@ -107,11 +85,9 @@ public interface Constants { public static final String ELEM_MULTIPOINT = "MultiPoint"; public static final String ELEM_POINTMEMBERS = "pointMembers"; - public static final QName QNAME_POINTMEMBERS = new QName(NS_GML, ELEM_POINTMEMBERS); public static final String ELEM_LINESTRING = "LineString"; - public static final QName QNAME_LINESTRING = new QName(NS_GML, ELEM_LINESTRING); public static final String ELEM_MULTILINESTRING = "MultiCurve"; @@ -119,15 +95,12 @@ public interface Constants { public static final String ELEM_LINESTRINGMEMBERS = "curveMembers"; public static final String ELEM_POLYGON = "Polygon"; - public static final QName QNAME_POLYGON = new QName(NS_GML, ELEM_POLYGON); public static final String ELEM_POLYGON_EXTERIOR = "exterior"; - public static final QName QNAME_POLYGON_EXTERIOR = new QName(NS_GML, ELEM_POLYGON_EXTERIOR); public static final String ELEM_POLYGON_INTERIOR = "interior"; - public static final QName QNAME_POLYGON_INTERIOR = new QName(NS_GML, ELEM_POLYGON_INTERIOR); public static final String ELEM_POLYGON_LINEARRING = "LinearRing"; @@ -139,7 +112,6 @@ public interface Constants { public static final String ELEM_GEOCOLLECTION = "MultiGeometry"; public static final String ELEM_GEOMEMBERS = "geometryMembers"; - public static final QName QNAME_GEOMEMBERS = new QName(NS_GML, ELEM_GEOMEMBERS); public static final String ELEM_POS = "pos"; @@ -155,7 +127,6 @@ public interface Constants { public static final String ELEM_DELETED_LINK = "deleted-link"; public static final String ATTR_SOURCE = "source"; - public static final String ATTR_RELATIONSHIP = "relationship"; public static final String ANNOTATION = "annotation"; @@ -180,6 +151,7 @@ public interface Constants { public final static String JSON_COUNT = "@odata.count"; public final static String JSON_NEXT_LINK = "@odata.nextLink"; public final static String JSON_DELTA_LINK = "@odata.deltaLink"; + public final static String JSON_ERROR = "error"; public final static String JSON_NULL = "odata.null"; @@ -188,56 +160,44 @@ public interface Constants { public final static String JSON_URL = "url"; public final static String JSON_COORDINATES = "coordinates"; - public final static String JSON_GEOMETRIES = "geometries"; - public final static String JSON_CRS = "crs"; public final static String JSON_NAME = "name"; // Atom stuff public final static String ATOM_ELEM_ENTRY = "entry"; + public static final QName QNAME_ATOM_ELEM_ENTRY = new QName(NS_ATOM, ATOM_ELEM_ENTRY); public final static String ATOM_ELEM_ENTRY_REF = "ref"; public final static String ATOM_ATTR_ID = "id"; - public final static QName QNAME_ATOM_ATTR_ID = new QName(ATOM_ATTR_ID); - public static final QName QNAME_ATOM_ELEM_ENTRY = new QName(NS_ATOM, ATOM_ELEM_ENTRY); - public final static String ATOM_ELEM_FEED = "feed"; - public static final QName QNAME_ATOM_ELEM_FEED = new QName(NS_ATOM, ATOM_ELEM_FEED); public final static String ATOM_ELEM_CATEGORY = "category"; - public static final QName QNAME_ATOM_ELEM_CATEGORY = new QName(NS_ATOM, ATOM_ELEM_CATEGORY); public static final String ATOM_ELEM_COUNT = "count"; public final static String ATOM_ELEM_ID = "id"; - public static final QName QNAME_ATOM_ELEM_ID = new QName(NS_ATOM, ATOM_ELEM_ID); public static final String ATOM_ELEM_TITLE = "title"; - public static final QName QNAME_ATOM_ELEM_TITLE = new QName(NS_ATOM, ATOM_ELEM_TITLE); public static final String ATOM_ELEM_SUMMARY = "summary"; - public static final QName QNAME_ATOM_ELEM_SUMMARY = new QName(NS_ATOM, ATOM_ELEM_SUMMARY); public static final String ATOM_ELEM_UPDATED = "updated"; - public static final QName QNAME_ATOM_ELEM_UPDATED = new QName(NS_ATOM, ATOM_ELEM_UPDATED); public final static String ATOM_ELEM_LINK = "link"; - public static final QName QNAME_ATOM_ELEM_LINK = new QName(NS_ATOM, ATOM_ELEM_LINK); public final static String ATOM_ELEM_CONTENT = "content"; - public static final QName QNAME_ATOM_ELEM_CONTENT = new QName(NS_ATOM, ATOM_ELEM_CONTENT); public static final String ATOM_ELEM_ACTION = "action"; @@ -245,33 +205,22 @@ public interface Constants { public static final String ATOM_ELEM_INLINE = "inline"; public static final String ATOM_ATTR_TERM = "term"; - public static final String ATOM_ATTR_SCHEME = "scheme"; - public static final String ATOM_ATTR_SRC = "src"; - public static final String ATOM_ATTR_ETAG = "etag"; - public static final String ATOM_ATTR_METADATAETAG = "metadata-etag"; public static final String ATOM_ELEM_DELETED_ENTRY = "deleted-entry"; // error stuff public static final String ERROR_CODE = "code"; - public static final String ERROR_MESSAGE = "message"; - public static final String ERROR_TARGET = "target"; - public static final String ERROR_DETAILS = "details"; - public static final String ERROR_INNERERROR = "innererror"; // canonical functions to be applied via dynamic annotation Apply public static final String CANONICAL_FUNCTION_CONCAT = "odata.concat"; - public static final String CANONICAL_FUNCTION_FILLURITEMPLATE = "odata.fillUriTemplate"; - public static final String CANONICAL_FUNCTION_URIENCODE = "odata.uriEncode"; - } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLink.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLink.java index 2a009dbeb..c7591b5ba 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLink.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLink.java @@ -123,17 +123,17 @@ public class ODataLink extends ODataItem { switch (this.type) { case ASSOCIATION: - rel = version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL) + title; + rel = version.getNamespace(ODataServiceVersion.NamespaceKey.ASSOCIATION_LINK_REL) + title; break; case ENTITY_NAVIGATION: case ENTITY_SET_NAVIGATION: - rel = version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL) + title; + rel = version.getNamespace(ODataServiceVersion.NamespaceKey.NAVIGATION_LINK_REL) + title; break; case MEDIA_EDIT: default: - rel = version.getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL) + title; + rel = version.getNamespace(ODataServiceVersion.NamespaceKey.MEDIA_EDIT_LINK_REL) + title; break; } } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinkType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinkType.java index f74b718d6..da945e05c 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinkType.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinkType.java @@ -70,7 +70,7 @@ public enum ODataLinkType { */ public static ODataLinkType fromString(final ODataServiceVersion version, final String rel, final String type) { if (StringUtils.isNotBlank(rel) - && rel.startsWith(version.getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL))) { + && rel.startsWith(version.getNamespace(ODataServiceVersion.NamespaceKey.MEDIA_EDIT_LINK_REL))) { return MEDIA_EDIT.setType(StringUtils.isBlank(type) ? "*/*" : type); } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/ODataServiceVersion.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/ODataServiceVersion.java index 862443232..2db4038ee 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/ODataServiceVersion.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/ODataServiceVersion.java @@ -18,7 +18,6 @@ */ package org.apache.olingo.commons.api.edm.constants; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; @@ -36,123 +35,88 @@ public enum ODataServiceVersion { V30("3.0"), V40("4.0"); + public enum NamespaceKey { + DATASERVICES, METADATA, SCHEME, + NAVIGATION_LINK_REL, ASSOCIATION_LINK_REL, MEDIA_EDIT_LINK_REL, DELTA_LINK_REL + } + + private static final Map V30_NAMESPACES = new HashMap() { + private static final long serialVersionUID = 3109256773218160485L; + private static final String BASE = "http://schemas.microsoft.com/ado/2007/08/dataservices"; + { + put(NamespaceKey.DATASERVICES, BASE); + put(NamespaceKey.METADATA, BASE + "/metadata"); + put(NamespaceKey.SCHEME, BASE + "/scheme"); + put(NamespaceKey.NAVIGATION_LINK_REL, BASE + "/related/"); + put(NamespaceKey.ASSOCIATION_LINK_REL, BASE + "/relatedlinks/"); + put(NamespaceKey.MEDIA_EDIT_LINK_REL, BASE + "/edit-media/"); + } + }; + + private static final Map V40_NAMESPACES = new HashMap() { + private static final long serialVersionUID = 3109256773218160485L; + private static final String BASE = "http://docs.oasis-open.org/odata/ns/"; + { + put(NamespaceKey.DATASERVICES, BASE + "data"); + put(NamespaceKey.METADATA, BASE + "metadata"); + put(NamespaceKey.SCHEME, BASE + "scheme"); + put(NamespaceKey.NAVIGATION_LINK_REL, BASE + "related/"); + put(NamespaceKey.ASSOCIATION_LINK_REL, BASE + "relatedlinks/"); + put(NamespaceKey.MEDIA_EDIT_LINK_REL, BASE + "edit-media/"); + put(NamespaceKey.DELTA_LINK_REL, BASE + "delta"); + } + }; + + public enum JsonKey { + TYPE, ID, ETAG, + READ_LINK, EDIT_LINK, MEDIA_READ_LINK, MEDIA_EDIT_LINK, MEDIA_CONTENT_TYPE, MEDIA_ETAG, + ASSOCIATION_LINK, NAVIGATION_LINK, + COUNT, NEXT_LINK, DELTA_LINK, ERROR + } + + private static final Map V30_JSON = new HashMap() { + private static final long serialVersionUID = 3109256773218160485L; + { + put(JsonKey.TYPE, "odata.type"); + put(JsonKey.ID, "odata.id"); + put(JsonKey.ETAG, "odata.etag"); + put(JsonKey.READ_LINK, "odata.readLink"); + put(JsonKey.EDIT_LINK, "odata.editLink"); + put(JsonKey.MEDIA_READ_LINK, "odata.mediaReadLink"); + put(JsonKey.MEDIA_EDIT_LINK, "odata.mediaEditLink"); + put(JsonKey.MEDIA_CONTENT_TYPE, "odata.mediaContentType"); + put(JsonKey.MEDIA_ETAG, "odata.mediaEtag"); + put(JsonKey.ASSOCIATION_LINK, "@odata.associationLinkUrl"); + put(JsonKey.NAVIGATION_LINK, "@odata.navigationLinkUrl"); + put(JsonKey.COUNT, "odata.count"); + put(JsonKey.NEXT_LINK, "odata.nextLink"); + put(JsonKey.ERROR, "odata.error"); + } + }; + + private static final Map V40_JSON = new HashMap() { + private static final long serialVersionUID = 3109256773218160485L; + { + put(JsonKey.TYPE, Constants.JSON_TYPE); + put(JsonKey.ID, Constants.JSON_ID); + put(JsonKey.ETAG, Constants.JSON_ETAG); + put(JsonKey.READ_LINK, Constants.JSON_READ_LINK); + put(JsonKey.EDIT_LINK, Constants.JSON_EDIT_LINK); + put(JsonKey.MEDIA_READ_LINK, Constants.JSON_MEDIA_READ_LINK); + put(JsonKey.MEDIA_EDIT_LINK, Constants.JSON_MEDIA_EDIT_LINK); + put(JsonKey.MEDIA_CONTENT_TYPE, Constants.JSON_MEDIA_CONTENT_TYPE); + put(JsonKey.MEDIA_ETAG, Constants.JSON_MEDIA_ETAG); + put(JsonKey.ASSOCIATION_LINK, Constants.JSON_ASSOCIATION_LINK); + put(JsonKey.NAVIGATION_LINK, Constants.JSON_NAVIGATION_LINK); + put(JsonKey.COUNT, Constants.JSON_COUNT); + put(JsonKey.NEXT_LINK, Constants.JSON_NEXT_LINK); + put(JsonKey.DELTA_LINK, Constants.JSON_DELTA_LINK); + put(JsonKey.ERROR, Constants.JSON_ERROR); + } + }; + private static final Pattern DATASERVICEVERSIONPATTERN = Pattern.compile("(\\p{Digit}+\\.\\p{Digit}+)(:?;.*)?"); - public static final String NS_DATASERVICES = "dataservices"; - - public static final String NS_METADATA = "metadata"; - - public static final String NS_SCHEME = "scheme"; - - public static final String NAVIGATION_LINK_REL = "navigationLinkRel"; - - public static final String ASSOCIATION_LINK_REL = "associationLinkRel"; - - public static final String MEDIA_EDIT_LINK_REL = "mediaEditLinkRel"; - - public static final String JSON_TYPE = "jsonType"; - - public static final String JSON_ID = "jsonId"; - - public static final String JSON_ETAG = "jsonETag"; - - public static final String JSON_READ_LINK = "jsonReadLink"; - - public static final String JSON_EDIT_LINK = "jsonEditLink"; - - public static final String JSON_MEDIAREAD_LINK = "jsonMediaReadLink"; - - public static final String JSON_MEDIAEDIT_LINK = "jsonMediaEditLink"; - - public static final String JSON_MEDIA_CONTENT_TYPE = "jsonMediaContentType"; - - public static final String JSON_MEDIA_ETAG = "jsonMediaETag"; - - public static final String JSON_ASSOCIATION_LINK = "jsonAssociationLink"; - - public static final String JSON_NAVIGATION_LINK = "jsonNavigationLink"; - - public final static String JSON_COUNT = "jsonCount"; - - public final static String JSON_NEXT_LINK = "jsonNextLink"; - - public final static String JSON_DELTA_LINK = "jsonDeltaLink"; - - public static final String JSON_ERROR = "jsonError"; - - private static final Map V30_NAMESPACES = Collections.unmodifiableMap(new HashMap() { - - private static final long serialVersionUID = 3109256773218160485L; - - { - put(NS_DATASERVICES, "http://schemas.microsoft.com/ado/2007/08/dataservices"); - put(NS_METADATA, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"); - put(NS_SCHEME, "http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"); - put(NAVIGATION_LINK_REL, "http://schemas.microsoft.com/ado/2007/08/dataservices/related/"); - put(ASSOCIATION_LINK_REL, "http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/"); - put(MEDIA_EDIT_LINK_REL, "http://schemas.microsoft.com/ado/2007/08/dataservices/edit-media/"); - } - }); - - private static final Map V30_JSON = Collections.unmodifiableMap(new HashMap() { - - private static final long serialVersionUID = 3109256773218160485L; - - { - put(JSON_TYPE, "odata.type"); - put(JSON_ID, "odata.id"); - put(JSON_ETAG, "odata.etag"); - put(JSON_READ_LINK, "odata.readLink"); - put(JSON_EDIT_LINK, "odata.editLink"); - put(JSON_MEDIAREAD_LINK, "odata.mediaReadLink"); - put(JSON_MEDIAEDIT_LINK, "odata.mediaEditLink"); - put(JSON_MEDIA_CONTENT_TYPE, "odata.mediaContentType"); - put(JSON_MEDIA_ETAG, "odata.mediaEtag"); - put(JSON_ASSOCIATION_LINK, "@odata.associationLinkUrl"); - put(JSON_NAVIGATION_LINK, "@odata.navigationLinkUrl"); - put(JSON_COUNT, "odata.count"); - put(JSON_NEXT_LINK, "odata.nextLink"); - put(JSON_ERROR, "odata.error"); - } - }); - - private static final Map V40_NAMESPACES = Collections.unmodifiableMap(new HashMap() { - - private static final long serialVersionUID = 3109256773218160485L; - - { - put(NS_METADATA, "http://docs.oasis-open.org/odata/ns/metadata"); - put(NS_DATASERVICES, "http://docs.oasis-open.org/odata/ns/data"); - put(NS_SCHEME, "http://docs.oasis-open.org/odata/ns/scheme"); - put(NAVIGATION_LINK_REL, "http://docs.oasis-open.org/odata/ns/related/"); - put(ASSOCIATION_LINK_REL, "http://docs.oasis-open.org/odata/ns/relatedlinks/"); - put(MEDIA_EDIT_LINK_REL, "http://docs.oasis-open.org/odata/ns/edit-media/"); - } - }); - - private static final Map V40_JSON = Collections.unmodifiableMap(new HashMap() { - - private static final long serialVersionUID = 3109256773218160485L; - - { - put(JSON_TYPE, Constants.JSON_TYPE); - put(JSON_ID, Constants.JSON_ID); - put(JSON_ETAG, Constants.JSON_ETAG); - put(JSON_READ_LINK, Constants.JSON_READ_LINK); - put(JSON_EDIT_LINK, Constants.JSON_EDIT_LINK); - put(JSON_MEDIAREAD_LINK, Constants.JSON_MEDIA_READ_LINK); - put(JSON_MEDIAEDIT_LINK, Constants.JSON_MEDIA_EDIT_LINK); - put(JSON_MEDIA_CONTENT_TYPE, Constants.JSON_MEDIA_CONTENT_TYPE); - put(JSON_MEDIA_ETAG, Constants.JSON_MEDIA_ETAG); - put(JSON_ASSOCIATION_LINK, Constants.JSON_ASSOCIATION_LINK); - put(JSON_NAVIGATION_LINK, Constants.JSON_NAVIGATION_LINK); - put(JSON_COUNT, Constants.JSON_COUNT); - put(JSON_NEXT_LINK, Constants.JSON_NEXT_LINK); - put(JSON_DELTA_LINK, Constants.JSON_DELTA_LINK); - put(JSON_ERROR, "error"); - } - }); - /** * Validates format and range of a data service version string. * @@ -205,20 +169,12 @@ public enum ODataServiceVersion { this.version = version; } - public Map getNamespaceMap() { - return this == V10 || this == V20 - ? Collections. emptyMap() - : this == V30 - ? V30_NAMESPACES - : V40_NAMESPACES; + public String getNamespace(final NamespaceKey key) { + return this == V10 || this == V20 ? null : this == V30 ? V30_NAMESPACES.get(key) : V40_NAMESPACES.get(key); } - public Map getJSONMap() { - return this == V10 || this == V20 - ? Collections. emptyMap() - : this == V30 - ? V30_JSON - : V40_JSON; + public String getJsonName(final JsonKey key) { + return this == V10 || this == V20 ? null : this == V30 ? V30_JSON.get(key) : V40_JSON.get(key); } @Override 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 95ab24154..13b24363e 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 @@ -30,13 +30,9 @@ import org.apache.olingo.commons.api.edm.EdmTypeDefinition; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class EdmTypeInfo { - private static final Logger LOG = LoggerFactory.getLogger(EdmTypeInfo.class); - public static class Builder { private String typeExpression; @@ -127,8 +123,8 @@ public class EdmTypeInfo { try { primitiveType = EdmPrimitiveTypeKind.valueOf(fullQualifiedName.getName()); - } catch (IllegalArgumentException e) { - LOG.debug("{} does not appear to refer to an Edm primitive type", fullQualifiedName); + } catch (final IllegalArgumentException e) { + primitiveType = null; } if (primitiveType == null && this.edm != null) { typeDefinition = this.edm.getTypeDefinition(fullQualifiedName); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AbstractAtomDealer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AbstractAtomDealer.java index 46bcecd22..e24a596d3 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AbstractAtomDealer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AbstractAtomDealer.java @@ -33,105 +33,71 @@ abstract class AbstractAtomDealer { protected final ODataServiceVersion version; + protected final String namespaceMetadata; + protected final String namespaceData; + protected final QName etagQName; - protected final QName metadataEtagQName; - protected final QName inlineQName; - protected final QName actionQName; - protected final QName propertiesQName; - protected final QName typeQName; - protected final QName nullQName; - protected final QName elementQName; - protected final QName countQName; - protected final QName uriQName; - protected final QName nextQName; - protected final QName annotationQName; - protected final QName contextQName; - protected final QName entryRefQName; - protected final QName propertyValueQName; - protected final QName deletedEntryQName; - protected final QName reasonQName; - protected final QName linkQName; - protected final QName deletedLinkQName; - protected final QName errorCodeQName; - protected final QName errorMessageQName; - protected final QName errorTargetQName; public AbstractAtomDealer(final ODataServiceVersion version) { this.version = version; - etagQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ATTR_ETAG); - metadataEtagQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ATTR_METADATAETAG); - inlineQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_INLINE); - actionQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_ACTION); - propertiesQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES); - typeQName = new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATTR_TYPE); - nullQName = new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATTR_NULL); - elementQName = version.compareTo(ODataServiceVersion.V40) < 0 - ? new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES), Constants.ELEM_ELEMENT) - : new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ELEM_ELEMENT); - countQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_COUNT); - uriQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES), Constants.ELEM_URI); - nextQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES), Constants.NEXT_LINK_REL); - annotationQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ANNOTATION); - contextQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.CONTEXT); - entryRefQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_ENTRY_REF); - propertyValueQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.VALUE); + namespaceMetadata = version.getNamespace(ODataServiceVersion.NamespaceKey.METADATA); + namespaceData = version.getNamespace(ODataServiceVersion.NamespaceKey.DATASERVICES); + + etagQName = new QName(namespaceMetadata, Constants.ATOM_ATTR_ETAG); + metadataEtagQName = new QName(namespaceMetadata, Constants.ATOM_ATTR_METADATAETAG); + inlineQName = new QName(namespaceMetadata, Constants.ATOM_ELEM_INLINE); + actionQName = new QName(namespaceMetadata, Constants.ATOM_ELEM_ACTION); + propertiesQName = new QName(namespaceMetadata, Constants.PROPERTIES); + typeQName = new QName(namespaceMetadata, Constants.ATTR_TYPE); + nullQName = new QName(namespaceMetadata, Constants.ATTR_NULL); + elementQName = new QName(version.compareTo(ODataServiceVersion.V40) < 0 ? namespaceData : namespaceMetadata, + Constants.ELEM_ELEMENT); + countQName = new QName(namespaceMetadata, Constants.ATOM_ELEM_COUNT); + uriQName = new QName(namespaceData, Constants.ELEM_URI); + nextQName = new QName(namespaceData, Constants.NEXT_LINK_REL); + annotationQName = new QName(namespaceMetadata, Constants.ANNOTATION); + contextQName = new QName(namespaceMetadata, Constants.CONTEXT); + entryRefQName = new QName(namespaceMetadata, Constants.ATOM_ELEM_ENTRY_REF); + propertyValueQName = new QName(namespaceMetadata, Constants.VALUE); deletedEntryQName = new QName(Constants.NS_ATOM_TOMBSTONE, Constants.ATOM_ELEM_DELETED_ENTRY); - reasonQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ELEM_REASON); - linkQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_LINK); - deletedLinkQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ELEM_DELETED_LINK); + reasonQName = new QName(namespaceMetadata, Constants.ELEM_REASON); + linkQName = new QName(namespaceMetadata, Constants.ATOM_ELEM_LINK); + deletedLinkQName = new QName(namespaceMetadata, Constants.ELEM_DELETED_LINK); - errorCodeQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ERROR_CODE); - errorMessageQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ERROR_MESSAGE); - errorTargetQName = - new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ERROR_TARGET); + errorCodeQName = new QName(namespaceMetadata, Constants.ERROR_CODE); + errorMessageQName = new QName(namespaceMetadata, Constants.ERROR_MESSAGE); + errorTargetQName = new QName(namespaceMetadata, Constants.ERROR_TARGET); } protected void namespaces(final XMLStreamWriter writer) throws XMLStreamException { writer.writeNamespace(StringUtils.EMPTY, Constants.NS_ATOM); writer.writeNamespace(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI); - writer.writeNamespace(Constants.PREFIX_METADATA, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); - writer.writeNamespace( - Constants.PREFIX_DATASERVICES, version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES)); + writer.writeNamespace(Constants.PREFIX_METADATA, version.getNamespace(ODataServiceVersion.NamespaceKey.METADATA)); + writer.writeNamespace(Constants.PREFIX_DATASERVICES, + version.getNamespace(ODataServiceVersion.NamespaceKey.DATASERVICES)); writer.writeNamespace(Constants.PREFIX_GML, Constants.NS_GML); writer.writeNamespace(Constants.PREFIX_GEORSS, Constants.NS_GEORSS); } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java index 3f38331e0..b29c17e32 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java @@ -54,6 +54,7 @@ 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.constants.ODataServiceVersion; +import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion.NamespaceKey; import org.apache.olingo.commons.api.edm.geo.Geospatial; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataDeserializer; @@ -157,12 +158,12 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria } if (link.getRel().startsWith( - version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL))) { + version.getNamespace(ODataServiceVersion.NamespaceKey.NAVIGATION_LINK_REL))) { ((LinkedComplexValue) value).getNavigationLinks().add(link); inline(reader, event.asStartElement(), link); } else if (link.getRel().startsWith( - version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL))) { + version.getNamespace(ODataServiceVersion.NamespaceKey.ASSOCIATION_LINK_REL))) { ((Valuable) value).asLinkedComplex().getAssociationLinks().add(link); } @@ -468,7 +469,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria delta.setNext(URI.create(href.getValue())); } } - if (Constants.DELTA_LINK_REL.equals(rel.getValue())) { + if (ODataServiceVersion.V40.getNamespace(NamespaceKey.DELTA_LINK_REL).equals(rel.getValue())) { final Attribute href = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_HREF)); if (href != null) { delta.setDeltaLink(URI.create(href.getValue())); @@ -678,16 +679,16 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria entity.setMediaETag(mediaETag.getValue()); } } else if (link.getRel().startsWith( - version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL))) { + version.getNamespace(ODataServiceVersion.NamespaceKey.NAVIGATION_LINK_REL))) { entity.getNavigationLinks().add(link); inline(reader, event.asStartElement(), link); } else if (link.getRel().startsWith( - version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL))) { + version.getNamespace(ODataServiceVersion.NamespaceKey.ASSOCIATION_LINK_REL))) { entity.getAssociationLinks().add(link); } else if (link.getRel().startsWith( - version.getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL))) { + version.getNamespace(ODataServiceVersion.NamespaceKey.MEDIA_EDIT_LINK_REL))) { final Attribute metag = event.asStartElement().getAttributeByName(etagQName); if (metag != null) { @@ -810,7 +811,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria entitySet.setNext(URI.create(href.getValue())); } } - if (Constants.DELTA_LINK_REL.equals(rel.getValue())) { + if (ODataServiceVersion.V40.getNamespace(NamespaceKey.DELTA_LINK_REL).equals(rel.getValue())) { final Attribute href = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_HREF)); if (href != null) { entitySet.setDeltaLink(URI.create(href.getValue())); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java index 8c0818ecd..5772023c5 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java @@ -41,6 +41,7 @@ import org.apache.olingo.commons.api.domain.ODataOperation; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; +import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion.NamespaceKey; import org.apache.olingo.commons.api.edm.geo.Geospatial; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataSerializer; @@ -77,11 +78,9 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize throws XMLStreamException, EdmPrimitiveTypeException { for (Object item : value) { if (version.compareTo(ODataServiceVersion.V40) < 0) { - writer.writeStartElement(Constants.PREFIX_DATASERVICES, Constants.ELEM_ELEMENT, - version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES)); + writer.writeStartElement(Constants.PREFIX_DATASERVICES, Constants.ELEM_ELEMENT, namespaceData); } else { - writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ELEM_ELEMENT, - version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); + writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ELEM_ELEMENT, namespaceMetadata); } value(writer, valueType, kind, item); writer.writeEndElement(); @@ -93,7 +92,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize final ValueType valueType, final EdmPrimitiveTypeKind kind, final Object value) throws XMLStreamException, EdmPrimitiveTypeException { if (value == null) { - writer.writeAttribute(Constants.PREFIX_METADATA, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), + writer.writeAttribute(Constants.PREFIX_METADATA, namespaceMetadata, Constants.ATTR_NULL, Boolean.TRUE.toString()); return; } @@ -133,11 +132,9 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize throws XMLStreamException, EdmPrimitiveTypeException { if (version.compareTo(ODataServiceVersion.V40) >= 0 && standalone) { - writer.writeStartElement(Constants.PREFIX_METADATA, Constants.VALUE, - version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES)); + writer.writeStartElement(Constants.PREFIX_METADATA, Constants.VALUE, namespaceData); } else { - writer.writeStartElement(Constants.PREFIX_DATASERVICES, property.getName(), - version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES)); + writer.writeStartElement(Constants.PREFIX_DATASERVICES, property.getName(), namespaceData); } if (standalone) { @@ -148,8 +145,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize if (StringUtils.isNotBlank(property.getType())) { typeInfo = new EdmTypeInfo.Builder().setTypeExpression(property.getType()).build(); if (!EdmPrimitiveTypeKind.String.getFullQualifiedName().toString().equals(typeInfo.internal())) { - writer.writeAttribute(Constants.PREFIX_METADATA, - version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), + writer.writeAttribute(Constants.PREFIX_METADATA, namespaceMetadata, Constants.ATTR_TYPE, typeInfo.external(version)); } } @@ -213,8 +209,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize } if (link.getInlineEntity() != null || link.getInlineEntitySet() != null) { - writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE, - version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); + writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE, namespaceMetadata); if (link.getInlineEntity() != null) { writer.writeStartElement(Constants.ATOM_ELEM_ENTRY); @@ -257,8 +252,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize private void annotation(final XMLStreamWriter writer, final Annotation annotation, final String target) throws XMLStreamException, EdmPrimitiveTypeException { - writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ANNOTATION, - version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); + writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ANNOTATION, namespaceMetadata); writer.writeAttribute(Constants.ATOM_ATTR_TERM, annotation.getTerm()); @@ -270,8 +264,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize if (StringUtils.isNotBlank(annotation.getType())) { typeInfo = new EdmTypeInfo.Builder().setTypeExpression(annotation.getType()).build(); if (!EdmPrimitiveTypeKind.String.getFullQualifiedName().toString().equals(typeInfo.internal())) { - writer.writeAttribute(Constants.PREFIX_METADATA, - version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), + writer.writeAttribute(Constants.PREFIX_METADATA, namespaceMetadata, Constants.ATTR_TYPE, typeInfo.external(version)); } } @@ -289,9 +282,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize } if (serverMode && StringUtils.isNotBlank(entity.getETag())) { - writer.writeAttribute( - version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), - Constants.ATOM_ATTR_ETAG, entity.getETag()); + writer.writeAttribute(namespaceMetadata, Constants.ATOM_ATTR_ETAG, entity.getETag()); } if (entity.getId() != null) { @@ -301,7 +292,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize } writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY); - writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, version.getNamespaceMap().get(ODataServiceVersion.NS_SCHEME)); + writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, version.getNamespace(ODataServiceVersion.NamespaceKey.SCHEME)); if (StringUtils.isNotBlank(entity.getType())) { writer.writeAttribute(Constants.ATOM_ATTR_TERM, new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version)); @@ -328,8 +319,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize if (serverMode) { for (ODataOperation operation : entity.getOperations()) { - writer.writeStartElement( - version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_ACTION); + writer.writeStartElement(namespaceMetadata, Constants.ATOM_ELEM_ACTION); writer.writeAttribute(Constants.ATTR_METADATA, operation.getMetadataAnchor()); writer.writeAttribute(Constants.ATTR_TITLE, operation.getTitle()); writer.writeAttribute(Constants.ATTR_TARGET, operation.getTarget().toASCIIString()); @@ -347,11 +337,11 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize } writer.writeEndElement(); - writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES); + writer.writeStartElement(namespaceMetadata, Constants.PROPERTIES); properties(writer, entity.getProperties()); } else { writer.writeAttribute(Constants.ATTR_TYPE, ContentType.APPLICATION_XML.toContentTypeString()); - writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES); + writer.writeStartElement(namespaceMetadata, Constants.PROPERTIES); properties(writer, entity.getProperties()); writer.writeEndElement(); } @@ -364,13 +354,13 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize private void entityRef(final XMLStreamWriter writer, final Entity entity) throws XMLStreamException { writer.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF); - writer.writeNamespace(StringUtils.EMPTY, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); + writer.writeNamespace(StringUtils.EMPTY, namespaceMetadata); writer.writeAttribute(Constants.ATOM_ATTR_ID, entity.getId().toASCIIString()); } private void entityRef(final XMLStreamWriter writer, final ResWrap container) throws XMLStreamException { writer.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF); - writer.writeNamespace(StringUtils.EMPTY, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); + writer.writeNamespace(StringUtils.EMPTY, namespaceMetadata); addContextInfo(writer, container); writer.writeAttribute(Constants.ATOM_ATTR_ID, container.getPayload().getId().toASCIIString()); } @@ -381,7 +371,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize if (entity.getType() == null && entity.getProperties().isEmpty()) { writer.writeStartDocument(); - writer.setDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); + writer.setDefaultNamespace(namespaceMetadata); entityRef(writer, entity); } else { @@ -403,7 +393,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize if (entity.getType() == null && entity.getProperties().isEmpty()) { writer.writeStartDocument(); - writer.setDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); + writer.setDefaultNamespace(namespaceMetadata); entityRef(writer, container); } else { @@ -426,8 +416,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize } if (entitySet.getCount() != null) { - writer.writeStartElement( - version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_COUNT); + writer.writeStartElement(namespaceMetadata, Constants.ATOM_ELEM_COUNT); writer.writeCharacters(Integer.toString(entitySet.getCount())); writer.writeEndElement(); } @@ -463,7 +452,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize } if (entitySet.getDeltaLink() != null) { final LinkImpl next = new LinkImpl(); - next.setRel(Constants.DELTA_LINK_REL); + next.setRel(ODataServiceVersion.V40.getNamespace(NamespaceKey.DELTA_LINK_REL)); next.setHref(entitySet.getDeltaLink().toASCIIString()); links(writer, Collections. singletonList(next)); @@ -505,7 +494,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize writer.writeStartDocument(); writer.writeStartElement(Constants.ELEM_LINKS); - writer.writeDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES)); + writer.writeDefaultNamespace(namespaceData); writer.writeStartElement(Constants.ELEM_URI); writer.writeCharacters(link.getHref()); @@ -570,16 +559,12 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize ((EntityImpl) container.getPayload()).setBaseURI(base); } - writer.writeAttribute( - version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), - Constants.CONTEXT, + writer.writeAttribute(namespaceMetadata, Constants.CONTEXT, container.getContextURL().getURI().toASCIIString()); } if (StringUtils.isNotBlank(container.getMetadataETag())) { - writer.writeAttribute( - version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), - Constants.ATOM_ATTR_METADATAETAG, + writer.writeAttribute(namespaceMetadata, Constants.ATOM_ATTR_METADATAETAG, container.getMetadataETag()); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java index e56ae67e3..56c8db8ef 100755 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java @@ -97,21 +97,21 @@ public class JsonDeserializer implements ODataDeserializer { this.version = version; this.serverMode = serverMode; - jsonType = version.getJSONMap().get(ODataServiceVersion.JSON_TYPE); - jsonId = version.getJSONMap().get(ODataServiceVersion.JSON_ID); - jsonETag = version.getJSONMap().get(ODataServiceVersion.JSON_ETAG); - jsonReadLink = version.getJSONMap().get(ODataServiceVersion.JSON_READ_LINK); - jsonEditLink = version.getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK); - jsonMediaReadLink = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK); - jsonMediaEditLink = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK); - jsonMediaContentType = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE); - jsonMediaETag = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIA_ETAG); - jsonAssociationLink = version.getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK); - jsonNavigationLink = version.getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK); - jsonCount = version.getJSONMap().get(ODataServiceVersion.JSON_COUNT); - jsonNextLink = version.getJSONMap().get(ODataServiceVersion.JSON_NEXT_LINK); - jsonDeltaLink = version.getJSONMap().get(ODataServiceVersion.JSON_DELTA_LINK); - jsonError = version.getJSONMap().get(ODataServiceVersion.JSON_ERROR); + jsonType = version.getJsonName(ODataServiceVersion.JsonKey.TYPE); + jsonId = version.getJsonName(ODataServiceVersion.JsonKey.ID); + jsonETag = version.getJsonName(ODataServiceVersion.JsonKey.ETAG); + jsonReadLink = version.getJsonName(ODataServiceVersion.JsonKey.READ_LINK); + jsonEditLink = version.getJsonName(ODataServiceVersion.JsonKey.EDIT_LINK); + jsonMediaReadLink = version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_READ_LINK); + jsonMediaEditLink = version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK); + jsonMediaContentType = version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_CONTENT_TYPE); + jsonMediaETag = version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_ETAG); + jsonAssociationLink = version.getJsonName(ODataServiceVersion.JsonKey.ASSOCIATION_LINK); + jsonNavigationLink = version.getJsonName(ODataServiceVersion.JsonKey.NAVIGATION_LINK); + jsonCount = version.getJsonName(ODataServiceVersion.JsonKey.COUNT); + jsonNextLink = version.getJsonName(ODataServiceVersion.JsonKey.NEXT_LINK); + jsonDeltaLink = version.getJsonName(ODataServiceVersion.JsonKey.DELTA_LINK); + jsonError = version.getJsonName(ODataServiceVersion.JsonKey.ERROR); } private JsonGeoValueDeserializer getGeoDeserializer() { @@ -172,7 +172,7 @@ public class JsonDeserializer implements ODataDeserializer { if (field.getKey().endsWith(jsonNavigationLink)) { final LinkImpl link = new LinkImpl(); link.setTitle(getTitle(field)); - link.setRel(version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL) + getTitle(field)); + link.setRel(version.getNamespace(ODataServiceVersion.NamespaceKey.NAVIGATION_LINK_REL) + getTitle(field)); if (field.getValue().isValueNode()) { link.setHref(field.getValue().textValue()); @@ -186,7 +186,7 @@ public class JsonDeserializer implements ODataDeserializer { } else if (field.getKey().endsWith(jsonAssociationLink)) { final LinkImpl link = new LinkImpl(); link.setTitle(getTitle(field)); - link.setRel(version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL) + getTitle(field)); + link.setRel(version.getNamespace(ODataServiceVersion.NamespaceKey.ASSOCIATION_LINK_REL) + getTitle(field)); link.setHref(field.getValue().textValue()); link.setType(ODataLinkType.ASSOCIATION.toString()); linked.getAssociationLinks().add(link); @@ -206,7 +206,7 @@ public class JsonDeserializer implements ODataDeserializer { final LinkImpl link = new LinkImpl(); link.setTitle(getTitle(field)); - link.setRel(version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL) + getTitle(field)); + link.setRel(version.getNamespace(ODataServiceVersion.NamespaceKey.NAVIGATION_LINK_REL) + getTitle(field)); link.setHref(field.getValue().textValue()); link.setType(ODataLinkType.ENTITY_NAVIGATION.toString()); linked.getNavigationLinks().add(link); @@ -218,7 +218,7 @@ public class JsonDeserializer implements ODataDeserializer { final LinkImpl link = new LinkImpl(); link.setTitle(getTitle(field)); - link.setRel(version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL) + getTitle(field)); + link.setRel(version.getNamespace(ODataServiceVersion.NamespaceKey.NAVIGATION_LINK_REL) + getTitle(field)); link.setHref(node.asText()); link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString()); linked.getNavigationLinks().add(link); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java index 39208a1df..b44bde1fb 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java @@ -155,7 +155,7 @@ public class JsonEntityDeserializer extends JsonDeserializer { if (field.getKey().endsWith(getJSONAnnotation(jsonMediaEditLink))) { final LinkImpl link = new LinkImpl(); link.setTitle(getTitle(field)); - link.setRel(version.getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL) + getTitle(field)); + link.setRel(version.getNamespace(ODataServiceVersion.NamespaceKey.MEDIA_EDIT_LINK_REL) + getTitle(field)); link.setHref(field.getValue().textValue()); link.setType(ODataLinkType.MEDIA_EDIT.toString()); entity.getMediaEditLinks().add(link); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java index 0d411bd94..a8191a256 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java @@ -67,17 +67,17 @@ public class JsonEntitySerializer extends JsonSerializer { } if (StringUtils.isNotBlank(entity.getETag())) { - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ETAG), entity.getETag()); + jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.ETAG), entity.getETag()); } } if (StringUtils.isNotBlank(entity.getType())) { - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_TYPE), + jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.TYPE), new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version)); } if (entity.getId() != null) { - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), entity.getId().toASCIIString()); + jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.ID), entity.getId().toASCIIString()); } for (Annotation annotation : entity.getAnnotations()) { @@ -89,11 +89,11 @@ public class JsonEntitySerializer extends JsonSerializer { } if (serverMode && entity.getEditLink() != null && StringUtils.isNotBlank(entity.getEditLink().getHref())) { - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK), + jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.EDIT_LINK), entity.getEditLink().getHref()); if (entity.isMediaEntity()) { - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK), + jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_READ_LINK), entity.getEditLink().getHref() + "/$value"); } } @@ -102,7 +102,7 @@ public class JsonEntitySerializer extends JsonSerializer { for (Link link : entity.getMediaEditLinks()) { if (link.getTitle() == null) { - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK), link.getHref()); + jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK), link.getHref()); } if (link.getInlineEntity() != null) { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetSerializer.java index e07637ef6..f0e07be6e 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetSerializer.java @@ -65,17 +65,17 @@ public class JsonEntitySetSerializer extends JsonSerializer { } if (entitySet.getId() != null) { - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), entitySet.getId().toASCIIString()); + jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.ID), entitySet.getId().toASCIIString()); } - jgen.writeNumberField(version.getJSONMap().get(ODataServiceVersion.JSON_COUNT), + jgen.writeNumberField(version.getJsonName(ODataServiceVersion.JsonKey.COUNT), entitySet.getCount() == null ? entitySet.getEntities().size() : entitySet.getCount()); if (serverMode) { if (entitySet.getNext() != null) { - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_NEXT_LINK), + jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.NEXT_LINK), entitySet.getNext().toASCIIString()); } if (entitySet.getDeltaLink() != null) { - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_DELTA_LINK), + jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.DELTA_LINK), entitySet.getDeltaLink().toASCIIString()); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java index 9e5841872..a8423090a 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java @@ -60,7 +60,7 @@ public class JsonPropertySerializer extends JsonSerializer { } if (StringUtils.isNotBlank(property.getType())) { - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_TYPE), + jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.TYPE), new EdmTypeInfo.Builder().setTypeExpression(property.getType()).build().external(version)); } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java index 7d60720c9..93bde5deb 100755 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java @@ -192,7 +192,7 @@ public class JsonSerializer implements ODataSerializer { if (StringUtils.isNotBlank(link.getHref())) { jgen.writeStringField( link.getTitle() + StringUtils.prependIfMissing( - version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK), "@"), + version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK), "@"), link.getHref()); } } @@ -201,7 +201,7 @@ public class JsonSerializer implements ODataSerializer { for (Link link : linked.getAssociationLinks()) { if (StringUtils.isNotBlank(link.getHref())) { jgen.writeStringField( - link.getTitle() + version.getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK), + link.getTitle() + version.getJsonName(ODataServiceVersion.JsonKey.ASSOCIATION_LINK), link.getHref()); } } @@ -213,7 +213,7 @@ public class JsonSerializer implements ODataSerializer { if (StringUtils.isNotBlank(link.getHref())) { jgen.writeStringField( - link.getTitle() + version.getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK), + link.getTitle() + version.getJsonName(ODataServiceVersion.JsonKey.NAVIGATION_LINK), link.getHref()); } @@ -292,7 +292,7 @@ public class JsonSerializer implements ODataSerializer { jgen.writeStartObject(); if (typeInfo != null) { - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_TYPE), typeInfo.external(version)); + jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.TYPE), typeInfo.external(version)); } for (Property property : value) { @@ -337,7 +337,7 @@ public class JsonSerializer implements ODataSerializer { } if (StringUtils.isNotBlank(type)) { jgen.writeFieldName( - name + StringUtils.prependIfMissing(version.getJSONMap().get(ODataServiceVersion.JSON_TYPE), "@")); + name + StringUtils.prependIfMissing(version.getJsonName(ODataServiceVersion.JsonKey.TYPE), "@")); jgen.writeString(new EdmTypeInfo.Builder().setTypeExpression(type).build().external(version)); } } diff --git a/pom.xml b/pom.xml index 1597e80c1..a934d941d 100644 --- a/pom.xml +++ b/pom.xml @@ -217,11 +217,6 @@ cxf-rt-rs-security-oauth2 ${cxf.version} - - org.apache.cxf - cxf-rt-rs-extension-providers - ${cxf.version} - org.springframework spring-web @@ -322,7 +317,7 @@ org.apache.maven.plugins maven-resources-plugin 2.6 - + org.sonatype.plugins jarjar-maven-plugin @@ -408,9 +403,6 @@ true alphabetical - UTF-8 - UTF-8 - UTF-8 -Dfile.encoding=UTF-8 @@ -421,8 +413,6 @@ true alphabetical UTF-8 - UTF-8 - UTF-8 -Dfile.encoding=UTF-8