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/05/22 13:43:51 UTC
[43/51] [abbrv] [partial] Removing /ODataJClient: merge complete
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ODataTimestamp.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ODataTimestamp.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ODataTimestamp.java
deleted file mode 100644
index b59a498..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ODataTimestamp.java
+++ /dev/null
@@ -1,142 +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 com.msopentech.odatajclient.engine.data;
-
-import com.msopentech.odatajclient.engine.metadata.edm.EdmSimpleType;
-import java.io.Serializable;
-import java.sql.Timestamp;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
-/**
- * Helper class for handling datetime and datetime-offset primitive values.
- *
- * @see com.msopentech.odatajclient.engine.data.metadata.edm.EdmSimpleType#DATE_TIME
- * @see com.msopentech.odatajclient.engine.data.metadata.edm.EdmSimpleType#DATE_TIME_OFFSET
- */
-public final class ODataTimestamp implements Serializable {
-
- private static final long serialVersionUID = 4053990618660356004L;
-
- private final SimpleDateFormat sdf;
-
- private final Timestamp timestamp;
-
- private String timezone;
-
- private final boolean offset;
-
- public static ODataTimestamp getInstance(final EdmSimpleType type, final Timestamp timestamp) {
- return new ODataTimestamp(new SimpleDateFormat(type.pattern()),
- new Date(timestamp.getTime()), timestamp.getNanos(), type == EdmSimpleType.DateTimeOffset);
- }
-
- public static ODataTimestamp parse(final EdmSimpleType type, final String input) {
- final ODataTimestamp instance;
-
- final String[] dateParts = input.split("\\.");
- final SimpleDateFormat sdf = new SimpleDateFormat(type.pattern());
- final boolean isOffset = type == EdmSimpleType.DateTimeOffset;
-
- try {
- final Date date = sdf.parse(dateParts[0]);
- if (dateParts.length > 1) {
- int idx = dateParts[1].indexOf('+');
- if (idx == -1) {
- idx = dateParts[1].indexOf('-');
- }
- if (idx == -1) {
- instance = new ODataTimestamp(sdf, date, Integer.parseInt(dateParts[1]), isOffset);
- } else {
- instance = new ODataTimestamp(sdf, date,
- Integer.parseInt(dateParts[1].substring(0, idx)), dateParts[1].substring(idx), isOffset);
- }
- } else {
- instance = new ODataTimestamp(sdf, date, isOffset);
- }
- } catch (Exception e) {
- throw new IllegalArgumentException("Cannot parse " + type.pattern(), e);
- }
-
- return instance;
- }
-
- private ODataTimestamp(final SimpleDateFormat sdf, final Date date, final boolean offset) {
- this.sdf = sdf;
- this.timestamp = new Timestamp(date.getTime());
- this.offset = offset;
- }
-
- private ODataTimestamp(final SimpleDateFormat sdf, final Date date, final int nanos, final boolean offset) {
- this(sdf, date, offset);
- this.timestamp.setNanos(nanos);
- }
-
- private ODataTimestamp(
- final SimpleDateFormat sdf, final Date date, final int nanos, final String timezone, final boolean offset) {
- this(sdf, date, nanos, offset);
- this.timezone = timezone;
- }
-
- public Timestamp getTimestamp() {
- return timestamp;
- }
-
- public String getTimezone() {
- return timezone;
- }
-
- public boolean isOffset() {
- return offset;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public boolean equals(final Object obj) {
- return EqualsBuilder.reflectionEquals(this, obj, "sdf");
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public int hashCode() {
- return HashCodeBuilder.reflectionHashCode(this, "sdf");
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public String toString() {
- final StringBuilder formatted = new StringBuilder().append(sdf.format(timestamp));
- if (timestamp.getNanos() > 0) {
- formatted.append('.').append(String.valueOf(timestamp.getNanos()));
- }
- if (StringUtils.isNotBlank(timezone)) {
- formatted.append(timezone);
- }
- return formatted.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ODataValue.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ODataValue.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ODataValue.java
deleted file mode 100644
index 37a4dd4..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ODataValue.java
+++ /dev/null
@@ -1,111 +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 com.msopentech.odatajclient.engine.data;
-
-import java.io.Serializable;
-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;
-
-/**
- * Abstract representation of an OData entity property value.
- */
-public abstract class ODataValue implements Serializable {
-
- private static final long serialVersionUID = 7445422004232581877L;
-
- /**
- * Check is is a primitive value.
- *
- * @return 'TRUE' if primitive; 'FALSE' otherwise.
- */
- public boolean isPrimitive() {
- return (this instanceof ODataPrimitiveValue);
- }
-
- /**
- * Casts to primitive value.
- *
- * @return primitive value.
- */
- public ODataPrimitiveValue asPrimitive() {
- return isPrimitive() ? (ODataPrimitiveValue) this : null;
- }
-
- /**
- * Check is is a complex value.
- *
- * @return 'TRUE' if complex; 'FALSE' otherwise.
- */
- public boolean isComplex() {
- return (this instanceof ODataComplexValue);
- }
-
- /**
- * Casts to complex value.
- *
- * @return complex value.
- */
- public ODataComplexValue asComplex() {
- return isComplex() ? (ODataComplexValue) this : null;
- }
-
- /**
- * Check is is a collection value.
- *
- * @return 'TRUE' if collection; 'FALSE' otherwise.
- */
- public boolean isCollection() {
- return (this instanceof ODataCollectionValue);
- }
-
- /**
- * Casts to collection value.
- *
- * @return collection value.
- */
- public ODataCollectionValue asCollection() {
- return isCollection() ? (ODataCollectionValue) this : null;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public boolean equals(final Object obj) {
- return EqualsBuilder.reflectionEquals(this, obj);
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public int hashCode() {
- return HashCodeBuilder.reflectionHashCode(this);
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public String toString() {
- return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ODataWriter.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ODataWriter.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ODataWriter.java
deleted file mode 100644
index e0d4928..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ODataWriter.java
+++ /dev/null
@@ -1,91 +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 com.msopentech.odatajclient.engine.data;
-
-import com.msopentech.odatajclient.engine.format.ODataPubFormat;
-import com.msopentech.odatajclient.engine.format.ODataFormat;
-import java.io.InputStream;
-import java.io.Serializable;
-import java.util.Collection;
-
-/**
- * OData writer.
- * <br/>
- * Use this interface to serialize an OData request body.
- * <br/>
- * This interface provides method helpers to serialize a set of entities and a single entity as well.
- */
-public interface ODataWriter extends Serializable {
-
- /**
- * Writes a collection of OData entities.
- *
- * @param entities entities to be serialized.
- * @param format serialization format.
- * @return stream of serialized objects.
- */
- InputStream writeEntities(Collection<ODataEntity> entities, ODataPubFormat format);
-
- /**
- * Writes a collection of OData entities.
- *
- * @param entities entities to be serialized.
- * @param format serialization format.
- * @param outputType whether to explicitly output type information.
- * @return stream of serialized objects.
- */
- InputStream writeEntities(Collection<ODataEntity> entities, ODataPubFormat format, boolean outputType);
-
- /**
- * Serializes a single OData entity.
- *
- * @param entity entity to be serialized.
- * @param format serialization format.
- * @return stream of serialized object.
- */
- InputStream writeEntity(ODataEntity entity, ODataPubFormat format);
-
- /**
- * Serializes a single OData entity.
- *
- * @param entity entity to be serialized.
- * @param format serialization format.
- * @param outputType whether to explicitly output type information.
- * @return stream of serialized object.
- */
- InputStream writeEntity(ODataEntity entity, ODataPubFormat format, boolean outputType);
-
- /**
- * Writes a single OData entity property.
- *
- * @param property entity property to be serialized.
- * @param format serialization format.
- * @return stream of serialized object.
- */
- InputStream writeProperty(ODataProperty property, ODataFormat format);
-
- /**
- * Writes an OData link.
- *
- * @param link link to be serialized.
- * @param format serialization format.
- * @return stream of serialized object.
- */
- InputStream writeLink(ODataLink link, ODataFormat format);
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ResourceFactory.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ResourceFactory.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ResourceFactory.java
deleted file mode 100644
index a2c6029..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ResourceFactory.java
+++ /dev/null
@@ -1,281 +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 com.msopentech.odatajclient.engine.data;
-
-import com.msopentech.odatajclient.engine.data.impl.v3.AtomEntry;
-import com.msopentech.odatajclient.engine.data.impl.v3.AtomFeed;
-import com.msopentech.odatajclient.engine.data.impl.v3.AtomLink;
-import com.msopentech.odatajclient.engine.data.impl.v3.JSONEntry;
-import com.msopentech.odatajclient.engine.data.impl.v3.JSONFeed;
-import com.msopentech.odatajclient.engine.data.impl.v3.JSONLink;
-import com.msopentech.odatajclient.engine.format.ODataPubFormat;
-
-public class ResourceFactory {
-
- /**
- * Gets a new instance of <tt>Feed</tt>.
- *
- * @param <T> resource type.
- * @param resourceClass reference class.
- * @return <tt>Feed</tt> object.
- */
- @SuppressWarnings("unchecked")
- public static <T extends Feed> T newFeed(final Class<T> resourceClass) {
- T result = null;
-
- if (AtomFeed.class.equals(resourceClass)) {
- result = (T) new AtomFeed();
- }
- if (JSONFeed.class.equals(resourceClass)) {
- result = (T) new JSONFeed();
- }
-
- return result;
- }
-
- /**
- * Gets a new instance of <tt>Entry</tt>.
- *
- * @param <T> resource type.
- * @param resourceClass reference class.
- * @return <tt>Entry</tt> object.
- */
- @SuppressWarnings("unchecked")
- public static <T extends Entry> T newEntry(final Class<T> resourceClass) {
- T result = null;
-
- if (AtomEntry.class.equals(resourceClass)) {
- result = (T) new AtomEntry();
- }
- if (JSONEntry.class.equals(resourceClass)) {
- result = (T) new JSONEntry();
- }
-
- return result;
- }
-
- /**
- * Gets a new instance of <tt>Link</tt>.
- *
- * @param <T> resource type.
- * @param resourceClass reference class.
- * @return <tt>Link</tt> object.
- */
- @SuppressWarnings("unchecked")
- public static <T extends Link> T newLink(final Class<T> resourceClass) {
- T result = null;
-
- if (AtomLink.class.equals(resourceClass)) {
- result = (T) new AtomLink();
- }
- if (JSONLink.class.equals(resourceClass)) {
- result = (T) new JSONLink();
- }
-
- return result;
- }
-
- /**
- * Gets feed reference class from the given format.
- *
- * @param <T> resource type.
- * @param format format.
- * @return resource reference class.
- */
- @SuppressWarnings("unchecked")
- public static <T extends Feed> Class<T> feedClassForFormat(final ODataPubFormat format) {
- Class<T> result = null;
-
- switch (format) {
- case ATOM:
- result = (Class<T>) AtomFeed.class;
- break;
-
- case JSON:
- case JSON_FULL_METADATA:
- case JSON_NO_METADATA:
- result = (Class<T>) JSONFeed.class;
- break;
- }
-
- return result;
- }
-
- /**
- * Gets entry reference class from the given format.
- *
- * @param <T> resource type.
- * @param format format.
- * @return resource reference class.
- */
- @SuppressWarnings("unchecked")
- public static <T extends Entry> Class<T> entryClassForFormat(final ODataPubFormat format) {
- Class<T> result = null;
-
- switch (format) {
- case ATOM:
- result = (Class<T>) AtomEntry.class;
- break;
-
- case JSON:
- case JSON_FULL_METADATA:
- case JSON_NO_METADATA:
- result = (Class<T>) JSONEntry.class;
- break;
- }
-
- return result;
- }
-
- /**
- * Gets <tt>Link</tt> object from feed resource.
- *
- * @param <T> link resource type.
- * @param <K> feed resource type.
- * @param resourceClass feed reference class.
- * @return <tt>Link</tt> object.
- */
- @SuppressWarnings("unchecked")
- public static <T extends Link, K extends Feed> T newLinkForFeed(final Class<K> resourceClass) {
- T result = null;
-
- if (AtomFeed.class.equals(resourceClass)) {
- result = (T) new AtomLink();
- }
- if (JSONFeed.class.equals(resourceClass)) {
- result = (T) new JSONLink();
- }
-
- return result;
- }
-
- /**
- * Gets <tt>Link</tt> object from entry resource.
- *
- * @param <T> link resource type.
- * @param <K> entry resource type.
- * @param resourceClass entry reference class.
- * @return <tt>Link</tt> object.
- */
- @SuppressWarnings("unchecked")
- public static <T extends Link, K extends Entry> T newLinkForEntry(final Class<K> resourceClass) {
- T result = null;
-
- if (AtomEntry.class.equals(resourceClass)) {
- result = (T) new AtomLink();
- }
- if (JSONEntry.class.equals(resourceClass)) {
- result = (T) new JSONLink();
- }
-
- return result;
- }
-
- /**
- * Gets <tt>Feed</tt> object from link resource.
- *
- * @param <T> link resource type.
- * @param <K> feed resource type.
- * @param resourceClass link reference class.
- * @return <tt>Feed</tt> object.
- */
- @SuppressWarnings("unchecked")
- public static <T extends Link, K extends Feed> Class<K> feedClassForLink(
- final Class<T> resourceClass) {
-
- Class<K> result = null;
-
- if (AtomLink.class.equals(resourceClass)) {
- result = (Class<K>) AtomFeed.class;
- }
- if (JSONLink.class.equals(resourceClass)) {
- result = (Class<K>) JSONFeed.class;
- }
-
- return result;
- }
-
- /**
- * Gets <tt>Link</tt> object from entry resource.
- *
- * @param <T> link resource type.
- * @param <K> entry resource type.
- * @param resourceClass entry reference class.
- * @return <tt>Link</tt> object.
- */
- @SuppressWarnings("unchecked")
- public static <T extends Link, K extends Entry> Class<T> linkClassForEntry(
- final Class<K> resourceClass) {
-
- Class<T> result = null;
-
- if (AtomEntry.class.equals(resourceClass)) {
- result = (Class<T>) AtomLink.class;
- }
- if (JSONEntry.class.equals(resourceClass)) {
- result = (Class<T>) JSONLink.class;
- }
-
- return result;
- }
-
- /**
- * Gets <tt>Entry</tt> object from link resource.
- *
- * @param <T> link resource type.
- * @param <K> entry resource type.
- * @param resourceClass link reference class.
- * @return <tt>Entry</tt> object.
- */
- @SuppressWarnings("unchecked")
- public static <T extends Link, K extends Entry> Class<K> entryClassForLink(final Class<T> resourceClass) {
- Class<K> result = null;
-
- if (AtomLink.class.equals(resourceClass)) {
- result = (Class<K>) AtomEntry.class;
- }
- if (JSONLink.class.equals(resourceClass)) {
- result = (Class<K>) JSONEntry.class;
- }
-
- return result;
- }
-
- /**
- * Gets <tt>Entry</tt> object from feed resource.
- *
- * @param <T> feed resource type.
- * @param <K> entry resource type.
- * @param resourceClass feed reference class.
- * @return <tt>Entry</tt> object.
- */
- @SuppressWarnings("unchecked")
- public static <T extends Feed, K extends Entry> Class<K> entryClassForFeed(final Class<T> resourceClass) {
- Class<K> result = null;
-
- if (AtomFeed.class.equals(resourceClass)) {
- result = (Class<K>) AtomEntry.class;
- }
- if (JSONFeed.class.equals(resourceClass)) {
- result = (Class<K>) JSONEntry.class;
- }
-
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ServiceDocument.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ServiceDocument.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ServiceDocument.java
deleted file mode 100644
index 690d17c..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ServiceDocument.java
+++ /dev/null
@@ -1,138 +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 com.msopentech.odatajclient.engine.data;
-
-import java.net.URI;
-import java.util.List;
-
-/**
- * REST resource for an <tt>ODataServiceDocument</tt>.
- *
- * @see ODataServiceDocument
- */
-public interface ServiceDocument {
-
- String getTitle();
-
- /**
- * Gets base URI.
- *
- * @return base URI.
- */
- URI getBaseURI();
-
- /**
- * Returns metadata context.
- *
- * @return metadata context
- */
- String getMetadataContext();
-
- /**
- * Returns metadata ETag.
- *
- * @return metadata ETag
- */
- String getMetadataETag();
-
- /**
- * Gets top level entity sets.
- *
- * @return top level entity sets.
- */
- List<ServiceDocumentElement> getEntitySets();
-
- /**
- * Gets top level entity set with given name.
- *
- * @param name entity set name
- * @return entity set with given name if found, otherwise null
- */
- ServiceDocumentElement getEntitySetByName(String name);
-
- /**
- * Gets top level entity set with given title.
- *
- * @param title entity set title
- * @return entity set with given title if found, otherwise null
- */
- ServiceDocumentElement getEntitySetByTitle(String title);
-
- /**
- * Gets top level function imports.
- *
- * @return top level function imports.
- */
- List<ServiceDocumentElement> getFunctionImports();
-
- /**
- * Gets top level function import set with given name.
- *
- * @param name function import name
- * @return function import with given name if found, otherwise null
- */
- ServiceDocumentElement getFunctionImportByName(String name);
-
- /**
- * Gets top level function import with given title.
- *
- * @param title function import title
- * @return function import with given title if found, otherwise null
- */
- ServiceDocumentElement getFunctionImportByTitle(String title);
-
- /**
- * Gets top level singletons.
- *
- * @return top level singletons.
- */
- List<ServiceDocumentElement> getSingletons();
-
- /**
- * Gets top level singleton with given name.
- *
- * @param name singleton name
- * @return singleton with given name if found, otherwise null
- */
- ServiceDocumentElement getSingletonByName(String name);
-
- /**
- * Gets top level singleton with given title.
- *
- * @param title singleton title
- * @return singleton with given title if found, otherwise null
- */
- ServiceDocumentElement getSingletonByTitle(String title);
-
- /**
- * Gets related service documents.
- *
- * @return related service documents.
- */
- List<ServiceDocumentElement> getRelatedServiceDocuments();
-
- /**
- * Gets related service document with given title.
- *
- * @param title related service document title
- * @return related service document with given title if found, otherwise null
- */
- ServiceDocumentElement getRelatedServiceDocumentByTitle(String title);
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ServiceDocumentElement.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ServiceDocumentElement.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ServiceDocumentElement.java
deleted file mode 100644
index 04c2064..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/ServiceDocumentElement.java
+++ /dev/null
@@ -1,74 +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 com.msopentech.odatajclient.engine.data;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-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;
-
-public class ServiceDocumentElement {
-
- private String name;
-
- private String title;
-
- @JsonProperty("url")
- private String href;
-
- public String getName() {
- return name;
- }
-
- public void setName(final String name) {
- this.name = name;
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(final String title) {
- this.title = title;
- }
-
- public String getHref() {
- return href;
- }
-
- public void setHref(final String href) {
- this.href = href;
- }
-
- @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/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractEntry.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractEntry.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractEntry.java
deleted file mode 100644
index bf98c20..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractEntry.java
+++ /dev/null
@@ -1,340 +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 com.msopentech.odatajclient.engine.data.impl;
-
-import com.msopentech.odatajclient.engine.data.Entry;
-import com.msopentech.odatajclient.engine.data.Link;
-import com.msopentech.odatajclient.engine.data.ODataOperation;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.commons.lang3.StringUtils;
-import org.w3c.dom.Element;
-
-/**
- * Abstract base for classes implementing <tt>EntryResource</tt>.
- */
-public abstract class AbstractEntry<LINK extends Link>
- extends AbstractPayloadObject implements Entry {
-
- private static final long serialVersionUID = 2127764552600969783L;
-
- private String eTag;
-
- private String type;
-
- private String id;
-
- private LINK readLink;
-
- private LINK editLink;
-
- private List<LINK> associationLinks;
-
- private List<LINK> navigationLinks;
-
- private List<LINK> mediaEditLinks;
-
- private List<ODataOperation> operations;
-
- private Element content;
-
- private Element mediaEntryProperties;
-
- private String mediaContentSource;
-
- private String mediaContentType;
-
- public AbstractEntry() {
- associationLinks = new ArrayList<LINK>();
- navigationLinks = new ArrayList<LINK>();
- mediaEditLinks = new ArrayList<LINK>();
- operations = new ArrayList<ODataOperation>();
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public String getETag() {
- return eTag;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public void setETag(final String eTag) {
- this.eTag = eTag;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public String getType() {
- return type;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public void setType(final String type) {
- this.type = type;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public String getId() {
- return id;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public void setId(final String id) {
- this.id = id;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public LINK getSelfLink() {
- return readLink;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- @SuppressWarnings("unchecked")
- public void setSelfLink(final Link readLink) {
- this.readLink = (LINK) readLink;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public LINK getEditLink() {
- return editLink;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- @SuppressWarnings("unchecked")
- public void setEditLink(final Link editLink) {
- this.editLink = (LINK) editLink;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- @SuppressWarnings("unchecked")
- public boolean addAssociationLink(final Link link) {
- return associationLinks.add((LINK) link);
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public List<LINK> getAssociationLinks() {
- return associationLinks;
- }
-
- @SuppressWarnings("unchecked")
- private void setLinks(final List<LINK> links, final List<Link> linkResources) {
- links.clear();
- for (Link link : linkResources) {
- links.add((LINK) link);
- }
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- @SuppressWarnings("unchecked")
- public boolean addNavigationLink(final Link link) {
- return navigationLinks.add((LINK) link);
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public void setAssociationLinks(final List<Link> associationLinks) {
- setLinks(this.associationLinks, associationLinks);
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public List<LINK> getNavigationLinks() {
- return navigationLinks;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- @SuppressWarnings("unchecked")
- public boolean addMediaEditLink(final Link link) {
- return mediaEditLinks.add((LINK) link);
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public void setNavigationLinks(final List<Link> navigationLinks) {
- setLinks(this.navigationLinks, navigationLinks);
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public List<LINK> getMediaEditLinks() {
- return mediaEditLinks;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public void setMediaEditLinks(final List<Link> mediaEditLinks) {
- setLinks(this.mediaEditLinks, mediaEditLinks);
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public List<ODataOperation> getOperations() {
- return operations;
- }
-
- /**
- * Adds operation.
- *
- * @param operation operation.
- * @return 'TRUE' in case of success; 'FALSE' otherwise.
- */
- public boolean addOperation(final ODataOperation operation) {
- return this.operations.add(operation);
- }
-
- /**
- * Sets operations.
- *
- * @param operations operations.
- */
- public void setOperations(final List<ODataOperation> operations) {
- this.operations.clear();
- if (operations != null && !operations.isEmpty()) {
- this.operations.addAll(operations);
- }
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public Element getContent() {
- return content;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public void setContent(final Element content) {
- this.content = content;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public Element getMediaEntryProperties() {
- return mediaEntryProperties;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public void setMediaEntryProperties(final Element mediaEntryProperties) {
- this.mediaEntryProperties = mediaEntryProperties;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public String getMediaContentType() {
- return this.mediaContentType;
- }
-
- /**
- * Sets media content type.
- *
- * @param mediaContentType media content type.
- */
- @Override
- public void setMediaContentType(final String mediaContentType) {
- this.mediaContentType = mediaContentType;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public String getMediaContentSource() {
- return this.mediaContentSource;
- }
-
- /**
- * Sets media content source.
- *
- * @param mediaContentSource media content source.
- */
- @Override
- public void setMediaContentSource(final String mediaContentSource) {
- this.mediaContentSource = mediaContentSource;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public boolean isMediaEntry() {
- return getMediaEntryProperties() != null || StringUtils.isNotBlank(this.mediaContentSource);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractJSONEntry.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractJSONEntry.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractJSONEntry.java
deleted file mode 100644
index 7db4366..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractJSONEntry.java
+++ /dev/null
@@ -1,90 +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 com.msopentech.odatajclient.engine.data.impl;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.msopentech.odatajclient.engine.data.impl.v3.JSONLink;
-import com.msopentech.odatajclient.engine.uri.SegmentType;
-import java.net.URI;
-
-/**
- * A single entry, represented via JSON.
- */
-@JsonSerialize(using = JSONEntrySerializer.class)
-@JsonDeserialize(using = JSONEntryDeserializer.class)
-public abstract class AbstractJSONEntry extends AbstractEntry<JSONLink> {
-
- private static final long serialVersionUID = -5275365545400797758L;
-
- private URI metadata;
-
- private String mediaETag;
-
- @JsonIgnore
- @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(String eTag) {
- this.mediaETag = eTag;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractJacksonTool.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractJacksonTool.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractJacksonTool.java
deleted file mode 100644
index 43c77fb..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractJacksonTool.java
+++ /dev/null
@@ -1,83 +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 com.msopentech.odatajclient.engine.data.impl;
-
-import com.fasterxml.aalto.stax.InputFactoryImpl;
-import com.fasterxml.aalto.stax.OutputFactoryImpl;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.InjectableValues;
-import com.fasterxml.jackson.databind.JsonDeserializer;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
-import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
-import com.fasterxml.jackson.dataformat.xml.XmlFactory;
-import com.fasterxml.jackson.dataformat.xml.XmlMapper;
-import com.msopentech.odatajclient.engine.client.ODataClient;
-import java.io.IOException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-abstract class AbstractJacksonTool {
-
- protected static final Logger LOG = LoggerFactory.getLogger(AbstractJacksonTool.class);
-
- protected final ODataClient client;
-
- protected AbstractJacksonTool(final ODataClient client) {
- this.client = client;
- }
-
- protected ObjectMapper getObjectMapper() {
- final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
-
- mapper.setInjectableValues(new InjectableValues.Std().addValue(ODataClient.class, client));
-
- mapper.setSerializerProvider(new InjectableSerializerProvider(mapper.getSerializerProvider(),
- mapper.getSerializationConfig().withAttribute(ODataClient.class, client),
- mapper.getSerializerFactory()));
-
- return mapper;
- }
-
- protected XmlMapper getXmlMapper() {
- final XmlMapper xmlMapper = new XmlMapper(
- new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule());
-
- xmlMapper.setInjectableValues(new InjectableValues.Std().addValue(ODataClient.class, client));
-
- xmlMapper.addHandler(new DeserializationProblemHandler() {
-
- @Override
- public boolean handleUnknownProperty(final DeserializationContext ctxt, final JsonParser jp,
- final JsonDeserializer<?> deserializer, final Object beanOrClass, final String propertyName)
- throws IOException, JsonProcessingException {
-
- // skip any unknown property
- LOG.warn("Skipping unknown property {}", propertyName);
- ctxt.getParser().skipChildren();
- return true;
- }
- });
- return xmlMapper;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractLink.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractLink.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractLink.java
deleted file mode 100644
index d575ce3..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractLink.java
+++ /dev/null
@@ -1,142 +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 com.msopentech.odatajclient.engine.data.impl;
-
-import com.msopentech.odatajclient.engine.data.Entry;
-import com.msopentech.odatajclient.engine.data.Feed;
-import com.msopentech.odatajclient.engine.data.Link;
-
-/**
- * Abstract base for classes implementing <tt>LinkResource</tt>.
- */
-public abstract class AbstractLink<ENTRY extends Entry, FEED extends Feed>
- extends AbstractPayloadObject implements Link {
-
- private static final long serialVersionUID = -3449344217160035501L;
-
- private String title;
-
- private String rel;
-
- private String href;
-
- private String type;
-
- private ENTRY entry;
-
- private FEED feed;
-
- /**
- * {@inheritDoc }
- */
- @Override
- public String getTitle() {
- return title;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public void setTitle(final String title) {
- this.title = title;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public String getRel() {
- return rel;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public void setRel(final String rel) {
- this.rel = rel;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public String getHref() {
- return href;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public void setHref(final String href) {
- this.href = href;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public String getType() {
- return type;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public void setType(final String type) {
- this.type = type;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public Entry getInlineEntry() {
- return entry;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- @SuppressWarnings("unchecked")
- public void setInlineEntry(final Entry entry) {
- this.entry = (ENTRY) entry;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public Feed getInlineFeed() {
- return feed;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- @SuppressWarnings("unchecked")
- public void setInlineFeed(final Feed feed) {
- this.feed = (FEED) feed;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractODataBinder.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractODataBinder.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractODataBinder.java
deleted file mode 100644
index 161c988..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractODataBinder.java
+++ /dev/null
@@ -1,608 +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 com.msopentech.odatajclient.engine.data.impl;
-
-import com.msopentech.odatajclient.engine.client.ODataClient;
-import com.msopentech.odatajclient.engine.data.Entry;
-import com.msopentech.odatajclient.engine.data.Feed;
-import com.msopentech.odatajclient.engine.data.LinkCollection;
-import com.msopentech.odatajclient.engine.data.Link;
-import com.msopentech.odatajclient.engine.data.ODataBinder;
-import com.msopentech.odatajclient.engine.data.ODataCollectionValue;
-import com.msopentech.odatajclient.engine.data.ODataComplexValue;
-import com.msopentech.odatajclient.engine.data.ODataEntity;
-import com.msopentech.odatajclient.engine.data.ODataEntitySet;
-import com.msopentech.odatajclient.engine.data.ODataGeospatialValue;
-import com.msopentech.odatajclient.engine.data.ODataInlineEntity;
-import com.msopentech.odatajclient.engine.data.ODataInlineEntitySet;
-import com.msopentech.odatajclient.engine.data.ODataLink;
-import com.msopentech.odatajclient.engine.data.ODataLinkCollection;
-import com.msopentech.odatajclient.engine.data.ODataOperation;
-import com.msopentech.odatajclient.engine.data.ODataPrimitiveValue;
-import com.msopentech.odatajclient.engine.data.ODataProperty;
-import com.msopentech.odatajclient.engine.data.ODataProperty.PropertyType;
-import com.msopentech.odatajclient.engine.data.ODataServiceDocument;
-import com.msopentech.odatajclient.engine.data.ODataValue;
-import com.msopentech.odatajclient.engine.data.ResourceFactory;
-import com.msopentech.odatajclient.engine.data.ServiceDocument;
-import com.msopentech.odatajclient.engine.data.ServiceDocumentElement;
-import com.msopentech.odatajclient.engine.metadata.EdmType;
-import com.msopentech.odatajclient.engine.utils.ODataConstants;
-import com.msopentech.odatajclient.engine.utils.ODataVersion;
-import com.msopentech.odatajclient.engine.utils.URIUtils;
-import com.msopentech.odatajclient.engine.utils.XMLUtils;
-import java.io.StringWriter;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.ParserConfigurationException;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-public abstract class AbstractODataBinder implements ODataBinder {
-
- private static final long serialVersionUID = 454285889193689536L;
-
- /**
- * Logger.
- */
- protected final Logger LOG = LoggerFactory.getLogger(AbstractODataBinder.class);
-
- protected final ODataClient client;
-
- protected AbstractODataBinder(final ODataClient client) {
- this.client = client;
- }
-
- protected Element newEntryContent() {
- Element properties = null;
- try {
- final DocumentBuilder builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
- final Document doc = builder.newDocument();
- properties = doc.createElement(ODataConstants.ELEM_PROPERTIES);
- properties.setAttribute(ODataConstants.XMLNS_METADATA,
- client.getWorkingVersion().getNamespaceMap().get(ODataVersion.NS_METADATA));
- properties.setAttribute(ODataConstants.XMLNS_DATASERVICES,
- client.getWorkingVersion().getNamespaceMap().get(ODataVersion.NS_DATASERVICES));
- properties.setAttribute(ODataConstants.XMLNS_GML, ODataConstants.NS_GML);
- properties.setAttribute(ODataConstants.XMLNS_GEORSS, ODataConstants.NS_GEORSS);
- } catch (ParserConfigurationException e) {
- LOG.error("Failure building entry content", e);
- }
-
- return properties;
- }
-
- @Override
- public <T extends Feed> T getFeed(final ODataEntitySet feed, final Class<T> reference) {
- final T feedResource = ResourceFactory.newFeed(reference);
-
- final List<Entry> entries = new ArrayList<Entry>();
- feedResource.setEntries(entries);
-
- final URI next = feed.getNext();
- if (next != null) {
- feedResource.setNext(next);
- }
-
- for (ODataEntity entity : feed.getEntities()) {
- entries.add(getEntry(entity, ResourceFactory.entryClassForFeed(reference)));
- }
-
- feedResource.setEntries(entries);
-
- return feedResource;
- }
-
- @Override
- public <T extends Entry> T getEntry(final ODataEntity entity, final Class<T> reference) {
- return getEntry(entity, reference, true);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public <T extends Entry> T getEntry(final ODataEntity entity, final Class<T> reference,
- final boolean setType) {
-
- final T entry = ResourceFactory.newEntry(reference);
- entry.setType(entity.getName());
-
- // -------------------------------------------------------------
- // Add edit and self link
- // -------------------------------------------------------------
- final URI editLink = entity.getEditLink();
- if (editLink != null) {
- final Link entryEditLink = ResourceFactory.newLinkForEntry(reference);
- entryEditLink.setTitle(entity.getName());
- entryEditLink.setHref(editLink.toASCIIString());
- entryEditLink.setRel(ODataConstants.EDIT_LINK_REL);
- entry.setEditLink(entryEditLink);
- }
-
- if (entity.isReadOnly()) {
- final Link entrySelfLink = ResourceFactory.newLinkForEntry(reference);
- entrySelfLink.setTitle(entity.getName());
- entrySelfLink.setHref(entity.getLink().toASCIIString());
- entrySelfLink.setRel(ODataConstants.SELF_LINK_REL);
- entry.setSelfLink(entrySelfLink);
- }
- // -------------------------------------------------------------
-
- // -------------------------------------------------------------
- // Append navigation links (handling inline entry / feed as well)
- // -------------------------------------------------------------
- // handle navigation links
- for (ODataLink link : entity.getNavigationLinks()) {
- // append link
- LOG.debug("Append navigation link\n{}", link);
- entry.addNavigationLink(getLinkResource(link, ResourceFactory.linkClassForEntry(reference)));
- }
- // -------------------------------------------------------------
-
- // -------------------------------------------------------------
- // Append edit-media links
- // -------------------------------------------------------------
- for (ODataLink link : entity.getEditMediaLinks()) {
- LOG.debug("Append edit-media link\n{}", link);
- entry.addMediaEditLink(getLinkResource(link, ResourceFactory.linkClassForEntry(reference)));
- }
- // -------------------------------------------------------------
-
- // -------------------------------------------------------------
- // Append association links
- // -------------------------------------------------------------
- for (ODataLink link : entity.getAssociationLinks()) {
- LOG.debug("Append association link\n{}", link);
- entry.addAssociationLink(getLinkResource(link, ResourceFactory.linkClassForEntry(reference)));
- }
- // -------------------------------------------------------------
-
- final Element content = newEntryContent();
- if (entity.isMediaEntity()) {
- entry.setMediaEntryProperties(content);
- entry.setMediaContentSource(entity.getMediaContentSource());
- entry.setMediaContentType(entity.getMediaContentType());
- } else {
- entry.setContent(content);
- }
-
- for (ODataProperty prop : entity.getProperties()) {
- content.appendChild(toDOMElement(prop, content.getOwnerDocument(), setType));
- }
-
- return entry;
- }
-
- @Override
- public Element toDOMElement(final ODataProperty prop) {
- try {
- return toDOMElement(prop, XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder().newDocument(), true);
- } catch (ParserConfigurationException e) {
- LOG.error("Error retrieving property DOM", e);
- throw new IllegalArgumentException(e);
- }
- }
-
- @Override
- public ODataLinkCollection getLinkCollection(final LinkCollection linkCollection) {
- final ODataLinkCollection collection = new ODataLinkCollection(linkCollection.getNext());
- collection.setLinks(linkCollection.getLinks());
- return collection;
- }
-
- @Override
- public ODataServiceDocument getODataServiceDocument(final ServiceDocument resource) {
- final ODataServiceDocument serviceDocument = new ODataServiceDocument();
-
- for (ServiceDocumentElement entitySet : resource.getEntitySets()) {
- // handles V3 JSON format oddities, where title is not contained
- serviceDocument.getEntitySets().put(StringUtils.isBlank(entitySet.getTitle())
- ? entitySet.getName() : entitySet.getTitle(),
- URIUtils.getURI(resource.getBaseURI(), entitySet.getHref()));
- }
-
- return serviceDocument;
- }
-
- @Override
- public ODataEntitySet getODataEntitySet(final Feed resource) {
- return getODataEntitySet(resource, null);
- }
-
- @Override
- public ODataEntitySet getODataEntitySet(final Feed resource, final URI defaultBaseURI) {
- if (LOG.isDebugEnabled()) {
- final StringWriter writer = new StringWriter();
- client.getSerializer().feed(resource, writer);
- writer.flush();
- LOG.debug("FeedResource -> ODataEntitySet:\n{}", writer.toString());
- }
-
- final URI base = defaultBaseURI == null ? resource.getBaseURI() : defaultBaseURI;
-
- final URI next = resource.getNext();
-
- final ODataEntitySet entitySet = next == null
- ? client.getObjectFactory().newEntitySet()
- : client.getObjectFactory().newEntitySet(URIUtils.getURI(base, next.toASCIIString()));
-
- if (resource.getCount() != null) {
- entitySet.setCount(resource.getCount());
- }
-
- for (Entry entryResource : resource.getEntries()) {
- entitySet.addEntity(getODataEntity(entryResource));
- }
-
- return entitySet;
- }
-
- @Override
- public ODataEntity getODataEntity(final Entry resource) {
- return getODataEntity(resource, null);
- }
-
- @Override
- public ODataEntity getODataEntity(final Entry resource, final URI defaultBaseURI) {
- if (LOG.isDebugEnabled()) {
- final StringWriter writer = new StringWriter();
- client.getSerializer().entry(resource, writer);
- writer.flush();
- LOG.debug("EntryResource -> ODataEntity:\n{}", writer.toString());
- }
-
- final URI base = defaultBaseURI == null ? resource.getBaseURI() : defaultBaseURI;
-
- final ODataEntity entity = resource.getSelfLink() == null
- ? client.getObjectFactory().newEntity(resource.getType())
- : client.getObjectFactory().newEntity(resource.getType(),
- URIUtils.getURI(base, resource.getSelfLink().getHref()));
-
- if (StringUtils.isNotBlank(resource.getETag())) {
- entity.setETag(resource.getETag());
- }
-
- if (resource.getEditLink() != null) {
- entity.setEditLink(URIUtils.getURI(base, resource.getEditLink().getHref()));
- }
-
- for (Link link : resource.getAssociationLinks()) {
- entity.addLink(client.getObjectFactory().newAssociationLink(link.getTitle(), base, link.getHref()));
- }
-
- for (Link link : resource.getNavigationLinks()) {
- final Entry inlineEntry = link.getInlineEntry();
- final Feed inlineFeed = link.getInlineFeed();
-
- if (inlineEntry == null && inlineFeed == null) {
- entity.addLink(
- client.getObjectFactory().newEntityNavigationLink(link.getTitle(), base, link.getHref()));
- } else if (inlineFeed == null) {
- entity.addLink(client.getObjectFactory().newInlineEntity(
- link.getTitle(), base, link.getHref(),
- getODataEntity(inlineEntry,
- inlineEntry.getBaseURI() == null ? base : inlineEntry.getBaseURI())));
- } else {
- entity.addLink(client.getObjectFactory().newInlineEntitySet(
- link.getTitle(), base, link.getHref(),
- getODataEntitySet(inlineFeed,
- inlineFeed.getBaseURI() == null ? base : inlineFeed.getBaseURI())));
- }
- }
-
- for (Link link : resource.getMediaEditLinks()) {
- entity.addLink(client.getObjectFactory().newMediaEditLink(link.getTitle(), base, link.getHref()));
- }
-
- for (ODataOperation operation : resource.getOperations()) {
- operation.setTarget(URIUtils.getURI(base, operation.getTarget()));
- entity.addOperation(operation);
- }
-
- final Element content;
- if (resource.isMediaEntry()) {
- entity.setMediaEntity(true);
- entity.setMediaContentSource(resource.getMediaContentSource());
- entity.setMediaContentType(resource.getMediaContentType());
- content = resource.getMediaEntryProperties();
- } else {
- content = resource.getContent();
- }
- if (content != null) {
- for (Node property : XMLUtils.getChildNodes(content, Node.ELEMENT_NODE)) {
- try {
- entity.addProperty(getProperty((Element) property));
- } catch (IllegalArgumentException e) {
- LOG.warn("Failure retrieving EdmType for {}", property.getTextContent(), e);
- }
- }
- }
-
- return entity;
- }
-
- @Override
- public <T extends Link> T getLinkResource(final ODataLink link, final Class<T> reference) {
- final T linkResource = ResourceFactory.newLink(reference);
- linkResource.setRel(link.getRel());
- linkResource.setTitle(link.getName());
- linkResource.setHref(link.getLink() == null ? null : link.getLink().toASCIIString());
- linkResource.setType(link.getType().toString());
-
- if (link instanceof ODataInlineEntity) {
- // append inline entity
- final ODataEntity inlineEntity = ((ODataInlineEntity) link).getEntity();
- LOG.debug("Append in-line entity\n{}", inlineEntity);
-
- linkResource.setInlineEntry(getEntry(inlineEntity, ResourceFactory.entryClassForLink(reference)));
- } else if (link instanceof ODataInlineEntitySet) {
- // append inline feed
- final ODataEntitySet InlineFeed = ((ODataInlineEntitySet) link).getEntitySet();
- LOG.debug("Append in-line feed\n{}", InlineFeed);
-
- linkResource.setInlineFeed(getFeed(InlineFeed, ResourceFactory.feedClassForLink(reference)));
- }
-
- return linkResource;
- }
-
- @Override
- public ODataProperty getProperty(final Element property) {
- final ODataProperty res;
-
- final Node nullNode = property.getAttributes().getNamedItem(ODataConstants.ATTR_NULL);
-
- if (nullNode == null) {
- final EdmType edmType = StringUtils.isBlank(property.getAttribute(ODataConstants.ATTR_M_TYPE))
- ? null
- : newEdmType(property.getAttribute(ODataConstants.ATTR_M_TYPE));
-
- final PropertyType propType = edmType == null
- ? guessPropertyType(property)
- : edmType.isCollection()
- ? PropertyType.COLLECTION
- : edmType.isSimpleType()
- ? PropertyType.PRIMITIVE
- : PropertyType.COMPLEX;
-
- switch (propType) {
- case COLLECTION:
- res = fromCollectionPropertyElement(property, edmType);
- break;
-
- case COMPLEX:
- res = fromComplexPropertyElement(property, edmType);
- break;
-
- case PRIMITIVE:
- res = fromPrimitivePropertyElement(property, edmType);
- break;
-
- case EMPTY:
- default:
- res = client.getObjectFactory().newPrimitiveProperty(XMLUtils.getSimpleName(property), null);
- }
- } else {
- res = client.getObjectFactory().newPrimitiveProperty(XMLUtils.getSimpleName(property), null);
- }
-
- return res;
- }
-
- protected PropertyType guessPropertyType(final Element property) {
- PropertyType res = null;
-
- if (property.hasChildNodes()) {
- final NodeList children = property.getChildNodes();
-
- for (int i = 0; res == null && i < children.getLength(); i++) {
- final Node child = children.item(i);
-
- if (child.getNodeType() == Node.ELEMENT_NODE
- && !child.getNodeName().startsWith(ODataConstants.PREFIX_GML)) {
-
- res = ODataConstants.ELEM_ELEMENT.equals(XMLUtils.getSimpleName(child))
- ? PropertyType.COLLECTION
- : PropertyType.COMPLEX;
- }
- }
- } else {
- res = PropertyType.EMPTY;
- }
-
- if (res == null) {
- res = PropertyType.PRIMITIVE;
- }
-
- return res;
- }
-
- protected Element toDOMElement(final ODataProperty prop, final Document doc, final boolean setType) {
- final Element element;
-
- if (prop.hasNullValue()) {
- // null property handling
- element = toNullPropertyElement(prop, doc);
- } else if (prop.hasPrimitiveValue()) {
- // primitive property handling
- element = toPrimitivePropertyElement(prop, doc, setType);
- } else if (prop.hasCollectionValue()) {
- // collection property handling
- element = toCollectionPropertyElement(prop, doc, setType);
- } else {
- // complex property handling
- element = toComplexPropertyElement(prop, doc, setType);
- }
-
- element.setAttribute(ODataConstants.XMLNS_METADATA,
- client.getWorkingVersion().getNamespaceMap().get(ODataVersion.NS_METADATA));
- element.setAttribute(ODataConstants.XMLNS_DATASERVICES,
- client.getWorkingVersion().getNamespaceMap().get(ODataVersion.NS_DATASERVICES));
- element.setAttribute(ODataConstants.XMLNS_GML, ODataConstants.NS_GML);
- element.setAttribute(ODataConstants.XMLNS_GEORSS, ODataConstants.NS_GEORSS);
-
- return element;
- }
-
- protected Element toNullPropertyElement(final ODataProperty prop, final Document doc) {
- final Element element = doc.createElement(ODataConstants.PREFIX_DATASERVICES + prop.getName());
- element.setAttribute(ODataConstants.ATTR_NULL, Boolean.toString(true));
- return element;
- }
-
- protected Element toPrimitivePropertyElement(
- final ODataProperty prop, final Document doc, final boolean setType) {
-
- return toPrimitivePropertyElement(prop.getName(), prop.getPrimitiveValue(), doc, setType);
- }
-
- protected Element toPrimitivePropertyElement(
- final String name, final ODataPrimitiveValue value, final Document doc, final boolean setType) {
-
- final Element element = doc.createElement(ODataConstants.PREFIX_DATASERVICES + name);
- if (setType) {
- element.setAttribute(ODataConstants.ATTR_M_TYPE, value.getTypeName());
- }
-
- if (value instanceof ODataGeospatialValue) {
- element.appendChild(doc.importNode(((ODataGeospatialValue) value).toTree(), true));
- } else {
- element.setTextContent(value.toString());
- }
-
- return element;
- }
-
- protected Element toCollectionPropertyElement(
- final ODataProperty prop, final Document doc, final boolean setType) {
-
- if (!prop.hasCollectionValue()) {
- throw new IllegalArgumentException("Invalid property value type "
- + prop.getValue().getClass().getSimpleName());
- }
-
- final ODataCollectionValue value = prop.getCollectionValue();
-
- final Element element = doc.createElement(ODataConstants.PREFIX_DATASERVICES + prop.getName());
- if (value.getTypeName() != null && setType) {
- element.setAttribute(ODataConstants.ATTR_M_TYPE, value.getTypeName());
- }
-
- for (ODataValue el : value) {
- if (el.isPrimitive()) {
- element.appendChild(
- toPrimitivePropertyElement(ODataConstants.ELEM_ELEMENT, el.asPrimitive(), doc, setType));
- } else {
- element.appendChild(
- toComplexPropertyElement(ODataConstants.ELEM_ELEMENT, el.asComplex(), doc, setType));
- }
- }
-
- return element;
- }
-
- protected Element toComplexPropertyElement(
- final ODataProperty prop, final Document doc, final boolean setType) {
-
- return toComplexPropertyElement(prop.getName(), prop.getComplexValue(), doc, setType);
- }
-
- protected Element toComplexPropertyElement(
- final String name, final ODataComplexValue value, final Document doc, final boolean setType) {
-
- final Element element = doc.createElement(ODataConstants.PREFIX_DATASERVICES + name);
- if (value.getTypeName() != null && setType) {
- element.setAttribute(ODataConstants.ATTR_M_TYPE, value.getTypeName());
- }
-
- for (ODataProperty field : value) {
- element.appendChild(toDOMElement(field, doc, true));
- }
- return element;
- }
-
- protected ODataPrimitiveValue fromPrimitiveValueElement(final Element prop, final EdmType edmType) {
- final ODataPrimitiveValue value;
- if (edmType != null && edmType.getSimpleType().isGeospatial()) {
- final Element geoProp = ODataConstants.PREFIX_GML.equals(prop.getPrefix())
- ? prop : (Element) XMLUtils.getChildNodes(prop, Node.ELEMENT_NODE).get(0);
- value = client.getGeospatialValueBuilder().
- setType(edmType.getSimpleType()).setTree(geoProp).build();
- } else {
- value = client.getPrimitiveValueBuilder().
- setType(edmType == null ? null : edmType.getSimpleType()).setText(prop.getTextContent()).build();
- }
- return value;
- }
-
- protected ODataProperty fromPrimitivePropertyElement(final Element prop, final EdmType edmType) {
- return client.getObjectFactory().newPrimitiveProperty(
- XMLUtils.getSimpleName(prop), fromPrimitiveValueElement(prop, edmType));
- }
-
- protected ODataComplexValue fromComplexValueElement(final Element prop, final EdmType edmType) {
- final ODataComplexValue value = new ODataComplexValue(edmType == null ? null : edmType.getTypeExpression());
-
- for (Node child : XMLUtils.getChildNodes(prop, Node.ELEMENT_NODE)) {
- value.add(getProperty((Element) child));
- }
-
- return value;
- }
-
- protected ODataProperty fromComplexPropertyElement(final Element prop, final EdmType edmType) {
- return client.getObjectFactory().newComplexProperty(XMLUtils.getSimpleName(prop),
- fromComplexValueElement(prop, edmType));
- }
-
- protected ODataProperty fromCollectionPropertyElement(final Element prop, final EdmType edmType) {
- final ODataCollectionValue value =
- new ODataCollectionValue(edmType == null ? null : edmType.getTypeExpression());
-
- final EdmType type = edmType == null ? null : newEdmType(edmType.getBaseType());
- final NodeList elements = prop.getChildNodes();
-
- for (int i = 0; i < elements.getLength(); i++) {
- if (elements.item(i).getNodeType() != Node.TEXT_NODE) {
- final Element child = (Element) elements.item(i);
-
- switch (guessPropertyType(child)) {
- case COMPLEX:
- value.add(fromComplexValueElement(child, type));
- break;
- case PRIMITIVE:
- value.add(fromPrimitiveValueElement(child, type));
- break;
- default:
- // do not add null or empty values
- }
- }
- }
-
- return client.getObjectFactory().newCollectionProperty(XMLUtils.getSimpleName(prop), value);
- }
-
- protected abstract EdmType newEdmType(String expression);
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractODataDeserializer.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractODataDeserializer.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractODataDeserializer.java
deleted file mode 100644
index 3a16e9c..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/data/impl/AbstractODataDeserializer.java
+++ /dev/null
@@ -1,204 +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 com.msopentech.odatajclient.engine.data.impl;
-
-import com.fasterxml.aalto.stax.InputFactoryImpl;
-import com.fasterxml.aalto.stax.OutputFactoryImpl;
-import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
-import com.fasterxml.jackson.dataformat.xml.XmlFactory;
-import com.fasterxml.jackson.dataformat.xml.XmlMapper;
-import com.msopentech.odatajclient.engine.client.ODataClient;
-import com.msopentech.odatajclient.engine.data.Entry;
-import com.msopentech.odatajclient.engine.data.Feed;
-import com.msopentech.odatajclient.engine.data.LinkCollection;
-import com.msopentech.odatajclient.engine.data.ODataDeserializer;
-import com.msopentech.odatajclient.engine.data.ODataError;
-import com.msopentech.odatajclient.engine.data.impl.v3.AtomDeserializer;
-import com.msopentech.odatajclient.engine.data.impl.v3.AtomEntry;
-import com.msopentech.odatajclient.engine.data.impl.v3.AtomFeed;
-import com.msopentech.odatajclient.engine.data.impl.v3.JSONFeed;
-import com.msopentech.odatajclient.engine.data.impl.v3.JSONLinkCollection;
-import com.msopentech.odatajclient.engine.data.impl.v3.JSONODataError;
-import com.msopentech.odatajclient.engine.data.impl.v3.JSONODataErrorBundle;
-import com.msopentech.odatajclient.engine.data.impl.v3.JSONProperty;
-import com.msopentech.odatajclient.engine.data.impl.v3.XMLLinkCollection;
-import com.msopentech.odatajclient.engine.data.impl.v3.XMLODataError;
-import com.msopentech.odatajclient.engine.format.ODataFormat;
-import com.msopentech.odatajclient.engine.utils.ODataConstants;
-import com.msopentech.odatajclient.engine.utils.XMLUtils;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-public abstract class AbstractODataDeserializer extends AbstractJacksonTool implements ODataDeserializer {
-
- private static final long serialVersionUID = -4244158979195609909L;
-
- private final AtomDeserializer atomDeserializer;
-
- public AbstractODataDeserializer(final ODataClient client) {
- super(client);
- this.atomDeserializer = new AtomDeserializer(client);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public <T extends Feed> T toFeed(final InputStream input, final Class<T> reference) {
- T entry;
-
- if (AtomFeed.class.equals(reference)) {
- entry = (T) toAtomFeed(input);
- } else {
- entry = (T) toJSONFeed(input);
- }
-
- return entry;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public <T extends Entry> T toEntry(final InputStream input, final Class<T> reference) {
- T entry;
-
- if (AtomEntry.class.equals(reference)) {
- entry = (T) toAtomEntry(input);
-
- } else {
- entry = (T) toJSONEntry(input);
- }
-
- return entry;
- }
-
- @Override
- public Element toPropertyDOM(final InputStream input, final ODataFormat format) {
- return format == ODataFormat.XML
- ? toPropertyDOMFromXML(input)
- : toPropertyDOMFromJSON(input);
- }
-
- @Override
- public LinkCollection toLinkCollection(final InputStream input, final ODataFormat format) {
- return format == ODataFormat.XML
- ? toLinkCollectionFromXML(input)
- : toLinkCollectionFromJSON(input);
- }
-
- @Override
- public ODataError toODataError(final InputStream input, final boolean isXML) {
- return isXML
- ? toODataErrorFromXML(input)
- : toODataErrorFromJSON(input);
- }
-
- @Override
- public Element toDOM(final InputStream input) {
- return XMLUtils.PARSER.deserialize(input);
- }
-
- /*
- * ------------------ Protected methods ------------------
- */
- protected AtomFeed toAtomFeed(final InputStream input) {
- try {
- return atomDeserializer.feed(toDOM(input));
- } catch (Exception e) {
- throw new IllegalArgumentException("While deserializing Atom feed", e);
- }
- }
-
- protected AtomEntry toAtomEntry(final InputStream input) {
- try {
- return atomDeserializer.entry(toDOM(input));
- } catch (Exception e) {
- throw new IllegalArgumentException("While deserializing Atom entry", e);
- }
- }
-
- protected JSONFeed toJSONFeed(final InputStream input) {
- try {
- return getObjectMapper().readValue(input, JSONFeed.class);
- } catch (IOException e) {
- throw new IllegalArgumentException("While deserializing JSON feed", e);
- }
- }
-
- protected abstract AbstractJSONEntry toJSONEntry(final InputStream input);
-
- protected Element toPropertyDOMFromXML(final InputStream input) {
- return toDOM(input);
- }
-
- protected Element toPropertyDOMFromJSON(final InputStream input) {
- try {
- return getObjectMapper().readValue(input, JSONProperty.class).getContent();
- } catch (IOException e) {
- throw new IllegalArgumentException("While deserializing JSON property", e);
- }
- }
-
- protected XMLLinkCollection toLinkCollectionFromXML(final InputStream input) {
- final Element root = toDOM(input);
-
- final NodeList uris = root.getOwnerDocument().getElementsByTagName(ODataConstants.ELEM_URI);
-
- final List<URI> links = new ArrayList<URI>();
- for (int i = 0; i < uris.getLength(); i++) {
- links.add(URI.create(uris.item(i).getTextContent()));
- }
-
- final NodeList next = root.getElementsByTagName(ODataConstants.NEXT_LINK_REL);
- final XMLLinkCollection linkCollection = next.getLength() > 0
- ? new XMLLinkCollection(URI.create(next.item(0).getTextContent()))
- : new XMLLinkCollection();
- linkCollection.setLinks(links);
-
- return linkCollection;
- }
-
- protected JSONLinkCollection toLinkCollectionFromJSON(final InputStream input) {
- try {
- return getObjectMapper().readValue(input, JSONLinkCollection.class);
- } catch (IOException e) {
- throw new IllegalArgumentException("While deserializing JSON $links", e);
- }
- }
-
- protected XMLODataError toODataErrorFromXML(final InputStream input) {
- try {
- final XmlMapper xmlMapper = new XmlMapper(
- new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule());
- return xmlMapper.readValue(input, XMLODataError.class);
- } catch (Exception e) {
- throw new IllegalArgumentException("While deserializing XML error", e);
- }
- }
-
- protected JSONODataError toODataErrorFromJSON(final InputStream input) {
- try {
- return getObjectMapper().readValue(input, JSONODataErrorBundle.class).getError();
- } catch (IOException e) {
- throw new IllegalArgumentException("While deserializing JSON error", e);
- }
- }
-}