You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by il...@apache.org on 2014/03/24 09:45:43 UTC
[6/9] [OLINGO-200] Moving Atom and JSON (de)serializer to commons
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AbstractValue.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AbstractValue.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AbstractValue.java
deleted file mode 100644
index 9f2d19a..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AbstractValue.java
+++ /dev/null
@@ -1,98 +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 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);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomDeserializer.java
deleted file mode 100644
index 74d98a6..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomDeserializer.java
+++ /dev/null
@@ -1,370 +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 org.apache.olingo.client.core.data.v3.XMLLinkCollectionImpl;
-import java.io.InputStream;
-import java.net.URI;
-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.commons.api.domain.ODataOperation;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class AtomDeserializer extends AbstractAtomDealer {
-
- private static final Logger LOG = LoggerFactory.getLogger(AtomDeserializer.class);
-
- private static final XMLInputFactory FACTORY = XMLInputFactory.newInstance();
-
- private final AtomPropertyDeserializer propDeserializer;
-
- public AtomDeserializer(final ODataServiceVersion version) {
- super(version);
- this.propDeserializer = new AtomPropertyDeserializer(version);
- }
-
- 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");
- }
-
- return startEvent;
- }
-
- private void common(final XMLEventReader reader, final StartElement start,
- final AbstractAtomObject object, final String key) throws XMLStreamException {
-
- boolean foundEndElement = false;
- while (reader.hasNext() && !foundEndElement) {
- final XMLEvent event = reader.nextEvent();
-
- 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;
- }
- }
- }
-
- 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 XMLLinkCollectionImpl linkCollection(final InputStream input) throws XMLStreamException {
- final XMLEventReader reader = FACTORY.createXMLEventReader(input);
-
- final XMLLinkCollectionImpl linkCollection = new XMLLinkCollectionImpl();
-
- boolean isURI = false;
- boolean isNext = false;
- while (reader.hasNext()) {
- final XMLEvent event = reader.nextEvent();
- if (event.isStartElement()) {
- isURI = uriQName.equals(event.asStartElement().getName());
- isNext = nextQName.equals(event.asStartElement().getName());
- }
-
- if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
- if (isURI) {
- linkCollection.getLinks().add(URI.create(event.asCharacters().getData()));
- isURI = false;
- } else if (isNext) {
- linkCollection.setNext(URI.create(event.asCharacters().getData()));
- isNext = false;
- }
- }
- }
-
- return linkCollection;
- }
-
- 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();
- 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());
- }
-
- boolean foundEndEntry = false;
- while (reader.hasNext() && !foundEndEntry) {
- final XMLEvent event = reader.nextEvent();
-
- 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());
- }
-
- 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()));
- }
-
- 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 (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
- foundEndEntry = true;
- }
- }
-
- return entry;
- }
-
- 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();
- final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE);
- if (xmlBase != null) {
- feed.setBaseURI(xmlBase.getValue());
- }
-
- 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()));
- }
- }
-
- 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);
- } else if (XMLLinkCollectionImpl.class.equals(reference)) {
- return (T) linkCollection(input);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomEntryImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomEntryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomEntryImpl.java
deleted file mode 100644
index aa7c0c1..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomEntryImpl.java
+++ /dev/null
@@ -1,25 +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;
-
-public class AtomEntryImpl extends AbstractEntry {
-
- private static final long serialVersionUID = 6973729343868293279L;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomFeedImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomFeedImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomFeedImpl.java
deleted file mode 100644
index 94f2540..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomFeedImpl.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.client.core.data;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.olingo.client.api.data.Entry;
-import org.apache.olingo.client.api.data.Feed;
-
-/**
- * List of entries, represented via Atom.
- *
- * @see AtomEntry
- */
-public class AtomFeedImpl extends AbstractAtomObject implements Feed {
-
- private static final long serialVersionUID = 5466590540021319153L;
-
- private Integer count;
-
- private final List<Entry> entries = new ArrayList<Entry>();
-
- private URI next;
-
- @Override
- public void setCount(final Integer count) {
- this.count = count;
- }
-
- @Override
- public Integer getCount() {
- return count;
- }
-
- @Override
- public List<Entry> getEntries() {
- return entries;
- }
-
- @Override
- public void setNext(final URI next) {
- this.next = next;
- }
-
- @Override
- public URI getNext() {
- return next;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomGeoValueDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomGeoValueDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomGeoValueDeserializer.java
deleted file mode 100644
index 1187a81..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomGeoValueDeserializer.java
+++ /dev/null
@@ -1,261 +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 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.data.GeoUtils;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.geo.Geospatial;
-import org.apache.olingo.commons.api.edm.geo.GeospatialCollection;
-import org.apache.olingo.commons.api.edm.geo.LineString;
-import org.apache.olingo.commons.api.edm.geo.MultiLineString;
-import org.apache.olingo.commons.api.edm.geo.MultiPoint;
-import org.apache.olingo.commons.api.edm.geo.MultiPolygon;
-import org.apache.olingo.commons.api.edm.geo.Point;
-import org.apache.olingo.commons.api.edm.geo.Polygon;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
-
-class AtomGeoValueDeserializer {
-
- private List<Point> points(final XMLEventReader reader, final StartElement start,
- final EdmPrimitiveTypeKind 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);
- try {
- point.setX(EdmDouble.getInstance().valueOfString(pointInfo[0], null, null,
- Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class));
- point.setY(EdmDouble.getInstance().valueOfString(pointInfo[1], null, null,
- Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class));
- } catch (EdmPrimitiveTypeException e) {
- throw new XMLStreamException("While deserializing point coordinates as double", e);
- }
- 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 EdmPrimitiveTypeKind 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 EdmPrimitiveTypeKind 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 EdmPrimitiveTypeKind 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 EdmPrimitiveTypeKind 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 EdmPrimitiveTypeKind 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 EdmPrimitiveTypeKind 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 EdmPrimitiveTypeKind 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;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomGeoValueSerializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomGeoValueSerializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomGeoValueSerializer.java
deleted file mode 100644
index 02425b4..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomGeoValueSerializer.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.client.core.data;
-
-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.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.geo.Geospatial;
-import org.apache.olingo.commons.api.edm.geo.GeospatialCollection;
-import org.apache.olingo.commons.api.edm.geo.LineString;
-import org.apache.olingo.commons.api.edm.geo.MultiLineString;
-import org.apache.olingo.commons.api.edm.geo.MultiPoint;
-import org.apache.olingo.commons.api.edm.geo.MultiPolygon;
-import org.apache.olingo.commons.api.edm.geo.Point;
-import org.apache.olingo.commons.api.edm.geo.Polygon;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
-
-class AtomGeoValueSerializer {
-
- private void points(final XMLStreamWriter writer, final Iterator<Point> itor, final boolean wrap)
- throws XMLStreamException {
-
- while (itor.hasNext()) {
- final Point point = itor.next();
-
- if (wrap) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POINT, Constants.NS_GML);
- }
-
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POS, Constants.NS_GML);
- try {
- writer.writeCharacters(EdmDouble.getInstance().valueToString(point.getX(), null, null,
- Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)
- + " "
- + EdmDouble.getInstance().valueToString(point.getY(), null, null,
- Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null));
- } catch (EdmPrimitiveTypeException e) {
- throw new XMLStreamException("While serializing point coordinates as double", e);
- }
- writer.writeEndElement();
-
- if (wrap) {
- writer.writeEndElement();
- }
- }
- }
-
- private void lineStrings(final XMLStreamWriter writer, final Iterator<LineString> itor, final boolean wrap)
- throws XMLStreamException {
-
- while (itor.hasNext()) {
- final LineString lineString = itor.next();
-
- if (wrap) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_LINESTRING, Constants.NS_GML);
- }
-
- points(writer, lineString.iterator(), false);
-
- if (wrap) {
- writer.writeEndElement();
- }
- }
- }
-
- private void polygons(final XMLStreamWriter writer, final Iterator<Polygon> itor, final boolean wrap)
- throws XMLStreamException {
-
- while (itor.hasNext()) {
- final Polygon polygon = itor.next();
-
- if (wrap) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON, Constants.NS_GML);
- }
-
- if (!polygon.getExterior().isEmpty()) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_EXTERIOR, Constants.NS_GML);
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_LINEARRING, Constants.NS_GML);
-
- points(writer, polygon.getExterior().iterator(), false);
-
- writer.writeEndElement();
- writer.writeEndElement();
- }
- if (!polygon.getInterior().isEmpty()) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_INTERIOR, Constants.NS_GML);
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_LINEARRING, Constants.NS_GML);
-
- points(writer, polygon.getInterior().iterator(), false);
-
- writer.writeEndElement();
- writer.writeEndElement();
- }
-
- if (wrap) {
- writer.writeEndElement();
- }
- }
- }
-
- private void writeSrsName(final XMLStreamWriter writer, final Geospatial value) throws XMLStreamException {
- if (value.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.getEdmPrimitiveTypeKind()) {
- case GeographyPoint:
- case GeometryPoint:
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POINT, Constants.NS_GML);
- writeSrsName(writer, value);
-
- points(writer, Collections.singleton((Point) value).iterator(), false);
-
- writer.writeEndElement();
- break;
-
- case GeometryMultiPoint:
- case GeographyMultiPoint:
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_MULTIPOINT, Constants.NS_GML);
- writeSrsName(writer, value);
-
- if (!((MultiPoint) value).isEmpty()) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POINTMEMBERS, Constants.NS_GML);
- points(writer, ((MultiPoint) value).iterator(), true);
- writer.writeEndElement();
- }
-
- writer.writeEndElement();
- break;
-
- case GeometryLineString:
- case GeographyLineString:
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_LINESTRING, Constants.NS_GML);
- writeSrsName(writer, value);
-
- lineStrings(writer, Collections.singleton((LineString) value).iterator(), false);
-
- writer.writeEndElement();
- break;
-
- case GeometryMultiLineString:
- case GeographyMultiLineString:
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_MULTILINESTRING, Constants.NS_GML);
- writeSrsName(writer, value);
-
- if (!((MultiLineString) value).isEmpty()) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_LINESTRINGMEMBERS, Constants.NS_GML);
- lineStrings(writer, ((MultiLineString) value).iterator(), true);
- writer.writeEndElement();
- }
-
- writer.writeEndElement();
- break;
-
- case GeographyPolygon:
- case GeometryPolygon:
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON, Constants.NS_GML);
- writeSrsName(writer, value);
-
- polygons(writer, Collections.singleton(((Polygon) value)).iterator(), false);
-
- writer.writeEndElement();
- break;
-
- case GeographyMultiPolygon:
- case GeometryMultiPolygon:
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_MULTIPOLYGON, Constants.NS_GML);
- writeSrsName(writer, value);
-
- if (!((MultiPolygon) value).isEmpty()) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_SURFACEMEMBERS, Constants.NS_GML);
- polygons(writer, ((MultiPolygon) value).iterator(), true);
- writer.writeEndElement();
- }
-
- writer.writeEndElement();
- break;
-
- case GeographyCollection:
- case GeometryCollection:
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_GEOCOLLECTION, Constants.NS_GML);
- writeSrsName(writer, value);
-
- if (!((GeospatialCollection) value).isEmpty()) {
- writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_GEOMEMBERS, Constants.NS_GML);
- for (final Iterator<Geospatial> itor = ((GeospatialCollection) value).iterator(); itor.hasNext();) {
- serialize(writer, itor.next());
- }
- writer.writeEndElement();
- }
-
- writer.writeEndElement();
- break;
-
- default:
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomPropertyDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomPropertyDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomPropertyDeserializer.java
deleted file mode 100644
index 736d791..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomPropertyDeserializer.java
+++ /dev/null
@@ -1,214 +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 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.commons.api.domain.ODataPropertyType;
-import org.apache.olingo.client.core.edm.EdmTypeInfo;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-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 EdmTypeInfo typeInfo) throws XMLStreamException {
-
- Value value = null;
-
- boolean foundEndProperty = false;
- while (reader.hasNext() && !foundEndProperty) {
- final XMLEvent event = reader.nextEvent();
-
- if (event.isStartElement() && typeInfo != null && typeInfo.getPrimitiveTypeKind().isGeospatial()) {
- final EdmPrimitiveTypeKind geoType = EdmPrimitiveTypeKind.valueOfFQN(
- version, typeInfo.getFullQualifiedName().toString());
- value = new GeospatialValueImpl(this.geoDeserializer.deserialize(reader, event.asStartElement(), geoType));
- }
-
- if (event.isCharacters() && !event.asCharacters().isWhiteSpace()
- && (typeInfo == null || !typeInfo.getPrimitiveTypeKind().isGeospatial())) {
-
- 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 EdmTypeInfo typeInfo) throws XMLStreamException {
-
- final CollectionValueImpl value = new CollectionValueImpl();
-
- final EdmTypeInfo type = typeInfo == null
- ? null
- : new EdmTypeInfo.Builder().setTypeExpression(typeInfo.getFullQualifiedName().toString()).build();
-
- 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 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;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomPropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomPropertyImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomPropertyImpl.java
deleted file mode 100644
index c2a94fb..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomPropertyImpl.java
+++ /dev/null
@@ -1,25 +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;
-
-public class AtomPropertyImpl extends AbstractPropertyImpl {
-
- private static final long serialVersionUID = 48748492242474814L;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomPropertySerializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomPropertySerializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomPropertySerializer.java
deleted file mode 100644
index b1ef2e6..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomPropertySerializer.java
+++ /dev/null
@@ -1,88 +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 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);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomSerializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomSerializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomSerializer.java
deleted file mode 100644
index 8337a72..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AtomSerializer.java
+++ /dev/null
@@ -1,264 +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 java.io.Writer;
-import java.util.Collections;
-import java.util.List;
-import javax.xml.XMLConstants;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.http.entity.ContentType;
-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.data.Property;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-
-public class AtomSerializer extends AbstractAtomDealer {
-
- private static final XMLOutputFactory FACTORY = XMLOutputFactory.newInstance();
-
- private final AtomPropertySerializer propSerializer;
-
- public AtomSerializer(final ODataServiceVersion version) {
- super(version);
- this.propSerializer = new AtomPropertySerializer(version);
- }
-
- private void startDocument(final XMLStreamWriter writer, final String rootElement) throws XMLStreamException {
- writer.writeStartDocument();
- writer.setDefaultNamespace(Constants.NS_ATOM);
-
- writer.writeStartElement(rootElement);
-
- namespaces(writer);
- }
-
- private void property(final Writer outWriter, final Property property) throws XMLStreamException {
- final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
-
- writer.writeStartDocument();
-
- propSerializer.property(writer, property);
-
- writer.writeEndDocument();
- writer.flush();
- }
-
- private void links(final XMLStreamWriter writer, final List<Link> links) throws XMLStreamException {
- for (Link link : links) {
- writer.writeStartElement(Constants.ATOM_ELEM_LINK);
-
- if (StringUtils.isNotBlank(link.getRel())) {
- writer.writeAttribute(Constants.ATTR_REL, link.getRel());
- }
- if (StringUtils.isNotBlank(link.getTitle())) {
- writer.writeAttribute(Constants.ATTR_TITLE, link.getTitle());
- }
- if (StringUtils.isNotBlank(link.getHref())) {
- writer.writeAttribute(Constants.ATTR_HREF, link.getHref());
- }
- if (StringUtils.isNotBlank(link.getType())) {
- writer.writeAttribute(Constants.ATTR_TYPE, link.getType());
- }
-
- if (link.getInlineEntry() != null || link.getInlineFeed() != null) {
- writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE,
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
-
- if (link.getInlineEntry() != null) {
- writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
- entry(writer, link.getInlineEntry());
- writer.writeEndElement();
- }
- if (link.getInlineFeed() != null) {
- writer.writeStartElement(Constants.ATOM_ELEM_FEED);
- feed(writer, link.getInlineFeed());
- writer.writeEndElement();
- }
-
- writer.writeEndElement();
- }
-
- writer.writeEndElement();
- }
- }
-
- 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();
- }
-
- 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) {
- writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, entry.getBaseURI().toASCIIString());
- }
-
- if (StringUtils.isNotBlank(entry.getId())) {
- 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);
- }
-
- links(writer, entry.getAssociationLinks());
- links(writer, entry.getNavigationLinks());
- links(writer, entry.getMediaEditLinks());
-
- writer.writeStartElement(Constants.ATOM_ELEM_CONTENT);
- if (entry.isMediaEntry()) {
- if (StringUtils.isNotBlank(entry.getMediaContentType())) {
- writer.writeAttribute(Constants.ATTR_TYPE, entry.getMediaContentType());
- }
- if (StringUtils.isNotBlank(entry.getMediaContentSource())) {
- writer.writeAttribute(Constants.ATOM_ATTR_SRC, entry.getMediaContentSource());
- }
- writer.writeEndElement();
-
- writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES);
- properties(writer, entry.getProperties());
- } else {
- 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();
- }
- writer.writeEndElement();
- }
-
- private void entry(final Writer outWriter, final Entry entry) throws XMLStreamException {
- final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
-
- 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) {
- writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, feed.getBaseURI().toASCIIString());
- }
-
- if (feed.getCount() != null) {
- writer.writeStartElement(
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_COUNT);
- writer.writeCharacters(Integer.toString(feed.getCount()));
- writer.writeEndElement();
- }
-
- if (StringUtils.isNotBlank(feed.getId())) {
- 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()) {
- writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
- entry(writer, entry);
- writer.writeEndElement();
- }
-
- 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.writeStartElement(Constants.ELEM_LINKS);
- writer.writeDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
-
- writer.writeStartElement(Constants.ELEM_URI);
- writer.writeCharacters(link.getHref());
- writer.writeEndElement();
-
- writer.writeEndElement();
-
- writer.writeEndDocument();
- writer.flush();
- }
-
- public <T> void write(final Writer writer, final T obj) throws 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);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/CollectionValueImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/CollectionValueImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/CollectionValueImpl.java
deleted file mode 100644
index fa2e23c..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/CollectionValueImpl.java
+++ /dev/null
@@ -1,40 +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 java.util.ArrayList;
-import java.util.List;
-import org.apache.olingo.client.api.data.CollectionValue;
-import org.apache.olingo.client.api.data.Value;
-
-public class CollectionValueImpl extends AbstractValue implements CollectionValue {
-
- private final List<Value> value = new ArrayList<Value>();
-
- @Override
- public boolean isCollection() {
- return true;
- }
-
- @Override
- public List<Value> get() {
- return value;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ComplexValueImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ComplexValueImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ComplexValueImpl.java
deleted file mode 100644
index 9f4f5ab..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ComplexValueImpl.java
+++ /dev/null
@@ -1,40 +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 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;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/GeospatialValueImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/GeospatialValueImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/GeospatialValueImpl.java
deleted file mode 100644
index fdb0f44..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/GeospatialValueImpl.java
+++ /dev/null
@@ -1,42 +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 org.apache.olingo.client.api.data.GeospatialValue;
-import org.apache.olingo.commons.api.edm.geo.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;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONEntryDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONEntryDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONEntryDeserializer.java
deleted file mode 100644
index 2626a95..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONEntryDeserializer.java
+++ /dev/null
@@ -1,244 +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.JsonParseException;
-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 org.apache.olingo.client.api.Constants;
-import org.apache.olingo.client.api.data.Link;
-import org.apache.olingo.commons.api.domain.ODataLinkType;
-import org.apache.olingo.commons.api.domain.ODataOperation;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-
-/**
- * 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 AbstractJsonDeserializer<JSONEntryImpl> {
-
- private String getTitle(final Map.Entry<String, JsonNode> entry) {
- return entry.getKey().substring(0, entry.getKey().indexOf('@'));
- }
-
- private String setInline(final String name, final String suffix, final ObjectNode tree,
- final ObjectCodec codec, final LinkImpl link) throws IOException {
-
- final String entryNamePrefix = name.substring(0, name.indexOf(suffix));
- if (tree.has(entryNamePrefix)) {
- final JsonNode inline = tree.path(entryNamePrefix);
-
- if (inline instanceof ObjectNode) {
- 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()) {
- feed.getEntries().add(entries.next().traverse(codec).readValuesAs(JSONEntryImpl.class).next());
- }
-
- link.setInlineFeed(feed);
- }
- }
- return entryNamePrefix;
- }
-
- @Override
- protected JSONEntryImpl doDeserialize(final JsonParser parser, final DeserializationContext ctxt)
- throws IOException, JsonProcessingException {
-
- final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser);
-
- if (tree.has(Constants.JSON_VALUE) && tree.get(Constants.JSON_VALUE).isArray()) {
- throw new JsonParseException("Expected OData Entity, found EntitySet", parser.getCurrentLocation());
- }
-
- final JSONEntryImpl entry = new JSONEntryImpl();
-
- if (tree.hasNonNull(Constants.JSON_METADATA)) {
- entry.setMetadata(URI.create(tree.get(Constants.JSON_METADATA).textValue()));
- tree.remove(Constants.JSON_METADATA);
- }
-
- if (tree.hasNonNull(Constants.JSON_MEDIA_ETAG)) {
- entry.setMediaETag(tree.get(Constants.JSON_MEDIA_ETAG).textValue());
- tree.remove(Constants.JSON_MEDIA_ETAG);
- }
-
- if (tree.hasNonNull(Constants.JSON_ETAG)) {
- entry.setETag(tree.get(Constants.JSON_ETAG).textValue());
- tree.remove(Constants.JSON_ETAG);
- }
-
- if (tree.hasNonNull(Constants.JSON_TYPE)) {
- entry.setType(tree.get(Constants.JSON_TYPE).textValue());
- tree.remove(Constants.JSON_TYPE);
- }
-
- if (tree.hasNonNull(Constants.JSON_ID)) {
- 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);
- }
-
- if (tree.hasNonNull(Constants.JSON_READ_LINK)) {
- final LinkImpl link = new LinkImpl();
- link.setRel(Constants.SELF_LINK_REL);
- link.setHref(tree.get(Constants.JSON_READ_LINK).textValue());
- entry.setSelfLink(link);
-
- tree.remove(Constants.JSON_READ_LINK);
- }
-
- if (tree.hasNonNull(Constants.JSON_EDIT_LINK)) {
- final LinkImpl link = new LinkImpl();
- link.setRel(Constants.EDIT_LINK_REL);
- link.setHref(tree.get(Constants.JSON_EDIT_LINK).textValue());
- entry.setEditLink(link);
-
- tree.remove(Constants.JSON_EDIT_LINK);
- }
-
- if (tree.hasNonNull(Constants.JSON_MEDIAREAD_LINK)) {
- entry.setMediaContentSource(tree.get(Constants.JSON_MEDIAREAD_LINK).textValue());
- tree.remove(Constants.JSON_MEDIAREAD_LINK);
- }
- if (tree.hasNonNull(Constants.JSON_MEDIAEDIT_LINK)) {
- tree.remove(Constants.JSON_MEDIAEDIT_LINK);
- }
- if (tree.hasNonNull(Constants.JSON_MEDIA_CONTENT_TYPE)) {
- entry.setMediaContentType(tree.get(Constants.JSON_MEDIA_CONTENT_TYPE).textValue());
- tree.remove(Constants.JSON_MEDIA_CONTENT_TYPE);
- }
-
- final Set<String> toRemove = new HashSet<String>();
- 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));
-
- if (field.getValue().isValueNode()) {
- link.setHref(field.getValue().textValue());
- link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
- }
- // 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(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));
- } 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.setHref(field.getValue().textValue());
- link.setType(ODataLinkType.ASSOCIATION.toString());
- entry.getAssociationLinks().add(link);
-
- toRemove.add(field.getKey());
- } 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.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());
- } else if (field.getKey().charAt(0) == '#') {
- final ODataOperation operation = new ODataOperation();
- operation.setMetadataAnchor(field.getKey());
-
- final ObjectNode opNode = (ObjectNode) tree.get(field.getKey());
- operation.setTitle(opNode.get(Constants.ATTR_TITLE).asText());
- operation.setTarget(URI.create(opNode.get(Constants.ATTR_TARGET).asText()));
-
- entry.getOperations().add(operation);
-
- toRemove.add(field.getKey());
- }
- }
- tree.remove(toRemove);
-
- String type = null;
- for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.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());
- entry.getProperties().add(property);
- }
- }
-
- return entry;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/fac84b3e/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONEntryImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONEntryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONEntryImpl.java
deleted file mode 100644
index cafe289..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONEntryImpl.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.client.core.data;
-
-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;
-
-/**
- * A single entry, represented via JSON.
- */
-@JsonSerialize(using = JSONEntrySerializer.class)
-@JsonDeserialize(using = JSONEntryDeserializer.class)
-public class JSONEntryImpl extends AbstractEntry {
-
- private static final long serialVersionUID = -5275365545400797758L;
-
- private URI metadata;
-
- private String mediaETag;
-
- public void setId(final String id) throws ParseException {
- this.setCommonProperty("id", id);
- }
-
- @Override
- public URI getBaseURI() {
- URI baseURI = null;
- if (metadata != null) {
- final String metadataURI = getMetadata().toASCIIString();
- baseURI = URI.create(metadataURI.substring(0, metadataURI.indexOf(SegmentType.METADATA.getValue())));
- }
-
- return baseURI;
- }
-
- /**
- * Gets the metadata URI.
- *
- * @return the metadata URI
- */
- public URI getMetadata() {
- return metadata;
- }
-
- /**
- * Sets the metadata URI.
- *
- * @param metadata metadata URI.
- */
- public void setMetadata(final URI metadata) {
- this.metadata = metadata;
- }
-
- /**
- * The odata.mediaEtag annotation MAY be included; its value MUST be the ETag of the binary stream represented by this
- * media entity or named stream property.
- *
- * @return odata.mediaEtag annotation value.
- */
- public String getMediaETag() {
- return mediaETag;
- }
-
- /**
- * The odata.mediaEtag annotation MAY be included; its value MUST be the ETag of the binary stream represented by this
- * media entity or named stream property.
- *
- * @param eTag odata.mediaEtag annotation value.
- */
- public void setMediaETag(final String eTag) {
- this.mediaETag = eTag;
- }
-}