[OLINGO-200] New StAX (replacing DOM) (de)serializers in place - still IT to check

This commit is contained in:
Francesco Chicchiriccò 2014-03-19 17:58:11 +01:00
parent aa80231bca
commit 381b417035
142 changed files with 4980 additions and 3661 deletions

View File

@ -19,4 +19,158 @@
under the License.
-->
<entry xml:base="http://192.168.43.55:8080/DefaultService.svc/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"><id>http://192.168.43.55:8080/DefaultService.svc/AllGeoTypesSet(-8)</id><category term="Microsoft.Test.OData.Services.AstoriaDefaultService.AllSpatialTypes" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" title="AllSpatialTypes" href="AllGeoTypesSet(-8)" /><title /><updated>2013-08-21T10:50:04Z</updated><author><name /></author><content type="application/xml"><m:properties><d:Id m:type="Edm.Int32">-8</d:Id><d:Geog m:type="Edm.GeographyPoint"><gml:Point gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326"><gml:pos>51.5961 178.94</gml:pos></gml:Point></d:Geog><d:GeogPoint m:type="Edm.GeographyPoint"><gml:Point gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326"><gml:pos>51.65 178.7</gml:pos></gml:Point></d:GeogPoint><d:GeogLine m:type="Edm.GeographyLineString"><gml:LineString gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326"><gml:pos>10 10</gml:pos><gml:pos>20 20</gml:pos><gml:pos>40 10</gml:pos></gml:LineString></d:GeogLine><d:GeogPolygon m:type="Edm.GeographyPolygon"><gml:Polygon gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326" /></d:GeogPolygon><d:GeogCollection m:type="Edm.GeographyCollection"><gml:MultiGeometry gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326" /></d:GeogCollection><d:GeogMultiPoint m:type="Edm.GeographyMultiPoint"><gml:MultiPoint gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326"><gml:pointMembers><gml:Point><gml:pos>47.38 -122.7</gml:pos></gml:Point></gml:pointMembers></gml:MultiPoint></d:GeogMultiPoint><d:GeogMultiLine m:type="Edm.GeographyMultiLineString"><gml:MultiCurve gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326"><gml:curveMembers><gml:LineString><gml:pos>10.5 10.5</gml:pos><gml:pos>20.5 20.5</gml:pos><gml:pos>40.5 10.5</gml:pos></gml:LineString><gml:LineString><gml:pos>40.5 40.5</gml:pos><gml:pos>30.5 30.5</gml:pos><gml:pos>20.5 40.5</gml:pos><gml:pos>10.5 30.5</gml:pos></gml:LineString></gml:curveMembers></gml:MultiCurve></d:GeogMultiLine><d:GeogMultiPolygon m:type="Edm.GeographyMultiPolygon"><gml:MultiSurface gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326"><gml:surfaceMembers><gml:Polygon><gml:exterior><gml:LinearRing><gml:pos>40 40</gml:pos><gml:pos>45 20</gml:pos><gml:pos>30 45</gml:pos><gml:pos>40 40</gml:pos></gml:LinearRing></gml:exterior></gml:Polygon><gml:Polygon><gml:exterior><gml:LinearRing><gml:pos>35 20</gml:pos><gml:pos>20 45</gml:pos><gml:pos>5 30</gml:pos><gml:pos>10 10</gml:pos><gml:pos>30 10</gml:pos><gml:pos>35 20</gml:pos></gml:LinearRing></gml:exterior><gml:interior><gml:LinearRing><gml:pos>20 30</gml:pos><gml:pos>25 20</gml:pos><gml:pos>15 20</gml:pos><gml:pos>20 30</gml:pos></gml:LinearRing></gml:interior></gml:Polygon></gml:surfaceMembers></gml:MultiSurface></d:GeogMultiPolygon><d:Geom m:type="Edm.GeometryPoint"><gml:Point gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0"><gml:pos>4369367.0586663447 6352015.6916818349</gml:pos></gml:Point></d:Geom><d:GeomPoint m:type="Edm.GeometryPoint"><gml:Point gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0"><gml:pos>4377000.868172125 6348217.1067010015</gml:pos></gml:Point></d:GeomPoint><d:GeomLine m:type="Edm.GeometryLineString"><gml:LineString gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0"><gml:pos>1 1</gml:pos><gml:pos>3 3</gml:pos><gml:pos>2 4</gml:pos><gml:pos>2 0</gml:pos></gml:LineString></d:GeomLine><d:GeomPolygon m:type="Edm.GeometryPolygon"><gml:Polygon gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0"><gml:exterior><gml:LinearRing><gml:pos>30 20</gml:pos><gml:pos>10 40</gml:pos><gml:pos>45 40</gml:pos><gml:pos>30 20</gml:pos></gml:LinearRing></gml:exterior></gml:Polygon></d:GeomPolygon><d:GeomCollection m:type="Edm.GeometryCollection"><gml:MultiGeometry gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0"><gml:geometryMembers><gml:Point><gml:pos>4 6</gml:pos></gml:Point><gml:LineString><gml:pos>4 6</gml:pos><gml:pos>7 10</gml:pos></gml:LineString></gml:geometryMembers></gml:MultiGeometry></d:GeomCollection><d:GeomMultiPoint m:null="true" /><d:GeomMultiLine m:type="Edm.GeometryMultiLineString"><gml:MultiCurve gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0" /></d:GeomMultiLine><d:GeomMultiPolygon m:type="Edm.GeometryMultiPolygon"><gml:MultiSurface gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0" /></d:GeomMultiPolygon></m:properties></content></entry>
<entry xml:base="http://192.168.43.55:8080/DefaultService.svc/"
xmlns="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:georss="http://www.georss.org/georss"
xmlns:gml="http://www.opengis.net/gml">
<id>http://192.168.43.55:8080/DefaultService.svc/AllGeoTypesSet(-8)</id>
<category term="Microsoft.Test.OData.Services.AstoriaDefaultService.AllSpatialTypes" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" title="AllSpatialTypes" href="AllGeoTypesSet(-8)" />
<title />
<updated>2013-08-21T10:50:04Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:Id m:type="Edm.Int32">-8</d:Id>
<d:Geog m:type="Edm.GeographyPoint">
<gml:Point gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326">
<gml:pos>51.5961 178.94</gml:pos>
</gml:Point>
</d:Geog>
<d:GeogPoint m:type="Edm.GeographyPoint">
<gml:Point gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326">
<gml:pos>51.65 178.7</gml:pos>
</gml:Point>
</d:GeogPoint>
<d:GeogLine m:type="Edm.GeographyLineString">
<gml:LineString gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326">
<gml:pos>10 10</gml:pos>
<gml:pos>20 20</gml:pos>
<gml:pos>40 10</gml:pos>
</gml:LineString>
</d:GeogLine>
<d:GeogPolygon m:type="Edm.GeographyPolygon">
<gml:Polygon gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326" />
</d:GeogPolygon>
<d:GeogCollection m:type="Edm.GeographyCollection">
<gml:MultiGeometry gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326" />
</d:GeogCollection>
<d:GeogMultiPoint m:type="Edm.GeographyMultiPoint">
<gml:MultiPoint gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326">
<gml:pointMembers>
<gml:Point>
<gml:pos>47.38 -122.7</gml:pos>
</gml:Point>
</gml:pointMembers>
</gml:MultiPoint>
</d:GeogMultiPoint>
<d:GeogMultiLine m:type="Edm.GeographyMultiLineString">
<gml:MultiCurve gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326">
<gml:curveMembers>
<gml:LineString>
<gml:pos>10.5 10.5</gml:pos>
<gml:pos>20.5 20.5</gml:pos>
<gml:pos>40.5 10.5</gml:pos>
</gml:LineString>
<gml:LineString>
<gml:pos>40.5 40.5</gml:pos>
<gml:pos>30.5 30.5</gml:pos>
<gml:pos>20.5 40.5</gml:pos>
<gml:pos>10.5 30.5</gml:pos>
</gml:LineString>
</gml:curveMembers>
</gml:MultiCurve>
</d:GeogMultiLine>
<d:GeogMultiPolygon m:type="Edm.GeographyMultiPolygon">
<gml:MultiSurface gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326">
<gml:surfaceMembers>
<gml:Polygon>
<gml:exterior>
<gml:LinearRing>
<gml:pos>40 40</gml:pos>
<gml:pos>45 20</gml:pos>
<gml:pos>30 45</gml:pos>
<gml:pos>40 40</gml:pos>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
<gml:Polygon>
<gml:exterior>
<gml:LinearRing>
<gml:pos>35 20</gml:pos>
<gml:pos>20 45</gml:pos>
<gml:pos>5 30</gml:pos>
<gml:pos>10 10</gml:pos>
<gml:pos>30 10</gml:pos>
<gml:pos>35 20</gml:pos>
</gml:LinearRing>
</gml:exterior>
<gml:interior>
<gml:LinearRing>
<gml:pos>20 30</gml:pos>
<gml:pos>25 20</gml:pos>
<gml:pos>15 20</gml:pos>
<gml:pos>20 30</gml:pos>
</gml:LinearRing>
</gml:interior>
</gml:Polygon>
</gml:surfaceMembers>
</gml:MultiSurface>
</d:GeogMultiPolygon>
<d:Geom m:type="Edm.GeometryPoint">
<gml:Point gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0">
<gml:pos>4369367.0586663447 6352015.6916818349</gml:pos>
</gml:Point>
</d:Geom>
<d:GeomPoint m:type="Edm.GeometryPoint">
<gml:Point gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0">
<gml:pos>4377000.868172125 6348217.1067010015</gml:pos>
</gml:Point>
</d:GeomPoint>
<d:GeomLine m:type="Edm.GeometryLineString">
<gml:LineString gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0">
<gml:pos>1 1</gml:pos>
<gml:pos>3 3</gml:pos>
<gml:pos>2 4</gml:pos>
<gml:pos>2 0</gml:pos>
</gml:LineString>
</d:GeomLine>
<d:GeomPolygon m:type="Edm.GeometryPolygon">
<gml:Polygon gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0">
<gml:exterior>
<gml:LinearRing>
<gml:pos>30 20</gml:pos>
<gml:pos>10 40</gml:pos>
<gml:pos>45 40</gml:pos>
<gml:pos>30 20</gml:pos>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</d:GeomPolygon>
<d:GeomCollection m:type="Edm.GeometryCollection">
<gml:MultiGeometry gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0">
<gml:geometryMembers>
<gml:Point>
<gml:pos>4 6</gml:pos>
</gml:Point>
<gml:LineString>
<gml:pos>4 6</gml:pos>
<gml:pos>7 10</gml:pos>
</gml:LineString>
</gml:geometryMembers>
</gml:MultiGeometry>
</d:GeomCollection>
<d:GeomMultiPoint m:null="true" />
<d:GeomMultiLine m:type="Edm.GeometryMultiLineString">
<gml:MultiCurve gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0" />
</d:GeomMultiLine>
<d:GeomMultiPolygon m:type="Edm.GeometryMultiPolygon">
<gml:MultiSurface gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0" />
</d:GeomMultiPolygon>
</m:properties>
</content>
</entry>

View File

