http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java new file mode 100644 index 0000000..630146b --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java @@ -0,0 +1,53 @@ +/* + * 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; + +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmType; +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.Annotatable; + +public class EdmTypeImpl extends AbstractEdmNamed implements EdmType { + + protected final FullQualifiedName typeName; + protected final EdmTypeKind kind; + + public EdmTypeImpl(final Edm edm, final FullQualifiedName typeName, final EdmTypeKind kind, + final Annotatable annotatable) { + super(edm, typeName.getName(), annotatable); + this.typeName = typeName; + this.kind = kind; + } + + @Override + public FullQualifiedName getFullQualifiedName() { + return typeName; + } + + @Override + public String getNamespace() { + return typeName.getNamespace(); + } + + @Override + public EdmTypeKind getKind() { + return kind; + } +}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java new file mode 100644 index 0000000..67008ab --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java @@ -0,0 +1,228 @@ +/* + * 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; + +import org.apache.commons.lang3.StringUtils; +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmComplexType; +import org.apache.olingo.commons.api.edm.EdmEntityType; +import org.apache.olingo.commons.api.edm.EdmEnumType; +import org.apache.olingo.commons.api.edm.EdmPrimitiveType; +import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; +import org.apache.olingo.commons.api.edm.EdmType; +import org.apache.olingo.commons.api.edm.EdmTypeDefinition; +import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; + +public class EdmTypeInfo { + + public static class Builder { + + private String typeExpression; + private String defaultNamespace; + private Edm edm; + + public Builder setTypeExpression(final String typeExpression) { + this.typeExpression = typeExpression; + return this; + } + + public Builder setDefaultNamespace(final String defaultNamespace) { + this.defaultNamespace = defaultNamespace; + return this; + } + + public Builder setEdm(final Edm edm) { + this.edm = edm; + return this; + } + + public EdmTypeInfo build() { + return new EdmTypeInfo(edm, typeExpression.indexOf('.') == -1 && StringUtils.isNotBlank(defaultNamespace) + ? defaultNamespace + "." + typeExpression + : typeExpression); + } + } + + private final boolean collection; + private final FullQualifiedName fullQualifiedName; + private EdmPrimitiveTypeKind primitiveType; + private EdmTypeDefinition typeDefinition; + private EdmEnumType enumType; + private EdmComplexType complexType; + private EdmEntityType entityType; + + private EdmTypeInfo(final Edm edm, final String typeExpression) { + String baseType; + final int collStartIdx = typeExpression.indexOf("Collection("); + final int collEndIdx = typeExpression.lastIndexOf(')'); + if (collStartIdx == -1) { + baseType = typeExpression; + collection = false; + } else { + if (collEndIdx == -1) { + throw new IllegalArgumentException("Malformed type: " + typeExpression); + } + + collection = true; + baseType = typeExpression.substring(collStartIdx + 11, collEndIdx); + } + + baseType = baseType.replaceAll("^#", ""); + + final String typeName; + final String namespace; + + final int lastDotIdx = baseType.lastIndexOf('.'); + if (lastDotIdx == -1) { + namespace = EdmPrimitiveType.EDM_NAMESPACE; + typeName = baseType; + } else { + namespace = baseType.substring(0, lastDotIdx); + typeName = baseType.substring(lastDotIdx + 1); + } + + if (StringUtils.isBlank(typeName)) { + throw new IllegalArgumentException("Null or empty type name in " + typeExpression); + } + + fullQualifiedName = new FullQualifiedName(namespace, typeName); + + try { + primitiveType = EdmPrimitiveTypeKind.valueOf(fullQualifiedName.getName()); + } catch (final IllegalArgumentException e) { + primitiveType = null; + } + if (primitiveType == null && edm != null) { + typeDefinition = edm.getTypeDefinition(fullQualifiedName); + if (typeDefinition == null) { + enumType = edm.getEnumType(fullQualifiedName); + if (enumType == null) { + complexType = edm.getComplexType(fullQualifiedName); + if (complexType == null) { + entityType = edm.getEntityType(fullQualifiedName); + } + } + } + } + } + + public String internal() { + final StringBuilder deserialize = new StringBuilder(); + + if (isCollection()) { + deserialize.append("Collection("); + } + + deserialize.append(getFullQualifiedName().toString()); + + if (isCollection()) { + deserialize.append(")"); + } + + return deserialize.toString(); + } + + public String external() { + final StringBuilder serialize = new StringBuilder(); + + if (isCollection()) { + serialize.append('#'); + serialize.append("Collection("); + } + + if (isPrimitiveType()) { + serialize.append(getFullQualifiedName().getName()); + }else{ + serialize.append(getFullQualifiedName().toString()); + } + + if (isCollection()) { + serialize.append(")"); + } + + if (!isPrimitiveType() && !isCollection()) { + serialize.insert(0, '#'); + } + + return serialize.toString(); + } + + public boolean isCollection() { + return collection; + } + + public FullQualifiedName getFullQualifiedName() { + return fullQualifiedName; + } + + public boolean isPrimitiveType() { + return primitiveType != null; + } + + public EdmPrimitiveTypeKind getPrimitiveTypeKind() { + return primitiveType; + } + + public boolean isTypeDefinition() { + return typeDefinition != null; + } + + public EdmTypeDefinition getTypeDefinition() { + return typeDefinition; + } + + public boolean isEnumType() { + return enumType != null; + } + + public EdmEnumType getEnumType() { + return enumType; + } + + public boolean isComplexType() { + return complexType != null; + } + + public EdmComplexType getComplexType() { + return complexType; + } + + public boolean isEntityType() { + return entityType != null; + } + + public EdmEntityType getEntityType() { + return entityType; + } + + public EdmType getType() { + return isPrimitiveType() + ? EdmPrimitiveTypeFactory.getInstance(getPrimitiveTypeKind()) + : isTypeDefinition() + ? getTypeDefinition() + : isEnumType() + ? getEnumType() + : isComplexType() + ? getComplexType() + : isEntityType() + ? getEntityType() + : null; + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/Target.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/Target.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/Target.java new file mode 100644 index 0000000..083ef6f --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/Target.java @@ -0,0 +1,66 @@ +/* + * 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; + +import org.apache.olingo.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.commons.api.edm.FullQualifiedName; + +/** + * An Edm target element. It contains a target as a String name as well as the {@link FullQualifiedName} of the entity + * container it is contained in. + */ +public class Target { + + private String targetName; + private FullQualifiedName entityContainer; + + public Target(String target, EdmEntityContainer defaultContainer) { + final String[] bindingTargetParts = target.split("/"); + if (bindingTargetParts.length == 1) { + entityContainer = defaultContainer.getFullQualifiedName(); + targetName = bindingTargetParts[0]; + } else { + entityContainer = new FullQualifiedName(bindingTargetParts[0]); + targetName = bindingTargetParts[1]; + } + } + + /** + * @return name of the target as a String + */ + public String getTargetName() { + return targetName; + } + + /** + * @return {@link FullQualifiedName} of the entity container this target is contained in. + */ + public FullQualifiedName getEntityContainer() { + return entityContainer; + } + + @Override + public String toString() { + if (entityContainer == null) { + return targetName; + } + return entityContainer.getFullQualifiedNameAsString() + "/" + targetName; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/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 index 371a4a2..419adea 100644 --- 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 @@ -24,7 +24,7 @@ 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.provider.EdmTypeInfo; +import org.apache.olingo.commons.core.edm.EdmTypeInfo; public class EdmCastImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmCast { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/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 index a1005c0..03ae319 100644 --- 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 @@ -24,7 +24,7 @@ import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpressi 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.provider.EdmTypeInfo; +import org.apache.olingo.commons.core.edm.EdmTypeInfo; public class EdmIsOfImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmIsOf { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/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 index 4aaf731..cd71c6c 100644 --- 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 @@ -24,7 +24,7 @@ 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.provider.EdmTypeInfo; +import org.apache.olingo.commons.core.edm.EdmTypeInfo; public class EdmRecordImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmRecord { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmAnnotatable.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmAnnotatable.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmAnnotatable.java deleted file mode 100644 index 0574a4e..0000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmAnnotatable.java +++ /dev/null @@ -1,69 +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.commons.core.edm.provider; - -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.provider.Annotatable; -import org.apache.olingo.commons.api.edm.provider.Annotation; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public abstract class AbstractEdmAnnotatable implements EdmAnnotatable { - - private final Annotatable annotatable; - private List<EdmAnnotation> annotations; - protected final Edm edm; - - public AbstractEdmAnnotatable(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) { - final List<EdmAnnotation> annotationsLocal = new ArrayList<EdmAnnotation>(); - if (annotatable != null) { - for (Annotation annotation : annotatable.getAnnotations()) { - annotationsLocal.add(new EdmAnnotationImpl(edm, annotation)); - } - - annotations = Collections.unmodifiableList(annotationsLocal); - } - } - return annotations; - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBindingTarget.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBindingTarget.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBindingTarget.java deleted file mode 100644 index 9ef4c74..0000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBindingTarget.java +++ /dev/null @@ -1,133 +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.commons.core.edm.provider; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmBindingTarget; -import org.apache.olingo.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.provider.BindingTarget; -import org.apache.olingo.commons.api.edm.provider.NavigationPropertyBinding; - -public abstract class AbstractEdmBindingTarget extends AbstractEdmNamed implements EdmBindingTarget { - - private final BindingTarget target; - private final EdmEntityContainer container; - - private List<EdmNavigationPropertyBinding> navigationPropertyBindings; - - public AbstractEdmBindingTarget(final Edm edm, final EdmEntityContainer container, final BindingTarget target) { - super(edm, target.getName(), target); - this.container = container; - this.target = target; - } - - @Override - public List<EdmNavigationPropertyBinding> getNavigationPropertyBindings() { - if (navigationPropertyBindings == null) { - List<NavigationPropertyBinding> providerBindings = target.getNavigationPropertyBindings(); - final List<EdmNavigationPropertyBinding> navigationPropertyBindingsLocal = - new ArrayList<EdmNavigationPropertyBinding>(); - if (providerBindings != null) { - for (NavigationPropertyBinding binding : providerBindings) { - navigationPropertyBindingsLocal.add(new EdmNavigationPropertyBindingImpl(binding.getPath(), - binding.getTarget())); - } - navigationPropertyBindings = Collections.unmodifiableList(navigationPropertyBindingsLocal); - } - } - return navigationPropertyBindings; - } - - @Override - public EdmEntityContainer getEntityContainer() { - return container; - } - - @Override - public EdmEntityType getEntityType() { - final EdmEntityType entityType = edm.getEntityType(target.getTypeFQN()); - if (entityType == null) { - throw new EdmException("Can´t find entity type: " + target.getTypeFQN() + " for entity set or singleton: " - + getName()); - } - return entityType; - } - - @Override - public FullQualifiedName getAnnotationsTargetFQN() { - return container.getFullQualifiedName(); - } - - @Override - public String getAnnotationsTargetPath() { - return getName(); - } - - @Override - public EdmBindingTarget getRelatedBindingTarget(final String path) { - if (path == null) { - return null; - } - EdmBindingTarget bindingTarget = null; - boolean found = false; - for (final Iterator<EdmNavigationPropertyBinding> itor = getNavigationPropertyBindings().iterator(); itor.hasNext() - && !found;) { - - final EdmNavigationPropertyBinding binding = itor.next(); - if(binding.getPath() == null || binding.getTarget() == null){ - throw new EdmException("Path or Target in navigation property binding must not be null!"); - } - if (path.startsWith(binding.getPath())) { - final Target edmTarget = new Target(binding.getTarget(), container); - - final EdmEntityContainer entityContainer = edm.getEntityContainer(edmTarget.getEntityContainer()); - if (entityContainer == null) { - throw new EdmException("Cannot find entity container with name: " + edmTarget.getEntityContainer()); - } - try { - bindingTarget = entityContainer.getEntitySet(edmTarget.getTargetName()); - - if (bindingTarget == null) { - throw new EdmException("Cannot find EntitySet " + edmTarget.getTargetName()); - } - } catch (EdmException e) { - // try with singletons ... - bindingTarget = entityContainer.getSingleton(edmTarget.getTargetName()); - - if (bindingTarget == null) { - throw new EdmException("Cannot find Singleton " + edmTarget.getTargetName()); - } - } finally { - found = bindingTarget != null; - } - } - } - - return bindingTarget; - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmNamed.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmNamed.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmNamed.java deleted file mode 100644 index 8835bc5..0000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmNamed.java +++ /dev/null @@ -1,38 +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.commons.core.edm.provider; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmNamed; -import org.apache.olingo.commons.api.edm.provider.Annotatable; - -public abstract class AbstractEdmNamed extends AbstractEdmAnnotatable implements EdmNamed { - - private final String name; - - public AbstractEdmNamed(final Edm edm, final String name, final Annotatable annotatable) { - super(edm, annotatable); - this.name = name; - } - - @Override - public String getName() { - return name; - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperation.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperation.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperation.java deleted file mode 100644 index c615376..0000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperation.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.commons.core.edm.provider; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmBindingTarget; -import org.apache.olingo.commons.api.edm.EdmEntitySet; -import org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.EdmOperation; -import org.apache.olingo.commons.api.edm.EdmParameter; -import org.apache.olingo.commons.api.edm.EdmReturnType; -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.Operation; -import org.apache.olingo.commons.api.edm.provider.Parameter; - -public abstract class AbstractEdmOperation extends EdmTypeImpl implements EdmOperation { - - private final Operation operation; - private Map<String, EdmParameter> parameters; - private List<String> parameterNames; - private EdmReturnType returnType; - - protected AbstractEdmOperation(final Edm edm, final FullQualifiedName name, final Operation operation, - final EdmTypeKind kind) { - - super(edm, name, kind, operation); - this.operation = operation; - } - - @Override - public EdmParameter getParameter(final String name) { - if (parameters == null) { - createParameters(); - } - return parameters.get(name); - } - - @Override - public List<String> getParameterNames() { - if (parameterNames == null) { - createParameters(); - } - return Collections.unmodifiableList(parameterNames); - } - - private void createParameters() { - if(parameters == null) { - final Map<String, EdmParameter> parametersLocal = new LinkedHashMap<String, EdmParameter>(); - final List<Parameter> providerParameters = operation.getParameters(); - if (providerParameters != null) { - final List<String> parameterNamesLocal = new ArrayList<String>(providerParameters.size()); - for (Parameter parameter : providerParameters) { - parametersLocal.put(parameter.getName(), new EdmParameterImpl(edm, parameter)); - parameterNamesLocal.add(parameter.getName()); - } - - parameters = parametersLocal; - parameterNames = parameterNamesLocal; - } else { - parameterNames = Collections.emptyList(); - } - } - } - - @Override - public EdmEntitySet getReturnedEntitySet(final EdmEntitySet bindingParameterEntitySet) { - EdmEntitySet returnedEntitySet = null; - if (bindingParameterEntitySet != null && operation.getEntitySetPath() != null) { - final EdmBindingTarget relatedBindingTarget = - bindingParameterEntitySet.getRelatedBindingTarget(operation.getEntitySetPath()); - if (relatedBindingTarget == null) { - throw new EdmException("Cannot find entity set with path: " + operation.getEntitySetPath()); - } - if (relatedBindingTarget instanceof EdmEntitySet) { - returnedEntitySet = (EdmEntitySet) relatedBindingTarget; - } else { - throw new EdmException("BindingTarget with name: " + relatedBindingTarget.getName() - + " must be an entity set"); - } - } - return returnedEntitySet; - } - - @Override - public EdmReturnType getReturnType() { - if (returnType == null && operation.getReturnType() != null) { - returnType = new EdmReturnTypeImpl(edm, operation.getReturnType()); - } - return returnType; - } - - @Override - public boolean isBound() { - return operation.isBound(); - } - - @Override - public FullQualifiedName getBindingParameterTypeFqn() { - if (isBound()) { - Parameter bindingParameter = operation.getParameters().get(0); - return bindingParameter.getTypeFQN(); - } - return null; - } - - @Override - public Boolean isBindingParameterTypeCollection() { - if (isBound()) { - Parameter bindingParameter = operation.getParameters().get(0); - return bindingParameter.isCollection(); - } - return null; - } - - @Override - public String getEntitySetPath() { - return operation.getEntitySetPath(); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperationImport.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperationImport.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperationImport.java deleted file mode 100644 index 27aa72b..0000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperationImport.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.commons.core.edm.provider; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.commons.api.edm.EdmEntitySet; -import org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.EdmOperationImport; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.provider.OperationImport; - -public abstract class AbstractEdmOperationImport extends AbstractEdmNamed implements EdmOperationImport { - - protected final EdmEntityContainer container; - private final Target entitySet; - private EdmEntitySet returnedEntitySet; - - public AbstractEdmOperationImport(final Edm edm, final EdmEntityContainer container, - final OperationImport operationImport) { - super(edm, operationImport.getName(), operationImport); - this.container = container; - if (operationImport.getEntitySet() != null) { - this.entitySet = new Target(operationImport.getEntitySet(), container); - } else { - this.entitySet = null; - } - } - - @Override - public FullQualifiedName getFullQualifiedName() { - return new FullQualifiedName(container.getNamespace(), getName()); - } - - @Override - public EdmEntitySet getReturnedEntitySet() { - if (entitySet != null && returnedEntitySet == null) { - EdmEntityContainer entityContainer = edm.getEntityContainer(entitySet.getEntityContainer()); - if (entityContainer == null) { - throw new EdmException("Can´t find entity container with name: " + entitySet.getEntityContainer()); - } - returnedEntitySet = entityContainer.getEntitySet(entitySet.getTargetName()); - if (returnedEntitySet == null) { - throw new EdmException("Can´t find entity set with name: " + entitySet.getTargetName()); - } - } - return returnedEntitySet; - } - - @Override - public EdmEntityContainer getEntityContainer() { - return container; - } - - @Override - public FullQualifiedName getAnnotationsTargetFQN() { - return container.getFullQualifiedName(); - } - - @Override - public String getAnnotationsTargetPath() { - return getName(); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmStructuredType.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmStructuredType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmStructuredType.java deleted file mode 100644 index 29d08ce..0000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmStructuredType.java +++ /dev/null @@ -1,196 +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.commons.core.edm.provider; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmElement; -import org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.EdmNavigationProperty; -import org.apache.olingo.commons.api.edm.EdmProperty; -import org.apache.olingo.commons.api.edm.EdmStructuredType; -import org.apache.olingo.commons.api.edm.EdmType; -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.NavigationProperty; -import org.apache.olingo.commons.api.edm.provider.Property; -import org.apache.olingo.commons.api.edm.provider.StructuralType; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -public abstract class AbstractEdmStructuredType extends EdmTypeImpl implements EdmStructuredType { - - protected EdmStructuredType baseType; - protected FullQualifiedName baseTypeName; - - private final StructuralType providerStructuredType; - - private List<String> propertyNames; - private Map<String, EdmProperty> properties; - private List<String> navigationPropertyNames; - private Map<String, EdmNavigationProperty> navigationProperties; - - public AbstractEdmStructuredType( - final Edm edm, - final FullQualifiedName typeName, - final EdmTypeKind kind, - final StructuralType structuredType) { - - super(edm, typeName, kind, structuredType); - this.baseTypeName = structuredType.getBaseTypeFQN(); - this.providerStructuredType = structuredType; - } - - protected abstract EdmStructuredType buildBaseType(FullQualifiedName baseTypeName); - - protected abstract void checkBaseType(); - - @Override - public List<String> getPropertyNames() { - if (propertyNames == null) { - final List<String> localPropertyNames = new ArrayList<String>(); - checkBaseType(); - if (baseType != null) { - localPropertyNames.addAll(baseType.getPropertyNames()); - } - localPropertyNames.addAll(getProperties().keySet()); - propertyNames = Collections.unmodifiableList(localPropertyNames); - } - return propertyNames; - } - - @Override - public List<String> getNavigationPropertyNames() { - if (navigationPropertyNames == null) { - final ArrayList<String> localNavigatinPropertyNames = new ArrayList<String>(); - checkBaseType(); - if (baseType != null) { - localNavigatinPropertyNames.addAll(baseType.getNavigationPropertyNames()); - } - localNavigatinPropertyNames.addAll(getNavigationProperties().keySet()); - navigationPropertyNames = Collections.unmodifiableList(localNavigatinPropertyNames); - } - return navigationPropertyNames; - } - - @Override - public EdmElement getProperty(final String name) { - EdmElement property = getStructuralProperty(name); - if (property == null) { - property = getNavigationProperty(name); - } - return property; - } - - @Override - public EdmProperty getStructuralProperty(final String name) { - EdmProperty property = null; - checkBaseType(); - if (baseType != null) { - property = baseType.getStructuralProperty(name); - } - if (property == null) { - property = getProperties().get(name); - } - return property; - } - - @Override - public EdmNavigationProperty getNavigationProperty(final String name) { - EdmNavigationProperty property = null; - checkBaseType(); - if (baseType != null) { - property = baseType.getNavigationProperty(name); - } - if (property == null) { - property = getNavigationProperties().get(name); - } - return property; - } - - @Override - public boolean compatibleTo(final EdmType targetType) { - EdmStructuredType sourceType = this; - if (targetType == null) { - throw new EdmException("Target type must not be null"); - } - while (!sourceType.getName().equals(targetType.getName()) - || !sourceType.getNamespace().equals(targetType.getNamespace())) { - - sourceType = sourceType.getBaseType(); - if (sourceType == null) { - return false; - } - } - - return true; - } - - @Override - public String getAnnotationsTargetPath() { - return null; - } - - @Override - public FullQualifiedName getAnnotationsTargetFQN() { - return getFullQualifiedName(); - } - - public Map<String, EdmProperty> getProperties() { - if (properties == null) { - final Map<String, EdmProperty> localPorperties = new LinkedHashMap<String, EdmProperty>(); - final List<Property> structureTypeProperties = providerStructuredType.getProperties(); - for (Property property : structureTypeProperties) { - localPorperties.put(property.getName(), new EdmPropertyImpl(edm, typeName, property)); - } - properties = Collections.unmodifiableMap(localPorperties); - } - return properties; - } - - public Map<String, EdmNavigationProperty> getNavigationProperties() { - if (navigationProperties == null) { - final Map<String, EdmNavigationProperty> localNavigationProperties = - new LinkedHashMap<String, EdmNavigationProperty>(); - final List<NavigationProperty> structuredTypeNavigationProperties = - providerStructuredType.getNavigationProperties(); - - if (structuredTypeNavigationProperties != null) { - for (NavigationProperty navigationProperty : structuredTypeNavigationProperties) { - localNavigationProperties.put(navigationProperty.getName(), - new EdmNavigationPropertyImpl(edm, typeName, navigationProperty)); - } - } - - navigationProperties = Collections.unmodifiableMap(localNavigationProperties); - } - return navigationProperties; - } - - public boolean isOpenType() { - return providerStructuredType.isOpenType(); - } - - public boolean isAbstract() { - return providerStructuredType.isAbstract(); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/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 deleted file mode 100644 index 32276c5..0000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java +++ /dev/null @@ -1,32 +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.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 AbstractEdmOperation implements EdmAction { - - public 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/ac32d236/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 deleted file mode 100644 index 7d93e9a..0000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImportImpl.java +++ /dev/null @@ -1,46 +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.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 AbstractEdmOperationImport 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/ac32d236/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 deleted file mode 100644 index 07523e6..0000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java +++ /dev/null @@ -1,225 +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.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.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 extends AbstractEdmAnnotatable implements EdmAnnotation { - - private final Annotation annotation; - private EdmTerm term; - private EdmAnnotationExpression expression; - - public EdmAnnotationImpl(final Edm edm, final Annotation annotation) { - super(edm, annotation); - this.annotation = 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; - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/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 deleted file mode 100644 index d12010d..0000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java +++ /dev/null @@ -1,151 +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.commons.core.edm.provider; - -import java.util.ArrayList; -import java.util.Collections; -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(); - - EdmAnnotationsTarget localTarget = baseEntityContainer == null ? null - : baseEntityContainer.getActionImport(path); - if (localTarget == null) { - localTarget = getTarget(edm.getComplexType(base), path); - if (localTarget == null) { - if(baseEntityContainer != null && baseEntityContainer.getFullQualifiedName().equals(base)){ - localTarget = baseEntityContainer; - } - if (localTarget == null) { - localTarget = baseEntityContainer == null ? null : baseEntityContainer.getEntitySet(path); - if (localTarget == null) { - localTarget = getTarget(edm.getEntityType(base), path); - if (localTarget == null) { - localTarget = getTarget(edm.getEnumType(base), path); - if (localTarget == null) { - localTarget = baseEntityContainer == null ? null : baseEntityContainer.getFunctionImport(path); - if (localTarget == null) { - localTarget = baseEntityContainer == null ? null : baseEntityContainer.getSingleton(path); - if (localTarget == null) { - localTarget = edm.getTerm(base); - if (localTarget == null) { - localTarget = edm.getTypeDefinition(base); - } - } - } - } - } - } - } - } - } - target = localTarget; - } - - 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) { - List<EdmAnnotation> annotationsLocal = new ArrayList<EdmAnnotation>(); - for (Annotation annotation : annotationGroup.getAnnotations()) { - annotationsLocal.add(new EdmAnnotationImpl(edm, annotation)); - } - - annotations = Collections.unmodifiableList(annotationsLocal); - } - return annotations; - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/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 deleted file mode 100644 index 7a14ae1..0000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java +++ /dev/null @@ -1,65 +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.commons.core.edm.provider; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmComplexType; -import org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.EdmStructuredType; -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.ComplexType; - -public class EdmComplexTypeImpl extends AbstractEdmStructuredType implements EdmComplexType { - - public EdmComplexTypeImpl(final Edm edm, final FullQualifiedName name, final ComplexType complexType) { - super(edm, name, EdmTypeKind.COMPLEX, complexType); - } - - @Override - protected EdmStructuredType buildBaseType(final FullQualifiedName baseTypeName) { - EdmComplexType baseType = null; - if (baseTypeName != null) { - baseType = edm.getComplexType(baseTypeName); - if (baseType == null) { - throw new EdmException("Can't find base type with name: " + baseTypeName + " for complex type: " - + getName()); - } - } - return baseType; - } - - @Override - public EdmComplexType getBaseType() { - checkBaseType(); - return (EdmComplexType) baseType; - } - - @Override - protected void checkBaseType() { - if (baseTypeName != null && baseType == null) { - baseType = buildBaseType(baseTypeName); - } - } - - @Override - public TargetType getAnnotationsTargetType() { - return TargetType.ComplexType; - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java deleted file mode 100644 index 165b5cd..0000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java +++ /dev/null @@ -1,327 +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.commons.core.edm.provider; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.apache.olingo.commons.api.ODataException; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmActionImport; -import org.apache.olingo.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.commons.api.edm.EdmEntitySet; -import org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.EdmFunctionImport; -import org.apache.olingo.commons.api.edm.EdmSingleton; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.provider.ActionImport; -import org.apache.olingo.commons.api.edm.provider.EdmProvider; -import org.apache.olingo.commons.api.edm.provider.EntityContainer; -import org.apache.olingo.commons.api.edm.provider.EntityContainerInfo; -import org.apache.olingo.commons.api.edm.provider.EntitySet; -import org.apache.olingo.commons.api.edm.provider.FunctionImport; -import org.apache.olingo.commons.api.edm.provider.Singleton; - -public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntityContainer { - - private final EdmProvider provider; - private EntityContainer container; - - private final FullQualifiedName entityContainerName; - private final FullQualifiedName parentContainerName; - - private List<EdmSingleton> singletons; - private final Map<String, EdmSingleton> singletonCache = Collections.synchronizedMap( - new LinkedHashMap<String, EdmSingleton>()); - private List<EdmEntitySet> entitySets; - private final Map<String, EdmEntitySet> entitySetCache = Collections.synchronizedMap( - new LinkedHashMap<String, EdmEntitySet>()); - private List<EdmActionImport> actionImports; - private final Map<String, EdmActionImport> actionImportCache = Collections.synchronizedMap( - new LinkedHashMap<String, EdmActionImport>()); - private List<EdmFunctionImport> functionImports; - private final Map<String, EdmFunctionImport> functionImportCache = Collections.synchronizedMap( - new LinkedHashMap<String, EdmFunctionImport>()); - - public EdmEntityContainerImpl(final Edm edm, final EdmProvider provider, - final EntityContainerInfo entityContainerInfo) { - super(edm, entityContainerInfo.getContainerName().getName(), null); - this.provider = provider; - this.entityContainerName = entityContainerInfo.getContainerName(); - this.parentContainerName = entityContainerInfo.getExtendsContainer(); - } - - public EdmEntityContainerImpl(final Edm edm, final EdmProvider provider, final FullQualifiedName containerFQN, - final EntityContainer entityContainer) { - super(edm, containerFQN.getName(), entityContainer); - this.provider = provider; - container = entityContainer; - this.entityContainerName = containerFQN; - this.parentContainerName = entityContainer.getExtendsContainerFQN(); - } - - @Override - public String getNamespace() { - return entityContainerName.getNamespace(); - } - - @Override - public FullQualifiedName getFullQualifiedName() { - return entityContainerName; - } - - @Override - public EdmSingleton getSingleton(final String singletonName) { - EdmSingleton singleton = singletonCache.get(singletonName); - if (singleton == null) { - singleton = createSingleton(singletonName); - if (singleton != null) { - singletonCache.put(singletonName, singleton); - } - } - return singleton; - } - - @Override - public EdmEntitySet getEntitySet(final String entitySetName) { - EdmEntitySet entitySet = entitySetCache.get(entitySetName); - if (entitySet == null) { - entitySet = createEntitySet(entitySetName); - if (entitySet != null) { - entitySetCache.put(entitySetName, entitySet); - } - } - return entitySet; - } - - @Override - public EdmActionImport getActionImport(final String actionImportName) { - EdmActionImport actionImport = actionImportCache.get(actionImportName); - if (actionImport == null) { - actionImport = createActionImport(actionImportName); - if (actionImport != null) { - actionImportCache.put(actionImportName, actionImport); - } - } - return actionImport; - } - - @Override - public EdmFunctionImport getFunctionImport(final String functionImportName) { - EdmFunctionImport functionImport = functionImportCache.get(functionImportName); - if (functionImport == null) { - functionImport = createFunctionImport(functionImportName); - if (functionImport != null) { - functionImportCache.put(functionImportName, functionImport); - } - } - return functionImport; - } - - @Override - public List<EdmEntitySet> getEntitySets() { - if (entitySets == null) { - loadAllEntitySets(); - } - return Collections.unmodifiableList(entitySets); - } - - @Override - public List<EdmFunctionImport> getFunctionImports() { - if (functionImports == null) { - loadAllFunctionImports(); - } - return Collections.unmodifiableList(functionImports); - } - - @Override - public List<EdmSingleton> getSingletons() { - if (singletons == null) { - loadAllSingletons(); - } - return Collections.unmodifiableList(singletons); - } - - @Override - public List<EdmActionImport> getActionImports() { - if (actionImports == null) { - loadAllActionImports(); - } - return Collections.unmodifiableList(actionImports); - } - - @Override - public FullQualifiedName getParentContainerName() { - return parentContainerName; - } - - protected EdmSingleton createSingleton(final String singletonName) { - EdmSingleton singleton = null; - - try { - final Singleton providerSingleton = provider.getSingleton(entityContainerName, singletonName); - if (providerSingleton != null) { - singleton = new EdmSingletonImpl(edm, this, providerSingleton); - } - } catch (ODataException e) { - throw new EdmException(e); - } - - return singleton; - } - - protected EdmEntitySet createEntitySet(final String entitySetName) { - EdmEntitySet entitySet = null; - - try { - final EntitySet providerEntitySet = provider.getEntitySet(entityContainerName, entitySetName); - if (providerEntitySet != null) { - entitySet = new EdmEntitySetImpl(edm, this, providerEntitySet); - } - } catch (ODataException e) { - throw new EdmException(e); - } - - return entitySet; - } - - protected EdmActionImport createActionImport(final String actionImportName) { - EdmActionImport actionImport = null; - - try { - final ActionImport providerImport = provider.getActionImport(entityContainerName, actionImportName); - if (providerImport != null) { - actionImport = new EdmActionImportImpl(edm, this, providerImport); - } - } catch (ODataException e) { - throw new EdmException(e); - } - - return actionImport; - } - - protected EdmFunctionImport createFunctionImport(final String functionImportName) { - EdmFunctionImport functionImport = null; - - try { - final FunctionImport providerImport = provider.getFunctionImport(entityContainerName, functionImportName); - if (providerImport != null) { - functionImport = new EdmFunctionImportImpl(edm, this, providerImport); - } - } catch (ODataException e) { - throw new EdmException(e); - } - - return functionImport; - } - - protected void loadAllEntitySets() { - loadContainer(); - final List<EntitySet> providerEntitySets = container.getEntitySets(); - final List<EdmEntitySet> entitySetsLocal = new ArrayList<EdmEntitySet>(); - - if (providerEntitySets != null) { - for (EntitySet entitySet : providerEntitySets) { - final EdmEntitySetImpl impl = new EdmEntitySetImpl(edm, this, entitySet); - entitySetCache.put(impl.getName(), impl); - entitySetsLocal.add(impl); - } - entitySets = entitySetsLocal; - } - } - - protected void loadAllFunctionImports() { - loadContainer(); - final List<FunctionImport> providerFunctionImports = container.getFunctionImports(); - final ArrayList<EdmFunctionImport> functionImportsLocal = new ArrayList<EdmFunctionImport>(); - - if (providerFunctionImports != null) { - for (FunctionImport functionImport : providerFunctionImports) { - EdmFunctionImportImpl impl = new EdmFunctionImportImpl(edm, this, functionImport); - functionImportCache.put(impl.getName(), impl); - functionImportsLocal.add(impl); - } - functionImports = functionImportsLocal; - } - } - - protected void loadAllSingletons() { - loadContainer(); - final List<Singleton> providerSingletons = container.getSingletons(); - final List<EdmSingleton> singletonsLocal = new ArrayList<EdmSingleton>(); - - if (providerSingletons != null) { - for (Singleton singleton : providerSingletons) { - final EdmSingletonImpl impl = new EdmSingletonImpl(edm, this, singleton); - singletonCache.put(singleton.getName(), impl); - singletonsLocal.add(impl); - } - singletons = singletonsLocal; - } - } - - protected void loadAllActionImports() { - loadContainer(); - final List<ActionImport> providerActionImports = container.getActionImports(); - final List<EdmActionImport> actionImportsLocal = new ArrayList<EdmActionImport>(); - - if (providerActionImports != null) { - for (ActionImport actionImport : providerActionImports) { - final EdmActionImportImpl impl = new EdmActionImportImpl(edm, this, actionImport); - actionImportCache.put(actionImport.getName(), impl); - actionImportsLocal.add(impl); - } - actionImports = actionImportsLocal; - } - - } - - private void loadContainer() { - if (container == null) { - try { - EntityContainer containerLocal = provider.getEntityContainer(); - if (containerLocal == null) { - containerLocal = new EntityContainer().setName(getName()); - } - - container = containerLocal; - } catch (ODataException e) { - throw new EdmException(e); - } - } - } - - @Override - public String getAnnotationsTargetPath() { - return null; - } - - @Override - public FullQualifiedName getAnnotationsTargetFQN() { - return getFullQualifiedName(); - } - - @Override - public TargetType getAnnotationsTargetType() { - return TargetType.EntityContainer; - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntitySetImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntitySetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntitySetImpl.java deleted file mode 100644 index 867b82c..0000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntitySetImpl.java +++ /dev/null @@ -1,44 +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.commons.core.edm.provider; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.commons.api.edm.EdmEntitySet; -import org.apache.olingo.commons.api.edm.provider.EntitySet; - -public class EdmEntitySetImpl extends AbstractEdmBindingTarget implements EdmEntitySet { - - private EntitySet entitySet; - - public EdmEntitySetImpl(final Edm edm, final EdmEntityContainer container, final EntitySet entitySet) { - super(edm, container, entitySet); - this.entitySet = entitySet; - } - - @Override - public boolean isIncludeInServiceDocument() { - return entitySet.isIncludeInServiceDocument(); - } - - @Override - public TargetType getAnnotationsTargetType() { - return TargetType.EntitySet; - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ac32d236/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java deleted file mode 100644 index 3040499..0000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java +++ /dev/null @@ -1,146 +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.commons.core.edm.provider; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; -import org.apache.olingo.commons.api.edm.EdmStructuredType; -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.EntityType; -import org.apache.olingo.commons.api.edm.provider.PropertyRef; - -public class EdmEntityTypeImpl extends AbstractEdmStructuredType implements EdmEntityType { - - private EntityType entityType; - private boolean baseTypeChecked = false; - private final boolean hasStream; - protected EdmEntityType entityBaseType; - private final List<String> keyPredicateNames = Collections.synchronizedList(new ArrayList<String>()); - private final Map<String, EdmKeyPropertyRef> keyPropertyRefs = - Collections.synchronizedMap(new LinkedHashMap<String, EdmKeyPropertyRef>()); - private List<EdmKeyPropertyRef> keyPropertyRefsList; - - public EdmEntityTypeImpl(final Edm edm, final FullQualifiedName name, final EntityType entityType) { - super(edm, name, EdmTypeKind.ENTITY, entityType); - this.entityType = entityType; - hasStream = entityType.hasStream(); - } - - @Override - protected void checkBaseType() { - if (!baseTypeChecked) { - if (baseTypeName != null) { - baseType = buildBaseType(baseTypeName); - entityBaseType = (EdmEntityType) baseType; - } - if (baseType == null - || (baseType.isAbstract() && ((EdmEntityType) baseType).getKeyPropertyRefs().size() == 0)) { - final List<PropertyRef> key = entityType.getKey(); - if (key != null) { - final List<EdmKeyPropertyRef> edmKey = new ArrayList<EdmKeyPropertyRef>(); - for (PropertyRef ref : key) { - edmKey.add(new EdmKeyPropertyRefImpl(this, ref)); - } - setEdmKeyPropertyRef(edmKey); - } - } - baseTypeChecked = true; - } - } - - protected void setEdmKeyPropertyRef(final List<EdmKeyPropertyRef> edmKey) { - for (EdmKeyPropertyRef ref : edmKey) { - if (ref.getAlias() == null) { - keyPredicateNames.add(ref.getName()); - keyPropertyRefs.put(ref.getName(), ref); - } else { - keyPredicateNames.add(ref.getAlias()); - keyPropertyRefs.put(ref.getAlias(), ref); - } - } - } - - @Override - protected EdmStructuredType buildBaseType(final FullQualifiedName baseTypeName) { - EdmEntityType baseType = null; - if (baseTypeName != null) { - baseType = edm.getEntityType(baseTypeName); - if (baseType == null) { - throw new EdmException("Cannot find base type with name: " + baseTypeName + " for entity type: " + getName()); - } - } - return baseType; - } - - @Override - public EdmEntityType getBaseType() { - checkBaseType(); - return entityBaseType; - } - - @Override - public List<String> getKeyPredicateNames() { - checkBaseType(); - if (keyPredicateNames.isEmpty() && baseType != null) { - return entityBaseType.getKeyPredicateNames(); - } - return Collections.unmodifiableList(keyPredicateNames); - } - - @Override - public List<EdmKeyPropertyRef> getKeyPropertyRefs() { - checkBaseType(); - if (keyPropertyRefsList == null) { - keyPropertyRefsList = new ArrayList<EdmKeyPropertyRef>(keyPropertyRefs.values()); - } - if (keyPropertyRefsList.isEmpty() && entityBaseType != null) { - return entityBaseType.getKeyPropertyRefs(); - } - return Collections.unmodifiableList(keyPropertyRefsList); - } - - @Override - public EdmKeyPropertyRef getKeyPropertyRef(final String keyPredicateName) { - checkBaseType(); - final EdmKeyPropertyRef edmKeyPropertyRef = keyPropertyRefs.get(keyPredicateName); - if (edmKeyPropertyRef == null && entityBaseType != null) { - return entityBaseType.getKeyPropertyRef(keyPredicateName); - } - return edmKeyPropertyRef; - } - - @Override - public boolean hasStream() { - return hasStream; - } - - @Override - public TargetType getAnnotationsTargetType() { - return TargetType.EntityType; - } -}
