You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/06/13 12:58:37 UTC
[17/21] [OLINGO-317] Rename and move of some packages and classes
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomGeoValueSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomGeoValueSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomGeoValueSerializer.java
deleted file mode 100644
index 7b83e8a..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomGeoValueSerializer.java
+++ /dev/null
@@ -1,221 +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.commons.core.data;
-
-import java.util.Collections;
-import java.util.Iterator;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.geo.Geospatial;
-import org.apache.olingo.commons.api.edm.geo.GeospatialCollection;
-import org.apache.olingo.commons.api.edm.geo.LineString;
-import org.apache.olingo.commons.api.edm.geo.MultiLineString;
-import org.apache.olingo.commons.api.edm.geo.MultiPoint;
-import org.apache.olingo.commons.api.edm.geo.MultiPolygon;
-import org.apache.olingo.commons.api.edm.geo.Point;
-import org.apache.olingo.commons.api.edm.geo.Polygon;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
-
-class AtomGeoValueSerializer {
-
- private void points(final XMLStreamWriter writer, final Iterator<Point> itor, final boolean wrap)
- throws XMLStreamException {
-
- while (itor.hasNext()) {
- final Point point = itor.next();
-
- if (wrap) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POINT, Constants.NS_GML);
- }
-
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POS, Constants.NS_GML);
- try {
- writer.writeCharacters(EdmDouble.getInstance().valueToString(point.getX(), null, null,
- Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)
- + " "
- + EdmDouble.getInstance().valueToString(point.getY(), null, null,
- Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null));
- } catch (EdmPrimitiveTypeException e) {
- throw new XMLStreamException("While serializing point coordinates as double", e);
- }
- writer.writeEndElement();
-
- if (wrap) {
- writer.writeEndElement();
- }
- }
- }
-
- private void lineStrings(final XMLStreamWriter writer, final Iterator<LineString> itor, final boolean wrap)
- throws XMLStreamException {
-
- while (itor.hasNext()) {
- final LineString lineString = itor.next();
-
- if (wrap) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_LINESTRING, Constants.NS_GML);
- }
-
- points(writer, lineString.iterator(), false);
-
- if (wrap) {
- writer.writeEndElement();
- }
- }
- }
-
- private void polygons(final XMLStreamWriter writer, final Iterator<Polygon> itor, final boolean wrap)
- throws XMLStreamException {
-
- while (itor.hasNext()) {
- final Polygon polygon = itor.next();
-
- if (wrap) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON, Constants.NS_GML);
- }
-
- if (!polygon.getExterior().isEmpty()) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_EXTERIOR, Constants.NS_GML);
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_LINEARRING, Constants.NS_GML);
-
- points(writer, polygon.getExterior().iterator(), false);
-
- writer.writeEndElement();
- writer.writeEndElement();
- }
- if (!polygon.getInterior().isEmpty()) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_INTERIOR, Constants.NS_GML);
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_LINEARRING, Constants.NS_GML);
-
- points(writer, polygon.getInterior().iterator(), false);
-
- writer.writeEndElement();
- writer.writeEndElement();
- }
-
- if (wrap) {
- writer.writeEndElement();
- }
- }
- }
-
- private void writeSrsName(final XMLStreamWriter writer, final Geospatial value) throws XMLStreamException {
- if (value.getSrid() != null && value.getSrid().isNotDefault()) {
- writer.writeAttribute(Constants.PREFIX_GML, Constants.NS_GML, Constants.ATTR_SRSNAME,
- Constants.SRS_URLPREFIX + value.getSrid().toString());
- }
- }
-
- public void serialize(final XMLStreamWriter writer, final Geospatial value) throws XMLStreamException {
- switch (value.getEdmPrimitiveTypeKind()) {
- case GeographyPoint:
- case GeometryPoint:
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POINT, Constants.NS_GML);
- writeSrsName(writer, value);
-
- points(writer, Collections.singleton((Point) value).iterator(), false);
-
- writer.writeEndElement();
- break;
-
- case GeometryMultiPoint:
- case GeographyMultiPoint:
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_MULTIPOINT, Constants.NS_GML);
- writeSrsName(writer, value);
-
- if (!((MultiPoint) value).isEmpty()) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POINTMEMBERS, Constants.NS_GML);
- points(writer, ((MultiPoint) value).iterator(), true);
- writer.writeEndElement();
- }
-
- writer.writeEndElement();
- break;
-
- case GeometryLineString:
- case GeographyLineString:
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_LINESTRING, Constants.NS_GML);
- writeSrsName(writer, value);
-
- lineStrings(writer, Collections.singleton((LineString) value).iterator(), false);
-
- writer.writeEndElement();
- break;
-
- case GeometryMultiLineString:
- case GeographyMultiLineString:
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_MULTILINESTRING, Constants.NS_GML);
- writeSrsName(writer, value);
-
- if (!((MultiLineString) value).isEmpty()) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_LINESTRINGMEMBERS, Constants.NS_GML);
- lineStrings(writer, ((MultiLineString) value).iterator(), true);
- writer.writeEndElement();
- }
-
- writer.writeEndElement();
- break;
-
- case GeographyPolygon:
- case GeometryPolygon:
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON, Constants.NS_GML);
- writeSrsName(writer, value);
-
- polygons(writer, Collections.singleton(((Polygon) value)).iterator(), false);
-
- writer.writeEndElement();
- break;
-
- case GeographyMultiPolygon:
- case GeometryMultiPolygon:
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_MULTIPOLYGON, Constants.NS_GML);
- writeSrsName(writer, value);
-
- if (!((MultiPolygon) value).isEmpty()) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_SURFACEMEMBERS, Constants.NS_GML);
- polygons(writer, ((MultiPolygon) value).iterator(), true);
- writer.writeEndElement();
- }
-
- writer.writeEndElement();
- break;
-
- case GeographyCollection:
- case GeometryCollection:
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_GEOCOLLECTION, Constants.NS_GML);
- writeSrsName(writer, value);
-
- if (!((GeospatialCollection) value).isEmpty()) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_GEOMEMBERS, Constants.NS_GML);
- for (final Iterator<Geospatial> itor = ((GeospatialCollection) value).iterator(); itor.hasNext();) {
- serialize(writer, itor.next());
- }
- writer.writeEndElement();
- }
-
- writer.writeEndElement();
- break;
-
- default:
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java
deleted file mode 100644
index 3d4eae6..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java
+++ /dev/null
@@ -1,540 +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.commons.core.data;
-
-import java.io.Writer;
-import java.util.Collections;
-import java.util.List;
-
-import javax.xml.XMLConstants;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.Annotation;
-import org.apache.olingo.commons.api.data.CollectionValue;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.Link;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.data.Value;
-import org.apache.olingo.commons.api.domain.ODataOperation;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.api.format.ContentType;
-import org.apache.olingo.commons.api.op.ODataSerializer;
-import org.apache.olingo.commons.api.op.ODataSerializerException;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-
-import com.fasterxml.aalto.stax.OutputFactoryImpl;
-
-public class AtomSerializer extends AbstractAtomDealer implements ODataSerializer {
-
- private static final XMLOutputFactory FACTORY = new OutputFactoryImpl();
-
- private final AtomGeoValueSerializer geoSerializer;
-
- private final boolean serverMode;
-
- public AtomSerializer(final ODataServiceVersion version) {
- this(version, false);
- }
-
- public AtomSerializer(final ODataServiceVersion version, final boolean serverMode) {
- super(version);
- this.geoSerializer = new AtomGeoValueSerializer();
- this.serverMode = serverMode;
- }
-
- private void collection(final XMLStreamWriter writer, final CollectionValue value) throws XMLStreamException {
- for (Value item : value.get()) {
- if (version.compareTo(ODataServiceVersion.V40) < 0) {
- writer.writeStartElement(Constants.PREFIX_DATASERVICES, Constants.ELEM_ELEMENT,
- version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
- } else {
- writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ELEM_ELEMENT,
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
- }
- value(writer, item);
- writer.writeEndElement();
- }
- }
-
- private void value(final XMLStreamWriter writer, final Value value) throws XMLStreamException {
- if (value.isPrimitive()) {
- writer.writeCharacters(value.asPrimitive().get());
- } else if (value.isEnum()) {
- writer.writeCharacters(value.asEnum().get());
- } else if (value.isGeospatial()) {
- this.geoSerializer.serialize(writer, value.asGeospatial().get());
- } else if (value.isCollection()) {
- collection(writer, value.asCollection());
- } else if (value.isComplex()) {
- for (Property property : value.asComplex().get()) {
- property(writer, property, false);
- }
- }
- }
-
- public void property(final XMLStreamWriter writer, final Property property, final boolean standalone)
- throws XMLStreamException {
-
- if (version.compareTo(ODataServiceVersion.V40) >= 0 && standalone) {
- writer.writeStartElement(Constants.PREFIX_METADATA, Constants.VALUE,
- version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
- } else {
- writer.writeStartElement(Constants.PREFIX_DATASERVICES, property.getName(),
- version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
- }
-
- if (standalone) {
- namespaces(writer);
- }
-
- if (StringUtils.isNotBlank(property.getType())) {
- final EdmTypeInfo 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),
- Constants.ATTR_TYPE, typeInfo.external(version));
- }
- }
-
- if (property.getValue().isNull()) {
- writer.writeAttribute(Constants.PREFIX_METADATA, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
- Constants.ATTR_NULL, Boolean.TRUE.toString());
- } else {
- value(writer, property.getValue());
- if (property.getValue().isLinkedComplex()) {
- links(writer, property.getValue().asLinkedComplex().getAssociationLinks());
- links(writer, property.getValue().asLinkedComplex().getNavigationLinks());
- }
- }
-
- writer.writeEndElement();
-
- for (Annotation annotation : property.getAnnotations()) {
- annotation(writer, annotation, property.getName());
- }
- }
-
- private void property(final XMLStreamWriter writer, final Property property) throws XMLStreamException {
- property(writer, property, true);
- }
-
- private void startDocument(final XMLStreamWriter writer, final String rootElement) throws XMLStreamException {
- writer.writeStartDocument();
- writer.setDefaultNamespace(Constants.NS_ATOM);
-
- writer.writeStartElement(rootElement);
-
- namespaces(writer);
- }
-
- private void property(final Writer outWriter, final Property property) throws XMLStreamException {
- final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
-
- writer.writeStartDocument();
-
- property(writer, property);
-
- writer.writeEndDocument();
- writer.flush();
- }
-
- private void links(final XMLStreamWriter writer, final List<Link> links) throws XMLStreamException {
- for (Link link : links) {
- writer.writeStartElement(Constants.ATOM_ELEM_LINK);
-
- if (StringUtils.isNotBlank(link.getRel())) {
- writer.writeAttribute(Constants.ATTR_REL, link.getRel());
- }
- if (StringUtils.isNotBlank(link.getTitle())) {
- writer.writeAttribute(Constants.ATTR_TITLE, link.getTitle());
- }
- if (StringUtils.isNotBlank(link.getHref())) {
- writer.writeAttribute(Constants.ATTR_HREF, link.getHref());
- }
- if (StringUtils.isNotBlank(link.getType())) {
- writer.writeAttribute(Constants.ATTR_TYPE, link.getType());
- }
-
- if (link.getInlineEntity() != null || link.getInlineEntitySet() != null) {
- writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE,
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
-
- if (link.getInlineEntity() != null) {
- writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
- entity(writer, link.getInlineEntity());
- writer.writeEndElement();
- }
- if (link.getInlineEntitySet() != null) {
- writer.writeStartElement(Constants.ATOM_ELEM_FEED);
- entitySet(writer, link.getInlineEntitySet());
- writer.writeEndElement();
- }
-
- writer.writeEndElement();
- }
-
- for (Annotation annotation : link.getAnnotations()) {
- annotation(writer, annotation, null);
- }
-
- writer.writeEndElement();
- }
- }
-
- private void common(final XMLStreamWriter writer, final AbstractODataObject object) throws XMLStreamException {
- if (StringUtils.isNotBlank(object.getTitle())) {
- writer.writeStartElement(Constants.ATOM_ELEM_TITLE);
- writer.writeAttribute(Constants.ATTR_TYPE, TYPE_TEXT);
- writer.writeCharacters(object.getTitle());
- writer.writeEndElement();
- }
- }
-
- private void properties(final XMLStreamWriter writer, final List<Property> properties) throws XMLStreamException {
- for (Property property : properties) {
- property(writer, property, false);
- }
- }
-
- private void annotation(final XMLStreamWriter writer, final Annotation annotation, final String target)
- throws XMLStreamException {
-
- writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ANNOTATION,
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
-
- writer.writeAttribute(Constants.ATOM_ATTR_TERM, annotation.getTerm());
-
- if (target != null) {
- writer.writeAttribute(Constants.ATTR_TARGET, target);
- }
-
- if (StringUtils.isNotBlank(annotation.getType())) {
- final EdmTypeInfo 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),
- Constants.ATTR_TYPE, typeInfo.external(version));
- }
- }
-
- if (annotation.getValue().isNull()) {
- writer.writeAttribute(Constants.PREFIX_METADATA, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
- Constants.ATTR_NULL, Boolean.TRUE.toString());
- } else {
- value(writer, annotation.getValue());
- }
-
- writer.writeEndElement();
- }
-
- private void entity(final XMLStreamWriter writer, final Entity entity) throws XMLStreamException {
- if (entity.getBaseURI() != null) {
- writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, entity.getBaseURI().toASCIIString());
- }
-
- if (serverMode && StringUtils.isNotBlank(entity.getETag())) {
- writer.writeAttribute(
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
- Constants.ATOM_ATTR_ETAG, entity.getETag());
- }
-
- if (entity.getId() != null) {
- writer.writeStartElement(Constants.ATOM_ELEM_ID);
- writer.writeCharacters(entity.getId().toASCIIString());
- writer.writeEndElement();
- }
-
- writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY);
- writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, version.getNamespaceMap().get(ODataServiceVersion.NS_SCHEME));
- if (StringUtils.isNotBlank(entity.getType())) {
- writer.writeAttribute(Constants.ATOM_ATTR_TERM,
- new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version));
- }
- writer.writeEndElement();
-
- if (entity instanceof AbstractODataObject) {
- common(writer, (AbstractODataObject) entity);
- }
-
- if (serverMode) {
- if (entity.getEditLink() != null) {
- links(writer, Collections.singletonList(entity.getEditLink()));
- }
-
- if (entity.getSelfLink() != null) {
- links(writer, Collections.singletonList(entity.getSelfLink()));
- }
- }
-
- links(writer, entity.getAssociationLinks());
- links(writer, entity.getNavigationLinks());
- links(writer, entity.getMediaEditLinks());
-
- if (serverMode) {
- for (ODataOperation operation : entity.getOperations()) {
- writer.writeStartElement(
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), 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());
- writer.writeEndElement();
- }
- }
-
- writer.writeStartElement(Constants.ATOM_ELEM_CONTENT);
- if (entity.isMediaEntity()) {
- if (StringUtils.isNotBlank(entity.getMediaContentType())) {
- writer.writeAttribute(Constants.ATTR_TYPE, entity.getMediaContentType());
- }
- if (entity.getMediaContentSource() != null) {
- writer.writeAttribute(Constants.ATOM_ATTR_SRC, entity.getMediaContentSource().toASCIIString());
- }
- writer.writeEndElement();
-
- writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES);
- properties(writer, entity.getProperties());
- } else {
- writer.writeAttribute(Constants.ATTR_TYPE, ContentType.APPLICATION_XML);
- writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES);
- properties(writer, entity.getProperties());
- writer.writeEndElement();
- }
- writer.writeEndElement();
-
- for (Annotation annotation : entity.getAnnotations()) {
- annotation(writer, annotation, null);
- }
- }
-
- 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.writeAttribute(Constants.ATOM_ATTR_ID, entity.getId().toASCIIString());
- }
-
- private void entityRef(final XMLStreamWriter writer, final ResWrap<Entity> container) throws XMLStreamException {
- writer.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF);
- writer.writeNamespace(StringUtils.EMPTY, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
- addContextInfo(writer, container);
- writer.writeAttribute(Constants.ATOM_ATTR_ID, container.getPayload().getId().toASCIIString());
- }
-
- private void entity(final Writer outWriter, final Entity entity) throws XMLStreamException {
- final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
-
- if (entity.getType() == null && entity.getProperties().isEmpty()) {
- writer.writeStartDocument();
- writer.setDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
-
- entityRef(writer, entity);
- } else {
- startDocument(writer, Constants.ATOM_ELEM_ENTRY);
-
- entity(writer, entity);
- }
-
- writer.writeEndElement();
- writer.writeEndDocument();
- writer.flush();
- }
-
- private void entity(final Writer outWriter, final ResWrap<Entity> container) throws XMLStreamException {
- final Entity entity = container.getPayload();
-
- final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
-
- if (entity.getType() == null && entity.getProperties().isEmpty()) {
- writer.writeStartDocument();
- writer.setDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
-
- entityRef(writer, container);
- } else {
- startDocument(writer, Constants.ATOM_ELEM_ENTRY);
-
- addContextInfo(writer, container);
-
- entity(writer, entity);
- }
-
- writer.writeEndElement();
- writer.writeEndDocument();
- writer.flush();
- }
-
- private void entitySet(final XMLStreamWriter writer, final EntitySet entitySet) throws XMLStreamException {
- if (entitySet.getBaseURI() != null) {
- writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, entitySet.getBaseURI().toASCIIString());
- }
-
- if (entitySet.getCount() != null) {
- writer.writeStartElement(
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_COUNT);
- writer.writeCharacters(Integer.toString(entitySet.getCount()));
- writer.writeEndElement();
- }
-
- if (entitySet.getId() != null) {
- writer.writeStartElement(Constants.ATOM_ELEM_ID);
- writer.writeCharacters(entitySet.getId().toASCIIString());
- writer.writeEndElement();
- }
-
- if (entitySet instanceof AbstractODataObject) {
- common(writer, (AbstractODataObject) entitySet);
- }
-
- for (Entity entity : entitySet.getEntities()) {
- if (entity.getType() == null && entity.getProperties().isEmpty()) {
- entityRef(writer, entity);
- writer.writeEndElement();
- } else {
- writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
- entity(writer, entity);
- writer.writeEndElement();
- }
- }
-
- if (serverMode) {
- if (entitySet.getNext() != null) {
- final LinkImpl next = new LinkImpl();
- next.setRel(Constants.NEXT_LINK_REL);
- next.setHref(entitySet.getNext().toASCIIString());
-
- links(writer, Collections.<Link> singletonList(next));
- }
- if (entitySet.getDeltaLink() != null) {
- final LinkImpl next = new LinkImpl();
- next.setRel(Constants.DELTA_LINK_REL);
- next.setHref(entitySet.getDeltaLink().toASCIIString());
-
- links(writer, Collections.<Link> singletonList(next));
- }
- }
- }
-
- private void entitySet(final Writer outWriter, final EntitySet entitySet) throws XMLStreamException {
- final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
-
- startDocument(writer, Constants.ATOM_ELEM_FEED);
-
- entitySet(writer, entitySet);
-
- writer.writeEndElement();
- writer.writeEndDocument();
- writer.flush();
- }
-
- private void entitySet(final Writer outWriter, final ResWrap<EntitySet> entitySet) throws XMLStreamException {
- final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
-
- startDocument(writer, Constants.ATOM_ELEM_FEED);
-
- addContextInfo(writer, entitySet);
-
- entitySet(writer, entitySet.getPayload());
-
- writer.writeEndElement();
- writer.writeEndDocument();
- writer.flush();
- }
-
- private void link(final Writer outWriter, final Link link) throws XMLStreamException {
- final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
-
- writer.writeStartDocument();
-
- writer.writeStartElement(Constants.ELEM_LINKS);
- writer.writeDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
-
- writer.writeStartElement(Constants.ELEM_URI);
- writer.writeCharacters(link.getHref());
- writer.writeEndElement();
-
- writer.writeEndElement();
-
- writer.writeEndDocument();
- writer.flush();
- }
-
- public <T> void write(final Writer writer, final T obj) throws ODataSerializerException {
- try {
- if (obj instanceof EntitySet) {
- entitySet(writer, (EntitySet) obj);
- } else if (obj instanceof Entity) {
- entity(writer, (Entity) obj);
- } else if (obj instanceof Property) {
- property(writer, (Property) obj);
- } else if (obj instanceof Link) {
- link(writer, (Link) obj);
- }
- } catch (final XMLStreamException e) {
- throw new ODataSerializerException(e);
- }
- }
-
- @SuppressWarnings("unchecked")
- public <T> void write(final Writer writer, final ResWrap<T> container) throws ODataSerializerException {
- final T obj = container == null ? null : container.getPayload();
-
- try {
- if (obj instanceof EntitySet) {
- this.entitySet(writer, (ResWrap<EntitySet>) container);
- } else if (obj instanceof Entity) {
- entity(writer, (ResWrap<Entity>) container);
- } else if (obj instanceof Property) {
- property(writer, (Property) obj);
- } else if (obj instanceof Link) {
- link(writer, (Link) obj);
- }
- } catch (final XMLStreamException e) {
- throw new ODataSerializerException(e);
- }
- }
-
- private <T> void addContextInfo(
- final XMLStreamWriter writer, final ResWrap<T> container) throws XMLStreamException {
-
- if (container.getContextURL() != null) {
- String base = container.getContextURL().getServiceRoot().toASCIIString();
- if (container.getPayload() instanceof EntitySet) {
- ((EntitySetImpl) container.getPayload()).setBaseURI(base);
- }
- if (container.getPayload() instanceof Entity) {
- ((EntityImpl) container.getPayload()).setBaseURI(base);
- }
-
- writer.writeAttribute(
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
- Constants.CONTEXT,
- container.getContextURL().getURI().toASCIIString());
- }
-
- if (StringUtils.isNotBlank(container.getMetadataETag())) {
- writer.writeAttribute(
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
- Constants.ATOM_ATTR_METADATAETAG,
- container.getMetadataETag());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaDeserializer.java
deleted file mode 100644
index 9ca82f1..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaDeserializer.java
+++ /dev/null
@@ -1,100 +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.commons.core.data;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.Iterator;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.ContextURL;
-import org.apache.olingo.commons.api.data.Delta;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.api.op.ODataDeserializerException;
-import org.apache.olingo.commons.core.data.v4.DeltaImpl;
-
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-public class JSONDeltaDeserializer extends JsonDeserializer {
-
- public JSONDeltaDeserializer(final ODataServiceVersion version, final boolean serverMode) {
- super(version, serverMode);
- }
-
- protected ResWrap<Delta> doDeserialize(final JsonParser parser) throws IOException {
-
- final ObjectNode tree = parser.getCodec().readTree(parser);
-
- final DeltaImpl delta = new DeltaImpl();
-
- final URI contextURL = tree.hasNonNull(Constants.JSON_CONTEXT) ?
- URI.create(tree.get(Constants.JSON_CONTEXT).textValue()) : null;
- if (contextURL != null) {
- delta.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA));
- }
-
- if (tree.hasNonNull(jsonCount)) {
- delta.setCount(tree.get(jsonCount).asInt());
- }
- if (tree.hasNonNull(jsonNextLink)) {
- delta.setNext(URI.create(tree.get(jsonNextLink).textValue()));
- }
- if (tree.hasNonNull(jsonDeltaLink)) {
- delta.setDeltaLink(URI.create(tree.get(jsonDeltaLink).textValue()));
- }
-
- if (tree.hasNonNull(Constants.VALUE)) {
- JSONEntityDeserializer entityDeserializer = new JSONEntityDeserializer(version, serverMode);
- for (final Iterator<JsonNode> itor = tree.get(Constants.VALUE).iterator(); itor.hasNext();) {
- final ObjectNode item = (ObjectNode) itor.next();
- final ContextURL itemContextURL = item.hasNonNull(Constants.JSON_CONTEXT)
- ? ContextURL.getInstance(URI.create(item.get(Constants.JSON_CONTEXT).textValue())) : null;
- item.remove(Constants.JSON_CONTEXT);
-
- if (itemContextURL == null || itemContextURL.isEntity()) {
- delta.getEntities().add(entityDeserializer.doDeserialize(item.traverse(parser.getCodec())).getPayload());
- } else if (itemContextURL.isDeltaDeletedEntity()) {
- delta.getDeletedEntities().add(parser.getCodec().treeToValue(item, DeletedEntityImpl.class));
- } else if (itemContextURL.isDeltaLink()) {
- delta.getAddedLinks().add(parser.getCodec().treeToValue(item, DeltaLinkImpl.class));
- } else if (itemContextURL.isDeltaDeletedLink()) {
- delta.getDeletedLinks().add(parser.getCodec().treeToValue(item, DeltaLinkImpl.class));
- }
- }
- }
-
- return new ResWrap<Delta>(contextURL, null, delta);
- }
-
- public ResWrap<Delta> toDelta(InputStream input) throws ODataDeserializerException {
- try {
- JsonParser parser = new JsonFactory(new ObjectMapper()).createParser(input);
- return doDeserialize(parser);
- } catch (final IOException e) {
- throw new ODataDeserializerException(e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityDeserializer.java
deleted file mode 100644
index 00f0d3f..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityDeserializer.java
+++ /dev/null
@@ -1,220 +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.commons.core.data;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.Annotation;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.Link;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.domain.ODataLinkType;
-import org.apache.olingo.commons.api.domain.ODataOperation;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-/**
- * Reads JSON string into an entity.
- * <br/>
- * If metadata information is available, the corresponding entity fields and content will be populated.
- */
-public class JSONEntityDeserializer extends JsonDeserializer {
-
- public JSONEntityDeserializer(final ODataServiceVersion version, final boolean serverMode) {
- super(version, serverMode);
- }
-
- protected ResWrap<Entity> doDeserialize(final JsonParser parser) throws IOException {
-
- final ObjectNode tree = parser.getCodec().readTree(parser);
-
- if (tree.has(Constants.VALUE) && tree.get(Constants.VALUE).isArray()) {
- throw new JsonParseException("Expected OData Entity, found EntitySet", parser.getCurrentLocation());
- }
-
- final EntityImpl entity = new EntityImpl();
-
- final URI contextURL;
- if (tree.hasNonNull(Constants.JSON_CONTEXT)) {
- contextURL = URI.create(tree.get(Constants.JSON_CONTEXT).textValue());
- tree.remove(Constants.JSON_CONTEXT);
- } else if (tree.hasNonNull(Constants.JSON_METADATA)) {
- contextURL = URI.create(tree.get(Constants.JSON_METADATA).textValue());
- tree.remove(Constants.JSON_METADATA);
- } else {
- contextURL = null;
- }
- if (contextURL != null) {
- entity.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA));
- }
-
- final String metadataETag;
- if (tree.hasNonNull(Constants.JSON_METADATA_ETAG)) {
- metadataETag = tree.get(Constants.JSON_METADATA_ETAG).textValue();
- tree.remove(Constants.JSON_METADATA_ETAG);
- } else {
- metadataETag = null;
- }
-
- if (tree.hasNonNull(jsonETag)) {
- entity.setETag(tree.get(jsonETag).textValue());
- tree.remove(jsonETag);
- }
-
- if (tree.hasNonNull(jsonType)) {
- entity.setType(new EdmTypeInfo.Builder().setTypeExpression(tree.get(jsonType).textValue()).build().internal());
- tree.remove(jsonType);
- }
-
- if (tree.hasNonNull(jsonId)) {
- entity.setId(URI.create(tree.get(jsonId).textValue()));
- tree.remove(jsonId);
- }
-
- if (tree.hasNonNull(jsonReadLink)) {
- final LinkImpl link = new LinkImpl();
- link.setRel(Constants.SELF_LINK_REL);
- link.setHref(tree.get(jsonReadLink).textValue());
- entity.setSelfLink(link);
-
- tree.remove(jsonReadLink);
- }
-
- if (tree.hasNonNull(jsonEditLink)) {
- final LinkImpl link = new LinkImpl();
- if (serverMode) {
- link.setRel(Constants.EDIT_LINK_REL);
- }
- link.setHref(tree.get(jsonEditLink).textValue());
- entity.setEditLink(link);
-
- tree.remove(jsonEditLink);
- }
-
- if (tree.hasNonNull(jsonMediaReadLink)) {
- entity.setMediaContentSource(URI.create(tree.get(jsonMediaReadLink).textValue()));
- tree.remove(jsonMediaReadLink);
- }
- if (tree.hasNonNull(jsonMediaEditLink)) {
- entity.setMediaContentSource(URI.create(tree.get(jsonMediaEditLink).textValue()));
- tree.remove(jsonMediaEditLink);
- }
- if (tree.hasNonNull(jsonMediaContentType)) {
- entity.setMediaContentType(tree.get(jsonMediaContentType).textValue());
- tree.remove(jsonMediaContentType);
- }
- if (tree.hasNonNull(jsonMediaETag)) {
- entity.setMediaETag(tree.get(jsonMediaETag).textValue());
- tree.remove(jsonMediaETag);
- }
-
- final Set<String> toRemove = new HashSet<String>();
-
- final Map<String, List<Annotation>> annotations = new HashMap<String, List<Annotation>>();
- for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); itor.hasNext();) {
- final Map.Entry<String, JsonNode> field = itor.next();
- final Matcher customAnnotation = CUSTOM_ANNOTATION.matcher(field.getKey());
-
- links(field, entity, toRemove, tree, parser.getCodec());
- 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.setHref(field.getValue().textValue());
- link.setType(ODataLinkType.MEDIA_EDIT.toString());
- entity.getMediaEditLinks().add(link);
-
- if (tree.has(link.getTitle() + getJSONAnnotation(jsonMediaETag))) {
- link.setMediaETag(tree.get(link.getTitle() + getJSONAnnotation(jsonMediaETag)).asText());
- toRemove.add(link.getTitle() + getJSONAnnotation(jsonMediaETag));
- }
-
- toRemove.add(field.getKey());
- toRemove.add(setInline(field.getKey(), getJSONAnnotation(jsonMediaEditLink), tree, parser.getCodec(), link));
- } else if (field.getKey().endsWith(getJSONAnnotation(jsonMediaContentType))) {
- final String linkTitle = getTitle(field);
- for (Link link : entity.getMediaEditLinks()) {
- if (linkTitle.equals(link.getTitle())) {
- ((LinkImpl) link).setType(field.getValue().asText());
- }
- }
- toRemove.add(field.getKey());
- } else if (field.getKey().charAt(0) == '#') {
- final ODataOperation operation = new ODataOperation();
- operation.setMetadataAnchor(field.getKey());
-
- final ObjectNode opNode = (ObjectNode) tree.get(field.getKey());
- operation.setTitle(opNode.get(Constants.ATTR_TITLE).asText());
- operation.setTarget(URI.create(opNode.get(Constants.ATTR_TARGET).asText()));
-
- entity.getOperations().add(operation);
-
- toRemove.add(field.getKey());
- } else if (customAnnotation.matches() && !"odata".equals(customAnnotation.group(2))) {
- final Annotation annotation = new AnnotationImpl();
- annotation.setTerm(customAnnotation.group(2) + "." + customAnnotation.group(3));
- value(annotation, field.getValue(), parser.getCodec());
-
- if (!annotations.containsKey(customAnnotation.group(1))) {
- annotations.put(customAnnotation.group(1), new ArrayList<Annotation>());
- }
- annotations.get(customAnnotation.group(1)).add(annotation);
- }
- }
-
- for (Link link : entity.getNavigationLinks()) {
- if (annotations.containsKey(link.getTitle())) {
- link.getAnnotations().addAll(annotations.get(link.getTitle()));
- for (Annotation annotation : annotations.get(link.getTitle())) {
- toRemove.add(link.getTitle() + "@" + annotation.getTerm());
- }
- }
- }
- for (Link link : entity.getMediaEditLinks()) {
- if (annotations.containsKey(link.getTitle())) {
- link.getAnnotations().addAll(annotations.get(link.getTitle()));
- for (Annotation annotation : annotations.get(link.getTitle())) {
- toRemove.add(link.getTitle() + "@" + annotation.getTerm());
- }
- }
- }
-
- tree.remove(toRemove);
-
- populate(entity, entity.getProperties(), tree, parser.getCodec());
-
- return new ResWrap<Entity>(contextURL, metadataETag, entity);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java
deleted file mode 100644
index 36e7ae1..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java
+++ /dev/null
@@ -1,129 +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.commons.core.data;
-
-import java.io.IOException;
-import java.net.URI;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.Annotation;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.Link;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.domain.ODataOperation;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-
-/**
- * Writes out JSON string from an entity.
- */
-public class JSONEntitySerializer extends JsonSerializer {
-
- public JSONEntitySerializer(final ODataServiceVersion version, final boolean serverMode) {
- super(version, serverMode);
- }
-
- protected void doSerialize(final Entity entity, final JsonGenerator jgen) throws IOException {
- doContainerSerialize(new ResWrap<Entity>((URI) null, null, entity), jgen);
- }
-
- protected void doContainerSerialize(final ResWrap<Entity> container, final JsonGenerator jgen)
- throws IOException {
-
- final Entity entity = container.getPayload();
-
- jgen.writeStartObject();
-
- if (serverMode) {
- if (container.getContextURL() != null) {
- jgen.writeStringField(version.compareTo(ODataServiceVersion.V40) >= 0
- ? Constants.JSON_CONTEXT : Constants.JSON_METADATA,
- container.getContextURL().getURI().toASCIIString());
- }
- if (version.compareTo(ODataServiceVersion.V40) >= 0 && StringUtils.isNotBlank(container.getMetadataETag())) {
- jgen.writeStringField(Constants.JSON_METADATA_ETAG, container.getMetadataETag());
- }
-
- if (StringUtils.isNotBlank(entity.getETag())) {
- jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ETAG), entity.getETag());
- }
- }
-
- if (StringUtils.isNotBlank(entity.getType())) {
- jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_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());
- }
-
- for (Annotation annotation : entity.getAnnotations()) {
- valuable(jgen, annotation, "@" + annotation.getTerm());
- }
-
- for (Property property : entity.getProperties()) {
- valuable(jgen, property, property.getName());
- }
-
- if (serverMode && entity.getEditLink() != null && StringUtils.isNotBlank(entity.getEditLink().getHref())) {
- jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK),
- entity.getEditLink().getHref());
-
- if (entity.isMediaEntity()) {
- jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK),
- entity.getEditLink().getHref() + "/$value");
- }
- }
-
- links(entity, jgen);
-
- for (Link link : entity.getMediaEditLinks()) {
- if (link.getTitle() == null) {
- jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK), link.getHref());
- }
-
- if (link.getInlineEntity() != null) {
- jgen.writeObjectField(link.getTitle(), link.getInlineEntity());
- }
- if (link.getInlineEntitySet() != null) {
- jgen.writeArrayFieldStart(link.getTitle());
- for (Entity subEntry : link.getInlineEntitySet().getEntities()) {
- jgen.writeObject(subEntry);
- }
- jgen.writeEndArray();
- }
- }
-
- if (serverMode) {
- for (ODataOperation operation : entity.getOperations()) {
- jgen.writeObjectFieldStart("#" + StringUtils.substringAfterLast(operation.getMetadataAnchor(), "#"));
- jgen.writeStringField(Constants.ATTR_TITLE, operation.getTitle());
- jgen.writeStringField(Constants.ATTR_TARGET, operation.getTarget().toASCIIString());
- jgen.writeEndObject();
- }
- }
-
- jgen.writeEndObject();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetDeserializer.java
deleted file mode 100644
index e4cd3ab..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetDeserializer.java
+++ /dev/null
@@ -1,116 +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.commons.core.data;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.Annotation;
-import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-/**
- * Reads JSON string into an entity set.
- * <br/>
- * If metadata information is available, the corresponding entity fields and content will be populated.
- */
-public class JSONEntitySetDeserializer extends JsonDeserializer {
-
- public JSONEntitySetDeserializer(final ODataServiceVersion version, final boolean serverMode) {
- super(version, serverMode);
- }
-
- protected ResWrap<EntitySet> doDeserialize(final JsonParser parser) throws IOException {
-
- final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser);
-
- if (!tree.has(Constants.VALUE)) {
- return null;
- }
-
- final EntitySetImpl entitySet = new EntitySetImpl();
-
- URI contextURL;
- if (tree.hasNonNull(Constants.JSON_CONTEXT)) {
- contextURL = URI.create(tree.get(Constants.JSON_CONTEXT).textValue());
- tree.remove(Constants.JSON_CONTEXT);
- } else if (tree.hasNonNull(Constants.JSON_METADATA)) {
- contextURL = URI.create(tree.get(Constants.JSON_METADATA).textValue());
- tree.remove(Constants.JSON_METADATA);
- } else {
- contextURL = null;
- }
- if (contextURL != null) {
- entitySet.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA));
- }
-
- final String metadataETag;
- if (tree.hasNonNull(Constants.JSON_METADATA_ETAG)) {
- metadataETag = tree.get(Constants.JSON_METADATA_ETAG).textValue();
- tree.remove(Constants.JSON_METADATA_ETAG);
- } else {
- metadataETag = null;
- }
-
- if (tree.hasNonNull(jsonCount)) {
- entitySet.setCount(tree.get(jsonCount).asInt());
- tree.remove(jsonCount);
- }
- if (tree.hasNonNull(jsonNextLink)) {
- entitySet.setNext(URI.create(tree.get(jsonNextLink).textValue()));
- tree.remove(jsonNextLink);
- }
- if (tree.hasNonNull(jsonDeltaLink)) {
- entitySet.setDeltaLink(URI.create(tree.get(jsonDeltaLink).textValue()));
- tree.remove(jsonDeltaLink);
- }
-
- if (tree.hasNonNull(Constants.VALUE)) {
- final JSONEntityDeserializer entityDeserializer = new JSONEntityDeserializer(version, serverMode);
- for (final Iterator<JsonNode> itor = tree.get(Constants.VALUE).iterator(); itor.hasNext();) {
- entitySet.getEntities().add(
- entityDeserializer.doDeserialize(itor.next().traverse(parser.getCodec())).getPayload());
- }
- tree.remove(Constants.VALUE);
- }
-
- // any remaining entry is supposed to be an annotation or is ignored
- for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); itor.hasNext();) {
- final Map.Entry<String, JsonNode> field = itor.next();
- if (field.getKey().charAt(0) == '@') {
- final Annotation annotation = new AnnotationImpl();
- annotation.setTerm(field.getKey().substring(1));
-
- value(annotation, field.getValue(), parser.getCodec());
- entitySet.getAnnotations().add(annotation);
- }
- }
-
- return new ResWrap<EntitySet>(contextURL, metadataETag, entitySet);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetSerializer.java
deleted file mode 100644
index 1670259..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetSerializer.java
+++ /dev/null
@@ -1,94 +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.commons.core.data;
-
-import java.io.IOException;
-import java.net.URI;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.Annotation;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-
-public class JSONEntitySetSerializer extends JsonSerializer {
-
- public JSONEntitySetSerializer(final ODataServiceVersion version, final boolean serverMode) {
- super(version, serverMode);
- }
-
- protected void doSerialize(final EntitySet entitySet, final JsonGenerator jgen) throws IOException {
- doContainerSerialize(new ResWrap<EntitySet>((URI) null, null, entitySet), jgen);
- }
-
- protected void doContainerSerialize(final ResWrap<EntitySet> container, final JsonGenerator jgen)
- throws IOException {
-
- final EntitySet entitySet = container.getPayload();
-
- jgen.writeStartObject();
-
- if (serverMode) {
- if (container.getContextURL() != null) {
- jgen.writeStringField(version.compareTo(ODataServiceVersion.V40) >= 0
- ? Constants.JSON_CONTEXT : Constants.JSON_METADATA,
- container.getContextURL().getURI().toASCIIString());
- }
-
- if (version.compareTo(ODataServiceVersion.V40) >= 0 && StringUtils.isNotBlank(container.getMetadataETag())) {
- jgen.writeStringField(
- Constants.JSON_METADATA_ETAG,
- container.getMetadataETag());
- }
- }
-
- if (entitySet.getId() != null) {
- jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), entitySet.getId().toASCIIString());
- }
- jgen.writeNumberField(version.getJSONMap().get(ODataServiceVersion.JSON_COUNT),
- entitySet.getCount() == null ? entitySet.getEntities().size() : entitySet.getCount());
- if (serverMode) {
- if (entitySet.getNext() != null) {
- jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_NEXT_LINK),
- entitySet.getNext().toASCIIString());
- }
- if (entitySet.getDeltaLink() != null) {
- jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_DELTA_LINK),
- entitySet.getDeltaLink().toASCIIString());
- }
- }
-
- for (Annotation annotation : entitySet.getAnnotations()) {
- valuable(jgen, annotation, "@" + annotation.getTerm());
- }
-
- jgen.writeArrayFieldStart(Constants.VALUE);
- final JSONEntitySerializer entitySerializer = new JSONEntitySerializer(version, serverMode);
- for (Entity entity : entitySet.getEntities()) {
- entitySerializer.doSerialize(entity, jgen);
- }
- jgen.writeEndArray();
-
- jgen.writeEndObject();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONGeoValueDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONGeoValueDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONGeoValueDeserializer.java
deleted file mode 100644
index d645587..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONGeoValueDeserializer.java
+++ /dev/null
@@ -1,267 +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.commons.core.data;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.GeoUtils;
-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.geo.Geospatial;
-import org.apache.olingo.commons.api.edm.geo.GeospatialCollection;
-import org.apache.olingo.commons.api.edm.geo.LineString;
-import org.apache.olingo.commons.api.edm.geo.MultiLineString;
-import org.apache.olingo.commons.api.edm.geo.MultiPoint;
-import org.apache.olingo.commons.api.edm.geo.MultiPolygon;
-import org.apache.olingo.commons.api.edm.geo.Point;
-import org.apache.olingo.commons.api.edm.geo.Polygon;
-import org.apache.olingo.commons.api.edm.geo.SRID;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
-
-class JSONGeoValueDeserializer {
-
- private final ODataServiceVersion version;
-
- public JSONGeoValueDeserializer(final ODataServiceVersion version) {
- this.version = version;
- }
-
- private Point point(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type, final SRID srid) {
- Point point = null;
-
- if (itor.hasNext()) {
- point = new Point(GeoUtils.getDimension(type), srid);
- try {
- point.setX(EdmDouble.getInstance().valueOfString(itor.next().asText(), null, null,
- Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class));
- point.setY(EdmDouble.getInstance().valueOfString(itor.next().asText(), null, null,
- Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class));
- } catch (EdmPrimitiveTypeException e) {
- throw new IllegalArgumentException("While deserializing point coordinates as double", e);
- }
- }
-
- return point;
- }
-
- private MultiPoint multipoint(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type, final SRID srid) {
- final MultiPoint multiPoint;
-
- if (itor.hasNext()) {
- final List<Point> points = new ArrayList<Point>();
- while (itor.hasNext()) {
- final Iterator<JsonNode> mpItor = itor.next().elements();
- points.add(point(mpItor, type, srid));
- }
- multiPoint = new MultiPoint(GeoUtils.getDimension(type), srid, points);
- } else {
- multiPoint = new MultiPoint(GeoUtils.getDimension(type), srid, Collections.<Point>emptyList());
- }
-
- return multiPoint;
- }
-
- private LineString lineString(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type, final SRID srid) {
- final LineString lineString;
-
- if (itor.hasNext()) {
- final List<Point> points = new ArrayList<Point>();
- while (itor.hasNext()) {
- final Iterator<JsonNode> mpItor = itor.next().elements();
- points.add(point(mpItor, type, srid));
- }
- lineString = new LineString(GeoUtils.getDimension(type), srid, points);
- } else {
- lineString = new LineString(GeoUtils.getDimension(type), srid, Collections.<Point>emptyList());
- }
-
- return lineString;
- }
-
- private MultiLineString multiLineString(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type,
- final SRID srid) {
-
- final MultiLineString multiLineString;
-
- if (itor.hasNext()) {
- final List<LineString> lineStrings = new ArrayList<LineString>();
- while (itor.hasNext()) {
- final Iterator<JsonNode> mlsItor = itor.next().elements();
- lineStrings.add(lineString(mlsItor, type, srid));
- }
- multiLineString = new MultiLineString(GeoUtils.getDimension(type), srid, lineStrings);
- } else {
- multiLineString = new MultiLineString(GeoUtils.getDimension(type), srid, Collections.<LineString>emptyList());
- }
-
- return multiLineString;
- }
-
- private Polygon polygon(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type, final SRID srid) {
- List<Point> extPoints = null;
- if (itor.hasNext()) {
- final Iterator<JsonNode> extItor = itor.next().elements();
- if (extItor.hasNext()) {
- extPoints = new ArrayList<Point>();
- while (extItor.hasNext()) {
- final Iterator<JsonNode> mpItor = extItor.next().elements();
- extPoints.add(point(mpItor, type, srid));
- }
- }
- }
-
- List<Point> intPoints = null;
- if (itor.hasNext()) {
- final Iterator<JsonNode> intItor = itor.next().elements();
- if (intItor.hasNext()) {
- intPoints = new ArrayList<Point>();
- while (intItor.hasNext()) {
- final Iterator<JsonNode> mpItor = intItor.next().elements();
- intPoints.add(point(mpItor, type, srid));
- }
- }
- }
-
- return new Polygon(GeoUtils.getDimension(type), srid, intPoints, extPoints);
- }
-
- private MultiPolygon multiPolygon(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type, final SRID srid) {
- final MultiPolygon multiPolygon;
-
- if (itor.hasNext()) {
- final List<Polygon> polygons = new ArrayList<Polygon>();
- while (itor.hasNext()) {
- final Iterator<JsonNode> mpItor = itor.next().elements();
- polygons.add(polygon(mpItor, type, srid));
- }
- multiPolygon = new MultiPolygon(GeoUtils.getDimension(type), srid, polygons);
- } else {
- multiPolygon = new MultiPolygon(GeoUtils.getDimension(type), srid, Collections.<Polygon>emptyList());
- }
-
- return multiPolygon;
- }
-
- private GeospatialCollection collection(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type,
- final SRID srid) {
-
- final GeospatialCollection collection;
-
- if (itor.hasNext()) {
- final List<Geospatial> geospatials = new ArrayList<Geospatial>();
-
- while (itor.hasNext()) {
- final JsonNode geo = itor.next();
- final String collItemType = geo.get(Constants.ATTR_TYPE).asText();
- final String callAsType;
- if (EdmPrimitiveTypeKind.GeographyCollection.name().equals(collItemType)
- || EdmPrimitiveTypeKind.GeometryCollection.name().equals(collItemType)) {
-
- callAsType = collItemType;
- } else {
- callAsType = (type == EdmPrimitiveTypeKind.GeographyCollection ? "Geography" : "Geometry")
- + collItemType;
- }
-
- geospatials.add(deserialize(geo, new EdmTypeInfo.Builder().setTypeExpression(callAsType).build()));
- }
-
- collection = new GeospatialCollection(GeoUtils.getDimension(type), srid, geospatials);
- } else {
- collection = new GeospatialCollection(GeoUtils.getDimension(type), srid, Collections.<Geospatial>emptyList());
- }
-
- return collection;
- }
-
- public Geospatial deserialize(final JsonNode node, final EdmTypeInfo typeInfo) {
- final EdmPrimitiveTypeKind actualType;
- if ((typeInfo.getPrimitiveTypeKind() == EdmPrimitiveTypeKind.Geography
- || typeInfo.getPrimitiveTypeKind() == EdmPrimitiveTypeKind.Geometry)
- && node.has(Constants.ATTR_TYPE)) {
-
- String nodeType = node.get(Constants.ATTR_TYPE).asText();
- if (nodeType.startsWith("Geo")) {
- final int yIdx = nodeType.indexOf('y');
- nodeType = nodeType.substring(yIdx + 1);
- }
- actualType = EdmPrimitiveTypeKind.valueOfFQN(version, typeInfo.getFullQualifiedName().toString() + nodeType);
- } else {
- actualType = typeInfo.getPrimitiveTypeKind();
- }
-
- final Iterator<JsonNode> cooItor = node.has(Constants.JSON_COORDINATES)
- ? node.get(Constants.JSON_COORDINATES).elements()
- : Collections.<JsonNode>emptyList().iterator();
-
- SRID srid = null;
- if (node.has(Constants.JSON_CRS)) {
- srid = SRID.valueOf(
- node.get(Constants.JSON_CRS).get(Constants.PROPERTIES).get(Constants.JSON_NAME).asText().split(":")[1]);
- }
-
- Geospatial value = null;
- switch (actualType) {
- case GeographyPoint:
- case GeometryPoint:
- value = point(cooItor, actualType, srid);
- break;
-
- case GeographyMultiPoint:
- case GeometryMultiPoint:
- value = multipoint(cooItor, actualType, srid);
- break;
-
- case GeographyLineString:
- case GeometryLineString:
- value = lineString(cooItor, actualType, srid);
- break;
-
- case GeographyMultiLineString:
- case GeometryMultiLineString:
- value = multiLineString(cooItor, actualType, srid);
- break;
-
- case GeographyPolygon:
- case GeometryPolygon:
- value = polygon(cooItor, actualType, srid);
- break;
-
- case GeographyMultiPolygon:
- case GeometryMultiPolygon:
- value = multiPolygon(cooItor, actualType, srid);
- break;
-
- case GeographyCollection:
- case GeometryCollection:
- value = collection(node.get(Constants.JSON_GEOMETRIES).elements(), actualType, srid);
- break;
-
- default:
- }
-
- return value;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONGeoValueSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONGeoValueSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONGeoValueSerializer.java
deleted file mode 100644
index 4578e52..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONGeoValueSerializer.java
+++ /dev/null
@@ -1,184 +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.commons.core.data;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import java.io.IOException;
-import java.util.Iterator;
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.geo.ComposedGeospatial;
-import org.apache.olingo.commons.api.edm.geo.Geospatial;
-import org.apache.olingo.commons.api.edm.geo.GeospatialCollection;
-import org.apache.olingo.commons.api.edm.geo.LineString;
-import org.apache.olingo.commons.api.edm.geo.MultiLineString;
-import org.apache.olingo.commons.api.edm.geo.MultiPoint;
-import org.apache.olingo.commons.api.edm.geo.MultiPolygon;
-import org.apache.olingo.commons.api.edm.geo.Point;
-import org.apache.olingo.commons.api.edm.geo.Polygon;
-import org.apache.olingo.commons.api.edm.geo.SRID;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
-
-class JSONGeoValueSerializer {
-
- private void srid(final JsonGenerator jgen, final SRID srid) throws IOException {
- jgen.writeObjectFieldStart(Constants.JSON_CRS);
- jgen.writeStringField(Constants.ATTR_TYPE, Constants.JSON_NAME);
- jgen.writeObjectFieldStart(Constants.PROPERTIES);
- jgen.writeStringField(Constants.JSON_NAME, "EPSG:" + srid.toString());
- jgen.writeEndObject();
- jgen.writeEndObject();
- }
-
- private void point(final JsonGenerator jgen, final Point point) throws IOException {
- try {
- jgen.writeNumber(EdmDouble.getInstance().valueToString(point.getX(), null, null,
- Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null));
- jgen.writeNumber(EdmDouble.getInstance().valueToString(point.getY(), null, null,
- Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null));
- } catch (EdmPrimitiveTypeException e) {
- throw new IllegalArgumentException("While serializing point coordinates as double", e);
- }
- }
-
- private void multipoint(final JsonGenerator jgen, final MultiPoint multiPoint) throws IOException {
- for (final Iterator<Point> itor = multiPoint.iterator(); itor.hasNext();) {
- jgen.writeStartArray();
- point(jgen, itor.next());
- jgen.writeEndArray();
- }
- }
-
- private void lineString(final JsonGenerator jgen, final ComposedGeospatial<Point> lineString) throws IOException {
- for (final Iterator<Point> itor = lineString.iterator(); itor.hasNext();) {
- jgen.writeStartArray();
- point(jgen, itor.next());
- jgen.writeEndArray();
- }
- }
-
- private void multiLineString(final JsonGenerator jgen, final MultiLineString multiLineString) throws IOException {
- for (final Iterator<LineString> itor = multiLineString.iterator(); itor.hasNext();) {
- jgen.writeStartArray();
- lineString(jgen, itor.next());
- jgen.writeEndArray();
- }
- }
-
- private void polygon(final JsonGenerator jgen, final Polygon polygon) throws IOException {
- if (!polygon.getExterior().isEmpty()) {
- jgen.writeStartArray();
- lineString(jgen, polygon.getExterior());
- jgen.writeEndArray();
- }
- if (!polygon.getInterior().isEmpty()) {
- jgen.writeStartArray();
- lineString(jgen, polygon.getInterior());
- jgen.writeEndArray();
- }
- }
-
- private void multiPolygon(final JsonGenerator jgen, final MultiPolygon multiPolygon) throws IOException {
- for (final Iterator<Polygon> itor = multiPolygon.iterator(); itor.hasNext();) {
- final Polygon polygon = itor.next();
- jgen.writeStartArray();
- polygon(jgen, polygon);
- jgen.writeEndArray();
- }
- }
-
- private void collection(final JsonGenerator jgen, final GeospatialCollection collection) throws IOException {
- jgen.writeArrayFieldStart(Constants.JSON_GEOMETRIES);
- for (final Iterator<Geospatial> itor = collection.iterator(); itor.hasNext();) {
- jgen.writeStartObject();
- serialize(jgen, itor.next());
- jgen.writeEndObject();
- }
- jgen.writeEndArray();
- }
-
- public void serialize(final JsonGenerator jgen, final Geospatial value) throws IOException {
- if (value.getEdmPrimitiveTypeKind().equals(EdmPrimitiveTypeKind.GeographyCollection)
- || value.getEdmPrimitiveTypeKind().equals(EdmPrimitiveTypeKind.GeometryCollection)) {
-
- jgen.writeStringField(Constants.ATTR_TYPE, EdmPrimitiveTypeKind.GeometryCollection.name());
- } else {
- final int yIdx = value.getEdmPrimitiveTypeKind().name().indexOf('y');
- final String itemType = value.getEdmPrimitiveTypeKind().name().substring(yIdx + 1);
- jgen.writeStringField(Constants.ATTR_TYPE, itemType);
- }
-
- switch (value.getEdmPrimitiveTypeKind()) {
- case GeographyPoint:
- case GeometryPoint:
- jgen.writeArrayFieldStart(Constants.JSON_COORDINATES);
- point(jgen, (Point) value);
- jgen.writeEndArray();
- break;
-
- case GeographyMultiPoint:
- case GeometryMultiPoint:
- jgen.writeArrayFieldStart(Constants.JSON_COORDINATES);
- multipoint(jgen, (MultiPoint) value);
- jgen.writeEndArray();
- break;
-
- case GeographyLineString:
- case GeometryLineString:
- jgen.writeArrayFieldStart(Constants.JSON_COORDINATES);
- lineString(jgen, (LineString) value);
- jgen.writeEndArray();
- break;
-
- case GeographyMultiLineString:
- case GeometryMultiLineString:
- jgen.writeArrayFieldStart(Constants.JSON_COORDINATES);
- multiLineString(jgen, (MultiLineString) value);
- jgen.writeEndArray();
- break;
-
- case GeographyPolygon:
- case GeometryPolygon:
- jgen.writeArrayFieldStart(Constants.JSON_COORDINATES);
- polygon(jgen, (Polygon) value);
- jgen.writeEndArray();
- break;
-
- case GeographyMultiPolygon:
- case GeometryMultiPolygon:
- jgen.writeArrayFieldStart(Constants.JSON_COORDINATES);
- multiPolygon(jgen, (MultiPolygon) value);
- jgen.writeEndArray();
- break;
-
- case GeographyCollection:
- case GeometryCollection:
- collection(jgen, (GeospatialCollection) value);
- break;
-
- default:
- }
-
- if (value.getSrid() != null && value.getSrid().isNotDefault()) {
- srid(jgen, value.getSrid());
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONLinkCollectionDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONLinkCollectionDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONLinkCollectionDeserializer.java
deleted file mode 100755
index 1876b9c..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONLinkCollectionDeserializer.java
+++ /dev/null
@@ -1,80 +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.commons.core.data;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.data.v3.LinkCollection;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.api.op.ODataDeserializerException;
-import org.apache.olingo.commons.core.data.v3.LinkCollectionImpl;
-
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-public class JSONLinkCollectionDeserializer extends JsonDeserializer {
-
- public JSONLinkCollectionDeserializer(final ODataServiceVersion version, final boolean serverMode) {
- super(version, serverMode);
- }
-
- protected ResWrap<LinkCollection> doDeserialize(final JsonParser parser) throws IOException {
-
- final ObjectNode tree = parser.getCodec().readTree(parser);
-
- final LinkCollectionImpl links = new LinkCollectionImpl();
-
- if (tree.hasNonNull("odata.metadata")) {
- links.setMetadata(URI.create(tree.get("odata.metadata").textValue()));
- }
-
- if (tree.hasNonNull(Constants.JSON_URL)) {
- links.getLinks().add(URI.create(tree.get(Constants.JSON_URL).textValue()));
- }
-
- if (tree.hasNonNull(Constants.VALUE)) {
- for (final JsonNode item : tree.get(Constants.VALUE)) {
- final URI uri = URI.create(item.get(Constants.JSON_URL).textValue());
- links.getLinks().add(uri);
- }
- }
-
- if (tree.hasNonNull(jsonNextLink)) {
- links.setNext(URI.create(tree.get(jsonNextLink).textValue()));
- }
-
- return new ResWrap<LinkCollection>((URI) null, null, links);
- }
-
- public ResWrap<LinkCollection> toLinkCollection(InputStream input) throws ODataDeserializerException {
- try {
- JsonParser parser = new JsonFactory(new ObjectMapper()).createParser(input);
- return doDeserialize(parser);
- } catch (final IOException e) {
- throw new ODataDeserializerException(e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDeserializer.java
deleted file mode 100644
index 1803c10..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDeserializer.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.commons.core.data;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.domain.ODataError;
-import org.apache.olingo.commons.api.domain.ODataErrorDetail;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-public class JSONODataErrorDeserializer extends JsonDeserializer {
-
- public JSONODataErrorDeserializer(final ODataServiceVersion version, final boolean serverMode) {
- super(version, serverMode);
- }
-
- protected ODataError doDeserialize(final JsonParser parser) throws IOException {
-
- final ODataErrorImpl error = new ODataErrorImpl();
-
- final ObjectNode tree = parser.getCodec().readTree(parser);
- if (tree.has(jsonError)) {
- final JsonNode errorNode = tree.get(jsonError);
-
- if (errorNode.has(Constants.ERROR_CODE)) {
- error.setCode(errorNode.get(Constants.ERROR_CODE).textValue());
- }
- if (errorNode.has(Constants.ERROR_MESSAGE)) {
- final JsonNode message = errorNode.get(Constants.ERROR_MESSAGE);
- if (message.isValueNode()) {
- error.setMessage(message.textValue());
- } else if (message.isObject()) {
- error.setMessage(message.get(Constants.VALUE).asText());
- }
- }
- if (errorNode.has(Constants.ERROR_TARGET)) {
- error.setTarget(errorNode.get(Constants.ERROR_TARGET).textValue());
- }
- if (errorNode.hasNonNull(Constants.ERROR_DETAILS)) {
- List<ODataErrorDetail> details = new ArrayList<ODataErrorDetail>();
- JSONODataErrorDetailDeserializer detailDeserializer =
- new JSONODataErrorDetailDeserializer(version, serverMode);
- for (Iterator<JsonNode> itor = errorNode.get(Constants.ERROR_DETAILS).iterator(); itor.hasNext();) {
- details.add(detailDeserializer.doDeserialize(itor.next().traverse(parser.getCodec()))
- .getPayload());
- }
-
- error.setDetails(details);
- }
- if (errorNode.hasNonNull(Constants.ERROR_INNERERROR)) {
- final JsonNode innerError = errorNode.get(Constants.ERROR_INNERERROR);
- for (final Iterator<String> itor = innerError.fieldNames(); itor.hasNext();) {
- final String keyTmp = itor.next();
- final String val = innerError.get(keyTmp).toString();
- error.getInnerError().put(keyTmp, val);
- }
- }
- }
-
- return error;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b15439ff/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDetailDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDetailDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDetailDeserializer.java
deleted file mode 100644
index 6fe51ce..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDetailDeserializer.java
+++ /dev/null
@@ -1,59 +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.commons.core.data;
-
-import java.io.IOException;
-import java.net.URI;
-
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.domain.ODataErrorDetail;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.JsonNode;
-
-public class JSONODataErrorDetailDeserializer extends JsonDeserializer {
-
- public JSONODataErrorDetailDeserializer(final ODataServiceVersion version, final boolean serverMode) {
- super(version, serverMode);
- }
-
- protected ResWrap<ODataErrorDetail> doDeserialize(final JsonParser parser) throws IOException {
-
- final ODataErrorDetailImpl error = new ODataErrorDetailImpl();
- final JsonNode errorNode = parser.getCodec().readTree(parser);
- if (errorNode.has(Constants.ERROR_CODE)) {
- error.setCode(errorNode.get(Constants.ERROR_CODE).textValue());
- }
- if (errorNode.has(Constants.ERROR_MESSAGE)) {
- final JsonNode message = errorNode.get(Constants.ERROR_MESSAGE);
- if (message.isValueNode()) {
- error.setMessage(message.textValue());
- } else if (message.isObject()) {
- error.setMessage(message.get(Constants.VALUE).asText());
- }
- }
- if (errorNode.has(Constants.ERROR_TARGET)) {
- error.setTarget(errorNode.get(Constants.ERROR_TARGET).textValue());
- }
-
- return new ResWrap<ODataErrorDetail>((URI) null, null, error);
- }
-}