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/10 10:49:56 UTC
[4/6] Merge from master
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/f70d3f0b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/PropertyDeserializer.java
----------------------------------------------------------------------
diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/PropertyDeserializer.java
index 0000000,89bdfcf..ce8e4aa
mode 000000,100644..100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/PropertyDeserializer.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/PropertyDeserializer.java
@@@ -1,0 -1,104 +1,129 @@@
+ /*
+ * 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.edm.xml;
+
+ 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.v4.AnnotationImpl;
+ import org.apache.olingo.client.core.op.impl.AbstractEdmDeserializer;
-import org.apache.olingo.commons.api.edm.constants.ConcurrencyMode;
+ import org.apache.olingo.commons.api.edm.constants.EdmContentKind;
+ import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.api.edm.constants.StoreGeneratedPattern;
++import org.apache.olingo.odata4.client.api.edm.ConcurrencyMode;
++import org.apache.olingo.odata4.client.api.edm.StoreGeneratedPattern;
+
+ public class PropertyDeserializer extends AbstractEdmDeserializer<AbstractProperty> {
+
+ @Override
+ protected AbstractProperty doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ final AbstractProperty property = ODataServiceVersion.V30 == client.getServiceVersion()
+ ? new org.apache.olingo.client.core.edm.xml.v3.PropertyImpl()
+ : new org.apache.olingo.client.core.edm.xml.v4.PropertyImpl();
+
+ for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
+ final JsonToken token = jp.getCurrentToken();
+ if (token == JsonToken.FIELD_NAME) {
+ if ("Name".equals(jp.getCurrentName())) {
+ property.setName(jp.nextTextValue());
+ } else if ("Type".equals(jp.getCurrentName())) {
+ property.setType(jp.nextTextValue());
+ } else if ("Nullable".equals(jp.getCurrentName())) {
+ property.setNullable(BooleanUtils.toBoolean(jp.nextTextValue()));
+ } else if ("DefaultValue".equals(jp.getCurrentName())) {
+ property.setDefaultValue(jp.nextTextValue());
+ } else if ("MaxLength".equals(jp.getCurrentName())) {
+ final String maxLenght = jp.nextTextValue();
+ property.setMaxLength(maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght));
+ } else if ("FixedLength".equals(jp.getCurrentName())) {
- property.setFixedLength(BooleanUtils.toBoolean(jp.nextTextValue()));
++ if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
++ ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
++ setFixedLength(BooleanUtils.toBoolean(jp.nextTextValue()));
++ }
+ } else if ("Precision".equals(jp.getCurrentName())) {
+ property.setPrecision(Integer.valueOf(jp.nextTextValue()));
+ } else if ("Scale".equals(jp.getCurrentName())) {
- property.setScale(Integer.valueOf(jp.nextTextValue()));
++ final String scale = jp.nextTextValue();
++ property.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale));
+ } else if ("Unicode".equals(jp.getCurrentName())) {
+ property.setUnicode(BooleanUtils.toBoolean(jp.nextTextValue()));
+ } else if ("Collation".equals(jp.getCurrentName())) {
- property.setCollation(jp.nextTextValue());
++ if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
++ ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
++ setCollation(jp.nextTextValue());
++ }
+ } else if ("SRID".equals(jp.getCurrentName())) {
+ property.setSrid(jp.nextTextValue());
+ } else if ("ConcurrencyMode".equals(jp.getCurrentName())) {
- property.setConcurrencyMode(ConcurrencyMode.valueOf(jp.nextTextValue()));
++ if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
++ ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
++ setConcurrencyMode(ConcurrencyMode.valueOf(jp.nextTextValue()));
++ }
+ } else if ("StoreGeneratedPattern".equals(jp.getCurrentName())) {
- property.setStoreGeneratedPattern(StoreGeneratedPattern.valueOf(jp.nextTextValue()));
++ if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
++ ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
++ setStoreGeneratedPattern(StoreGeneratedPattern.valueOf(jp.nextTextValue()));
++ }
+ } else if ("FC_SourcePath".equals(jp.getCurrentName())) {
- ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
- setFcSourcePath(jp.nextTextValue());
++ if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
++ ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
++ setFcSourcePath(jp.nextTextValue());
++ }
+ } else if ("FC_TargetPath".equals(jp.getCurrentName())) {
- ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
- setFcTargetPath(jp.nextTextValue());
++ if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
++ ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
++ setFcTargetPath(jp.nextTextValue());
++ }
+ } else if ("FC_ContentKind".equals(jp.getCurrentName())) {
- ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
- setFcContentKind(EdmContentKind.valueOf(jp.nextTextValue()));
++ if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
++ ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
++ setFcContentKind(EdmContentKind.valueOf(jp.nextTextValue()));
++ }
+ } else if ("FC_NsPrefix".equals(jp.getCurrentName())) {
- ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
- setFcNSPrefix(jp.nextTextValue());
++ if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
++ ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
++ setFcNSPrefix(jp.nextTextValue());
++ }
+ } else if ("FC_NsUri".equals(jp.getCurrentName())) {
- ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
- setFcNSURI(jp.nextTextValue());
++ if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
++ ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
++ setFcNSURI(jp.nextTextValue());
++ }
+ } else if ("FC_KeepInContent".equals(jp.getCurrentName())) {
- ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
- setFcKeepInContent(BooleanUtils.toBoolean(jp.nextTextValue()));
++ if (property instanceof org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) {
++ ((org.apache.olingo.client.core.edm.xml.v3.PropertyImpl) property).
++ setFcKeepInContent(BooleanUtils.toBoolean(jp.nextTextValue()));
++ }
+ } else if ("Annotation".equals(jp.getCurrentName())) {
+ ((org.apache.olingo.client.core.edm.xml.v4.PropertyImpl) property).
+ setAnnotation(jp.readValueAs(AnnotationImpl.class));
+ }
+ }
+ }
+
+ return property;
+ }
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/f70d3f0b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v3/PropertyImpl.java
----------------------------------------------------------------------
diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v3/PropertyImpl.java
index 0000000,c2fc43c..53b3230
mode 000000,100644..100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v3/PropertyImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v3/PropertyImpl.java
@@@ -1,0 -1,95 +1,141 @@@
+ /*
+ * 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.edm.xml.v3;
+
+ import org.apache.olingo.client.api.edm.xml.v3.Property;
+ import org.apache.olingo.client.core.edm.xml.AbstractProperty;
+ import org.apache.olingo.commons.api.edm.constants.EdmContentKind;
++import org.apache.olingo.odata4.client.api.edm.ConcurrencyMode;
++import org.apache.olingo.odata4.client.api.edm.StoreGeneratedPattern;
+
+ public class PropertyImpl extends AbstractProperty implements Property {
+
+ private static final long serialVersionUID = 6224524803474652100L;
+
++ private String collation;
++
++ private boolean fixedLength;
++
++ private ConcurrencyMode concurrencyMode;
++
++ private StoreGeneratedPattern storeGeneratedPattern = StoreGeneratedPattern.None;
++
+ private String fcSourcePath;
+
+ private String fcTargetPath;
+
+ private EdmContentKind fcContentKind = EdmContentKind.text;
+
+ private String fcNSPrefix;
+
+ private String fcNSURI;
+
+ private boolean fcKeepInContent = true;
+
+ @Override
++ public boolean isFixedLength() {
++ return fixedLength;
++ }
++
++ public void setFixedLength(final boolean fixedLength) {
++ this.fixedLength = fixedLength;
++ }
++
++ @Override
++ public String getCollation() {
++ return collation;
++ }
++
++ public void setCollation(final String collation) {
++ this.collation = collation;
++ }
++
++ @Override
++ public ConcurrencyMode getConcurrencyMode() {
++ return concurrencyMode;
++ }
++
++ public void setConcurrencyMode(final ConcurrencyMode concurrencyMode) {
++ this.concurrencyMode = concurrencyMode;
++ }
++
++ @Override
++ public StoreGeneratedPattern getStoreGeneratedPattern() {
++ return storeGeneratedPattern;
++ }
++
++ public void setStoreGeneratedPattern(final StoreGeneratedPattern storeGeneratedPattern) {
++ this.storeGeneratedPattern = storeGeneratedPattern;
++ }
++
++ @Override
+ public String getFcSourcePath() {
+ return fcSourcePath;
+ }
+
+ public void setFcSourcePath(final String fcSourcePath) {
+ this.fcSourcePath = fcSourcePath;
+ }
+
+ @Override
+ public String getFcTargetPath() {
+ return fcTargetPath;
+ }
+
+ public void setFcTargetPath(final String fcTargetPath) {
+ this.fcTargetPath = fcTargetPath;
+ }
+
+ @Override
+ public EdmContentKind getFcContentKind() {
+ return fcContentKind;
+ }
+
+ public void setFcContentKind(final EdmContentKind fcContentKind) {
+ this.fcContentKind = fcContentKind;
+ }
+
+ @Override
+ public String getFcNSPrefix() {
+ return fcNSPrefix;
+ }
+
+ public void setFcNSPrefix(final String fcNSPrefix) {
+ this.fcNSPrefix = fcNSPrefix;
+ }
+
+ @Override
+ public String getFcNSURI() {
+ return fcNSURI;
+ }
+
+ public void setFcNSURI(final String fcNSURI) {
+ this.fcNSURI = fcNSURI;
+ }
+
+ @Override
+ public boolean isFcKeepInContent() {
+ return fcKeepInContent;
+ }
+
+ public void setFcKeepInContent(final boolean fcKeepInContent) {
+ this.fcKeepInContent = fcKeepInContent;
+ }
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/f70d3f0b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/ReturnTypeDeserializer.java
----------------------------------------------------------------------
diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/ReturnTypeDeserializer.java
index 0000000,f51a850..89c4070
mode 000000,100644..100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/ReturnTypeDeserializer.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/ReturnTypeDeserializer.java
@@@ -1,0 -1,62 +1,63 @@@
+ /*
+ * 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.edm.xml.v4;
+
+ 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.op.impl.AbstractEdmDeserializer;
+
+ public class ReturnTypeDeserializer extends AbstractEdmDeserializer<ReturnTypeImpl> {
+
+ @Override
+ protected ReturnTypeImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ final ReturnTypeImpl returnType = new ReturnTypeImpl();
+
+ for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
+ final JsonToken token = jp.getCurrentToken();
+ if (token == JsonToken.FIELD_NAME) {
+ if ("Type".equals(jp.getCurrentName())) {
+ returnType.setType(jp.nextTextValue());
+ } else if ("Nullable".equals(jp.getCurrentName())) {
+ returnType.setNullable(BooleanUtils.toBoolean(jp.nextTextValue()));
+ } else if ("MaxLength".equals(jp.getCurrentName())) {
+ final String maxLenght = jp.nextTextValue();
+ returnType.setMaxLength(maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght));
+ } else if ("Precision".equals(jp.getCurrentName())) {
+ returnType.setPrecision(Integer.valueOf(jp.nextTextValue()));
+ } else if ("Scale".equals(jp.getCurrentName())) {
- returnType.setScale(Integer.valueOf(jp.nextTextValue()));
++ final String scale = jp.nextTextValue();
++ returnType.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale));
+ } else if ("SRID".equals(jp.getCurrentName())) {
+ returnType.setSrid(jp.nextTextValue());
+ }
+ }
+ }
+
+ return returnType;
+ }
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/f70d3f0b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/TermDeserializer.java
----------------------------------------------------------------------
diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/TermDeserializer.java
index 0000000,9d4e803..f1b756e
mode 000000,100644..100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/TermDeserializer.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/TermDeserializer.java
@@@ -1,0 -1,77 +1,78 @@@
+ /*
+ * 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.edm.xml.v4;
+
+ 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.commons.lang3.StringUtils;
+ import org.apache.olingo.client.api.edm.xml.v4.CSDLElement;
+ import org.apache.olingo.client.core.op.impl.AbstractEdmDeserializer;
+
+ public class TermDeserializer extends AbstractEdmDeserializer<TermImpl> {
+
+ @Override
+ protected TermImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ final TermImpl term = new TermImpl();
+
+ for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
+ final JsonToken token = jp.getCurrentToken();
+ if (token == JsonToken.FIELD_NAME) {
+ if ("Name".equals(jp.getCurrentName())) {
+ term.setName(jp.nextTextValue());
+ } else if ("Type".equals(jp.getCurrentName())) {
+ term.setType(jp.nextTextValue());
+ } else if ("BaseTerm".equals(jp.getCurrentName())) {
+ term.setBaseTerm(jp.nextTextValue());
+ } else if ("DefaultValue".equals(jp.getCurrentName())) {
+ term.setDefaultValue(jp.nextTextValue());
+ } else if ("Nullable".equals(jp.getCurrentName())) {
+ term.setNullable(BooleanUtils.toBoolean(jp.nextTextValue()));
+ } else if ("MaxLength".equals(jp.getCurrentName())) {
+ final String maxLenght = jp.nextTextValue();
+ term.setMaxLength(maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght));
+ } else if ("Precision".equals(jp.getCurrentName())) {
+ term.setPrecision(Integer.valueOf(jp.nextTextValue()));
+ } else if ("Scale".equals(jp.getCurrentName())) {
- term.setScale(Integer.valueOf(jp.nextTextValue()));
++ final String scale = jp.nextTextValue();
++ term.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale));
+ } else if ("SRID".equals(jp.getCurrentName())) {
+ term.setSrid(jp.nextTextValue());
+ } else if ("AppliesTo".equals(jp.getCurrentName())) {
+ for (String split : StringUtils.split(jp.nextTextValue())) {
+ term.getAppliesTo().add(CSDLElement.valueOf(split));
+ }
+ } else if ("Annotation".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ term.setAnnotation(jp.readValueAs(AnnotationImpl.class));
+ }
+ }
+ }
+
+ return term;
+ }
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/f70d3f0b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/TypeDefinitionDeserializer.java
----------------------------------------------------------------------
diff --cc lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/TypeDefinitionDeserializer.java
index 0000000,f951c77..28dee4d
mode 000000,100644..100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/TypeDefinitionDeserializer.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/v4/TypeDefinitionDeserializer.java
@@@ -1,0 -1,66 +1,67 @@@
+ /*
+ * 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.edm.xml.v4;
+
+ 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.op.impl.AbstractEdmDeserializer;
+
+ public class TypeDefinitionDeserializer extends AbstractEdmDeserializer<TypeDefinitionImpl> {
+
+ @Override
+ protected TypeDefinitionImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ final TypeDefinitionImpl typeDefinition = new TypeDefinitionImpl();
+
+ for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
+ final JsonToken token = jp.getCurrentToken();
+ if (token == JsonToken.FIELD_NAME) {
+ if ("Name".equals(jp.getCurrentName())) {
+ typeDefinition.setName(jp.nextTextValue());
+ } else if ("UnderlyingType".equals(jp.getCurrentName())) {
+ typeDefinition.setUnderlyingType(jp.nextTextValue());
+ } else if ("MaxLength".equals(jp.getCurrentName())) {
+ typeDefinition.setMaxLength(jp.nextIntValue(0));
+ } else if ("Unicode".equals(jp.getCurrentName())) {
+ typeDefinition.setUnicode(BooleanUtils.toBoolean(jp.nextTextValue()));
+ } else if ("Precision".equals(jp.getCurrentName())) {
+ typeDefinition.setPrecision(jp.nextIntValue(0));
+ } else if ("Scale".equals(jp.getCurrentName())) {
- typeDefinition.setScale(jp.nextIntValue(0));
++ final String scale = jp.nextTextValue();
++ typeDefinition.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale));
+ } else if ("SRID".equals(jp.getCurrentName())) {
+ typeDefinition.setSrid(jp.nextTextValue());
+ } else if ("Annotation".equals(jp.getCurrentName())) {
+ jp.nextToken();
+ typeDefinition.getAnnotations().add(jp.readValueAs(AnnotationImpl.class));
+ }
+ }
+ }
+
+ return typeDefinition;
+ }
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/f70d3f0b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java
----------------------------------------------------------------------
diff --cc lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java
index 0000000,f183ff3..78e925a
mode 000000,100644..100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java
@@@ -1,0 -1,286 +1,282 @@@
+ /*
+ * 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.v4;
+
+ import static org.junit.Assert.assertEquals;
+ import static org.junit.Assert.assertNotNull;
+ import static org.junit.Assert.assertNull;
+ import static org.junit.Assert.assertFalse;
+ import static org.junit.Assert.assertTrue;
+
+ import org.apache.olingo.client.api.ODataV4Client;
+ import org.apache.olingo.client.api.edm.xml.v4.Annotation;
+ import org.apache.olingo.client.api.edm.xml.v4.Annotations;
+ import org.apache.olingo.client.api.edm.xml.v4.ComplexType;
+ import org.apache.olingo.client.api.edm.xml.v4.EntityContainer;
+ import org.apache.olingo.client.api.edm.xml.v4.EntityType;
+ import org.apache.olingo.client.api.edm.xml.v4.Function;
+ import org.apache.olingo.client.api.edm.xml.v4.FunctionImport;
+ import org.apache.olingo.client.api.edm.xml.v4.Schema;
+ import org.apache.olingo.client.api.edm.xml.v4.Singleton;
+ import org.apache.olingo.client.api.edm.xml.v4.XMLMetadata;
+ import org.apache.olingo.client.core.AbstractTest;
+ import org.apache.olingo.client.core.edm.xml.v4.annotation.Apply;
+ import org.apache.olingo.client.core.edm.xml.v4.annotation.Collection;
+ import org.apache.olingo.client.core.edm.xml.v4.annotation.ConstExprConstructImpl;
+ import org.apache.olingo.client.core.edm.xml.v4.annotation.Path;
+ import org.apache.olingo.commons.api.edm.Edm;
+ import org.apache.olingo.commons.api.edm.EdmAction;
+ import org.apache.olingo.commons.api.edm.EdmComplexType;
+ import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+ import org.apache.olingo.commons.api.edm.EdmEntitySet;
+ import org.apache.olingo.commons.api.edm.EdmEntityType;
+ import org.apache.olingo.commons.api.edm.EdmEnumType;
+ import org.apache.olingo.commons.api.edm.EdmFunction;
+ import org.apache.olingo.commons.api.edm.EdmFunctionImport;
+ import org.apache.olingo.commons.api.edm.EdmFunctionImportInfo;
+ import org.apache.olingo.commons.api.edm.FullQualifiedName;
+ import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.commons.api.edm.constants.StoreGeneratedPattern;
+ import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+ import org.junit.Test;
+
+ public class MetadataTest extends AbstractTest {
+
+ @Override
+ protected ODataV4Client getClient() {
+ return v4Client;
+ }
+
+ @Test
+ public void parse() {
+ final Edm edm = getClient().getReader().
+ readMetadata(getClass().getResourceAsStream("metadata.xml"));
+ assertNotNull(edm);
+
+ // 1. Enum
+ final EdmEnumType responseEnumType = edm.getEnumType(
+ new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "ResponseType"));
+ assertNotNull(responseEnumType);
+ assertEquals(6, responseEnumType.getMemberNames().size());
+ assertEquals("3", responseEnumType.getMember("Accepted").getValue());
+ assertEquals(EdmTypeKind.ENUM, responseEnumType.getKind());
+
+ // 2. Complex
+ final EdmComplexType responseStatus = edm.getComplexType(
+ new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "ResponseStatus"));
+ assertNotNull(responseStatus);
+ assertTrue(responseStatus.getNavigationPropertyNames().isEmpty());
+ assertEquals("Recipient", responseStatus.getBaseType().getName());
+ assertEquals(EdmPrimitiveTypeKind.DateTimeOffset.getEdmPrimitiveTypeInstance(),
+ responseStatus.getProperty("Time").getType());
+
+ // 3. Entity
+ final EdmEntityType user = edm.getEntityType(
+ new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "User"));
+ assertNotNull(user);
+ final EdmEntityType entity = edm.getEntityType(
+ new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Entity"));
+ assertEquals(entity, user.getBaseType());
+ assertFalse(user.getPropertyNames().isEmpty());
+ assertFalse(user.getNavigationPropertyNames().isEmpty());
+ final EdmEntityType folder = edm.getEntityType(
+ new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Folder"));
+ assertEquals(folder, user.getNavigationProperty("Inbox").getType());
+
+ // 4. Action
+ final EdmAction move = edm.getAction(
+ new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Move"),
+ new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Folder"),
+ false);
+ assertNotNull(move);
+ assertTrue(move.isBound());
+ assertEquals(2, move.getParameterNames().size());
+ assertEquals(
+ EdmPrimitiveTypeKind.String.getEdmPrimitiveTypeInstance(), move.getParameter("DestinationId").getType());
+
+ // 5. EntityContainer
+ final EdmEntityContainer container = edm.getEntityContainer(
+ new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "EntityContainer"));
+ assertNotNull(container);
+ final EdmEntitySet users = container.getEntitySet("Users");
+ assertNotNull(users);
+ assertEquals(edm.getEntityType(new FullQualifiedName(container.getNamespace(), "User")),
+ users.getEntityType());
+ assertEquals(container.getEntitySet("Folders"), users.getRelatedBindingTarget("Folders"));
+ }
+
+ @Test
+ public void demo() {
+ final XMLMetadata metadata = getClient().getDeserializer().
+ toMetadata(getClass().getResourceAsStream("demo-metadata.xml"));
+ assertNotNull(metadata);
+
+ assertFalse(metadata.getSchema(0).getAnnotationsList().isEmpty());
+ final Annotations annots = metadata.getSchema(0).getAnnotationsList("ODataDemo.DemoService/Suppliers");
+ assertNotNull(annots);
+ assertFalse(annots.getAnnotations().isEmpty());
+ assertEquals(ConstExprConstructImpl.Type.String,
+ annots.getAnnotation("Org.OData.Publication.V1.PrivacyPolicyUrl").getConstExpr().getType());
+ assertEquals("http://www.odata.org/",
+ annots.getAnnotation("Org.OData.Publication.V1.PrivacyPolicyUrl").getConstExpr().getValue());
+ }
+
+ @Test
+ public void multipleSchemas() {
+ final XMLMetadata metadata = getClient().getDeserializer().
+ toMetadata(getClass().getResourceAsStream("northwind-metadata.xml"));
+ assertNotNull(metadata);
+
+ final Schema first = metadata.getSchema("NorthwindModel");
+ assertNotNull(first);
+
+ final Schema second = metadata.getSchema("ODataWebExperimental.Northwind.Model");
+ assertNotNull(second);
+
- assertEquals(StoreGeneratedPattern.Identity,
- first.getEntityType("Category").getProperty("CategoryID").getStoreGeneratedPattern());
-
+ final EntityContainer entityContainer = second.getEntityContainer();
+ assertNotNull(entityContainer);
+ assertEquals("NorthwindEntities", entityContainer.getName());
+ assertTrue(entityContainer.isLazyLoadingEnabled());
+ }
+
+ /**
+ * Tests Example 85 from CSDL specification.
+ */
+ @Test
+ public void fromdoc1() {
+ final XMLMetadata metadata = getClient().getDeserializer().
+ toMetadata(getClass().getResourceAsStream("fromdoc1-metadata.xml"));
+ assertNotNull(metadata);
+
+ assertFalse(metadata.getReferences().isEmpty());
+ assertEquals("Org.OData.Measures.V1", metadata.getReferences().get(1).getIncludes().get(0).getNamespace());
+
+ final EntityType product = metadata.getSchema(0).getEntityType("Product");
+ assertTrue(product.isHasStream());
+ assertEquals("UoM.ISOCurrency", product.getProperty("Price").getAnnotation().getTerm());
+ assertEquals("Products", product.getNavigationProperty("Supplier").getPartner());
+
+ final EntityType category = metadata.getSchema(0).getEntityType("Category");
+ assertNotNull(category);
+
+ final ComplexType address = metadata.getSchema(0).getComplexType("Address");
+ assertFalse(address.getNavigationProperty("Country").getReferentialConstraints().isEmpty());
+ assertEquals("Name",
+ address.getNavigationProperty("Country").getReferentialConstraints().get(0).getReferencedProperty());
+
+ final Function productsByRating = metadata.getSchema(0).getFunctions("ProductsByRating").get(0);
+ assertNotNull(productsByRating.getParameter("Rating"));
+ assertEquals("Edm.Int32", productsByRating.getParameter("Rating").getType());
+ assertEquals("Collection(ODataDemo.Product)", productsByRating.getReturnType().getType());
+
+ final Singleton contoso = metadata.getSchema(0).getEntityContainer().getSingleton("Contoso");
+ assertNotNull(contoso);
+ assertFalse(contoso.getNavigationPropertyBindings().isEmpty());
+ assertEquals("Products", contoso.getNavigationPropertyBindings().get(0).getPath());
+
+ final FunctionImport functionImport = metadata.getSchema(0).getEntityContainer().
+ getFunctionImport("ProductsByRating");
+ assertNotNull(functionImport);
+ assertEquals(metadata.getSchema(0).getNamespace() + "." + productsByRating.getName(),
+ functionImport.getFunction());
+
+ // Now let's go high-level
+ final Edm edm = getClient().getReader().
+ readMetadata(getClass().getResourceAsStream("fromdoc1-metadata.xml"));
+ assertNotNull(edm);
+
+ final EdmFunctionImportInfo fiInfo = edm.getServiceMetadata().getFunctionImportInfos().get(0);
+ final EdmEntityContainer demoService = edm.getEntityContainer(
+ new FullQualifiedName(metadata.getSchema(0).getNamespace(), fiInfo.getEntityContainerName()));
+ assertNotNull(demoService);
+ final EdmFunctionImport fi = demoService.getFunctionImport(fiInfo.getFunctionImportName());
+ assertNotNull(fi);
+ assertEquals(demoService.getEntitySet("Products"), fi.getReturnedEntitySet());
+
+ final EdmFunction function = edm.getFunction(
+ new FullQualifiedName(metadata.getSchema(0).getNamespace(), "ProductsByRating"),
+ null, Boolean.FALSE, null);
+ assertNotNull(function);
+ assertEquals(function.getName(), fi.getFunction(null).getName());
+ assertEquals(function.getNamespace(), fi.getFunction(null).getNamespace());
+ assertEquals(function.getParameterNames(), fi.getFunction(null).getParameterNames());
+ assertEquals(function.getReturnType().getType().getName(),
+ fi.getFunction(null).getReturnType().getType().getName());
+ assertEquals(function.getReturnType().getType().getNamespace(),
+ fi.getFunction(null).getReturnType().getType().getNamespace());
+ }
+
+ /**
+ * Tests Example 86 from CSDL specification.
+ */
+ @Test
+ public void fromdoc2() {
+ final XMLMetadata metadata = getClient().getDeserializer().
+ toMetadata(getClass().getResourceAsStream("fromdoc2-metadata.xml"));
+ assertNotNull(metadata);
+
+ // Check displayName
+ final Annotation displayName = metadata.getSchema(0).getAnnotationsList("ODataDemo.Supplier").
+ getAnnotation("Vocabulary1.DisplayName");
+ assertNotNull(displayName);
+ assertNull(displayName.getConstExpr());
+ assertNotNull(displayName.getDynExpr());
+
+ assertTrue(displayName.getDynExpr() instanceof Apply);
+ final Apply apply = (Apply) displayName.getDynExpr();
+ assertEquals(Apply.CANONICAL_FUNCTION_CONCAT, apply.getFunction());
+ assertEquals(3, apply.getParameters().size());
+
+ final Path firstArg = new Path();
+ firstArg.setValue("Name");
+ assertEquals(firstArg, apply.getParameters().get(0));
+
+ final ConstExprConstructImpl secondArg = new ConstExprConstructImpl();
+ secondArg.setType(ConstExprConstructImpl.Type.String);
+ secondArg.setValue(" in ");
+ assertEquals(secondArg, apply.getParameters().get(1));
+
+ final Path thirdArg = new Path();
+ thirdArg.setValue("Address/CountryName");
+ assertEquals(thirdArg, apply.getParameters().get(2));
+
+ // Check Tags
+ final Annotation tags = metadata.getSchema(0).getAnnotationsList("ODataDemo.Product").
+ getAnnotation("Vocabulary1.Tags");
+ assertNotNull(tags);
+ assertNull(tags.getConstExpr());
+ assertNotNull(tags.getDynExpr());
+
+ assertTrue(tags.getDynExpr() instanceof Collection);
+ final Collection collection = (Collection) tags.getDynExpr();
+ assertEquals(1, collection.getItems().size());
+ assertEquals(ConstExprConstructImpl.Type.String, ((ConstExprConstructImpl) collection.getItems().get(0)).getType());
+ assertEquals("MasterData", ((ConstExprConstructImpl) collection.getItems().get(0)).getValue());
+ }
+
+ /**
+ * Various annotation examples taken from CSDL specification.
+ */
+ @Test
+ public void fromdoc3() {
+ final Edm metadata = getClient().getReader().
+ readMetadata(getClass().getResourceAsStream("fromdoc3-metadata.xml"));
+ assertNotNull(metadata);
+ }
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/f70d3f0b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveType.java
----------------------------------------------------------------------
diff --cc lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveType.java
index 0000000,7ce5c9a..d5b7e6d
mode 000000,100644..100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveType.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveType.java
@@@ -1,0 -1,166 +1,166 @@@
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ package org.apache.olingo.commons.api.edm;
+
+ /**
+ * EdmPrimitiveType is a primitive type as defined in the Entity Data Model (EDM).
+ * <br/>
+ * There are methods to convert EDM primitive types from and to Java objects, respectively. The following Java types are
+ * supported:
+ * <table frame="hsides" rules="groups">
+ * <thead>
+ * <tr><th>EDM primitive type</th><th>Java types</th></tr>
+ * </thead>
+ * <tbody>
+ * <tr><td>Binary</td><td>byte[], {@link Byte}[]</td></tr>
+ * <tr><td>Boolean</td><td>{@link Boolean}</td></tr>
+ * <tr><td>Byte</td><td>{@link Short}, {@link Byte}, {@link Integer}, {@link Long}, {@link java.math.BigInteger}
+ * </td></tr>
+ * <tr><td>Date</td><td>{@link java.util.Calendar}, {@link java.util.Date}, {@link Long}</td></tr>
+ * <tr><td>DateTimeOffset</td><td>{@link java.util.Calendar}, {@link java.util.Date}, {@link Long}</td></tr>
+ * <tr><td>Decimal</td><td>{@link java.math.BigDecimal}, {@link java.math.BigInteger}, {@link Double}, {@link Float},
+ * {@link Byte}, {@link Short}, {@link Integer}, {@link Long}</td></tr>
+ * <tr><td>Double</td><td>{@link Double}, {@link Float}, {@link java.math.BigDecimal}, {@link Byte}, {@link Short},
+ * {@link Integer}, {@link Long}</td></tr>
+ * <tr><td>Duration</td><td>{@link java.math.BigDecimal}, {@link java.math.BigInteger}, {@link Double}, {@link Float},
+ * {@link Byte}, {@link Short}, {@link Integer}, {@link Long}</td></tr>
+ * <tr><td>Guid</td><td>{@link java.util.UUID}</td></tr>
+ * <tr><td>Int16</td><td>{@link Short}, {@link Byte}, {@link Integer}, {@link Long}, {@link java.math.BigInteger}
+ * </td></tr>
+ * <tr><td>Int32</td><td>{@link Integer}, {@link Byte}, {@link Short}, {@link Long}, {@link java.math.BigInteger}
+ * </td></tr>
+ * <tr><td>Int64</td><td>{@link Long}, {@link Byte}, {@link Short}, {@link Integer}, {@link java.math.BigInteger}
+ * </td></tr>
+ * <tr><td>SByte</td><td>{@link Byte}, {@link Short}, {@link Integer}, {@link Long}, {@link java.math.BigInteger}
+ * </td></tr>
+ * <tr><td>Single</td><td>{@link Float}, {@link Double}, {@link java.math.BigDecimal}, {@link Byte}, {@link Short},
+ * {@link Integer}, {@link Long}</td></tr>
+ * <tr><td>String</td><td>{@link String}</td></tr>
+ * <tr><td>TimeOfDay</td><td>{@link java.util.Calendar}, {@link java.util.Date}, {@link Long}</td></tr>
+ * </tbody>
+ * </table>
+ * <p>
+ * The first Java type is the default type for the respective EDM primitive type.
+ * </p>
+ * <p>
+ * For all EDM primitive types, the <code>Nullable</code> facet is taken into account. For <code>Binary</code> and
+ * <code>String</code>, <code>MaxLength</code> is also applicable. For <code>String</code>, the facet
+ * <code>Unicode</code> is considered additionally. The EDM primitive types <code>DateTimeOffset</code>,
+ * <code>Decimal</code>, <code>Duration</code>, and <code>TimeOfDay</code> can have a <code>Precision</code> facet.
+ * Additionally, <code>Decimal</code> can have the facet <code>Scale</code>.
+ * </p>
+ */
+ public interface EdmPrimitiveType extends EdmType {
+
- static final String EDM_NAMESPACE = "Edm";
++ String EDM_NAMESPACE = "Edm";
+
- static final String SYSTEM_NAMESPACE = "System";
++ String SYSTEM_NAMESPACE = "System";
+
+ /**
+ * Checks type compatibility.
+ *
+ * @param primitiveType the {@link EdmPrimitiveType} to be tested for compatibility
+ * @return <code>true</code> if the provided type is compatible to this type
+ */
+ boolean isCompatible(EdmPrimitiveType primitiveType);
+
+ /**
+ * Returns the default Java type for this EDM primitive type as described in the documentation of
+ * {@link EdmPrimitiveType}.
+ *
+ * @return the default Java type
+ */
+ Class<?> getDefaultType();
+
+ /**
+ * Validates literal value.
+ *
+ * @param value the literal value
+ * @param isNullable whether the <code>null</code> value is allowed
+ * @param maxLength the maximum length
+ * @param precision the precision
+ * @param scale the scale
+ * @param isUnicode whether non-ASCII characters are allowed (relevant only for Edm.String)
+ * @return <code>true</code> if the validation is successful
+ */
+ boolean validate(String value,
+ Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode);
+
+ /**
+ * Converts literal representation of value to system data type.
+ *
+ * @param value the literal representation of value
+ * @param isNullable whether the <code>null</code> value is allowed
+ * @param maxLength the maximum length
+ * @param precision the precision
+ * @param scale the scale
+ * @param isUnicode whether non-ASCII characters are allowed (relevant only for Edm.String)
+ * @param returnType the class of the returned value; it must be one of the list in the documentation of
+ * {@link EdmPrimitiveType}
+ * @throws EdmPrimitiveTypeException
+ * @return the value as an instance of the class the parameter <code>returnType</code> indicates
+ */
+ <T> T valueOfString(String value,
+ Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode,
+ Class<T> returnType) throws EdmPrimitiveTypeException;
+
+ /**
+ * Converts system data type to literal representation of value.
+ * <p>
+ * Returns <code>null</code> if value is <code>null</code> and <code>null</code> is an allowed value.
+ * </p>
+ *
+ * @param value the Java value as Object; its type must be one of the list in the documentation of
+ * {@link EdmPrimitiveType}
+ * @param isNullable whether the <code>null</code> value is allowed
+ * @param maxLength the maximum length
+ * @param precision the precision
+ * @param scale the scale
+ * @param isUnicode whether non-ASCII characters are allowed (relevant only for Edm.String)
+ * @throws EdmPrimitiveTypeException
+ * @return literal representation as String
+ */
+ String valueToString(Object value,
+ Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode)
+ throws EdmPrimitiveTypeException;
+
+ /**
+ * Converts default literal representation to URI literal representation.
+ * <p>
+ * Returns <code>null</code> if the literal is <code>null</code>. Does not perform any validation.
+ * </p>
+ *
+ * @param literal the literal in default representation
+ * @return URI literal representation as String
+ */
+ String toUriLiteral(String literal);
+
+ /**
+ * Converts URI literal representation to default literal representation.
+ * <p>
+ * Returns <code>null</code> if the literal is <code>null</code>. Checks the presence of a required prefix and of
+ * required surrounding quotation marks but does not perform any further validation.
+ * </p>
+ *
+ * @param literal the literal in URI representation
+ * @return default literal representation as String
+ * @throws EdmPrimitiveTypeException if a required prefix or required surrounding quotation marks are missing
+ */
+ String fromUriLiteral(String literal) throws EdmPrimitiveTypeException;
+ }
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/f70d3f0b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDuration.java
----------------------------------------------------------------------
diff --cc lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDuration.java
index 0000000,fab05a7..87944c0
mode 000000,100644..100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDuration.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDuration.java
@@@ -1,0 -1,140 +1,141 @@@
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ package org.apache.olingo.commons.core.edm.primitivetype;
+
+ import java.math.BigDecimal;
+ import java.math.BigInteger;
+ import java.util.regex.Matcher;
+ import java.util.regex.Pattern;
+
+ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+
+ public final class EdmDuration extends SingletonPrimitiveType {
+
+ private static final Pattern PATTERN = Pattern.compile(
+ "[-+]?P(?:(\\p{Digit}+)D)?(?:T(?:(\\p{Digit}+)H)?(?:(\\p{Digit}+)M)?"
+ + "(?:(\\p{Digit}+(?:\\.(?:\\p{Digit}+?)0*)?)S)?)?");
+
+ private static final EdmDuration INSTANCE = new EdmDuration();
+
+ {
+ uriPrefix = "duration'";
+ uriSuffix = "'";
+ }
+
+ public static EdmDuration getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public Class<?> getDefaultType() {
+ return BigDecimal.class;
+ }
+
+ @Override
+ protected <T> T internalValueOfString(final String value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
++
+ final Matcher matcher = PATTERN.matcher(value);
+ if (!matcher.matches()
+ || matcher.group(1) == null && matcher.group(2) == null && matcher.group(3) == null
+ && matcher.group(4) == null) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)");
+ }
+
+ BigDecimal result = (matcher.group(1) == null ? BigDecimal.ZERO
+ : new BigDecimal(matcher.group(1)).multiply(BigDecimal.valueOf(24 * 60 * 60))).
+ add(matcher.group(2) == null ? BigDecimal.ZERO
+ : new BigDecimal(matcher.group(2)).multiply(BigDecimal.valueOf(60 * 60))).
+ add(matcher.group(3) == null ? BigDecimal.ZERO
+ : new BigDecimal(matcher.group(3)).multiply(BigDecimal.valueOf(60))).
+ add(matcher.group(4) == null ? BigDecimal.ZERO : new BigDecimal(matcher.group(4)));
+
+ if (result.scale() <= (precision == null ? 0 : precision)) {
- result = value.startsWith("-") ? result.negate() : result;
++ result = value.charAt(0) == '-' ? result.negate() : result;
+ } else {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(literal, facets)");
+ }
+
+ try {
+ return EdmDecimal.convertDecimal(result, returnType);
+ } catch (final IllegalArgumentException e) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e");
+ } catch (final ClassCastException e) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
+ }
+ }
+
+ @Override
+ protected <T> String internalValueToString(final T value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
+
+ BigDecimal valueDecimal;
+ if (value instanceof BigDecimal) {
+ valueDecimal = (BigDecimal) value;
+ } else if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
+ valueDecimal = BigDecimal.valueOf(((Number) value).longValue());
+ } else if (value instanceof BigInteger) {
+ valueDecimal = new BigDecimal((BigInteger) value);
+ } else {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
+ }
+
+ if (valueDecimal.scale() > (precision == null ? 0 : precision)) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)");
+ }
+
+ final StringBuilder result = new StringBuilder();
+ if (valueDecimal.signum() == -1) {
+ result.append('-');
+ valueDecimal = valueDecimal.negate();
+ }
+ result.append('P');
+ BigInteger seconds = valueDecimal.toBigInteger();
+ final BigInteger days = seconds.divide(BigInteger.valueOf(24 * 60 * 60));
+ if (!days.equals(BigInteger.ZERO)) {
+ result.append(days.toString());
+ result.append('D');
+ }
+ result.append('T');
+ seconds = seconds.subtract(days.multiply(BigInteger.valueOf(24 * 60 * 60)));
+ final BigInteger hours = seconds.divide(BigInteger.valueOf(60 * 60));
+ if (!hours.equals(BigInteger.ZERO)) {
+ result.append(hours.toString());
+ result.append('H');
+ }
+ seconds = seconds.subtract(hours.multiply(BigInteger.valueOf(60 * 60)));
+ final BigInteger minutes = seconds.divide(BigInteger.valueOf(60));
+ if (!minutes.equals(BigInteger.ZERO)) {
+ result.append(minutes.toString());
+ result.append('M');
+ }
+ result.append(valueDecimal.remainder(BigDecimal.valueOf(60)).toPlainString());
+ result.append('S');
+
+ return result.toString();
+ }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/f70d3f0b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java
----------------------------------------------------------------------
diff --cc lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java
index 0000000,b0deeef..e368607
mode 000000,100644..100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java
@@@ -1,0 -1,98 +1,95 @@@
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ package org.apache.olingo.commons.core.edm.primitivetype;
+
+ import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+ import org.apache.olingo.commons.api.edm.FullQualifiedName;
+
+ //TODO: Should we delete this typekind and use a facade?
+ public enum EdmPrimitiveTypeKind {
+
+ Binary, Boolean, Byte, Date, DateTimeOffset, Decimal, Double, Duration, Guid,
+ Int16, Int32, Int64, SByte, Single, String, TimeOfDay;
+
+ /**
+ * Returns the {@link FullQualifiedName} for this type kind.
+ *
+ * @return {@link FullQualifiedName}
+ */
+ public FullQualifiedName getFullQualifiedName() {
+ return new FullQualifiedName(EdmPrimitiveType.EDM_NAMESPACE, toString());
+ }
+
+ /**
+ * Returns an instance for this {@link EdmPrimitiveTypeKind} in the form of {@link EdmPrimitiveType}.
+ *
+ * @return {@link EdmPrimitiveType} instance
+ */
+ public EdmPrimitiveType getEdmPrimitiveTypeInstance() {
+ switch (this) {
+ case Binary:
+ return EdmBinary.getInstance();
+ case Boolean:
+ return EdmBoolean.getInstance();
+ case Byte:
+ return EdmByte.getInstance();
+ case Date:
+ return EdmDate.getInstance();
+ case DateTimeOffset:
+ return EdmDateTimeOffset.getInstance();
+ case Decimal:
+ return EdmDecimal.getInstance();
+ case Double:
+ return EdmDouble.getInstance();
+ case Duration:
+ return EdmDuration.getInstance();
+ case Guid:
+ return EdmGuid.getInstance();
+ case Int16:
+ return EdmInt16.getInstance();
+ case Int32:
+ return EdmInt32.getInstance();
+ case Int64:
+ return EdmInt64.getInstance();
+ case SByte:
+ return EdmSByte.getInstance();
+ case Single:
+ return EdmSingle.getInstance();
+ case String:
+ return EdmString.getInstance();
+ case TimeOfDay:
+ return EdmTimeOfDay.getInstance();
+ default:
+ throw new RuntimeException("Wrong type:" + this);
+ }
+ }
+
+ /**
+ * Gets <tt>EdmPrimitiveTypeKind</tt> from a full string (e.g. 'Edm.Int32').
+ *
+ * @param value string value type.
+ * @return <tt>EdmPrimitiveTypeKind</tt> object.
+ */
- public static EdmPrimitiveTypeKind fromString(final String value) {
- final String noNsValue = value.substring(4);
- for (EdmPrimitiveTypeKind edmSimpleType : EdmPrimitiveTypeKind.values()) {
- if (edmSimpleType.name().equals(noNsValue)) {
- return edmSimpleType;
- }
++ public static EdmPrimitiveTypeKind valueOfFQN(final String value) {
++ if (!value.startsWith(EdmPrimitiveType.EDM_NAMESPACE + ".")) {
++ throw new IllegalArgumentException(value + " does not look like an Edm primitive type");
+ }
- throw new IllegalArgumentException(value);
++ return valueOf(value.substring(4));
+ }
+ }