@ -31,8 +31,6 @@ public class Constants {
public final static String NAME = "name";
public final static String PROPERTIES = "properties";
// XML namespaces and prefixes
public final static String NS_ATOM = "http://www.w3.org/2005/Atom";
@ -71,7 +69,7 @@ public class Constants {
public static final String NEXT_LINK_REL = "next";
// XML elements and attributes
public static final String ELEM_PROPERTIES = PREFIX_METADATA + PROPERTIES;
public static final String PROPERTIES = "properties";
public static final String ELEM_ELEMENT = "element";
@ -83,15 +81,17 @@ public class Constants {
public static final String ATTR_M_NULL = PREFIX_METADATA + ":" + ATTR_NULL;
public static final String ATTR_XMLBASE = "xml:base";
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 ATTR_REL = "rel";
public static final String ATTR_HREF = "href";
public static final String ATTR_TITLE = "title";
public static final String ATTR_METADATA = "metadata";
public static final String ATTR_TITLE = "title";
public static final String ATTR_HREF = "href";
public static final String ATTR_TARGET = "target";
@ -99,17 +99,19 @@ public class Constants {
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";
public static final String ELEM_MULTIPOINT = "MultiPoint";
public static final String ELEM_POINTMEMBERS = "pointMembers";
public static final QName QNAME_POINTMEMBERS = new QName(Constants.NS_GML, ELEM_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(Constants.NS_GML, ELEM_LINESTRING);
public static final QName QNAME_LINESTRING = new QName(NS_GML, ELEM_LINESTRING);
public static final String ELEM_MULTILINESTRING = "MultiCurve";
@ -117,15 +119,15 @@ public class Constants {
public static final String ELEM_POLYGON = "Polygon";
public static final QName QNAME_POLYGON = new QName(Constants.NS_GML, ELEM_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(Constants.NS_GML, ELEM_POLYGON_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(Constants.NS_GML, ELEM_POLYGON_INTERIOR);
public static final QName QNAME_POLYGON_INTERIOR = new QName(NS_GML, ELEM_POLYGON_INTERIOR);
public static final String ELEM_POLYGON_LINEARRING = "LinearRing";
@ -137,7 +139,7 @@ public class Constants {
public static final String ELEM_GEOMEMBERS = "geometryMembers";
public static final QName QNAME_GEOMEMBERS = new QName(Constants.NS_GML, ELEM_GEOMEMBERS);
public static final QName QNAME_GEOMEMBERS = new QName(NS_GML, ELEM_GEOMEMBERS);
public static final String ELEM_POS = "pos";
@ -154,10 +156,14 @@ public class Constants {
public final static String JSON_TYPE = "odata.type";
public final static String JSON_TYPE_SUFFIX = "@" + JSON_TYPE;
public final static String JSON_ETAG = "odata.etag";
public final static String JSON_MEDIA_ETAG = "odata.mediaETag";
public final static String JSON_MEDIA_ETAG_SUFFIX = "@" + JSON_MEDIA_ETAG;
public final static String JSON_ID = "odata.id";
public final static String JSON_READ_LINK = "odata.readLink";
@ -168,16 +174,18 @@ public class Constants {
public final static String JSON_MEDIAEDIT_LINK = "odata.mediaEditLink";
public final static String JSON_MEDIAEDIT_LINK_SUFFIX = "@" + JSON_MEDIAEDIT_LINK;
public final static String JSON_MEDIA_CONTENT_TYPE = "odata.mediaContentType";
public final static String JSON_MEDIA_CONTENT_TYPE_SUFFIX = "@" + JSON_MEDIA_CONTENT_TYPE;
public final static String JSON_NAVIGATION_LINK_SUFFIX = "@odata.navigationLinkUrl";
public final static String JSON_BIND_LINK_SUFFIX = "@odata.bind";
public final static String JSON_ASSOCIATION_LINK_SUFFIX = "@odata.associationLinkUrl";
public final static String JSON_MEDIAEDIT_LINK_SUFFIX = "@odata.mediaEditLink";
public final static String JSON_NULL = "odata.null";
public final static String JSON_VALUE = "value";
@ -190,38 +198,52 @@ public class Constants {
public final static String JSON_CRS = "crs";
public final static String JSON_COUNT = "odata.count";
public final static String JSON_NEXT_LINK = "odata.nextLink";
// 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_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 final static String ATOM_ELEM_LINK = "link";
public final static String ATOM_ELEM_CONTENT = "content";
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 String ATOM_ELEM_AUTHOR = "author";
public static final QName QNAME_ATOM_ELEM_UPDATED = new QName(NS_ATOM, ATOM_ELEM_UPDATED);
public static final String ATOM_ELEM_AUTHOR_NAME = "name";
public final static String ATOM_ELEM_LINK = "link";
public static final String ATOM_ELEM_AUTHOR_URI = "uri";
public static final QName QNAME_ATOM_ELEM_LINK = new QName(NS_ATOM, ATOM_ELEM_LINK);
public static final String ATOM_ELEM_AUTHOR_EMAIL = "email";
public final static String ATOM_ELEM_CONTENT = "content";
public static final String ATOM_ELEM_ACTION = PREFIX_METADATA + "action";
public static final QName QNAME_ATOM_ELEM_CONTENT = new QName(NS_ATOM, ATOM_ELEM_CONTENT);
public static final String ATOM_ELEM_INLINE = PREFIX_METADATA + "inline";
public static final String ATOM_ELEM_ACTION = "action";
public static final String ATOM_ATTR_TITLE = "atom:title";
public static final String ATOM_ELEM_INLINE = "inline";
public static final String ATOM_ATTR_TERM = "term";
@ -229,8 +251,6 @@ public class Constants {
public static final String ATOM_ATTR_SRC = "src";
public static final String ATOM_ATTR_ETAG = PREFIX_METADATA + "etag";
public static final String ATOM_ATTR_COUNT = PREFIX_METADATA + "count";
public static final String ATOM_ATTR_ETAG = "etag";
}

View File

@ -0,0 +1,27 @@
/*
* 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.client.api.data;
import java.util.List;
public interface CollectionValue extends Value {
@Override
List<Value> get();
}

View File

@ -0,0 +1,27 @@
/*
* 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.client.api.data;
import java.util.List;
public interface ComplexValue extends Value {
@Override
List<Property> get();
}

View File

@ -21,7 +21,6 @@ package org.apache.olingo.client.api.data;
import org.apache.olingo.client.api.domain.ODataOperation;
import java.net.URI;
import java.util.List;
import org.w3c.dom.Element;
public interface Entry {
@ -32,13 +31,6 @@ public interface Entry {
*/
String getETag();
/**
* Sets ETag.
*
* @param eTag ETag.
*/
void setETag(String eTag);
/**
* Gets base URI.
*
@ -67,13 +59,6 @@ public interface Entry {
*/
String getId();
/**
* Sets entry ID.
*
* @param id entry ID.
*/
void setId(String id);
/**
* Gets entry self link.
*
@ -131,32 +116,19 @@ public interface Entry {
List<ODataOperation> getOperations();
/**
* Gets content.
* Gets properties.
*
* @return content.
* @return properties.
*/
Element getContent();
List<Property> getProperties();
/**
* Sets content.
* Gets property with given name.
*
* @param content content.
* @param name property name
* @return property with given name if found, null otherwise
*/
void setContent(Element content);
/**
* Gets media entry properties.
*
* @return media entry properties.
*/
Element getMediaEntryProperties();
/**
* Sets media entry properties.
*
* @param content media entry properties.
*/
void setMediaEntryProperties(Element content);
Property getProperty(String name);
/**
* Gets media content type.

View File

@ -31,12 +31,26 @@ public interface Feed {
URI getBaseURI();
/**
* Gets number of entries if an <tt>inlinecount</tt> was required.
* Sets number of entries.
*
* @param count number of entries
*/
void setCount(Integer count);
/**
* Gets number of entries - if it was required.
*
* @return number of entries into the feed.
*/
Integer getCount();
/**
* Gest feed ID.
*
* @return feed ID.
*/
String getId();
/**
* Gets entries.
*

View File

@ -0,0 +1,28 @@
/*
* 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.client.api.data;
import org.apache.olingo.client.api.domain.geospatial.Geospatial;
public interface GeospatialValue extends Value {
@Override
Geospatial get();
}

View File

@ -76,6 +76,20 @@ public interface Link {
*/
void setHref(String href);
/**
* Gets Media ETag.
*
* @return media ETag
*/
String getMediaETag();
/**
* Sets Media ETag.
*
* @param etag media ETag
*/
void setMediaETag(String etag);
/**
* Gets in-line entry.
*

View File

@ -0,0 +1,26 @@
/*
* 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.client.api.data;
public interface NullValue extends Value {
@Override
Void get();
}

View File

@ -0,0 +1,25 @@
/*
* 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.client.api.data;
public interface PrimitiveValue extends Value {
@Override
String get();
}

View File

@ -0,0 +1,34 @@
/*
* 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.client.api.data;
public interface Property {
String getName();
void setName(String name);
String getType();
void setType(String type);
Value getValue();
void setValue(Value value);
}

View File

@ -0,0 +1,44 @@
/*
* 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.client.api.data;
public interface Value {
boolean isNull();
boolean isSimple();
boolean isGeospatial();
boolean isComplex();
boolean isCollection();
Object get();
NullValue asNull();
PrimitiveValue asSimple();
GeospatialValue asGeospatial();
ComplexValue asComplex();
CollectionValue asCollection();
}

View File

@ -18,30 +18,8 @@
*/
package org.apache.olingo.client.api.domain;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.domain.geospatial.Geospatial;
import org.apache.olingo.client.api.domain.geospatial.GeospatialCollection;
import org.apache.olingo.client.api.domain.geospatial.LineString;
import org.apache.olingo.client.api.domain.geospatial.MultiLineString;
import org.apache.olingo.client.api.domain.geospatial.MultiPoint;
import org.apache.olingo.client.api.domain.geospatial.MultiPolygon;
import org.apache.olingo.client.api.domain.geospatial.Point;
import org.apache.olingo.client.api.domain.geospatial.Polygon;
import org.apache.olingo.client.api.utils.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class ODataGeospatialValue extends ODataPrimitiveValue {
@ -62,17 +40,6 @@ public class ODataGeospatialValue extends ODataPrimitiveValue {
this.ogv = new ODataGeospatialValue(client);
}
/**
* Sets the given value provided as a DOM tree.
*
* @param tree value.
* @return the current builder.
*/
public Builder setTree(final Element tree) {
this.ogv.tree = tree;
return this;
}
/**
* Sets the actual object value.
*
@ -93,14 +60,14 @@ public class ODataGeospatialValue extends ODataPrimitiveValue {
public Builder setType(final ODataJClientEdmPrimitiveType type) {
isSupported(type);
if (!type.isGeospatial()) {
if (type != null && !type.isGeospatial()) {
throw new IllegalArgumentException(
"Use " + ODataPrimitiveValue.class.getSimpleName() + " for non-geospatial types");
}
if (type == ODataJClientEdmPrimitiveType.Geography || type == ODataJClientEdmPrimitiveType.Geometry) {
throw new IllegalArgumentException(
type + "is not an instantiable type. "
type + " is not an instantiable type. "
+ "An entity can declare a property to be of type Geometry. "
+ "An instance of an entity MUST NOT have a value of type Geometry. "
+ "Each value MUST be of some subtype.");
@ -115,33 +82,17 @@ public class ODataGeospatialValue extends ODataPrimitiveValue {
* @return <tt>ODataGeospatialValue</tt> object.
*/
public ODataGeospatialValue build() {
if (this.ogv.tree == null && this.ogv.value == null) {
throw new IllegalArgumentException("Must provide either tree or value");
if (this.ogv.value == null) {
throw new IllegalArgumentException("No Geospatial value provided");
}
if (this.ogv.tree != null && this.ogv.value != null) {
throw new IllegalArgumentException("Cannot provide both tree and value");
}
if (this.ogv.type == null) {
throw new IllegalArgumentException("Must provide geospatial type");
}
if (this.ogv.tree != null) {
this.ogv.value = this.ogv.parseTree(this.ogv.tree, this.ogv.type);
}
if (this.ogv.value != null) {
this.ogv.tree = this.ogv.parseGeospatial((Geospatial) this.ogv.value);
this.ogv.type = ((Geospatial) this.ogv.value).getEdmSimpleType();
}
return this.ogv;
}
}
/**
* DOM tree.
*/
private Element tree;
/**
* Protected constructor, need to use the builder to instantiate this class.
*
@ -151,338 +102,7 @@ public class ODataGeospatialValue extends ODataPrimitiveValue {
super(client);
}
private Geospatial.Dimension getDimension() {
Geospatial.Dimension dimension;
switch (this.type) {
case Geography:
case GeographyCollection:
case GeographyLineString:
case GeographyMultiLineString:
case GeographyPoint:
case GeographyMultiPoint:
case GeographyPolygon:
case GeographyMultiPolygon:
dimension = Geospatial.Dimension.GEOGRAPHY;
break;
default:
dimension = Geospatial.Dimension.GEOMETRY;
}
return dimension;
}
private List<Point> parsePoints(final NodeList posList) {
final List<Point> result = new ArrayList<Point>();
for (int i = 0; i < posList.getLength(); i++) {
final String[] pointInfo = posList.item(i).getTextContent().split(" ");
final Point point = new Point(getDimension());
point.setX(Double.valueOf(pointInfo[0]));
point.setY(Double.valueOf(pointInfo[1]));
result.add(point);
}
return result;
}
private LineString parseLineString(final Element element) {
return new LineString(getDimension(),
parsePoints(element.getElementsByTagName(Constants.ELEM_POS)));
}
private Polygon parsePolygon(final Element element) {
List<Point> extPoints = null;
final Element exterior
= (Element) element.getElementsByTagName(Constants.ELEM_POLYGON_EXTERIOR).item(0);
if (exterior != null) {
extPoints = parsePoints(
((Element) exterior.getElementsByTagName(Constants.ELEM_POLYGON_LINEARRING).item(0)).
getElementsByTagName(Constants.ELEM_POS));
}
List<Point> intPoints = null;
final Element interior
= (Element) element.getElementsByTagName(Constants.ELEM_POLYGON_INTERIOR).item(0);
if (interior != null) {
intPoints = parsePoints(
((Element) interior.getElementsByTagName(Constants.ELEM_POLYGON_LINEARRING).item(0)).
getElementsByTagName(Constants.ELEM_POS));
}
return new Polygon(getDimension(), intPoints, extPoints);
}
/**
* Parses given tree as geospatial value.
*/
private Geospatial parseTree(final Element tree, final ODataJClientEdmPrimitiveType type) {
Geospatial value;
switch (type) {
case GeographyPoint:
case GeometryPoint:
value = parsePoints(tree.getElementsByTagName(Constants.ELEM_POS)).get(0);
break;
case GeographyMultiPoint:
case GeometryMultiPoint:
final Element pMembs
= (Element) tree.getElementsByTagName(Constants.ELEM_POINTMEMBERS).item(0);
final List<Point> points = pMembs == null
? Collections.<Point>emptyList()
: parsePoints(pMembs.getElementsByTagName(Constants.ELEM_POS));
value = new MultiPoint(getDimension(), points);
break;
case GeographyLineString:
case GeometryLineString:
value = parseLineString(tree);
break;
case GeographyMultiLineString:
case GeometryMultiLineString:
final Element mlMembs
= (Element) tree.getElementsByTagName(Constants.ELEM_LINESTRINGMEMBERS).item(0);
final List<LineString> lineStrings;
if (mlMembs == null) {
lineStrings = Collections.<LineString>emptyList();
} else {
lineStrings = new ArrayList<LineString>();
final NodeList lineStringNodes = mlMembs.getElementsByTagName(Constants.ELEM_LINESTRING);
for (int i = 0; i < lineStringNodes.getLength(); i++) {
lineStrings.add(parseLineString((Element) lineStringNodes.item(i)));
}
}
value = new MultiLineString(getDimension(), lineStrings);
break;
case GeographyPolygon:
case GeometryPolygon:
value = parsePolygon(tree);
break;
case GeographyMultiPolygon:
case GeometryMultiPolygon:
final Element mpMembs
= (Element) tree.getElementsByTagName(Constants.ELEM_SURFACEMEMBERS).item(0);
final List<Polygon> polygons;
if (mpMembs == null) {
polygons = Collections.<Polygon>emptyList();
} else {
polygons = new ArrayList<Polygon>();
final NodeList polygonNodes = mpMembs.getElementsByTagName(Constants.ELEM_POLYGON);
for (int i = 0; i < polygonNodes.getLength(); i++) {
polygons.add(parsePolygon((Element) polygonNodes.item(i)));
}
}
value = new MultiPolygon(getDimension(), polygons);
break;
case GeographyCollection:
case GeometryCollection:
final Element cMembs
= (Element) tree.getElementsByTagName(Constants.ELEM_GEOMEMBERS).item(0);
final List<Geospatial> geospatials;
if (cMembs == null) {
geospatials = Collections.<Geospatial>emptyList();
} else {
geospatials = new ArrayList<Geospatial>();
for (Node geom : XMLUtils.getChildNodes(cMembs, Node.ELEMENT_NODE)) {
geospatials.add(parseTree((Element) geom, XMLUtils.simpleTypeForNode(getDimension(), geom)));
}
}
value = new GeospatialCollection(getDimension(), geospatials);
break;
default:
value = null;
}
return value;
}
private void parsePoints(final Element parent, final Iterator<Point> itor, final boolean wrap) {
while (itor.hasNext()) {
final Point point = itor.next();
final Element pos = parent.getOwnerDocument().
createElementNS(Constants.NS_GML, Constants.ELEM_POS);
pos.appendChild(parent.getOwnerDocument().createTextNode(
Double.toString(point.getX()) + " " + point.getY()));
final Element appendable;
if (wrap) {
final Element epoint = parent.getOwnerDocument().
createElementNS(Constants.NS_GML, Constants.ELEM_POINT);
parent.appendChild(epoint);
appendable = epoint;
} else {
appendable = parent;
}
appendable.appendChild(pos);
}
}
private void parseLineStrings(final Element parent, final Iterator<LineString> itor, final boolean wrap) {
while (itor.hasNext()) {
final LineString lineString = itor.next();
final Element appendable;
if (wrap) {
final Element eLineString = parent.getOwnerDocument().
createElementNS(Constants.NS_GML, Constants.ELEM_LINESTRING);
parent.appendChild(eLineString);
appendable = eLineString;
} else {
appendable = parent;
}
parsePoints(appendable, lineString.iterator(), false);
}
}
private void parsePolygons(final Element parent, final Iterator<Polygon> itor, final boolean wrap) {
while (itor.hasNext()) {
final Polygon polygon = itor.next();
final Element appendable;
if (wrap) {
final Element ePolygon = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_POLYGON);
parent.appendChild(ePolygon);
appendable = ePolygon;
} else {
appendable = parent;
}
if (!polygon.getExterior().isEmpty()) {
final Element exterior = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_POLYGON_EXTERIOR);
appendable.appendChild(exterior);
final Element linearRing = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_POLYGON_LINEARRING);
exterior.appendChild(linearRing);
parsePoints(linearRing, polygon.getExterior().iterator(), false);
}
if (!polygon.getInterior().isEmpty()) {
final Element interior = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_POLYGON_INTERIOR);
appendable.appendChild(interior);
final Element linearRing = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_POLYGON_LINEARRING);
interior.appendChild(linearRing);
parsePoints(linearRing, polygon.getInterior().iterator(), false);
}
}
}
private Element parseGeospatial(final Geospatial value) {
final DocumentBuilder builder;
try {
builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new IllegalStateException("Failure initializing Geospatial DOM tree", e);
}
final Document doc = builder.newDocument();
final Element tree;
switch (value.getEdmSimpleType()) {
case GeographyPoint:
case GeometryPoint:
tree = doc.createElementNS(Constants.NS_GML, Constants.ELEM_POINT);
parsePoints(tree, Collections.singleton((Point) value).iterator(), false);
break;
case GeometryMultiPoint:
case GeographyMultiPoint:
tree = doc.createElementNS(Constants.NS_GML, Constants.ELEM_MULTIPOINT);
final Element pMembs = doc.createElementNS(Constants.NS_GML, Constants.ELEM_POINTMEMBERS);
tree.appendChild(pMembs);
parsePoints(pMembs, ((MultiPoint) value).iterator(), true);
break;
case GeometryLineString:
case GeographyLineString:
tree = doc.createElementNS(Constants.NS_GML, Constants.ELEM_LINESTRING);
parseLineStrings(tree, Collections.singleton((LineString) value).iterator(), false);
break;
case GeometryMultiLineString:
case GeographyMultiLineString:
tree = doc.createElementNS(Constants.NS_GML, Constants.ELEM_MULTILINESTRING);
final Element mlMembs
= doc.createElementNS(Constants.NS_GML, Constants.ELEM_LINESTRINGMEMBERS);
tree.appendChild(mlMembs);
parseLineStrings(mlMembs, ((MultiLineString) value).iterator(), true);
break;
case GeographyPolygon:
case GeometryPolygon:
tree = doc.createElementNS(Constants.NS_GML, Constants.ELEM_POLYGON);
parsePolygons(tree, Collections.singleton(((Polygon) value)).iterator(), false);
break;
case GeographyMultiPolygon:
case GeometryMultiPolygon:
tree = doc.createElementNS(Constants.NS_GML, Constants.ELEM_MULTIPOLYGON);
final Element mpMembs
= doc.createElementNS(Constants.NS_GML, Constants.ELEM_SURFACEMEMBERS);
tree.appendChild(mpMembs);
parsePolygons(mpMembs, ((MultiPolygon) value).iterator(), true);
break;
case GeographyCollection:
case GeometryCollection:
tree = doc.createElementNS(Constants.NS_GML, Constants.ELEM_GEOCOLLECTION);
final Element gMembs
= doc.createElementNS(Constants.NS_GML, Constants.ELEM_GEOMEMBERS);
tree.appendChild(gMembs);
final Iterator<Geospatial> itor = ((GeospatialCollection) value).iterator();
while (itor.hasNext()) {
final Geospatial geospatial = itor.next();
gMembs.appendChild(doc.importNode(parseGeospatial(geospatial), true));
}
break;
default:
tree = null;
}
return tree;
}
public Element toTree() {
return this.tree;
}
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final ODataGeospatialValue other = (ODataGeospatialValue) obj;
return this.tree.isEqualNode(other.tree);
}
@Override
public String toString() {
final StringWriter writer = new StringWriter();
client.getSerializer().dom(this.tree, writer);
return writer.toString();
public Geospatial getGeospatial() {
return (Geospatial) this.value;
}
}

View File

@ -38,7 +38,7 @@ public class ODataJClientEdmType {
private boolean collection;
private ODataJClientEdmPrimitiveType simpleType;
private ODataJClientEdmPrimitiveType primitiveType;
private EnumType enumType;
@ -88,7 +88,7 @@ public class ODataJClientEdmType {
}
if (namespaceOrAlias.equals(ODataJClientEdmPrimitiveType.namespace())) {
this.simpleType = ODataJClientEdmPrimitiveType.fromValue(
this.primitiveType = ODataJClientEdmPrimitiveType.fromValue(
ODataJClientEdmPrimitiveType.namespace() + "." + typeName);
} else if (metadata != null) {
if (!metadata.isNsOrAlias(namespaceOrAlias)) {
@ -116,7 +116,7 @@ public class ODataJClientEdmType {
}
}
if (!isSimpleType() && !isEnumType() && !isComplexType() && !isEntityType()) {
if (!isPrimitiveType() && !isEnumType() && !isComplexType() && !isEntityType()) {
throw new IllegalArgumentException("Could not parse type information out of " + typeExpression);
}
}
@ -136,8 +136,12 @@ public class ODataJClientEdmType {
*
* @return 'TRUE' if is a simple type; 'FALSE' otherwise.
*/
public final boolean isSimpleType() {
return this.simpleType != null;
public final boolean isPrimitiveType() {
return this.primitiveType != null;
}
public boolean isGeospatialType() {
return isPrimitiveType() && this.primitiveType.isGeospatial();
}
/**
@ -145,12 +149,12 @@ public class ODataJClientEdmType {
*
* @return simple type. An <tt>EdmTypeNotFoundException</tt> will be raised if it is not a simple type.
*/
public final ODataJClientEdmPrimitiveType getSimpleType() {
if (!isSimpleType()) {
public final ODataJClientEdmPrimitiveType getPrimitiveType() {
if (!isPrimitiveType()) {
throw new IllegalArgumentException("Cannot find Primitive in " + this.typeExpression);
}
return this.simpleType;
return this.primitiveType;
}
/**

View File

@ -29,6 +29,53 @@ public class ODataLink extends ODataItem {
private static final long serialVersionUID = 7274966414277952124L;
public static class Builder {
private ODataServiceVersion version;
private URI uri;
private ODataLinkType type;
private String title;
private String mediaETag;
public Builder setVersion(final ODataServiceVersion version) {
this.version = version;
return this;
}
public Builder setURI(final URI uri) {
this.uri = uri;
return this;
}
public Builder setURI(final URI baseURI, final String href) {
this.uri = URIUtils.getURI(baseURI, href);
return this;
}
public Builder setType(final ODataLinkType type) {
this.type = type;
return this;
}
public Builder setTitle(final String title) {
this.title = title;
return this;
}
public void setMediaETag(final String mediaETag) {
this.mediaETag = mediaETag;
}
public ODataLink build() {
ODataLink instance = new ODataLink(version, uri, type, title);
instance.mediaETag = this.mediaETag;
return instance;
}
}
/**
* Link type.
*/
@ -39,6 +86,11 @@ public class ODataLink extends ODataItem {
*/
protected final String rel;
/**
* ETag for media edit links.
*/
private String mediaETag;
/**
* Constructor.
*
@ -47,7 +99,7 @@ public class ODataLink extends ODataItem {
* @param type type.
* @param title title.
*/
public ODataLink(final ODataServiceVersion version, final URI uri, final ODataLinkType type, final String title) {
protected ODataLink(final ODataServiceVersion version, final URI uri, final ODataLinkType type, final String title) {
super(title);
this.link = uri;
@ -79,7 +131,7 @@ public class ODataLink extends ODataItem {
* @param type type.
* @param title title.
*/
public ODataLink(final ODataServiceVersion version,
protected ODataLink(final ODataServiceVersion version,
final URI baseURI, final String href, final ODataLinkType type, final String title) {
this(version, URIUtils.getURI(baseURI, href), type, title);
@ -102,4 +154,14 @@ public class ODataLink extends ODataItem {
public String getRel() {
return rel;
}
/**
* Gets Media ETag.
*
* @return media ETag
*/
public String getMediaETag() {
return mediaETag;
}
}

View File

@ -20,7 +20,6 @@ package org.apache.olingo.client.api.domain;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.ContentType;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
@ -65,9 +64,9 @@ public enum ODataLinkType {
* @param type type.
* @return <code>ODataLinkType</code> object.
*/
public static ODataLinkType fromString(final ODataClient client, final String rel, final String type) {
if (StringUtils.isNotBlank(rel) && rel.startsWith(client.getServiceVersion().getNamespaceMap().
get(ODataServiceVersion.MEDIA_EDIT_LINK_REL))) {
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))) {
return MEDIA_EDIT.setType(StringUtils.isBlank(type) ? "*/*" : type);
}

View File

@ -31,10 +31,6 @@ import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.domain.ODataDuration;
import org.apache.olingo.client.api.domain.ODataTimestamp;
import org.apache.olingo.client.api.domain.ODataValue;
/**
* OData primitive property value.

View File

@ -23,40 +23,12 @@ import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.olingo.client.api.domain.ODataCollectionValue;
import org.apache.olingo.client.api.domain.ODataComplexValue;
import org.apache.olingo.client.api.domain.ODataPrimitiveValue;
import org.apache.olingo.client.api.domain.ODataValue;
/**
* OData entity property.
*/
public class ODataProperty implements Serializable, ODataInvokeResult {
/**
* Property type.
*/
public enum PropertyType {
/**
* Primitive.
*/
PRIMITIVE,
/**
* Collection
*/
COLLECTION,
/**
* Complex.
*/
COMPLEX,
/**
* Empty type (possibly, no type information could be retrieved).
*/
EMPTY
}
private static final long serialVersionUID = 926939448778950450L;
/**

View File

@ -16,31 +16,25 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.client.core.xml;
package org.apache.olingo.client.api.domain;
import java.io.InputStream;
import java.io.Writer;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* DOM Parser.
*/
public abstract class AbstractDOMParser {
public enum ODataPropertyType {
/**
* Parses the given input into a DOM tree.
*
* @param input stream to be parsed and de-serialized.
* @return DOM tree
* Primitive (including geospatial and enum).
*/
public abstract Element deserialize(InputStream input);
PRIMITIVE,
/**
* Writes DOM object by the given writer.
*
* @param content DOM to be streamed.
* @param writer writer.
* Collection
*/
public abstract void serialize(Node content, Writer writer);
COLLECTION,
/**
* Complex.
*/
COMPLEX,
/**
* Empty type (possibly, no type information could be retrieved).
*/
EMPTY
}

View File

@ -36,10 +36,13 @@ public abstract class ComposedGeospatial<T extends Geospatial> extends Geospatia
*
* @param dimension dimension.
* @param type type.
* @param crs crs.
* @param geospatials geospatials info.
*/
protected ComposedGeospatial(final Dimension dimension, final Type type, final List<T> geospatials) {
super(dimension, type);
protected ComposedGeospatial(final Dimension dimension, final Type type, final String crs,
final List<T> geospatials) {
super(dimension, type, crs);
this.geospatials = new ArrayList<T>();
if (geospatials != null) {
this.geospatials.addAll(geospatials);

View File

@ -27,22 +27,23 @@ import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
*/
public class GeospatialCollection extends ComposedGeospatial<Geospatial> {
private static final long serialVersionUID = -9181547636133878977L;
private static final long serialVersionUID = -9181547636133878977L;
/**
* Constructor.
*
* @param dimension dimension.
* @param geospatials geospatials info.
*/
public GeospatialCollection(final Dimension dimension, final List<Geospatial> geospatials) {
super(dimension, Type.GEOSPATIALCOLLECTION, geospatials);
}
/**
* Constructor.
*
* @param dimension dimension.
* @param crs crs.
* @param geospatials geospatials info.
*/
public GeospatialCollection(final Dimension dimension, final String crs, final List<Geospatial> geospatials) {
super(dimension, Type.GEOSPATIALCOLLECTION, crs, geospatials);
}
@Override
public ODataJClientEdmPrimitiveType getEdmSimpleType() {
return dimension == Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyCollection
: ODataJClientEdmPrimitiveType.GeometryCollection;
}
@Override
public ODataJClientEdmPrimitiveType getEdmSimpleType() {
return dimension == Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyCollection
: ODataJClientEdmPrimitiveType.GeometryCollection;
}
}

View File

@ -24,16 +24,16 @@ import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
public class LineString extends ComposedGeospatial<Point> {
private static final long serialVersionUID = 3207958185407535907L;
private static final long serialVersionUID = 3207958185407535907L;
public LineString(final Dimension dimension, final List<Point> points) {
super(dimension, Type.LINESTRING, points);
}
public LineString(final Dimension dimension, final String crs, final List<Point> points) {
super(dimension, Type.LINESTRING, crs, points);
}
@Override
public ODataJClientEdmPrimitiveType getEdmSimpleType() {
return dimension == Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyLineString
: ODataJClientEdmPrimitiveType.GeometryLineString;
}
@Override
public ODataJClientEdmPrimitiveType getEdmSimpleType() {
return dimension == Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyLineString
: ODataJClientEdmPrimitiveType.GeometryLineString;
}
}

View File

@ -26,8 +26,8 @@ public class MultiLineString extends ComposedGeospatial<LineString> {
private static final long serialVersionUID = -5042414471218124125L;
public MultiLineString(final Dimension dimension, final List<LineString> lineStrings) {
super(dimension, Type.MULTILINESTRING, lineStrings);
public MultiLineString(final Dimension dimension, final String crs, final List<LineString> lineStrings) {
super(dimension, Type.MULTILINESTRING, crs, lineStrings);
}
@Override

View File

@ -26,8 +26,8 @@ public class MultiPoint extends ComposedGeospatial<Point> {
private static final long serialVersionUID = 4951011255142116129L;
public MultiPoint(final Dimension dimension, final List<Point> points) {
super(dimension, Type.MULTIPOINT, points);
public MultiPoint(final Dimension dimension, final String crs, final List<Point> points) {
super(dimension, Type.MULTIPOINT, crs, points);
}
@Override

View File

@ -26,8 +26,8 @@ public class MultiPolygon extends ComposedGeospatial<Polygon> {
private static final long serialVersionUID = -160184788048512883L;
public MultiPolygon(final Dimension dimension, final List<Polygon> polygons) {
super(dimension, Type.MULTIPOLYGON, polygons);
public MultiPolygon(final Dimension dimension, final String crs, final List<Polygon> polygons) {
super(dimension, Type.MULTIPOLYGON, crs, polygons);
}
@Override

View File

@ -40,8 +40,8 @@ public class Point extends Geospatial {
*/
private double z;
public Point(final Dimension dimension) {
super(dimension, Type.POINT);
public Point(final Dimension dimension, final String crs) {
super(dimension, Type.POINT, crs);
}
public double getX() {

View File

@ -37,13 +37,14 @@ public class Polygon extends Geospatial {
* Constructor.
*
* @param dimension dimension.
* @param crs crs.
* @param interior interior points.
* @param exterior exterior points.
*/
public Polygon(final Dimension dimension, final List<Point> interior, final List<Point> exterior) {
super(dimension, Type.POLYGON);
this.interior = new MultiPoint(dimension, interior);
this.exterior = new MultiPoint(dimension, exterior);
public Polygon(final Dimension dimension, final String crs, final List<Point> interior, final List<Point> exterior) {
super(dimension, Type.POLYGON, crs);
this.interior = new MultiPoint(dimension, crs, interior);
this.exterior = new MultiPoint(dimension, crs, exterior);
}
/**

View File

@ -24,6 +24,7 @@ import org.apache.olingo.client.api.data.Entry;
import org.apache.olingo.client.api.data.Feed;
import org.apache.olingo.client.api.data.Link;
import org.apache.olingo.client.api.data.LinkCollection;
import org.apache.olingo.client.api.data.Property;
import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.client.api.domain.ODataEntity;
import org.apache.olingo.client.api.domain.ODataEntitySet;
@ -31,7 +32,6 @@ import org.apache.olingo.client.api.domain.ODataLink;
import org.apache.olingo.client.api.domain.ODataLinkCollection;
import org.apache.olingo.client.api.domain.ODataProperty;
import org.apache.olingo.client.api.domain.ODataServiceDocument;
import org.w3c.dom.Element;
public interface ODataBinder extends Serializable {
@ -73,12 +73,14 @@ public interface ODataBinder extends Serializable {
Link getLink(ODataLink link, boolean isXML);
/**
* Gets the given OData property as DOM element.
* Gets a <tt>Property</tt> from the given OData property.
*
* @param prop OData property.
* @return <tt>Element</tt> object.
* @param property OData property.
* @param reference reference class.
* @param setType whether to explicitly output type information.
* @return <tt>Property</tt> object.
*/
Element toDOMElement(ODataProperty prop);
Property getProperty(ODataProperty property, Class<? extends Entry> reference, boolean setType);
/**
* Gets <tt>ODataServiceDocument</tt> from the given service document resource.
@ -123,12 +125,12 @@ public interface ODataBinder extends Serializable {
ODataEntity getODataEntity(Entry resource, URI defaultBaseURI);
/**
* Gets an <tt>ODataProperty</tt> from the given DOM element.
* Gets an <tt>ODataProperty</tt> from the given property resource.
*
* @param property content.
* @param property property resource.
* @return <tt>ODataProperty</tt> object.
*/
ODataProperty getODataProperty(Element property);
ODataProperty getODataProperty(Property property);
/**
* Gets <tt>ODataLinkCollection</tt> from the given link collection resource.

View File

@ -24,11 +24,11 @@ import org.apache.olingo.client.api.data.Entry;
import org.apache.olingo.client.api.data.Error;
import org.apache.olingo.client.api.data.Feed;
import org.apache.olingo.client.api.data.LinkCollection;
import org.apache.olingo.client.api.data.Property;
import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.client.api.edm.xml.XMLMetadata;
import org.apache.olingo.client.api.format.ODataFormat;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.w3c.dom.Element;
/**
* Utility class for serialization.
@ -65,13 +65,13 @@ public interface ODataDeserializer extends Serializable {
Entry toEntry(InputStream input, ODataPubFormat format);
/**
* Gets a DOM representation of the given InputStream.
* Gets a property object from the given InputStream.
*
* @param input stream to be de-serialized.
* @param format XML or JSON
* @return DOM.
* @return Property instance.
*/
Element toPropertyDOM(InputStream input, ODataFormat format);
Property toProperty(InputStream input, ODataFormat format);
/**
* Gets the ODataError object represented by the given InputStream.
@ -82,14 +82,6 @@ public interface ODataDeserializer extends Serializable {
*/
Error toError(InputStream input, boolean isXML);
/**
* Parses the given input into a DOM tree.
*
* @param input stream to be parsed and de-serialized.
* @return DOM tree
*/
Element toDOM(InputStream input);
/**
* Gets a list of links from the given InputStream.
*

View File

@ -24,9 +24,8 @@ import java.io.Writer;
import org.apache.olingo.client.api.data.Entry;
import org.apache.olingo.client.api.data.Feed;
import org.apache.olingo.client.api.data.Link;
import org.apache.olingo.client.api.data.Property;
import org.apache.olingo.client.api.format.ODataFormat;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* Utility class for serialization.
@ -66,22 +65,20 @@ public interface ODataSerializer extends Serializable {
void entry(Entry obj, Writer writer);
/**
* Writes entry content onto the given stream.
* Writes the property object onto the given stream.
*
* @param element element to be streamed.
* @param format streaming format.
* @param property object to be streamed.
* @param out output stream.
*/
void property(Element element, ODataFormat format, OutputStream out);
void property(Property property, OutputStream out);
/**
* Writes entry content by the given writer.
* Writes the property object by the given writer.
*
* @param element element to be streamed.
* @param format streaming format.
* @param property object to be streamed.
* @param writer writer.
*/
void property(Element element, ODataFormat format, Writer writer);
void property(Property property, Writer writer);
/**
* Writes link onto the given stream.
@ -100,20 +97,4 @@ public interface ODataSerializer extends Serializable {
* @param writer writer.
*/
void link(Link link, ODataFormat format, Writer writer);
/**
* Writes DOM object onto the given stream.
*
* @param content DOM to be streamed.
* @param out output stream.
*/
void dom(Node content, OutputStream out);
/**
* Writes DOM object by the given writer.
*
* @param content DOM to be streamed.
* @param writer writer.
*/
void dom(Node content, Writer writer);
}

View File

@ -0,0 +1,90 @@
/*
* 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.client.api.utils;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.domain.geospatial.Geospatial;
public final class GeoUtils {
private GeoUtils() {
// Empty private constructor for static utility classes
}
public static Geospatial.Dimension getDimension(final ODataJClientEdmPrimitiveType type) {
Geospatial.Dimension dimension;
switch (type) {
case Geography:
case GeographyCollection:
case GeographyLineString:
case GeographyMultiLineString:
case GeographyPoint:
case GeographyMultiPoint:
case GeographyPolygon:
case GeographyMultiPolygon:
dimension = Geospatial.Dimension.GEOGRAPHY;
break;
default:
dimension = Geospatial.Dimension.GEOMETRY;
}
return dimension;
}
public static ODataJClientEdmPrimitiveType getType(final Geospatial.Dimension dimension, final String elementName) {
ODataJClientEdmPrimitiveType type = null;
if (Constants.ELEM_POINT.equals(elementName)) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyPoint
: ODataJClientEdmPrimitiveType.GeometryPoint;
} else if (Constants.ELEM_MULTIPOINT.equals(elementName)) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyMultiPoint
: ODataJClientEdmPrimitiveType.GeometryMultiPoint;
} else if (Constants.ELEM_LINESTRING.equals(elementName)) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyLineString
: ODataJClientEdmPrimitiveType.GeometryLineString;
} else if (Constants.ELEM_MULTILINESTRING.equals(elementName)) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyMultiLineString
: ODataJClientEdmPrimitiveType.GeometryMultiLineString;
} else if (Constants.ELEM_POLYGON.equals(elementName)) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyPolygon
: ODataJClientEdmPrimitiveType.GeometryPolygon;
} else if (Constants.ELEM_MULTIPOLYGON.equals(elementName)) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyMultiPolygon
: ODataJClientEdmPrimitiveType.GeometryMultiPolygon;
} else if (Constants.ELEM_GEOCOLLECTION.equals(elementName)
|| Constants.ELEM_GEOMEMBERS.equals(elementName)) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyCollection
: ODataJClientEdmPrimitiveType.GeometryCollection;
}
return type;
}
}

View File

@ -1,178 +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.client.api.utils;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.domain.geospatial.Geospatial;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* XML utilities.
*/
public final class XMLUtils {
/**
* DOM factory.
*/
public static final DocumentBuilderFactory DOC_BUILDER_FACTORY = DocumentBuilderFactory.newInstance();
private XMLUtils() {
// Empty private constructor for static utility classes
}
/**
* Gets XML node name.
*
* @param node node.
* @return node name.
*/
public static String getSimpleName(final Node node) {
return node.getLocalName() == null
? node.getNodeName().substring(node.getNodeName().indexOf(':') + 1)
: node.getLocalName();
}
/**
* Gets the given node's children of the given type.
*
* @param node parent.
* @param nodetype searched child type.
* @return children.
*/
public static List<Node> getChildNodes(final Node node, final short nodetype) {
final List<Node> result = new ArrayList<Node>();
final NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
final Node child = children.item(i);
if (child.getNodeType() == nodetype) {
result.add(child);
}
}
return result;
}
/**
* Gets the given node's children with the given name.
*
* @param node parent.
* @param name searched child name.
* @return children.
*/
public static List<Element> getChildElements(final Element node, final String name) {
final List<Element> result = new ArrayList<Element>();
if (StringUtils.isNotBlank(name)) {
final NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
final Node child = children.item(i);
if ((child instanceof Element) && name.equals(child.getNodeName())) {
result.add((Element) child);
}
}
}
return result;
}
/**
* Checks if the given node has <tt>element</tt> children.
*
* @param node parent.
* @return 'TRUE' if the given node has at least one <tt>element</tt> child; 'FALSE' otherwise.
*/
public static boolean hasElementsChildNode(final Node node) {
boolean found = false;
for (Node child : getChildNodes(node, Node.ELEMENT_NODE)) {
if (Constants.ELEM_ELEMENT.equals(XMLUtils.getSimpleName(child))) {
found = true;
}
}
return found;
}
/**
* Checks if the given node has only text children.
*
* @param node parent.
* @return 'TRUE' if the given node has only text children; 'FALSE' otherwise.
*/
public static boolean hasOnlyTextChildNodes(final Node node) {
boolean result = true;
final NodeList children = node.getChildNodes();
for (int i = 0; result && i < children.getLength(); i++) {
final Node child = children.item(i);
if (child.getNodeType() != Node.TEXT_NODE) {
result = false;
}
}
return result;
}
public static ODataJClientEdmPrimitiveType simpleTypeForNode(final Geospatial.Dimension dimension, final Node node) {
ODataJClientEdmPrimitiveType type = null;
if (Constants.ELEM_POINT.equals(node.getNodeName())) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyPoint
: ODataJClientEdmPrimitiveType.GeometryPoint;
} else if (Constants.ELEM_MULTIPOINT.equals(node.getNodeName())) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyMultiPoint
: ODataJClientEdmPrimitiveType.GeometryMultiPoint;
} else if (Constants.ELEM_LINESTRING.equals(node.getNodeName())) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyLineString
: ODataJClientEdmPrimitiveType.GeometryLineString;
} else if (Constants.ELEM_MULTILINESTRING.equals(node.getNodeName())) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyMultiLineString
: ODataJClientEdmPrimitiveType.GeometryMultiLineString;
} else if (Constants.ELEM_POLYGON.equals(node.getNodeName())) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyPolygon
: ODataJClientEdmPrimitiveType.GeometryPolygon;
} else if (Constants.ELEM_MULTIPOLYGON.equals(node.getNodeName())) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyMultiPolygon
: ODataJClientEdmPrimitiveType.GeometryMultiPolygon;
} else if (Constants.ELEM_GEOCOLLECTION.equals(node.getNodeName())
|| Constants.ELEM_GEOMEMBERS.equals(node.getNodeName())) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyCollection
: ODataJClientEdmPrimitiveType.GeometryCollection;
}
return type;
}
}

View File

@ -75,6 +75,10 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>

View File

@ -0,0 +1,80 @@
/*
* 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.client.core.data;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
abstract class AbstractAtomDealer {
protected static final String TYPE_TEXT = "text";
protected final ODataServiceVersion version;
protected final QName etagQName;
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;
public AbstractAtomDealer(final ODataServiceVersion version) {
this.version = version;
this.etagQName =
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ATTR_ETAG);
this.inlineQName =
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_INLINE);
this.actionQName =
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_ACTION);
this.propertiesQName =
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES);
this.typeQName = new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATTR_TYPE);
this.nullQName = new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATTR_NULL);
this.elementQName =
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES), Constants.ELEM_ELEMENT);
this.countQName =
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_COUNT);
}
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_GML, Constants.NS_GML);
writer.writeNamespace(Constants.PREFIX_GEORSS, Constants.NS_GEORSS);
}
}

View File

@ -0,0 +1,78 @@
/*
* 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.client.core.data;
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
import java.net.URI;
import java.text.ParseException;
import java.util.Date;
abstract class AbstractAtomObject extends AbstractPayloadObject {
private static final long serialVersionUID = -4391162864875546927L;
private static final ISO8601DateFormat ISO_DATEFORMAT = new ISO8601DateFormat();
private URI baseURI;
private String id;
private String title;
private String summary;
private Date updated;
public URI getBaseURI() {
return baseURI;
}
public void setBaseURI(final String baseURI) {
this.baseURI = URI.create(baseURI);
}
public String getId() {
return id;
}
public String getTitle() {
return title;
}
public String getSummary() {
return summary;
}
public Date getUpdated() {
return updated;
}
public void setCommonProperty(final String key, final String value) throws ParseException {
if ("id".equals(key)) {
this.id = value;
} else if ("title".equals(key)) {
this.title = value;
} else if ("summary".equals(key)) {
this.summary = value;
} else if ("updated".equals(key)) {
this.updated = ISO_DATEFORMAT.parse(value);
}
}
}

View File

@ -23,13 +23,13 @@ import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.data.Entry;
import org.apache.olingo.client.api.data.Link;
import org.apache.olingo.client.api.data.Property;
import org.apache.olingo.client.api.domain.ODataOperation;
import org.w3c.dom.Element;
/**
* Abstract base for classes implementing an OData entry in Atom and JSON.
*/
public abstract class AbstractEntry extends AbstractPayloadObject implements Entry {
public abstract class AbstractEntry extends AbstractAtomObject implements Entry {
private static final long serialVersionUID = 2127764552600969783L;
@ -37,8 +37,6 @@ public abstract class AbstractEntry extends AbstractPayloadObject implements Ent
private String type;
private String id;
private Link readLink;
private Link editLink;
@ -51,9 +49,7 @@ public abstract class AbstractEntry extends AbstractPayloadObject implements Ent
private final List<ODataOperation> operations = new ArrayList<ODataOperation>();
private Element content;
private Element mediaEntryProperties;
private final List<Property> properties = new ArrayList<Property>();
private String mediaContentSource;
@ -64,7 +60,6 @@ public abstract class AbstractEntry extends AbstractPayloadObject implements Ent
return eTag;
}
@Override
public void setETag(final String eTag) {
this.eTag = eTag;
}
@ -79,16 +74,6 @@ public abstract class AbstractEntry extends AbstractPayloadObject implements Ent
this.type = type;
}
@Override
public String getId() {
return id;
}
@Override
public void setId(final String id) {
this.id = id;
}
@Override
public Link getSelfLink() {
return readLink;
@ -130,26 +115,21 @@ public abstract class AbstractEntry extends AbstractPayloadObject implements Ent
}
@Override
public Element getContent() {
return content;
public List<Property> getProperties() {
return properties;
}
@Override
public void setContent(final Element content) {
this.content = content;
}
public Property getProperty(final String name) {
Property result = null;
/**
* {@inheritDoc }
*/
@Override
public Element getMediaEntryProperties() {
return mediaEntryProperties;
}
for (Property property : properties) {
if (name.equals(property.getName())) {
result = property;
}
}
@Override
public void setMediaEntryProperties(final Element mediaEntryProperties) {
this.mediaEntryProperties = mediaEntryProperties;
return result;
}
@Override
@ -174,6 +154,6 @@ public abstract class AbstractEntry extends AbstractPayloadObject implements Ent
@Override
public boolean isMediaEntry() {
return getMediaEntryProperties() != null || StringUtils.isNotBlank(this.mediaContentSource);
return StringUtils.isNotBlank(this.mediaContentSource);
}
}

View File

@ -0,0 +1,171 @@
/*
* 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.client.core.data;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.Iterator;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.data.CollectionValue;
import org.apache.olingo.client.api.data.ComplexValue;
import org.apache.olingo.client.api.data.Value;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.domain.ODataJClientEdmType;
import org.apache.olingo.client.api.domain.ODataPropertyType;
abstract class AbstractJsonDeserializer<T> extends ODataJacksonDeserializer<T> {
private final JSONGeoValueDeserializer geoDeserializer = new JSONGeoValueDeserializer();
protected ODataJClientEdmPrimitiveType getPrimitiveType(final JsonNode node) {
ODataJClientEdmPrimitiveType result = ODataJClientEdmPrimitiveType.String;
if (node.isIntegralNumber()) {
result = ODataJClientEdmPrimitiveType.Int32;
} else if (node.isBoolean()) {
result = ODataJClientEdmPrimitiveType.Boolean;
} else if (node.isFloatingPointNumber()) {
result = ODataJClientEdmPrimitiveType.Double;
}
return result;
}
private ODataPropertyType guessPropertyType(final JsonNode node) {
ODataPropertyType type = null;
if (node.isValueNode() || node.isNull()) {
type = ODataPropertyType.PRIMITIVE;
} else if (node.isArray()) {
type = ODataPropertyType.COLLECTION;
} else if (node.isObject()) {
type = ODataPropertyType.COMPLEX;
} else {
type = ODataPropertyType.EMPTY;
}
return type;
}
private Value fromPrimitive(final JsonNode node, final ODataJClientEdmType typeInfo) {
Value value = null;
if (node.isNull()) {
value = new NullValueImpl();
} else {
if (typeInfo != null && typeInfo.isGeospatialType()) {
final ODataJClientEdmPrimitiveType geoType = ODataJClientEdmPrimitiveType.fromValue(typeInfo.getBaseType());
value = new GeospatialValueImpl(this.geoDeserializer.deserialize(node, geoType));
} else {
value = new PrimitiveValueImpl(node.asText());
}
}
return value;
}
private ComplexValue fromComplex(final JsonNode node) {
final ComplexValue value = new ComplexValueImpl();
String type = null;
for (final Iterator<Map.Entry<String, JsonNode>> itor = node.fields(); itor.hasNext();) {
final Map.Entry<String, JsonNode> field = itor.next();
if (type == null && field.getKey().endsWith(Constants.JSON_TYPE_SUFFIX)) {
type = field.getValue().asText();
} else {
final JSONPropertyImpl property = new JSONPropertyImpl();
property.setName(field.getKey());
property.setType(type);
type = null;
value(property, field.getValue());
value.get().add(property);
}
}
return value;
}
private CollectionValue fromCollection(final Iterator<JsonNode> nodeItor, final ODataJClientEdmType typeInfo) {
final CollectionValueImpl value = new CollectionValueImpl();
final ODataJClientEdmType type = typeInfo == null
? null
: new ODataJClientEdmType(typeInfo.getBaseType());
while (nodeItor.hasNext()) {
final JsonNode child = nodeItor.next();
if (child.isValueNode()) {
value.get().add(fromPrimitive(child, type));
} else if (child.isContainerNode()) {
if (child.has(Constants.JSON_TYPE)) {
((ObjectNode) child).remove(Constants.JSON_TYPE);
}
value.get().add(fromComplex(child));
}
}
return value;
}
protected void value(final JSONPropertyImpl property, final JsonNode node) {
final ODataJClientEdmType typeInfo = StringUtils.isBlank(property.getType())
? null
: new ODataJClientEdmType(property.getType());
final ODataPropertyType propType = typeInfo == null
? guessPropertyType(node)
: typeInfo.isCollection()
? ODataPropertyType.COLLECTION
: typeInfo.isPrimitiveType()
? ODataPropertyType.PRIMITIVE
: ODataPropertyType.COMPLEX;
switch (propType) {
case COLLECTION:
property.setValue(fromCollection(node.elements(), typeInfo));
break;
case COMPLEX:
if (node.has(Constants.JSON_TYPE)) {
property.setType(node.get(Constants.JSON_TYPE).asText());
((ObjectNode) node).remove(Constants.JSON_TYPE);
}
property.setValue(fromComplex(node));
break;
case PRIMITIVE:
if (property.getType() == null) {
property.setType(getPrimitiveType(node).toString());
}
property.setValue(fromPrimitive(node, typeInfo));
break;
case EMPTY:
default:
property.setValue(new PrimitiveValueImpl(StringUtils.EMPTY));
}
}
}

View File

@ -0,0 +1,94 @@
/*
* 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.client.core.data;
import com.fasterxml.jackson.core.JsonGenerator;
import java.io.IOException;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.olingo.client.api.data.CollectionValue;
import org.apache.olingo.client.api.data.Property;
import org.apache.olingo.client.api.data.Value;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.domain.ODataJClientEdmType;
abstract class AbstractJsonSerializer<T> extends ODataJacksonSerializer<T> {
private static final ODataJClientEdmPrimitiveType[] NUMBER_TYPES = {
ODataJClientEdmPrimitiveType.Byte, ODataJClientEdmPrimitiveType.SByte,
ODataJClientEdmPrimitiveType.Single, ODataJClientEdmPrimitiveType.Double,
ODataJClientEdmPrimitiveType.Int16, ODataJClientEdmPrimitiveType.Int32, ODataJClientEdmPrimitiveType.Int64
};
private final JSONGeoValueSerializer geoSerializer = new JSONGeoValueSerializer();
private void collection(final JsonGenerator jgen, final String itemType, final CollectionValue value)
throws IOException {
jgen.writeStartArray();
for (Value item : value.get()) {
value(jgen, itemType, item);
}
jgen.writeEndArray();
}
private void value(final JsonGenerator jgen, final String type, final Value value) throws IOException {
final ODataJClientEdmType typeInfo = type == null
? null
: new ODataJClientEdmType(type);
if (value.isNull()) {
jgen.writeNull();
} else if (value.isSimple()) {
final boolean isNumber = typeInfo == null
? NumberUtils.isNumber(value.asSimple().get())
: ArrayUtils.contains(NUMBER_TYPES, typeInfo.getPrimitiveType());
final boolean isBoolean = typeInfo == null
? (value.asSimple().get().equalsIgnoreCase(Boolean.TRUE.toString())
|| value.asSimple().get().equalsIgnoreCase(Boolean.FALSE.toString()))
: typeInfo.getPrimitiveType() == ODataJClientEdmPrimitiveType.Boolean;
if (isNumber) {
jgen.writeNumber(value.asSimple().get());
} else if (isBoolean) {
jgen.writeBoolean(BooleanUtils.toBoolean(value.asSimple().get()));
} else {
jgen.writeString(value.asSimple().get());
}
} else if (value.isGeospatial()) {
jgen.writeStartObject();
geoSerializer.serialize(jgen, value.asGeospatial().get());
jgen.writeEndObject();
} else if (value.isCollection()) {
collection(jgen, typeInfo == null ? null : typeInfo.getBaseType(), value.asCollection());
} else if (value.isComplex()) {
jgen.writeStartObject();
for (Property property : value.asComplex().get()) {
property(jgen, property, property.getName());
}
jgen.writeEndObject();
}
}
protected void property(final JsonGenerator jgen, final Property property, final String name) throws IOException {
jgen.writeFieldName(name);
value(jgen, property.getType(), property.getValue());
}
}

View File

@ -0,0 +1,80 @@
/*
* 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.client.core.data;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.olingo.client.api.data.Property;
import org.apache.olingo.client.api.data.Value;
public abstract class AbstractPropertyImpl implements Property {
private String name;
private String type;
private Value value;
@Override
public String getName() {
return name;
}
@Override
public void setName(final String name) {
this.name = name;
}
@Override
public String getType() {
return type;
}
@Override
public void setType(final String type) {
this.type = type;
}
@Override
public Value getValue() {
return value;
}
@Override
public void setValue(final Value value) {
this.value = value;
}
@Override
public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}

View File

@ -0,0 +1,98 @@
/*
* 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.client.core.data;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.olingo.client.api.data.CollectionValue;
import org.apache.olingo.client.api.data.ComplexValue;
import org.apache.olingo.client.api.data.GeospatialValue;
import org.apache.olingo.client.api.data.NullValue;
import org.apache.olingo.client.api.data.PrimitiveValue;
import org.apache.olingo.client.api.data.Value;
public abstract class AbstractValue implements Value {
@Override
public boolean isNull() {
return false;
}
@Override
public boolean isSimple() {
return false;
}
@Override
public boolean isGeospatial() {
return false;
}
@Override
public boolean isComplex() {
return false;
}
@Override
public boolean isCollection() {
return false;
}
@Override
public NullValue asNull() {
return isNull() ? (NullValue) this : null;
}
@Override
public PrimitiveValue asSimple() {
return isSimple() ? (PrimitiveValue) this : null;
}
@Override
public GeospatialValue asGeospatial() {
return isGeospatial() ? (GeospatialValue) this : null;
}
@Override
public ComplexValue asComplex() {
return isComplex() ? (ComplexValue) this : null;
}
@Override
public CollectionValue asCollection() {
return isCollection() ? (CollectionValue) this : null;
}
@Override
public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}

View File

@ -18,201 +18,322 @@
*/
package org.apache.olingo.client.core.data;
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.ODataClient;
import java.text.ParseException;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import org.apache.http.entity.ContentType;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.domain.ODataOperation;
import org.apache.olingo.client.api.utils.XMLUtils;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
public class AtomDeserializer {
public class AtomDeserializer extends AbstractAtomDealer {
private static final Logger LOG = LoggerFactory.getLogger(AtomDeserializer.class);
private static final ISO8601DateFormat ISO_DATEFORMAT = new ISO8601DateFormat();
private static final XMLInputFactory FACTORY = XMLInputFactory.newInstance();
private final ODataClient client;
private final AtomPropertyDeserializer propDeserializer;
public AtomDeserializer(final ODataClient client) {
this.client = client;
public AtomDeserializer(final ODataServiceVersion version) {
super(version);
this.propDeserializer = new AtomPropertyDeserializer(version);
}
private void common(final Element input, final AtomObject object) {
if (StringUtils.isNotBlank(input.getAttribute(Constants.ATTR_XMLBASE))) {
object.setBaseURI(input.getAttribute(Constants.ATTR_XMLBASE));
private AtomPropertyImpl property(final InputStream input) throws XMLStreamException {
final XMLEventReader reader = FACTORY.createXMLEventReader(input);
return propDeserializer.deserialize(reader, skipBeforeFirstStartElement(reader));
}
private StartElement skipBeforeFirstStartElement(final XMLEventReader reader) throws XMLStreamException {
StartElement startEvent = null;
while (reader.hasNext() && startEvent == null) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
startEvent = event.asStartElement();
}
}
if (startEvent == null) {
throw new IllegalArgumentException("Cannot find any XML start element");
}
final List<Element> ids = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_ID);
if (!ids.isEmpty()) {
object.setId(ids.get(0).getTextContent());
}
return startEvent;
}
final List<Element> titles = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_TITLE);
if (!titles.isEmpty()) {
object.setTitle(titles.get(0).getTextContent());
}
private void common(final XMLEventReader reader, final StartElement start,
final AbstractAtomObject object, final String key) throws XMLStreamException {
final List<Element> summaries = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_SUMMARY);
if (!summaries.isEmpty()) {
object.setSummary(summaries.get(0).getTextContent());
}
boolean foundEndElement = false;
while (reader.hasNext() && !foundEndElement) {
final XMLEvent event = reader.nextEvent();
final List<Element> updateds = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_UPDATED);
if (!updateds.isEmpty()) {
try {
object.setUpdated(ISO_DATEFORMAT.parse(updateds.get(0).getTextContent()));
} catch (Exception e) {
LOG.error("Could not parse date {}", updateds.get(0).getTextContent(), e);
if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
try {
object.setCommonProperty(key, event.asCharacters().getData());
} catch (ParseException e) {
throw new XMLStreamException("While parsing Atom entry or feed common elements", e);
}
}
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndElement = true;
}
}
}
public AtomEntryImpl entry(final Element input) {
if (!Constants.ATOM_ELEM_ENTRY.equals(input.getNodeName())) {
private void inline(final XMLEventReader reader, final StartElement start, final LinkImpl link)
throws XMLStreamException {
boolean foundEndElement = false;
while (reader.hasNext() && !foundEndElement) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement() && inlineQName.equals(event.asStartElement().getName())) {
StartElement inline = null;
while (reader.hasNext() && inline == null) {
final XMLEvent innerEvent = reader.peek();
if (innerEvent.isCharacters() && innerEvent.asCharacters().isWhiteSpace()) {
reader.nextEvent();
} else if (innerEvent.isStartElement()) {
inline = innerEvent.asStartElement();
}
}
if (inline != null) {
if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(inline.getName())) {
link.setInlineEntry(entry(reader, inline));
}
if (Constants.QNAME_ATOM_ELEM_FEED.equals(inline.getName())) {
link.setInlineFeed(feed(reader, inline));
}
}
}
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndElement = true;
}
}
}
private void properties(final XMLEventReader reader, final StartElement start, final AtomEntryImpl entry)
throws XMLStreamException {
boolean foundEndProperties = false;
while (reader.hasNext() && !foundEndProperties) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
entry.getProperties().add(propDeserializer.deserialize(reader, event.asStartElement()));
}
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndProperties = true;
}
}
}
private AtomEntryImpl entry(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
if (!Constants.QNAME_ATOM_ELEM_ENTRY.equals(start.getName())) {
return null;
}
final AtomEntryImpl entry = new AtomEntryImpl();
common(input, entry);
final String etag = input.getAttribute(Constants.ATOM_ATTR_ETAG);
if (StringUtils.isNotBlank(etag)) {
entry.setETag(etag);
final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE);
if (xmlBase != null) {
entry.setBaseURI(xmlBase.getValue());
}
final Attribute etag = start.getAttributeByName(etagQName);
if (etag != null) {
entry.setETag(etag.getValue());
}
final List<Element> categories = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_CATEGORY);
if (!categories.isEmpty()) {
entry.setType(categories.get(0).getAttribute(Constants.ATOM_ATTR_TERM));
}
boolean foundEndEntry = false;
while (reader.hasNext() && !foundEndEntry) {
final XMLEvent event = reader.nextEvent();
final List<Element> links = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_LINK);
for (Element linkElem : links) {
final LinkImpl link = new LinkImpl();
link.setRel(linkElem.getAttribute(Constants.ATTR_REL));
link.setTitle(linkElem.getAttribute(Constants.ATTR_TITLE));
link.setHref(linkElem.getAttribute(Constants.ATTR_HREF));
if (Constants.SELF_LINK_REL.equals(link.getRel())) {
entry.setSelfLink(link);
} else if (Constants.EDIT_LINK_REL.equals(link.getRel())) {
entry.setEditLink(link);
} else if (link.getRel().startsWith(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL))) {
link.setType(linkElem.getAttribute(Constants.ATTR_TYPE));
entry.getNavigationLinks().add(link);
final List<Element> inlines = XMLUtils.getChildElements(linkElem, Constants.ATOM_ELEM_INLINE);
if (!inlines.isEmpty()) {
final List<Element> entries =
XMLUtils.getChildElements(inlines.get(0), Constants.ATOM_ELEM_ENTRY);
if (!entries.isEmpty()) {
link.setInlineEntry(entry(entries.get(0)));
if (event.isStartElement()) {
if (Constants.QNAME_ATOM_ELEM_ID.equals(event.asStartElement().getName())) {
common(reader, event.asStartElement(), entry, "id");
} else if (Constants.QNAME_ATOM_ELEM_TITLE.equals(event.asStartElement().getName())) {
common(reader, event.asStartElement(), entry, "title");
} else if (Constants.QNAME_ATOM_ELEM_SUMMARY.equals(event.asStartElement().getName())) {
common(reader, event.asStartElement(), entry, "summary");
} else if (Constants.QNAME_ATOM_ELEM_UPDATED.equals(event.asStartElement().getName())) {
common(reader, event.asStartElement(), entry, "updated");
} else if (Constants.QNAME_ATOM_ELEM_CATEGORY.equals(event.asStartElement().getName())) {
final Attribute term = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATOM_ATTR_TERM));
if (term != null) {
entry.setType(term.getValue());
}
} else if (Constants.QNAME_ATOM_ELEM_LINK.equals(event.asStartElement().getName())) {
final LinkImpl link = new LinkImpl();
final Attribute rel = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_REL));
if (rel != null) {
link.setRel(rel.getValue());
}
final Attribute title = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TITLE));
if (title != null) {
link.setTitle(title.getValue());
}
final Attribute href = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_HREF));
if (href != null) {
link.setHref(href.getValue());
}
final Attribute type = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TYPE));
if (type != null) {
link.setType(type.getValue());
}
final List<Element> feeds =
XMLUtils.getChildElements(inlines.get(0), Constants.ATOM_ELEM_FEED);
if (!feeds.isEmpty()) {
link.setInlineFeed(feed(feeds.get(0)));
if (Constants.SELF_LINK_REL.equals(link.getRel())) {
entry.setSelfLink(link);
} else if (Constants.EDIT_LINK_REL.equals(link.getRel())) {
entry.setEditLink(link);
} else if (link.getRel().startsWith(version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL))) {
entry.getNavigationLinks().add(link);
inline(reader, event.asStartElement(), link);
} else if (link.getRel().startsWith(
version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL))) {
entry.getAssociationLinks().add(link);
} else if (link.getRel().startsWith(
version.getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL))) {
final Attribute metag = event.asStartElement().getAttributeByName(etagQName);
if (metag != null) {
link.setMediaETag(metag.getValue());
}
entry.getMediaEditLinks().add(link);
}
} else if (actionQName.equals(event.asStartElement().getName())) {
final ODataOperation operation = new ODataOperation();
final Attribute metadata = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_METADATA));
if (metadata != null) {
operation.setMetadataAnchor(metadata.getValue());
}
final Attribute title = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TITLE));
if (title != null) {
operation.setTitle(title.getValue());
}
final Attribute target = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TARGET));
if (target != null) {
operation.setTarget(URI.create(target.getValue()));
}
}
} else if (link.getRel().startsWith(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL))) {
entry.getAssociationLinks().add(link);
} else if (link.getRel().startsWith(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL))) {
entry.getMediaEditLinks().add(link);
}
}
final List<Element> authors = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_AUTHOR);
if (!authors.isEmpty()) {
final AtomEntryImpl.Author author = new AtomEntryImpl.Author();
for (Node child : XMLUtils.getChildNodes(input, Node.ELEMENT_NODE)) {
if (Constants.ATOM_ELEM_AUTHOR_NAME.equals(XMLUtils.getSimpleName(child))) {
author.setName(child.getTextContent());
} else if (Constants.ATOM_ELEM_AUTHOR_URI.equals(XMLUtils.getSimpleName(child))) {
author.setUri(child.getTextContent());
} else if (Constants.ATOM_ELEM_AUTHOR_EMAIL.equals(XMLUtils.getSimpleName(child))) {
author.setEmail(child.getTextContent());
entry.getOperations().add(operation);
} else if (Constants.QNAME_ATOM_ELEM_CONTENT.equals(event.asStartElement().getName())) {
final Attribute type = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TYPE));
if (type == null || ContentType.APPLICATION_XML.getMimeType().equals(type.getValue())) {
properties(reader, skipBeforeFirstStartElement(reader), entry);
} else {
entry.setMediaContentType(type.getValue());
final Attribute src = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATOM_ATTR_SRC));
if (src != null) {
entry.setMediaContentSource(src.getValue());
}
}
} else if (propertiesQName.equals(event.asStartElement().getName())) {
properties(reader, event.asStartElement(), entry);
}
}
if (!author.isEmpty()) {
entry.setAuthor(author);
}
}
final List<Element> actions = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_ACTION);
for (Element action : actions) {
final ODataOperation operation = new ODataOperation();
operation.setMetadataAnchor(action.getAttribute(Constants.ATTR_METADATA));
operation.setTitle(action.getAttribute(Constants.ATTR_TITLE));
operation.setTarget(URI.create(action.getAttribute(Constants.ATTR_TARGET)));
entry.getOperations().add(operation);
}
final List<Element> contents = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_CONTENT);
if (!contents.isEmpty()) {
final Element content = contents.get(0);
List<Element> props = XMLUtils.getChildElements(content, Constants.ELEM_PROPERTIES);
if (props.isEmpty()) {
entry.setMediaContentSource(content.getAttribute(Constants.ATOM_ATTR_SRC));
entry.setMediaContentType(content.getAttribute(Constants.ATTR_TYPE));
props = XMLUtils.getChildElements(input, Constants.ELEM_PROPERTIES);
if (!props.isEmpty()) {
entry.setMediaEntryProperties(props.get(0));
}
} else {
entry.setContent(props.get(0));
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndEntry = true;
}
}
return entry;
}
public AtomFeedImpl feed(final Element input) {
if (!Constants.ATOM_ELEM_FEED.equals(input.getNodeName())) {
private AtomEntryImpl entry(final InputStream input) throws XMLStreamException {
final XMLEventReader reader = FACTORY.createXMLEventReader(input);
return entry(reader, skipBeforeFirstStartElement(reader));
}
private void count(final XMLEventReader reader, final StartElement start, final AtomFeedImpl feed)
throws XMLStreamException {
boolean foundEndElement = false;
while (reader.hasNext() && !foundEndElement) {
final XMLEvent event = reader.nextEvent();
if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
feed.setCount(Integer.valueOf(event.asCharacters().getData()));
}
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndElement = true;
}
}
}
private AtomFeedImpl feed(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
if (!Constants.QNAME_ATOM_ELEM_FEED.equals(start.getName())) {
return null;
}
final AtomFeedImpl feed = new AtomFeedImpl();
common(input, feed);
final List<Element> entries = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_ENTRY);
for (Element entry : entries) {
feed.getEntries().add(entry(entry));
final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE);
if (xmlBase != null) {
feed.setBaseURI(xmlBase.getValue());
}
final List<Element> links = XMLUtils.getChildElements(input, Constants.ATOM_ELEM_LINK);
for (Element link : links) {
if (Constants.NEXT_LINK_REL.equals(link.getAttribute(Constants.ATTR_REL))) {
feed.setNext(URI.create(link.getAttribute(Constants.ATTR_HREF)));
boolean foundEndFeed = false;
while (reader.hasNext() && !foundEndFeed) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
if (countQName.equals(event.asStartElement().getName())) {
count(reader, event.asStartElement(), feed);
} else if (Constants.QNAME_ATOM_ELEM_ID.equals(event.asStartElement().getName())) {
common(reader, event.asStartElement(), feed, "id");
} else if (Constants.QNAME_ATOM_ELEM_TITLE.equals(event.asStartElement().getName())) {
common(reader, event.asStartElement(), feed, "title");
} else if (Constants.QNAME_ATOM_ELEM_SUMMARY.equals(event.asStartElement().getName())) {
common(reader, event.asStartElement(), feed, "summary");
} else if (Constants.QNAME_ATOM_ELEM_UPDATED.equals(event.asStartElement().getName())) {
common(reader, event.asStartElement(), feed, "updated");
} else if (Constants.QNAME_ATOM_ELEM_LINK.equals(event.asStartElement().getName())) {
final Attribute rel = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_REL));
if (rel != null && Constants.NEXT_LINK_REL.equals(rel.getValue())) {
final Attribute href = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_HREF));
if (href != null) {
feed.setNext(URI.create(href.getValue()));
}
}
} else if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(event.asStartElement().getName())) {
feed.getEntries().add(entry(reader, event.asStartElement()));
}
}
}
final List<Element> counts = XMLUtils.getChildElements(input, Constants.ATOM_ATTR_COUNT);
if (!counts.isEmpty()) {
try {
feed.setCount(Integer.parseInt(counts.get(0).getTextContent()));
} catch (Exception e) {
LOG.error("Could not parse $inlinecount {}", counts.get(0).getTextContent(), e);
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndFeed = true;
}
}
return feed;
}
private AtomFeedImpl feed(final InputStream input) throws XMLStreamException {
final XMLEventReader reader = FACTORY.createXMLEventReader(input);
return feed(reader, skipBeforeFirstStartElement(reader));
}
@SuppressWarnings("unchecked")
public <T> T read(final InputStream input, final Class<T> reference) throws XMLStreamException {
if (AtomFeedImpl.class.equals(reference)) {
return (T) feed(input);
} else if (AtomEntryImpl.class.equals(reference)) {
return (T) entry(input);
} else if (AtomPropertyImpl.class.equals(reference)) {
return (T) property(input);
}
return null;
}
}

