http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/annotation/EdmIsOfImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/annotation/EdmIsOfImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/annotation/EdmIsOfImpl.java deleted file mode 100644 index b732d34..0000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/annotation/EdmIsOfImpl.java +++ /dev/null @@ -1,80 +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.edm.annotation; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmType; -import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression; -import org.apache.olingo.commons.api.edm.annotation.EdmIsOf; -import org.apache.olingo.commons.api.edm.geo.SRID; -import org.apache.olingo.commons.api.edm.provider.annotation.IsOf; -import org.apache.olingo.commons.core.edm.EdmTypeInfo; -import org.apache.olingo.commons.core.edm.annotation.AbstractEdmAnnotatableDynamicAnnotationExpression; - -public class EdmIsOfImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmIsOf { - - private final Edm edm; - - private final IsOf isOf; - - private final EdmDynamicAnnotationExpression value; - - private EdmType type; - - public EdmIsOfImpl(final Edm edm, final IsOf isOf, final EdmDynamicAnnotationExpression value) { - this.edm = edm; - this.isOf = isOf; - this.value = value; - } - - @Override - public Integer getMaxLength() { - return isOf.getMaxLength(); - } - - @Override - public Integer getPrecision() { - return isOf.getPrecision(); - } - - @Override - public Integer getScale() { - return isOf.getScale(); - } - - @Override - public SRID getSrid() { - return isOf.getSrid(); - } - - @Override - public EdmType getType() { - if (type == null) { - final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(isOf.getType()).build(); - type = typeInfo.getType(); - } - return type; - } - - @Override - public EdmDynamicAnnotationExpression getValue() { - return value; - } - -}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/annotation/EdmRecordImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/annotation/EdmRecordImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/annotation/EdmRecordImpl.java deleted file mode 100644 index c5ea7e0..0000000 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/annotation/EdmRecordImpl.java +++ /dev/null @@ -1,55 +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.edm.annotation; - -import java.util.List; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmStructuredType; -import org.apache.olingo.commons.api.edm.annotation.EdmPropertyValue; -import org.apache.olingo.commons.api.edm.annotation.EdmRecord; -import org.apache.olingo.commons.core.edm.EdmTypeInfo; -import org.apache.olingo.commons.core.edm.annotation.AbstractEdmAnnotatableDynamicAnnotationExpression; - -public class EdmRecordImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmRecord { - - private final List<EdmPropertyValue> propertyValues; - - private EdmStructuredType type; - - public EdmRecordImpl(final Edm edm, final String type, final List<EdmPropertyValue> propertyValues) { - this.propertyValues = propertyValues; - - if (type != null) { - final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(type).build(); - this.type = typeInfo.getEntityType() == null ? typeInfo.getComplexType() : typeInfo.getEntityType(); - } - } - - @Override - public List<EdmPropertyValue> getPropertyValues() { - return propertyValues; - } - - @Override - public EdmStructuredType getType() { - return type; - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/NavigationPropertyDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/NavigationPropertyDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/NavigationPropertyDeserializer.java index a422c53..40a5ffb 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/NavigationPropertyDeserializer.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/NavigationPropertyDeserializer.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -31,7 +31,7 @@ public class NavigationPropertyDeserializer extends AbstractEdmDeserializer<Navi @Override protected NavigationPropertyImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { + throws IOException, JsonProcessingException { final NavigationPropertyImpl property = new NavigationPropertyImpl(); @@ -41,7 +41,15 @@ public class NavigationPropertyDeserializer extends AbstractEdmDeserializer<Navi if ("Name".equals(jp.getCurrentName())) { property.setName(jp.nextTextValue()); } else if ("Type".equals(jp.getCurrentName())) { - property.setType(jp.nextTextValue()); + String metadataTypeName = jp.nextTextValue(); + if (metadataTypeName.startsWith("Collection(")) { + property.setType(metadataTypeName.substring(metadataTypeName.indexOf("(") + 1, + metadataTypeName.length() - 1)); + property.setCollection(true); + } else { + property.setType(metadataTypeName); + property.setCollection(false); + } } else if ("Nullable".equals(jp.getCurrentName())) { property.setNullable(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("Partner".equals(jp.getCurrentName())) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ParameterDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ParameterDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ParameterDeserializer.java index d0430d9..7ca059e 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ParameterDeserializer.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ParameterDeserializer.java @@ -42,7 +42,15 @@ public class ParameterDeserializer extends AbstractEdmDeserializer<ParameterImpl if ("Name".equals(jp.getCurrentName())) { parameter.setName(jp.nextTextValue()); } else if ("Type".equals(jp.getCurrentName())) { - parameter.setType(jp.nextTextValue()); + String metadataTypeName = jp.nextTextValue(); + if (metadataTypeName.startsWith("Collection(")) { + parameter.setType(metadataTypeName.substring(metadataTypeName.indexOf("(") + 1, + metadataTypeName.length() - 1)); + parameter.setCollection(true); + } else { + parameter.setType(metadataTypeName); + parameter.setCollection(false); + } } else if ("Nullable".equals(jp.getCurrentName())) { parameter.setNullable(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("MaxLength".equals(jp.getCurrentName())) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/PropertyDeserializer.java ---------------------------------------------------------------------- diff --git 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 index 283b35c..09bada5 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 @@ -42,7 +42,15 @@ public class PropertyDeserializer extends AbstractEdmDeserializer<PropertyImpl> if ("Name".equals(jp.getCurrentName())) { property.setName(jp.nextTextValue()); } else if ("Type".equals(jp.getCurrentName())) { - property.setType(jp.nextTextValue()); + String metadataTypeName = jp.nextTextValue(); + if (metadataTypeName.startsWith("Collection(")) { + property.setType(metadataTypeName.substring(metadataTypeName.indexOf("(") + 1, + metadataTypeName.length() - 1)); + property.setCollection(true); + } else { + property.setType(metadataTypeName); + property.setCollection(false); + } } else if ("Nullable".equals(jp.getCurrentName())) { property.setNullable(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("DefaultValue".equals(jp.getCurrentName())) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/PropertyImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/PropertyImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/PropertyImpl.java index 697fd9c..c7312cd 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/PropertyImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/PropertyImpl.java @@ -18,10 +18,12 @@ */ package org.apache.olingo.client.core.edm.xml; +import org.apache.olingo.commons.api.edm.provider.Property; + import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @JsonDeserialize(using = PropertyDeserializer.class) -public class PropertyImpl extends org.apache.olingo.commons.api.edm.provider.Property { +public class PropertyImpl extends Property { private static final long serialVersionUID = -4521766603286651372L; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ReturnTypeDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ReturnTypeDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ReturnTypeDeserializer.java index 1a8cd94..314b7b1 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ReturnTypeDeserializer.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/ReturnTypeDeserializer.java @@ -40,7 +40,15 @@ public class ReturnTypeDeserializer extends AbstractEdmDeserializer<ReturnTypeIm final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Type".equals(jp.getCurrentName())) { - returnType.setType(jp.nextTextValue()); + String metadataTypeName = jp.nextTextValue(); + if (metadataTypeName.startsWith("Collection(")) { + returnType.setType(metadataTypeName.substring(metadataTypeName.indexOf("(") + 1, + metadataTypeName.length() - 1)); + returnType.setCollection(true); + } else { + returnType.setType(metadataTypeName); + returnType.setCollection(false); + } } else if ("Nullable".equals(jp.getCurrentName())) { returnType.setNullable(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("MaxLength".equals(jp.getCurrentName())) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java index 98d817b..253df78 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java @@ -28,7 +28,7 @@ import org.apache.olingo.client.api.data.ServiceDocument; import org.apache.olingo.client.api.domain.ODataEntitySetIterator; import org.apache.olingo.client.api.edm.xml.XMLMetadata; import org.apache.olingo.client.api.serialization.ODataReader; -import org.apache.olingo.client.core.edm.EdmClientImpl; +import org.apache.olingo.client.core.edm.ClientEdmProvider; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.Property; @@ -44,6 +44,7 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.provider.Schema; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; +import org.apache.olingo.commons.core.edm.provider.EdmProviderImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,7 +68,8 @@ public class ODataReaderImpl implements ODataReader { @Override public Edm readMetadata(final Map<String, Schema> xmlSchemas) { - return new EdmClientImpl(xmlSchemas); + ClientEdmProvider prov = new ClientEdmProvider(xmlSchemas); + return new EdmProviderImpl(prov); } @Override http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/URIEscapeTest.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/URIEscapeTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/URIEscapeTest.java index f10e236..6dd7de5 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/URIEscapeTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/URIEscapeTest.java @@ -27,13 +27,13 @@ import java.util.Calendar; import java.util.Collections; import java.util.TimeZone; -import org.apache.olingo.client.core.edm.EdmEnumTypeImpl; import org.apache.olingo.client.core.edm.xml.EnumTypeImpl; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.edm.EdmEnumType; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.geo.Geospatial; import org.apache.olingo.commons.api.edm.geo.Point; +import org.apache.olingo.commons.core.edm.provider.EdmEnumTypeImpl; import org.junit.Test; public class URIEscapeTest { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/v4/FilterFactoryTest.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/v4/FilterFactoryTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/v4/FilterFactoryTest.java index a643d23..a9fc341 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/v4/FilterFactoryTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/v4/FilterFactoryTest.java @@ -30,11 +30,11 @@ import org.apache.olingo.client.api.uri.FilterArgFactory; import org.apache.olingo.client.api.uri.FilterFactory; import org.apache.olingo.client.api.uri.URIFilter; import org.apache.olingo.client.core.AbstractTest; -import org.apache.olingo.client.core.edm.EdmEnumTypeImpl; import org.apache.olingo.client.core.edm.xml.EnumTypeImpl; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.edm.EdmEnumType; import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.core.edm.provider.EdmEnumTypeImpl; import org.junit.Test; public class FilterFactoryTest extends AbstractTest { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java ---------------------------------------------------------------------- diff --git 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 index 2bea290..c9deca2 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,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -83,7 +83,7 @@ public class MetadataTest extends AbstractTest { // 1. Enum final EdmEnumType responseEnumType = edm.getEnumType( - new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "ResponseType")); + new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "ResponseType")); assertNotNull(responseEnumType); assertEquals(6, responseEnumType.getMemberNames().size()); assertEquals("3", responseEnumType.getMember("Accepted").getValue()); @@ -91,56 +91,56 @@ public class MetadataTest extends AbstractTest { // 2. Complex final EdmComplexType responseStatus = edm.getComplexType( - new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "ResponseStatus")); + new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "ResponseStatus")); assertNotNull(responseStatus); assertTrue(responseStatus.getNavigationPropertyNames().isEmpty()); assertEquals("Recipient", responseStatus.getBaseType().getName()); assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.DateTimeOffset), - responseStatus.getProperty("Time").getType()); + responseStatus.getProperty("Time").getType()); // 3. Entity final EdmEntityType user = edm.getEntityType( - new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "User")); + new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "User")); assertNotNull(user); assertFalse(user.getPropertyNames().isEmpty()); assertFalse(user.getNavigationPropertyNames().isEmpty()); final EdmEntityType entity = edm.getEntityType( - new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Entity")); + new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Entity")); assertEquals(entity, user.getBaseType()); assertFalse(entity.getPropertyNames().isEmpty()); assertTrue(entity.getNavigationPropertyNames().isEmpty()); final EdmEntityType folder = edm.getEntityType( - new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Folder")); + new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Folder")); assertEquals(folder, user.getNavigationProperty("Inbox").getType()); // 4. Action final EdmAction move = edm.getBoundAction( - new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Move"), - new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Folder"), - false); + 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(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String), - move.getParameter("DestinationId").getType()); + move.getParameter("DestinationId").getType()); // 5. EntityContainer final EdmEntityContainer container = edm.getEntityContainer( - new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "EntityContainer")); + 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()); + users.getEntityType()); assertEquals(container.getEntitySet("Folders"), users.getRelatedBindingTarget("Folders")); } @Test public void demo() { final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML). - toMetadata(getClass().getResourceAsStream("demo-metadata.xml")); + toMetadata(getClass().getResourceAsStream("demo-metadata.xml")); assertNotNull(metadata); assertFalse(metadata.getSchema(0).getAnnotationGroups().isEmpty()); @@ -148,13 +148,13 @@ public class MetadataTest extends AbstractTest { assertNotNull(annots); assertFalse(annots.getAnnotations().isEmpty()); assertEquals(ConstantAnnotationExpression.Type.String, - annots.getAnnotation("Org.OData.Publication.V1.PrivacyPolicyUrl").getExpression().asConstant().getType()); + annots.getAnnotation("Org.OData.Publication.V1.PrivacyPolicyUrl").getExpression().asConstant().getType()); assertEquals("http://www.odata.org/", - annots.getAnnotation("Org.OData.Publication.V1.PrivacyPolicyUrl").getExpression().asConstant().getValue()); + annots.getAnnotation("Org.OData.Publication.V1.PrivacyPolicyUrl").getExpression().asConstant().getValue()); // Now let's test some edm:Annotations final Edm edm = getClient().getReader(). - readMetadata(getClass().getResourceAsStream("demo-metadata.xml")); + readMetadata(getClass().getResourceAsStream("demo-metadata.xml")); assertNotNull(edm); final EdmSchema schema = edm.getSchema("ODataDemo"); @@ -181,7 +181,7 @@ public class MetadataTest extends AbstractTest { @Test public void multipleSchemas() { final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML). - toMetadata(getClass().getResourceAsStream("northwind-metadata.xml")); + toMetadata(getClass().getResourceAsStream("northwind-metadata.xml")); assertNotNull(metadata); final Schema first = metadata.getSchema("NorthwindModel"); @@ -201,7 +201,7 @@ public class MetadataTest extends AbstractTest { @Test public void fromdoc1() { final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML). - toMetadata(getClass().getResourceAsStream("fromdoc1-metadata.xml")); + toMetadata(getClass().getResourceAsStream("fromdoc1-metadata.xml")); assertNotNull(metadata); assertFalse(metadata.getReferences().isEmpty()); @@ -218,12 +218,14 @@ public class MetadataTest extends AbstractTest { final ComplexType address = metadata.getSchema(0).getComplexType("Address"); assertFalse(address.getNavigationProperty("Country").getReferentialConstraints().isEmpty()); assertEquals("Name", - address.getNavigationProperty("Country").getReferentialConstraints().get(0).getReferencedProperty()); + 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()); +// assertEquals("Collection(ODataDemo.Product)", productsByRating.getReturnType().getType()); + assertEquals("ODataDemo.Product", productsByRating.getReturnType().getType()); + assertTrue(productsByRating.getReturnType().isCollection()); final Singleton contoso = metadata.getSchema(0).getEntityContainer().getSingleton("Contoso"); assertNotNull(contoso); @@ -231,10 +233,10 @@ public class MetadataTest extends AbstractTest { assertEquals("Products", contoso.getNavigationPropertyBindings().get(0).getPath()); final FunctionImport functionImport = metadata.getSchema(0).getEntityContainer(). - getFunctionImport("ProductsByRating"); + getFunctionImport("ProductsByRating"); assertNotNull(functionImport); assertEquals(metadata.getSchema(0).getNamespace() + "." + productsByRating.getName(), - functionImport.getFunction()); + functionImport.getFunction()); // Now let's go high-level final Edm edm = getClient().getReader().readMetadata(getClass().getResourceAsStream("fromdoc1-metadata.xml")); @@ -252,16 +254,19 @@ public class MetadataTest extends AbstractTest { assertNotNull(fi); assertEquals(demoService.getEntitySet("Products"), fi.getReturnedEntitySet()); - final EdmFunction edmFunction = edm.getUnboundFunction( - new FullQualifiedName(metadata.getSchema(0).getNamespace(), "ProductsByRating"), null); + final EdmFunction edmFunction = + edm.getUnboundFunction( + new FullQualifiedName(metadata.getSchema(0).getNamespace(), "ProductsByRating"), function + .getParameterNames()); assertNotNull(edmFunction); - assertEquals(edmFunction.getName(), fi.getUnboundFunction(null).getName()); - assertEquals(edmFunction.getNamespace(), fi.getUnboundFunction(null).getNamespace()); - assertEquals(edmFunction.getParameterNames(), fi.getUnboundFunction(null).getParameterNames()); + assertEquals(edmFunction.getName(), fi.getUnboundFunction(function.getParameterNames()).getName()); + assertEquals(edmFunction.getNamespace(), fi.getUnboundFunction(function.getParameterNames()).getNamespace()); + assertEquals(edmFunction.getParameterNames(), fi.getUnboundFunction(function.getParameterNames()) + .getParameterNames()); assertEquals(edmFunction.getReturnType().getType().getName(), - fi.getUnboundFunction(null).getReturnType().getType().getName()); + fi.getUnboundFunction(function.getParameterNames()).getReturnType().getType().getName()); assertEquals(edmFunction.getReturnType().getType().getNamespace(), - fi.getUnboundFunction(null).getReturnType().getType().getNamespace()); + fi.getUnboundFunction(function.getParameterNames()).getReturnType().getType().getNamespace()); } final EdmTypeDefinition weight = edm.getTypeDefinition(new FullQualifiedName("ODataDemo", "Weight")); @@ -277,12 +282,12 @@ public class MetadataTest extends AbstractTest { @Test public void fromdoc2() { final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML) - .toMetadata(getClass().getResourceAsStream("fromdoc2-metadata.xml")); + .toMetadata(getClass().getResourceAsStream("fromdoc2-metadata.xml")); assertNotNull(metadata); // Check displayName final Annotation displayName = metadata.getSchema(0).getAnnotationGroup("ODataDemo.Supplier"). - getAnnotation("Vocabulary1.DisplayName"); + getAnnotation("Vocabulary1.DisplayName"); assertNotNull(displayName); assertTrue(displayName.getExpression().isDynamic()); @@ -306,7 +311,7 @@ public class MetadataTest extends AbstractTest { // Check Tags final Annotation tags = metadata.getSchema(0).getAnnotationGroup("ODataDemo.Product"). - getAnnotation("Vocabulary1.Tags"); + getAnnotation("Vocabulary1.Tags"); assertNotNull(tags); assertTrue(tags.getExpression().isDynamic()); @@ -341,7 +346,7 @@ public class MetadataTest extends AbstractTest { @Test public void fromdoc4() { final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML). - toMetadata(getClass().getResourceAsStream("fromdoc4-metadata.xml")); + toMetadata(getClass().getResourceAsStream("fromdoc4-metadata.xml")); assertNotNull(metadata); final Annotations group = metadata.getSchema(0).getAnnotationGroups().get(0); @@ -356,7 +361,7 @@ public class MetadataTest extends AbstractTest { assertTrue(annotation.getExpression().isDynamic()); assertTrue(annotation.getExpression().asDynamic().isTwoParamsOp()); assertEquals(TwoParamsOpDynamicAnnotationExpression.Type.And, - annotation.getExpression().asDynamic().asTwoParamsOp().getType()); + annotation.getExpression().asDynamic().asTwoParamsOp().getType()); assertTrue(annotation.getExpression().asDynamic().asTwoParamsOp().getLeftExpression().isPath()); annotation = group.getAnnotation("Vocab.Supplier"); @@ -367,7 +372,7 @@ public class MetadataTest extends AbstractTest { assertTrue(urlRef.getValue().isDynamic()); assertTrue(urlRef.getValue().asDynamic().isApply()); - // Now let's go high-level + // Now let's go high-level final Edm edm = getClient().getReader().readMetadata(getClass().getResourceAsStream("fromdoc4-metadata.xml")); assertNotNull(edm); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntityContainer.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntityContainer.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntityContainer.java index 53ab80e..07e330f 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntityContainer.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntityContainer.java @@ -39,15 +39,6 @@ public interface EdmEntityContainer extends EdmNamed, EdmAnnotationsTarget, EdmA FullQualifiedName getFullQualifiedName(); /** - * Returns whether this container is the default container in the current schema. - * <br/> - * According to CSDL specifications, this method will always return <tt>true</tt> for OData 4.0. - * - * @return whether this container is the default container in the current schema, always <tt>true</tt> for OData 4.0 - */ - boolean isDefault(); - - /** * Get contained Singleton by name. * * @param name http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EdmProvider.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EdmProvider.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EdmProvider.java index d221ca1..38a03d7 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EdmProvider.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EdmProvider.java @@ -18,11 +18,11 @@ */ package org.apache.olingo.commons.api.edm.provider; +import java.util.List; + import org.apache.olingo.commons.api.ODataException; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import java.util.List; - public abstract class EdmProvider { /** @@ -192,4 +192,20 @@ public abstract class EdmProvider { public EntityContainer getEntityContainer() throws ODataException { return null; } + + /** + * @param targetName + * @return {@link Annotations} group for the given Target + */ + public Annotations getAnnotationsGroup(FullQualifiedName targetName) throws ODataException { + return null; + } + + /** + * @param annotatedName + * @return Annotatble element by target name + */ + public Annotatable getAnnoatatable(FullQualifiedName annotatedName) throws ODataException { + return null; + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/TypeDefinition.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/TypeDefinition.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/TypeDefinition.java index 7ef8b36..b886b1e 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/TypeDefinition.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/TypeDefinition.java @@ -55,7 +55,10 @@ public class TypeDefinition extends AbstractEdmItem implements Named, Annotatabl } public String getUnderlyingType() { - return underlyingType.getFullQualifiedNameAsString(); + if(underlyingType != null){ + return underlyingType.getFullQualifiedNameAsString(); + } + return null; } public TypeDefinition setUnderlyingType(final String underlyingType) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java index ea8f725..c1dd630 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java @@ -61,11 +61,6 @@ public abstract class AbstractEdmEntityContainer extends EdmNamedImpl implements } @Override - public boolean isDefault() { - return true; - } - - @Override public String getNamespace() { return entityContainerName.getNamespace(); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEnumType.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEnumType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEnumType.java index 0172607..549980f 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEnumType.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEnumType.java @@ -53,7 +53,7 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum uriSuffix = "'"; } - protected abstract Collection<? extends EdmMember> getMembers(); + protected abstract Collection<EdmMember> getMembers(); @Override public EdmMember getMember(final String name) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmCastImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmCastImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmCastImpl.java new file mode 100644 index 0000000..419adea --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmCastImpl.java @@ -0,0 +1,79 @@ +/* + * 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.annotation; + +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmType; +import org.apache.olingo.commons.api.edm.annotation.EdmCast; +import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression; +import org.apache.olingo.commons.api.edm.geo.SRID; +import org.apache.olingo.commons.api.edm.provider.annotation.Cast; +import org.apache.olingo.commons.core.edm.EdmTypeInfo; + +public class EdmCastImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmCast { + + private final Edm edm; + + private final Cast cast; + + private final EdmDynamicAnnotationExpression value; + + private EdmType type; + + public EdmCastImpl(final Edm edm, final Cast cast, final EdmDynamicAnnotationExpression value) { + this.edm = edm; + this.cast = cast; + this.value = value; + } + + @Override + public Integer getMaxLength() { + return cast.getMaxLength(); + } + + @Override + public Integer getPrecision() { + return cast.getPrecision(); + } + + @Override + public Integer getScale() { + return cast.getScale(); + } + + @Override + public SRID getSrid() { + return cast.getSrid(); + } + + @Override + public EdmType getType() { + if (type == null) { + final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(cast.getType()).build(); + type = typeInfo.getType(); + } + return type; + } + + @Override + public EdmDynamicAnnotationExpression getValue() { + return value; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmConstantAnnotationExpressionImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmConstantAnnotationExpressionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmConstantAnnotationExpressionImpl.java new file mode 100644 index 0000000..83ad8ec --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmConstantAnnotationExpressionImpl.java @@ -0,0 +1,139 @@ +/* + * 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.annotation; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.api.domain.ODataEnumValue; +import org.apache.olingo.commons.api.domain.ODataValue; +import org.apache.olingo.commons.api.edm.EdmPrimitiveType; +import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; +import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; +import org.apache.olingo.commons.api.edm.annotation.EdmConstantAnnotationExpression; +import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression; +import org.apache.olingo.commons.api.edm.provider.annotation.ConstantAnnotationExpression; +import org.apache.olingo.commons.core.domain.ODataCollectionValueImpl; +import org.apache.olingo.commons.core.domain.ODataEnumValueImpl; +import org.apache.olingo.commons.core.domain.ODataPrimitiveValueImpl; +import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; + +public class EdmConstantAnnotationExpressionImpl implements EdmConstantAnnotationExpression { + + private final ODataValue value; + + public EdmConstantAnnotationExpressionImpl(final ConstantAnnotationExpression constExprConstruct) { + if (constExprConstruct.getType() == ConstantAnnotationExpression.Type.EnumMember) { + final List<ODataEnumValue> enumValues = new ArrayList<ODataEnumValue>(); + String enumTypeName = null; + for (String split : StringUtils.split(constExprConstruct.getValue(), ' ')) { + final String[] enumSplit = StringUtils.split(split, '/'); + enumTypeName = enumSplit[0]; + enumValues.add(new ODataEnumValueImpl(enumSplit[0], enumSplit[1])); + } + if (enumValues.size() == 1) { + value = enumValues.get(0); + } else { + final ODataCollectionValueImpl collValue = new ODataCollectionValueImpl(enumTypeName); + for (ODataValue enumValue : enumValues) { + collValue.add(enumValue); + } + value = collValue; + } + } else { + EdmPrimitiveTypeKind kind; + switch (constExprConstruct.getType()) { + case Binary: + kind = EdmPrimitiveTypeKind.Binary; + break; + case Bool: + kind = EdmPrimitiveTypeKind.Boolean; + break; + case Date: + kind = EdmPrimitiveTypeKind.Date; + break; + case DateTimeOffset: + kind = EdmPrimitiveTypeKind.DateTimeOffset; + break; + case Decimal: + kind = EdmPrimitiveTypeKind.Decimal; + break; + case Duration: + kind = EdmPrimitiveTypeKind.Duration; + break; + case Float: + kind = EdmPrimitiveTypeKind.Single; + break; + case Guid: + kind = EdmPrimitiveTypeKind.Guid; + break; + case Int: + kind = EdmPrimitiveTypeKind.Int32; + break; + case TimeOfDay: + kind = EdmPrimitiveTypeKind.TimeOfDay; + break; + case String: + default: + kind = EdmPrimitiveTypeKind.String; + } + final ODataPrimitiveValueImpl.BuilderImpl primitiveValueBuilder = new ODataPrimitiveValueImpl.BuilderImpl(); + primitiveValueBuilder.setType(kind); + try { + final EdmPrimitiveType primitiveType = EdmPrimitiveTypeFactory.getInstance(kind); + primitiveValueBuilder.setValue( + primitiveType.valueOfString(constExprConstruct.getValue(), + null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, + primitiveType.getDefaultType())); + } catch (final EdmPrimitiveTypeException e) { + throw new IllegalArgumentException(e); + } + + value = primitiveValueBuilder.build(); + } + } + + @Override + public boolean isConstant() { + return true; + } + + @Override + public EdmConstantAnnotationExpression asConstant() { + return this; + } + + @Override + public boolean isDynamic() { + return false; + } + + @Override + public EdmDynamicAnnotationExpression asDynamic() { + return null; + } + + @Override + public ODataValue getValue() { + return value; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmIsOfImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmIsOfImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmIsOfImpl.java new file mode 100644 index 0000000..03ae319 --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmIsOfImpl.java @@ -0,0 +1,79 @@ +/* + * 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.annotation; + +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmType; +import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression; +import org.apache.olingo.commons.api.edm.annotation.EdmIsOf; +import org.apache.olingo.commons.api.edm.geo.SRID; +import org.apache.olingo.commons.api.edm.provider.annotation.IsOf; +import org.apache.olingo.commons.core.edm.EdmTypeInfo; + +public class EdmIsOfImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmIsOf { + + private final Edm edm; + + private final IsOf isOf; + + private final EdmDynamicAnnotationExpression value; + + private EdmType type; + + public EdmIsOfImpl(final Edm edm, final IsOf isOf, final EdmDynamicAnnotationExpression value) { + this.edm = edm; + this.isOf = isOf; + this.value = value; + } + + @Override + public Integer getMaxLength() { + return isOf.getMaxLength(); + } + + @Override + public Integer getPrecision() { + return isOf.getPrecision(); + } + + @Override + public Integer getScale() { + return isOf.getScale(); + } + + @Override + public SRID getSrid() { + return isOf.getSrid(); + } + + @Override + public EdmType getType() { + if (type == null) { + final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(isOf.getType()).build(); + type = typeInfo.getType(); + } + return type; + } + + @Override + public EdmDynamicAnnotationExpression getValue() { + return value; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java new file mode 100644 index 0000000..cd71c6c --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java @@ -0,0 +1,54 @@ +/* + * 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.annotation; + +import java.util.List; + +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmStructuredType; +import org.apache.olingo.commons.api.edm.annotation.EdmPropertyValue; +import org.apache.olingo.commons.api.edm.annotation.EdmRecord; +import org.apache.olingo.commons.core.edm.EdmTypeInfo; + +public class EdmRecordImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmRecord { + + private final List<EdmPropertyValue> propertyValues; + + private EdmStructuredType type; + + public EdmRecordImpl(final Edm edm, final String type, final List<EdmPropertyValue> propertyValues) { + this.propertyValues = propertyValues; + + if (type != null) { + final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(type).build(); + this.type = typeInfo.getEntityType() == null ? typeInfo.getComplexType() : typeInfo.getEntityType(); + } + } + + @Override + public List<EdmPropertyValue> getPropertyValues() { + return propertyValues; + } + + @Override + public EdmStructuredType getType() { + return type; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java new file mode 100644 index 0000000..292f234 --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java @@ -0,0 +1,36 @@ +/* + * 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.provider; + +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmAction; +import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.api.edm.constants.EdmTypeKind; +import org.apache.olingo.commons.api.edm.provider.Action; + +public class EdmActionImpl extends EdmOperationImpl implements EdmAction { + + public static EdmActionImpl getInstance(final Edm edm, final FullQualifiedName name, final Action action) { + return EdmOperationImpl.getInstance(new EdmActionImpl(edm, name, action)); + } + + private EdmActionImpl(final Edm edm, final FullQualifiedName name, final Action action) { + super(edm, name, action, EdmTypeKind.ACTION); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImportImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImportImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImportImpl.java new file mode 100644 index 0000000..5d9c68a --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImportImpl.java @@ -0,0 +1,46 @@ +/* + * 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.provider; + +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmAction; +import org.apache.olingo.commons.api.edm.EdmActionImport; +import org.apache.olingo.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.commons.api.edm.provider.ActionImport; + +public class EdmActionImportImpl extends EdmOperationImportImpl implements EdmActionImport { + + private final ActionImport actionImport; + + public EdmActionImportImpl(final Edm edm, final EdmEntityContainer container, final ActionImport actionImport) { + + super(edm, container, actionImport); + this.actionImport = actionImport; + } + + @Override + public EdmAction getUnboundAction() { + return edm.getUnboundAction(actionImport.getActionFQN()); + } + + @Override + public TargetType getAnnotationsTargetType() { + return TargetType.ActionImport; + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java new file mode 100644 index 0000000..f4f0b6f --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java @@ -0,0 +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.commons.core.edm.provider; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmAnnotation; +import org.apache.olingo.commons.api.edm.EdmTerm; +import org.apache.olingo.commons.api.edm.provider.Annotatable; +import org.apache.olingo.commons.api.edm.provider.Annotation; +import org.apache.olingo.commons.core.edm.EdmAnnotationHelper; + +public class EdmAnnotationHelperImpl implements EdmAnnotationHelper { + + private final Edm edm; + + private final Annotatable annotatable; + + private List<EdmAnnotation> annotations; + + public EdmAnnotationHelperImpl(final Edm edm, final Annotatable annotatable) { + this.edm = edm; + this.annotatable = annotatable; + } + + @Override + public EdmAnnotation getAnnotation(final EdmTerm term) { + EdmAnnotation result = null; + for (EdmAnnotation annotation : getAnnotations()) { + if (term.getFullQualifiedName().equals(annotation.getTerm().getFullQualifiedName())) { + result = annotation; + } + } + + return result; + } + + @Override + public List<EdmAnnotation> getAnnotations() { + if (annotations == null) { + annotations = new ArrayList<EdmAnnotation>(); + for (Annotation annotation : annotatable.getAnnotations()) { + annotations.add(new EdmAnnotationImpl(edm, annotation)); + } + } + return annotations; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java new file mode 100644 index 0000000..9bebd12 --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java @@ -0,0 +1,244 @@ +/* + * 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.provider; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmAnnotatable; +import org.apache.olingo.commons.api.edm.EdmAnnotation; +import org.apache.olingo.commons.api.edm.EdmTerm; +import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression; +import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression; +import org.apache.olingo.commons.api.edm.annotation.EdmPropertyValue; +import org.apache.olingo.commons.api.edm.provider.Annotatable; +import org.apache.olingo.commons.api.edm.provider.Annotation; +import org.apache.olingo.commons.api.edm.provider.annotation.AnnotationExpression; +import org.apache.olingo.commons.api.edm.provider.annotation.DynamicAnnotationExpression; +import org.apache.olingo.commons.api.edm.provider.annotation.PropertyValue; +import org.apache.olingo.commons.core.edm.EdmAnnotationHelper; +import org.apache.olingo.commons.core.edm.annotation.EdmAndImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmAnnotationPathImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmApplyImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmCastImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmCollectionImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmConstantAnnotationExpressionImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmEqImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmGeImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmGtImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmIfImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmIsOfImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmLabeledElementImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmLabeledElementReferenceImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmLeImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmLtImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmNavigationPropertyPathImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmNeImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmNotImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmNullImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmOrImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmPathImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmPropertyPathImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmPropertyValueImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmRecordImpl; +import org.apache.olingo.commons.core.edm.annotation.EdmUrlRefImpl; + +public class EdmAnnotationImpl implements EdmAnnotation { + + private final Edm edm; + + private final Annotation annotation; + + private final EdmAnnotationHelper helper; + + private EdmTerm term; + + private EdmAnnotationExpression expression; + + public EdmAnnotationImpl(final Edm edm, final Annotation annotation) { + this.edm = edm; + this.annotation = annotation; + this.helper = new EdmAnnotationHelperImpl(edm, annotation); + } + + @Override + public EdmTerm getTerm() { + if (term == null) { + term = edm.getTerm(new FullQualifiedName(annotation.getTerm())); + } + return term; + } + + @Override + public String getQualifier() { + return annotation.getQualifier(); + } + + private EdmAnnotationExpression getExpression(final AnnotationExpression exp) { + EdmAnnotationExpression _expression = null; + + if (exp.isConstant()) { + _expression = new EdmConstantAnnotationExpressionImpl(exp.asConstant()); + } else if (annotation.getExpression().isDynamic()) { + _expression = getDynamicExpression(exp.asDynamic()); + } + + return _expression; + } + + private EdmDynamicAnnotationExpression getDynamicExpression(final DynamicAnnotationExpression exp) { + EdmDynamicAnnotationExpression _expression = null; + + if (exp.isNot()) { + _expression = new EdmNotImpl(getDynamicExpression(exp.asNot().getExpression())); + } else if (exp.isTwoParamsOp()) { + switch (exp.asTwoParamsOp().getType()) { + case And: + _expression = new EdmAndImpl( + getDynamicExpression(exp.asTwoParamsOp().getLeftExpression()), + getDynamicExpression(exp.asTwoParamsOp().getRightExpression())); + break; + + case Or: + _expression = new EdmOrImpl( + getDynamicExpression(exp.asTwoParamsOp().getLeftExpression()), + getDynamicExpression(exp.asTwoParamsOp().getRightExpression())); + break; + + case Eq: + _expression = new EdmEqImpl( + getDynamicExpression(exp.asTwoParamsOp().getLeftExpression()), + getDynamicExpression(exp.asTwoParamsOp().getRightExpression())); + break; + + case Ne: + _expression = new EdmNeImpl( + getDynamicExpression(exp.asTwoParamsOp().getLeftExpression()), + getDynamicExpression(exp.asTwoParamsOp().getRightExpression())); + break; + + case Ge: + _expression = new EdmGeImpl( + getDynamicExpression(exp.asTwoParamsOp().getLeftExpression()), + getDynamicExpression(exp.asTwoParamsOp().getRightExpression())); + break; + + case Gt: + _expression = new EdmGtImpl( + getDynamicExpression(exp.asTwoParamsOp().getLeftExpression()), + getDynamicExpression(exp.asTwoParamsOp().getRightExpression())); + break; + + case Le: + _expression = new EdmLeImpl( + getDynamicExpression(exp.asTwoParamsOp().getLeftExpression()), + getDynamicExpression(exp.asTwoParamsOp().getRightExpression())); + break; + + case Lt: + _expression = new EdmLtImpl( + getDynamicExpression(exp.asTwoParamsOp().getLeftExpression()), + getDynamicExpression(exp.asTwoParamsOp().getRightExpression())); + break; + + default: + } + } else if (exp.isAnnotationPath()) { + _expression = new EdmAnnotationPathImpl(exp.asAnnotationPath().getValue()); + } else if (exp.isApply()) { + final List<EdmAnnotationExpression> parameters = + new ArrayList<EdmAnnotationExpression>(exp.asApply().getParameters().size()); + for (AnnotationExpression param : exp.asApply().getParameters()) { + parameters.add(getExpression(param)); + } + _expression = new EdmApplyImpl(exp.asApply().getFunction(), parameters); + } else if (exp.isCast()) { + _expression = new EdmCastImpl(edm, exp.asCast(), getDynamicExpression(exp.asCast().getValue())); + } else if (exp.isCollection()) { + final List<EdmAnnotationExpression> items = + new ArrayList<EdmAnnotationExpression>(exp.asCollection().getItems().size()); + for (AnnotationExpression param : exp.asCollection().getItems()) { + items.add(getExpression(param)); + } + _expression = new EdmCollectionImpl(items); + } else if (exp.isIf()) { + _expression = new EdmIfImpl( + getExpression(exp.asIf().getGuard()), + getExpression(exp.asIf().getThen()), + getExpression(exp.asIf().getElse())); + } else if (exp.isIsOf()) { + _expression = new EdmIsOfImpl(edm, exp.asIsOf(), getDynamicExpression(exp.asIsOf().getValue())); + } else if (exp.isLabeledElement()) { + _expression = new EdmLabeledElementImpl( + exp.asLabeledElement().getName(), getDynamicExpression(exp.asLabeledElement().getValue())); + } else if (exp.isLabeledElementReference()) { + _expression = new EdmLabeledElementReferenceImpl(exp.asLabeledElementReference().getValue()); + } else if (exp.isNull()) { + _expression = new EdmNullImpl(); + } else if (exp.isNavigationPropertyPath()) { + _expression = new EdmNavigationPropertyPathImpl(exp.asNavigationPropertyPath().getValue()); + } else if (exp.isPath()) { + _expression = new EdmPathImpl(exp.asPath().getValue()); + } else if (exp.isPropertyPath()) { + _expression = new EdmPropertyPathImpl(exp.asPropertyPath().getValue()); + } else if (exp.isPropertyValue()) { + _expression = new EdmPropertyValueImpl( + exp.asPropertyValue().getProperty(), getExpression(exp.asPropertyValue().getValue())); + } else if (exp.isRecord()) { + final List<EdmPropertyValue> propertyValues = + new ArrayList<EdmPropertyValue>(exp.asRecord().getPropertyValues().size()); + for (PropertyValue propertyValue : exp.asRecord().getPropertyValues()) { + propertyValues.add(new EdmPropertyValueImpl( + propertyValue.getProperty(), getExpression(propertyValue.getValue()))); + } + _expression = new EdmRecordImpl(edm, exp.asRecord().getType(), propertyValues); + } else if (exp.isUrlRef()) { + _expression = new EdmUrlRefImpl(getExpression(exp.asUrlRef().getValue())); + } + + if (_expression instanceof EdmAnnotatable && exp instanceof Annotatable) { + for (Annotation _annotation : ((Annotatable) exp).getAnnotations()) { + ((EdmAnnotatable) _expression).getAnnotations().add(new EdmAnnotationImpl(edm, _annotation)); + } + } + + return _expression; + } + + @Override + public EdmAnnotationExpression getExpression() { + if (expression == null) { + expression = getExpression(annotation.getExpression()); + } + return expression; + } + + @Override + public EdmAnnotation getAnnotation(final EdmTerm term) { + return helper.getAnnotation(term); + } + + @Override + public List<EdmAnnotation> getAnnotations() { + return helper.getAnnotations(); + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java new file mode 100644 index 0000000..d64056d --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java @@ -0,0 +1,143 @@ +/* + * 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.provider; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmAnnotation; +import org.apache.olingo.commons.api.edm.EdmAnnotations; +import org.apache.olingo.commons.api.edm.EdmAnnotationsTarget; +import org.apache.olingo.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.commons.api.edm.EdmEnumType; +import org.apache.olingo.commons.api.edm.EdmSchema; +import org.apache.olingo.commons.api.edm.EdmStructuredType; +import org.apache.olingo.commons.api.edm.EdmTerm; +import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.api.edm.provider.Annotation; +import org.apache.olingo.commons.api.edm.provider.Annotations; + +public class EdmAnnotationsImpl implements EdmAnnotations { + + private final Edm edm; + private final EdmSchema schema; + private final Annotations annotationGroup; + private EdmAnnotationsTarget target; + private List<EdmAnnotation> annotations; + + public EdmAnnotationsImpl(final Edm edm, final EdmSchema schema, final Annotations annotationGroup) { + this.edm = edm; + this.schema = schema; + this.annotationGroup = annotationGroup; + } + + private EdmAnnotationsTarget getTarget(final EdmStructuredType structured, final String path) { + EdmAnnotationsTarget _target = null; + if (structured != null) { + _target = path == null + ? structured + : structured.getStructuralProperty(path); + if (_target == null) { + _target = structured.getNavigationProperty(path); + } + } + return _target; + } + + private EdmAnnotationsTarget getTarget(final EdmEnumType enumType, final String path) { + EdmAnnotationsTarget _target = null; + if (enumType != null) { + _target = path == null + ? enumType + : enumType.getMember(path); + } + return _target; + } + + @Override + public EdmAnnotationsTarget getTarget() { + if (target == null) { + final String[] splitted = StringUtils.split(annotationGroup.getTarget(), '/'); + final FullQualifiedName base = new FullQualifiedName(splitted[0]); + final String path = splitted.length > 1 ? splitted[1] : null; + + final EdmEntityContainer baseEntityContainer = schema.getEntityContainer(base); + + target = baseEntityContainer == null? null: baseEntityContainer.getActionImport(path); + if (target == null) { + target = getTarget(edm.getComplexType(base), path); + if (target == null) { + target = baseEntityContainer; + if (target == null) { + target = baseEntityContainer == null? null: baseEntityContainer.getEntitySet(path); + if (target == null) { + target = getTarget(edm.getEntityType(base), path); + if (target == null) { + target = getTarget(edm.getEnumType(base), path); + if (target == null) { + target = baseEntityContainer == null? null: baseEntityContainer.getFunctionImport(path); + if (target == null) { + target = baseEntityContainer == null? null: baseEntityContainer.getSingleton(path); + if (target == null) { + target = edm.getTerm(base); + if (target == null) { + target = edm.getTypeDefinition(base); + } + } + } + } + } + } + } + } + } + } + return target; + } + + @Override + public String getQualifier() { + return annotationGroup.getQualifier(); + } + + @Override + public EdmAnnotation getAnnotation(final EdmTerm term) { + EdmAnnotation result = null; + for (EdmAnnotation annotation : getAnnotations()) { + if (term.getFullQualifiedName().equals(annotation.getTerm().getFullQualifiedName())) { + result = annotation; + } + } + return result; + } + + @Override + public List<EdmAnnotation> getAnnotations() { + if (annotations == null) { + annotations = new ArrayList<EdmAnnotation>(); + for (Annotation annotation : annotationGroup.getAnnotations()) { + annotations.add(new EdmAnnotationImpl(edm, annotation)); + } + } + return annotations; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java new file mode 100644 index 0000000..d6bb531 --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java @@ -0,0 +1,71 @@ +/* + * 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.provider; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmAnnotation; +import org.apache.olingo.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding; +import org.apache.olingo.commons.api.edm.EdmTerm; +import org.apache.olingo.commons.api.edm.provider.BindingTarget; +import org.apache.olingo.commons.api.edm.provider.NavigationPropertyBinding; +import org.apache.olingo.commons.core.edm.AbstractEdmBindingTarget; +import org.apache.olingo.commons.core.edm.EdmAnnotationHelper; +import org.apache.olingo.commons.core.edm.EdmNavigationPropertyBindingImpl; + +public abstract class EdmBindingTargetImpl extends AbstractEdmBindingTarget { + + private final BindingTarget target; + private List<EdmNavigationPropertyBinding> navigationPropertyBindings; + private final EdmAnnotationHelper helper; + + public EdmBindingTargetImpl(final Edm edm, final EdmEntityContainer container, final BindingTarget target) { + super(edm, container, target.getName(), target.getTypeFQN()); + this.target = target; + this.helper = new EdmAnnotationHelperImpl(edm, target); + } + + @Override + public List<EdmNavigationPropertyBinding> getNavigationPropertyBindings() { + if (navigationPropertyBindings == null) { + List<NavigationPropertyBinding> providerBindings = target.getNavigationPropertyBindings(); + navigationPropertyBindings = new ArrayList<EdmNavigationPropertyBinding>(); + if (providerBindings != null) { + for (NavigationPropertyBinding binding : providerBindings) { + navigationPropertyBindings.add(new EdmNavigationPropertyBindingImpl(binding.getPath(), binding.getTarget())); + } + } + } + return navigationPropertyBindings; + } + + + @Override + public EdmAnnotation getAnnotation(final EdmTerm term) { + return helper.getAnnotation(term); + } + + @Override + public List<EdmAnnotation> getAnnotations() { + return helper.getAnnotations(); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cef4fae/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java new file mode 100644 index 0000000..5b641ba --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java @@ -0,0 +1,82 @@ +/* + * 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.provider; + +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmAnnotation; +import org.apache.olingo.commons.api.edm.EdmNavigationProperty; +import org.apache.olingo.commons.api.edm.EdmProperty; +import org.apache.olingo.commons.api.edm.EdmTerm; +import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.api.edm.provider.ComplexType; +import org.apache.olingo.commons.core.edm.AbstractEdmComplexType; +import org.apache.olingo.commons.core.edm.EdmAnnotationHelper; +import org.apache.olingo.commons.core.edm.EdmStructuredTypeHelper; + +import java.util.List; +import java.util.Map; + +public class EdmComplexTypeImpl extends AbstractEdmComplexType { + + private final EdmStructuredTypeHelper helper; + + private EdmAnnotationHelper annotationHelper; + + public static EdmComplexTypeImpl getInstance( + final Edm edm, final FullQualifiedName name, final ComplexType complexType) { + + return new EdmComplexTypeImpl(edm, name, complexType); + } + + private EdmComplexTypeImpl(final Edm edm, final FullQualifiedName name, final ComplexType complexType) { + super(edm, name, complexType.getBaseTypeFQN()); + this.helper = new EdmStructuredTypeHelperImpl(edm, name, complexType); + this.annotationHelper = new EdmAnnotationHelperImpl(edm, complexType); + } + + @Override + protected Map<String, EdmProperty> getProperties() { + return helper.getProperties(); + } + + @Override + protected Map<String, EdmNavigationProperty> getNavigationProperties() { + return helper.getNavigationProperties(); + } + + @Override + public boolean isOpenType() { + return helper.isOpenType(); + } + + @Override + public boolean isAbstract() { + return helper.isAbstract(); + } + + @Override + public EdmAnnotation getAnnotation(final EdmTerm term) { + return annotationHelper == null ? null : annotationHelper.getAnnotation(term); + } + + @Override + public List<EdmAnnotation> getAnnotations() { + return annotationHelper == null ? null : annotationHelper.getAnnotations(); + } +}
