You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by il...@apache.org on 2014/03/11 13:53:10 UTC
[08/11] [OLINGO-200] V3 (de)serializers + unit tests merged
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONErrorImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONErrorImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONErrorImpl.java
new file mode 100644
index 0000000..d0a19e1
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONErrorImpl.java
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.data;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.olingo.client.api.data.Error;
+
+/**
+ * This class represents an OData error returned as JSON.
+ */
+public class JSONErrorImpl extends AbstractPayloadObject implements Error {
+
+ private static final long serialVersionUID = -3476499168507242932L;
+
+ /**
+ * Error message.
+ */
+ public static class Message extends AbstractPayloadObject {
+
+ private static final long serialVersionUID = 2577818040815637859L;
+
+ private String lang;
+
+ private String value;
+
+ /**
+ * Gets language.
+ *
+ * @return language.
+ */
+ public String getLang() {
+ return lang;
+ }
+
+ /**
+ * Sets language.
+ *
+ * @param lang language.
+ */
+ public void setLang(final String lang) {
+ this.lang = lang;
+ }
+
+ /**
+ * Gets message.
+ *
+ * @return message.
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Sets message.
+ *
+ * @param value message.
+ */
+ public void setValue(final String value) {
+ this.value = value;
+ }
+ }
+
+ /**
+ * Inner error.
+ */
+ static class InnerError extends AbstractPayloadObject {
+
+ private static final long serialVersionUID = -3920947476143537640L;
+
+ private String message;
+
+ private String type;
+
+ private String stacktrace;
+
+ private InnerError internalexception;
+
+ /**
+ * Gets inner message.
+ *
+ * @return message.
+ */
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * Sets inner message.
+ *
+ * @param message message.
+ */
+ public void setMessage(final String message) {
+ this.message = message;
+ }
+
+ /**
+ * Gets type.
+ *
+ * @return type.
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * Sets type.
+ *
+ * @param type type.
+ */
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ /**
+ * Gets stack-trace.
+ *
+ * @return stack-trace.
+ */
+ public String getStacktrace() {
+ return stacktrace;
+ }
+
+ /**
+ * Sets stack-trace.
+ *
+ * @param stacktrace stack-trace.
+ */
+ public void setStacktrace(final String stacktrace) {
+ this.stacktrace = stacktrace;
+ }
+
+ public InnerError getInternalexception() {
+ return internalexception;
+ }
+
+ public void setInternalexception(final InnerError internalexception) {
+ this.internalexception = internalexception;
+ }
+ }
+
+ private String code;
+
+ @JsonProperty(value = "message")
+ private Message message;
+
+ @JsonProperty(value = "innererror", required = false)
+ private InnerError innererror;
+
+ /**
+ * {@inheritDoc }
+ */
+ @Override
+ public String getCode() {
+ return code;
+ }
+
+ /**
+ * Sets error code.
+ *
+ * @param code error code.
+ */
+ public void setCode(final String code) {
+ this.code = code;
+ }
+
+ /**
+ * {@inheritDoc }
+ */
+ @JsonIgnore
+ @Override
+ public String getMessageLang() {
+ return this.message == null ? null : this.message.getLang();
+ }
+
+ /**
+ * {@inheritDoc }
+ */
+ @JsonIgnore
+ @Override
+ public String getMessageValue() {
+ return this.message == null ? null : this.message.getValue();
+ }
+
+ /**
+ * Sets the value of the message property.
+ *
+ * @param value allowed object is {@link Error.Message }
+ *
+ */
+ public void setMessage(final Message value) {
+ this.message = value;
+ }
+
+ /**
+ * {@inheritDoc }
+ */
+ @JsonIgnore
+ @Override
+ public String getInnerErrorMessage() {
+ return this.innererror == null ? null : this.innererror.getMessage();
+ }
+
+ /**
+ * {@inheritDoc }
+ */
+ @JsonIgnore
+ @Override
+ public String getInnerErrorType() {
+ return this.innererror == null ? null : this.innererror.getType();
+ }
+
+ /**
+ * {@inheritDoc }
+ */
+ @JsonIgnore
+ @Override
+ public String getInnerErrorStacktrace() {
+ return this.innererror == null ? null : this.innererror.getStacktrace();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONFeedDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONFeedDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONFeedDeserializer.java
new file mode 100644
index 0000000..23dd23a
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONFeedDeserializer.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.data;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Iterator;
+import org.apache.olingo.client.api.ODataConstants;
+
+/**
+ * Reads JSON string into a feed.
+ * <br/>
+ * If metadata information is available, the corresponding entry fields and content will be populated.
+ */
+public class JSONFeedDeserializer extends ODataJacksonDeserializer<JSONFeedImpl> {
+
+ @Override
+ protected JSONFeedImpl doDeserialize(final JsonParser parser, final DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser);
+
+ final JSONFeedImpl feed = new JSONFeedImpl();
+
+ if (tree.hasNonNull(ODataConstants.JSON_METADATA)) {
+ feed.setMetadata(URI.create(tree.get(ODataConstants.JSON_METADATA).textValue()));
+ }
+ if (tree.hasNonNull("odata.count")) {
+ feed.setCount(tree.get("odata.count").asInt());
+ }
+ if (tree.hasNonNull("odata.nextLink")) {
+ feed.setNext(URI.create(tree.get("odata.nextLink").textValue()));
+ }
+
+ if (tree.hasNonNull(ODataConstants.JSON_VALUE)) {
+ for (final Iterator<JsonNode> itor = tree.get(ODataConstants.JSON_VALUE).iterator(); itor.hasNext();) {
+ feed.getEntries().add(itor.next().traverse(parser.getCodec()).readValueAs(JSONEntryImpl.class));
+ }
+ }
+
+ return feed;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONFeedImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONFeedImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONFeedImpl.java
new file mode 100644
index 0000000..ced3d09
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONFeedImpl.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.data;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.olingo.client.api.data.Entry;
+import org.apache.olingo.client.api.data.Feed;
+import org.apache.olingo.client.api.uri.SegmentType;
+
+/**
+ * List of entries, represented via JSON.
+ *
+ * @see JSONEntry
+ */
+@JsonDeserialize(using = JSONFeedDeserializer.class)
+public class JSONFeedImpl extends AbstractPayloadObject implements Feed {
+
+ private static final long serialVersionUID = -3576372289800799417L;
+
+ private URI metadata;
+
+ private Integer count;
+
+ private final List<Entry> entries = new ArrayList<Entry>();
+
+ private String next;
+
+ @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;
+ }
+
+ @Override
+ public Integer getCount() {
+ return count;
+ }
+
+ public void setCount(final Integer count) {
+ this.count = count;
+ }
+
+ @Override
+ public List<Entry> getEntries() {
+ return entries;
+ }
+
+ @Override
+ public void setNext(final URI next) {
+ this.next = next.toASCIIString();
+ }
+
+ @Override
+ public URI getNext() {
+ return next == null ? null : URI.create(next);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONLinkCollectionImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONLinkCollectionImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONLinkCollectionImpl.java
new file mode 100644
index 0000000..ea99940
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONLinkCollectionImpl.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.data;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.olingo.client.api.data.LinkCollection;
+
+/**
+ * Link from an entry, represented via JSON.
+ */
+public class JSONLinkCollectionImpl extends AbstractPayloadObject implements LinkCollection {
+
+ private static final long serialVersionUID = -5006368367235783907L;
+
+ /**
+ * JSON link URL representation.
+ */
+ static class JSONLinkURL extends AbstractPayloadObject {
+
+ private static final long serialVersionUID = 5365055617973271468L;
+
+ private URI url;
+
+ public URI getUrl() {
+ return url;
+ }
+
+ public void setUrl(final URI url) {
+ this.url = url;
+ }
+ }
+
+ @JsonProperty(value = "odata.metadata", required = false)
+ private URI metadata;
+
+ @JsonProperty(required = false)
+ private URI url;
+
+ @JsonProperty(value = "value", required = false)
+ private final List<JSONLinkURL> links = new ArrayList<JSONLinkURL>();
+
+ @JsonProperty(value = "odata.nextLink", required = false)
+ private String next;
+
+ /**
+ * Gets 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;
+ }
+
+ /**
+ * {@inheritDoc }
+ */
+ @JsonIgnore
+ @Override
+ public List<URI> getLinks() {
+ final List<URI> result = new ArrayList<URI>();
+
+ if (this.url == null) {
+ for (JSONLinkURL link : links) {
+ result.add(link.getUrl());
+ }
+ } else {
+ result.add(this.url);
+ }
+
+ return result;
+ }
+
+ /**
+ * {@inheritDoc }
+ */
+ @JsonIgnore
+ @Override
+ public void setNext(final URI next) {
+ this.next = next == null ? null : next.toASCIIString();
+ }
+
+ /**
+ * {@inheritDoc }
+ */
+ @JsonIgnore
+ @Override
+ public URI getNext() {
+ return next == null ? null : URI.create(next);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertyDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertyDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertyDeserializer.java
new file mode 100644
index 0000000..6451eab
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertyDeserializer.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.data;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.io.IOException;
+import java.net.URI;
+import java.util.List;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.client.api.ODataConstants;
+import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
+import org.apache.olingo.client.api.utils.XMLUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Parse JSON string into <tt>JSONProperty</tt>.
+ *
+ * @see JSONProperty
+ */
+public class JSONPropertyDeserializer extends ODataJacksonDeserializer<JSONPropertyImpl> {
+
+ @Override
+ protected JSONPropertyImpl doDeserialize(final JsonParser parser, final DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser);
+
+ final JSONPropertyImpl property = new JSONPropertyImpl();
+
+ if (tree.hasNonNull(ODataConstants.JSON_METADATA)) {
+ property.setMetadata(URI.create(tree.get(ODataConstants.JSON_METADATA).textValue()));
+ tree.remove(ODataConstants.JSON_METADATA);
+ }
+
+ try {
+ final DocumentBuilder builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
+ final Document document = builder.newDocument();
+
+ Element content = document.createElement(ODataConstants.ELEM_PROPERTY);
+
+ if (property.getMetadata() != null) {
+ final String metadataURI = property.getMetadata().toASCIIString();
+ final int dashIdx = metadataURI.lastIndexOf('#');
+ if (dashIdx != -1) {
+ content.setAttribute(ODataConstants.ATTR_M_TYPE, metadataURI.substring(dashIdx + 1));
+ }
+ }
+
+ JsonNode subtree = null;
+ if (tree.has(ODataConstants.JSON_VALUE)) {
+ if (tree.has(ODataConstants.JSON_TYPE)
+ && StringUtils.isBlank(content.getAttribute(ODataConstants.ATTR_M_TYPE))) {
+
+ content.setAttribute(ODataConstants.ATTR_M_TYPE, tree.get(ODataConstants.JSON_TYPE).asText());
+ }
+
+ final JsonNode value = tree.get(ODataConstants.JSON_VALUE);
+ if (value.isValueNode()) {
+ content.appendChild(document.createTextNode(value.asText()));
+ } else if (ODataJClientEdmPrimitiveType.isGeospatial(content.getAttribute(ODataConstants.ATTR_M_TYPE))) {
+ subtree = tree.objectNode();
+ ((ObjectNode) subtree).put(ODataConstants.JSON_VALUE, tree.get(ODataConstants.JSON_VALUE));
+ if (StringUtils.isNotBlank(content.getAttribute(ODataConstants.ATTR_M_TYPE))) {
+ ((ObjectNode) subtree).put(
+ ODataConstants.JSON_VALUE + "@" + ODataConstants.JSON_TYPE,
+ content.getAttribute(ODataConstants.ATTR_M_TYPE));
+ }
+ } else {
+ subtree = tree.get(ODataConstants.JSON_VALUE);
+ }
+ } else {
+ subtree = tree;
+ }
+
+ if (subtree != null) {
+ JSONDOMTreeUtils.buildSubtree(client, content, subtree);
+ }
+
+ final List<Node> children = XMLUtils.getChildNodes(content, Node.ELEMENT_NODE);
+ if (children.size() == 1) {
+ final Element value = (Element) children.iterator().next();
+ if (ODataConstants.JSON_VALUE.equals(XMLUtils.getSimpleName(value))) {
+ if (StringUtils.isNotBlank(content.getAttribute(ODataConstants.ATTR_M_TYPE))) {
+ value.setAttribute(ODataConstants.ATTR_M_TYPE, content.getAttribute(ODataConstants.ATTR_M_TYPE));
+ }
+ content = value;
+ }
+ }
+
+ property.setContent(content);
+ } catch (ParserConfigurationException e) {
+ throw new JsonParseException("Cannot build property", parser.getCurrentLocation(), e);
+ }
+
+ return property;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertyImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertyImpl.java
new file mode 100644
index 0000000..66b889a
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertyImpl.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.data;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import java.net.URI;
+import org.w3c.dom.Element;
+
+/**
+ * A single property (primitive, complex or collection) represented via JSON.
+ */
+@JsonSerialize(using = JSONPropertySerializer.class)
+@JsonDeserialize(using = JSONPropertyDeserializer.class)
+public class JSONPropertyImpl extends AbstractPayloadObject {
+
+ private static final long serialVersionUID = 553414431536637434L;
+
+ private URI metadata;
+
+ private Element content;
+
+ /**
+ * Gets metadata URI.
+ *
+ * @return metadata URI.
+ */
+ public URI getMetadata() {
+ return metadata;
+ }
+
+ /**
+ * Sets metadata URI.
+ *
+ * @param metadata metadata URI.
+ */
+ public void setMetadata(final URI metadata) {
+ this.metadata = metadata;
+ }
+
+ /**
+ * Gets content.
+ *
+ * @return content as DOM element.
+ */
+ public Element getContent() {
+ return content;
+ }
+
+ /**
+ * Sets content.
+ *
+ * @param content content as DOM element.
+ */
+ public void setContent(final Element content) {
+ this.content = content;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertySerializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertySerializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertySerializer.java
new file mode 100644
index 0000000..be272f1
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONPropertySerializer.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.data;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonLocation;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import java.io.IOException;
+import javax.xml.parsers.DocumentBuilder;
+import org.apache.olingo.client.api.ODataConstants;
+import org.apache.olingo.client.api.domain.ODataJClientEdmPrimitiveType;
+import org.apache.olingo.client.api.utils.XMLUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Writes out JSON string from <tt>JSONProperty</tt>.
+ *
+ * @see JSONProperty
+ */
+public class JSONPropertySerializer extends ODataJacksonSerializer<JSONPropertyImpl> {
+
+ @Override
+ public void doSerialize(final JSONPropertyImpl property, final JsonGenerator jgen, final SerializerProvider provider)
+ throws IOException, JsonProcessingException {
+
+ jgen.writeStartObject();
+
+ if (property.getMetadata() != null) {
+ jgen.writeStringField(ODataConstants.JSON_METADATA, property.getMetadata().toASCIIString());
+ }
+
+ final Element content = property.getContent();
+ if (XMLUtils.hasOnlyTextChildNodes(content)) {
+ jgen.writeStringField(ODataConstants.JSON_VALUE, content.getTextContent());
+ } else {
+ try {
+ final DocumentBuilder builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder();
+ final Document document = builder.newDocument();
+ final Element wrapper = document.createElement(ODataConstants.ELEM_PROPERTY);
+
+ if (XMLUtils.hasElementsChildNode(content)) {
+ wrapper.appendChild(document.renameNode(
+ document.importNode(content, true), null, ODataConstants.JSON_VALUE));
+
+ JSONDOMTreeUtils.writeSubtree(client, jgen, wrapper);
+ } else if (ODataJClientEdmPrimitiveType.isGeospatial(content.getAttribute(ODataConstants.ATTR_M_TYPE))) {
+ wrapper.appendChild(document.renameNode(
+ document.importNode(content, true), null, ODataConstants.JSON_VALUE));
+
+ JSONDOMTreeUtils.writeSubtree(client, jgen, wrapper, true);
+ } else {
+ JSONDOMTreeUtils.writeSubtree(client, jgen, content);
+ }
+ } catch (Exception e) {
+ throw new JsonParseException("Cannot serialize property", JsonLocation.NA, e);
+ }
+ }
+
+ jgen.writeEndObject();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/data/LinkImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/LinkImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/LinkImpl.java
new file mode 100644
index 0000000..9ba76dc
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/LinkImpl.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.data;
+
+import org.apache.olingo.client.api.data.Entry;
+import org.apache.olingo.client.api.data.Feed;
+import org.apache.olingo.client.api.data.Link;
+
+public class LinkImpl 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;
+
+ @Override
+ public String getTitle() {
+ return title;
+ }
+
+ @Override
+ public void setTitle(final String title) {
+ this.title = title;
+ }
+
+ @Override
+ public String getRel() {
+ return rel;
+ }
+
+ @Override
+ public void setRel(final String rel) {
+ this.rel = rel;
+ }
+
+ @Override
+ public String getHref() {
+ return href;
+ }
+
+ @Override
+ public void setHref(final String href) {
+ this.href = href;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ @Override
+ public Entry getInlineEntry() {
+ return entry;
+ }
+
+ @Override
+ public void setInlineEntry(final Entry entry) {
+ this.entry = entry;
+ }
+
+ @Override
+ public Feed getInlineFeed() {
+ return feed;
+ }
+
+ @Override
+ public void setInlineFeed(final Feed feed) {
+ this.feed = feed;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ODataEntitySetIterator.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ODataEntitySetIterator.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ODataEntitySetIterator.java
new file mode 100644
index 0000000..ad9d837
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ODataEntitySetIterator.java
@@ -0,0 +1,309 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.data;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.client.api.ODataClient;
+import org.apache.olingo.client.api.ODataConstants;
+import org.apache.olingo.client.api.data.Entry;
+import org.apache.olingo.client.api.domain.ODataEntity;
+import org.apache.olingo.client.api.domain.ODataEntitySet;
+import org.apache.olingo.client.api.format.ODataPubFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * OData entity set iterator class.
+ * <br/>
+ * <b>Please don't forget to call the <tt>close()>/<tt> method when not needed any more.</b>
+ */
+public class ODataEntitySetIterator implements Iterator<ODataEntity> {
+
+ /**
+ * Logger.
+ */
+ private static final Logger LOG = LoggerFactory.getLogger(ODataEntitySetIterator.class);
+
+ private static final long serialVersionUID = 9039605899821494025L;
+
+ private final ODataClient odataClient;
+
+ private final InputStream stream;
+
+ private final ODataPubFormat format;
+
+ private Entry cached;
+
+ private ODataEntitySet entitySet;
+
+ private final ByteArrayOutputStream osFeed;
+
+ private final String namespaces;
+
+ private boolean available = true;
+
+ /**
+ * Constructor.
+ *
+ * @param odataClient client instance getting this request
+ * @param stream source stream.
+ * @param format OData format.
+ */
+ public ODataEntitySetIterator(final ODataClient odataClient, final InputStream stream, final ODataPubFormat format) {
+ this.odataClient = odataClient;
+ this.stream = stream;
+ this.format = format;
+ this.osFeed = new ByteArrayOutputStream();
+
+ if (format == ODataPubFormat.ATOM) {
+ namespaces = getAllElementAttributes(stream, "feed", osFeed);
+ } else {
+ namespaces = null;
+ try {
+ if (consume(stream, "\"value\":", osFeed, true) >= 0) {
+ int c = 0;
+ while (c != '[' && (c = stream.read()) >= 0) {
+ osFeed.write(c);
+ }
+ }
+ } catch (IOException e) {
+ LOG.error("Error parsing feed", e);
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc }
+ */
+ @Override
+ public boolean hasNext() {
+ if (available && cached == null) {
+ if (format == ODataPubFormat.ATOM) {
+ cached = nextAtomEntryFromFeed(stream, osFeed, namespaces);
+ } else {
+ cached = nextJsonEntryFromFeed(stream, osFeed);
+ }
+
+ if (cached == null) {
+ available = false;
+ entitySet = odataClient.getReader().
+ readEntitySet(new ByteArrayInputStream(osFeed.toByteArray()), format);
+ close();
+ }
+ }
+
+ return available;
+ }
+
+ /**
+ * {@inheritDoc }
+ */
+ @Override
+ public ODataEntity next() {
+ if (hasNext()) {
+ final ODataEntity res = odataClient.getBinder().getODataEntity(cached);
+ cached = null;
+ return res;
+ }
+
+ throw new NoSuchElementException("No entity found");
+ }
+
+ /**
+ * Unsupported operation.
+ */
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("Operation not supported");
+ }
+
+ /**
+ * Closes the current iterator.
+ */
+ public void close() {
+ IOUtils.closeQuietly(stream);
+ IOUtils.closeQuietly(osFeed);
+ }
+
+ /**
+ * Gets the next link if exists.
+ *
+ * @return next link if exists; null otherwise.
+ */
+ public URI getNext() {
+ if (entitySet == null) {
+ throw new IllegalStateException("Iteration must be completed in order to retrieve the link for next page");
+ }
+ return entitySet.getNext();
+ }
+
+ private Entry nextJsonEntryFromFeed(final InputStream input, final OutputStream osFeed) {
+ final ByteArrayOutputStream entry = new ByteArrayOutputStream();
+
+ Entry jsonEntry = null;
+ try {
+ int c = 0;
+
+ boolean foundNewOne = false;
+
+ do {
+ c = input.read();
+ if (c == '{') {
+ entry.write(c);
+ c = -1;
+ foundNewOne = true;
+ }
+ if (c == ']') {
+ osFeed.write(c);
+ c = -1;
+ }
+ } while (c >= 0);
+
+ if (foundNewOne) {
+ int count = 1;
+ c = 0;
+
+ while (count > 0 && c >= 0) {
+ c = input.read();
+ if (c == '{') {
+ count++;
+ } else if (c == '}') {
+ count--;
+ }
+ entry.write(c);
+ }
+
+ if (c >= 0) {
+ jsonEntry = odataClient.getDeserializer().toEntry(
+ new ByteArrayInputStream(entry.toByteArray()), ODataPubFormat.JSON);
+ }
+ } else {
+ while ((c = input.read()) >= 0) {
+ osFeed.write(c);
+ }
+ }
+ } catch (Exception e) {
+ LOG.error("Error retrieving entities from EntitySet", e);
+ }
+
+ return jsonEntry;
+ }
+
+ /**
+ * De-Serializes a stream into an OData entity set.
+ *
+ * @param input stream to de-serialize.
+ * @param format de-serialize as AtomFeed or JSONFeed
+ * @return de-serialized entity set.
+ */
+ private Entry nextAtomEntryFromFeed(final InputStream input, final OutputStream osFeed, final String namespaces) {
+ final ByteArrayOutputStream entry = new ByteArrayOutputStream();
+
+ Entry atomEntry = null;
+
+ try {
+ if (consume(input, "<entry>", osFeed, false) >= 0) {
+ entry.write("<entry ".getBytes(ODataConstants.UTF8));
+ entry.write(namespaces.getBytes(ODataConstants.UTF8));
+ entry.write(">".getBytes(ODataConstants.UTF8));
+
+ if (consume(input, "</entry>", entry, true) >= 0) {
+ atomEntry = odataClient.getDeserializer().
+ toEntry(new ByteArrayInputStream(entry.toByteArray()), ODataPubFormat.ATOM);
+ }
+ }
+ } catch (Exception e) {
+ LOG.error("Error retrieving entities from EntitySet", e);
+ }
+
+ return atomEntry;
+ }
+
+ private String getAllElementAttributes(final InputStream input, final String name, final OutputStream os) {
+ final ByteArrayOutputStream attrs = new ByteArrayOutputStream();
+
+ String res;
+
+ try {
+ byte[] attrsDeclaration = null;
+
+ final String key = "<" + name + " ";
+ if (consume(input, key, os, true) >= 0 && consume(input, ">", attrs, false) >= 0) {
+ attrsDeclaration = attrs.toByteArray();
+ os.write(attrsDeclaration);
+ os.write('>');
+ }
+
+ res = attrsDeclaration == null
+ ? StringUtils.EMPTY
+ : new String(attrsDeclaration, ODataConstants.UTF8).trim();
+ } catch (Exception e) {
+ LOG.error("Error retrieving entities from EntitySet", e);
+ res = StringUtils.EMPTY;
+ }
+
+ return res.endsWith("/") ? res.substring(0, res.length() - 1) : res;
+ }
+
+ private int consume(
+ final InputStream input, final String end, final OutputStream os, final boolean includeEndKey)
+ throws IOException {
+
+ final char[] endKey = end.toCharArray();
+ final char[] endLowerKey = end.toLowerCase().toCharArray();
+ final char[] endUpperKey = end.toUpperCase().toCharArray();
+
+ int pos = 0;
+ int c = 0;
+ while (pos < endKey.length && (c = input.read()) >= 0) {
+ if (c == endLowerKey[pos] || c == endUpperKey[pos]) {
+ pos++;
+ if (includeEndKey && os != null) {
+ os.write(c);
+ }
+ } else if (pos > 0) {
+ if (!includeEndKey && os != null) {
+ for (int i = 0; i < pos; i++) {
+ os.write(endKey[i]);
+ }
+ }
+ if (os != null) {
+ os.write(c);
+ }
+ pos = 0;
+ } else {
+ if (os != null) {
+ os.write(c);
+ }
+ }
+ }
+
+ return c;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/data/OperationImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/OperationImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/OperationImpl.java
new file mode 100644
index 0000000..a981742
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/OperationImpl.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.data;
+
+import java.io.Serializable;
+import java.net.URI;
+import org.apache.olingo.client.api.data.Operation;
+
+/**
+ * Representation of an OData operation (legacy, action or function).
+ */
+public class OperationImpl extends AbstractPayloadObject implements Operation, Serializable {
+
+ private static final long serialVersionUID = -5784652334334645128L;
+
+ private String metadataAnchor;
+
+ private String title;
+
+ private URI target;
+
+ /**
+ * Gets metadata anchor.
+ *
+ * @return metadata anchor.
+ */
+ @Override
+ public String getMetadataAnchor() {
+ return metadataAnchor;
+ }
+
+ /**
+ * Sets metadata anchor.
+ *
+ * @param metadataAnchor metadata anchor.
+ */
+ @Override
+ public void setMetadataAnchor(final String metadataAnchor) {
+ this.metadataAnchor = metadataAnchor;
+ }
+
+ /**
+ * Gets title.
+ *
+ * @return title.
+ */
+ @Override
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * Sets title.
+ *
+ * @param title title.
+ */
+ @Override
+ public void setTitle(final String title) {
+ this.title = title;
+ }
+
+ /**
+ * Gets target.
+ *
+ * @return target.
+ */
+ @Override
+ public URI getTarget() {
+ return target;
+ }
+
+ /**
+ * Sets target.
+ *
+ * @param target target.
+ */
+ @Override
+ public void setTarget(final URI target) {
+ this.target = target;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLErrorImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLErrorImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLErrorImpl.java
new file mode 100644
index 0000000..3cc105f
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLErrorImpl.java
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.data;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
+import java.util.Map;
+import org.apache.olingo.client.api.data.Error;
+
+/**
+ * This class represents an OData error returned as JSON.
+ */
+public class XMLErrorImpl extends AbstractPayloadObject implements Error {
+
+ private static final long serialVersionUID = -3476499168507242932L;
+
+ @JacksonXmlText(false)
+ private String code;
+
+ @JsonProperty
+ private Message message;
+
+ @JsonProperty(required = false)
+ private InnerError innererror;
+
+ @Override
+ public String getCode() {
+ return code;
+ }
+
+ /**
+ * Sets error code.
+ *
+ * @param code error code.
+ */
+ public void setCode(final String code) {
+ this.code = code;
+ }
+
+ @JsonIgnore
+ @Override
+ public String getMessageLang() {
+ return this.message == null ? null : this.message.getLang();
+ }
+
+ @JsonIgnore
+ @Override
+ public String getMessageValue() {
+ return this.message == null ? null : this.message.getValue();
+ }
+
+ /**
+ * Sets the value of the message property.
+ *
+ * @param value allowed object is {@link Error.Message }
+ *
+ */
+ public void setMessage(final Message value) {
+ this.message = value;
+ }
+
+ @JsonIgnore
+ @Override
+ public String getInnerErrorMessage() {
+ return this.innererror == null ? null : this.innererror.getMessage().getValue();
+ }
+
+ @JsonIgnore
+ @Override
+ public String getInnerErrorType() {
+ return this.innererror == null ? null : this.innererror.getType().getValue();
+ }
+
+ @JsonIgnore
+ @Override
+ public String getInnerErrorStacktrace() {
+ return this.innererror == null ? null : this.innererror.getStacktrace().getValue();
+ }
+
+ static class TextChildContainer extends AbstractPayloadObject {
+
+ private static final long serialVersionUID = -8908394095210115904L;
+
+ public TextChildContainer() {
+ super();
+ }
+
+ public TextChildContainer(final String value) {
+ super();
+ this.value = value;
+ }
+
+ @JsonCreator
+ public TextChildContainer(final Map<String, Object> props) {
+ super();
+ this.value = (String) props.get("");
+ }
+
+ private String value;
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(final String value) {
+ this.value = value;
+ }
+ }
+
+ /**
+ * Error message.
+ */
+ public static class Message extends TextChildContainer {
+
+ private static final long serialVersionUID = 2577818040815637859L;
+
+ private String lang;
+
+ public Message() {
+ super();
+ }
+
+ @JsonCreator
+ public Message(final Map<String, Object> props) {
+ super(props);
+ this.lang = (String) props.get("lang");
+ }
+
+ /**
+ * Gets language.
+ *
+ * @return language.
+ */
+ public String getLang() {
+ return lang;
+ }
+
+ /**
+ * Sets language.
+ *
+ * @param lang language.
+ */
+ public void setLang(final String lang) {
+ this.lang = lang;
+ }
+ }
+
+ /**
+ * Inner error.
+ */
+ static class InnerError extends AbstractPayloadObject {
+
+ private static final long serialVersionUID = -3920947476143537640L;
+
+ private TextChildContainer message;
+
+ private TextChildContainer type;
+
+ private TextChildContainer stacktrace;
+
+ private InnerError internalexception;
+
+ public TextChildContainer getMessage() {
+ return message;
+ }
+
+ public void setMessage(final TextChildContainer message) {
+ this.message = message;
+ }
+
+ public TextChildContainer getType() {
+ return type;
+ }
+
+ public void setType(final TextChildContainer type) {
+ this.type = type;
+ }
+
+ public TextChildContainer getStacktrace() {
+ return stacktrace;
+ }
+
+ public void setStacktrace(final TextChildContainer stacktrace) {
+ this.stacktrace = stacktrace;
+ }
+
+ public InnerError getInternalexception() {
+ return internalexception;
+ }
+
+ public void setInternalexception(final InnerError internalexception) {
+ this.internalexception = internalexception;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLLinkCollectionImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLLinkCollectionImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLLinkCollectionImpl.java
new file mode 100644
index 0000000..05977ea
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLLinkCollectionImpl.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.data;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.olingo.client.api.data.LinkCollection;
+
+public class XMLLinkCollectionImpl implements LinkCollection {
+
+ private final List<URI> links = new ArrayList<URI>();
+
+ private URI next;
+
+ /**
+ * Constructor.
+ */
+ public XMLLinkCollectionImpl() {
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param next next page link.
+ */
+ public XMLLinkCollectionImpl(final URI next) {
+ this.next = next;
+ }
+
+ /**
+ * {@inheritDoc }
+ */
+ @Override
+ public List<URI> getLinks() {
+ return links;
+ }
+
+ /**
+ * {@inheritDoc }
+ */
+ @Override
+ public void setNext(final URI next) {
+ this.next = next;
+ }
+
+ /**
+ * {@inheritDoc }
+ */
+ @Override
+ public URI getNext() {
+ return next;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/AnnotationPropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/AnnotationPropertyImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/AnnotationPropertyImpl.java
deleted file mode 100644
index 3ee57a6..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/AnnotationPropertyImpl.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.client.core.deserializer;
-
-import org.apache.olingo.client.api.deserializer.AnnotationProperty;
-
-public class AnnotationPropertyImpl implements AnnotationProperty {
-
- private final String name;
-
- private final String value;
-
- public AnnotationPropertyImpl(final String name, final String value) {
- this.name = name;
- this.value = value;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getValue() {
- return value;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "AnnotationPropertyImpl [name=" + name + ", value=" + value + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/ComplexValueImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/ComplexValueImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/ComplexValueImpl.java
deleted file mode 100644
index eda1e34..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/ComplexValueImpl.java
+++ /dev/null
@@ -1,82 +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.deserializer;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.apache.olingo.client.api.deserializer.AnnotationProperty;
-import org.apache.olingo.client.api.deserializer.ComplexValue;
-import org.apache.olingo.client.api.deserializer.NavigationProperty;
-import org.apache.olingo.client.api.deserializer.StructuralProperty;
-import org.apache.olingo.client.api.deserializer.Value;
-
-public class ComplexValueImpl extends PropertyCollection implements ComplexValue {
-
- public ComplexValueImpl() {
- }
-
- public ComplexValueImpl(final Map<String, AnnotationProperty> annotationProperties,
- final Map<String, NavigationProperty> navigationProperties,
- final Map<String, StructuralProperty> structuralProperties) {
-
- super(annotationProperties, navigationProperties, structuralProperties);
- }
-
- @Override
- public Value getValue(final String name) {
- final StructuralProperty property = structuralProperties.get(name);
- if (property == null) {
- return null;
- }
- return property.getValue();
- }
-
- @Override
- public Map<String, AnnotationProperty> getAnnotationProperties() {
- return Collections.unmodifiableMap(annotationProperties);
- }
-
- @Override
- public Map<String, NavigationProperty> getNavigationProperties() {
- return Collections.unmodifiableMap(navigationProperties);
- }
-
- @Override
- public boolean isComplex() {
- return true;
- }
-
- @Override
- public Map<String, StructuralProperty> getContent() {
- return Collections.unmodifiableMap(structuralProperties);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public <T> T getContentAs(final T type) {
- return (T) getContent();
- }
-
- @Override
- public String toString() {
- return "ComplexValueImpl [annotations=" + annotationProperties + ", navigationProperties=" + navigationProperties
- + ", properties=" + structuralProperties + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/EntityImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/EntityImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/EntityImpl.java
deleted file mode 100644
index ac88bf3..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/EntityImpl.java
+++ /dev/null
@@ -1,126 +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.deserializer;
-
-import java.util.Map;
-
-import org.apache.olingo.client.api.deserializer.AnnotationProperty;
-import org.apache.olingo.client.api.deserializer.Entity;
-import org.apache.olingo.client.api.deserializer.NavigationProperty;
-import org.apache.olingo.client.api.deserializer.Property;
-import org.apache.olingo.client.api.deserializer.StructuralProperty;
-
-public class EntityImpl extends PropertyCollection implements Entity {
-
- public EntityImpl() {
- }
-
- public EntityImpl(final Map<String, AnnotationProperty> annotationProperties,
- final Map<String, NavigationProperty> navigationProperties,
- final Map<String, StructuralProperty> structuralProperties) {
-
- super(annotationProperties, navigationProperties, structuralProperties);
- }
-
- @Override
- public String getODataMetaDataEtag() {
- return getAnnotationValue("odata.metadataEtag");
- }
-
- @Override
- public String getODataType() {
- return getAnnotationValue("odata.type");
- }
-
- @Override
- public Long getODataCount() {
- return Long.valueOf(getAnnotationValue("odata.count"));
- }
-
- @Override
- public String getODataNextLink() {
- return getAnnotationValue("odata.nextLink");
- }
-
- @Override
- public String getODataDeltaLink() {
- return getAnnotationValue("odata.deltaLink");
- }
-
- @Override
- public String getODataReadLink() {
- return getAnnotationValue("odata.readLink");
- }
-
- @Override
- public String getODataContext() {
- return getAnnotationValue("odata.context");
- }
-
- @Override
- public String getODataId() {
- return getAnnotationValue("odata.id");
- }
-
- @Override
- public String getODataETag() {
- return getAnnotationValue("odata.etag");
- }
-
- @Override
- public String getODataEditLink() {
- return getAnnotationValue("odata.editLink");
- }
-
- @Override
- public Object getPropertyContent(final String name) {
- final StructuralProperty property = structuralProperties.get(name);
- if (property != null) {
- return property.getValue().getContent();
- }
- return null;
- }
-
- @Override
- public Property getProperty(final String name) {
- Property property = structuralProperties.get(name);
- if (property == null) {
- property = annotationProperties.get(name);
- }
- if (property == null) {
- property = navigationProperties.get(name);
- }
- return property;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public <T extends Property> T getProperty(final String name, final Class<T> clazz) {
- final Property property = getProperty(name);
- return (T) property;
- }
-
- private String getAnnotationValue(final String key) {
- final AnnotationProperty property = annotationProperties.get(key);
- if (property == null) {
- return null;
- }
- return property.getValue();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/EntitySetBuilder.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/EntitySetBuilder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/EntitySetBuilder.java
deleted file mode 100644
index 879622a..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/EntitySetBuilder.java
+++ /dev/null
@@ -1,72 +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.deserializer;
-
-import java.io.IOException;
-
-import org.apache.olingo.client.api.deserializer.EntitySet;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-public class EntitySetBuilder {
-
- private final JsonParser parser;
-
- public EntitySetBuilder(final JsonParser jp) {
- parser = jp;
- }
-
- public EntitySet buildEntitySet() throws JsonParseException, IOException {
- return parseEntitySet(parser);
- }
-
- private EntitySet parseEntitySet(final JsonParser jp) throws JsonParseException, IOException {
- final EntitySetImpl entitySet = new EntitySetImpl();
- boolean arrayStarted = false;
-
- while (jp.nextToken() != null) {
- final JsonToken token = jp.getCurrentToken();
- switch (token) {
- case START_ARRAY:
- final PropertyCollectionBuilder builder = new PropertyCollectionBuilder(jp, entitySet);
- entitySet.setPropertyCollectionBuilder(builder);
- arrayStarted = true;
- break;
-
- case START_OBJECT:
- if (arrayStarted) {
- return entitySet;
- }
- break;
-
- case VALUE_NUMBER_INT:
- case VALUE_STRING:
- entitySet.addAnnotation(jp.getCurrentName(), jp.getValueAsString());
- break;
-
- default:
- break;
- }
- }
-
- return entitySet;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/EntitySetImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/EntitySetImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/EntitySetImpl.java
deleted file mode 100644
index f344a21..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/EntitySetImpl.java
+++ /dev/null
@@ -1,120 +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.deserializer;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.olingo.client.api.deserializer.Entity;
-import org.apache.olingo.client.api.deserializer.EntitySet;
-
-import com.fasterxml.jackson.core.JsonParseException;
-
-public class EntitySetImpl implements EntitySet, Iterator<Entity> {
-
- private String odataContext;
-
- private Long odataCount;
-
- private String odataNextLink;
-
- private String odataDeltaLink;
-
- private List<Entity> entities = null;
-
- private PropertyCollectionBuilder propertyCollectionsBuilder;
-
- @Override
- public String getODataContext() {
- return odataContext;
- }
-
- @Override
- public Long getODataCount() {
- return odataCount;
- }
-
- @Override
- public String getODataNextLink() {
- return odataNextLink;
- }
-
- @Override
- public String getODataDeltaLink() {
- return odataDeltaLink;
- }
-
- public void addAnnotation(final String name, final String value) {
- if ("odata.context".equalsIgnoreCase(name)) {
- odataContext = value;
- } else if ("odata.deltaLink".equalsIgnoreCase(name)) {
- odataDeltaLink = value;
- } else if ("odata.count".equalsIgnoreCase(name)) {
- odataCount = Long.parseLong(value);
- } else if ("odata.nextLink".equalsIgnoreCase(name)) {
- odataNextLink = value;
- }
- }
-
- @Override
- public List<Entity> getEntities() {
- if (entities == null) {
- entities = new ArrayList<Entity>();
-
- while (propertyCollectionsBuilder.parseNext()) {
- entities.add(propertyCollectionsBuilder.buildEntity());
- }
- }
-
- return entities;
- }
-
- public void setPropertyCollectionBuilder(final PropertyCollectionBuilder builder) {
- propertyCollectionsBuilder = builder;
- }
-
- @Override
- public boolean hasNext() {
- try {
- return propertyCollectionsBuilder.hasNext();
- } catch (JsonParseException e) {
- } catch (IOException e) {
- }
- return false;
- }
-
- @Override
- public Entity next() {
- if (propertyCollectionsBuilder.parseNext()) {
- return propertyCollectionsBuilder.buildEntity();
- }
- return null;
- }
-
- @Override
- public void remove() {
- }
-
- @Override
- public Iterator<Entity> iterator() {
- return this;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/JsonReader.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/JsonReader.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/JsonReader.java
deleted file mode 100644
index 105065c..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/JsonReader.java
+++ /dev/null
@@ -1,89 +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.deserializer;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map;
-
-import org.apache.olingo.client.api.deserializer.ClientException;
-import org.apache.olingo.client.api.deserializer.Entity;
-import org.apache.olingo.client.api.deserializer.EntitySet;
-import org.apache.olingo.client.api.deserializer.Property;
-import org.apache.olingo.client.api.deserializer.Reader;
-import org.apache.olingo.client.api.deserializer.StructuralProperty;
-
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonParser;
-
-public class JsonReader implements Reader {
-
- @Override
- public EntitySet readEntitySet(final InputStream in) throws ClientException {
-
- final JsonFactory jsonFactory = new JsonFactory();
- // or, for data binding, org.codehaus.jackson.mapper.MappingJsonFactory
- try {
- JsonParser jp = jsonFactory.createParser(in);
- EntitySetBuilder entitySet = new EntitySetBuilder(jp);
- return entitySet.buildEntitySet();
- } catch (JsonParseException e) {
- throw new ClientException("JSON Parsing failed.", e);
- } catch (IOException e) {
- throw new ClientException("JSON Parsing failed.", e);
- }
- }
-
- @Override
- public Entity readEntity(final InputStream in) throws ClientException {
- Entity entity = null;
-
- final JsonFactory jsonFactory = new JsonFactory();
- // or, for data binding, org.codehaus.jackson.mapper.MappingJsonFactory
- try {
- final JsonParser jp = jsonFactory.createParser(in);
- final PropertyCollectionBuilder builder = new PropertyCollectionBuilder(jp);
- builder.parseNext();
- entity = builder.buildEntity();
- } catch (JsonParseException e) {
- throw new ClientException("JSON Parsing failed.", e);
- } catch (IOException e) {
- throw new ClientException("JSON Parsing failed.", e);
- }
-
- return entity;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.olingo.core.consumer.Reader#parseProperty(java.io.InputStream)
- */
- @Override
- public Property readProperty(final InputStream in) throws ClientException {
- final Entity entity = readEntity(in);
-
- final Map<String, StructuralProperty> properties = entity.getStructuralProperties();
- if (properties.size() == 1) {
- return properties.values().iterator().next();
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/NavigationPropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/NavigationPropertyImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/NavigationPropertyImpl.java
deleted file mode 100644
index 1c09a90..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/NavigationPropertyImpl.java
+++ /dev/null
@@ -1,89 +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.deserializer;
-
-import org.apache.olingo.client.api.deserializer.NavigationProperty;
-
-public class NavigationPropertyImpl implements NavigationProperty {
-
- private final String name;
-
- private String associationLink;
-
- private String navigationLink;
-
- public NavigationPropertyImpl(final String name) {
- this.name = parseName(name);
- }
-
- public NavigationPropertyImpl(final String name, final String link) {
- this(name);
- updateLink(name, link);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getAssociationLink() {
- return associationLink;
- }
-
- @Override
- public String getNavigationLink() {
- return navigationLink;
- }
-
- public void updateLink(final String name, final String link) {
- final String regexNavigationLink = ".*@odata.navigationLink$";
- final String regexAssociationLink = ".*@odata.associationLink$";
- if (name.matches(regexNavigationLink)) {
- navigationLink = link;
- } else if (name.matches(regexAssociationLink)) {
- associationLink = link;
- }
- }
-
- private String parseName(final String nameToParse) {
- final String[] split = nameToParse.split("@");
- if (split.length == 2) {
- return split[0];
- } else {
- throw new IllegalArgumentException("Got OData Navigation with unparseable format '"
- + nameToParse + "'.");
- }
- }
-
- public void updateLink(final NavigationProperty navigationProperty) {
- if (navigationProperty.getAssociationLink() != null) {
- associationLink = navigationProperty.getAssociationLink();
- }
- if (navigationProperty.getNavigationLink() != null) {
- navigationLink = navigationProperty.getNavigationLink();
- }
- }
-
- @Override
- public String toString() {
- return "NavigationPropertyImpl [name=" + name + ", associationLink=" + associationLink
- + ", navigationLink=" + navigationLink + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/PrimitiveValue.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/PrimitiveValue.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/PrimitiveValue.java
deleted file mode 100644
index c28bffa..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/PrimitiveValue.java
+++ /dev/null
@@ -1,51 +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.deserializer;
-
-import org.apache.olingo.client.api.deserializer.Value;
-
-public class PrimitiveValue implements Value {
-
- private final Object content;
-
- public PrimitiveValue(final Object content) {
- this.content = content;
- }
-
- @Override
- public boolean isComplex() {
- return false;
- }
-
- @Override
- public Object getContent() {
- return content;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public <T> T getContentAs(final T type) {
- return (T) content;
- }
-
- @Override
- public String toString() {
- return String.valueOf(content);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/PropertyCollection.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/PropertyCollection.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/PropertyCollection.java
deleted file mode 100644
index 8b10213..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/PropertyCollection.java
+++ /dev/null
@@ -1,96 +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.deserializer;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.client.api.deserializer.AnnotationProperty;
-import org.apache.olingo.client.api.deserializer.NavigationProperty;
-import org.apache.olingo.client.api.deserializer.Property;
-import org.apache.olingo.client.api.deserializer.StructuralProperty;
-
-abstract class PropertyCollection {
-
- protected Map<String, AnnotationProperty> annotationProperties = new HashMap<String, AnnotationProperty>();
-
- protected Map<String, NavigationProperty> navigationProperties = new HashMap<String, NavigationProperty>();
-
- protected Map<String, StructuralProperty> structuralProperties = new HashMap<String, StructuralProperty>();
-
- public PropertyCollection() {
- }
-
- protected PropertyCollection(final Map<String, AnnotationProperty> annotationProperties,
- final Map<String, NavigationProperty> navigationProperties,
- final Map<String, StructuralProperty> structuralProperties) {
-
- this.annotationProperties = annotationProperties;
- this.navigationProperties = navigationProperties;
- this.structuralProperties = structuralProperties;
- }
-
- public List<Property> getProperties() {
- final int initialCapacity = annotationProperties.size() + navigationProperties.size() + structuralProperties.size();
-
- final List<Property> properties = new ArrayList<Property>(initialCapacity);
- properties.addAll(annotationProperties.values());
- properties.addAll(navigationProperties.values());
- properties.addAll(structuralProperties.values());
-
- return properties;
- }
-
- public Map<String, AnnotationProperty> getAnnotationProperties() {
- return Collections.unmodifiableMap(annotationProperties);
- }
-
- public Map<String, NavigationProperty> getNavigationProperties() {
- return Collections.unmodifiableMap(navigationProperties);
- }
-
- public Map<String, StructuralProperty> getStructuralProperties() {
- return Collections.unmodifiableMap(structuralProperties);
- }
-
- public void addProperty(final Property property) {
- if (property == null) {
- throw new IllegalArgumentException("Property parameter MUST NOT be NULL.");
- }
-
- if (property instanceof NavigationPropertyImpl) {
- final NavigationPropertyImpl navProperty = (NavigationPropertyImpl) navigationProperties.get(property.getName());
- if (navProperty == null) {
- navigationProperties.put(property.getName(), (NavigationPropertyImpl) property);
- } else {
- final NavigationProperty temp = (NavigationProperty) property;
- navProperty.updateLink(temp);
- }
- } else if (property instanceof AnnotationPropertyImpl) {
- annotationProperties.put(property.getName(), (AnnotationPropertyImpl) property);
- } else if (property instanceof StructuralProperty) {
- structuralProperties.put(property.getName(), (StructuralProperty) property);
- } else {
- throw new IllegalArgumentException("Unknown class '" + property.getClass() + "'.");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/78c3eaa4/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/PropertyCollectionBuilder.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/PropertyCollectionBuilder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/PropertyCollectionBuilder.java
deleted file mode 100644
index 7643e49..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/deserializer/PropertyCollectionBuilder.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.client.core.deserializer;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.olingo.client.api.deserializer.AnnotationProperty;
-import org.apache.olingo.client.api.deserializer.ComplexValue;
-import org.apache.olingo.client.api.deserializer.Entity;
-import org.apache.olingo.client.api.deserializer.NavigationProperty;
-import org.apache.olingo.client.api.deserializer.Property;
-import org.apache.olingo.client.api.deserializer.StructuralProperty;
-import org.apache.olingo.client.api.deserializer.Value;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class PropertyCollectionBuilder extends PropertyCollection {
-
- private static final Logger LOG = LoggerFactory.getLogger(PropertyCollectionBuilder.class);
-
- private JsonParser parser;
-
- private EntitySetImpl enclosingEntitySet;
-
- private PropertyCollectionBuilder next = null;
-
- public PropertyCollectionBuilder(final JsonParser parser) {
- this.parser = parser;
- }
-
- private PropertyCollectionBuilder() {
- }
-
- public PropertyCollectionBuilder(final JsonParser jp, final EntitySetImpl entitySet) {
- this(jp);
- enclosingEntitySet = entitySet;
- }
-
- public Entity buildEntity() {
- final Entity entity = new EntityImpl(annotationProperties, navigationProperties, structuralProperties);
- resetProperties();
- return entity;
- }
-
- public ComplexValue buildComplexValue() {
- final ComplexValue value = new ComplexValueImpl(annotationProperties, navigationProperties, structuralProperties);
- resetProperties();
- return value;
- }
-
- private void resetProperties() {
- annotationProperties = new HashMap<String, AnnotationProperty>();
- navigationProperties = new HashMap<String, NavigationProperty>();
- structuralProperties = new HashMap<String, StructuralProperty>();
- }
-
- public boolean hasNext() throws JsonParseException, IOException {
- if (parser.isClosed()) {
- return false;
- }
- next = parseNextObject(parser, this);
- return (next != null);
- }
-
- public boolean parseNext() {
- try {
- if (hasNext()) {
- if (next != null) {
- return true;
- }
-
- if (next == null) {
- parser.close();
- return false;
- }
- return true;
- }
- } catch (JsonParseException e) {
- LOG.error("While parsing", e);
- } catch (IOException e) {
- LOG.error("While parsing", e);
- }
- return false;
-
- }
-
- /**
- *
- * @param jp
- * @param builder
- * @return
- * @throws IOException
- * @throws JsonParseException
- */
- private PropertyCollectionBuilder parseNextObject(final JsonParser jp, final PropertyCollectionBuilder builder)
- throws JsonParseException, IOException {
-
- boolean endReached = readToStartObjectOrEnd(jp);
- if (endReached) {
- return null;
- }
-
- //
- String currentFieldName = null;
- List<Value> values = null;
-
- while (jp.nextToken() != null) {
- final JsonToken token = jp.getCurrentToken();
- switch (token) {
- case START_OBJECT:
- if (currentFieldName != null) {
- final ComplexValue cvp = parseNextObject(jp, new PropertyCollectionBuilder()).buildComplexValue();
- if (values == null) {
- builder.addProperty(new StructuralPropertyImpl(currentFieldName, cvp));
- } else {
- values.add(cvp);
- }
- }
- break;
- case END_OBJECT:
- return builder;
- case START_ARRAY:
- values = new ArrayList<Value>();
- break;
- case END_ARRAY:
- if (values != null) {
- builder.addProperty(new StructuralPropertyImpl(currentFieldName, values));
- values = null;
- }
- break;
- case FIELD_NAME:
- currentFieldName = jp.getCurrentName();
- break;
- case NOT_AVAILABLE:
- break;
- case VALUE_EMBEDDED_OBJECT:
- break;
- case VALUE_NULL:
- Property nullProperty = createProperty(jp.getCurrentName(), null);
- builder.addProperty(nullProperty);
- break;
- case VALUE_FALSE:
- case VALUE_NUMBER_FLOAT:
- case VALUE_NUMBER_INT:
- case VALUE_STRING:
- case VALUE_TRUE:
- if (values == null) {
- Property property = createProperty(jp.getCurrentName(), jp.getValueAsString());
- builder.addProperty(property);
- } else {
- PrimitiveValue value = new PrimitiveValue(jp.getValueAsString());
- values.add(value);
- }
- break;
- default:
- break;
- }
- }
-
- return null;
- }
-
- private boolean readToStartObjectOrEnd(final JsonParser jp) throws IOException, JsonParseException {
- final JsonToken endToken = JsonToken.START_OBJECT;
- JsonToken token = jp.getCurrentToken() == null ? jp.nextToken() : jp.getCurrentToken();
- while (token != null && token != endToken) {
- if (enclosingEntitySet != null) {
- switch (token) {
- case VALUE_FALSE:
- case VALUE_NUMBER_FLOAT:
- case VALUE_NUMBER_INT:
- case VALUE_TRUE:
- case VALUE_STRING:
- enclosingEntitySet.addAnnotation(jp.getCurrentName(), jp.getValueAsString());
- break;
-
- default:
- break;
- }
- }
- //
- token = jp.nextToken();
- }
-
- return token == null;
- }
-
- private Property createProperty(final String name, final String value) {
- if (name.contains("@")) {
- return new NavigationPropertyImpl(name, value);
- } else if (name.contains(".")) {
- return new AnnotationPropertyImpl(name, value);
- } else {
- return new StructuralPropertyImpl(name, new PrimitiveValue(value));
- }
- }
-}