You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2015/02/27 15:25:13 UTC
[2/2] olingo-odata4 git commit: [OLINGO-575] Start removing
unnecessary common classes in client
[OLINGO-575] Start removing unnecessary common classes in client
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/68b14ffe
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/68b14ffe
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/68b14ffe
Branch: refs/heads/master
Commit: 68b14ffe4eeeba786655c384f3a82bccb5560915
Parents: d088866
Author: Christian Amend <ch...@apache.org>
Authored: Fri Feb 27 15:24:29 2015 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Fri Feb 27 15:24:29 2015 +0100
----------------------------------------------------------------------
.../olingo/client/api/CommonODataClient.java | 8 +-
.../api/serialization/CommonODataBinder.java | 107 ----
.../api/serialization/CommonODataReader.java | 122 ----
.../client/api/serialization/ODataBinder.java | 76 ++-
.../client/api/serialization/ODataReader.java | 104 ++-
.../retrieve/XMLMetadataRequestImpl.java | 4 +-
.../core/serialization/AbstractODataBinder.java | 637 ------------------
.../core/serialization/AbstractODataReader.java | 157 -----
.../core/serialization/ODataBinderImpl.java | 642 +++++++++++++++++--
.../core/serialization/ODataReaderImpl.java | 127 +++-
10 files changed, 871 insertions(+), 1113 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/68b14ffe/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java
index cdfcff6..e9fb6a8 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java
@@ -26,8 +26,8 @@ import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType;
import org.apache.olingo.client.api.communication.request.invoke.InvokeRequestFactory;
import org.apache.olingo.client.api.communication.request.retrieve.CommonRetrieveRequestFactory;
import org.apache.olingo.client.api.serialization.ClientODataDeserializer;
-import org.apache.olingo.client.api.serialization.CommonODataBinder;
-import org.apache.olingo.client.api.serialization.CommonODataReader;
+import org.apache.olingo.client.api.serialization.ODataBinder;
+import org.apache.olingo.client.api.serialization.ODataReader;
import org.apache.olingo.client.api.serialization.ODataWriter;
import org.apache.olingo.client.api.uri.CommonFilterFactory;
import org.apache.olingo.client.api.uri.CommonURIBuilder;
@@ -59,11 +59,11 @@ public interface CommonODataClient<UT extends CommonUpdateType> {
ClientODataDeserializer getDeserializer(ODataFormat format);
- CommonODataReader getReader();
+ ODataReader getReader();
ODataWriter getWriter();
- CommonODataBinder getBinder();
+ ODataBinder getBinder();
ODataObjectFactory getObjectFactory();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/68b14ffe/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/CommonODataBinder.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/CommonODataBinder.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/CommonODataBinder.java
deleted file mode 100644
index d0c7814..0000000
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/CommonODataBinder.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.client.api.serialization;
-
-import org.apache.olingo.client.api.data.ServiceDocument;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.Link;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.domain.ODataEntity;
-import org.apache.olingo.commons.api.domain.ODataEntitySet;
-import org.apache.olingo.commons.api.domain.ODataProperty;
-import org.apache.olingo.commons.api.domain.ODataLink;
-import org.apache.olingo.commons.api.domain.ODataServiceDocument;
-
-public interface CommonODataBinder {
-
- /**
- * Gets a <tt>EntitySet</tt> from the given OData entity set.
- *
- * @param entitySet OData entity set.
- * @return {@link EntitySet} object.
- */
- EntitySet getEntitySet(ODataEntitySet entitySet);
-
- /**
- * Gets an <tt>Entity</tt> from the given OData entity.
- *
- * @param entity OData entity.
- * @return {@link Entity} object.
- */
- Entity getEntity(ODataEntity entity);
-
- /**
- * Gets a <tt>Link</tt> from the given OData link.
- *
- * @param link OData link.
- * @return <tt>Link</tt> object.
- */
- Link getLink(ODataLink link);
-
- /**
- * Gets a <tt>Property</tt> from the given OData property.
- *
- * @param property OData property.
- * @return <tt>Property</tt> object.
- */
- Property getProperty(ODataProperty property);
-
- /**
- * Adds the given property to the given entity.
- *
- * @param entity OData entity.
- * @param property OData property.
- * @return whether add was successful or not.
- */
- boolean add(ODataEntity entity, ODataProperty property);
-
- /**
- * Gets <tt>ODataServiceDocument</tt> from the given service document resource.
- *
- * @param resource service document resource.
- * @return <tt>ODataServiceDocument</tt> object.
- */
- ODataServiceDocument getODataServiceDocument(ServiceDocument resource);
-
- /**
- * Gets <tt>ODataEntitySet</tt> from the given entity set resource.
- *
- * @param resource entity set resource.
- * @return {@link org.apache.olingo.commons.api.domain.ODataEntitySet} object.
- */
- ODataEntitySet getODataEntitySet(ResWrap<EntitySet> resource);
-
- /**
- * Gets <tt>ODataEntity</tt> from the given entity resource.
- *
- * @param resource entity resource.
- * @return {@link org.apache.olingo.commons.api.domain.ODataEntity} object.
- */
- ODataEntity getODataEntity(ResWrap<Entity> resource);
-
- /**
- * Gets an <tt>ODataProperty</tt> from the given property resource.
- *
- * @param resource property resource.
- * @return {@link org.apache.olingo.commons.api.domain.ODataProperty} object.
- */
- ODataProperty getODataProperty(ResWrap<Property> resource);
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/68b14ffe/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/CommonODataReader.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/CommonODataReader.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/CommonODataReader.java
deleted file mode 100644
index 7ad713d..0000000
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/CommonODataReader.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.client.api.serialization;
-
-import java.io.InputStream;
-import java.util.Map;
-
-import org.apache.olingo.client.api.edm.xml.Schema;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.domain.ODataEntity;
-import org.apache.olingo.commons.api.domain.ODataEntitySet;
-import org.apache.olingo.commons.api.domain.ODataProperty;
-import org.apache.olingo.commons.api.domain.ODataError;
-import org.apache.olingo.commons.api.domain.ODataServiceDocument;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
-
-/**
- * OData reader.
- * <br/>
- * Use this class to de-serialize an OData response body.
- * <br/>
- * This class provides method helpers to de-serialize an entire entity set, a set of entities or a single entity.
- */
-public interface CommonODataReader {
-
- /**
- * Parses a stream into metadata representation.
- *
- * @param input stream to de-serialize.
- * @return metadata representation.
- */
- Edm readMetadata(InputStream input);
-
- /**
- * Parses a stream into metadata representation, including referenced metadata documents.
- *
- * @param xmlSchemas XML representation of the requested metadata document + any other referenced (via
- * <tt><edmx:Reference/></tt>) metadata document
- * @return metadata representation.
- */
- Edm readMetadata(Map<String, Schema> xmlSchemas);
-
- /**
- * Parses an OData service document.
- *
- * @param input stream to de-serialize.
- * @param format de-serialize as XML or JSON
- * @return List of URIs.
- * @throws ODataDeserializerException
- */
- ODataServiceDocument readServiceDocument(InputStream input, ODataFormat format) throws ODataDeserializerException;
-
- /**
- * De-Serializes a stream into an OData entity set.
- *
- * @param input stream to de-serialize.
- * @param format de-serialize format
- * @return de-serialized entity set.
- * @throws ODataDeserializerException
- */
- ODataEntitySet readEntitySet(InputStream input, ODataFormat format) throws ODataDeserializerException;
-
- /**
- * Parses a stream taking care to de-serializes the first OData entity found.
- *
- * @param input stream to de-serialize.
- * @param format de-serialize format
- * @return entity de-serialized.
- * @throws ODataDeserializerException
- */
- ODataEntity readEntity(InputStream input, ODataFormat format) throws ODataDeserializerException;
-
- /**
- * Parses a stream taking care to de-serialize the first OData entity property found.
- *
- * @param input stream to de-serialize.
- * @param format de-serialize as XML or JSON
- * @return OData entity property de-serialized.
- * @throws ODataDeserializerException
- */
- ODataProperty readProperty(InputStream input, ODataFormat format) throws ODataDeserializerException;
-
- /**
- * Parses a stream into an OData error.
- *
- * @param inputStream stream to de-serialize.
- * @param format format
- * @return OData error.
- * @throws ODataDeserializerException
- */
- ODataError readError(InputStream inputStream, ODataFormat format) throws ODataDeserializerException;
-
- /**
- * Parses a stream into the object type specified by the given reference.
- *
- * @param <T> expected object type.
- * @param src input stream.
- * @param format format
- * @param reference reference.
- * @return read object.
- * @throws ODataDeserializerException
- */
- <T> ResWrap<T> read(InputStream src, String format, Class<T> reference) throws ODataDeserializerException;
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/68b14ffe/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataBinder.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataBinder.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataBinder.java
index d7b3685..289c0cb 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataBinder.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataBinder.java
@@ -18,25 +18,93 @@
*/
package org.apache.olingo.client.api.serialization;
+import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.commons.api.data.Delta;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Link;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.ODataDelta;
import org.apache.olingo.commons.api.domain.ODataEntity;
import org.apache.olingo.commons.api.domain.ODataEntitySet;
+import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.domain.ODataProperty;
+import org.apache.olingo.commons.api.domain.ODataServiceDocument;
-public interface ODataBinder extends CommonODataBinder {
+public interface ODataBinder {
- @Override
+ /**
+ * Gets a <tt>EntitySet</tt> from the given OData entity set.
+ *
+ * @param entitySet OData entity set.
+ * @return {@link EntitySet} object.
+ */
+ EntitySet getEntitySet(ODataEntitySet entitySet);
+
+ /**
+ * Gets an <tt>Entity</tt> from the given OData entity.
+ *
+ * @param entity OData entity.
+ * @return {@link Entity} object.
+ */
+ Entity getEntity(ODataEntity entity);
+
+ /**
+ * Gets a <tt>Link</tt> from the given OData link.
+ *
+ * @param link OData link.
+ * @return <tt>Link</tt> object.
+ */
+ Link getLink(ODataLink link);
+
+ /**
+ * Gets a <tt>Property</tt> from the given OData property.
+ *
+ * @param property OData property.
+ * @return <tt>Property</tt> object.
+ */
+ Property getProperty(ODataProperty property);
+
+ /**
+ * Adds the given property to the given entity.
+ *
+ * @param entity OData entity.
+ * @param property OData property.
+ * @return whether add was successful or not.
+ */
+ boolean add(ODataEntity entity, ODataProperty property);
+
+ /**
+ * Gets <tt>ODataServiceDocument</tt> from the given service document resource.
+ *
+ * @param resource service document resource.
+ * @return <tt>ODataServiceDocument</tt> object.
+ */
+ ODataServiceDocument getODataServiceDocument(ServiceDocument resource);
+
+ /**
+ * Gets <tt>ODataEntitySet</tt> from the given entity set resource.
+ *
+ * @param resource entity set resource.
+ * @return {@link org.apache.olingo.commons.api.domain.ODataEntitySet} object.
+ */
ODataEntitySet getODataEntitySet(ResWrap<EntitySet> resource);
- @Override
+ /**
+ * Gets <tt>ODataEntity</tt> from the given entity resource.
+ *
+ * @param resource entity resource.
+ * @return {@link org.apache.olingo.commons.api.domain.ODataEntity} object.
+ */
ODataEntity getODataEntity(ResWrap<Entity> resource);
- @Override
+ /**
+ * Gets an <tt>ODataProperty</tt> from the given property resource.
+ *
+ * @param resource property resource.
+ * @return {@link org.apache.olingo.commons.api.domain.ODataProperty} object.
+ */
ODataProperty getODataProperty(ResWrap<Property> resource);
ODataDelta getODataDelta(ResWrap<Delta> resource);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/68b14ffe/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataReader.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataReader.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataReader.java
index 2ba39a8..611666a 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataReader.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataReader.java
@@ -1,39 +1,121 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.client.api.serialization;
import java.io.InputStream;
+import java.util.Map;
+import org.apache.olingo.client.api.edm.xml.Schema;
+import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.ODataEntity;
import org.apache.olingo.commons.api.domain.ODataEntitySet;
+import org.apache.olingo.commons.api.domain.ODataError;
import org.apache.olingo.commons.api.domain.ODataProperty;
+import org.apache.olingo.commons.api.domain.ODataServiceDocument;
+import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
-public interface ODataReader extends CommonODataReader {
+/**
+ * OData reader.
+ * <br/>
+ * Use this class to de-serialize an OData response body.
+ * <br/>
+ * This class provides method helpers to de-serialize an entire entity set, a set of entities or a single entity.
+ */
+public interface ODataReader {
+ /**
+ * Parses a stream into metadata representation.
+ *
+ * @param input stream to de-serialize.
+ * @return metadata representation.
+ */
+ Edm readMetadata(InputStream input);
+
+ /**
+ * Parses a stream into metadata representation, including referenced metadata documents.
+ *
+ * @param xmlSchemas XML representation of the requested metadata document + any other referenced (via
+ * <tt><edmx:Reference/></tt>) metadata document
+ * @return metadata representation.
+ */
+ Edm readMetadata(Map<String, Schema> xmlSchemas);
+
+ /**
+ * Parses an OData service document.
+ *
+ * @param input stream to de-serialize.
+ * @param format de-serialize as XML or JSON
+ * @return List of URIs.
+ * @throws ODataDeserializerException
+ */
+ ODataServiceDocument readServiceDocument(InputStream input, ODataFormat format) throws ODataDeserializerException;
- @Override
+ /**
+ * De-Serializes a stream into an OData entity set.
+ *
+ * @param input stream to de-serialize.
+ * @param format de-serialize format
+ * @return de-serialized entity set.
+ * @throws ODataDeserializerException
+ */
ODataEntitySet readEntitySet(InputStream input, ODataFormat format) throws ODataDeserializerException;
- @Override
+ /**
+ * Parses a stream taking care to de-serializes the first OData entity found.
+ *
+ * @param input stream to de-serialize.
+ * @param format de-serialize format
+ * @return entity de-serialized.
+ * @throws ODataDeserializerException
+ */
ODataEntity readEntity(InputStream input, ODataFormat format) throws ODataDeserializerException;
- @Override
+ /**
+ * Parses a stream taking care to de-serialize the first OData entity property found.
+ *
+ * @param input stream to de-serialize.
+ * @param format de-serialize as XML or JSON
+ * @return OData entity property de-serialized.
+ * @throws ODataDeserializerException
+ */
ODataProperty readProperty(InputStream input, ODataFormat format) throws ODataDeserializerException;
+
+ /**
+ * Parses a stream into an OData error.
+ *
+ * @param inputStream stream to de-serialize.
+ * @param format format
+ * @return OData error.
+ * @throws ODataDeserializerException
+ */
+ ODataError readError(InputStream inputStream, ODataFormat format) throws ODataDeserializerException;
+
+ /**
+ * Parses a stream into the object type specified by the given reference.
+ *
+ * @param <T> expected object type.
+ * @param src input stream.
+ * @param format format
+ * @param reference reference.
+ * @return read object.
+ * @throws ODataDeserializerException
+ */
+ <T> ResWrap<T> read(InputStream src, String format, Class<T> reference) throws ODataDeserializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/68b14ffe/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/XMLMetadataRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/XMLMetadataRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/XMLMetadataRequestImpl.java
index 3b326e5..ff2b0ea 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/XMLMetadataRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/XMLMetadataRequestImpl.java
@@ -40,7 +40,7 @@ import org.apache.olingo.client.core.edm.xml.SchemaImpl;
import org.apache.olingo.commons.api.format.ODataFormat;
public class XMLMetadataRequestImpl
- extends AbstractMetadataRequestImpl<org.apache.olingo.client.api.edm.xml.XMLMetadata>
+ extends AbstractMetadataRequestImpl<XMLMetadata>
implements XMLMetadataRequest {
XMLMetadataRequestImpl(final ODataClient odataClient, final URI uri) {
@@ -48,7 +48,7 @@ public class XMLMetadataRequestImpl
}
@Override
- public ODataRetrieveResponse<org.apache.olingo.client.api.edm.xml.XMLMetadata> execute() {
+ public ODataRetrieveResponse<XMLMetadata> execute() {
final SingleXMLMetadatRequestImpl rootReq = new SingleXMLMetadatRequestImpl((ODataClient) odataClient, uri, null);
final ODataRetrieveResponse<XMLMetadata> rootRes = rootReq.execute();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/68b14ffe/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataBinder.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataBinder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataBinder.java
deleted file mode 100644
index cc4594d..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataBinder.java
+++ /dev/null
@@ -1,637 +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.serialization;
-
-import java.io.StringWriter;
-import java.net.URI;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.client.api.CommonODataClient;
-import org.apache.olingo.client.api.EdmEnabledODataClient;
-import org.apache.olingo.client.api.data.ServiceDocument;
-import org.apache.olingo.client.api.data.ServiceDocumentItem;
-import org.apache.olingo.client.api.serialization.CommonODataBinder;
-import org.apache.olingo.client.core.uri.URIUtils;
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.ContextURL;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.Link;
-import org.apache.olingo.commons.api.data.Linked;
-import org.apache.olingo.commons.api.data.LinkedComplexValue;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.data.Valuable;
-import org.apache.olingo.commons.api.domain.ODataCollectionValue;
-import org.apache.olingo.commons.api.domain.ODataComplexValue;
-import org.apache.olingo.commons.api.domain.ODataEntity;
-import org.apache.olingo.commons.api.domain.ODataEntitySet;
-import org.apache.olingo.commons.api.domain.ODataInlineEntity;
-import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
-import org.apache.olingo.commons.api.domain.ODataLink;
-import org.apache.olingo.commons.api.domain.ODataLinkType;
-import org.apache.olingo.commons.api.domain.ODataLinked;
-import org.apache.olingo.commons.api.domain.ODataOperation;
-import org.apache.olingo.commons.api.domain.ODataProperty;
-import org.apache.olingo.commons.api.domain.ODataServiceDocument;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmBindingTarget;
-import org.apache.olingo.commons.api.edm.EdmComplexType;
-import org.apache.olingo.commons.api.edm.EdmElement;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.EdmProperty;
-import org.apache.olingo.commons.api.edm.EdmSchema;
-import org.apache.olingo.commons.api.edm.EdmStructuredType;
-import org.apache.olingo.commons.api.edm.EdmType;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.commons.api.serialization.ODataSerializerException;
-import org.apache.olingo.commons.core.data.EntityImpl;
-import org.apache.olingo.commons.core.data.EntitySetImpl;
-import org.apache.olingo.commons.core.data.LinkImpl;
-import org.apache.olingo.commons.core.data.PropertyImpl;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
-import org.apache.olingo.commons.core.serialization.ContextURLParser;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class AbstractODataBinder implements CommonODataBinder {
-
- /**
- * Logger.
- */
- protected static final Logger LOG = LoggerFactory.getLogger(AbstractODataBinder.class);
-
- protected final CommonODataClient<?> client;
-
- protected AbstractODataBinder(final CommonODataClient<?> client) {
- this.client = client;
- }
-
- @Override
- public ODataServiceDocument getODataServiceDocument(final ServiceDocument resource) {
- final ODataServiceDocument serviceDocument = new ODataServiceDocument();
-
- for (ServiceDocumentItem entitySet : resource.getEntitySets()) {
- serviceDocument.getEntitySets().
- put(entitySet.getName(), URIUtils.getURI(resource.getBaseURI(), entitySet.getUrl()));
- }
-
- return serviceDocument;
- }
-
- @Override
- public EntitySet getEntitySet(final ODataEntitySet odataEntitySet) {
- final EntitySet entitySet = new EntitySetImpl();
-
- entitySet.setCount(odataEntitySet.getCount());
-
- final URI next = odataEntitySet.getNext();
- if (next != null) {
- entitySet.setNext(next);
- }
-
- for (ODataEntity entity : odataEntitySet.getEntities()) {
- entitySet.getEntities().add(getEntity(entity));
- }
-
- return entitySet;
- }
-
- protected void links(final ODataLinked odataLinked, final Linked linked) {
- // -------------------------------------------------------------
- // Append navigation links (handling inline entity / entity set as well)
- // -------------------------------------------------------------
- // handle navigation links
- for (ODataLink link : odataLinked.getNavigationLinks()) {
- // append link
- LOG.debug("Append navigation link\n{}", link);
- linked.getNavigationLinks().add(getLink(link));
- }
- // -------------------------------------------------------------
-
- // -------------------------------------------------------------
- // Append association links
- // -------------------------------------------------------------
- for (ODataLink link : odataLinked.getAssociationLinks()) {
- LOG.debug("Append association link\n{}", link);
- linked.getAssociationLinks().add(getLink(link));
- }
- // -------------------------------------------------------------
- }
-
- @Override
- public Entity getEntity(final ODataEntity odataEntity) {
- final Entity entity = new EntityImpl();
-
- entity.setType(odataEntity.getTypeName() == null ? null : odataEntity.getTypeName().toString());
-
- // -------------------------------------------------------------
- // Add edit and self link
- // -------------------------------------------------------------
- final URI odataEditLink = odataEntity.getEditLink();
- if (odataEditLink != null) {
- final LinkImpl editLink = new LinkImpl();
- editLink.setTitle(entity.getType());
- editLink.setHref(odataEditLink.toASCIIString());
- editLink.setRel(Constants.EDIT_LINK_REL);
- entity.setEditLink(editLink);
- }
-
- if (odataEntity.isReadOnly()) {
- final LinkImpl selfLink = new LinkImpl();
- selfLink.setTitle(entity.getType());
- selfLink.setHref(odataEntity.getLink().toASCIIString());
- selfLink.setRel(Constants.SELF_LINK_REL);
- entity.setSelfLink(selfLink);
- }
- // -------------------------------------------------------------
-
- links(odataEntity, entity);
-
- // -------------------------------------------------------------
- // Append edit-media links
- // -------------------------------------------------------------
- for (ODataLink link : odataEntity.getMediaEditLinks()) {
- LOG.debug("Append edit-media link\n{}", link);
- entity.getMediaEditLinks().add(getLink(link));
- }
- // -------------------------------------------------------------
-
- if (odataEntity.isMediaEntity()) {
- entity.setMediaContentSource(odataEntity.getMediaContentSource());
- entity.setMediaContentType(odataEntity.getMediaContentType());
- entity.setMediaETag(odataEntity.getMediaETag());
- }
-
- for (ODataProperty property : odataEntity.getProperties()) {
- entity.getProperties().add(getProperty(property));
- }
-
- return entity;
- }
-
- @Override
- public Link getLink(final ODataLink link) {
- final Link linkResource = new LinkImpl();
- linkResource.setRel(link.getRel());
- linkResource.setTitle(link.getName());
- linkResource.setHref(link.getLink() == null ? null : link.getLink().toASCIIString());
- linkResource.setType(link.getType().toString());
- linkResource.setMediaETag(link.getMediaETag());
-
- if (link instanceof ODataInlineEntity) {
- // append inline entity
- final ODataEntity inlineEntity = ((ODataInlineEntity) link).getEntity();
- LOG.debug("Append in-line entity\n{}", inlineEntity);
-
- linkResource.setInlineEntity(getEntity(inlineEntity));
- } else if (link instanceof ODataInlineEntitySet) {
- // append inline entity set
- final ODataEntitySet InlineEntitySet = ((ODataInlineEntitySet) link).getEntitySet();
- LOG.debug("Append in-line entity set\n{}", InlineEntitySet);
-
- linkResource.setInlineEntitySet(getEntitySet(InlineEntitySet));
- }
-
- return linkResource;
- }
-
- protected Object getValue(final ODataValue value) {
- if (value == null) {
- return null;
- } else if (value.isPrimitive()) {
- return value.asPrimitive().toValue();
- } else if (value.isComplex()) {
- final ODataComplexValue<? extends ODataProperty> _value = value.asComplex();
- List<Property> valueResource = new ArrayList<Property>();
-
- for (final ODataProperty propertyValue : _value) {
- valueResource.add(getProperty(propertyValue));
- }
- return valueResource;
- } else if (value.isCollection()) {
- final ODataCollectionValue<? extends ODataValue> _value = value.asCollection();
- ArrayList<Object> valueResource = new ArrayList<Object>();
-
- for (final ODataValue collectionValue : _value) {
- valueResource.add(getValue(collectionValue));
- }
- return valueResource;
- }
- return null;
- }
-
- protected abstract boolean add(ODataEntitySet entitySet, ODataEntity entity);
-
- @Override
- public ODataEntitySet getODataEntitySet(final ResWrap<EntitySet> resource) {
- if (LOG.isDebugEnabled()) {
- final StringWriter writer = new StringWriter();
- try {
- client.getSerializer(ODataFormat.JSON).write(writer, resource.getPayload());
- } catch (final ODataSerializerException e) {
- }
- writer.flush();
- LOG.debug("EntitySet -> ODataEntitySet:\n{}", writer.toString());
- }
-
- final URI base = resource.getContextURL() == null
- ? resource.getPayload().getBaseURI()
- : ContextURLParser.parse(resource.getContextURL()).getServiceRoot();
-
- final URI next = resource.getPayload().getNext();
-
- final ODataEntitySet entitySet = next == null
- ? client.getObjectFactory().newEntitySet()
- : client.getObjectFactory().newEntitySet(URIUtils.getURI(base, next.toASCIIString()));
-
- if (resource.getPayload().getCount() != null) {
- entitySet.setCount(resource.getPayload().getCount());
- }
-
- for (Entity entityResource : resource.getPayload().getEntities()) {
- add(entitySet, getODataEntity(
- new ResWrap<Entity>(resource.getContextURL(), resource.getMetadataETag(), entityResource)));
- }
-
- return entitySet;
- }
-
- protected void odataNavigationLinks(final EdmType edmType,
- final Linked linked, final ODataLinked odataLinked, final String metadataETag, final URI base) {
-
- for (Link link : linked.getNavigationLinks()) {
- final String href = link.getHref();
- final String title = link.getTitle();
- final Entity inlineEntity = link.getInlineEntity();
- final EntitySet inlineEntitySet = link.getInlineEntitySet();
- if (inlineEntity == null && inlineEntitySet == null) {
- ODataLinkType linkType = null;
- if (edmType instanceof EdmStructuredType) {
- final EdmNavigationProperty navProp = ((EdmStructuredType) edmType).getNavigationProperty(title);
- if (navProp != null) {
- linkType = navProp.isCollection() ?
- ODataLinkType.ENTITY_SET_NAVIGATION :
- ODataLinkType.ENTITY_NAVIGATION;
- }
- }
- if (linkType == null) {
- linkType = link.getType() == null ?
- ODataLinkType.ENTITY_NAVIGATION :
- ODataLinkType.fromString(client.getServiceVersion(), link.getRel(), link.getType());
- }
-
- odataLinked.addLink(linkType == ODataLinkType.ENTITY_NAVIGATION ?
- client.getObjectFactory().newEntityNavigationLink(title, URIUtils.getURI(base, href)) :
- client.getObjectFactory().newEntitySetNavigationLink(title, URIUtils.getURI(base, href)));
- } else if (inlineEntity != null) {
- odataLinked.addLink(createODataInlineEntity(inlineEntity,
- URIUtils.getURI(base, href), title, metadataETag));
- } else {
- odataLinked.addLink(createODataInlineEntitySet(inlineEntitySet,
- URIUtils.getURI(base, href), title, metadataETag));
- }
- }
- }
-
- private ODataInlineEntity createODataInlineEntity(final Entity inlineEntity,
- final URI uri, final String title, final String metadataETag) {
- return new ODataInlineEntity(client.getServiceVersion(), uri, ODataLinkType.ENTITY_NAVIGATION, title,
- getODataEntity(new ResWrap<Entity>(
- inlineEntity.getBaseURI() == null ? null : inlineEntity.getBaseURI(), metadataETag,
- inlineEntity)));
- }
-
- private ODataInlineEntitySet createODataInlineEntitySet(final EntitySet inlineEntitySet,
- final URI uri, final String title, final String metadataETag) {
- return new ODataInlineEntitySet(client.getServiceVersion(), uri, ODataLinkType.ENTITY_SET_NAVIGATION, title,
- getODataEntitySet(new ResWrap<EntitySet>(
- inlineEntitySet.getBaseURI() == null ? null : inlineEntitySet.getBaseURI(), metadataETag,
- inlineEntitySet)));
- }
-
- private EdmEntityType findEntityType(
- final String entitySetOrSingletonOrType, final EdmEntityContainer container) {
-
- EdmEntityType type = null;
-
- final String firstToken = StringUtils.substringBefore(entitySetOrSingletonOrType, "/");
- EdmBindingTarget bindingTarget = container.getEntitySet(firstToken);
- if (bindingTarget == null) {
- bindingTarget = container.getSingleton(firstToken);
- }
- if (bindingTarget != null) {
- type = bindingTarget.getEntityType();
- }
-
- if (entitySetOrSingletonOrType.indexOf('/') != -1) {
- final String[] splitted = entitySetOrSingletonOrType.split("/");
- if (splitted.length > 1) {
- for (int i = 1; i < splitted.length && type != null; i++) {
- final EdmNavigationProperty navProp = type.getNavigationProperty(splitted[i]);
- if (navProp == null) {
- type = null;
- } else {
- type = navProp.getType();
- }
- }
- }
- }
-
- return type;
- }
-
- /**
- * Infer type name from various sources of information including Edm and context URL, if available.
- *
- * @param candidateTypeName type name as provided by the service
- * @param contextURL context URL
- * @param metadataETag metadata ETag
- * @return Edm type information
- */
- private EdmType findType(final String candidateTypeName, final ContextURL contextURL, final String metadataETag) {
- EdmType type = null;
-
- if (client instanceof EdmEnabledODataClient) {
- final Edm edm = ((EdmEnabledODataClient) client).getEdm(metadataETag);
- if (StringUtils.isNotBlank(candidateTypeName)) {
- type = edm.getEntityType(new FullQualifiedName(candidateTypeName));
- }
- if (type == null && contextURL != null) {
- if (contextURL.getDerivedEntity() == null) {
- for (EdmSchema schema : edm.getSchemas()) {
- final EdmEntityContainer container = schema.getEntityContainer();
- if (container != null) {
- final EdmEntityType entityType = findEntityType(contextURL.getEntitySetOrSingletonOrType(), container);
-
- if (entityType != null) {
- if (contextURL.getNavOrPropertyPath() == null) {
- type = entityType;
- } else {
- final EdmNavigationProperty navProp =
- entityType.getNavigationProperty(contextURL.getNavOrPropertyPath());
-
- type = navProp == null
- ? entityType
- : navProp.getType();
- }
- }
- }
- }
- if (type == null) {
- type = new EdmTypeInfo.Builder().setEdm(edm).
- setTypeExpression(contextURL.getEntitySetOrSingletonOrType()).build().getType();
- }
- } else {
- type = edm.getEntityType(new FullQualifiedName(contextURL.getDerivedEntity()));
- }
- }
- }
-
- return type;
- }
-
- @Override
- public ODataEntity getODataEntity(final ResWrap<Entity> resource) {
- if (LOG.isDebugEnabled()) {
- final StringWriter writer = new StringWriter();
- try {
- client.getSerializer(ODataFormat.JSON).write(writer, resource.getPayload());
- } catch (final ODataSerializerException e) {
- }
- writer.flush();
- LOG.debug("EntityResource -> ODataEntity:\n{}", writer.toString());
- }
-
- final ContextURL contextURL = ContextURLParser.parse(resource.getContextURL());
- final URI base = resource.getContextURL() == null
- ? resource.getPayload().getBaseURI()
- : contextURL.getServiceRoot();
- final EdmType edmType = findType(resource.getPayload().getType(), contextURL, resource.getMetadataETag());
- FullQualifiedName typeName = null;
- if (resource.getPayload().getType() == null) {
- if (edmType != null) {
- typeName = edmType.getFullQualifiedName();
- }
- } else {
- typeName = new FullQualifiedName(resource.getPayload().getType());
- }
-
- final ODataEntity entity = resource.getPayload().getSelfLink() == null
- ? client.getObjectFactory().newEntity(typeName)
- : client.getObjectFactory().newEntity(typeName,
- URIUtils.getURI(base, resource.getPayload().getSelfLink().getHref()));
-
- if (StringUtils.isNotBlank(resource.getPayload().getETag())) {
- entity.setETag(resource.getPayload().getETag());
- }
-
- if (resource.getPayload().getEditLink() != null) {
- entity.setEditLink(URIUtils.getURI(base, resource.getPayload().getEditLink().getHref()));
- }
-
- for (Link link : resource.getPayload().getAssociationLinks()) {
- entity.addLink(client.getObjectFactory().
- newAssociationLink(link.getTitle(), URIUtils.getURI(base, link.getHref())));
- }
-
- odataNavigationLinks(edmType, resource.getPayload(), entity, resource.getMetadataETag(), base);
-
- for (Link link : resource.getPayload().getMediaEditLinks()) {
- entity.addLink(client.getObjectFactory().
- newMediaEditLink(link.getTitle(), URIUtils.getURI(base, link.getHref())));
- }
-
- for (ODataOperation operation : resource.getPayload().getOperations()) {
- operation.setTarget(URIUtils.getURI(base, operation.getTarget()));
- entity.getOperations().add(operation);
- }
-
- if (resource.getPayload().isMediaEntity()) {
- entity.setMediaEntity(true);
- entity.setMediaContentSource(URIUtils.getURI(base, resource.getPayload().getMediaContentSource()));
- entity.setMediaContentType(resource.getPayload().getMediaContentType());
- entity.setMediaETag(resource.getPayload().getMediaETag());
- }
-
- for (final Property property : resource.getPayload().getProperties()) {
- EdmType propertyType = null;
- if (edmType instanceof EdmEntityType) {
- final EdmElement edmProperty = ((EdmEntityType) edmType).getProperty(property.getName());
- if (edmProperty != null) {
- propertyType = edmProperty.getType();
- if (edmProperty instanceof EdmNavigationProperty) {
- final String propertyTypeName = propertyType.getFullQualifiedName().getFullQualifiedNameAsString();
- entity.addLink(createLinkFromNavigationProperty(property, propertyTypeName));
- break;
- }
- }
- }
- add(entity, getODataProperty(propertyType, property));
- }
-
- return entity;
- }
-
- private ODataLink createLinkFromNavigationProperty(final Property property, final String propertyTypeName) {
- if (property.isCollection()) {
- EntitySet inlineEntitySet = new EntitySetImpl();
- for (final Object inlined : property.asCollection()) {
- Entity inlineEntity = new EntityImpl();
- inlineEntity.setType(propertyTypeName);
- inlineEntity.getProperties().addAll(
- inlined instanceof LinkedComplexValue ? ((LinkedComplexValue) inlined).getValue() :
- inlined instanceof Property ? ((Property) inlined).asComplex() : null);
- inlineEntitySet.getEntities().add(inlineEntity);
- }
- return createODataInlineEntitySet(inlineEntitySet, null, property.getName(), null);
- } else {
- Entity inlineEntity = new EntityImpl();
- inlineEntity.setType(propertyTypeName);
- inlineEntity.getProperties().addAll(
- property.isLinkedComplex() ? property.asLinkedComplex().getValue() : property.asComplex());
- return createODataInlineEntity(inlineEntity, null, property.getName(), null);
- }
- }
-
- protected EdmTypeInfo buildTypeInfo(final ContextURL contextURL, final String metadataETag,
- final String propertyName, final String propertyType) {
-
- FullQualifiedName typeName = null;
- final EdmType type = findType(null, contextURL, metadataETag);
- if (type instanceof EdmStructuredType) {
- final EdmProperty edmProperty = ((EdmStructuredType) type).getStructuralProperty(propertyName);
- if (edmProperty != null) {
- typeName = edmProperty.getType().getFullQualifiedName();
- }
- }
- if (typeName == null && type != null) {
- typeName = type.getFullQualifiedName();
- }
-
- return buildTypeInfo(typeName, propertyType);
- }
-
- protected EdmTypeInfo buildTypeInfo(final FullQualifiedName typeName, final String propertyType) {
- EdmTypeInfo typeInfo = null;
- if (typeName == null) {
- if (propertyType != null) {
- typeInfo = new EdmTypeInfo.Builder().setTypeExpression(propertyType).build();
- }
- } else {
- if (propertyType == null || propertyType.equals(EdmPrimitiveTypeKind.String.getFullQualifiedName().toString())) {
- typeInfo = new EdmTypeInfo.Builder().setTypeExpression(typeName.toString()).build();
- } else {
- typeInfo = new EdmTypeInfo.Builder().setTypeExpression(propertyType).build();
- }
- }
- return typeInfo;
- }
-
- protected abstract ODataProperty getODataProperty(EdmType type, Property resource);
-
- protected ODataValue getODataValue(final FullQualifiedName type,
- final Valuable valuable, final URI contextURL, final String metadataETag) {
-
- ODataValue value = null;
- if (valuable.isGeospatial()) {
- value = client.getObjectFactory().newPrimitiveValueBuilder().
- setValue(valuable.asGeospatial()).
- setType(type == null
- || EdmPrimitiveTypeKind.Geography.getFullQualifiedName().equals(type)
- || EdmPrimitiveTypeKind.Geometry.getFullQualifiedName().equals(type)
- ? valuable.asGeospatial().getEdmPrimitiveTypeKind()
- : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).
- build();
- } else if (valuable.isPrimitive() || valuable.getValueType() == null) {
- // fixes non-string values treated as string when no type information is available at de-serialization level
- if (type != null && !EdmPrimitiveTypeKind.String.getFullQualifiedName().equals(type)
- && EdmPrimitiveType.EDM_NAMESPACE.equals(type.getNamespace())
- && valuable.asPrimitive() instanceof String) {
-
- final EdmPrimitiveType primitiveType =
- EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.valueOf(type.getName()));
- final Class<?> returnType = primitiveType.getDefaultType().isAssignableFrom(Calendar.class)
- ? Timestamp.class : primitiveType.getDefaultType();
- try {
- valuable.setValue(valuable.getValueType(),
- primitiveType.valueOfString(valuable.asPrimitive().toString(),
- null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null,
- returnType));
- } catch (EdmPrimitiveTypeException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- value = client.getObjectFactory().newPrimitiveValueBuilder().
- setValue(valuable.asPrimitive()).
- setType(type == null || !EdmPrimitiveType.EDM_NAMESPACE.equals(type.getNamespace())
- ? null
- : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).
- build();
- } else if (valuable.isComplex()) {
- final ODataComplexValue<ODataProperty> cValue =
- (ODataComplexValue<ODataProperty>) client.getObjectFactory().
- newComplexValue(type == null ? null : type.toString());
-
- if (!valuable.isNull()) {
- EdmComplexType edmType = null;
- if (client instanceof EdmEnabledODataClient && type != null) {
- edmType = ((EdmEnabledODataClient) client).getEdm(metadataETag).getComplexType(type);
- }
-
- for (Property property : valuable.asComplex()) {
- EdmType edmPropertyType = null;
- if (edmType != null) {
- final EdmElement edmProp = edmType.getProperty(property.getName());
- if (edmProp != null) {
- edmPropertyType = edmProp.getType();
- }
- }
-
- cValue.add(getODataProperty(edmPropertyType, property));
- }
- }
-
- value = cValue;
- } else if (valuable.isCollection()) {
- value = client.getObjectFactory().newCollectionValue(type == null ? null : "Collection(" + type.toString() + ")");
-
- for (Object _value : valuable.asCollection()) {
- final Property fake = new PropertyImpl();
- fake.setValue(valuable.getValueType().getBaseType(), _value);
- value.asCollection().add(getODataValue(type, fake, contextURL, metadataETag));
- }
- }
-
- return value;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/68b14ffe/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataReader.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataReader.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataReader.java
deleted file mode 100644
index 876581d..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AbstractODataReader.java
+++ /dev/null
@@ -1,157 +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.serialization;
-
-import java.io.InputStream;
-import java.net.URI;
-import java.util.Map;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.olingo.client.api.CommonODataClient;
-import org.apache.olingo.client.api.data.ServiceDocument;
-import org.apache.olingo.client.api.domain.ODataEntitySetIterator;
-import org.apache.olingo.client.api.edm.xml.Schema;
-import org.apache.olingo.client.api.edm.xml.XMLMetadata;
-import org.apache.olingo.client.api.serialization.CommonODataReader;
-import org.apache.olingo.client.core.edm.EdmClientImpl;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.domain.ODataEntity;
-import org.apache.olingo.commons.api.domain.ODataEntitySet;
-import org.apache.olingo.commons.api.domain.ODataProperty;
-import org.apache.olingo.commons.api.domain.ODataError;
-import org.apache.olingo.commons.api.domain.ODataServiceDocument;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class AbstractODataReader implements CommonODataReader {
-
- /**
- * Logger.
- */
- protected static final Logger LOG = LoggerFactory.getLogger(AbstractODataReader.class);
-
- protected final CommonODataClient<?> client;
-
- protected AbstractODataReader(final CommonODataClient<?> client) {
- this.client = client;
- }
-
- @Override
- public Edm readMetadata(final InputStream input) {
- return readMetadata(client.getDeserializer(ODataFormat.XML).toMetadata(input).getSchemaByNsOrAlias());
- }
-
- @Override
- public Edm readMetadata(final Map<String, Schema> xmlSchemas) {
- return new EdmClientImpl(client.getServiceVersion(), xmlSchemas);
- }
-
- @Override
- public ODataServiceDocument readServiceDocument(final InputStream input, final ODataFormat format)
- throws ODataDeserializerException {
- return client.getBinder().getODataServiceDocument(
- client.getDeserializer(format).toServiceDocument(input).getPayload());
- }
-
- @Override
- public ODataError readError(final InputStream inputStream, final ODataFormat format )
- throws ODataDeserializerException {
- return client.getDeserializer(format).toError(inputStream);
- }
-
- @Override
- public <T> ResWrap<T> read(final InputStream src, final String format, final Class<T> reference)
- throws ODataDeserializerException {
- ResWrap<T> res;
-
- try {
- if (ODataEntitySetIterator.class.isAssignableFrom(reference)) {
- res = new ResWrap<T>(
- (URI) null,
- null,
- reference.cast(new ODataEntitySetIterator<ODataEntitySet, ODataEntity>(
- client, src, ODataFormat.fromString(format))));
- } else if (ODataEntitySet.class.isAssignableFrom(reference)) {
- final ResWrap<EntitySet> resource = client.getDeserializer(ODataFormat.fromString(format))
- .toEntitySet(src);
- res = new ResWrap<T>(
- resource.getContextURL(),
- resource.getMetadataETag(),
- reference.cast(client.getBinder().getODataEntitySet(resource)));
- } else if (ODataEntity.class.isAssignableFrom(reference)) {
- final ResWrap<Entity> container = client.getDeserializer(ODataFormat.fromString(format)).toEntity(src);
- res = new ResWrap<T>(
- container.getContextURL(),
- container.getMetadataETag(),
- reference.cast(client.getBinder().getODataEntity(container)));
- } else if (ODataProperty.class.isAssignableFrom(reference)) {
- final ResWrap<Property> container = client.getDeserializer(ODataFormat.fromString(format)).toProperty(src);
- res = new ResWrap<T>(
- container.getContextURL(),
- container.getMetadataETag(),
- reference.cast(client.getBinder().getODataProperty(container)));
- } else if (ODataValue.class.isAssignableFrom(reference)) {
- res = new ResWrap<T>(
- (URI) null,
- null,
- reference.cast(client.getObjectFactory().newPrimitiveValueBuilder().
- setType(ODataFormat.fromString(format) == ODataFormat.TEXT_PLAIN
- ? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
- setValue(IOUtils.toString(src)) // TODO: set correct value
- .build()));
- } else if (XMLMetadata.class.isAssignableFrom(reference)) {
- res = new ResWrap<T>(
- (URI) null,
- null,
- reference.cast(readMetadata(src)));
- } else if (ODataServiceDocument.class.isAssignableFrom(reference)) {
- final ResWrap<ServiceDocument> resource =
- client.getDeserializer(ODataFormat.fromString(format)).toServiceDocument(src);
- res = new ResWrap<T>(
- resource.getContextURL(),
- resource.getMetadataETag(),
- reference.cast(client.getBinder().getODataServiceDocument(resource.getPayload())));
- } else if (ODataError.class.isAssignableFrom(reference)) {
- res = new ResWrap<T>(
- (URI) null,
- null,
- reference.cast(readError(src, ODataFormat.fromString(format))));
- } else {
- throw new IllegalArgumentException("Invalid reference type " + reference);
- }
- } catch (Exception e) {
- LOG.warn("Cast error", e);
- res = null;
- } finally {
- if (!ODataEntitySetIterator.class.isAssignableFrom(reference)) {
- IOUtils.closeQuietly(src);
- }
- }
-
- return res;
- }
-}