You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2016/03/04 21:36:50 UTC
[07/39] olingo-odata4 git commit: [OLINGO-832] Introduced
AbstractEntityCollection
[OLINGO-832] Introduced AbstractEntityCollection
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/c6d45d9f
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/c6d45d9f
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/c6d45d9f
Branch: refs/heads/OLINGO-856_ODataHandlerInAPI
Commit: c6d45d9f51e47c97f083076bfe37620630a8d03d
Parents: 44e1b02
Author: Michael Bolz <mi...@sap.com>
Authored: Tue Jan 26 14:41:49 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Tue Jan 26 14:41:49 2016 +0100
----------------------------------------------------------------------
.../api/data/AbstractEntityCollection.java | 33 ++++++++++++++++++++
.../commons/api/data/EntityCollection.java | 5 ++-
.../olingo/commons/api/data/EntityIterator.java | 17 +++++++++-
.../apache/olingo/commons/api/data/Link.java | 6 ++--
.../server/api/serializer/ODataSerializer.java | 6 ++--
.../serializer/json/ODataJsonSerializer.java | 14 ++++-----
.../core/serializer/xml/ODataXmlSerializer.java | 15 ++++-----
7 files changed, 74 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c6d45d9f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractEntityCollection.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractEntityCollection.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractEntityCollection.java
new file mode 100644
index 0000000..9b4f9ff
--- /dev/null
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractEntityCollection.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.commons.api.data;
+
+import java.net.URI;
+import java.util.Iterator;
+
+public abstract class AbstractEntityCollection extends AbstractODataObject implements Iterable<Entity> {
+ public abstract Integer getCount();
+
+ public abstract URI getNext();
+
+ public abstract URI getDeltaLink();
+//
+// @Override
+// Iterator<Entity> iterator();
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c6d45d9f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
index d3ec8e8..86d8747 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
@@ -26,7 +26,7 @@ import java.util.List;
/**
* Data representation for a collection of single entities.
*/
-public class EntityCollection extends AbstractODataObject implements Iterable<Entity> {
+public class EntityCollection extends AbstractEntityCollection {
private final List<Entity> entities = new ArrayList<Entity>();
private Integer count;
@@ -47,6 +47,7 @@ public class EntityCollection extends AbstractODataObject implements Iterable<En
*
* @return number of entries into the entity set.
*/
+ @Override
public Integer getCount() {
return count;
}
@@ -74,6 +75,7 @@ public class EntityCollection extends AbstractODataObject implements Iterable<En
*
* @return next link if exists; null otherwise.
*/
+ @Override
public URI getNext() {
return next;
}
@@ -83,6 +85,7 @@ public class EntityCollection extends AbstractODataObject implements Iterable<En
*
* @return delta link if exists; null otherwise.
*/
+ @Override
public URI getDeltaLink() {
return deltaLink;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c6d45d9f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
index 18f1019..697676e 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
@@ -18,14 +18,16 @@
*/
package org.apache.olingo.commons.api.data;
+import org.apache.olingo.commons.api.ex.ODataRuntimeException;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
+import java.net.URI;
import java.util.Iterator;
/**
* Data representation for a collection of single entities.
*/
-public abstract class EntityIterator extends EntityCollection implements Iterator<Entity> {
+public abstract class EntityIterator extends AbstractEntityCollection implements Iterator<Entity> {
public abstract boolean hasNext();
public abstract Entity next();
@@ -40,4 +42,17 @@ public abstract class EntityIterator extends EntityCollection implements Iterato
public Iterator<Entity> iterator() {
return this;
}
+
+ public Integer getCount() {
+ throw new ODataRuntimeException("getCount() not supported for " + getClass().getSimpleName());
+ }
+
+ public URI getNext() {
+ throw new ODataRuntimeException("getNext() not supported for " + getClass().getSimpleName());
+
+ }
+
+ public URI getDeltaLink() {
+ throw new ODataRuntimeException("getDeltaLink() not supported for " + getClass().getSimpleName());
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c6d45d9f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
index 0bf8237..996e378 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
@@ -32,7 +32,7 @@ public class Link extends Annotatable {
private String type;
private String mediaETag;
private Entity entity;
- private EntityCollection entitySet;
+ private AbstractEntityCollection entitySet;
private String bindingLink;
private List<String> bindingLinks = new ArrayList<String>();
@@ -149,7 +149,7 @@ public class Link extends Annotatable {
*
* @return in-line entity set.
*/
- public EntityCollection getInlineEntitySet() {
+ public AbstractEntityCollection getInlineEntitySet() {
return entitySet;
}
@@ -158,7 +158,7 @@ public class Link extends Annotatable {
*
* @param entitySet entity set.
*/
- public void setInlineEntitySet(final EntityCollection entitySet) {
+ public void setInlineEntitySet(final AbstractEntityCollection entitySet) {
this.entitySet = entitySet;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c6d45d9f/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
index 5dd5187..3deb396 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
@@ -19,7 +19,7 @@
package org.apache.olingo.server.api.serializer;
import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntityCollection;
+import org.apache.olingo.commons.api.data.AbstractEntityCollection;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.edm.EdmComplexType;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
@@ -61,7 +61,7 @@ public interface ODataSerializer {
* @param options options for the serializer
*/
SerializerResult entityCollection(ServiceMetadata metadata, EdmEntityType entityType,
- EntityCollection entitySet, EntityCollectionSerializerOptions options) throws SerializerException;
+ AbstractEntityCollection entitySet, EntityCollectionSerializerOptions options) throws SerializerException;
/**
* Writes entity data into an InputStream.
@@ -131,5 +131,5 @@ public interface ODataSerializer {
* @param ReferenceCollectionSerializerOptions {@link ReferenceCollectionSerializerOptions}
*/
SerializerResult referenceCollection(ServiceMetadata metadata, EdmEntitySet edmEntitySet,
- EntityCollection entityCollection, ReferenceCollectionSerializerOptions options) throws SerializerException;
+ AbstractEntityCollection entityCollection, ReferenceCollectionSerializerOptions options) throws SerializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c6d45d9f/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index 7f84319..c381760 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -29,7 +29,7 @@ import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntityCollection;
+import org.apache.olingo.commons.api.data.AbstractEntityCollection;
import org.apache.olingo.commons.api.data.Link;
import org.apache.olingo.commons.api.data.Linked;
import org.apache.olingo.commons.api.data.Property;
@@ -136,7 +136,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
@Override
public SerializerResult entityCollection(final ServiceMetadata metadata,
- final EdmEntityType entityType, final EntityCollection entitySet,
+ final EdmEntityType entityType, final AbstractEntityCollection entitySet,
final EntityCollectionSerializerOptions options) throws SerializerException {
OutputStream outputStream = null;
SerializerException cachedException = null;
@@ -213,7 +213,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
}
protected void writeEntitySet(final ServiceMetadata metadata, final EdmEntityType entityType,
- final EntityCollection entitySet, final ExpandOption expand, final SelectOption select,
+ final AbstractEntityCollection entitySet, final ExpandOption expand, final SelectOption select,
final boolean onlyReference, final JsonGenerator json) throws IOException,
SerializerException {
json.writeStartArray();
@@ -724,7 +724,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
@Override
public SerializerResult referenceCollection(final ServiceMetadata metadata, final EdmEntitySet edmEntitySet,
- final EntityCollection entityCollection, final ReferenceCollectionSerializerOptions options)
+ final AbstractEntityCollection entityCollection, final ReferenceCollectionSerializerOptions options)
throws SerializerException {
OutputStream outputStream = null;
SerializerException cachedException = null;
@@ -743,7 +743,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
}
json.writeArrayFieldStart(Constants.VALUE);
- for (final Entity entity : entityCollection.getEntities()) {
+ for (final Entity entity : entityCollection) {
json.writeStartObject();
json.writeStringField(Constants.JSON_ID, uriHelper.buildCanonicalURL(edmEntitySet, entity));
json.writeEndObject();
@@ -783,7 +783,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
}
}
- void writeCount(final EntityCollection entityCollection, final JsonGenerator json) throws IOException {
+ void writeCount(final AbstractEntityCollection entityCollection, final JsonGenerator json) throws IOException {
if (entityCollection.getCount() != null) {
if (isIEEE754Compatible) {
json.writeStringField(Constants.JSON_COUNT, entityCollection.getCount().toString());
@@ -793,7 +793,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
}
}
- void writeNextLink(final EntityCollection entitySet, final JsonGenerator json) throws IOException {
+ void writeNextLink(final AbstractEntityCollection entitySet, final JsonGenerator json) throws IOException {
if (entitySet.getNext() != null) {
json.writeStringField(Constants.JSON_NEXT_LINK, entitySet.getNext().toASCIIString());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c6d45d9f/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
index 7e56976..70d797f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
@@ -35,6 +35,7 @@ import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntityCollection;
+import org.apache.olingo.commons.api.data.AbstractEntityCollection;
import org.apache.olingo.commons.api.data.Link;
import org.apache.olingo.commons.api.data.Linked;
import org.apache.olingo.commons.api.data.Property;
@@ -209,7 +210,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
@Override
public SerializerResult entityCollection(final ServiceMetadata metadata,
- final EdmEntityType entityType, final EntityCollection entitySet,
+ final EdmEntityType entityType, final AbstractEntityCollection entitySet,
final EntityCollectionSerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
@@ -335,7 +336,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
}
protected void writeEntitySet(final ServiceMetadata metadata, final EdmEntityType entityType,
- final EntityCollection entitySet, final ExpandOption expand, final SelectOption select,
+ final AbstractEntityCollection entitySet, final ExpandOption expand, final SelectOption select,
final XMLStreamWriter writer) throws XMLStreamException, SerializerException {
for (final Entity entity : entitySet) {
writeEntity(metadata, entityType, entity, null, expand, select, writer, false);
@@ -555,7 +556,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
link.setRel(Constants.NS_NAVIGATION_LINK_REL + navigationPropertyName);
link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE);
link.setTitle(navigationPropertyName);
- EntityCollection target = new EntityCollection();
+ AbstractEntityCollection target = new EntityCollection();
link.setInlineEntitySet(target);
if (linked.getId() != null) {
link.setHref(linked.getId().toASCIIString() + "/" + navigationPropertyName);
@@ -1035,12 +1036,12 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
@Override
public SerializerResult referenceCollection(final ServiceMetadata metadata, final EdmEntitySet edmEntitySet,
- final EntityCollection entityCollection, final ReferenceCollectionSerializerOptions options)
+ final AbstractEntityCollection entityCollection, final ReferenceCollectionSerializerOptions options)
throws SerializerException {
return entityReferenceCollection(entityCollection, options);
}
- protected SerializerResult entityReferenceCollection(final EntityCollection entitySet,
+ protected SerializerResult entityReferenceCollection(final AbstractEntityCollection entitySet,
final ReferenceCollectionSerializerOptions options) throws SerializerException {
OutputStream outputStream = null;
SerializerException cachedException = null;
@@ -1086,14 +1087,14 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
}
}
- private void writeCount(final EntityCollection entitySet, final XMLStreamWriter writer)
+ private void writeCount(final AbstractEntityCollection entitySet, final XMLStreamWriter writer)
throws XMLStreamException {
writer.writeStartElement(METADATA, Constants.ATOM_ELEM_COUNT, NS_METADATA);
writer.writeCharacters(String.valueOf(entitySet.getCount()));
writer.writeEndElement();
}
- private void writeNextLink(final EntityCollection entitySet, final XMLStreamWriter writer)
+ private void writeNextLink(final AbstractEntityCollection entitySet, final XMLStreamWriter writer)
throws XMLStreamException {
writer.writeStartElement(ATOM, Constants.ATOM_ELEM_LINK, NS_ATOM);
writer.writeAttribute(Constants.ATTR_REL, Constants.NEXT_LINK_REL);