You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by il...@apache.org on 2014/03/24 10:42:14 UTC
[25/50] [abbrv] Package rename
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ComplexTypeDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ComplexTypeDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ComplexTypeDeserializer.java
new file mode 100644
index 0000000..754bad4
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ComplexTypeDeserializer.java
@@ -0,0 +1,83 @@
+/*
+ * 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.op;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.olingo.client.core.edm.xml.AbstractComplexType;
+import org.apache.olingo.client.core.edm.xml.v4.AnnotationImpl;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+
+public class ComplexTypeDeserializer extends AbstractEdmDeserializer<AbstractComplexType> {
+
+ @Override
+ protected AbstractComplexType doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ final AbstractComplexType complexType = ODataServiceVersion.V30 == client.getServiceVersion()
+ ? new org.apache.olingo.client.core.edm.xml.v3.ComplexTypeImpl()
+ : new org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl();
+
+ for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
+ final JsonToken token = jp.getCurrentToken();
+ if (token == JsonToken.FIELD_NAME) {
+ if ("Name".equals(jp.getCurrentName())) {
+ complexType.setName(jp.nextTextValue());
+ } else if ("Abstract".equals(jp.getCurrentName())) {
+ ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType).
+ setAbstractEntityType(BooleanUtils.toBoolean(jp.nextTextValue()));
+ } else if ("BaseType".equals(jp.getCurrentName())) {
+ ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType).
+ setBaseType(jp.nextTextValue());
+ } else if ("OpenType".equals(jp.getCurrentName())) {
+ ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType).
+ setOpenType(BooleanUtils.toBoolean(jp.nextTextValue()));
+ } else if ("Property".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ if (complexType instanceof org.apache.olingo.client.core.edm.xml.v3.ComplexTypeImpl) {
+ ((org.apache.olingo.client.core.edm.xml.v3.ComplexTypeImpl) complexType).
+ getProperties().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v3.PropertyImpl.class));
+ } else {
+ ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType).
+ getProperties().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v4.PropertyImpl.class));
+ }
+ } else if ("NavigationProperty".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType).
+ getNavigationProperties().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v4.NavigationPropertyImpl.class));
+ } else if ("Annotation".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType).
+ setAnnotation(jp.readValueAs(AnnotationImpl.class));
+ }
+ }
+ }
+
+ return complexType;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntityContainerDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntityContainerDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntityContainerDeserializer.java
new file mode 100644
index 0000000..131ba9e
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntityContainerDeserializer.java
@@ -0,0 +1,102 @@
+/*
+ * 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.op;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.olingo.client.core.edm.xml.AbstractEntityContainer;
+import org.apache.olingo.client.core.edm.xml.v3.AssociationSetImpl;
+import org.apache.olingo.client.core.edm.xml.v4.ActionImportImpl;
+import org.apache.olingo.client.core.edm.xml.v4.AnnotationImpl;
+import org.apache.olingo.client.core.edm.xml.v4.SingletonImpl;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+
+@SuppressWarnings("rawtypes")
+public class EntityContainerDeserializer extends AbstractEdmDeserializer<AbstractEntityContainer> {
+
+ @Override
+ protected AbstractEntityContainer doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ final AbstractEntityContainer entityContainer = ODataServiceVersion.V30 == client.getServiceVersion()
+ ? new org.apache.olingo.client.core.edm.xml.v3.EntityContainerImpl()
+ : new org.apache.olingo.client.core.edm.xml.v4.EntityContainerImpl();
+
+ for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
+ final JsonToken token = jp.getCurrentToken();
+ if (token == JsonToken.FIELD_NAME) {
+ if ("Name".equals(jp.getCurrentName())) {
+ entityContainer.setName(jp.nextTextValue());
+ } else if ("Extends".equals(jp.getCurrentName())) {
+ entityContainer.setExtends(jp.nextTextValue());
+ } else if ("LazyLoadingEnabled".equals(jp.getCurrentName())) {
+ entityContainer.setLazyLoadingEnabled(BooleanUtils.toBoolean(jp.nextTextValue()));
+ } else if ("IsDefaultEntityContainer".equals(jp.getCurrentName())) {
+ entityContainer.setDefaultEntityContainer(BooleanUtils.toBoolean(jp.nextTextValue()));
+ } else if ("EntitySet".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ if (entityContainer instanceof org.apache.olingo.client.core.edm.xml.v3.EntityContainerImpl) {
+ ((org.apache.olingo.client.core.edm.xml.v3.EntityContainerImpl) entityContainer).
+ getEntitySets().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v3.EntitySetImpl.class));
+ } else {
+ ((org.apache.olingo.client.core.edm.xml.v4.EntityContainerImpl) entityContainer).
+ getEntitySets().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v4.EntitySetImpl.class));
+ }
+ } else if ("AssociationSet".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v3.EntityContainerImpl) entityContainer).
+ getAssociationSets().add(jp.readValueAs(AssociationSetImpl.class));
+ } else if ("Singleton".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v4.EntityContainerImpl) entityContainer).
+ getSingletons().add(jp.readValueAs(SingletonImpl.class));
+ } else if ("ActionImport".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v4.EntityContainerImpl) entityContainer).
+ getActionImports().add(jp.readValueAs(ActionImportImpl.class));
+ } else if ("FunctionImport".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ if (entityContainer instanceof org.apache.olingo.client.core.edm.xml.v3.EntityContainerImpl) {
+ ((org.apache.olingo.client.core.edm.xml.v3.EntityContainerImpl) entityContainer).
+ getFunctionImports().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v3.FunctionImportImpl.class));
+ } else {
+ ((org.apache.olingo.client.core.edm.xml.v4.EntityContainerImpl) entityContainer).
+ getFunctionImports().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v4.FunctionImportImpl.class));
+ }
+ } else if ("Annotation".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v4.EntityContainerImpl) entityContainer).
+ setAnnotation(jp.readValueAs(AnnotationImpl.class));
+ }
+ }
+ }
+
+ return entityContainer;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntityKeyDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntityKeyDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntityKeyDeserializer.java
new file mode 100644
index 0000000..8462f4a
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntityKeyDeserializer.java
@@ -0,0 +1,50 @@
+/*
+ * 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.op;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+
+import java.io.IOException;
+
+import org.apache.olingo.client.core.edm.xml.EntityKeyImpl;
+import org.apache.olingo.client.core.edm.xml.PropertyRefImpl;
+
+public class EntityKeyDeserializer extends AbstractEdmDeserializer<EntityKeyImpl> {
+
+ @Override
+ protected EntityKeyImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ final EntityKeyImpl entityKey = new EntityKeyImpl();
+
+ for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
+ final JsonToken token = jp.getCurrentToken();
+
+ if (token == JsonToken.FIELD_NAME && "PropertyRef".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ entityKey.getPropertyRefs().add(jp.readValueAs( PropertyRefImpl.class));
+ }
+ }
+
+ return entityKey;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntitySetDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntitySetDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntitySetDeserializer.java
new file mode 100644
index 0000000..d11206e
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntitySetDeserializer.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.op;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.olingo.client.core.edm.xml.AbstractEntitySet;
+import org.apache.olingo.client.core.edm.xml.v4.AnnotationImpl;
+import org.apache.olingo.client.core.edm.xml.v4.NavigationPropertyBindingImpl;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+
+public class EntitySetDeserializer extends AbstractEdmDeserializer<AbstractEntitySet> {
+
+ @Override
+ protected AbstractEntitySet doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ final AbstractEntitySet entitySet = ODataServiceVersion.V30 == client.getServiceVersion()
+ ? new org.apache.olingo.client.core.edm.xml.v3.EntitySetImpl()
+ : new org.apache.olingo.client.core.edm.xml.v4.EntitySetImpl();
+
+ for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
+ final JsonToken token = jp.getCurrentToken();
+ if (token == JsonToken.FIELD_NAME) {
+ if ("Name".equals(jp.getCurrentName())) {
+ entitySet.setName(jp.nextTextValue());
+ } else if ("EntityType".equals(jp.getCurrentName())) {
+ entitySet.setEntityType(jp.nextTextValue());
+ } else if ("IncludeInServiceDocument".equals(jp.getCurrentName())) {
+ ((org.apache.olingo.client.core.edm.xml.v4.EntitySetImpl) entitySet).
+ setIncludeInServiceDocument(BooleanUtils.toBoolean(jp.nextTextValue()));
+ } else if ("NavigationPropertyBinding".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v4.EntitySetImpl) entitySet).
+ getNavigationPropertyBindings().add(
+ jp.readValueAs(NavigationPropertyBindingImpl.class));
+ } else if ("Annotation".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v4.EntitySetImpl) entitySet).
+ setAnnotation(jp.readValueAs(AnnotationImpl.class));
+ }
+ }
+ }
+
+ return entitySet;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntityTypeDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntityTypeDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntityTypeDeserializer.java
new file mode 100644
index 0000000..b2775e5
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EntityTypeDeserializer.java
@@ -0,0 +1,92 @@
+/*
+ * 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.op;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.olingo.client.core.edm.xml.AbstractEntityType;
+import org.apache.olingo.client.core.edm.xml.EntityKeyImpl;
+import org.apache.olingo.client.core.edm.xml.v4.AnnotationImpl;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+
+public class EntityTypeDeserializer extends AbstractEdmDeserializer<AbstractEntityType> {
+
+ @Override
+ protected AbstractEntityType doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ final AbstractEntityType entityType = ODataServiceVersion.V30 == client.getServiceVersion()
+ ? new org.apache.olingo.client.core.edm.xml.v3.EntityTypeImpl()
+ : new org.apache.olingo.client.core.edm.xml.v4.EntityTypeImpl();
+
+ for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
+ final JsonToken token = jp.getCurrentToken();
+ if (token == JsonToken.FIELD_NAME) {
+ if ("Name".equals(jp.getCurrentName())) {
+ entityType.setName(jp.nextTextValue());
+ } else if ("Abstract".equals(jp.getCurrentName())) {
+ entityType.setAbstractEntityType(BooleanUtils.toBoolean(jp.nextTextValue()));
+ } else if ("BaseType".equals(jp.getCurrentName())) {
+ entityType.setBaseType(jp.nextTextValue());
+ } else if ("OpenType".equals(jp.getCurrentName())) {
+ entityType.setOpenType(BooleanUtils.toBoolean(jp.nextTextValue()));
+ } else if ("HasStream".equals(jp.getCurrentName())) {
+ entityType.setHasStream(BooleanUtils.toBoolean(jp.nextTextValue()));
+ } else if ("Key".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ entityType.setKey(jp.readValueAs(EntityKeyImpl.class));
+ } else if ("Property".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ if (entityType instanceof org.apache.olingo.client.core.edm.xml.v3.EntityTypeImpl) {
+ ((org.apache.olingo.client.core.edm.xml.v3.EntityTypeImpl) entityType).
+ getProperties().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v3.PropertyImpl.class));
+ } else {
+ ((org.apache.olingo.client.core.edm.xml.v4.EntityTypeImpl) entityType).
+ getProperties().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v4.PropertyImpl.class));
+ }
+ } else if ("NavigationProperty".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ if (entityType instanceof org.apache.olingo.client.core.edm.xml.v3.EntityTypeImpl) {
+ ((org.apache.olingo.client.core.edm.xml.v3.EntityTypeImpl) entityType).
+ getNavigationProperties().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v3.NavigationPropertyImpl.class));
+ } else {
+ ((org.apache.olingo.client.core.edm.xml.v4.EntityTypeImpl) entityType).
+ getNavigationProperties().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v4.NavigationPropertyImpl.class));
+ }
+ } else if ("Annotation".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v4.EntityTypeImpl) entityType).
+ setAnnotation(jp.readValueAs(AnnotationImpl.class));
+ }
+ }
+ }
+
+ return entityType;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EnumTypeDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EnumTypeDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EnumTypeDeserializer.java
new file mode 100644
index 0000000..f2b891c
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/EnumTypeDeserializer.java
@@ -0,0 +1,73 @@
+/*
+ * 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.op;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.olingo.client.core.edm.xml.AbstractEnumType;
+import org.apache.olingo.client.core.edm.xml.v4.AnnotationImpl;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+
+public class EnumTypeDeserializer extends AbstractEdmDeserializer<AbstractEnumType> {
+
+ @Override
+ protected AbstractEnumType doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ final AbstractEnumType enumType = ODataServiceVersion.V30 == client.getServiceVersion()
+ ? new org.apache.olingo.client.core.edm.xml.v3.EnumTypeImpl()
+ : new org.apache.olingo.client.core.edm.xml.v4.EnumTypeImpl();
+
+ for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
+ final JsonToken token = jp.getCurrentToken();
+ if (token == JsonToken.FIELD_NAME) {
+ if ("Name".equals(jp.getCurrentName())) {
+ enumType.setName(jp.nextTextValue());
+ } else if ("UnderlyingType".equals(jp.getCurrentName())) {
+ enumType.setUnderlyingType(jp.nextTextValue());
+ } else if ("IsFlags".equals(jp.getCurrentName())) {
+ enumType.setFlags(BooleanUtils.toBoolean(jp.nextTextValue()));
+ } else if ("Member".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ if (enumType instanceof org.apache.olingo.client.core.edm.xml.v3.EnumTypeImpl) {
+ ((org.apache.olingo.client.core.edm.xml.v3.EnumTypeImpl) enumType).
+ getMembers().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v3.MemberImpl.class));
+ } else {
+ ((org.apache.olingo.client.core.edm.xml.v4.EnumTypeImpl) enumType).
+ getMembers().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v4.MemberImpl.class));
+ }
+ } else if ("Annotation".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v4.EnumTypeImpl) enumType).
+ setAnnotation(jp.readValueAs(AnnotationImpl.class));
+ }
+ }
+ }
+
+ return enumType;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/InjectableSerializerProvider.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/InjectableSerializerProvider.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/InjectableSerializerProvider.java
new file mode 100644
index 0000000..b9b5374
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/InjectableSerializerProvider.java
@@ -0,0 +1,43 @@
+/*
+ * 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.op;
+
+import com.fasterxml.jackson.databind.SerializationConfig;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
+import com.fasterxml.jackson.databind.ser.SerializerFactory;
+
+class InjectableSerializerProvider extends DefaultSerializerProvider {
+
+ private static final long serialVersionUID = 3432260063063739646L;
+
+ public InjectableSerializerProvider(
+ final SerializerProvider src, final SerializationConfig config, final SerializerFactory factory) {
+
+ super(src, config, factory);
+ }
+
+ @Override
+ public InjectableSerializerProvider createInstance(
+ final SerializationConfig config, final SerializerFactory factory) {
+
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataObjectFactoryImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataObjectFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataObjectFactoryImpl.java
new file mode 100644
index 0000000..0b71abc
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataObjectFactoryImpl.java
@@ -0,0 +1,165 @@
+/*
+ * 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.op;
+
+import java.net.URI;
+import org.apache.olingo.client.api.CommonODataClient;
+import org.apache.olingo.client.api.domain.ODataLinkType;
+import org.apache.olingo.client.api.domain.ODataCollectionValue;
+import org.apache.olingo.client.api.domain.ODataComplexValue;
+import org.apache.olingo.client.api.domain.ODataEntity;
+import org.apache.olingo.client.api.domain.ODataEntitySet;
+import org.apache.olingo.client.api.domain.ODataGeospatialValue;
+import org.apache.olingo.client.api.domain.ODataInlineEntity;
+import org.apache.olingo.client.api.domain.ODataInlineEntitySet;
+import org.apache.olingo.client.api.domain.ODataLink;
+import org.apache.olingo.client.api.domain.ODataObjectFactory;
+import org.apache.olingo.client.api.domain.ODataPrimitiveValue;
+import org.apache.olingo.client.api.domain.ODataProperty;
+
+public class ODataObjectFactoryImpl implements ODataObjectFactory {
+
+ private static final long serialVersionUID = -3769695665946919447L;
+
+ protected final CommonODataClient client;
+
+ public ODataObjectFactoryImpl(final CommonODataClient client) {
+ this.client = client;
+ }
+
+ @Override
+ public ODataEntitySet newEntitySet() {
+ return new ODataEntitySet();
+ }
+
+ @Override
+ public ODataEntitySet newEntitySet(final URI next) {
+ return new ODataEntitySet(next);
+ }
+
+ @Override
+ public ODataEntity newEntity(final String name) {
+ return new ODataEntity(name);
+ }
+
+ @Override
+ public ODataEntity newEntity(final String name, final URI link) {
+ final ODataEntity result = new ODataEntity(name);
+ result.setLink(link);
+ return result;
+ }
+
+ @Override
+ public ODataInlineEntitySet newInlineEntitySet(final String name, final URI link,
+ final ODataEntitySet entitySet) {
+
+ return new ODataInlineEntitySet(client.getServiceVersion(),
+ link, ODataLinkType.ENTITY_SET_NAVIGATION, name, entitySet);
+ }
+
+ @Override
+ public ODataInlineEntitySet newInlineEntitySet(final String name, final URI baseURI, final String href,
+ final ODataEntitySet entitySet) {
+
+ return new ODataInlineEntitySet(client.getServiceVersion(),
+ baseURI, href, ODataLinkType.ENTITY_SET_NAVIGATION, name, entitySet);
+ }
+
+ @Override
+ public ODataInlineEntity newInlineEntity(final String name, final URI link, final ODataEntity entity) {
+ return new ODataInlineEntity(client.getServiceVersion(), link, ODataLinkType.ENTITY_NAVIGATION, name, entity);
+ }
+
+ @Override
+ public ODataInlineEntity newInlineEntity(final String name, final URI baseURI, final String href,
+ final ODataEntity entity) {
+
+ return new ODataInlineEntity(client.getServiceVersion(),
+ baseURI, href, ODataLinkType.ENTITY_NAVIGATION, name, entity);
+ }
+
+ @Override
+ public ODataLink newEntityNavigationLink(final String name, final URI link) {
+ return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(link).
+ setType(ODataLinkType.ENTITY_NAVIGATION).setTitle(name).build();
+ }
+
+ @Override
+ public ODataLink newEntityNavigationLink(final String name, final URI baseURI, final String href) {
+ return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(baseURI, href).
+ setType(ODataLinkType.ENTITY_NAVIGATION).setTitle(name).build();
+ }
+
+ @Override
+ public ODataLink newFeedNavigationLink(final String name, final URI link) {
+ return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(link).
+ setType(ODataLinkType.ENTITY_SET_NAVIGATION).setTitle(name).build();
+ }
+
+ @Override
+ public ODataLink newFeedNavigationLink(final String name, final URI baseURI, final String href) {
+ return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(baseURI, href).
+ setType(ODataLinkType.ENTITY_SET_NAVIGATION).setTitle(name).build();
+ }
+
+ @Override
+ public ODataLink newAssociationLink(final String name, final URI link) {
+ return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(link).
+ setType(ODataLinkType.ASSOCIATION).setTitle(name).build();
+ }
+
+ @Override
+ public ODataLink newAssociationLink(final String name, final URI baseURI, final String href) {
+ return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(baseURI, href).
+ setType(ODataLinkType.ASSOCIATION).setTitle(name).build();
+ }
+
+ @Override
+ public ODataLink newMediaEditLink(final String name, final URI link) {
+ return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(link).
+ setType(ODataLinkType.MEDIA_EDIT).setTitle(name).build();
+ }
+
+ @Override
+ public ODataLink newMediaEditLink(final String name, final URI baseURI, final String href) {
+ return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(baseURI, href).
+ setType(ODataLinkType.MEDIA_EDIT).setTitle(name).build();
+ }
+
+ @Override
+ public ODataProperty newPrimitiveProperty(final String name, final ODataPrimitiveValue value) {
+ return new ODataProperty(name, value);
+ }
+
+ @Override
+ public ODataProperty newPrimitiveProperty(final String name, final ODataGeospatialValue value) {
+ return new ODataProperty(name, value);
+ }
+
+ @Override
+ public ODataProperty newComplexProperty(final String name, final ODataComplexValue value) {
+ return new ODataProperty(name, value);
+ }
+
+ @Override
+ public ODataProperty newCollectionProperty(final String name, final ODataCollectionValue value) {
+ return new ODataProperty(name, value);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java
new file mode 100644
index 0000000..7e5c9b4
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java
@@ -0,0 +1,101 @@
+/*
+ * 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.op;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Collections;
+import org.apache.commons.io.IOUtils;
+import org.apache.olingo.client.api.CommonODataClient;
+import org.apache.olingo.client.api.domain.ODataEntity;
+import org.apache.olingo.client.api.domain.ODataLink;
+import org.apache.olingo.client.api.domain.ODataProperty;
+import org.apache.olingo.client.api.format.ODataFormat;
+import org.apache.olingo.client.api.format.ODataPubFormat;
+import org.apache.olingo.client.api.op.ODataWriter;
+
+public class ODataWriterImpl implements ODataWriter {
+
+ private static final long serialVersionUID = 3265794768412314485L;
+
+ protected final CommonODataClient client;
+
+ public ODataWriterImpl(final CommonODataClient client) {
+ this.client = client;
+ }
+
+ @Override
+ public InputStream writeEntities(final Collection<ODataEntity> entities, final ODataPubFormat format) {
+ return writeEntities(entities, format, true);
+ }
+
+ @Override
+ public InputStream writeEntities(
+ final Collection<ODataEntity> entities, final ODataPubFormat format, final boolean outputType) {
+
+ final ByteArrayOutputStream output = new ByteArrayOutputStream();
+ try {
+ for (ODataEntity entity : entities) {
+ client.getSerializer().entry(client.getBinder().getEntry(
+ entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM), outputType), output);
+ }
+
+ return new ByteArrayInputStream(output.toByteArray());
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
+ }
+
+ @Override
+ public InputStream writeEntity(final ODataEntity entity, final ODataPubFormat format) {
+ return writeEntity(entity, format, true);
+ }
+
+ @Override
+ public InputStream writeEntity(final ODataEntity entity, final ODataPubFormat format, final boolean outputType) {
+ return writeEntities(Collections.<ODataEntity>singleton(entity), format, outputType);
+ }
+
+ @Override
+ public InputStream writeProperty(final ODataProperty property, final ODataFormat format) {
+ final ByteArrayOutputStream output = new ByteArrayOutputStream();
+ try {
+ client.getSerializer().property(client.getBinder().getProperty(
+ property, ResourceFactory.entryClassForFormat(format == ODataFormat.XML), true), output);
+
+ return new ByteArrayInputStream(output.toByteArray());
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
+ }
+
+ @Override
+ public InputStream writeLink(final ODataLink link, final ODataFormat format) {
+ final ByteArrayOutputStream output = new ByteArrayOutputStream();
+ try {
+ client.getSerializer().link(client.getBinder().getLink(link, format == ODataFormat.XML), format, output);
+
+ return new ByteArrayInputStream(output.toByteArray());
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ResourceFactory.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ResourceFactory.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ResourceFactory.java
new file mode 100644
index 0000000..da3ead2
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ResourceFactory.java
@@ -0,0 +1,125 @@
+/*
+ * 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.op;
+
+import org.apache.olingo.client.api.data.Entry;
+import org.apache.olingo.client.api.data.Feed;
+import org.apache.olingo.client.api.data.Property;
+import org.apache.olingo.client.api.format.ODataPubFormat;
+import org.apache.olingo.client.core.data.AtomEntryImpl;
+import org.apache.olingo.client.core.data.AtomFeedImpl;
+import org.apache.olingo.client.core.data.AtomPropertyImpl;
+import org.apache.olingo.client.core.data.JSONEntryImpl;
+import org.apache.olingo.client.core.data.JSONFeedImpl;
+import org.apache.olingo.client.core.data.JSONPropertyImpl;
+
+public class ResourceFactory {
+
+ /**
+ * Gets a new instance of <tt>Feed</tt>.
+ *
+ * @param resourceClass reference class.
+ * @return <tt>Feed</tt> object.
+ */
+ public static Feed newFeed(final Class<? extends Feed> resourceClass) {
+ Feed result = null;
+
+ if (AtomFeedImpl.class.equals(resourceClass)) {
+ result = new AtomFeedImpl();
+ }
+ if (JSONFeedImpl.class.equals(resourceClass)) {
+ result = new JSONFeedImpl();
+ }
+
+ return result;
+ }
+
+ /**
+ * Gets a new instance of <tt>Entry</tt>.
+ *
+ * @param resourceClass reference class.
+ * @return <tt>Entry</tt> object.
+ */
+ public static Entry newEntry(final Class<? extends Entry> resourceClass) {
+ Entry result = null;
+ if (AtomEntryImpl.class.equals(resourceClass)) {
+ result = new AtomEntryImpl();
+ }
+ if (JSONEntryImpl.class.equals(resourceClass)) {
+ result = new JSONEntryImpl();
+ }
+
+ return result;
+ }
+
+ public static Property newProperty(final Class<? extends Entry> resourceClass) {
+ Property result = null;
+ if (AtomEntryImpl.class.equals(resourceClass)) {
+ result = new AtomPropertyImpl();
+ }
+ if (JSONEntryImpl.class.equals(resourceClass)) {
+ result = new JSONPropertyImpl();
+ }
+
+ return result;
+ }
+
+ /**
+ * Gets feed reference class from the given format.
+ *
+ * @param isXML whether it is JSON or XML / Atom
+ * @return resource reference class.
+ */
+ public static Class<? extends Feed> feedClassForFormat(final boolean isXML) {
+ return isXML ? AtomFeedImpl.class : JSONFeedImpl.class;
+ }
+
+ /**
+ * Gets entry reference class from the given format.
+ *
+ * @param isXML whether it is JSON or XML / Atom
+ * @return resource reference class.
+ */
+ public static Class<? extends Entry> entryClassForFormat(final boolean isXML) {
+ return isXML ? AtomEntryImpl.class : JSONEntryImpl.class;
+ }
+
+ /**
+ * Gets <tt>Entry</tt> object from feed resource.
+ *
+ * @param resourceClass feed reference class.
+ * @return <tt>Entry</tt> object.
+ */
+ public static Class<? extends Entry> entryClassForFeed(final Class<? extends Feed> resourceClass) {
+ Class<? extends Entry> result = null;
+
+ if (AtomFeedImpl.class.equals(resourceClass)) {
+ result = AtomEntryImpl.class;
+ }
+ if (JSONFeedImpl.class.equals(resourceClass)) {
+ result = JSONEntryImpl.class;
+ }
+
+ return result;
+ }
+
+ public static ODataPubFormat formatForEntryClass(final Class<? extends Entry> reference) {
+ return reference.equals(AtomEntryImpl.class) ? ODataPubFormat.ATOM : ODataPubFormat.JSON;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/SchemaDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/SchemaDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/SchemaDeserializer.java
new file mode 100644
index 0000000..47eb195
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/SchemaDeserializer.java
@@ -0,0 +1,149 @@
+/*
+ * 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.op;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+
+import java.io.IOException;
+
+import org.apache.olingo.client.core.edm.xml.AbstractSchema;
+import org.apache.olingo.client.core.edm.xml.v3.AssociationImpl;
+import org.apache.olingo.client.core.edm.xml.v3.UsingImpl;
+import org.apache.olingo.client.core.edm.xml.v3.ValueTermImpl;
+import org.apache.olingo.client.core.edm.xml.v4.ActionImpl;
+import org.apache.olingo.client.core.edm.xml.v4.AnnotationImpl;
+import org.apache.olingo.client.core.edm.xml.v4.FunctionImpl;
+import org.apache.olingo.client.core.edm.xml.v4.TypeDefinitionImpl;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+
+@SuppressWarnings("rawtypes")
+public class SchemaDeserializer extends AbstractEdmDeserializer<AbstractSchema> {
+
+ @Override
+ protected AbstractSchema doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ final AbstractSchema schema = ODataServiceVersion.V30 == client.getServiceVersion()
+ ? new org.apache.olingo.client.core.edm.xml.v3.SchemaImpl()
+ : new org.apache.olingo.client.core.edm.xml.v4.SchemaImpl();
+
+ for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
+ final JsonToken token = jp.getCurrentToken();
+ if (token == JsonToken.FIELD_NAME) {
+ if ("Namespace".equals(jp.getCurrentName())) {
+ schema.setNamespace(jp.nextTextValue());
+ } else if ("Alias".equals(jp.getCurrentName())) {
+ schema.setAlias(jp.nextTextValue());
+ } else if ("Using".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v3.SchemaImpl) schema).
+ getUsings().add(jp.readValueAs( UsingImpl.class));
+ } else if ("Association".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v3.SchemaImpl) schema).
+ getAssociations().add(jp.readValueAs( AssociationImpl.class));
+ } else if ("ComplexType".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ if (schema instanceof org.apache.olingo.client.core.edm.xml.v3.SchemaImpl) {
+ ((org.apache.olingo.client.core.edm.xml.v3.SchemaImpl) schema).
+ getComplexTypes().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v3.ComplexTypeImpl.class));
+ } else {
+ ((org.apache.olingo.client.core.edm.xml.v4.SchemaImpl) schema).
+ getComplexTypes().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl.class));
+ }
+ } else if ("EntityType".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ if (schema instanceof org.apache.olingo.client.core.edm.xml.v3.SchemaImpl) {
+ ((org.apache.olingo.client.core.edm.xml.v3.SchemaImpl) schema).
+ getEntityTypes().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v3.EntityTypeImpl.class));
+ } else {
+ ((org.apache.olingo.client.core.edm.xml.v4.SchemaImpl) schema).
+ getEntityTypes().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v4.EntityTypeImpl.class));
+ }
+ } else if ("EnumType".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ if (schema instanceof org.apache.olingo.client.core.edm.xml.v3.SchemaImpl) {
+ ((org.apache.olingo.client.core.edm.xml.v3.SchemaImpl) schema).
+ getEnumTypes().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v3.EnumTypeImpl.class));
+ } else {
+ ((org.apache.olingo.client.core.edm.xml.v4.SchemaImpl) schema).
+ getEnumTypes().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v4.EnumTypeImpl.class));
+ }
+ } else if ("ValueTerm".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v3.SchemaImpl) schema).
+ getValueTerms().add(jp.readValueAs( ValueTermImpl.class));
+ } else if ("EntityContainer".equals(jp.getCurrentName())) {
+ jp.nextToken();
+
+ if (schema instanceof org.apache.olingo.client.core.edm.xml.v3.SchemaImpl) {
+ ((org.apache.olingo.client.core.edm.xml.v3.SchemaImpl) schema).
+ getEntityContainers().add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v3.EntityContainerImpl.class));
+ } else {
+ org.apache.olingo.client.core.edm.xml.v4.EntityContainerImpl entityContainer
+ = jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v4.EntityContainerImpl.class);
+ entityContainer.setDefaultEntityContainer(true);
+ ((org.apache.olingo.client.core.edm.xml.v4.SchemaImpl) schema).
+ setEntityContainer(entityContainer);
+ }
+ } else if ("Annotations".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ if (schema instanceof org.apache.olingo.client.core.edm.xml.v3.SchemaImpl) {
+ ((org.apache.olingo.client.core.edm.xml.v3.SchemaImpl) schema).getAnnotationsList().
+ add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v3.AnnotationsImpl.class));
+ } else {
+ ((org.apache.olingo.client.core.edm.xml.v4.SchemaImpl) schema).getAnnotationsList().
+ add(jp.readValueAs(
+ org.apache.olingo.client.core.edm.xml.v4.AnnotationsImpl.class));
+ }
+ } else if ("Action".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v4.SchemaImpl) schema).getActions().
+ add(jp.readValueAs( ActionImpl.class));
+ } else if ("Annotation".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v4.SchemaImpl) schema).getAnnotations().
+ add(jp.readValueAs( AnnotationImpl.class));
+ } else if ("Function".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v4.SchemaImpl) schema).getFunctions().
+ add(jp.readValueAs( FunctionImpl.class));
+ } else if ("TypeDefinition".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ ((org.apache.olingo.client.core.edm.xml.v4.SchemaImpl) schema).
+ getTypeDefinitions().add(jp.readValueAs( TypeDefinitionImpl.class));
+ }
+ }
+ }
+
+ return schema;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractEdmDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractEdmDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractEdmDeserializer.java
deleted file mode 100644
index 5850a2d..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractEdmDeserializer.java
+++ /dev/null
@@ -1,71 +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.op.impl;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonDeserializer;
-import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser;
-
-import java.io.IOException;
-
-import org.apache.olingo.client.api.CommonODataClient;
-import org.apache.olingo.client.core.edm.xml.v4.ReturnTypeImpl;
-import org.apache.olingo.client.core.edm.xml.v4.annotation.ConstExprConstructImpl;
-
-public abstract class AbstractEdmDeserializer<T> extends JsonDeserializer<T> {
-
- protected CommonODataClient client;
-
- protected boolean isAnnotationConstExprConstruct(final JsonParser jp) throws IOException {
- return ConstExprConstructImpl.Type.fromString(jp.getCurrentName()) != null;
- }
-
- protected ConstExprConstructImpl parseAnnotationConstExprConstruct(final JsonParser jp) throws IOException {
- final ConstExprConstructImpl constExpr = new ConstExprConstructImpl();
- constExpr.setType(ConstExprConstructImpl.Type.fromString(jp.getCurrentName()));
- constExpr.setValue(jp.nextTextValue());
- return constExpr;
- }
-
- protected ReturnTypeImpl parseReturnType(final JsonParser jp, final String elementName) throws IOException {
- ReturnTypeImpl returnType;
- if (elementName.equals(((FromXmlParser) jp).getStaxReader().getLocalName())) {
- returnType = new ReturnTypeImpl();
- returnType.setType(jp.nextTextValue());
- } else {
- jp.nextToken();
- returnType = jp.readValueAs( ReturnTypeImpl.class);
- }
- return returnType;
- }
-
- protected abstract T doDeserialize(JsonParser jp, DeserializationContext ctxt)
- throws IOException, JsonProcessingException;
-
- @Override
- public T deserialize(final JsonParser jp, final DeserializationContext ctxt)
- throws IOException, JsonProcessingException {
-
- client = (CommonODataClient) ctxt.findInjectableValue(CommonODataClient.class.getName(), null, null);
- return doDeserialize(jp, ctxt);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractJacksonTool.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractJacksonTool.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractJacksonTool.java
deleted file mode 100644
index eb26d95..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractJacksonTool.java
+++ /dev/null
@@ -1,85 +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.op.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 java.io.IOException;
-
-import org.apache.olingo.client.api.CommonODataClient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-abstract class AbstractJacksonTool {
-
- protected static final Logger LOG = LoggerFactory.getLogger(AbstractJacksonTool.class);
-
- protected final CommonODataClient client;
-
- protected AbstractJacksonTool(final CommonODataClient client) {
- this.client = client;
- }
-
- protected ObjectMapper getObjectMapper() {
- final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
-
- mapper.setInjectableValues(new InjectableValues.Std().addValue(CommonODataClient.class, client));
-
- mapper.setSerializerProvider(new InjectableSerializerProvider(mapper.getSerializerProvider(),
- mapper.getSerializationConfig().withAttribute(CommonODataClient.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(CommonODataClient.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/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataBinder.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataBinder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataBinder.java
deleted file mode 100644
index 2c2cdea..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataBinder.java
+++ /dev/null
@@ -1,404 +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.op.impl;
-
-import java.io.StringWriter;
-import java.net.URI;
-import java.util.Iterator;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.client.api.CommonODataClient;
-import org.apache.olingo.client.api.Constants;
-import org.apache.olingo.client.api.data.Entry;
-import org.apache.olingo.client.api.data.Feed;
-import org.apache.olingo.client.api.data.Link;
-import org.apache.olingo.client.api.data.Property;
-import org.apache.olingo.client.api.data.ServiceDocument;
-import org.apache.olingo.client.api.data.ServiceDocumentItem;
-import org.apache.olingo.client.api.data.Value;
-import org.apache.olingo.client.api.domain.ODataCollectionValue;
-import org.apache.olingo.client.api.domain.ODataComplexValue;
-import org.apache.olingo.client.api.domain.ODataEntity;
-import org.apache.olingo.client.api.domain.ODataEntitySet;
-import org.apache.olingo.client.api.domain.ODataInlineEntity;
-import org.apache.olingo.client.api.domain.ODataInlineEntitySet;
-import org.apache.olingo.client.api.domain.ODataLink;
-import org.apache.olingo.client.api.domain.ODataOperation;
-import org.apache.olingo.client.api.domain.ODataProperty;
-import org.apache.olingo.client.api.domain.ODataServiceDocument;
-import org.apache.olingo.client.api.domain.ODataValue;
-import org.apache.olingo.client.api.format.ODataPubFormat;
-import org.apache.olingo.client.api.op.CommonODataBinder;
-import org.apache.olingo.client.core.data.CollectionValueImpl;
-import org.apache.olingo.client.core.data.ComplexValueImpl;
-import org.apache.olingo.client.core.data.GeospatialValueImpl;
-import org.apache.olingo.client.core.data.JSONPropertyImpl;
-import org.apache.olingo.client.core.data.LinkImpl;
-import org.apache.olingo.client.core.data.NullValueImpl;
-import org.apache.olingo.client.core.data.PrimitiveValueImpl;
-import org.apache.olingo.client.core.uri.URIUtils;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class AbstractODataBinder implements CommonODataBinder {
-
- private static final long serialVersionUID = 454285889193689536L;
-
- /**
- * Logger.
- */
- protected final Logger LOG = LoggerFactory.getLogger(AbstractODataBinder.class);
-
- protected final CommonODataClient client;
-
- protected AbstractODataBinder(final CommonODataClient client) {
- this.client = client;
- }
-
- @Override
- public ODataServiceDocument getODataServiceDocument(final ServiceDocument resource) {
- final ODataServiceDocument serviceDocument = new ODataServiceDocument();
-
- for (ServiceDocumentItem entitySet : resource.getEntitySets()) {
- // 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 Feed getFeed(final ODataEntitySet feed, final Class<? extends Feed> reference) {
- final Feed feedResource = ResourceFactory.newFeed(reference);
-
- feedResource.setCount(feed.getCount());
-
- final URI next = feed.getNext();
- if (next != null) {
- feedResource.setNext(next);
- }
-
- for (ODataEntity entity : feed.getEntities()) {
- feedResource.getEntries().add(getEntry(entity, ResourceFactory.entryClassForFeed(reference)));
- }
-
- return feedResource;
- }
-
- @Override
- public Entry getEntry(final ODataEntity entity, final Class<? extends Entry> reference) {
- return getEntry(entity, reference, true);
- }
-
- @Override
- public Entry getEntry(final ODataEntity entity, final Class<? extends Entry> reference, final boolean setType) {
- final Entry entry = ResourceFactory.newEntry(reference);
- entry.setType(entity.getName());
-
- // -------------------------------------------------------------
- // Add edit and self link
- // -------------------------------------------------------------
- final URI editLink = entity.getEditLink();
- if (editLink != null) {
- final LinkImpl entryEditLink = new LinkImpl();
- entryEditLink.setTitle(entity.getName());
- entryEditLink.setHref(editLink.toASCIIString());
- entryEditLink.setRel(Constants.EDIT_LINK_REL);
- entry.setEditLink(entryEditLink);
- }
-
- if (entity.isReadOnly()) {
- final LinkImpl entrySelfLink = new LinkImpl();
- entrySelfLink.setTitle(entity.getName());
- entrySelfLink.setHref(entity.getLink().toASCIIString());
- entrySelfLink.setRel(Constants.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.getNavigationLinks().add(getLink(link,
- ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
- }
- // -------------------------------------------------------------
-
- // -------------------------------------------------------------
- // Append edit-media links
- // -------------------------------------------------------------
- for (ODataLink link : entity.getEditMediaLinks()) {
- LOG.debug("Append edit-media link\n{}", link);
- entry.getMediaEditLinks().add(getLink(link,
- ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
- }
- // -------------------------------------------------------------
-
- // -------------------------------------------------------------
- // Append association links
- // -------------------------------------------------------------
- for (ODataLink link : entity.getAssociationLinks()) {
- LOG.debug("Append association link\n{}", link);
- entry.getAssociationLinks().add(getLink(link,
- ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
- }
- // -------------------------------------------------------------
-
- if (entity.isMediaEntity()) {
- entry.setMediaContentSource(entity.getMediaContentSource());
- entry.setMediaContentType(entity.getMediaContentType());
- }
-
- for (ODataProperty property : entity.getProperties()) {
- entry.getProperties().add(getProperty(property, reference, setType));
- }
-
- return entry;
- }
-
- @Override
- public Link getLink(final ODataLink link, boolean isXML) {
- final Link linkResource = new LinkImpl();
- linkResource.setRel(link.getRel());
- linkResource.setTitle(link.getName());
- linkResource.setHref(link.getLink() == null ? null : link.getLink().toASCIIString());
- linkResource.setType(link.getType().toString());
- linkResource.setMediaETag(link.getMediaETag());
-
- if (link instanceof ODataInlineEntity) {
- // append inline entity
- final ODataEntity inlineEntity = ((ODataInlineEntity) link).getEntity();
- LOG.debug("Append in-line entity\n{}", inlineEntity);
-
- linkResource.setInlineEntry(getEntry(inlineEntity, ResourceFactory.entryClassForFormat(isXML)));
- } 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.feedClassForFormat(isXML)));
- }
-
- return linkResource;
- }
-
- @Override
- public Property getProperty(final ODataProperty property, final Class<? extends Entry> reference,
- final boolean setType) {
-
- final Property propertyResource = ResourceFactory.newProperty(reference);
- propertyResource.setName(property.getName());
- propertyResource.setValue(getValue(property.getValue(), reference, setType));
-
- if (setType) {
- if (property.hasPrimitiveValue()) {
- propertyResource.setType(property.getPrimitiveValue().getType().toString());
- } else if (property.hasComplexValue()) {
- propertyResource.setType(property.getComplexValue().getType());
- } else if (property.hasCollectionValue()) {
- propertyResource.setType(property.getCollectionValue().getType());
- }
- }
-
- return propertyResource;
- }
-
- private Value getValue(final ODataValue value, final Class<? extends Entry> reference, final boolean setType) {
- Value valueResource = null;
-
- if (value == null) {
- valueResource = new NullValueImpl();
- } else if (value.isPrimitive()) {
- valueResource = new PrimitiveValueImpl(value.asPrimitive().toString());
- } else if (value.isGeospatial()) {
- valueResource = new GeospatialValueImpl(value.asGeospatial().toValue());
- } else if (value.isComplex()) {
- final ODataComplexValue _value = value.asComplex();
- valueResource = new ComplexValueImpl();
-
- for (final Iterator<ODataProperty> itor = _value.iterator(); itor.hasNext();) {
- valueResource.asComplex().get().add(getProperty(itor.next(), reference, setType));
- }
- } else if (value.isCollection()) {
- final ODataCollectionValue _value = value.asCollection();
- valueResource = new CollectionValueImpl();
-
- for (final Iterator<ODataValue> itor = _value.iterator(); itor.hasNext();) {
- valueResource.asCollection().get().add(getValue(itor.next(), reference, setType));
- }
- }
-
- return valueResource;
- }
-
- @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("Feed -> 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.getOperations().add(operation);
- }
-
- if (resource.isMediaEntry()) {
- entity.setMediaEntity(true);
- entity.setMediaContentSource(resource.getMediaContentSource());
- entity.setMediaContentType(resource.getMediaContentType());
- }
-
- for (Property property : resource.getProperties()) {
- entity.getProperties().add(getODataProperty(property));
- }
-
- return entity;
- }
-
- @Override
- public ODataProperty getODataProperty(final Property property) {
- return new ODataProperty(property.getName(), getODataValue(property));
- }
-
- private ODataValue getODataValue(final Property resource) {
- ODataValue value = null;
-
- if (resource.getValue().isSimple()) {
- value = client.getPrimitiveValueBuilder().
- setText(resource.getValue().asSimple().get()).
- setType(resource.getType() == null
- ? null
- : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), resource.getType())).build();
- } else if (resource.getValue().isGeospatial()) {
- value = client.getGeospatialValueBuilder().
- setValue(resource.getValue().asGeospatial().get()).
- setType(resource.getType() == null
- || EdmPrimitiveTypeKind.Geography.getFullQualifiedName().toString().equals(resource.getType())
- || EdmPrimitiveTypeKind.Geometry.getFullQualifiedName().toString().equals(resource.getType())
- ? null
- : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), resource.getType())).build();
- } else if (resource.getValue().isComplex()) {
- value = new ODataComplexValue(resource.getType());
-
- for (Property property : resource.getValue().asComplex().get()) {
- value.asComplex().add(getODataProperty(property));
- }
- } else if (resource.getValue().isCollection()) {
- value = new ODataCollectionValue(resource.getType());
-
- for (Value _value : resource.getValue().asCollection().get()) {
- final JSONPropertyImpl fake = new JSONPropertyImpl();
- fake.setValue(_value);
- value.asCollection().add(getODataValue(fake));
- }
- }
-
- return value;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataDeserializer.java
deleted file mode 100644
index 67acc09..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataDeserializer.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.client.core.op.impl;
-
-import java.io.InputStream;
-import org.apache.olingo.client.api.CommonODataClient;
-import org.apache.olingo.client.api.data.Entry;
-import org.apache.olingo.client.api.data.ODataError;
-import org.apache.olingo.client.api.data.Feed;
-import org.apache.olingo.client.api.data.Property;
-import org.apache.olingo.client.api.format.ODataFormat;
-import org.apache.olingo.client.api.format.ODataPubFormat;
-import org.apache.olingo.client.api.op.CommonODataDeserializer;
-import org.apache.olingo.client.core.data.AtomDeserializer;
-import org.apache.olingo.client.core.data.AtomEntryImpl;
-import org.apache.olingo.client.core.data.AtomFeedImpl;
-import org.apache.olingo.client.core.data.AtomPropertyImpl;
-import org.apache.olingo.client.core.data.JSONEntryImpl;
-import org.apache.olingo.client.core.data.JSONErrorBundle;
-import org.apache.olingo.client.core.data.JSONFeedImpl;
-import org.apache.olingo.client.core.data.JSONPropertyImpl;
-import org.apache.olingo.client.core.data.XMLErrorImpl;
-
-public abstract class AbstractODataDeserializer extends AbstractJacksonTool implements CommonODataDeserializer {
-
- private static final long serialVersionUID = -4244158979195609909L;
-
- private final AtomDeserializer atomDeserializer;
-
- public AbstractODataDeserializer(final CommonODataClient client) {
- super(client);
-
- this.atomDeserializer = new AtomDeserializer(client.getServiceVersion());
- }
-
- @Override
- public Feed toFeed(final InputStream input, final ODataPubFormat format) {
- return format == ODataPubFormat.ATOM
- ? atom(input, AtomFeedImpl.class)
- : json(input, JSONFeedImpl.class);
- }
-
- @Override
- public Entry toEntry(final InputStream input, final ODataPubFormat format) {
- return format == ODataPubFormat.ATOM
- ? atom(input, AtomEntryImpl.class)
- : json(input, JSONEntryImpl.class);
- }
-
- @Override
- public Property toProperty(final InputStream input, final ODataFormat format) {
- return format == ODataFormat.XML
- ? atom(input, AtomPropertyImpl.class)
- : json(input, JSONPropertyImpl.class);
- }
-
- @Override
- public ODataError toError(final InputStream input, final boolean isXML) {
- return isXML
- ? xml(input, XMLErrorImpl.class)
- : json(input, JSONErrorBundle.class).getError();
- }
-
- /*
- * ------------------ Protected methods ------------------
- */
- protected <T> T xml(final InputStream input, final Class<T> reference) {
- try {
- return getXmlMapper().readValue(input, reference);
- } catch (Exception e) {
- throw new IllegalArgumentException("While deserializing " + reference.getName(), e);
- }
- }
-
- protected <T> T atom(final InputStream input, final Class<T> reference) {
- try {
- return atomDeserializer.read(input, reference);
- } catch (Exception e) {
- throw new IllegalArgumentException("While deserializing " + reference.getName(), e);
- }
- }
-
- protected <T> T json(final InputStream input, final Class<T> reference) {
- try {
- return getObjectMapper().readValue(input, reference);
- } catch (Exception e) {
- throw new IllegalArgumentException("While deserializing " + reference.getName(), e);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c876e670/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataReader.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataReader.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataReader.java
deleted file mode 100644
index 596e8fd..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataReader.java
+++ /dev/null
@@ -1,117 +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.op.impl;
-
-import java.io.InputStream;
-import org.apache.commons.io.IOUtils;
-import org.apache.olingo.client.api.CommonODataClient;
-import org.apache.olingo.client.api.data.ODataError;
-import org.apache.olingo.client.api.data.Property;
-import org.apache.olingo.client.api.domain.ODataEntity;
-import org.apache.olingo.client.api.domain.ODataEntitySet;
-import org.apache.olingo.client.api.domain.ODataEntitySetIterator;
-import org.apache.olingo.client.api.domain.ODataProperty;
-import org.apache.olingo.client.api.domain.ODataServiceDocument;
-import org.apache.olingo.client.api.domain.ODataValue;
-import org.apache.olingo.client.api.edm.xml.XMLMetadata;
-import org.apache.olingo.client.api.format.ODataFormat;
-import org.apache.olingo.client.api.format.ODataPubFormat;
-import org.apache.olingo.client.api.format.ODataValueFormat;
-import org.apache.olingo.client.api.op.CommonODataReader;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class AbstractODataReader implements CommonODataReader {
-
- private static final long serialVersionUID = -1988865870981207079L;
-
- /**
- * Logger.
- */
- protected static final Logger LOG = LoggerFactory.getLogger(AbstractODataReader.class);
-
- protected final CommonODataClient client;
-
- protected AbstractODataReader(final CommonODataClient client) {
- this.client = client;
- }
-
- @Override
- public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format) {
- return client.getBinder().getODataEntitySet(client.getDeserializer().toFeed(input, format));
- }
-
- @Override
- public ODataEntity readEntity(final InputStream input, final ODataPubFormat format) {
- return client.getBinder().getODataEntity(client.getDeserializer().toEntry(input, format));
- }
-
- @Override
- public ODataProperty readProperty(final InputStream input, final ODataFormat format) {
- final Property property = client.getDeserializer().toProperty(input, format);
- return client.getBinder().getODataProperty(property);
- }
-
- @Override
- public ODataError readError(final InputStream inputStream, final boolean isXML) {
- return client.getDeserializer().toError(inputStream, isXML);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public <T> T read(final InputStream src, final String format, final Class<T> reference) {
- Object res;
-
- try {
- if (ODataEntitySetIterator.class.isAssignableFrom(reference)) {
- res = new ODataEntitySetIterator(client, src, ODataPubFormat.fromString(format));
- } else if (ODataEntitySet.class.isAssignableFrom(reference)) {
- res = readEntitySet(src, ODataPubFormat.fromString(format));
- } else if (ODataEntity.class.isAssignableFrom(reference)) {
- res = readEntity(src, ODataPubFormat.fromString(format));
- } else if (ODataProperty.class.isAssignableFrom(reference)) {
- res = readProperty(src, ODataFormat.fromString(format));
- } else if (ODataValue.class.isAssignableFrom(reference)) {
- res = client.getPrimitiveValueBuilder().
- setType(ODataValueFormat.fromString(format) == ODataValueFormat.TEXT
- ? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
- setText(IOUtils.toString(src)).
- build();
- } else if (XMLMetadata.class.isAssignableFrom(reference)) {
- res = readMetadata(src);
- } else if (ODataServiceDocument.class.isAssignableFrom(reference)) {
- res = readServiceDocument(src, ODataFormat.fromString(format));
- } else if (ODataError.class.isAssignableFrom(reference)) {
- res = readError(src, !format.toString().contains("json"));
- } else {
- throw new IllegalArgumentException("Invalid reference type " + reference);
- }
- } catch (Exception e) {
- LOG.warn("Cast error", e);
- res = null;
- } finally {
- if (!ODataEntitySetIterator.class.isAssignableFrom(reference)) {
- IOUtils.closeQuietly(src);
- }
- }
-
- return (T) res;
- }
-}