View File

@ -18,102 +18,8 @@
*/
package org.apache.olingo.client.core.data;
import java.net.URI;
import java.util.Date;
import org.apache.commons.lang3.StringUtils;
public class AtomEntryImpl extends AbstractEntry implements AtomObject {
public class AtomEntryImpl extends AbstractEntry {
private static final long serialVersionUID = 6973729343868293279L;
public static class Author {
private String name;
private String uri;
private String email;
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getUri() {
return uri;
}
public void setUri(final String uri) {
this.uri = uri;
}
public String getEmail() {
return email;
}
public void setEmail(final String email) {
this.email = email;
}
public boolean isEmpty() {
return StringUtils.isBlank(name) && StringUtils.isBlank(uri) && StringUtils.isBlank(email);
}
}
private URI baseURI;
private String title;
private String summary;
private Date updated;
private Author author;
@Override
public void setBaseURI(final String baseURI) {
this.baseURI = URI.create(baseURI);
}
@Override
public URI getBaseURI() {
return baseURI;
}
public String getTitle() {
return title;
}
@Override
public void setTitle(final String title) {
this.title = title;
}
public String getSummary() {
return summary;
}
@Override
public void setSummary(final String summary) {
this.summary = summary;
}
public Date getUpdated() {
return updated == null ? null : new Date(updated.getTime());
}
@Override
public void setUpdated(final Date updated) {
this.updated = new Date(updated.getTime());
}
public Author getAuthor() {
return author;
}
public void setAuthor(final Author author) {
this.author = author;
}
}

View File

@ -20,7 +20,6 @@ package org.apache.olingo.client.core.data;
import java.net.URI;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.olingo.client.api.data.Entry;
import org.apache.olingo.client.api.data.Feed;
@ -30,20 +29,10 @@ import org.apache.olingo.client.api.data.Feed;
*
* @see AtomEntry
*/
public class AtomFeedImpl extends AbstractPayloadObject implements AtomObject, Feed {
public class AtomFeedImpl extends AbstractAtomObject implements Feed {
private static final long serialVersionUID = 5466590540021319153L;
private URI baseURI;
private String id;
private String title;
private String summary;
private Date updated;
private Integer count;
private final List<Entry> entries = new ArrayList<Entry>();
@ -51,51 +40,6 @@ public class AtomFeedImpl extends AbstractPayloadObject implements AtomObject, F
private URI next;
@Override
public URI getBaseURI() {
return baseURI;
}
@Override
public void setBaseURI(final String baseURI) {
this.baseURI = URI.create(baseURI);
}
public String getId() {
return id;
}
@Override
public void setId(final String id) {
this.id = id;
}
public String getTitle() {
return title;
}
@Override
public void setTitle(final String title) {
this.title = title;
}
public String getSummary() {
return summary;
}
@Override
public void setSummary(final String summary) {
this.summary = summary;
}
public Date getUpdated() {
return new Date(updated.getTime());
}
@Override
public void setUpdated(final Date updated) {
this.updated = new Date(updated.getTime());
}
public void setCount(final Integer count) {
this.count = count;
}

View File

@ -0,0 +1,252 @@
/*
* 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.client.core.data;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.domain.geospatial.Geospatial;
import org.apache.olingo.client.api.domain.geospatial.GeospatialCollection;
import org.apache.olingo.client.api.domain.geospatial.LineString;
import org.apache.olingo.client.api.domain.geospatial.MultiLineString;
import org.apache.olingo.client.api.domain.geospatial.MultiPoint;
import org.apache.olingo.client.api.domain.geospatial.MultiPolygon;
import org.apache.olingo.client.api.domain.geospatial.Point;
import org.apache.olingo.client.api.domain.geospatial.Polygon;
class AtomGeoValueDeserializer {
private List<Point> points(final XMLEventReader reader, final StartElement start,
final ODataJClientEdmPrimitiveType type, final String crs) throws XMLStreamException {
final List<Point> result = new ArrayList<Point>();
boolean foundEndProperty = false;
while (reader.hasNext() && !foundEndProperty) {
final XMLEvent event = reader.nextEvent();
if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
final String[] pointInfo = event.asCharacters().getData().split(" ");
final Point point = new Point(GeoUtils.getDimension(type), crs);
point.setX(Double.valueOf(pointInfo[0]));
point.setY(Double.valueOf(pointInfo[1]));
result.add(point);
}
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndProperty = true;
}
}
return result;
}
private MultiPoint multipoint(final XMLEventReader reader, final StartElement start,
final ODataJClientEdmPrimitiveType type, final String crs) throws XMLStreamException {
List<Point> points = Collections.<Point>emptyList();
boolean foundEndProperty = false;
while (reader.hasNext() && !foundEndProperty) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement() && event.asStartElement().getName().equals(Constants.QNAME_POINTMEMBERS)) {
points = points(reader, event.asStartElement(), type, null);
}
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndProperty = true;
}
}
return new MultiPoint(GeoUtils.getDimension(type), crs, points);
}
private LineString lineString(final XMLEventReader reader, final StartElement start,
final ODataJClientEdmPrimitiveType type, final String crs) throws XMLStreamException {
return new LineString(GeoUtils.getDimension(type), crs, points(reader, start, type, null));
}
private Polygon polygon(final XMLEventReader reader, final StartElement start,
final ODataJClientEdmPrimitiveType type, final String crs) throws XMLStreamException {
List<Point> extPoints = null;
List<Point> intPoints = null;
boolean foundEndProperty = false;
while (reader.hasNext() && !foundEndProperty) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
if (event.asStartElement().getName().equals(Constants.QNAME_POLYGON_EXTERIOR)) {
extPoints = points(reader, event.asStartElement(), type, null);
}
if (event.asStartElement().getName().equals(Constants.QNAME_POLYGON_INTERIOR)) {
intPoints = points(reader, event.asStartElement(), type, null);
}
}
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndProperty = true;
}
}
return new Polygon(GeoUtils.getDimension(type), crs, intPoints, extPoints);
}
private MultiLineString multiLineString(final XMLEventReader reader, final StartElement start,
final ODataJClientEdmPrimitiveType type, final String crs) throws XMLStreamException {
final List<LineString> lineStrings = new ArrayList<LineString>();
boolean foundEndProperty = false;
while (reader.hasNext() && !foundEndProperty) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement() && event.asStartElement().getName().equals(Constants.QNAME_LINESTRING)) {
lineStrings.add(lineString(reader, event.asStartElement(), type, null));
}
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndProperty = true;
}
}
return new MultiLineString(GeoUtils.getDimension(type), crs, lineStrings);
}
private MultiPolygon multiPolygon(final XMLEventReader reader, final StartElement start,
final ODataJClientEdmPrimitiveType type, final String crs) throws XMLStreamException {
final List<Polygon> polygons = new ArrayList<Polygon>();
boolean foundEndProperty = false;
while (reader.hasNext() && !foundEndProperty) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement() && event.asStartElement().getName().equals(Constants.QNAME_POLYGON)) {
polygons.add(polygon(reader, event.asStartElement(), type, null));
}
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndProperty = true;
}
}
return new MultiPolygon(GeoUtils.getDimension(type), crs, polygons);
}
private GeospatialCollection collection(final XMLEventReader reader, final StartElement start,
final ODataJClientEdmPrimitiveType type, final String crs) throws XMLStreamException {
final List<Geospatial> geospatials = new ArrayList<Geospatial>();
boolean foundEndCollection = false;
while (reader.hasNext() && !foundEndCollection) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement() && event.asStartElement().getName().equals(Constants.QNAME_GEOMEMBERS)) {
boolean foundEndMembers = false;
while (reader.hasNext() && !foundEndMembers) {
final XMLEvent subevent = reader.nextEvent();
if (subevent.isStartElement()) {
geospatials.add(deserialize(reader, subevent.asStartElement(),
GeoUtils.getType(GeoUtils.getDimension(type), subevent.asStartElement().getName().getLocalPart())));
}
if (subevent.isEndElement() && Constants.QNAME_GEOMEMBERS.equals(subevent.asEndElement().getName())) {
foundEndMembers = true;
}
}
}
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndCollection = true;
}
}
return new GeospatialCollection(GeoUtils.getDimension(type), crs, geospatials);
}
public Geospatial deserialize(final XMLEventReader reader, final StartElement start,
final ODataJClientEdmPrimitiveType type) throws XMLStreamException {
String crs = null;
final Attribute srsName = start.getAttributeByName(Constants.QNAME_ATTR_SRSNAME);
if (srsName != null) {
crs = StringUtils.substringAfterLast(srsName.getValue(), "/");
}
Geospatial value;
switch (type) {
case GeographyPoint:
case GeometryPoint:
value = points(reader, start, type, crs).get(0);
break;
case GeographyMultiPoint:
case GeometryMultiPoint:
value = multipoint(reader, start, type, crs);
break;
case GeographyLineString:
case GeometryLineString:
value = lineString(reader, start, type, crs);
break;
case GeographyMultiLineString:
case GeometryMultiLineString:
value = multiLineString(reader, start, type, crs);
break;
case GeographyPolygon:
case GeometryPolygon:
value = polygon(reader, start, type, crs);
break;
case GeographyMultiPolygon:
case GeometryMultiPolygon:
value = multiPolygon(reader, start, type, crs);
break;
case GeographyCollection:
case GeometryCollection:
value = collection(reader, start, type, crs);
break;
default:
value = null;
}
return value;
}
}

View File

@ -0,0 +1,222 @@
/*
* 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.client.core.data;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Collections;
import java.util.Iterator;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.domain.geospatial.Geospatial;
import org.apache.olingo.client.api.domain.geospatial.GeospatialCollection;
import org.apache.olingo.client.api.domain.geospatial.LineString;
import org.apache.olingo.client.api.domain.geospatial.MultiLineString;
import org.apache.olingo.client.api.domain.geospatial.MultiPoint;
import org.apache.olingo.client.api.domain.geospatial.MultiPolygon;
import org.apache.olingo.client.api.domain.geospatial.Point;
import org.apache.olingo.client.api.domain.geospatial.Polygon;
class AtomGeoValueSerializer {
public static final ThreadLocal<DecimalFormat> DOUBLE_FORMAT = new ThreadLocal<DecimalFormat>() {
@Override
protected DecimalFormat initialValue() {
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols();
otherSymbols.setDecimalSeparator('.');
return new DecimalFormat("#.#########################", otherSymbols);
}
};
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);
writer.writeCharacters(DOUBLE_FORMAT.get().format(point.getX()) + " " + DOUBLE_FORMAT.get().format(point.getY()));
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.getCrs() != null) {
writer.writeAttribute(Constants.PREFIX_GML, Constants.NS_GML, Constants.ATTR_SRSNAME,
Constants.SRS_URLPREFIX + value.getCrs());
}
}
public void serialize(final XMLStreamWriter writer, final Geospatial value) throws XMLStreamException {
switch (value.getEdmSimpleType()) {
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:
}
}
}

View File

@ -0,0 +1,218 @@
/*
* 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.client.core.data;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.data.CollectionValue;
import org.apache.olingo.client.api.data.ComplexValue;
import org.apache.olingo.client.api.data.Value;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.domain.ODataJClientEdmType;
import org.apache.olingo.client.api.domain.ODataPropertyType;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
class AtomPropertyDeserializer extends AbstractAtomDealer {
private final AtomGeoValueDeserializer geoDeserializer;
public AtomPropertyDeserializer(final ODataServiceVersion version) {
super(version);
this.geoDeserializer = new AtomGeoValueDeserializer();
}
private Value fromPrimitive(final XMLEventReader reader, final StartElement start,
final ODataJClientEdmType typeInfo) throws XMLStreamException {
Value value = null;
boolean foundEndProperty = false;
while (reader.hasNext() && !foundEndProperty) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
if (typeInfo != null && typeInfo.isGeospatialType()) {
final ODataJClientEdmPrimitiveType geoType = ODataJClientEdmPrimitiveType.fromValue(typeInfo.getBaseType());
value = new GeospatialValueImpl(this.geoDeserializer.deserialize(reader, event.asStartElement(), geoType));
}
}
if (event.isCharacters() && !event.asCharacters().isWhiteSpace()
&& (typeInfo == null || !typeInfo.isGeospatialType())) {
value = new PrimitiveValueImpl(event.asCharacters().getData());
}
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndProperty = true;
}
}
return value;
}
private ComplexValue fromComplex(final XMLEventReader reader, final StartElement start)
throws XMLStreamException {
final ComplexValue value = new ComplexValueImpl();
boolean foundEndProperty = false;
while (reader.hasNext() && !foundEndProperty) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
value.get().add(deserialize(reader, event.asStartElement()));
}
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndProperty = true;
}
}
return value;
}
private CollectionValue fromCollection(final XMLEventReader reader, final StartElement start,
final ODataJClientEdmType typeInfo) throws XMLStreamException {
final CollectionValueImpl value = new CollectionValueImpl();
final ODataJClientEdmType type = typeInfo == null
? null
: new ODataJClientEdmType(typeInfo.getBaseType());
boolean foundEndProperty = false;
while (reader.hasNext() && !foundEndProperty) {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
switch (guessPropertyType(reader)) {
case COMPLEX:
value.get().add(fromComplex(reader, event.asStartElement()));
break;
case PRIMITIVE:
value.get().add(fromPrimitive(reader, event.asStartElement(), type));
break;
default:
// do not add null or empty values
}
}
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
foundEndProperty = true;
}
}
return value;
}
private ODataPropertyType guessPropertyType(final XMLEventReader reader) throws XMLStreamException {
XMLEvent child = null;
while (reader.hasNext() && child == null) {
final XMLEvent event = reader.peek();
if (event.isCharacters() && event.asCharacters().isWhiteSpace()) {
reader.nextEvent();
} else {
child = event;
}
}
ODataPropertyType type = null;
if (child == null) {
type = ODataPropertyType.PRIMITIVE;
} else {
if (child.isStartElement()) {
if (Constants.NS_GML.equals(child.asStartElement().getName().getNamespaceURI())) {
type = ODataPropertyType.PRIMITIVE;
} else if (elementQName.equals(child.asStartElement().getName())) {
type = ODataPropertyType.COLLECTION;
} else {
type = ODataPropertyType.COMPLEX;
}
} else if (child.isCharacters()) {
type = ODataPropertyType.PRIMITIVE;
} else {
type = ODataPropertyType.EMPTY;
}
}
return type;
}
public AtomPropertyImpl deserialize(final XMLEventReader reader, final StartElement start)
throws XMLStreamException {
final AtomPropertyImpl property = new AtomPropertyImpl();
property.setName(start.getName().getLocalPart());
final Attribute typeAttr = start.getAttributeByName(this.typeQName);
if (typeAttr != null) {
property.setType(typeAttr.getValue());
}
Value value;
final Attribute nullAttr = start.getAttributeByName(this.nullQName);
if (nullAttr == null) {
final ODataJClientEdmType typeInfo = StringUtils.isBlank(property.getType())
? null
: new ODataJClientEdmType(property.getType());
// final EdmTypeInfo typeInfo = StringUtils.isBlank(property.getType())
// ? null
// : new EdmTypeInfo.Builder().setTypeExpression(property.getType()).build();
final ODataPropertyType propType = typeInfo == null
? guessPropertyType(reader)
: typeInfo.isCollection()
? ODataPropertyType.COLLECTION
: typeInfo.isPrimitiveType()
? ODataPropertyType.PRIMITIVE
: ODataPropertyType.COMPLEX;
switch (propType) {
case COLLECTION:
value = fromCollection(reader, start, typeInfo);
break;
case COMPLEX:
value = fromComplex(reader, start);
break;
case PRIMITIVE:
value = fromPrimitive(reader, start, typeInfo);
break;
case EMPTY:
default:
value = new PrimitiveValueImpl(StringUtils.EMPTY);
}
} else {
value = new NullValueImpl();
}
property.setValue(value);
return property;
}
}

View File

@ -0,0 +1,25 @@
/*
* 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.client.core.data;
public class AtomPropertyImpl extends AbstractPropertyImpl {
private static final long serialVersionUID = 48748492242474814L;
}

View File

@ -0,0 +1,88 @@
/*
* 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.client.core.data;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.data.CollectionValue;
import org.apache.olingo.client.api.data.Property;
import org.apache.olingo.client.api.data.Value;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
class AtomPropertySerializer extends AbstractAtomDealer {
private final AtomGeoValueSerializer geoSerializer;
public AtomPropertySerializer(final ODataServiceVersion version) {
super(version);
this.geoSerializer = new AtomGeoValueSerializer();
}
private void collection(final XMLStreamWriter writer, final CollectionValue value) throws XMLStreamException {
for (Value item : value.get()) {
writer.writeStartElement(Constants.PREFIX_DATASERVICES, Constants.ELEM_ELEMENT,
version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
value(writer, item);
writer.writeEndElement();
}
}
private void value(final XMLStreamWriter writer, final Value value) throws XMLStreamException {
if (value.isSimple()) {
writer.writeCharacters(value.asSimple().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 {
writer.writeStartElement(Constants.PREFIX_DATASERVICES, property.getName(),
version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
if (standalone) {
namespaces(writer);
}
if (StringUtils.isNotBlank(property.getType())) {
writer.writeAttribute(Constants.PREFIX_METADATA, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
Constants.ATTR_TYPE, property.getType());
}
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());
}
writer.writeEndElement();
}
public void property(final XMLStreamWriter writer, final Property property) throws XMLStreamException {
property(writer, property, true);
}
}

View File

@ -18,167 +18,240 @@
*/
package org.apache.olingo.client.core.data;
import java.io.Writer;
import java.util.Collections;
import java.util.List;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.ContentType;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.data.Entry;
import org.apache.olingo.client.api.data.Feed;
import org.apache.olingo.client.api.data.Link;
import org.apache.olingo.client.api.utils.XMLUtils;
import org.apache.olingo.client.api.data.Property;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class AtomSerializer {
public class AtomSerializer extends AbstractAtomDealer {
private final ODataClient client;
private static final XMLOutputFactory FACTORY = XMLOutputFactory.newInstance();
public AtomSerializer(final ODataClient client) {
this.client = client;
private final AtomPropertySerializer propSerializer;
public AtomSerializer(final ODataServiceVersion version) {
super(version);
this.propSerializer = new AtomPropertySerializer(version);
}
public <T extends AbstractPayloadObject> Element serialize(final T obj) throws ParserConfigurationException {
if (obj instanceof AtomEntryImpl) {
return entry((AtomEntryImpl) obj);
} else if (obj instanceof AtomFeedImpl) {
return feed((AtomFeedImpl) obj);
} else {
throw new IllegalArgumentException("Unsupported Atom object for standalone serialization: " + obj);
}
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 setLinks(final Element entry, final List<Link> links) throws ParserConfigurationException {
private void property(final Writer outWriter, final Property property) throws XMLStreamException {
final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
writer.writeStartDocument();
propSerializer.property(writer, property);
writer.writeEndDocument();
writer.flush();
}
private void links(final XMLStreamWriter writer, final List<Link> links) throws XMLStreamException {
for (Link link : links) {
final Element linkElem = entry.getOwnerDocument().createElement(Constants.ATOM_ELEM_LINK);
linkElem.setAttribute(Constants.ATTR_REL, link.getRel());
linkElem.setAttribute(Constants.ATTR_TITLE, link.getTitle());
linkElem.setAttribute(Constants.ATTR_HREF, link.getHref());
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())) {
linkElem.setAttribute(Constants.ATTR_TYPE, link.getType());
writer.writeAttribute(Constants.ATTR_TYPE, link.getType());
}
if (link.getInlineEntry() != null || link.getInlineFeed() != null) {
final Element inline = entry.getOwnerDocument().createElement(Constants.ATOM_ELEM_INLINE);
linkElem.appendChild(inline);
writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE,
version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
if (link.getInlineEntry() != null) {
inline.appendChild(entry.getOwnerDocument().importNode(
entry((AtomEntryImpl) link.getInlineEntry()), true));
writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
entry(writer, link.getInlineEntry());
writer.writeEndElement();
}
if (link.getInlineFeed() != null) {
inline.appendChild(entry.getOwnerDocument().importNode(
feed((AtomFeedImpl) link.getInlineFeed()), true));
writer.writeStartElement(Constants.ATOM_ELEM_FEED);
feed(writer, link.getInlineFeed());
writer.writeEndElement();
}
writer.writeEndElement();
}
entry.appendChild(linkElem);
writer.writeEndElement();
}
}
private Element entry(final AtomEntryImpl entry) throws ParserConfigurationException {
final DocumentBuilder builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
final Document doc = builder.newDocument();
private void common(final XMLStreamWriter writer, final AbstractAtomObject 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();
}
final Element entryElem = doc.createElement(Constants.ATOM_ELEM_ENTRY);
entryElem.setAttribute(XMLConstants.XMLNS_ATTRIBUTE, Constants.NS_ATOM);
entryElem.setAttribute(Constants.XMLNS_METADATA,
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
entryElem.setAttribute(Constants.XMLNS_DATASERVICES,
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
entryElem.setAttribute(Constants.XMLNS_GML, Constants.NS_GML);
entryElem.setAttribute(Constants.XMLNS_GEORSS, Constants.NS_GEORSS);
if (StringUtils.isNotBlank(object.getSummary())) {
writer.writeStartElement(Constants.ATOM_ELEM_SUMMARY);
writer.writeAttribute(Constants.ATTR_TYPE, "text");
writer.writeCharacters(object.getSummary());
writer.writeEndElement();
}
}
private void properties(final XMLStreamWriter writer, final List<Property> properties) throws XMLStreamException {
for (Property property : properties) {
propSerializer.property(writer, property, false);
}
}
private void entry(final XMLStreamWriter writer, final Entry entry) throws XMLStreamException {
if (entry.getBaseURI() != null) {
entryElem.setAttribute(Constants.ATTR_XMLBASE, entry.getBaseURI().toASCIIString());
}
doc.appendChild(entryElem);
final Element category = doc.createElement(Constants.ATOM_ELEM_CATEGORY);
category.setAttribute(Constants.ATOM_ATTR_TERM, entry.getType());
category.setAttribute(Constants.ATOM_ATTR_SCHEME,
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_SCHEME));
entryElem.appendChild(category);
if (StringUtils.isNotBlank(entry.getTitle())) {
final Element title = doc.createElement(Constants.ATOM_ELEM_TITLE);
title.appendChild(doc.createTextNode(entry.getTitle()));
entryElem.appendChild(title);
writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, entry.getBaseURI().toASCIIString());
}
if (StringUtils.isNotBlank(entry.getSummary())) {
final Element summary = doc.createElement(Constants.ATOM_ELEM_SUMMARY);
summary.appendChild(doc.createTextNode(entry.getSummary()));
entryElem.appendChild(summary);
writer.writeStartElement(Constants.ATOM_ELEM_ID);
writer.writeCharacters(entry.getId());
writer.writeEndElement();
writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY);
writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, version.getNamespaceMap().get(ODataServiceVersion.NS_SCHEME));
writer.writeAttribute(Constants.ATOM_ATTR_TERM, entry.getType());
writer.writeEndElement();
if (entry instanceof AbstractAtomObject) {
common(writer, (AbstractAtomObject) entry);
}
setLinks(entryElem, entry.getAssociationLinks());
setLinks(entryElem, entry.getNavigationLinks());
setLinks(entryElem, entry.getMediaEditLinks());
links(writer, entry.getAssociationLinks());
links(writer, entry.getNavigationLinks());
links(writer, entry.getMediaEditLinks());
final Element content = doc.createElement(Constants.ATOM_ELEM_CONTENT);
writer.writeStartElement(Constants.ATOM_ELEM_CONTENT);
if (entry.isMediaEntry()) {
if (StringUtils.isNotBlank(entry.getMediaContentType())) {
content.setAttribute(Constants.ATTR_TYPE, entry.getMediaContentType());
writer.writeAttribute(Constants.ATTR_TYPE, entry.getMediaContentType());
}
if (StringUtils.isNotBlank(entry.getMediaContentSource())) {
content.setAttribute(Constants.ATOM_ATTR_SRC, entry.getMediaContentSource());
}
if (content.getAttributes().getLength() > 0) {
entryElem.appendChild(content);
writer.writeAttribute(Constants.ATOM_ATTR_SRC, entry.getMediaContentSource());
}
writer.writeEndElement();
if (entry.getMediaEntryProperties() != null) {
entryElem.appendChild(doc.importNode(entry.getMediaEntryProperties(), true));
}
writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES);
properties(writer, entry.getProperties());
} else {
content.setAttribute(Constants.ATTR_TYPE, ContentType.APPLICATION_XML.getMimeType());
if (entry.getContent() != null) {
content.appendChild(doc.importNode(entry.getContent(), true));
}
entryElem.appendChild(content);
writer.writeAttribute(Constants.ATTR_TYPE, ContentType.APPLICATION_XML.getMimeType());
writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES);
properties(writer, entry.getProperties());
writer.writeEndElement();
}
return entryElem;
writer.writeEndElement();
}
private Element feed(final AtomFeedImpl feed) throws ParserConfigurationException {
final DocumentBuilder builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
final Document doc = builder.newDocument();
private void entry(final Writer outWriter, final Entry entry) throws XMLStreamException {
final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
final Element feedElem = doc.createElement(Constants.ATOM_ELEM_FEED);
feedElem.setAttribute(XMLConstants.XMLNS_ATTRIBUTE, Constants.NS_ATOM);
feedElem.setAttribute(Constants.XMLNS_METADATA,
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
feedElem.setAttribute(Constants.XMLNS_DATASERVICES,
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
feedElem.setAttribute(Constants.XMLNS_GML, Constants.NS_GML);
feedElem.setAttribute(Constants.XMLNS_GEORSS, Constants.NS_GEORSS);
startDocument(writer, Constants.ATOM_ELEM_ENTRY);
entry(writer, entry);
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
}
private void feed(final XMLStreamWriter writer, final Feed feed) throws XMLStreamException {
if (feed.getBaseURI() != null) {
feedElem.setAttribute(Constants.ATTR_XMLBASE, feed.getBaseURI().toASCIIString());
}
doc.appendChild(feedElem);
if (StringUtils.isNotBlank(feed.getTitle())) {
final Element title = doc.createElement(Constants.ATOM_ELEM_TITLE);
title.appendChild(doc.createTextNode(feed.getTitle()));
feedElem.appendChild(title);
writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, feed.getBaseURI().toASCIIString());
}
if (StringUtils.isNotBlank(feed.getSummary())) {
final Element summary = doc.createElement(Constants.ATOM_ELEM_SUMMARY);
summary.appendChild(doc.createTextNode(feed.getSummary()));
feedElem.appendChild(summary);
if (feed.getCount() != null) {
writer.writeStartElement(
version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_COUNT);
writer.writeCharacters(Integer.toString(feed.getCount()));
writer.writeEndElement();
}
writer.writeStartElement(Constants.ATOM_ELEM_ID);
writer.writeCharacters(feed.getId());
writer.writeEndElement();
if (feed instanceof AbstractAtomObject) {
common(writer, (AbstractAtomObject) feed);
}
for (Entry entry : feed.getEntries()) {
feedElem.appendChild(doc.importNode(entry((AtomEntryImpl) entry), true));
writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
entry(writer, entry);
writer.writeEndElement();
}
return feedElem;
if (feed.getNext() != null) {
final LinkImpl next = new LinkImpl();
next.setRel(Constants.NEXT_LINK_REL);
next.setHref(feed.getNext().toASCIIString());
links(writer, Collections.<Link>singletonList(next));
}
}
private void feed(final Writer outWriter, final Feed feed) throws XMLStreamException {
final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
startDocument(writer, Constants.ATOM_ELEM_FEED);
feed(writer, feed);
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.writeNamespace(
Constants.PREFIX_DATASERVICES, version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES), Constants.ELEM_URI);
writer.writeCharacters(link.getHref());
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
}
public <T> void write(final Writer writer, final T obj) throws XMLStreamException {
if (obj instanceof Feed) {
feed(writer, (Feed) obj);
} else if (obj instanceof Entry) {
entry(writer, (Entry) obj);
} else if (obj instanceof Property) {
property(writer, (Property) obj);
} else if (obj instanceof Link) {
link(writer, (Link) obj);
}
}
}

View File

@ -16,22 +16,25 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.client.core.xml;
package org.apache.olingo.client.core.data;
import java.util.Iterator;
import java.util.ServiceLoader;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.client.api.data.CollectionValue;
import org.apache.olingo.client.api.data.Value;
public final class XMLParser {
public class CollectionValueImpl extends AbstractValue implements CollectionValue {
public static final AbstractDOMParser PARSER;
private final List<Value> value = new ArrayList<Value>();
static {
final Iterator<AbstractDOMParser> itor
= ServiceLoader.load(AbstractDOMParser.class, Thread.currentThread().getContextClassLoader()).iterator();
PARSER = itor.hasNext() ? itor.next() : new DefaultDOMParserImpl();
@Override
public boolean isCollection() {
return true;
}
private XMLParser() {
// Empty private constructor for static utility classes
@Override
public List<Value> get() {
return value;
}
}

View File

@ -0,0 +1,40 @@
/*
* 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.client.core.data;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.client.api.data.ComplexValue;
import org.apache.olingo.client.api.data.Property;
public class ComplexValueImpl extends AbstractValue implements ComplexValue {
private final List<Property> value = new ArrayList<Property>();
@Override
public boolean isComplex() {
return true;
}
@Override
public List<Property> get() {
return value;
}
}

View File

@ -0,0 +1,90 @@
/*
* 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.client.core.data;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.domain.geospatial.Geospatial;
public final class GeoUtils {
private GeoUtils() {
// Empty private constructor for static utility classes
}
public static Geospatial.Dimension getDimension(final ODataJClientEdmPrimitiveType type) {
Geospatial.Dimension dimension;
switch (type) {
case Geography:
case GeographyCollection:
case GeographyLineString:
case GeographyMultiLineString:
case GeographyPoint:
case GeographyMultiPoint:
case GeographyPolygon:
case GeographyMultiPolygon:
dimension = Geospatial.Dimension.GEOGRAPHY;
break;
default:
dimension = Geospatial.Dimension.GEOMETRY;
}
return dimension;
}
public static ODataJClientEdmPrimitiveType getType(final Geospatial.Dimension dimension, final String elementName) {
ODataJClientEdmPrimitiveType type = null;
if (Constants.ELEM_POINT.equals(elementName)) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyPoint
: ODataJClientEdmPrimitiveType.GeometryPoint;
} else if (Constants.ELEM_MULTIPOINT.equals(elementName)) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyMultiPoint
: ODataJClientEdmPrimitiveType.GeometryMultiPoint;
} else if (Constants.ELEM_LINESTRING.equals(elementName)) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyLineString
: ODataJClientEdmPrimitiveType.GeometryLineString;
} else if (Constants.ELEM_MULTILINESTRING.equals(elementName)) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyMultiLineString
: ODataJClientEdmPrimitiveType.GeometryMultiLineString;
} else if (Constants.ELEM_POLYGON.equals(elementName)) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyPolygon
: ODataJClientEdmPrimitiveType.GeometryPolygon;
} else if (Constants.ELEM_MULTIPOLYGON.equals(elementName)) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyMultiPolygon
: ODataJClientEdmPrimitiveType.GeometryMultiPolygon;
} else if (Constants.ELEM_GEOCOLLECTION.equals(elementName)
|| Constants.ELEM_GEOMEMBERS.equals(elementName)) {
type = dimension == Geospatial.Dimension.GEOGRAPHY
? ODataJClientEdmPrimitiveType.GeographyCollection
: ODataJClientEdmPrimitiveType.GeometryCollection;
}
return type;
}
}

View File

@ -1,412 +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.client.core.data;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.domain.geospatial.Geospatial;
import org.apache.olingo.client.api.utils.XMLUtils;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
final class GeospatialJSONHandler {
/**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(GeospatialJSONHandler.class);
private GeospatialJSONHandler() {
// Empty private constructor for static utility classes
}
private static Element deserializePoint(final Document document, final Iterator<JsonNode> itor) {
final Element point = document.createElementNS(Constants.NS_GML, Constants.ELEM_POINT);
final Element ppos = document.createElementNS(Constants.NS_GML, Constants.ELEM_POS);
point.appendChild(ppos);
if (itor.hasNext()) {
ppos.appendChild(document.createTextNode(itor.next().asText() + " " + itor.next().asText()));
}
return point;
}
private static void appendPoses(final Element parent, final Document document, final Iterator<JsonNode> itor) {
while (itor.hasNext()) {
final Iterator<JsonNode> lineItor = itor.next().elements();
final Element pos = document.createElementNS(Constants.NS_GML, Constants.ELEM_POS);
parent.appendChild(pos);
pos.appendChild(document.createTextNode(lineItor.next().asText() + " " + lineItor.next().asText()));
}
}
private static Element deserializeLineString(final Document document, final Iterator<JsonNode> itor) {
final Element lineString = document.createElementNS(Constants.NS_GML, Constants.ELEM_LINESTRING);
if (!itor.hasNext()) {
lineString.appendChild(document.createElementNS(Constants.NS_GML, Constants.ELEM_POSLIST));
}
appendPoses(lineString, document, itor);
return lineString;
}
private static Element deserializePolygon(final Document document, final Iterator<JsonNode> itor) {
final Element polygon = document.createElementNS(Constants.NS_GML, Constants.ELEM_POLYGON);
if (itor.hasNext()) {
final Iterator<JsonNode> extItor = itor.next().elements();
final Element exterior = document.createElementNS(
Constants.NS_GML, Constants.ELEM_POLYGON_EXTERIOR);
polygon.appendChild(exterior);
final Element extLR = document.createElementNS(
Constants.NS_GML, Constants.ELEM_POLYGON_LINEARRING);
exterior.appendChild(extLR);
appendPoses(extLR, document, extItor);
}
if (itor.hasNext()) {
final Iterator<JsonNode> intItor = itor.next().elements();
final Element interior = document.createElementNS(
Constants.NS_GML, Constants.ELEM_POLYGON_INTERIOR);
polygon.appendChild(interior);
final Element intLR = document.createElementNS(
Constants.NS_GML, Constants.ELEM_POLYGON_LINEARRING);
interior.appendChild(intLR);
appendPoses(intLR, document, intItor);
}
return polygon;
}
public static void deserialize(final JsonNode node, final Element parent, final String type) {
final Iterator<JsonNode> cooItor = node.has(Constants.JSON_COORDINATES)
? node.get(Constants.JSON_COORDINATES).elements()
: Collections.<JsonNode>emptyList().iterator();
Element root = null;
final ODataJClientEdmPrimitiveType edmSimpleType = ODataJClientEdmPrimitiveType.fromValue(type);
switch (edmSimpleType) {
case GeographyPoint:
case GeometryPoint:
root = deserializePoint(parent.getOwnerDocument(), cooItor);
break;
case GeographyMultiPoint:
case GeometryMultiPoint:
root = parent.getOwnerDocument().createElementNS(Constants.NS_GML, Constants.ELEM_MULTIPOINT);
if (cooItor.hasNext()) {
final Element pointMembers = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_POINTMEMBERS);
root.appendChild(pointMembers);
while (cooItor.hasNext()) {
final Iterator<JsonNode> mpItor = cooItor.next().elements();
pointMembers.appendChild(deserializePoint(parent.getOwnerDocument(), mpItor));
}
}
break;
case GeographyLineString:
case GeometryLineString:
root = deserializeLineString(parent.getOwnerDocument(), cooItor);
break;
case GeographyMultiLineString:
case GeometryMultiLineString:
root = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_MULTILINESTRING);
if (cooItor.hasNext()) {
final Element lineStringMembers = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_LINESTRINGMEMBERS);
root.appendChild(lineStringMembers);
while (cooItor.hasNext()) {
final Iterator<JsonNode> mlsItor = cooItor.next().elements();
lineStringMembers.appendChild(deserializeLineString(parent.getOwnerDocument(), mlsItor));
}
}
break;
case GeographyPolygon:
case GeometryPolygon:
root = deserializePolygon(parent.getOwnerDocument(), cooItor);
break;
case GeographyMultiPolygon:
case GeometryMultiPolygon:
root = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_MULTIPOLYGON);
if (cooItor.hasNext()) {
final Element surfaceMembers = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_SURFACEMEMBERS);
root.appendChild(surfaceMembers);
while (cooItor.hasNext()) {
final Iterator<JsonNode> mpItor = cooItor.next().elements();
surfaceMembers.appendChild(deserializePolygon(parent.getOwnerDocument(), mpItor));
}
}
break;
case GeographyCollection:
case GeometryCollection:
root = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_GEOCOLLECTION);
if (node.has(Constants.JSON_GEOMETRIES)) {
final Iterator<JsonNode> geoItor = node.get(Constants.JSON_GEOMETRIES).elements();
if (geoItor.hasNext()) {
final Element geometryMembers = parent.getOwnerDocument().createElementNS(
Constants.NS_GML, Constants.ELEM_GEOMEMBERS);
root.appendChild(geometryMembers);
while (geoItor.hasNext()) {
final JsonNode geo = geoItor.next();
final String collItemType = geo.get(Constants.ATTR_TYPE).asText();
final String callAsType;
if (ODataJClientEdmPrimitiveType.GeographyCollection.name().equals(collItemType)
|| ODataJClientEdmPrimitiveType.GeometryCollection.name().equals(collItemType)) {
callAsType = collItemType;
} else {
callAsType =
(edmSimpleType == ODataJClientEdmPrimitiveType.GeographyCollection ? "Geography" : "Geometry")
+ collItemType;
}
deserialize(geo, geometryMembers, ODataJClientEdmPrimitiveType.namespace() + "." + callAsType);
}
}
}
break;
default:
}
if (root != null) {
parent.appendChild(root);
if (node.has(Constants.JSON_CRS)) {
root.setAttribute(Constants.ATTR_SRSNAME,
Constants.JSON_GIS_URLPREFIX
+ node.get(Constants.JSON_CRS).get(Constants.PROPERTIES).get(Constants.NAME).
asText().split(":")[1]);
}
}
}
private static void serializeCrs(final JsonGenerator jgen, final Node node) throws IOException {
if (node.getAttributes().getNamedItem(Constants.ATTR_SRSNAME) != null) {
final String srsName = node.getAttributes().getNamedItem(Constants.ATTR_SRSNAME).getTextContent();
final int prefIdx = srsName.indexOf(Constants.JSON_GIS_URLPREFIX);
final String crsValue = srsName.substring(prefIdx + Constants.JSON_GIS_URLPREFIX.length());
jgen.writeObjectFieldStart(Constants.JSON_CRS);
jgen.writeStringField(Constants.ATTR_TYPE, Constants.NAME);
jgen.writeObjectFieldStart(Constants.PROPERTIES);
jgen.writeStringField(Constants.NAME, "EPSG:" + crsValue);
jgen.writeEndObject();
jgen.writeEndObject();
}
}
private static void serializePoint(final JsonGenerator jgen, final Node node) throws IOException {
for (String coord : node.getTextContent().split(" ")) {
jgen.writeNumber(coord);
}
}
private static void serializeLineString(final JsonGenerator jgen, final Element node) throws IOException {
for (Element element : XMLUtils.getChildElements(node, Constants.ELEM_POS)) {
jgen.writeStartArray();
serializePoint(jgen, element);
jgen.writeEndArray();
}
}
private static void serializePolygon(final JsonGenerator jgen, final Element node) throws IOException {
for (Element exterior : XMLUtils.getChildElements(node, Constants.ELEM_POLYGON_EXTERIOR)) {
jgen.writeStartArray();
serializeLineString(jgen,
XMLUtils.getChildElements(exterior, Constants.ELEM_POLYGON_LINEARRING).get(0));
jgen.writeEndArray();
}
for (Element interior : XMLUtils.getChildElements(node, Constants.ELEM_POLYGON_INTERIOR)) {
jgen.writeStartArray();
serializeLineString(jgen,
XMLUtils.getChildElements(interior, Constants.ELEM_POLYGON_LINEARRING).get(0));
jgen.writeEndArray();
}
}
public static void serialize(final ODataClient client,
final JsonGenerator jgen, final Element node, final String type) throws IOException {
final ODataJClientEdmPrimitiveType edmSimpleType = ODataJClientEdmPrimitiveType.fromValue(type);
if (edmSimpleType.equals(ODataJClientEdmPrimitiveType.GeographyCollection)
|| edmSimpleType.equals(ODataJClientEdmPrimitiveType.GeometryCollection)) {
jgen.writeStringField(Constants.ATTR_TYPE, ODataJClientEdmPrimitiveType.GeometryCollection.name());
} else {
final int yIdx = edmSimpleType.name().indexOf('y');
final String itemType = edmSimpleType.name().substring(yIdx + 1);
jgen.writeStringField(Constants.ATTR_TYPE, itemType);
}
Element root = null;
switch (edmSimpleType) {
case GeographyPoint:
case GeometryPoint:
root = XMLUtils.getChildElements(node, Constants.ELEM_POINT).get(0);
jgen.writeArrayFieldStart(Constants.JSON_COORDINATES);
serializePoint(jgen, XMLUtils.getChildElements(root, Constants.ELEM_POS).get(0));
jgen.writeEndArray();
break;
case GeographyMultiPoint:
case GeometryMultiPoint:
root = XMLUtils.getChildElements(node, Constants.ELEM_MULTIPOINT).get(0);
jgen.writeArrayFieldStart(Constants.JSON_COORDINATES);
final List<Element> pMembs = XMLUtils.getChildElements(root, Constants.ELEM_POINTMEMBERS);
if (pMembs != null && !pMembs.isEmpty()) {
for (Element point : XMLUtils.getChildElements(pMembs.get(0), Constants.ELEM_POINT)) {
jgen.writeStartArray();
serializePoint(jgen, XMLUtils.getChildElements(point, Constants.ELEM_POS).get(0));
jgen.writeEndArray();
}
}
jgen.writeEndArray();
break;
case GeographyLineString:
case GeometryLineString:
root = XMLUtils.getChildElements(node, Constants.ELEM_LINESTRING).get(0);
jgen.writeArrayFieldStart(Constants.JSON_COORDINATES);
serializeLineString(jgen, root);
jgen.writeEndArray();
break;
case GeographyMultiLineString:
case GeometryMultiLineString:
root = XMLUtils.getChildElements(node, Constants.ELEM_MULTILINESTRING).get(0);
jgen.writeArrayFieldStart(Constants.JSON_COORDINATES);
final List<Element> lMembs = XMLUtils.getChildElements(root, Constants.ELEM_LINESTRINGMEMBERS);
if (lMembs != null && !lMembs.isEmpty()) {
for (Element lineStr : XMLUtils.getChildElements(lMembs.get(0), Constants.ELEM_LINESTRING)) {
jgen.writeStartArray();
serializeLineString(jgen, lineStr);
jgen.writeEndArray();
}
}
jgen.writeEndArray();
break;
case GeographyPolygon:
case GeometryPolygon:
root = XMLUtils.getChildElements(node, Constants.ELEM_POLYGON).get(0);
jgen.writeArrayFieldStart(Constants.JSON_COORDINATES);
serializePolygon(jgen, root);
jgen.writeEndArray();
break;
case GeographyMultiPolygon:
case GeometryMultiPolygon:
root = XMLUtils.getChildElements(node, Constants.ELEM_MULTIPOLYGON).get(0);
jgen.writeArrayFieldStart(Constants.JSON_COORDINATES);
final List<Element> mpMembs = XMLUtils.getChildElements(root, Constants.ELEM_SURFACEMEMBERS);
if (mpMembs != null & !mpMembs.isEmpty()) {
for (Element pol : XMLUtils.getChildElements(mpMembs.get(0), Constants.ELEM_POLYGON)) {
jgen.writeStartArray();
serializePolygon(jgen, pol);
jgen.writeEndArray();
}
}
jgen.writeEndArray();
break;
case GeographyCollection:
case GeometryCollection:
root = XMLUtils.getChildElements(node, Constants.ELEM_GEOCOLLECTION).get(0);
final List<Element> cMembs = XMLUtils.getChildElements(root, Constants.ELEM_GEOMEMBERS);
if (cMembs != null && !cMembs.isEmpty()) {
jgen.writeArrayFieldStart(Constants.JSON_GEOMETRIES);
for (Node geom : XMLUtils.getChildNodes(cMembs.get(0), Node.ELEMENT_NODE)) {
try {
final DocumentBuilder builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
final Document doc = builder.newDocument();
final Element fakeParent = doc.createElementNS(
client.getServiceVersion().getNamespaceMap().
get(ODataServiceVersion.NS_DATASERVICES),
Constants.PREFIX_DATASERVICES + "fake");
fakeParent.appendChild(doc.importNode(geom, true));
final ODataJClientEdmPrimitiveType callAsType = XMLUtils.simpleTypeForNode(
edmSimpleType == ODataJClientEdmPrimitiveType.GeographyCollection
? Geospatial.Dimension.GEOGRAPHY : Geospatial.Dimension.GEOMETRY,
geom);
jgen.writeStartObject();
serialize(client, jgen, fakeParent, callAsType.toString());
jgen.writeEndObject();
} catch (Exception e) {
LOG.warn("While serializing {}", XMLUtils.getSimpleName(geom), e);
}
}
jgen.writeEndArray();
}
break;
default:
}
if (root != null) {
serializeCrs(jgen, root);
}
}
}

View File

@ -0,0 +1,42 @@
/*
* 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.client.core.data;
import org.apache.olingo.client.api.data.GeospatialValue;
import org.apache.olingo.client.api.domain.geospatial.Geospatial;
public class GeospatialValueImpl extends AbstractValue implements GeospatialValue {
private final Geospatial value;
public GeospatialValueImpl(final Geospatial value) {
this.value = value;
}
@Override
public boolean isGeospatial() {
return true;
}
@Override
public Geospatial get() {
return value;
}
}

View File

@ -1,260 +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.client.core.data;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import java.io.IOException;
import java.util.Iterator;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.domain.ODataPrimitiveValue;
import org.apache.olingo.client.api.utils.XMLUtils;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* DOM tree utilities class for JSON.
*/
final class JSONDOMTreeUtils {
private JSONDOMTreeUtils() {
// Empty private constructor for static utility classes
}
/**
* Recursively builds DOM content out of JSON subtree rooted at given node.
*
* @param client OData client.
* @param document root of the DOM document being built
* @param parent parent of the nodes being generated during this step
* @param node JSON node to be used as source for DOM elements
*/
public static void buildSubtree(final ODataClient client, final Element parent, final JsonNode node) {
final Iterator<String> fieldNameItor = node.fieldNames();
final Iterator<JsonNode> nodeItor = node.elements();
while (nodeItor.hasNext()) {
final JsonNode child = nodeItor.next();
final String name = fieldNameItor.hasNext() ? fieldNameItor.next() : "";
// no name? array item
if (name.isEmpty()) {
final Element element = parent.getOwnerDocument().createElementNS(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES),
Constants.PREFIX_DATASERVICES + Constants.ELEM_ELEMENT);
parent.appendChild(element);
if (child.isValueNode()) {
if (child.isNull()) {
element.setAttributeNS(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
Constants.ATTR_NULL, Boolean.toString(true));
} else {
element.appendChild(parent.getOwnerDocument().createTextNode(child.asText()));
}
}
if (child.isContainerNode()) {
buildSubtree(client, element, child);
}
} else if (!name.contains("@") && !Constants.JSON_TYPE.equals(name)) {
final Element property = parent.getOwnerDocument().createElementNS(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES),
Constants.PREFIX_DATASERVICES + name);
parent.appendChild(property);
boolean typeSet = false;
if (node.hasNonNull(name + "@" + Constants.JSON_TYPE)) {
property.setAttributeNS(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
Constants.ATTR_M_TYPE,
node.get(name + "@" + Constants.JSON_TYPE).textValue());
typeSet = true;
}
if (child.isNull()) {
property.setAttributeNS(client.getServiceVersion().getNamespaceMap().
get(ODataServiceVersion.NS_METADATA),
Constants.ATTR_NULL, Boolean.toString(true));
} else if (child.isValueNode()) {
if (!typeSet) {
if (child.isInt()) {
property.setAttributeNS(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
Constants.ATTR_M_TYPE, ODataJClientEdmPrimitiveType.Int32.toString());
}
if (child.isLong()) {
property.setAttributeNS(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
Constants.ATTR_M_TYPE, ODataJClientEdmPrimitiveType.Int64.toString());
}
if (child.isBigDecimal()) {
property.setAttributeNS(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
Constants.ATTR_M_TYPE, ODataJClientEdmPrimitiveType.Decimal.toString());
}
if (child.isDouble()) {
property.setAttributeNS(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
Constants.ATTR_M_TYPE, ODataJClientEdmPrimitiveType.Double.toString());
}
if (child.isBoolean()) {
property.setAttributeNS(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
Constants.ATTR_M_TYPE, ODataJClientEdmPrimitiveType.Boolean.toString());
}
if (child.isTextual()) {
property.setAttributeNS(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
Constants.ATTR_M_TYPE, ODataJClientEdmPrimitiveType.String.toString());
}
}
property.appendChild(parent.getOwnerDocument().createTextNode(child.asText()));
} else if (child.isContainerNode()) {
if (!typeSet && child.hasNonNull(Constants.JSON_TYPE)) {
property.
setAttributeNS(client.getServiceVersion().getNamespaceMap().
get(ODataServiceVersion.NS_METADATA),
Constants.ATTR_M_TYPE,
child.get(Constants.JSON_TYPE).textValue());
}
final String type = property.getAttribute(Constants.ATTR_M_TYPE);
if (StringUtils.isNotBlank(type) && ODataJClientEdmPrimitiveType.isGeospatial(type)) {
if (ODataJClientEdmPrimitiveType.Geography.toString().equals(type)
|| ODataJClientEdmPrimitiveType.Geometry.toString().equals(type)) {
final String geoType = child.get(Constants.ATTR_TYPE).textValue();
property.setAttributeNS(client.getServiceVersion().getNamespaceMap().get(
ODataServiceVersion.NS_METADATA), Constants.ATTR_M_TYPE,
geoType.startsWith("Geo")
? ODataJClientEdmPrimitiveType.namespace() + "." + geoType
: type + geoType);
}
if (child.has(Constants.JSON_COORDINATES) || child.has(Constants.JSON_GEOMETRIES)) {
GeospatialJSONHandler.deserialize(
child, property, property.getAttribute(Constants.ATTR_M_TYPE));
}
} else {
buildSubtree(client, property, child);
}
}
}
}
}
/**
* Serializes DOM content as JSON.
*
* @param client OData client.
* @param jgen JSON generator.
* @param content content.
* @throws IOException in case of write error.
*/
public static void writeSubtree(final ODataClient client, final JsonGenerator jgen, final Node content)
throws IOException {
writeSubtree(client, jgen, content, false);
}
/**
* Serializes DOM content as JSON.
*
* @param client OData client.
* @param jgen JSON generator.
* @param content content.
* @param propType whether to output type information in the way needed for property values or not.
* @throws IOException in case of write error.
*/
public static void writeSubtree(
final ODataClient client, final JsonGenerator jgen, final Node content, final boolean propType)
throws IOException {
for (Node child : XMLUtils.getChildNodes(content, Node.ELEMENT_NODE)) {
final String childName = XMLUtils.getSimpleName(child);
final Node typeAttr = child.getAttributes().getNamedItem(Constants.ATTR_M_TYPE);
if (typeAttr != null && ODataJClientEdmPrimitiveType.isGeospatial(typeAttr.getTextContent())) {
jgen.writeStringField(propType ? Constants.JSON_TYPE : childName + "@" + Constants.JSON_TYPE,
typeAttr.getTextContent());
jgen.writeObjectFieldStart(childName);
GeospatialJSONHandler.serialize(client, jgen, (Element) child, typeAttr.getTextContent());
jgen.writeEndObject();
} else if (XMLUtils.hasOnlyTextChildNodes(child)) {
if (child.hasChildNodes()) {
final String out;
if (typeAttr == null) {
out = child.getChildNodes().item(0).getNodeValue();
} else {
final ODataJClientEdmPrimitiveType type = ODataJClientEdmPrimitiveType.fromValue(typeAttr.getTextContent());
final ODataPrimitiveValue value = client.getPrimitiveValueBuilder().setType(type).
setText(child.getChildNodes().item(0).getNodeValue()).build();
out = value.toString();
jgen.writeStringField(childName + "@" + Constants.JSON_TYPE, type.toString());
}
jgen.writeStringField(childName, out);
} else {
if (child.getAttributes().getNamedItem(Constants.ATTR_NULL) == null) {
if (typeAttr != null && ODataJClientEdmPrimitiveType.String.toString().equals(typeAttr.getTextContent())) {
jgen.writeStringField(childName + "@" + Constants.JSON_TYPE, typeAttr.getTextContent());
jgen.writeStringField(childName, StringUtils.EMPTY);
} else {
jgen.writeArrayFieldStart(childName);
jgen.writeEndArray();
}
} else {
jgen.writeNullField(childName);
}
}
} else {
if (XMLUtils.hasElementsChildNode(child)) {
jgen.writeArrayFieldStart(childName);
for (Node nephew : XMLUtils.getChildNodes(child, Node.ELEMENT_NODE)) {
if (XMLUtils.hasOnlyTextChildNodes(nephew)) {
jgen.writeString(nephew.getChildNodes().item(0).getNodeValue());
} else {
jgen.writeStartObject();
writeSubtree(client, jgen, nephew);
jgen.writeEndObject();
}
}
jgen.writeEndArray();
} else {
jgen.writeObjectFieldStart(childName);
if (typeAttr != null) {
jgen.writeStringField(Constants.JSON_TYPE, typeAttr.getTextContent());
}
writeSubtree(client, jgen, child);
jgen.writeEndObject();
}
}
}
}
}

View File

@ -23,31 +23,29 @@ import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import java.net.URI;
import java.text.ParseException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.data.Link;
import org.apache.olingo.client.api.domain.ODataLinkType;
import org.apache.olingo.client.api.domain.ODataOperation;
import org.apache.olingo.client.api.utils.XMLUtils;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Reads JSON string into an entry.
* <br/>
* If metadata information is available, the corresponding entry fields and content will be populated.
*/
public class JSONEntryDeserializer extends ODataJacksonDeserializer<JSONEntryImpl> {
public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImpl> {
private String getTitle(final Map.Entry<String, JsonNode> entry) {
return entry.getKey().substring(0, entry.getKey().indexOf('@'));
@ -61,18 +59,17 @@ public class JSONEntryDeserializer extends ODataJacksonDeserializer<JSONEntryImp
final JsonNode inline = tree.path(entryNamePrefix);
if (inline instanceof ObjectNode) {
final JsonParser inlineParser = inline.traverse();
inlineParser.setCodec(codec);
link.setInlineEntry(inlineParser.readValuesAs(JSONEntryImpl.class).next());
link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
link.setInlineEntry(inline.traverse(codec).readValuesAs(JSONEntryImpl.class).next());
}
if (inline instanceof ArrayNode) {
link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
final JSONFeedImpl feed = new JSONFeedImpl();
final Iterator<JsonNode> entries = ((ArrayNode) inline).elements();
while (entries.hasNext()) {
final JsonParser inlineParser = entries.next().traverse();
inlineParser.setCodec(codec);
feed.getEntries().add(inlineParser.readValuesAs(JSONEntryImpl.class).next());
feed.getEntries().add(entries.next().traverse(codec).readValuesAs(JSONEntryImpl.class).next());
}
link.setInlineFeed(feed);
@ -91,10 +88,6 @@ public class JSONEntryDeserializer extends ODataJacksonDeserializer<JSONEntryImp
throw new JsonParseException("Expected OData Entity, found EntitySet", parser.getCurrentLocation());
}
final boolean isMediaEntry =
tree.hasNonNull(Constants.JSON_MEDIAREAD_LINK)
&& tree.hasNonNull(Constants.JSON_MEDIA_CONTENT_TYPE);
final JSONEntryImpl entry = new JSONEntryImpl();
if (tree.hasNonNull(Constants.JSON_METADATA)) {
@ -118,7 +111,11 @@ public class JSONEntryDeserializer extends ODataJacksonDeserializer<JSONEntryImp
}
if (tree.hasNonNull(Constants.JSON_ID)) {
entry.setId(tree.get(Constants.JSON_ID).textValue());
try {
entry.setId(tree.get(Constants.JSON_ID).textValue());
} catch (ParseException e) {
throw new JsonMappingException("While parsing Atom entry or feed common elements", e);
}
tree.remove(Constants.JSON_ID);
}
@ -145,10 +142,6 @@ public class JSONEntryDeserializer extends ODataJacksonDeserializer<JSONEntryImp
tree.remove(Constants.JSON_MEDIAREAD_LINK);
}
if (tree.hasNonNull(Constants.JSON_MEDIAEDIT_LINK)) {
/*final LinkImpl link = new LinkImpl();
link.setHref(tree.get(Constants.JSON_MEDIAEDIT_LINK).textValue());
entry.getMediaEditLinks().add(link);*/
tree.remove(Constants.JSON_MEDIAEDIT_LINK);
}
if (tree.hasNonNull(Constants.JSON_MEDIA_CONTENT_TYPE)) {
@ -157,15 +150,15 @@ public class JSONEntryDeserializer extends ODataJacksonDeserializer<JSONEntryImp
}
final Set<String> toRemove = new HashSet<String>();
final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields();
while (itor.hasNext()) {
for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); itor.hasNext();) {
final Map.Entry<String, JsonNode> field = itor.next();
if (field.getKey().endsWith(Constants.JSON_NAVIGATION_LINK_SUFFIX)) {
final LinkImpl link = new LinkImpl();
link.setTitle(getTitle(field));
link.setRel(client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL)
+ getTitle(field));
link.setRel(client.getServiceVersion().getNamespaceMap().
get(ODataServiceVersion.NAVIGATION_LINK_REL) + getTitle(field));
if (field.getValue().isValueNode()) {
link.setHref(field.getValue().textValue());
link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
@ -173,18 +166,18 @@ public class JSONEntryDeserializer extends ODataJacksonDeserializer<JSONEntryImp
// NOTE: this should be expected to happen, but it isn't - at least up to OData 4.0
/* if (field.getValue().isArray()) {
* link.setHref(field.getValue().asText());
* link.setType(LinkType.ENTITY_SET_NAVIGATION.toString());
* link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
* } */
entry.getNavigationLinks().add(link);
toRemove.add(field.getKey());
toRemove.add(setInline(field.getKey(),
Constants.JSON_NAVIGATION_LINK_SUFFIX, tree, parser.getCodec(), link));
toRemove.add(setInline(field.getKey(), Constants.JSON_NAVIGATION_LINK_SUFFIX, tree, parser.getCodec(), link));
} else if (field.getKey().endsWith(Constants.JSON_ASSOCIATION_LINK_SUFFIX)) {
final LinkImpl link = new LinkImpl();
link.setTitle(getTitle(field));
link.setRel(client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL)
+ getTitle(field));
link.setRel(client.getServiceVersion().getNamespaceMap().
get(ODataServiceVersion.ASSOCIATION_LINK_REL) + getTitle(field));
link.setHref(field.getValue().textValue());
link.setType(ODataLinkType.ASSOCIATION.toString());
entry.getAssociationLinks().add(link);
@ -193,15 +186,27 @@ public class JSONEntryDeserializer extends ODataJacksonDeserializer<JSONEntryImp
} else if (field.getKey().endsWith(Constants.JSON_MEDIAEDIT_LINK_SUFFIX)) {
final LinkImpl link = new LinkImpl();
link.setTitle(getTitle(field));
link.setRel(client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL)
+ getTitle(field));
link.setRel(client.getServiceVersion().getNamespaceMap().
get(ODataServiceVersion.MEDIA_EDIT_LINK_REL) + getTitle(field));
link.setHref(field.getValue().textValue());
link.setType(ODataLinkType.MEDIA_EDIT.toString());
entry.getMediaEditLinks().add(link);
if (tree.has(link.getTitle() + Constants.JSON_MEDIA_ETAG_SUFFIX)) {
link.setMediaETag(tree.get(link.getTitle() + Constants.JSON_MEDIA_ETAG_SUFFIX).asText());
toRemove.add(link.getTitle() + Constants.JSON_MEDIA_ETAG_SUFFIX);
}
toRemove.add(field.getKey());
toRemove.add(setInline(field.getKey(), Constants.JSON_MEDIAEDIT_LINK_SUFFIX, tree, parser.getCodec(), link));
} else if (field.getKey().endsWith(Constants.JSON_MEDIA_CONTENT_TYPE)) {
final String linkTitle = getTitle(field);
for (Link link : entry.getMediaEditLinks()) {
if (linkTitle.equals(link.getTitle())) {
((LinkImpl) link).setType(field.getValue().asText());
}
}
toRemove.add(field.getKey());
toRemove.add(setInline(field.getKey(),
Constants.JSON_MEDIAEDIT_LINK_SUFFIX, tree, parser.getCodec(), link));
} else if (field.getKey().charAt(0) == '#') {
final ODataOperation operation = new ODataOperation();
operation.setMetadataAnchor(field.getKey());
@ -217,23 +222,21 @@ public class JSONEntryDeserializer extends ODataJacksonDeserializer<JSONEntryImp
}
tree.remove(toRemove);
try {
final DocumentBuilder builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
final Document document = builder.newDocument();
String type = null;
for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); itor.hasNext();) {
final Map.Entry<String, JsonNode> field = itor.next();
final Element properties = document.createElementNS(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
Constants.ELEM_PROPERTIES);
JSONDOMTreeUtils.buildSubtree(client, properties, tree);
if (isMediaEntry) {
entry.setMediaEntryProperties(properties);
if (type == null && field.getKey().endsWith(Constants.JSON_TYPE_SUFFIX)) {
type = field.getValue().asText();
} else {
entry.setContent(properties);
final JSONPropertyImpl property = new JSONPropertyImpl();
property.setName(field.getKey());
property.setType(type);
type = null;
value(property, field.getValue());
entry.getProperties().add(property);
}
} catch (ParserConfigurationException e) {
throw new JsonParseException("Cannot build entry content", parser.getCurrentLocation(), e);
}
return entry;

View File

@ -22,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.net.URI;
import java.text.ParseException;
import org.apache.olingo.client.api.uri.SegmentType;
/**
@ -37,6 +38,10 @@ public class JSONEntryImpl extends AbstractEntry {
private String mediaETag;
public void setId(String id) throws ParseException {
this.setCommonProperty("id", id);
}
@JsonIgnore
@Override
public URI getBaseURI() {

View File

@ -26,15 +26,16 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.data.Entry;
import org.apache.olingo.client.api.data.Link;
import org.apache.olingo.client.api.data.Property;
import org.apache.olingo.client.api.domain.ODataLinkType;
/**
* Writes out JSON string from an entry.
*/
public class JSONEntrySerializer extends ODataJacksonSerializer<JSONEntryImpl> {
public class JSONEntrySerializer extends AbstractJsonSerializer<JSONEntryImpl> {
@Override
protected void doSerialize(final JSONEntryImpl entry, final JsonGenerator jgen, final SerializerProvider provider)
@ -45,55 +46,41 @@ public class JSONEntrySerializer extends ODataJacksonSerializer<JSONEntryImpl> {
if (entry.getMetadata() != null) {
jgen.writeStringField(Constants.JSON_METADATA, entry.getMetadata().toASCIIString());
}
if (StringUtils.isNotBlank(entry.getType())) {
jgen.writeStringField(Constants.JSON_TYPE, entry.getType());
}
if (entry.getId() != null) {
jgen.writeStringField(Constants.JSON_ID, entry.getId());
}
if (entry.getSelfLink() != null) {
jgen.writeStringField(Constants.JSON_READ_LINK, entry.getSelfLink().getHref());
}
if (entry.getEditLink() != null) {
jgen.writeStringField(Constants.JSON_EDIT_LINK, entry.getEditLink().getHref());
}
if (entry.getMediaContentSource() != null) {
jgen.writeStringField(Constants.JSON_MEDIAREAD_LINK, entry.getMediaContentSource());
}
if (entry.getMediaContentType() != null) {
jgen.writeStringField(Constants.JSON_MEDIA_CONTENT_TYPE, entry.getMediaContentType());
}
final Map<String, List<String>> entitySetLinks = new HashMap<String, List<String>>();
for (Link link : entry.getNavigationLinks()) {
ODataLinkType type = null;
try {
type = ODataLinkType.fromString(client.getServiceVersion(), link.getRel(), link.getType());
} catch (IllegalArgumentException e) {
// ignore
}
if (type == ODataLinkType.ENTITY_SET_NAVIGATION) {
final List<String> uris;
if (entitySetLinks.containsKey(link.getTitle())) {
uris = entitySetLinks.get(link.getTitle());
} else {
uris = new ArrayList<String>();
entitySetLinks.put(link.getTitle(), uris);
}
uris.add(link.getHref());
} else {
jgen.writeStringField(link.getTitle() + Constants.JSON_BIND_LINK_SUFFIX, link.getHref());
}
if (link.getInlineEntry() != null) {
jgen.writeObjectField(link.getTitle(), link.getInlineEntry());
} else if (link.getInlineFeed() != null) {
jgen.writeObjectField(link.getTitle(), link.getInlineFeed());
} else {
ODataLinkType type = null;
try {
type = ODataLinkType.fromString(client, link.getRel(), link.getType());
} catch (IllegalArgumentException e) {
// ignore
}
if (type == ODataLinkType.ENTITY_SET_NAVIGATION) {
final List<String> uris;
if (entitySetLinks.containsKey(link.getTitle())) {
uris = entitySetLinks.get(link.getTitle());
} else {
uris = new ArrayList<String>();
entitySetLinks.put(link.getTitle(), uris);
}
uris.add(link.getHref());
} else {
jgen.writeStringField(link.getTitle() + Constants.JSON_BIND_LINK_SUFFIX, link.getHref());
jgen.writeArrayFieldStart(link.getTitle());
for (Entry subEntry : link.getInlineFeed().getEntries()) {
jgen.writeObject(subEntry);
}
jgen.writeEndArray();
}
}
for (Map.Entry<String, List<String>> entitySetLink : entitySetLinks.entrySet()) {
@ -113,14 +100,16 @@ public class JSONEntrySerializer extends ODataJacksonSerializer<JSONEntryImpl> {
jgen.writeObjectField(link.getTitle(), link.getInlineEntry());
}
if (link.getInlineFeed() != null) {
jgen.writeObjectField(link.getTitle(), link.getInlineFeed());
jgen.writeArrayFieldStart(link.getTitle());
for (Entry subEntry : link.getInlineFeed().getEntries()) {
jgen.writeObject(subEntry);
}
jgen.writeEndArray();
}
}
if (entry.getMediaEntryProperties() == null) {
JSONDOMTreeUtils.writeSubtree(client, jgen, entry.getContent());
} else {
JSONDOMTreeUtils.writeSubtree(client, jgen, entry.getMediaEntryProperties());
for (Property property : entry.getProperties()) {
property(jgen, property, property.getName());
}
jgen.writeEndObject();

View File

@ -33,7 +33,7 @@ import org.apache.olingo.client.api.Constants;
* <br/>
* If metadata information is available, the corresponding entry fields and content will be populated.
*/
public class JSONFeedDeserializer extends ODataJacksonDeserializer<JSONFeedImpl> {
public class JSONFeedDeserializer extends AbstractJsonDeserializer<JSONFeedImpl> {
@Override
protected JSONFeedImpl doDeserialize(final JsonParser parser, final DeserializationContext ctxt)
@ -50,11 +50,11 @@ public class JSONFeedDeserializer extends ODataJacksonDeserializer<JSONFeedImpl>
if (tree.hasNonNull(Constants.JSON_METADATA)) {
feed.setMetadata(URI.create(tree.get(Constants.JSON_METADATA).textValue()));
}
if (tree.hasNonNull("odata.count")) {
feed.setCount(tree.get("odata.count").asInt());
if (tree.hasNonNull(Constants.JSON_COUNT)) {
feed.setCount(tree.get(Constants.JSON_COUNT).asInt());
}
if (tree.hasNonNull("odata.nextLink")) {
feed.setNext(URI.create(tree.get("odata.nextLink").textValue()));
if (tree.hasNonNull(Constants.JSON_NEXT_LINK)) {
feed.setNext(URI.create(tree.get(Constants.JSON_NEXT_LINK).textValue()));
}
if (tree.hasNonNull(Constants.JSON_VALUE)) {

View File

@ -19,6 +19,7 @@
package org.apache.olingo.client.core.data;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
@ -32,10 +33,13 @@ import org.apache.olingo.client.api.uri.SegmentType;
* @see JSONEntry
*/
@JsonDeserialize(using = JSONFeedDeserializer.class)
@JsonSerialize(using = JSONFeedSerializer.class)
public class JSONFeedImpl extends AbstractPayloadObject implements Feed {
private static final long serialVersionUID = -3576372289800799417L;
private String id;
private URI metadata;
private Integer count;
@ -73,11 +77,21 @@ public class JSONFeedImpl extends AbstractPayloadObject implements Feed {
this.metadata = metadata;
}
@Override
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
@Override
public Integer getCount() {
return count;
}
@Override
public void setCount(final Integer count) {
this.count = count;
}

View File

@ -0,0 +1,57 @@
/*
* 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.client.core.data;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.data.Entry;
public class JSONFeedSerializer extends AbstractJsonSerializer<JSONFeedImpl> {
@Override
protected void doSerialize(final JSONFeedImpl feed, final JsonGenerator jgen, final SerializerProvider provider)
throws IOException, JsonProcessingException {
jgen.writeStartObject();
if (feed.getMetadata() != null) {
jgen.writeStringField(Constants.JSON_METADATA, feed.getMetadata().toASCIIString());
}
if (feed.getId() != null) {
jgen.writeStringField(Constants.JSON_ID, feed.getId());
}
if (feed.getCount() != null) {
jgen.writeNumberField(Constants.JSON_COUNT, feed.getCount());
}
if (feed.getNext() != null) {
jgen.writeStringField(Constants.JSON_NEXT_LINK, feed.getNext().toASCIIString());
}
jgen.writeArrayFieldStart(Constants.JSON_VALUE);
for (Entry entry : feed.getEntries()) {
jgen.writeObject(entry);
}
jgen.writeEndArray();
}
}

View File

@ -0,0 +1,256 @@
/*
* 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.client.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.client.api.Constants;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.domain.geospatial.Geospatial;
import org.apache.olingo.client.api.domain.geospatial.GeospatialCollection;
import org.apache.olingo.client.api.domain.geospatial.LineString;
import org.apache.olingo.client.api.domain.geospatial.MultiLineString;
import org.apache.olingo.client.api.domain.geospatial.MultiPoint;
import org.apache.olingo.client.api.domain.geospatial.MultiPolygon;
import org.apache.olingo.client.api.domain.geospatial.Point;
import org.apache.olingo.client.api.domain.geospatial.Polygon;
class JSONGeoValueDeserializer {
private Point point(final Iterator<JsonNode> itor, final ODataJClientEdmPrimitiveType type, final String crs) {
Point point = null;
if (itor.hasNext()) {
point = new Point(GeoUtils.getDimension(type), crs);
point.setX(Double.valueOf(itor.next().asText()));
point.setY(Double.valueOf(itor.next().asText()));
}
return point;
}
private MultiPoint multipoint(final Iterator<JsonNode> itor, final ODataJClientEdmPrimitiveType type,
final String crs) {
MultiPoint multiPoint = null;
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, crs));
}
multiPoint = new MultiPoint(GeoUtils.getDimension(type), crs, points);
} else {
multiPoint = new MultiPoint(GeoUtils.getDimension(type), crs, Collections.<Point>emptyList());
}
return multiPoint;
}
private LineString lineString(final Iterator<JsonNode> itor, final ODataJClientEdmPrimitiveType type,
final String crs) {
LineString lineString = null;
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, crs));
}
lineString = new LineString(GeoUtils.getDimension(type), crs, points);
} else {
lineString = new LineString(GeoUtils.getDimension(type), crs, Collections.<Point>emptyList());
}
return lineString;
}
private MultiLineString multiLineString(final Iterator<JsonNode> itor, final ODataJClientEdmPrimitiveType type,
final String crs) {
MultiLineString multiLineString = null;
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, crs));
}
multiLineString = new MultiLineString(GeoUtils.getDimension(type), crs, lineStrings);
} else {
multiLineString = new MultiLineString(GeoUtils.getDimension(type), crs, Collections.<LineString>emptyList());
}
return multiLineString;
}
private Polygon polygon(final Iterator<JsonNode> itor, final ODataJClientEdmPrimitiveType type,
final String crs) {
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, crs));
}
}
}
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, crs));
}
}
}
return new Polygon(GeoUtils.getDimension(type), crs, intPoints, extPoints);
}
private MultiPolygon multiPolygon(final Iterator<JsonNode> itor, final ODataJClientEdmPrimitiveType type,
final String crs) {
MultiPolygon multiPolygon = null;
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, crs));
}
multiPolygon = new MultiPolygon(GeoUtils.getDimension(type), crs, polygons);
} else {
multiPolygon = new MultiPolygon(GeoUtils.getDimension(type), crs, Collections.<Polygon>emptyList());
}
return multiPolygon;
}
private GeospatialCollection collection(final Iterator<JsonNode> itor, final ODataJClientEdmPrimitiveType type,
final String crs) {
GeospatialCollection collection = null;
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 (ODataJClientEdmPrimitiveType.GeographyCollection.name().equals(collItemType)
|| ODataJClientEdmPrimitiveType.GeometryCollection.name().equals(collItemType)) {
callAsType = collItemType;
} else {
callAsType = (type == ODataJClientEdmPrimitiveType.GeographyCollection ? "Geography" : "Geometry")
+ collItemType;
}
geospatials.add(deserialize(geo, ODataJClientEdmPrimitiveType.valueOf(callAsType)));
}
collection = new GeospatialCollection(GeoUtils.getDimension(type), crs, geospatials);
} else {
collection = new GeospatialCollection(GeoUtils.getDimension(type), crs, Collections.<Geospatial>emptyList());
}
return collection;
}
public Geospatial deserialize(final JsonNode node, final ODataJClientEdmPrimitiveType type) {
final ODataJClientEdmPrimitiveType actualType;
if ((type == ODataJClientEdmPrimitiveType.Geography || type == ODataJClientEdmPrimitiveType.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 = ODataJClientEdmPrimitiveType.fromValue(type.toString() + nodeType);
} else {
actualType = type;
}
final Iterator<JsonNode> cooItor = node.has(Constants.JSON_COORDINATES)
? node.get(Constants.JSON_COORDINATES).elements()
: Collections.<JsonNode>emptyList().iterator();
String crs = null;
if (node.has(Constants.JSON_CRS)) {
crs = node.get(Constants.JSON_CRS).get(Constants.PROPERTIES).get(Constants.NAME).asText().split(":")[1];
}
Geospatial value = null;
switch (actualType) {
case GeographyPoint:
case GeometryPoint:
value = point(cooItor, type, crs);
break;
case GeographyMultiPoint:
case GeometryMultiPoint:
value = multipoint(cooItor, type, crs);
break;
case GeographyLineString:
case GeometryLineString:
value = lineString(cooItor, type, crs);
break;
case GeographyMultiLineString:
case GeometryMultiLineString:
value = multiLineString(cooItor, type, crs);
break;
case GeographyPolygon:
case GeometryPolygon:
value = polygon(cooItor, type, crs);
break;
case GeographyMultiPolygon:
case GeometryMultiPolygon:
value = multiPolygon(cooItor, type, crs);
break;
case GeographyCollection:
case GeometryCollection:
value = collection(node.get(Constants.JSON_GEOMETRIES).elements(), type, crs);
break;
default:
}
return value;
}
}

View File

@ -0,0 +1,175 @@
/*
* 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.client.core.data;
import com.fasterxml.jackson.core.JsonGenerator;
import java.io.IOException;
import java.util.Iterator;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.domain.geospatial.ComposedGeospatial;
import org.apache.olingo.client.api.domain.geospatial.Geospatial;
import org.apache.olingo.client.api.domain.geospatial.GeospatialCollection;
import org.apache.olingo.client.api.domain.geospatial.LineString;
import org.apache.olingo.client.api.domain.geospatial.MultiLineString;
import org.apache.olingo.client.api.domain.geospatial.MultiPoint;
import org.apache.olingo.client.api.domain.geospatial.MultiPolygon;
import org.apache.olingo.client.api.domain.geospatial.Point;
import org.apache.olingo.client.api.domain.geospatial.Polygon;
class JSONGeoValueSerializer {
private void crs(final JsonGenerator jgen, final String crs) throws IOException {
jgen.writeObjectFieldStart(Constants.JSON_CRS);
jgen.writeStringField(Constants.ATTR_TYPE, Constants.NAME);
jgen.writeObjectFieldStart(Constants.PROPERTIES);
jgen.writeStringField(Constants.NAME, "EPSG:" + crs);
jgen.writeEndObject();
jgen.writeEndObject();
}
private void point(final JsonGenerator jgen, final Point point) throws IOException {
jgen.writeNumber(point.getX());
jgen.writeNumber(point.getY());
}
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.getEdmSimpleType().equals(ODataJClientEdmPrimitiveType.GeographyCollection)
|| value.getEdmSimpleType().equals(ODataJClientEdmPrimitiveType.GeometryCollection)) {
jgen.writeStringField(Constants.ATTR_TYPE, ODataJClientEdmPrimitiveType.GeometryCollection.name());
} else {
final int yIdx = value.getEdmSimpleType().name().indexOf('y');
final String itemType = value.getEdmSimpleType().name().substring(yIdx + 1);
jgen.writeStringField(Constants.ATTR_TYPE, itemType);
}
switch (value.getEdmSimpleType()) {
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.getCrs() != null) {
crs(jgen, value.getCrs());
}
}
}

View File

@ -18,7 +18,6 @@
*/
package org.apache.olingo.client.core.data;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
@ -26,23 +25,14 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import java.net.URI;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.utils.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* Parse JSON string into <tt>JSONProperty</tt>.
* Parse JSON string into <tt>JSONPropertyImpl</tt>.
*
* @see JSONProperty
* @see JSONPropertyImpl
*/
public class JSONPropertyDeserializer extends ODataJacksonDeserializer<JSONPropertyImpl> {
public class JSONPropertyDeserializer extends AbstractJsonDeserializer<JSONPropertyImpl> {
@Override
protected JSONPropertyImpl doDeserialize(final JsonParser parser, final DeserializationContext ctxt)
@ -57,64 +47,36 @@ public class JSONPropertyDeserializer extends ODataJacksonDeserializer<JSONPrope
tree.remove(Constants.JSON_METADATA);
}
try {
final DocumentBuilder builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
final Document document = builder.newDocument();
Element content = document.createElement(Constants.ELEM_PROPERTY);
if (property.getMetadata() != null) {
final String metadataURI = property.getMetadata().toASCIIString();
final int dashIdx = metadataURI.lastIndexOf('#');
if (dashIdx != -1) {
content.setAttribute(Constants.ATTR_M_TYPE, metadataURI.substring(dashIdx + 1));
}
if (property.getMetadata() != null) {
final String metadataURI = property.getMetadata().toASCIIString();
final int dashIdx = metadataURI.lastIndexOf('#');
if (dashIdx != -1) {
property.setType(metadataURI.substring(dashIdx + 1));
}
}
JsonNode subtree = null;
if (tree.has(Constants.JSON_VALUE)) {
if (tree.has(Constants.JSON_TYPE)
&& StringUtils.isBlank(content.getAttribute(Constants.ATTR_M_TYPE))) {
if (tree.has(Constants.JSON_TYPE) && property.getType() == null) {
property.setType(tree.get(Constants.JSON_TYPE).asText());
}
content.setAttribute(Constants.ATTR_M_TYPE, tree.get(Constants.JSON_TYPE).asText());
}
if (tree.has(Constants.JSON_NULL) && tree.get(Constants.JSON_NULL).asBoolean()) {
property.setValue(new NullValueImpl());
}
final JsonNode value = tree.get(Constants.JSON_VALUE);
if (value.isValueNode()) {
content.appendChild(document.createTextNode(value.asText()));
} else if (ODataJClientEdmPrimitiveType.isGeospatial(content.getAttribute(Constants.ATTR_M_TYPE))) {
subtree = tree.objectNode();
((ObjectNode) subtree).put(Constants.JSON_VALUE, tree.get(Constants.JSON_VALUE));
if (StringUtils.isNotBlank(content.getAttribute(Constants.ATTR_M_TYPE))) {
((ObjectNode) subtree).put(
Constants.JSON_VALUE + "@" + Constants.JSON_TYPE,
content.getAttribute(Constants.ATTR_M_TYPE));
}
} else {
subtree = tree.get(Constants.JSON_VALUE);
}
JsonNode subtree = null;
if (tree.has(Constants.JSON_VALUE)) {
final JsonNode value = tree.get(Constants.JSON_VALUE);
if (value.isValueNode()) {
property.setValue(new PrimitiveValueImpl(value.asText()));
} else {
subtree = tree;
subtree = tree.get(Constants.JSON_VALUE);
}
} else {
subtree = tree;
}
if (subtree != null) {
JSONDOMTreeUtils.buildSubtree(client, content, subtree);
}
final List<Node> children = XMLUtils.getChildNodes(content, Node.ELEMENT_NODE);
if (children.size() == 1) {
final Element value = (Element) children.iterator().next();
if (Constants.JSON_VALUE.equals(XMLUtils.getSimpleName(value))) {
if (StringUtils.isNotBlank(content.getAttribute(Constants.ATTR_M_TYPE))) {
value.setAttribute(Constants.ATTR_M_TYPE, content.getAttribute(Constants.ATTR_M_TYPE));
}
content = value;
}
}
property.setContent(content);
} catch (ParserConfigurationException e) {
throw new JsonParseException("Cannot build property", parser.getCurrentLocation(), e);
if (property.getValue() == null && subtree != null) {
value(property, subtree);
}
return property;

View File

@ -21,21 +21,18 @@ package org.apache.olingo.client.core.data;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.net.URI;
import org.w3c.dom.Element;
/**
* A single property (primitive, complex or collection) represented via JSON.
*/
@JsonSerialize(using = JSONPropertySerializer.class)
@JsonDeserialize(using = JSONPropertyDeserializer.class)
public class JSONPropertyImpl extends AbstractPayloadObject {
public class JSONPropertyImpl extends AbstractPropertyImpl {
private static final long serialVersionUID = 553414431536637434L;
private URI metadata;
private Element content;
/**
* Gets metadata URI.
*
@ -53,22 +50,4 @@ public class JSONPropertyImpl extends AbstractPayloadObject {
public void setMetadata(final URI metadata) {
this.metadata = metadata;
}
/**
* Gets content.
*
* @return content as DOM element.
*/
public Element getContent() {
return content;
}
/**
* Sets content.
*
* @param content content as DOM element.
*/
public void setContent(final Element content) {
this.content = content;
}
}

View File

@ -19,28 +19,22 @@
package org.apache.olingo.client.core.data;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.utils.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.apache.olingo.client.api.data.Property;
/**
* Writes out JSON string from <tt>JSONProperty</tt>.
* Writes out JSON string from <tt>JSONPropertyImpl</tt>.
*
* @see JSONProperty
* @see JSONPropertyImpl
*/
public class JSONPropertySerializer extends ODataJacksonSerializer<JSONPropertyImpl> {
public class JSONPropertySerializer extends AbstractJsonSerializer<JSONPropertyImpl> {
@Override
public void doSerialize(final JSONPropertyImpl property, final JsonGenerator jgen, final SerializerProvider provider)
throws IOException, JsonProcessingException {
protected void doSerialize(final JSONPropertyImpl property, final JsonGenerator jgen,
final SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeStartObject();
@ -48,30 +42,15 @@ public class JSONPropertySerializer extends ODataJacksonSerializer<JSONPropertyI
jgen.writeStringField(Constants.JSON_METADATA, property.getMetadata().toASCIIString());
}
final Element content = property.getContent();
if (XMLUtils.hasOnlyTextChildNodes(content)) {
jgen.writeStringField(Constants.JSON_VALUE, content.getTextContent());
} else {
try {
final DocumentBuilder builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
final Document document = builder.newDocument();
final Element wrapper = document.createElement(Constants.ELEM_PROPERTY);
if (XMLUtils.hasElementsChildNode(content)) {
wrapper.appendChild(document.renameNode(
document.importNode(content, true), null, Constants.JSON_VALUE));
JSONDOMTreeUtils.writeSubtree(client, jgen, wrapper);
} else if (ODataJClientEdmPrimitiveType.isGeospatial(content.getAttribute(Constants.ATTR_M_TYPE))) {
wrapper.appendChild(document.renameNode(
document.importNode(content, true), null, Constants.JSON_VALUE));
JSONDOMTreeUtils.writeSubtree(client, jgen, wrapper, true);
} else {
JSONDOMTreeUtils.writeSubtree(client, jgen, content);
}
} catch (Exception e) {
throw new JsonParseException("Cannot serialize property", JsonLocation.NA, e);
if (property.getValue().isNull()) {
jgen.writeBooleanField(Constants.JSON_NULL, true);
} else if (property.getValue().isSimple()) {
jgen.writeStringField(Constants.JSON_VALUE, property.getValue().asSimple().get());
} else if (property.getValue().isGeospatial() || property.getValue().isCollection()) {
property(jgen, property, Constants.JSON_VALUE);
} else if (property.getValue().isComplex()) {
for (Property cproperty : property.getValue().asComplex().get()) {
property(jgen, cproperty, cproperty.getName());
}
}

View File

@ -34,6 +34,8 @@ public class LinkImpl extends AbstractPayloadObject implements Link {
private String type;
private String mediaETag;
private Entry entry;
private Feed feed;
@ -78,6 +80,16 @@ public class LinkImpl extends AbstractPayloadObject implements Link {
this.type = type;
}
@Override
public String getMediaETag() {
return mediaETag;
}
@Override
public void setMediaETag(final String mediaETag) {
this.mediaETag = mediaETag;
}
@Override
public Entry getInlineEntry() {
return entry;

View File

@ -18,24 +18,18 @@
*/
package org.apache.olingo.client.core.data;
import java.util.Date;
import org.apache.olingo.client.api.data.NullValue;
/**
* Common methods for <tt>AtomEntryImpl</tt> and <tt>AtomFeedImpl</tt>.
*
* @see AtomEntryImpl
* @see AtomFeedImpl
*/
public interface AtomObject {
public class NullValueImpl extends AbstractValue implements NullValue {
void setBaseURI(String baseURI);
@Override
public boolean isNull() {
return true;
}
void setId(String id);
void setTitle(String title);
void setSummary(String summary);
void setUpdated(Date updated);
@Override
public Void get() {
return null;
}
}

View File

@ -0,0 +1,41 @@
/*
* 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.client.core.data;
import org.apache.olingo.client.api.data.PrimitiveValue;
public class PrimitiveValueImpl extends AbstractValue implements PrimitiveValue {
private final String value;
public PrimitiveValueImpl(final String value) {
this.value = value;
}
@Override
public boolean isSimple() {
return true;
}
@Override
public String get() {
return value;
}
}

View File

@ -119,7 +119,7 @@ public class EdmTypeInfo {
} catch (IllegalArgumentException e) {
LOG.debug("{} does not appear to refer to an Edm primitive type", this.fullQualifiedName);
}
// TODO: implement Geospatial types!
// TODO - OLINGO-65 implement Geospatial types!
this.geospatialType = this.fullQualifiedName.getNamespace().equals(EdmPrimitiveType.EDM_NAMESPACE)
&& this.fullQualifiedName.getName().startsWith("Geo");
if (this.primitiveType == null && this.edm != null) {

View File

@ -29,7 +29,6 @@ import com.fasterxml.jackson.databind.DeserializationContext;
import java.io.IOException;
@SuppressWarnings("rawtypes")
public class EdmxDeserializer extends AbstractEdmDeserializer<AbstractEdmx> {
@Override
@ -59,7 +58,7 @@ public class EdmxDeserializer extends AbstractEdmDeserializer<AbstractEdmx> {
} else if ("Reference".equals(jp.getCurrentName())) {
jp.nextToken();
((org.apache.olingo.client.core.edm.xml.v4.EdmxImpl) edmx).getReferences().
add(jp.readValueAs( ReferenceImpl.class));
add(jp.readValueAs(ReferenceImpl.class));
}
}
}

View File

@ -48,7 +48,7 @@ public class AnnotationDeserializer extends AbstractEdmDeserializer<AnnotationIm
annotation.setConstExpr(parseAnnotationConstExprConstruct(jp));
} else {
// Dynamic Expressions
annotation.setDynExpr(jp.readValueAs( DynExprConstructImpl.class));
annotation.setDynExpr(jp.readValueAs(DynExprConstructImpl.class));
}
}
}

View File

@ -20,19 +20,18 @@ package org.apache.olingo.client.core.op.impl;
import java.io.StringWriter;
import java.net.URI;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import java.util.Iterator;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.data.Entry;
import org.apache.olingo.client.api.data.Feed;
import org.apache.olingo.client.api.data.Link;
import org.apache.olingo.client.api.data.LinkCollection;
import org.apache.olingo.client.api.domain.ODataOperation;
import org.apache.olingo.client.api.data.Property;
import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.client.api.data.ServiceDocumentItem;
import org.apache.olingo.client.api.data.Value;
import org.apache.olingo.client.api.domain.ODataCollectionValue;
import org.apache.olingo.client.api.domain.ODataComplexValue;
import org.apache.olingo.client.api.domain.ODataEntity;
@ -40,26 +39,26 @@ import org.apache.olingo.client.api.domain.ODataEntitySet;
import org.apache.olingo.client.api.domain.ODataGeospatialValue;
import org.apache.olingo.client.api.domain.ODataInlineEntity;
import org.apache.olingo.client.api.domain.ODataInlineEntitySet;
import org.apache.olingo.client.api.domain.ODataJClientEdmType;
import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
import org.apache.olingo.client.api.domain.ODataLink;
import org.apache.olingo.client.api.domain.ODataLinkCollection;
import org.apache.olingo.client.api.domain.ODataOperation;
import org.apache.olingo.client.api.domain.ODataPrimitiveValue;
import org.apache.olingo.client.api.domain.ODataProperty;
import org.apache.olingo.client.api.domain.ODataProperty.PropertyType;
import org.apache.olingo.client.api.domain.ODataServiceDocument;
import org.apache.olingo.client.api.domain.ODataValue;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.apache.olingo.client.api.op.ODataBinder;
import org.apache.olingo.client.api.utils.XMLUtils;
import org.apache.olingo.client.api.utils.URIUtils;
import org.apache.olingo.client.core.data.CollectionValueImpl;
import org.apache.olingo.client.core.data.ComplexValueImpl;
import org.apache.olingo.client.core.data.GeospatialValueImpl;
import org.apache.olingo.client.core.data.JSONPropertyImpl;
import org.apache.olingo.client.core.data.LinkImpl;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.client.core.data.NullValueImpl;
import org.apache.olingo.client.core.data.PrimitiveValueImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public abstract class AbstractODataBinder implements ODataBinder {
@ -76,25 +75,6 @@ public abstract class AbstractODataBinder implements ODataBinder {
this.client = client;
}
protected Element newEntryContent() {
Element properties = null;
try {
final DocumentBuilder builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
final Document doc = builder.newDocument();
properties = doc.createElement(Constants.ELEM_PROPERTIES);
properties.setAttribute(Constants.XMLNS_METADATA,
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
properties.setAttribute(Constants.XMLNS_DATASERVICES,
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
properties.setAttribute(Constants.XMLNS_GML, Constants.NS_GML);
properties.setAttribute(Constants.XMLNS_GEORSS, Constants.NS_GEORSS);
} catch (ParserConfigurationException e) {
LOG.error("Failure building entry content", e);
}
return properties;
}
@Override
public ODataServiceDocument getODataServiceDocument(final ServiceDocument resource) {
final ODataServiceDocument serviceDocument = new ODataServiceDocument();
@ -113,6 +93,8 @@ public abstract class AbstractODataBinder implements ODataBinder {
public Feed getFeed(final ODataEntitySet feed, final Class<? extends Feed> reference) {
final Feed feedResource = ResourceFactory.newFeed(reference);
feedResource.setCount(feed.getCount());
final URI next = feed.getNext();
if (next != null) {
feedResource.setNext(next);
@ -188,30 +170,94 @@ public abstract class AbstractODataBinder implements ODataBinder {
}
// -------------------------------------------------------------
final Element content = newEntryContent();
if (entity.isMediaEntity()) {
entry.setMediaEntryProperties(content);
entry.setMediaContentSource(entity.getMediaContentSource());
entry.setMediaContentType(entity.getMediaContentType());
} else {
entry.setContent(content);
}
for (ODataProperty prop : entity.getProperties()) {
content.appendChild(toDOMElement(prop, content.getOwnerDocument(), setType));
for (ODataProperty property : entity.getProperties()) {
entry.getProperties().add(getProperty(property, reference, setType));
}
return entry;
}
@Override
public Element toDOMElement(final ODataProperty prop) {
try {
return toDOMElement(prop, XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder().newDocument(), true);
} catch (ParserConfigurationException e) {
LOG.error("Error retrieving property DOM", e);
throw new IllegalArgumentException(e);
public Link getLink(final ODataLink link, boolean isXML) {
final Link linkResource = new LinkImpl();
linkResource.setRel(link.getRel());
linkResource.setTitle(link.getName());
linkResource.setHref(link.getLink() == null ? null : link.getLink().toASCIIString());
linkResource.setType(link.getType().toString());
linkResource.setMediaETag(link.getMediaETag());
if (link instanceof ODataInlineEntity) {
// append inline entity
final ODataEntity inlineEntity = ((ODataInlineEntity) link).getEntity();
LOG.debug("Append in-line entity\n{}", inlineEntity);
linkResource.setInlineEntry(getEntry(inlineEntity, ResourceFactory.entryClassForFormat(isXML)));
} else if (link instanceof ODataInlineEntitySet) {
// append inline feed
final ODataEntitySet InlineFeed = ((ODataInlineEntitySet) link).getEntitySet();
LOG.debug("Append in-line feed\n{}", InlineFeed);
linkResource.setInlineFeed(getFeed(InlineFeed, ResourceFactory.feedClassForFormat(isXML)));
}
return linkResource;
}
@Override
public Property getProperty(final ODataProperty property, final Class<? extends Entry> reference,
final boolean setType) {
final Property propertyResource = ResourceFactory.newProperty(reference);
propertyResource.setName(property.getName());
propertyResource.setValue(getValue(property.getValue(), reference, setType));
if (setType) {
if (property.hasPrimitiveValue()) {
propertyResource.setType(property.getPrimitiveValue().getTypeName());
} else if (property.hasComplexValue()) {
propertyResource.setType(property.getComplexValue().getTypeName());
} else if (property.hasCollectionValue()) {
propertyResource.setType(property.getCollectionValue().getTypeName());
}
}
return propertyResource;
}
private Value getValue(final ODataValue value, final Class<? extends Entry> reference, final boolean setType) {
Value valueResource = null;
if (value == null) {
valueResource = new NullValueImpl();
} else if (value.isPrimitive()) {
final ODataPrimitiveValue _value = value.asPrimitive();
if (_value instanceof ODataGeospatialValue) {
valueResource = new GeospatialValueImpl(((ODataGeospatialValue) _value).getGeospatial());
} else {
valueResource = new PrimitiveValueImpl(_value.toString());
}
} else if (value.isComplex()) {
final ODataComplexValue _value = value.asComplex();
valueResource = new ComplexValueImpl();
for (final Iterator<ODataProperty> itor = _value.iterator(); itor.hasNext();) {
valueResource.asComplex().get().add(getProperty(itor.next(), reference, setType));
}
} else if (value.isCollection()) {
final ODataCollectionValue _value = value.asCollection();
valueResource = new CollectionValueImpl();
for (final Iterator<ODataValue> itor = _value.iterator(); itor.hasNext();) {
valueResource.asCollection().get().add(getValue(itor.next(), reference, setType));
}
}
return valueResource;
}
@Override
@ -316,287 +362,55 @@ public abstract class AbstractODataBinder implements ODataBinder {
entity.getOperations().add(operation);
}
final Element content;
if (resource.isMediaEntry()) {
entity.setMediaEntity(true);
entity.setMediaContentSource(resource.getMediaContentSource());
entity.setMediaContentType(resource.getMediaContentType());
content = resource.getMediaEntryProperties();
} else {
content = resource.getContent();
}
if (content != null) {
for (Node property : XMLUtils.getChildNodes(content, Node.ELEMENT_NODE)) {
try {
entity.getProperties().add(getODataProperty((Element) property));
} catch (IllegalArgumentException e) {
LOG.warn("Failure retrieving EdmType for {}", property.getTextContent(), e);
}
}
for (Property property : resource.getProperties()) {
entity.getProperties().add(getODataProperty(property));
}
return entity;
}
@Override
public Link getLink(final ODataLink link, boolean isXML) {
final Link linkResource = new LinkImpl();
linkResource.setRel(link.getRel());
linkResource.setTitle(link.getName());
linkResource.setHref(link.getLink() == null ? null : link.getLink().toASCIIString());
linkResource.setType(link.getType().toString());
if (link instanceof ODataInlineEntity) {
// append inline entity
final ODataEntity inlineEntity = ((ODataInlineEntity) link).getEntity();
LOG.debug("Append in-line entity\n{}", inlineEntity);
linkResource.setInlineEntry(getEntry(inlineEntity, ResourceFactory.entryClassForFormat(isXML)));
} else if (link instanceof ODataInlineEntitySet) {
// append inline feed
final ODataEntitySet InlineFeed = ((ODataInlineEntitySet) link).getEntitySet();
LOG.debug("Append in-line feed\n{}", InlineFeed);
linkResource.setInlineFeed(getFeed(InlineFeed, ResourceFactory.feedClassForFormat(isXML)));
}
return linkResource;
public ODataProperty getODataProperty(final Property property) {
return new ODataProperty(property.getName(), getODataValue(property));
}
@Override
public ODataProperty getODataProperty(final Element property) {
final ODataProperty res;
private ODataValue getODataValue(final Property resource) {
ODataValue value = null;
final Node nullNode = property.getAttributes().getNamedItem(Constants.ATTR_M_NULL);
if (resource.getValue().isSimple()) {
value = new ODataPrimitiveValue.Builder(client).setText(resource.getValue().asSimple().get()).
setType(resource.getType() == null
? null
: ODataJClientEdmPrimitiveType.fromValue(resource.getType())).build();
} else if (resource.getValue().isGeospatial()) {
value = new ODataGeospatialValue.Builder(client).setValue(resource.getValue().asGeospatial().get()).
setType(resource.getType() == null
|| ODataJClientEdmPrimitiveType.Geography.toString().equals(resource.getType())
|| ODataJClientEdmPrimitiveType.Geometry.toString().equals(resource.getType())
? null
: ODataJClientEdmPrimitiveType.fromValue(resource.getType())).build();
} else if (resource.getValue().isComplex()) {
value = new ODataComplexValue(resource.getType());
if (nullNode == null) {
final ODataJClientEdmType edmType = StringUtils.isBlank(property.getAttribute(Constants.ATTR_M_TYPE))
? null
: new ODataJClientEdmType(property.getAttribute(Constants.ATTR_M_TYPE));
final PropertyType propType = edmType == null
? guessPropertyType(property)
: edmType.isCollection()
? PropertyType.COLLECTION
: edmType.isSimpleType()
? PropertyType.PRIMITIVE
: PropertyType.COMPLEX;
switch (propType) {
case COLLECTION:
res = fromCollectionPropertyElement(property, edmType);
break;
case COMPLEX:
res = fromComplexPropertyElement(property, edmType);
break;
case PRIMITIVE:
res = fromPrimitivePropertyElement(property, edmType);
break;
case EMPTY:
default:
res = client.getObjectFactory().newPrimitiveProperty(XMLUtils.getSimpleName(property), null);
for (Property property : resource.getValue().asComplex().get()) {
value.asComplex().add(getODataProperty(property));
}
} else {
res = client.getObjectFactory().newPrimitiveProperty(XMLUtils.getSimpleName(property), null);
}
} else if (resource.getValue().isCollection()) {
value = new ODataCollectionValue(resource.getType());
return res;
}
protected PropertyType guessPropertyType(final Element property) {
PropertyType res = null;
if (property.hasChildNodes()) {
final NodeList children = property.getChildNodes();
for (int i = 0; res == null && i < children.getLength(); i++) {
final Node child = children.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE
&& !child.getNodeName().startsWith(Constants.PREFIX_GML)) {
res = Constants.ELEM_ELEMENT.equals(XMLUtils.getSimpleName(child))
? PropertyType.COLLECTION
: PropertyType.COMPLEX;
}
for (Value _value : resource.getValue().asCollection().get()) {
final JSONPropertyImpl fake = new JSONPropertyImpl();
fake.setValue(_value);
value.asCollection().add(getODataValue(fake));
}
} else {
res = PropertyType.EMPTY;
}
if (res == null) {
res = PropertyType.PRIMITIVE;
}
return res;
}
protected Element toDOMElement(final ODataProperty prop, final Document doc, final boolean setType) {
final Element element;
if (prop.hasNullValue()) {
// null property handling
element = toNullPropertyElement(prop, doc);
} else if (prop.hasPrimitiveValue()) {
// primitive property handling
element = toPrimitivePropertyElement(prop, doc, setType);
} else if (prop.hasCollectionValue()) {
// collection property handling
element = toCollectionPropertyElement(prop, doc, setType);
} else {
// complex property handling
element = toComplexPropertyElement(prop, doc, setType);
}
element.setAttribute(Constants.XMLNS_METADATA,
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
element.setAttribute(Constants.XMLNS_DATASERVICES,
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
element.setAttribute(Constants.XMLNS_GML, Constants.NS_GML);
element.setAttribute(Constants.XMLNS_GEORSS, Constants.NS_GEORSS);
return element;
}
protected Element toNullPropertyElement(final ODataProperty prop, final Document doc) {
final Element element = doc.createElement(Constants.PREFIX_DATASERVICES + prop.getName());
element.setAttribute(Constants.ATTR_M_NULL, Boolean.toString(true));
return element;
}
protected Element toPrimitivePropertyElement(
final ODataProperty prop, final Document doc, final boolean setType) {
return toPrimitivePropertyElement(prop.getName(), prop.getPrimitiveValue(), doc, setType);
}
protected Element toPrimitivePropertyElement(
final String name, final ODataPrimitiveValue value, final Document doc, final boolean setType) {
final Element element = doc.createElement(Constants.PREFIX_DATASERVICES + name);
if (setType) {
element.setAttribute(Constants.ATTR_M_TYPE, value.getTypeName());
}
if (value instanceof ODataGeospatialValue) {
element.appendChild(doc.importNode(((ODataGeospatialValue) value).toTree(), true));
} else {
element.setTextContent(value.toString());
}
return element;
}
protected Element toCollectionPropertyElement(
final ODataProperty prop, final Document doc, final boolean setType) {
if (!prop.hasCollectionValue()) {
throw new IllegalArgumentException("Invalid property value type "
+ prop.getValue().getClass().getSimpleName());
}
final ODataCollectionValue value = prop.getCollectionValue();
final Element element = doc.createElement(Constants.PREFIX_DATASERVICES + prop.getName());
if (value.getTypeName() != null && setType) {
element.setAttribute(Constants.ATTR_M_TYPE, value.getTypeName());
}
for (ODataValue el : value) {
if (el.isPrimitive()) {
element.appendChild(
toPrimitivePropertyElement(Constants.ELEM_ELEMENT, el.asPrimitive(), doc, setType));
} else {
element.appendChild(
toComplexPropertyElement(Constants.ELEM_ELEMENT, el.asComplex(), doc, setType));
}
}
return element;
}
protected Element toComplexPropertyElement(
final ODataProperty prop, final Document doc, final boolean setType) {
return toComplexPropertyElement(prop.getName(), prop.getComplexValue(), doc, setType);
}
protected Element toComplexPropertyElement(
final String name, final ODataComplexValue value, final Document doc, final boolean setType) {
final Element element = doc.createElement(Constants.PREFIX_DATASERVICES + name);
if (value.getTypeName() != null && setType) {
element.setAttribute(Constants.ATTR_M_TYPE, value.getTypeName());
}
for (ODataProperty field : value) {
element.appendChild(toDOMElement(field, doc, true));
}
return element;
}
protected ODataPrimitiveValue fromPrimitiveValueElement(final Element prop, final ODataJClientEdmType edmType) {
final ODataPrimitiveValue value;
if (edmType != null && edmType.getSimpleType().isGeospatial()) {
final Element geoProp = Constants.PREFIX_GML.equals(prop.getPrefix())
? prop : (Element) XMLUtils.getChildNodes(prop, Node.ELEMENT_NODE).get(0);
value = client.getGeospatialValueBuilder().
setType(edmType.getSimpleType()).setTree(geoProp).build();
} else {
value = client.getPrimitiveValueBuilder().
setType(edmType == null ? null : edmType.getSimpleType()).setText(prop.getTextContent()).build();
}
return value;
}
protected ODataProperty fromPrimitivePropertyElement(final Element prop, final ODataJClientEdmType edmType) {
return client.getObjectFactory().newPrimitiveProperty(
XMLUtils.getSimpleName(prop), fromPrimitiveValueElement(prop, edmType));
}
protected ODataComplexValue fromComplexValueElement(final Element prop, final ODataJClientEdmType edmType) {
final ODataComplexValue value = new ODataComplexValue(edmType == null ? null : edmType.getTypeExpression());
for (Node child : XMLUtils.getChildNodes(prop, Node.ELEMENT_NODE)) {
value.add(getODataProperty((Element) child));
}
return value;
}
protected ODataProperty fromComplexPropertyElement(final Element prop, final ODataJClientEdmType edmType) {
return client.getObjectFactory().newComplexProperty(XMLUtils.getSimpleName(prop),
fromComplexValueElement(prop, edmType));
}
protected ODataProperty fromCollectionPropertyElement(final Element prop, final ODataJClientEdmType edmType) {
final ODataCollectionValue value =
new ODataCollectionValue(edmType == null ? null : edmType.getTypeExpression());
final ODataJClientEdmType type = edmType == null ? null : new ODataJClientEdmType(edmType.getBaseType());
final NodeList elements = prop.getChildNodes();
for (int i = 0; i < elements.getLength(); i++) {
if (elements.item(i).getNodeType() != Node.TEXT_NODE) {
final Element child = (Element) elements.item(i);
switch (guessPropertyType(child)) {
case COMPLEX:
value.add(fromComplexValueElement(child, type));
break;
case PRIMITIVE:
value.add(fromPrimitiveValueElement(child, type));
break;
default:
// do not add null or empty values
}
}
}
return client.getObjectFactory().newCollectionProperty(XMLUtils.getSimpleName(prop), value);
}
}

View File

@ -18,26 +18,20 @@
*/
package org.apache.olingo.client.core.op.impl;
import com.fasterxml.aalto.stax.InputFactoryImpl;
import com.fasterxml.aalto.stax.OutputFactoryImpl;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlFactory;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.data.Entry;
import org.apache.olingo.client.api.data.Error;
import org.apache.olingo.client.api.data.Feed;
import org.apache.olingo.client.api.data.LinkCollection;
import org.apache.olingo.client.api.data.Property;
import org.apache.olingo.client.api.format.ODataFormat;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.apache.olingo.client.api.op.ODataDeserializer;
import org.apache.olingo.client.core.data.AtomDeserializer;
import org.apache.olingo.client.core.data.AtomEntryImpl;
import org.apache.olingo.client.core.data.AtomFeedImpl;
import org.apache.olingo.client.core.data.AtomPropertyImpl;
import org.apache.olingo.client.core.data.JSONEntryImpl;
import org.apache.olingo.client.core.data.JSONErrorBundle;
import org.apache.olingo.client.core.data.JSONFeedImpl;
@ -45,9 +39,6 @@ import org.apache.olingo.client.core.data.JSONLinkCollectionImpl;
import org.apache.olingo.client.core.data.JSONPropertyImpl;
import org.apache.olingo.client.core.data.XMLErrorImpl;
import org.apache.olingo.client.core.data.XMLLinkCollectionImpl;
import org.apache.olingo.client.core.xml.XMLParser;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public abstract class AbstractODataDeserializer extends AbstractJacksonTool implements ODataDeserializer {
@ -57,135 +48,70 @@ public abstract class AbstractODataDeserializer extends AbstractJacksonTool impl
public AbstractODataDeserializer(final ODataClient client) {
super(client);
this.atomDeserializer = new AtomDeserializer(client);
this.atomDeserializer = new AtomDeserializer(client.getServiceVersion());
}
@Override
public Feed toFeed(final InputStream input, final ODataPubFormat format) {
return format == ODataPubFormat.ATOM
? toAtomFeed(input)
: toJSONFeed(input);
? atom(input, AtomFeedImpl.class)
: json(input, JSONFeedImpl.class);
}
@Override
public Entry toEntry(final InputStream input, final ODataPubFormat format) {
return format == ODataPubFormat.ATOM
? toAtomEntry(input)
: toJSONEntry(input);
? atom(input, AtomEntryImpl.class)
: json(input, JSONEntryImpl.class);
}
@Override
public Element toPropertyDOM(final InputStream input, final ODataFormat format) {
public Property toProperty(final InputStream input, final ODataFormat format) {
return format == ODataFormat.XML
? toPropertyDOMFromXML(input)
: toPropertyDOMFromJSON(input);
? atom(input, AtomPropertyImpl.class)
: json(input, JSONPropertyImpl.class);
}
@Override
public LinkCollection toLinkCollection(final InputStream input, final ODataFormat format) {
return format == ODataFormat.XML
? toLinkCollectionFromXML(input)
: toLinkCollectionFromJSON(input);
? xml(input, XMLLinkCollectionImpl.class)
: json(input, JSONLinkCollectionImpl.class);
}
@Override
public Error toError(final InputStream input, final boolean isXML) {
return isXML
? toErrorFromXML(input)
: toErrorFromJSON(input);
}
@Override
public Element toDOM(final InputStream input) {
return XMLParser.PARSER.deserialize(input);
? xml(input, XMLErrorImpl.class)
: json(input, JSONErrorBundle.class).getError();
}
/*
* ------------------ Protected methods ------------------
*/
protected Feed toAtomFeed(final InputStream input) {
protected <T> T xml(final InputStream input, final Class<T> reference) {
try {
return atomDeserializer.feed(toDOM(input));
return getXmlMapper().readValue(input, reference);
} catch (Exception e) {
throw new IllegalArgumentException("While deserializing Atom feed", e);
throw new IllegalArgumentException("While deserializing " + reference.getName(), e);
}
}
protected Entry toAtomEntry(final InputStream input) {
protected <T> T atom(final InputStream input, final Class<T> reference) {
try {
return atomDeserializer.entry(toDOM(input));
return atomDeserializer.read(input, reference);
} catch (Exception e) {
throw new IllegalArgumentException("While deserializing Atom entry", e);
throw new IllegalArgumentException("While deserializing " + reference.getName(), e);
}
}
protected Feed toJSONFeed(final InputStream input) {
protected <T> T json(final InputStream input, final Class<T> reference) {
try {
return getObjectMapper().readValue(input, JSONFeedImpl.class);
} catch (IOException e) {
throw new IllegalArgumentException("While deserializing JSON feed", e);
}
}
protected Entry toJSONEntry(final InputStream input) {
try {
return getObjectMapper().readValue(input, JSONEntryImpl.class);
} catch (IOException e) {
throw new IllegalArgumentException("While deserializing JSON entry", e);
}
}
protected Element toPropertyDOMFromXML(final InputStream input) {
return toDOM(input);
}
protected Element toPropertyDOMFromJSON(final InputStream input) {
try {
return getObjectMapper().readValue(input, JSONPropertyImpl.class).getContent();
} catch (IOException e) {
throw new IllegalArgumentException("While deserializing JSON property", e);
}
}
protected XMLLinkCollectionImpl toLinkCollectionFromXML(final InputStream input) {
final Element root = toDOM(input);
final NodeList uris = root.getOwnerDocument().getElementsByTagName(Constants.ELEM_URI);
final NodeList next = root.getElementsByTagName(Constants.NEXT_LINK_REL);
final XMLLinkCollectionImpl linkCollection = next.getLength() > 0
? new XMLLinkCollectionImpl(URI.create(next.item(0).getTextContent()))
: new XMLLinkCollectionImpl();
for (int i = 0; i < uris.getLength(); i++) {
linkCollection.getLinks().add(URI.create(uris.item(i).getTextContent()));
}
return linkCollection;
}
protected JSONLinkCollectionImpl toLinkCollectionFromJSON(final InputStream input) {
try {
return getObjectMapper().readValue(input, JSONLinkCollectionImpl.class);
} catch (IOException e) {
throw new IllegalArgumentException("While deserializing JSON $links", e);
}
}
protected Error toErrorFromXML(final InputStream input) {
try {
final XmlMapper xmlMapper = new XmlMapper(
new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule());
return xmlMapper.readValue(input, XMLErrorImpl.class);
return getObjectMapper().readValue(input, reference);
} catch (Exception e) {
throw new IllegalArgumentException("While deserializing XML error", e);
throw new IllegalArgumentException("While deserializing " + reference.getName(), e);
}
}
protected Error toErrorFromJSON(final InputStream input) {
try {
return getObjectMapper().readValue(input, JSONErrorBundle.class).getError();
} catch (IOException e) {
throw new IllegalArgumentException("While deserializing JSON error", e);
}
}
}

View File

@ -20,10 +20,9 @@ package org.apache.olingo.client.core.op.impl;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.data.Error;
import org.apache.olingo.client.api.data.Property;
import org.apache.olingo.client.api.domain.ODataEntity;
import org.apache.olingo.client.api.domain.ODataEntitySet;
import org.apache.olingo.client.api.domain.ODataEntitySetIterator;
@ -39,9 +38,6 @@ import org.apache.olingo.client.api.format.ODataValueFormat;
import org.apache.olingo.client.api.op.ODataReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public abstract class AbstractODataReader implements ODataReader {
@ -70,33 +66,7 @@ public abstract class AbstractODataReader implements ODataReader {
@Override
public ODataProperty readProperty(final InputStream input, final ODataFormat format) {
final Element property = client.getDeserializer().toPropertyDOM(input, format);
// The ODataProperty object is used either for actual entity properties and for invoke result
// (when return type is neither an entity nor a collection of entities).
// Such formats are mostly the same except for collections: an entity property looks like
// <aproperty m:type="Collection(AType)">
// <element>....</element>
// </aproperty>
//
// while an invoke result with returnType="Collection(AnotherType)" looks like
// <functionImportName>
// <element m:type="AnotherType">...</element>
// <functionImportName>
//
// The code below is meant for "normalizing" the latter into
// <functionImportName m:type="Collection(AnotherType)">
// <element m:type="AnotherType">...</element>
// <functionImportName>
final String type = property.getAttribute(Constants.ATTR_M_TYPE);
final NodeList elements = property.getElementsByTagName(Constants.ELEM_ELEMENT);
if (StringUtils.isBlank(type) && elements != null && elements.getLength() > 0) {
final Node elementType = elements.item(0).getAttributes().getNamedItem(Constants.ATTR_M_TYPE);
if (elementType != null) {
property.setAttribute(Constants.ATTR_M_TYPE, "Collection(" + elementType.getTextContent() + ")");
}
}
final Property property = client.getDeserializer().toProperty(input, format);
return client.getBinder().getODataProperty(property);
}

View File

@ -20,33 +20,25 @@ package org.apache.olingo.client.core.op.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import javax.xml.parsers.DocumentBuilder;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.data.Entry;
import org.apache.olingo.client.api.data.Feed;
import org.apache.olingo.client.api.data.Link;
import org.apache.olingo.client.api.data.Property;
import org.apache.olingo.client.api.format.ODataFormat;
import org.apache.olingo.client.api.op.ODataSerializer;
import org.apache.olingo.client.api.utils.XMLUtils;
import org.apache.olingo.client.core.data.AbstractPayloadObject;
import org.apache.olingo.client.core.data.AtomEntryImpl;
import org.apache.olingo.client.core.data.AtomFeedImpl;
import org.apache.olingo.client.core.data.AtomPropertyImpl;
import org.apache.olingo.client.core.data.AtomSerializer;
import org.apache.olingo.client.core.data.JSONEntryImpl;
import org.apache.olingo.client.core.data.JSONFeedImpl;
import org.apache.olingo.client.core.data.JSONPropertyImpl;
import org.apache.olingo.client.core.xml.XMLParser;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
public abstract class AbstractODataSerializer extends AbstractJacksonTool implements ODataSerializer {
@ -56,7 +48,8 @@ public abstract class AbstractODataSerializer extends AbstractJacksonTool implem
public AbstractODataSerializer(final ODataClient client) {
super(client);
this.atomSerializer = new AtomSerializer(client);
this.atomSerializer = new AtomSerializer(client.getServiceVersion());
}
@Override
@ -88,16 +81,16 @@ public abstract class AbstractODataSerializer extends AbstractJacksonTool implem
}
@Override
public void property(final Element element, final ODataFormat format, final OutputStream out) {
property(element, format, new OutputStreamWriter(out));
public void property(final Property obj, final OutputStream out) {
property(obj, new OutputStreamWriter(out));
}
@Override
public void property(final Element element, final ODataFormat format, final Writer writer) {
if (format == ODataFormat.XML) {
dom(element, writer);
public void property(final Property obj, final Writer writer) {
if (obj instanceof AtomPropertyImpl) {
atom((AtomPropertyImpl) obj, writer);
} else {
json(element, writer);
json((JSONPropertyImpl) obj, writer);
}
}
@ -109,34 +102,24 @@ public abstract class AbstractODataSerializer extends AbstractJacksonTool implem
@Override
public void link(final Link link, final ODataFormat format, final Writer writer) {
if (format == ODataFormat.XML) {
xmlLink(link, writer);
atom(link, writer);
} else {
jsonLink(link, writer);
}
}
@Override
public void dom(final Node content, final OutputStream out) {
dom(content, new OutputStreamWriter(out));
}
@Override
public void dom(final Node content, final Writer writer) {
XMLParser.PARSER.serialize(content, writer);
}
/*
* ------------------ Protected methods ------------------
*/
protected <T extends AbstractPayloadObject> void atom(final T obj, final Writer writer) {
protected <T> void atom(final T obj, final Writer writer) {
try {
dom(atomSerializer.serialize(obj), writer);
atomSerializer.write(writer, obj);
} catch (Exception e) {
throw new IllegalArgumentException("While serializing Atom object", e);
}
}
protected <T extends AbstractPayloadObject> void json(final T obj, final Writer writer) {
protected <T> void json(final T obj, final Writer writer) {
try {
getObjectMapper().writeValue(writer, obj);
} catch (IOException e) {
@ -144,31 +127,6 @@ public abstract class AbstractODataSerializer extends AbstractJacksonTool implem
}
}
protected void json(final Element element, final Writer writer) {
try {
final JSONPropertyImpl property = new JSONPropertyImpl();
property.setContent(element);
getObjectMapper().writeValue(writer, property);
} catch (IOException e) {
throw new IllegalArgumentException("While serializing JSON property", e);
}
}
protected void xmlLink(final Link link, final Writer writer) {
try {
final DocumentBuilder builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
final Document doc = builder.newDocument();
final Element uri = doc.createElementNS(
client.getServiceVersion().getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES),
Constants.ELEM_URI);
uri.appendChild(doc.createTextNode(link.getHref()));
dom(uri, writer);
} catch (Exception e) {
throw new IllegalArgumentException("While serializing XML link", e);
}
}
protected void jsonLink(final Link link, final Writer writer) {
final ObjectMapper mapper = getObjectMapper();
final ObjectNode uri = mapper.createObjectNode();

View File

@ -160,7 +160,8 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
*/
@Override
public ODataLink newEntityNavigationLink(final String name, final URI link) {
return new ODataLink(client.getServiceVersion(), link, ODataLinkType.ENTITY_NAVIGATION, name);
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(link).
setType(ODataLinkType.ENTITY_NAVIGATION).setTitle(name).build();
}
/**
@ -173,7 +174,8 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
*/
@Override
public ODataLink newEntityNavigationLink(final String name, final URI baseURI, final String href) {
return new ODataLink(client.getServiceVersion(), baseURI, href, ODataLinkType.ENTITY_NAVIGATION, name);
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(baseURI, href).
setType(ODataLinkType.ENTITY_NAVIGATION).setTitle(name).build();
}
/**
@ -185,7 +187,8 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
*/
@Override
public ODataLink newFeedNavigationLink(final String name, final URI link) {
return new ODataLink(client.getServiceVersion(), link, ODataLinkType.ENTITY_SET_NAVIGATION, name);
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(link).
setType(ODataLinkType.ENTITY_SET_NAVIGATION).setTitle(name).build();
}
/**
@ -198,7 +201,8 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
*/
@Override
public ODataLink newFeedNavigationLink(final String name, final URI baseURI, final String href) {
return new ODataLink(client.getServiceVersion(), baseURI, href, ODataLinkType.ENTITY_SET_NAVIGATION, name);
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(baseURI, href).
setType(ODataLinkType.ENTITY_SET_NAVIGATION).setTitle(name).build();
}
/**
@ -210,7 +214,8 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
*/
@Override
public ODataLink newAssociationLink(final String name, final URI link) {
return new ODataLink(client.getServiceVersion(), link, ODataLinkType.ASSOCIATION, name);
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(link).
setType(ODataLinkType.ASSOCIATION).setTitle(name).build();
}
/**
@ -223,7 +228,8 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
*/
@Override
public ODataLink newAssociationLink(final String name, final URI baseURI, final String href) {
return new ODataLink(client.getServiceVersion(), baseURI, href, ODataLinkType.ASSOCIATION, name);
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(baseURI, href).
setType(ODataLinkType.ASSOCIATION).setTitle(name).build();
}
/**
@ -235,7 +241,8 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
*/
@Override
public ODataLink newMediaEditLink(final String name, final URI link) {
return new ODataLink(client.getServiceVersion(), link, ODataLinkType.MEDIA_EDIT, name);
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(link).
setType(ODataLinkType.MEDIA_EDIT).setTitle(name).build();
}
/**
@ -248,7 +255,8 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
*/
@Override
public ODataLink newMediaEditLink(final String name, final URI baseURI, final String href) {
return new ODataLink(client.getServiceVersion(), baseURI, href, ODataLinkType.MEDIA_EDIT, name);
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(baseURI, href).
setType(ODataLinkType.MEDIA_EDIT).setTitle(name).build();
}
/**

View File

@ -27,9 +27,4 @@ public class ODataV3BinderImpl extends AbstractODataBinder {
public ODataV3BinderImpl(final ODataV3ClientImpl client) {
super(client);
}
// @Override
// protected EdmType newEdmType(final String expression) {
// return new EdmV3Type(expression);
// }
}

View File

@ -18,7 +18,6 @@
*/
package org.apache.olingo.client.core.op.impl;
import java.io.IOException;
import java.io.InputStream;
import org.apache.olingo.client.api.ODataClient;
@ -49,13 +48,9 @@ public class ODataV3DeserializerImpl extends AbstractODataDeserializer implement
@Override
public ServiceDocument toServiceDocument(final InputStream input, final ODataFormat format) {
try {
return format == ODataFormat.XML
? getXmlMapper().readValue(input, XMLServiceDocumentImpl.class)
: getObjectMapper().readValue(input, JSONServiceDocumentImpl.class);
} catch (IOException e) {
throw new IllegalArgumentException("Could not parse Service Document", e);
}
return format == ODataFormat.XML
? xml(input, XMLServiceDocumentImpl.class)
: json(input, JSONServiceDocumentImpl.class);
}
}

View File

@ -32,10 +32,6 @@ public class ODataV4BinderImpl extends AbstractODataBinder {
super(client);
}
// @Override
// protected EdmType newEdmType(final String expression) {
// return new EdmV4Type(expression);
// }
@Override
public ODataServiceDocument getODataServiceDocument(final ServiceDocument resource) {
final ODataServiceDocument serviceDocument = super.getODataServiceDocument(resource);

View File

@ -18,7 +18,6 @@
*/
package org.apache.olingo.client.core.op.impl;
import java.io.IOException;
import java.io.InputStream;
import org.apache.olingo.client.api.ODataClient;
@ -50,12 +49,9 @@ public class ODataV4DeserializerImpl extends AbstractODataDeserializer implement
@Override
public ServiceDocument toServiceDocument(final InputStream input, final ODataFormat format) {
try {
return format == ODataFormat.XML
? getXmlMapper().readValue(input, XMLServiceDocumentImpl.class)
: getObjectMapper().readValue(input, JSONServiceDocumentImpl.class);
} catch (IOException e) {
throw new IllegalArgumentException("Could not parse Service Document", e);
}
return format == ODataFormat.XML
? xml(input, XMLServiceDocumentImpl.class)
: json(input, JSONServiceDocumentImpl.class);
}
}

View File

@ -78,7 +78,8 @@ public class ODataWriterImpl implements ODataWriter {
public InputStream writeProperty(final ODataProperty property, final ODataFormat format) {
final ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
client.getSerializer().property(client.getBinder().toDOMElement(property), format, output);
client.getSerializer().property(client.getBinder().getProperty(
property, ResourceFactory.entryClassForFormat(format == ODataFormat.XML), true), output);
return new ByteArrayInputStream(output.toByteArray());
} finally {

View File

@ -20,11 +20,14 @@ package org.apache.olingo.client.core.op.impl;
import org.apache.olingo.client.api.data.Entry;
import org.apache.olingo.client.api.data.Feed;
import org.apache.olingo.client.api.data.Property;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.apache.olingo.client.core.data.AtomEntryImpl;
import org.apache.olingo.client.core.data.AtomFeedImpl;
import org.apache.olingo.client.core.data.AtomPropertyImpl;
import org.apache.olingo.client.core.data.JSONEntryImpl;
import org.apache.olingo.client.core.data.JSONFeedImpl;
import org.apache.olingo.client.core.data.JSONPropertyImpl;
public class ResourceFactory {
@ -65,6 +68,18 @@ public class ResourceFactory {
return result;
}
public static Property newProperty(final Class<? extends Entry> resourceClass) {
Property result = null;
if (AtomEntryImpl.class.equals(resourceClass)) {
result = new AtomPropertyImpl();
}
if (JSONEntryImpl.class.equals(resourceClass)) {
result = new JSONPropertyImpl();
}
return result;
}
/**
* Gets feed reference class from the given format.
*

View File

@ -1,53 +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.client.core.xml;
import org.apache.olingo.client.api.utils.XMLUtils;
import java.io.InputStream;
import java.io.Writer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
public class AndroidDOMParserImpl extends AbstractDOMParser {
@Override
public Element deserialize(final InputStream input) {
try {
return XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder().parse(input).getDocumentElement();
} catch (Exception e) {
throw new IllegalArgumentException("Could not parse DOM", e);
}
}
@Override
public void serialize(final Node content, final Writer writer) {
try {
TransformerFactory.newInstance().newTransformer().
transform(new DOMSource(content), new StreamResult(writer));
} catch (Exception e) {
throw new IllegalArgumentException("While serializing DOM element", e);
}
}
}

View File

@ -1,78 +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.client.core.xml;
import java.io.InputStream;
import java.io.Writer;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSParser;
import org.w3c.dom.ls.LSSerializer;
public class DefaultDOMParserImpl extends AbstractDOMParser {
private static final Object MONITOR = new Object();
private static DOMImplementationLS DOM_IMPL;
private void lazyInit() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
synchronized (MONITOR) {
if (DOM_IMPL == null) {
final DOMImplementationRegistry reg = DOMImplementationRegistry.newInstance();
DOM_IMPL = (DOMImplementationLS) reg.getDOMImplementation("LS");
}
}
}
@Override
public Element deserialize(final InputStream input) {
try {
lazyInit();
final LSParser parser = DOM_IMPL.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
final LSInput lsinput = DOM_IMPL.createLSInput();
lsinput.setByteStream(input);
return parser.parse(lsinput).getDocumentElement();
} catch (Exception e) {
throw new IllegalArgumentException("Could not parse DOM", e);
}
}
@Override
public void serialize(final Node content, final Writer writer) {
try {
lazyInit();
final LSSerializer serializer = DOM_IMPL.createLSSerializer();
final LSOutput lso = DOM_IMPL.createLSOutput();
lso.setCharacterStream(writer);
serializer.write(content, lso);
} catch (Exception e) {
throw new IllegalArgumentException("While serializing DOM element", e);
}
}
}

View File

@ -69,7 +69,7 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
if (ODataJClientEdmPrimitiveType.isGeospatial(value.getTypeName())) {
newValue = getClient().getGeospatialValueBuilder().
setType(ODataJClientEdmPrimitiveType.fromValue(value.getTypeName())).
setTree(((ODataGeospatialValue) value).toTree()).build();
setValue(((ODataGeospatialValue) value).getGeospatial()).build();
} else {
newValue = getClient().getPrimitiveValueBuilder().
setType(ODataJClientEdmPrimitiveType.fromValue(value.getTypeName())).

View File

@ -25,6 +25,7 @@ import org.apache.olingo.client.api.ODataV3Client;
import org.apache.olingo.client.api.ODataV4Client;
import org.apache.olingo.client.api.format.ODataFormat;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.BeforeClass;
public abstract class AbstractTest {
@ -35,6 +36,15 @@ public abstract class AbstractTest {
protected abstract ODataClient getClient();
@BeforeClass
public static void setUp() {
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreAttributeOrder(true);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setNormalizeWhitespace(true);
XMLUnit.setCompareUnmatched(false);
}
/**
* This is needed for correct number handling (Double, for example).
*/

View File

@ -0,0 +1,40 @@
/*
* 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.client.core;
import org.apache.olingo.client.api.Constants;
import org.custommonkey.xmlunit.ElementNameQualifier;
import org.w3c.dom.Element;
public class AtomLinksQualifier extends ElementNameQualifier {
@Override
public boolean qualifyForComparison(final Element control, final Element test) {
if (Constants.ATOM_ELEM_LINK.equals(control.getLocalName())
&& Constants.ATOM_ELEM_LINK.equals(test.getLocalName())) {
final String controlHref = control.getAttribute("href");
final String testHref = test.getAttribute("href");
return super.equalsNamespace(control, test) && controlHref != null && controlHref.equals(testHref);
} else {
return super.qualifyForComparison(control, test);
}
}
}

View File

@ -120,7 +120,7 @@ public class OpenTypeTestITCase extends AbstractV3TestITCase {
client.getPrimitiveValueBuilder().setType(ODataJClientEdmPrimitiveType.DateTime).setValue(new Date()).
build()));
final Point point = new Point(Geospatial.Dimension.GEOGRAPHY);
final Point point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
point.setX(1.2);
point.setY(2.1);
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aPoint",
@ -129,36 +129,35 @@ public class OpenTypeTestITCase extends AbstractV3TestITCase {
final List<Point> points = new ArrayList<Point>();
points.add(point);
points.add(point);
final MultiPoint multipoint = new MultiPoint(Geospatial.Dimension.GEOMETRY, points);
final MultiPoint multipoint = new MultiPoint(Geospatial.Dimension.GEOMETRY, null, points);
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aMultiPoint",
client.getGeospatialValueBuilder().setType(ODataJClientEdmPrimitiveType.GeometryMultiPoint).
setValue(multipoint).build()));
final LineString lineString = new LineString(Geospatial.Dimension.GEOMETRY, points);
final LineString lineString = new LineString(Geospatial.Dimension.GEOMETRY, null, points);
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aLineString",
client.getGeospatialValueBuilder().setType(ODataJClientEdmPrimitiveType.GeometryLineString).
setValue(lineString).build()));
final List<LineString> lineStrings = new ArrayList<LineString>();
lineStrings.add(lineString);
lineStrings.add(lineString);
final MultiLineString multiLineString = new MultiLineString(Geospatial.Dimension.GEOGRAPHY, lineStrings);
final MultiLineString multiLineString = new MultiLineString(Geospatial.Dimension.GEOGRAPHY, null, lineStrings);
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aMultiLineString",
client.getGeospatialValueBuilder().setType(ODataJClientEdmPrimitiveType.GeometryMultiLineString).
setValue(multiLineString).build()));
final Point otherPoint = new Point(Geospatial.Dimension.GEOGRAPHY);
final Point otherPoint = new Point(Geospatial.Dimension.GEOGRAPHY, null);
otherPoint.setX(3.4);
otherPoint.setY(4.3);
points.set(1, otherPoint);
points.add(otherPoint);
points.add(point);
final Polygon polygon =
new Polygon(Geospatial.Dimension.GEOGRAPHY, points, points);
final Polygon polygon = new Polygon(Geospatial.Dimension.GEOGRAPHY, null, points, points);
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aPolygon",
client.getGeospatialValueBuilder().setType(ODataJClientEdmPrimitiveType.GeographyPolygon).
setValue(polygon).build()));
final List<Polygon> polygons = new ArrayList<Polygon>();
polygons.add(polygon);
polygons.add(polygon);
final MultiPolygon multiPolygon = new MultiPolygon(Geospatial.Dimension.GEOGRAPHY, polygons);
final MultiPolygon multiPolygon = new MultiPolygon(Geospatial.Dimension.GEOGRAPHY, null, polygons);
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aMultiPolygon",
client.getGeospatialValueBuilder().setType(ODataJClientEdmPrimitiveType.GeographyMultiPolygon).
setValue(multiPolygon).build()));
@ -167,7 +166,7 @@ public class OpenTypeTestITCase extends AbstractV3TestITCase {
geospatials.add(polygon);
geospatials.add(multiLineString);
geospatials.add(multiPolygon);
final GeospatialCollection geoColl = new GeospatialCollection(Geospatial.Dimension.GEOGRAPHY, geospatials);
final GeospatialCollection geoColl = new GeospatialCollection(Geospatial.Dimension.GEOGRAPHY, null, geospatials);
row.getProperties().add(client.getObjectFactory().newPrimitiveProperty("aCollection",
client.getGeospatialValueBuilder().setType(ODataJClientEdmPrimitiveType.GeographyCollection).
setValue(geoColl).build()));

View File

@ -0,0 +1,132 @@
/*
* 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.client.core.v3;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.client.api.ODataV3Client;
import org.apache.olingo.client.api.format.ODataFormat;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.apache.olingo.client.core.AbstractTest;
import org.apache.olingo.client.core.AtomLinksQualifier;
import org.custommonkey.xmlunit.Diff;
import org.junit.Test;
public class AtomTest extends AbstractTest {
@Override
protected ODataV3Client getClient() {
return v3Client;
}
protected ODataPubFormat getODataPubFormat() {
return ODataPubFormat.ATOM;
}
protected ODataFormat getODataFormat() {
return ODataFormat.XML;
}
private String cleanup(final String input) throws Exception {
final TransformerFactory factory = TransformerFactory.newInstance();
final Source xslt = new StreamSource(getClass().getResourceAsStream("../atom_cleanup.xsl"));
final Transformer transformer = factory.newTransformer(xslt);
final StringWriter result = new StringWriter();
transformer.transform(new StreamSource(new ByteArrayInputStream(input.getBytes())), new StreamResult(result));
return result.toString();
}
protected void assertSimilar(final String filename, final String actual) throws Exception {
final Diff diff = new Diff(cleanup(IOUtils.toString(getClass().getResourceAsStream(filename))), actual);
diff.overrideElementQualifier(new AtomLinksQualifier());
assertTrue(diff.similar());
}
protected void feed(final String filename, final ODataPubFormat format) throws Exception {
final StringWriter writer = new StringWriter();
getClient().getSerializer().feed(getClient().getDeserializer().toFeed(
getClass().getResourceAsStream("Customer." + getSuffix(format)), format),
writer);
assertSimilar("Customer." + getSuffix(format), writer.toString());
}
@Test
public void feeds() throws Exception {
feed("Customer", getODataPubFormat());
}
protected void entry(final String filename, final ODataPubFormat format) throws Exception {
final StringWriter writer = new StringWriter();
getClient().getSerializer().entry(getClient().getDeserializer().toEntry(
getClass().getResourceAsStream(filename + "." + getSuffix(format)), format), writer);
assertSimilar(filename + "." + getSuffix(format), writer.toString());
}
@Test
public void entries() throws Exception {
entry("AllGeoTypesSet_-5", getODataPubFormat());
entry("AllGeoTypesSet_-8", getODataPubFormat());
entry("Car_16", getODataPubFormat());
entry("ComputerDetail_-10", getODataPubFormat());
entry("Customer_-10", getODataPubFormat());
entry("Products_1", getODataPubFormat());
entry("PersonDetails_0_Person", getODataPubFormat());
entry("Products_0_Categories", getODataPubFormat());
}
protected void property(final String filename, final ODataFormat format) throws Exception {
final StringWriter writer = new StringWriter();
getClient().getSerializer().property(getClient().getDeserializer().
toProperty(getClass().getResourceAsStream(filename + "." + getSuffix(format)), format), writer);
assertSimilar(filename + "." + getSuffix(format), writer.toString());
}
@Test
public void properties() throws Exception {
property("Products_1_DiscontinuedDate", getODataFormat());
property("AllGeoTypesSet_-10_GeogLine", getODataFormat());
property("AllGeoTypesSet_-10_GeogPoint", getODataFormat());
property("AllGeoTypesSet_-10_Geom", getODataFormat());
property("AllGeoTypesSet_-3_GeomMultiPolygon", getODataFormat());
property("AllGeoTypesSet_-5_GeogCollection", getODataFormat());
property("AllGeoTypesSet_-5_GeogPolygon", getODataFormat());
property("AllGeoTypesSet_-6_GeomMultiLine", getODataFormat());
property("AllGeoTypesSet_-7_GeomMultiPoint", getODataFormat());
property("AllGeoTypesSet_-8_GeomCollection", getODataFormat());
property("Customer_-10_BackupContactInfo", getODataFormat());
property("Customer_-10_PrimaryContactInfo", getODataFormat());
property("MessageAttachment_guid'1126a28b-a4af-4bbd-bf0a-2b2c22635565'_Attachment", getODataFormat());
property("MessageAttachment_guid'1126a28b-a4af-4bbd-bf0a-2b2c22635565'_AttachmentId", getODataFormat());
property("Product_-10_ComplexConcurrency_QueriedDateTime", getODataFormat());
property("Product_-10_Dimensions_Width", getODataFormat());
}
}

View File

@ -1,103 +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.client.core.v3;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.InputStream;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.ODataV3Client;
import org.apache.olingo.client.api.data.Entry;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.apache.olingo.client.api.utils.XMLUtils;
import org.apache.olingo.client.core.AbstractTest;
import org.junit.Test;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
public class EntryTest extends AbstractTest {
@Override
protected ODataV3Client getClient() {
return v3Client;
}
private void read(final ODataPubFormat format) throws IOException {
InputStream input = getClass().getResourceAsStream("Car_16." + getSuffix(format));
Entry entry = getClient().getDeserializer().toEntry(input, format);
assertNotNull(entry);
assertEquals("Car(16)", entry.getEditLink().getHref());
assertEquals(2, entry.getMediaEditLinks().size());
// this is a media entry
assertNull(entry.getContent());
final Element vin = XMLUtils.getChildElements(entry.getMediaEntryProperties(), "d:VIN").get(0);
assertNotNull(vin);
assertEquals("16", vin.getTextContent());
input.close();
// ---------------------------------------------
input = getClass().getResourceAsStream("Customer_-10." + getSuffix(format));
entry = getClient().getDeserializer().toEntry(input, format);
assertNotNull(entry);
input.close();
assertEquals("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer", entry.getType());
assertNotNull(entry.getBaseURI());
final Element content = entry.getContent();
assertEquals(Constants.ELEM_PROPERTIES, content.getNodeName());
boolean entered = false;
boolean checked = false;
for (int i = 0; i < content.getChildNodes().getLength(); i++) {
entered = true;
final Node property = content.getChildNodes().item(i);
if ("PrimaryContactInfo".equals(XMLUtils.getSimpleName(property))) {
checked = true;
assertEquals("Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails",
((Element) property).getAttribute(Constants.ATTR_M_TYPE));
}
}
assertTrue(entered);
assertTrue(checked);
}
@Test
public void atom() throws IOException {
read(ODataPubFormat.ATOM);
}
@Test
public void json() throws IOException {
read(ODataPubFormat.JSON_FULL_METADATA);
}
}

View File

@ -0,0 +1,106 @@
package org.apache.olingo.client.core.v3;
/*
* 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.
*/
import static org.junit.Assert.assertEquals;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.format.ODataFormat;
import org.apache.olingo.client.api.format.ODataPubFormat;
public class JSONTest extends AtomTest {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
@Override
protected ODataPubFormat getODataPubFormat() {
return ODataPubFormat.JSON;
}
@Override
protected ODataFormat getODataFormat() {
return ODataFormat.JSON;
}
private void cleanup(final ObjectNode node) {
if (node.has(Constants.JSON_TYPE)) {
node.remove(Constants.JSON_TYPE);
}
if (node.has(Constants.JSON_EDIT_LINK)) {
node.remove(Constants.JSON_EDIT_LINK);
}
if (node.has(Constants.JSON_READ_LINK)) {
node.remove(Constants.JSON_READ_LINK);
}
if (node.has(Constants.JSON_MEDIAEDIT_LINK)) {
node.remove(Constants.JSON_MEDIAEDIT_LINK);
}
if (node.has(Constants.JSON_MEDIAREAD_LINK)) {
node.remove(Constants.JSON_MEDIAREAD_LINK);
}
if (node.has(Constants.JSON_MEDIA_CONTENT_TYPE)) {
node.remove(Constants.JSON_MEDIA_CONTENT_TYPE);
}
final List<String> toRemove = new ArrayList<String>();
for (final Iterator<Map.Entry<String, JsonNode>> itor = node.fields(); itor.hasNext();) {
final Map.Entry<String, JsonNode> field = itor.next();
if (field.getKey().charAt(0) == '#'
|| field.getKey().endsWith(Constants.JSON_TYPE_SUFFIX)
|| field.getKey().endsWith(Constants.JSON_MEDIAEDIT_LINK_SUFFIX)
|| field.getKey().endsWith(Constants.JSON_MEDIA_CONTENT_TYPE_SUFFIX)
|| field.getKey().endsWith(Constants.JSON_ASSOCIATION_LINK_SUFFIX)
|| field.getKey().endsWith(Constants.JSON_MEDIA_ETAG_SUFFIX)) {
toRemove.add(field.getKey());
} else if (field.getValue().isObject()) {
cleanup((ObjectNode) field.getValue());
} else if (field.getValue().isArray()) {
for (final Iterator<JsonNode> arrayItems = field.getValue().elements(); arrayItems.hasNext();) {
final JsonNode arrayItem = arrayItems.next();
if (arrayItem.isObject()) {
cleanup((ObjectNode) arrayItem);
}
}
}
}
node.remove(toRemove);
}
@Override
protected void assertSimilar(final String filename, final String actual) throws Exception {
final JsonNode orig = OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream(filename)).
replace("Categories" + Constants.JSON_NAVIGATION_LINK_SUFFIX,
"Categories" + Constants.JSON_BIND_LINK_SUFFIX).
replace("\"Products(0)/Categories\"", "[\"Products(0)/Categories\"]").
replace(Constants.JSON_NAVIGATION_LINK_SUFFIX, Constants.JSON_BIND_LINK_SUFFIX));
cleanup((ObjectNode) orig);
assertEquals(orig, OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes())));
}
}

View File

@ -170,7 +170,7 @@ public class PrimitiveValueTest extends AbstractTest {
@Test
public void managePoint() {
final Point primitive = new Point(Geospatial.Dimension.GEOGRAPHY);
final Point primitive = new Point(Geospatial.Dimension.GEOGRAPHY, null);
primitive.setX(52.8606);
primitive.setY(173.334);
@ -194,27 +194,27 @@ public class PrimitiveValueTest extends AbstractTest {
@Test
public void manageLineString() {
final List<Point> points = new ArrayList<Point>();
Point point = new Point(Geospatial.Dimension.GEOGRAPHY);
Point point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
point.setX(40.5);
point.setY(40.5);
points.add(point);
point = new Point(Geospatial.Dimension.GEOGRAPHY);
point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
point.setX(30.5);
point.setY(30.5);
points.add(point);
point = new Point(Geospatial.Dimension.GEOGRAPHY);
point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
point.setX(20.5);
point.setY(40.5);
points.add(point);
point = new Point(Geospatial.Dimension.GEOGRAPHY);
point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
point.setX(10.5);
point.setY(30.5);
points.add(point);
final LineString primitive = new LineString(Geospatial.Dimension.GEOGRAPHY, points);
final LineString primitive = new LineString(Geospatial.Dimension.GEOGRAPHY, null, points);
final ODataValue value = getClient().getGeospatialValueBuilder().
setType(ODataJClientEdmPrimitiveType.GeographyLineString).setValue(primitive).build();
@ -234,12 +234,12 @@ public class PrimitiveValueTest extends AbstractTest {
@Test
public void manageMultiPoint() {
final List<Point> points = new ArrayList<Point>();
Point point = new Point(Geospatial.Dimension.GEOMETRY);
Point point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(0);
point.setY(0);
points.add(point);
final MultiPoint primitive = new MultiPoint(Geospatial.Dimension.GEOMETRY, points);
final MultiPoint primitive = new MultiPoint(Geospatial.Dimension.GEOMETRY, null, points);
final ODataValue value = getClient().getGeospatialValueBuilder().
setType(ODataJClientEdmPrimitiveType.GeometryMultiPoint).setValue(primitive).build();
@ -258,48 +258,48 @@ public class PrimitiveValueTest extends AbstractTest {
// line one ...
List<Point> points = new ArrayList<Point>();
Point point = new Point(Geospatial.Dimension.GEOMETRY);
Point point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(10);
point.setY(10);
points.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(20);
point.setY(20);
points.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(10);
point.setY(40);
points.add(point);
lines.add(new LineString(Geospatial.Dimension.GEOMETRY, points));
lines.add(new LineString(Geospatial.Dimension.GEOMETRY, null, points));
// line two ...
points = new ArrayList<Point>();
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(40);
point.setY(40);
points.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(30);
point.setY(30);
points.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(40);
point.setY(20);
points.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(30);
point.setY(10);
points.add(point);
lines.add(new LineString(Geospatial.Dimension.GEOMETRY, points));
lines.add(new LineString(Geospatial.Dimension.GEOMETRY, null, points));
final MultiLineString primitive = new MultiLineString(Geospatial.Dimension.GEOMETRY, lines);
final MultiLineString primitive = new MultiLineString(Geospatial.Dimension.GEOMETRY, null, lines);
final ODataValue value =
getClient().getGeospatialValueBuilder().setType(ODataJClientEdmPrimitiveType.GeometryMultiLineString).
@ -327,32 +327,32 @@ public class PrimitiveValueTest extends AbstractTest {
final List<Point> interior = new ArrayList<Point>();
final List<Point> exterior = new ArrayList<Point>();
Point point = new Point(Geospatial.Dimension.GEOGRAPHY);
Point point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
point.setX(5);
point.setY(15);
exterior.add(point);
point = new Point(Geospatial.Dimension.GEOGRAPHY);
point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
point.setX(10);
point.setY(40);
exterior.add(point);
point = new Point(Geospatial.Dimension.GEOGRAPHY);
point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
point.setX(20);
point.setY(10);
exterior.add(point);
point = new Point(Geospatial.Dimension.GEOGRAPHY);
point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
point.setX(10);
point.setY(5);
exterior.add(point);
point = new Point(Geospatial.Dimension.GEOGRAPHY);
point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
point.setX(5);
point.setY(15);
exterior.add(point);
final Polygon primitive = new Polygon(Geospatial.Dimension.GEOGRAPHY, interior, exterior);
final Polygon primitive = new Polygon(Geospatial.Dimension.GEOGRAPHY, null, interior, exterior);
final ODataValue value =
getClient().getGeospatialValueBuilder().setType(ODataJClientEdmPrimitiveType.GeographyPolygon).
@ -379,86 +379,86 @@ public class PrimitiveValueTest extends AbstractTest {
List<Point> exterior = new ArrayList<Point>();
// exterior one ...
Point point = new Point(Geospatial.Dimension.GEOMETRY);
Point point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(40);
point.setY(40);
exterior.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(20);
point.setY(45);
exterior.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(45);
point.setY(30);
exterior.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(40);
point.setY(40);
exterior.add(point);
polygons.add(new Polygon(Geospatial.Dimension.GEOMETRY, interior, exterior));
polygons.add(new Polygon(Geospatial.Dimension.GEOMETRY, null, interior, exterior));
// interior two ...
interior = new ArrayList<Point>();
exterior = new ArrayList<Point>();
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(30);
point.setY(20);
interior.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(20);
point.setY(25);
interior.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(20);
point.setY(15);
interior.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(30);
point.setY(20);
interior.add(point);
// exterior two ...
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(20);
point.setY(35);
exterior.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(45);
point.setY(20);
exterior.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(30);
point.setY(5);
exterior.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(10);
point.setY(10);
exterior.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(10);
point.setY(30);
exterior.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(20);
point.setY(35);
exterior.add(point);
polygons.add(new Polygon(Geospatial.Dimension.GEOMETRY, interior, exterior));
polygons.add(new Polygon(Geospatial.Dimension.GEOMETRY, null, interior, exterior));
final MultiPolygon primitive = new MultiPolygon(Geospatial.Dimension.GEOMETRY, polygons);
final MultiPolygon primitive = new MultiPolygon(Geospatial.Dimension.GEOMETRY, null, polygons);
final ODataValue value =
getClient().getGeospatialValueBuilder().setType(ODataJClientEdmPrimitiveType.GeometryMultiPolygon).
@ -492,19 +492,19 @@ public class PrimitiveValueTest extends AbstractTest {
public void manageGeomCollection() {
final List<Geospatial> collection = new ArrayList<Geospatial>();
Point point = new Point(Geospatial.Dimension.GEOMETRY);
Point point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(1);
point.setY(2);
point.setZ(3);
collection.add(point);
point = new Point(Geospatial.Dimension.GEOMETRY);
point = new Point(Geospatial.Dimension.GEOMETRY, null);
point.setX(4);
point.setY(5);
point.setZ(6);
collection.add(point);
final GeospatialCollection primitive = new GeospatialCollection(Geospatial.Dimension.GEOMETRY, collection);
final GeospatialCollection primitive = new GeospatialCollection(Geospatial.Dimension.GEOMETRY, null, collection);
final ODataValue value =
getClient().getGeospatialValueBuilder().setType(ODataJClientEdmPrimitiveType.GeometryCollection).
@ -524,19 +524,19 @@ public class PrimitiveValueTest extends AbstractTest {
public void manageGeogCollection() {
final List<Geospatial> collection = new ArrayList<Geospatial>();
Point point = new Point(Geospatial.Dimension.GEOGRAPHY);
Point point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
point.setX(1);
point.setY(2);
point.setZ(3);
collection.add(point);
point = new Point(Geospatial.Dimension.GEOGRAPHY);
point = new Point(Geospatial.Dimension.GEOGRAPHY, null);
point.setX(4);
point.setY(5);
point.setZ(6);
collection.add(point);
final GeospatialCollection primitive = new GeospatialCollection(Geospatial.Dimension.GEOGRAPHY, collection);
final GeospatialCollection primitive = new GeospatialCollection(Geospatial.Dimension.GEOGRAPHY, null, collection);
final ODataValue value =
getClient().getGeospatialValueBuilder().setType(ODataJClientEdmPrimitiveType.GeographyCollection).

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2005/Atom"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
version="1.0">
<xsl:template match="atom:updated"/>
<xsl:template match="atom:author"/>
<xsl:template match="atom:title">
<xsl:if test="string-length(.) &gt; 0">
<title type="{@type}">
<xsl:apply-templates/>
</title>
</xsl:if>
</xsl:template>
<xsl:template match="atom:link[@rel = 'self' or @rel = 'edit' or @rel = 'edit-media']"/>
<xsl:template match="m:action"/>
<xsl:template match="@*[name() = 'm:etag']"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

View File

@ -0,0 +1 @@
{"odata.metadata":"http://192.168.0.160:8080/DefaultService.svc/$metadata#Edm.GeographyLineString","odata.type":"Edm.GeographyLineString","value":{"type":"LineString","coordinates":[[40.5,40.5],[30.5,30.5],[20.5,40.5],[10.5,30.5]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<d:GeogLine xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:type="Edm.GeographyLineString"><gml:LineString gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326"><gml:pos>40.5 40.5</gml:pos><gml:pos>30.5 30.5</gml:pos><gml:pos>20.5 40.5</gml:pos><gml:pos>10.5 30.5</gml:pos></gml:LineString></d:GeogLine>

View File

@ -0,0 +1 @@
{"odata.metadata":"http://192.168.0.160:8080/DefaultService.svc/$metadata#Edm.GeographyPoint","odata.type":"Edm.GeographyPoint","value":{"type":"Point","coordinates":[52.8606,173.334],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<d:GeogPoint xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:type="Edm.GeographyPoint"><gml:Point gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326"><gml:pos>52.8606 173.334</gml:pos></gml:Point></d:GeogPoint>

View File

@ -0,0 +1 @@
{"odata.metadata":"http://192.168.0.160:8080/DefaultService.svc/$metadata#Edm.GeometryMultiPolygon","value":{"type":"MultiPolygon","coordinates":[[[[40.0,40.0],[20.0,45.0],[45.0,30.0],[40.0,40.0]]],[[[20.0,35.0],[45.0,20.0],[30.0,5.0],[10.0,10.0],[10.0,30.0],[20.0,35.0]],[[30.0,20.0],[20.0,25.0],[20.0,15.0],[30.0,20.0]]]],"crs":{"type":"name","properties":{"name":"EPSG:0"}}}}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<d:GeomMultiPolygon xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:type="Edm.GeometryMultiPolygon"><gml:MultiSurface gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0"><gml:surfaceMembers><gml:Polygon><gml:exterior><gml:LinearRing><gml:pos>40 40</gml:pos><gml:pos>20 45</gml:pos><gml:pos>45 30</gml:pos><gml:pos>40 40</gml:pos></gml:LinearRing></gml:exterior></gml:Polygon><gml:Polygon><gml:exterior><gml:LinearRing><gml:pos>20 35</gml:pos><gml:pos>45 20</gml:pos><gml:pos>30 5</gml:pos><gml:pos>10 10</gml:pos><gml:pos>10 30</gml:pos><gml:pos>20 35</gml:pos></gml:LinearRing></gml:exterior><gml:interior><gml:LinearRing><gml:pos>30 20</gml:pos><gml:pos>20 25</gml:pos><gml:pos>20 15</gml:pos><gml:pos>30 20</gml:pos></gml:LinearRing></gml:interior></gml:Polygon></gml:surfaceMembers></gml:MultiSurface></d:GeomMultiPolygon>

Some files were not shown because too many files have changed in this diff Show More