From bae3d847a866bf1376627b09e55b65f4570c9f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Wed, 5 Mar 2014 16:06:00 +0100 Subject: [PATCH] [OLINGO-186] client-side implementation of commons Edm interfaces completed: some refactoring on server-side performed to extract common abstract implementation --- .../client/api/edm/xml/CommonParameter.java | 14 +- .../client/api/edm/xml/CommonProperty.java | 13 +- .../odata4/client/api/edm/xml/Member.java | 2 +- .../odata4/client/api/edm/xml/Schema.java | 1 - .../XMLMetadata.java} | 5 +- .../client/api/edm/xml/v4/BindingTarget.java | 31 ++ .../api/edm/xml/v4/EntityContainer.java | 4 + .../client/api/edm/xml/v4/EntitySet.java | 6 +- .../client/api/edm/xml/v4/ReturnType.java | 14 +- .../client/api/edm/xml/v4/Singleton.java | 9 +- .../client/api/edm/xml/v4/TypeDefinition.java | 12 +- .../client/api/op/ODataDeserializer.java | 4 +- .../odata4/client/api/op/ODataReader.java | 4 +- .../odata4/client/api/utils/EdmTypeInfo.java | 81 ++++ .../edm/AbstractEdmServiceMetadataImpl.java | 115 +++++ .../odata4/client/core/edm/EdmActionImpl.java | 37 ++ .../client/core/edm/EdmActionImportImpl.java | 45 ++ .../client/core/edm/EdmBindingTargetImpl.java | 80 ++++ .../odata4/client/core/edm/EdmClientImpl.java | 285 +++++++++++ .../client/core/edm/EdmComplexTypeImpl.java | 63 +++ .../core/edm/EdmEntityContainerImpl.java | 87 ++++ .../client/core/edm/EdmEntitySetImpl.java} | 32 +- .../client/core/edm/EdmEntityTypeImpl.java | 79 +++ .../client/core/edm/EdmEnumTypeImpl.java | 83 ++++ .../client/core/edm/EdmFunctionImpl.java | 44 ++ .../core/edm/EdmFunctionImportImpl.java | 47 ++ .../core/edm/EdmKeyPropertyRefImpl.java | 49 ++ .../core/edm/EdmNavigationPropertyImpl.java | 74 +++ .../client/core/edm/EdmOperationImpl.java | 63 +++ .../core/edm/EdmOperationImportImpl.java | 35 ++ .../client/core/edm/EdmParameterImpl.java | 74 +++ .../client/core/edm/EdmPropertyImpl.java | 91 ++++ .../client/core/edm/EdmReturnTypeImpl.java | 68 +++ .../client/core/edm/EdmSingletonImpl.java | 35 ++ .../core/edm/EdmStructuredTypeHelperImpl.java | 71 +++ .../core/edm/EdmTypeDefinitionImpl.java | 74 +++ .../core/edm/v3/EdmServiceMetadataImpl.java | 52 ++ .../client/core/edm/v3/EdmTypeImpl.java | 5 +- .../core/edm/v4/EdmServiceMetadataImpl.java | 83 ++++ .../client/core/edm/v4/EdmTypeImpl.java | 5 +- .../core/edm/{ => xml}/AbstractEdmType.java | 9 +- .../client/core/edm/xml/AbstractMember.java | 6 +- .../core/edm/xml/AbstractParameter.java | 28 +- .../client/core/edm/xml/AbstractProperty.java | 35 +- .../AbstractXMLMetadata.java} | 20 +- .../core/edm/xml/ParameterDeserializer.java | 69 +++ .../core/edm/xml/PropertyDeserializer.java | 102 ++++ .../client/core/edm/xml/v3/ParameterImpl.java | 2 - .../client/core/edm/xml/v3/PropertyImpl.java | 19 +- .../v3/XMLMetadataImpl.java} | 13 +- .../edm/xml/v4/AnnotationDeserializer.java | 2 +- .../core/edm/xml/v4/AnnotationImpl.java | 4 +- .../core/edm/xml/v4/EntityContainerImpl.java | 2 + .../client/core/edm/xml/v4/EntitySetImpl.java | 6 +- .../client/core/edm/xml/v4/ParameterImpl.java | 2 - .../client/core/edm/xml/v4/PropertyImpl.java | 2 - .../edm/xml/v4/ReturnTypeDeserializer.java | 60 +++ .../core/edm/xml/v4/ReturnTypeImpl.java | 28 +- .../client/core/edm/xml/v4/SchemaImpl.java | 4 + .../edm/xml/v4/SingletonDeserializer.java | 2 +- .../client/core/edm/xml/v4/SingletonImpl.java | 16 +- .../xml/v4/TypeDefinitionDeserializer.java | 9 +- .../core/edm/xml/v4/TypeDefinitionImpl.java | 21 +- .../v4/XMLMetadataImpl.java} | 15 +- .../annotation/AbstractElOrAttrConstruct.java | 2 +- .../annotation/AnnotatedDynExprConstruct.java | 2 +- .../v4/annotation/AnnotationPath.java | 2 +- .../edm/{ => xml}/v4/annotation/Apply.java | 2 +- .../v4/annotation/ApplyDeserializer.java | 2 +- .../edm/{ => xml}/v4/annotation/Cast.java | 2 +- .../v4/annotation/CastDeserializer.java | 2 +- .../{ => xml}/v4/annotation/Collection.java | 2 +- .../v4/annotation/CollectionDeserializer.java | 2 +- .../v4/annotation/ConstExprConstructImpl.java | 2 +- .../DynExprConstructDeserializer.java | 2 +- .../v4/annotation/DynExprConstructImpl.java | 2 +- .../v4/annotation/DynExprDoubleParamOp.java | 2 +- .../v4/annotation/DynExprSingleParamOp.java | 2 +- .../v4/annotation/ExprConstructImpl.java | 2 +- .../core/edm/{ => xml}/v4/annotation/If.java | 2 +- .../edm/{ => xml}/v4/annotation/IsOf.java | 2 +- .../v4/annotation/IsOfDeserializer.java | 2 +- .../v4/annotation/LabeledElement.java | 2 +- .../LabeledElementDeserializer.java | 2 +- .../annotation/LabeledElementReference.java | 2 +- .../v4/annotation/NavigationPropertyPath.java | 2 +- .../edm/{ => xml}/v4/annotation/Null.java | 2 +- .../v4/annotation/NullDeserializer.java | 2 +- .../edm/{ => xml}/v4/annotation/Path.java | 2 +- .../{ => xml}/v4/annotation/PropertyPath.java | 2 +- .../v4/annotation/PropertyValue.java | 2 +- .../annotation/PropertyValueDeserializer.java | 2 +- .../edm/{ => xml}/v4/annotation/Record.java | 2 +- .../v4/annotation/RecordDeserializer.java | 2 +- .../edm/{ => xml}/v4/annotation/UrlRef.java | 2 +- .../v4/annotation/UrlRefDeserializer.java | 2 +- .../core/op/impl/AbstractEdmDeserializer.java | 2 +- .../op/impl/v3/ODataDeserializerImpl.java | 5 +- .../core/op/impl/v3/ODataReaderImpl.java | 7 +- .../op/impl/v4/ODataDeserializerImpl.java | 5 +- .../core/op/impl/v4/ODataReaderImpl.java | 7 +- .../odata4/client/core/v3/MetadataTest.java | 22 +- .../odata4/client/core/v4/MetadataTest.java | 157 +++--- .../odata4/client/core/v4/demo-metadata.xml | 143 +++++- .../client/core/v4/fromdoc1-metadata.xml | 10 + .../client/core/v4/northwind-metadata.xml | 451 +++++++++++++++++- .../olingo/odata4/commons/api/edm/Edm.java | 12 +- .../commons/api/edm/EdmActionImportInfo.java | 40 ++ .../commons/api/edm/EdmComplexType.java | 2 +- .../odata4/commons/api/edm/EdmEntityType.java | 2 +- .../api/edm/EdmFunctionImportInfo.java | 7 +- .../api/edm/EdmOperationImportInfo.java | 31 ++ .../commons/api/edm/EdmServiceMetadata.java | 5 + ...cturalType.java => EdmStructuredType.java} | 24 +- .../olingo/odata4/commons/api/edm/Target.java | 71 +++ .../core/edm/AbstractEdmBindingTarget.java | 55 +++ .../core/edm/AbstractEdmComplexType.java | 50 ++ .../core/edm/AbstractEdmEntityContainer.java | 101 ++++ .../core/edm/AbstractEdmEntityType.java | 113 +++++ .../core/edm/AbstractEdmEnumType.java} | 245 +++++----- .../commons/core/edm/AbstractEdmImpl.java | 2 +- .../core/edm/AbstractEdmKeyPropertyRef.java | 80 ++++ .../edm/AbstractEdmNavigationProperty.java | 76 +++ .../core/edm/AbstractEdmOperation.java | 113 +++++ .../core/edm/AbstractEdmOperationImport.java | 63 +++ .../core/edm/AbstractEdmParameter.java | 87 ++++ .../commons/core/edm/AbstractEdmProperty.java | 70 +++ .../core/edm/AbstractEdmReturnType.java | 85 ++++ .../core/edm/AbstractEdmStructuredType.java | 128 +++++ .../core/edm/AbstractEdmTypeDefinition.java | 107 +++++ .../core/edm/EdmActionImportInfoImpl.java | 45 ++ .../commons/core/edm}/EdmElementImpl.java | 5 +- .../core/edm}/EdmEntitySetInfoImpl.java | 19 +- .../core/edm}/EdmFunctionImportInfoImpl.java | 22 +- .../commons/core/edm}/EdmMemberImpl.java | 16 +- .../commons/core/edm}/EdmNamedImpl.java | 13 +- .../core/edm/EdmOperationImportInfoImpl.java | 36 ++ .../core/edm}/EdmSingletonInfoImpl.java | 19 +- .../core/edm/EdmStructuredTypeHelper.java | 30 ++ .../odata4/commons/core/edm}/EdmTypeImpl.java | 20 +- .../primitivetype/EdmPrimitiveTypeKind.java | 16 + .../server/api/edm/provider/ActionImport.java | 1 + .../server/api/edm/provider/ComplexType.java | 2 +- .../server/api/edm/provider/EntityType.java | 2 +- .../api/edm/provider/FunctionImport.java | 1 + .../provider/NavigationPropertyBinding.java | 2 + .../api/edm/provider/OperationImport.java | 3 + ...tructuralType.java => StructuredType.java} | 14 +- .../core/edm/provider/EdmActionImpl.java | 7 +- .../edm/provider/EdmActionImportImpl.java | 8 +- .../edm/provider/EdmBindingTargetImpl.java | 55 +-- .../core/edm/provider/EdmComplexTypeImpl.java | 43 +- .../edm/provider/EdmEntityContainerImpl.java | 117 ++--- .../core/edm/provider/EdmEntitySetImpl.java | 3 +- .../core/edm/provider/EdmEntityTypeImpl.java | 104 ++-- .../core/edm/provider/EdmEnumTypeImpl.java | 61 +++ .../core/edm/provider/EdmFunctionImpl.java | 11 +- .../edm/provider/EdmFunctionImportImpl.java | 8 +- .../edm/provider/EdmKeyPropertyRefImpl.java | 49 +- .../provider/EdmNavigationPropertyImpl.java | 47 +- .../core/edm/provider/EdmOperationImpl.java | 105 ++-- .../edm/provider/EdmOperationImportImpl.java | 41 +- .../core/edm/provider/EdmParameterImpl.java | 44 +- .../core/edm/provider/EdmPropertyImpl.java | 44 +- .../core/edm/provider/EdmProviderImpl.java | 96 ++-- .../core/edm/provider/EdmReturnTypeImpl.java | 46 +- .../edm/provider/EdmServiceMetadataImpl.java | 66 ++- .../core/edm/provider/EdmSingletonImpl.java | 3 +- .../edm/provider/EdmStructuralTypeImpl.java | 129 ----- .../provider/EdmStructuredTypeHelperImpl.java | 72 +++ .../edm/provider/EdmTypeDefinitionImpl.java | 72 +-- .../server/core/uri/UriResourceTypedImpl.java | 4 +- .../core/uri/parser/UriParseTreeVisitor.java | 16 +- .../core/edm/provider/EdmActionImplTest.java | 6 +- .../edm/provider/EdmActionImportImplTest.java | 17 +- .../edm/provider/EdmComplexTypeImplTest.java | 8 +- .../edm/provider/EdmEntitySetImplTest.java | 2 +- .../provider/EdmEntitySetInfoImplTest.java | 51 -- .../edm/provider/EdmEntityTypeImplTest.java | 14 +- .../server/core/edm/provider/EdmEnumTest.java | 4 +- .../edm/provider/EdmFunctionImplTest.java | 4 +- .../provider/EdmFunctionImportImplTest.java | 2 +- .../EdmFunctionImportInfoImplTest.java | 50 -- .../provider/EdmKeyPropertyRefImplTest.java | 18 +- .../core/edm/provider/EdmMemberImplTest.java | 3 +- .../core/edm/provider/EdmNamedImplTest.java | 1 + .../edm/provider/EdmSingletonImplTest.java | 2 +- .../provider/EdmSingletonInfoImplTest.java | 51 -- .../core/edm/provider/EdmTypeImplTest.java | 1 + .../server/core/testutil/EdmTechProvider.java | 2 +- 190 files changed, 5118 insertions(+), 1529 deletions(-) rename odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/{EdmMetadata.java => xml/XMLMetadata.java} (93%) create mode 100644 odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/BindingTarget.java create mode 100644 odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/utils/EdmTypeInfo.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/AbstractEdmServiceMetadataImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmActionImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmActionImportImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmBindingTargetImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmClientImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmComplexTypeImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEntityContainerImpl.java rename odata4-lib/{odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/Target.java => odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEntitySetImpl.java} (59%) create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEntityTypeImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEnumTypeImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmFunctionImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmFunctionImportImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmKeyPropertyRefImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmNavigationPropertyImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmOperationImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmOperationImportImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmParameterImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmPropertyImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmReturnTypeImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmSingletonImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmStructuredTypeHelperImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmTypeDefinitionImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v3/EdmServiceMetadataImpl.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v4/EdmServiceMetadataImpl.java rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/AbstractEdmType.java (94%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{AbstractEdmMetadata.java => xml/AbstractXMLMetadata.java} (81%) create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/ParameterDeserializer.java create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/PropertyDeserializer.java rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{v3/EdmMetadataImpl.java => xml/v3/XMLMetadataImpl.java} (74%) create mode 100644 odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/ReturnTypeDeserializer.java rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{v4/EdmMetadataImpl.java => xml/v4/XMLMetadataImpl.java} (70%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/AbstractElOrAttrConstruct.java (94%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/AnnotatedDynExprConstruct.java (95%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/AnnotationPath.java (93%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/Apply.java (96%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/ApplyDeserializer.java (96%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/Cast.java (96%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/CastDeserializer.java (97%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/Collection.java (95%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/CollectionDeserializer.java (96%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/ConstExprConstructImpl.java (95%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/DynExprConstructDeserializer.java (98%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/DynExprConstructImpl.java (94%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/DynExprDoubleParamOp.java (96%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/DynExprSingleParamOp.java (96%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/ExprConstructImpl.java (94%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/If.java (95%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/IsOf.java (96%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/IsOfDeserializer.java (97%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/LabeledElement.java (95%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/LabeledElementDeserializer.java (96%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/LabeledElementReference.java (93%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/NavigationPropertyPath.java (93%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/Null.java (93%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/NullDeserializer.java (96%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/Path.java (93%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/PropertyPath.java (93%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/PropertyValue.java (95%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/PropertyValueDeserializer.java (96%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/Record.java (95%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/RecordDeserializer.java (96%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/UrlRef.java (95%) rename odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/{ => xml}/v4/annotation/UrlRefDeserializer.java (96%) create mode 100644 odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmActionImportInfo.java create mode 100644 odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmOperationImportInfo.java rename odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/{EdmStructuralType.java => EdmStructuredType.java} (78%) create mode 100644 odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/Target.java create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmBindingTarget.java create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmComplexType.java create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmEntityContainer.java create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmEntityType.java rename odata4-lib/{odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumImpl.java => odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmEnumType.java} (58%) create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmKeyPropertyRef.java create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmNavigationProperty.java create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmOperation.java create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmOperationImport.java create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmParameter.java create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmProperty.java create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmReturnType.java create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmStructuredType.java create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmTypeDefinition.java create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmActionImportInfoImpl.java rename odata4-lib/{odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider => odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm}/EdmElementImpl.java (85%) rename odata4-lib/{odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider => odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm}/EdmEntitySetInfoImpl.java (71%) rename odata4-lib/{odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider => odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm}/EdmFunctionImportInfoImpl.java (62%) rename odata4-lib/{odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider => odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm}/EdmMemberImpl.java (74%) rename odata4-lib/{odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider => odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm}/EdmNamedImpl.java (82%) create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmOperationImportInfoImpl.java rename odata4-lib/{odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider => odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm}/EdmSingletonInfoImpl.java (70%) create mode 100644 odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmStructuredTypeHelper.java rename odata4-lib/{odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider => odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm}/EdmTypeImpl.java (73%) rename odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/{StructuralType.java => StructuredType.java} (83%) create mode 100644 odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumTypeImpl.java delete mode 100644 odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmStructuralTypeImpl.java create mode 100644 odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmStructuredTypeHelperImpl.java delete mode 100644 odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetInfoImplTest.java delete mode 100644 odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportInfoImplTest.java delete mode 100644 odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonInfoImplTest.java diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/CommonParameter.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/CommonParameter.java index 136628906..6d39a8d51 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/CommonParameter.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/CommonParameter.java @@ -18,8 +18,6 @@ */ package org.apache.olingo.odata4.client.api.edm.xml; -import java.math.BigInteger; - public interface CommonParameter extends Named { String getType(); @@ -30,16 +28,16 @@ public interface CommonParameter extends Named { void setNullable(boolean nullable); - String getMaxLength(); + Integer getMaxLength(); - void setMaxLength(String maxLength); + void setMaxLength(Integer maxLength); - BigInteger getPrecision(); + Integer getPrecision(); - void setPrecision(BigInteger precision); + void setPrecision(Integer precision); - BigInteger getScale(); + Integer getScale(); - void setScale(BigInteger scale); + void setScale(Integer scale); } diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/CommonProperty.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/CommonProperty.java index 1621cd23b..cc362a55a 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/CommonProperty.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/CommonProperty.java @@ -18,7 +18,6 @@ */ package org.apache.olingo.odata4.client.api.edm.xml; -import java.math.BigInteger; import org.apache.olingo.odata4.commons.api.edm.constants.ConcurrencyMode; import org.apache.olingo.odata4.commons.api.edm.constants.StoreGeneratedPattern; @@ -36,21 +35,21 @@ public interface CommonProperty extends Named { void setDefaultValue(String defaultValue); - String getMaxLength(); + Integer getMaxLength(); - void setMaxLength(String maxLength); + void setMaxLength(Integer maxLength); boolean isFixedLength(); void setFixedLength(boolean fixedLength); - BigInteger getPrecision(); + Integer getPrecision(); - void setPrecision(BigInteger precision); + void setPrecision(Integer precision); - BigInteger getScale(); + Integer getScale(); - void setScale(BigInteger scale); + void setScale(Integer scale); boolean isUnicode(); diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/Member.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/Member.java index cf1e258d8..d6292c96b 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/Member.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/Member.java @@ -22,5 +22,5 @@ public interface Member { String getName(); - Integer getValue(); + String getValue(); } diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/Schema.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/Schema.java index 1856f8e3e..822923490 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/Schema.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/Schema.java @@ -18,7 +18,6 @@ */ package org.apache.olingo.odata4.client.api.edm.xml; -import org.apache.olingo.odata4.client.api.edm.xml.v3.Annotations; import java.util.List; public interface Schema { diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/EdmMetadata.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/XMLMetadata.java similarity index 93% rename from odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/EdmMetadata.java rename to odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/XMLMetadata.java index 9fef9c507..235021414 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/EdmMetadata.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/XMLMetadata.java @@ -16,15 +16,14 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.olingo.odata4.client.api.edm; +package org.apache.olingo.odata4.client.api.edm.xml; import java.util.List; -import org.apache.olingo.odata4.client.api.edm.xml.Schema; /** * Entry point for access information about EDM metadata. */ -public interface EdmMetadata { +public interface XMLMetadata { /** * Checks whether the given key is a valid namespace or alias in the EdM metadata document. diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/BindingTarget.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/BindingTarget.java new file mode 100644 index 000000000..c2c4abaab --- /dev/null +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/BindingTarget.java @@ -0,0 +1,31 @@ +/* + * 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.odata4.client.api.edm.xml.v4; + +import java.util.List; +import org.apache.olingo.odata4.client.api.edm.xml.Named; + +public interface BindingTarget extends Named, AnnotatedEdmItem { + + String getEntityType(); + + void setEntityType(String entityType); + + List getNavigationPropertyBindings(); +} diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/EntityContainer.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/EntityContainer.java index 6acf7415d..d3a76110b 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/EntityContainer.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/EntityContainer.java @@ -22,6 +22,10 @@ import java.util.List; public interface EntityContainer extends org.apache.olingo.odata4.client.api.edm.xml.EntityContainer { + List getSingletons(); + + Singleton getSingleton(String name); + /** * Gets the first action import with given name. * diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/EntitySet.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/EntitySet.java index c6754c742..abdd598b4 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/EntitySet.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/EntitySet.java @@ -18,13 +18,9 @@ */ package org.apache.olingo.odata4.client.api.edm.xml.v4; -import java.util.List; - -public interface EntitySet extends org.apache.olingo.odata4.client.api.edm.xml.EntitySet, AnnotatedEdmItem { +public interface EntitySet extends org.apache.olingo.odata4.client.api.edm.xml.EntitySet, BindingTarget { boolean isIncludeInServiceDocument(); void setIncludeInServiceDocument(boolean includeInServiceDocument); - - List getNavigationPropertyBindings(); } diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/ReturnType.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/ReturnType.java index 8e3c1f2b1..b6cd91209 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/ReturnType.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/ReturnType.java @@ -18,15 +18,13 @@ */ package org.apache.olingo.odata4.client.api.edm.xml.v4; -import java.math.BigInteger; - public interface ReturnType { - String getMaxLength(); + Integer getMaxLength(); - BigInteger getPrecision(); + Integer getPrecision(); - BigInteger getScale(); + Integer getScale(); String getSrid(); @@ -34,13 +32,13 @@ public interface ReturnType { boolean isNullable(); - void setMaxLength(String maxLength); + void setMaxLength(Integer maxLength); void setNullable(boolean nullable); - void setPrecision(BigInteger precision); + void setPrecision(Integer precision); - void setScale(BigInteger scale); + void setScale(Integer scale); void setSrid(String srid); diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/Singleton.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/Singleton.java index a706f895b..41145e536 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/Singleton.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/Singleton.java @@ -18,15 +18,8 @@ */ package org.apache.olingo.odata4.client.api.edm.xml.v4; -import java.util.List; import org.apache.olingo.odata4.client.api.edm.xml.Named; -public interface Singleton extends Named { - - String getType(); - - void setType(String type); - - List getNavigationPropertyBindings(); +public interface Singleton extends Named, BindingTarget { } diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/TypeDefinition.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/TypeDefinition.java index aaad5e769..531cf4522 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/TypeDefinition.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/edm/xml/v4/TypeDefinition.java @@ -26,11 +26,11 @@ public interface TypeDefinition extends Named { List getAnnotations(); - String getMaxLength(); + Integer getMaxLength(); - BigInteger getPrecision(); + Integer getPrecision(); - BigInteger getScale(); + Integer getScale(); String getSrid(); @@ -38,11 +38,11 @@ public interface TypeDefinition extends Named { boolean isUnicode(); - void setMaxLength(String maxLength); + void setMaxLength(Integer maxLength); - void setPrecision(BigInteger precision); + void setPrecision(Integer precision); - void setScale(BigInteger scale); + void setScale(Integer scale); void setSrid(String srid); diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/op/ODataDeserializer.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/op/ODataDeserializer.java index fe6872c71..8d6fc6286 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/op/ODataDeserializer.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/op/ODataDeserializer.java @@ -20,7 +20,7 @@ package org.apache.olingo.odata4.client.api.op; import java.io.InputStream; import java.io.Serializable; -import org.apache.olingo.odata4.client.api.edm.xml.Edmx; +import org.apache.olingo.odata4.client.api.edm.xml.XMLMetadata; import org.w3c.dom.Element; /** @@ -28,7 +28,7 @@ import org.w3c.dom.Element; */ public interface ODataDeserializer extends Serializable { - Edmx toMetadata(InputStream input); + XMLMetadata toMetadata(InputStream input); /** * Gets the ServiceDocumentResource object represented by the given InputStream. diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/op/ODataReader.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/op/ODataReader.java index e6f59db08..a9339195b 100644 --- a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/op/ODataReader.java +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/op/ODataReader.java @@ -20,7 +20,7 @@ package org.apache.olingo.odata4.client.api.op; import java.io.InputStream; import java.io.Serializable; -import org.apache.olingo.odata4.client.api.edm.EdmMetadata; +import org.apache.olingo.odata4.commons.api.edm.Edm; /** * OData reader. @@ -37,7 +37,7 @@ public interface ODataReader extends Serializable { * @param input stream to de-serialize. * @return metadata representation. */ - EdmMetadata readMetadata(InputStream input); + Edm readMetadata(InputStream input); /** * Parses an OData service document. diff --git a/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/utils/EdmTypeInfo.java b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/utils/EdmTypeInfo.java new file mode 100644 index 000000000..33dd46874 --- /dev/null +++ b/odata4-lib/odata4-client-api/src/main/java/org/apache/olingo/odata4/client/api/utils/EdmTypeInfo.java @@ -0,0 +1,81 @@ +/* + * 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.odata4.client.api.utils; + +import org.apache.commons.lang3.StringUtils; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; + +public class EdmTypeInfo { + + private final String typeExpression; + + private final boolean collection; + + private final FullQualifiedName fullQualifiedName; + + public EdmTypeInfo(final String typeExpression, final String defaultNamespace) { + this(typeExpression.indexOf('.') == -1 + ? defaultNamespace + "." + typeExpression + : typeExpression); + } + + public EdmTypeInfo(final String typeExpression) { + this.typeExpression = typeExpression; + + String baseType; + final int collStartIdx = typeExpression.indexOf("Collection("); + final int collEndIdx = typeExpression.lastIndexOf(')'); + if (collStartIdx == -1) { + baseType = typeExpression; + this.collection = false; + } else { + if (collEndIdx == -1) { + throw new IllegalArgumentException("Malformed type: " + typeExpression); + } + + this.collection = true; + baseType = typeExpression.substring(collStartIdx + 11, collEndIdx); + } + + final int lastDotIdx = baseType.lastIndexOf('.'); + if (lastDotIdx == -1) { + throw new IllegalArgumentException("Cannot find namespace or alias in " + typeExpression); + } + final String namespace = baseType.substring(0, lastDotIdx); + final String typeName = baseType.substring(lastDotIdx + 1); + if (StringUtils.isBlank(typeName)) { + throw new IllegalArgumentException("Null or empty type name in " + typeExpression); + } + + this.fullQualifiedName = new FullQualifiedName(namespace, typeName); + } + + public String getTypeExpression() { + return typeExpression; + } + + public boolean isCollection() { + return collection; + } + + public FullQualifiedName getFullQualifiedName() { + return fullQualifiedName; + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/AbstractEdmServiceMetadataImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/AbstractEdmServiceMetadataImpl.java new file mode 100644 index 000000000..d036e9f8e --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/AbstractEdmServiceMetadataImpl.java @@ -0,0 +1,115 @@ +/* + * 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.odata4.client.core.edm; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.olingo.odata4.client.api.edm.xml.CommonFunctionImport; +import org.apache.olingo.odata4.client.api.edm.xml.EntityContainer; +import org.apache.olingo.odata4.client.api.edm.xml.EntitySet; +import org.apache.olingo.odata4.client.api.edm.xml.Schema; +import org.apache.olingo.odata4.client.api.edm.xml.XMLMetadata; +import org.apache.olingo.odata4.commons.api.edm.EdmEntitySetInfo; +import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImportInfo; +import org.apache.olingo.odata4.commons.api.edm.EdmServiceMetadata; +import org.apache.olingo.odata4.commons.core.edm.EdmEntitySetInfoImpl; +import org.apache.olingo.odata4.commons.core.edm.EdmFunctionImportInfoImpl; + +public abstract class AbstractEdmServiceMetadataImpl implements EdmServiceMetadata { + + protected final XMLMetadata xmlMetadata; + + private List entitySetInfos; + + private List functionImportInfos; + + public static EdmServiceMetadata getInstance(final XMLMetadata xmlMetadata) { + return xmlMetadata instanceof org.apache.olingo.odata4.client.core.edm.xml.v3.XMLMetadataImpl + ? new org.apache.olingo.odata4.client.core.edm.v3.EdmServiceMetadataImpl( + (org.apache.olingo.odata4.client.core.edm.xml.v3.XMLMetadataImpl) xmlMetadata) + : new org.apache.olingo.odata4.client.core.edm.v4.EdmServiceMetadataImpl( + (org.apache.olingo.odata4.client.core.edm.xml.v4.XMLMetadataImpl) xmlMetadata); + + } + + public AbstractEdmServiceMetadataImpl(final XMLMetadata xmlMetadata) { + this.xmlMetadata = xmlMetadata; + } + + @Override + public InputStream getMetadata() { + throw new UnsupportedOperationException("Not supported in client code."); + } + + @Override + public List getEntitySetInfos() { + synchronized (this) { + if (entitySetInfos == null) { + entitySetInfos = new ArrayList(); + for (Schema schema : xmlMetadata.getSchemas()) { + for (EntityContainer entityContainer : schema.getEntityContainers()) { + for (EntitySet entitySet : entityContainer.getEntitySets()) { + entitySetInfos.add( + new EdmEntitySetInfoImpl(entityContainer.getName(), entitySet.getName())); + } + } + } + } + return entitySetInfos; + } + } + + @Override + public List getFunctionImportInfos() { + synchronized (this) { + if (functionImportInfos == null) { + functionImportInfos = new ArrayList(); + for (Schema schema : xmlMetadata.getSchemas()) { + for (EntityContainer entityContainer : schema.getEntityContainers()) { + for (CommonFunctionImport functionImport : entityContainer.getFunctionImports()) { + functionImportInfos.add( + new EdmFunctionImportInfoImpl(entityContainer.getName(), functionImport.getName())); + } + } + } + } + } + return functionImportInfos; + } + + @Override + public boolean equals(final Object obj) { + return EqualsBuilder.reflectionEquals(this, obj); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + @Override + public String toString() { + return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE); + } +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmActionImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmActionImpl.java new file mode 100644 index 000000000..8cf1eedf4 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmActionImpl.java @@ -0,0 +1,37 @@ +/* + * 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.odata4.client.core.edm; + +import org.apache.olingo.odata4.client.api.edm.xml.v4.Action; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmAction; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; + +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); + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmActionImportImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmActionImportImpl.java new file mode 100644 index 000000000..a133578f3 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmActionImportImpl.java @@ -0,0 +1,45 @@ +/* + * 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.odata4.client.core.edm; + +import org.apache.olingo.odata4.client.api.edm.xml.v4.ActionImport; +import org.apache.olingo.odata4.client.api.utils.EdmTypeInfo; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmAction; +import org.apache.olingo.odata4.commons.api.edm.EdmActionImport; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; + +public class EdmActionImportImpl extends EdmOperationImportImpl implements EdmActionImport { + + private final ActionImport actionImport; + + public EdmActionImportImpl(final Edm edm, final EdmEntityContainer container, final String name, + final ActionImport actionImport) { + + super(edm, container, name, actionImport); + this.actionImport = actionImport; + } + + @Override + public EdmAction getAction() { + return edm.getAction( + new EdmTypeInfo(actionImport.getAction(), container.getNamespace()).getFullQualifiedName(), null, null); + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmBindingTargetImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmBindingTargetImpl.java new file mode 100644 index 000000000..26f70e9b7 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmBindingTargetImpl.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.odata4.client.core.edm; + +import java.util.Iterator; +import java.util.List; +import org.apache.olingo.odata4.client.api.edm.xml.v4.BindingTarget; +import org.apache.olingo.odata4.client.api.edm.xml.v4.NavigationPropertyBinding; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmBindingTarget; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.api.edm.Target; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmBindingTarget; + +public abstract class EdmBindingTargetImpl extends AbstractEdmBindingTarget { + + private final BindingTarget target; + + public EdmBindingTargetImpl(final Edm edm, final EdmEntityContainer container, + final String name, final FullQualifiedName type, final BindingTarget target) { + + super(edm, container, name, type); + this.target = target; + } + + @Override + public EdmBindingTarget getRelatedBindingTarget(final String path) { + EdmBindingTarget bindingTarget = null; + + final List navigationPropertyBindings = target.getNavigationPropertyBindings(); + if (navigationPropertyBindings != null) { + boolean found = false; + for (final Iterator itor = navigationPropertyBindings.iterator(); + itor.hasNext() && !found;) { + + final NavigationPropertyBinding binding = itor.next(); + if (binding.getPath().equals(path)) { + final Target edmTarget = new Target.Builder(binding.getTarget(), container).build(); + + final EdmEntityContainer entityContainer = edm.getEntityContainer(edmTarget.getEntityContainer()); + if (entityContainer == null) { + throw new EdmException("Cant find entity container with name: " + edmTarget.getEntityContainer()); + } + bindingTarget = entityContainer.getEntitySet(edmTarget.getTargetName()); + if (bindingTarget == null) { + bindingTarget = entityContainer.getSingleton(edmTarget.getTargetName()); + if (bindingTarget == null) { + throw new EdmException("Cant find target with name: " + edmTarget.getTargetName()); + } + + found = true; + } else { + found = true; + } + } + } + } + + return bindingTarget; + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmClientImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmClientImpl.java new file mode 100644 index 000000000..ab15e7da7 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmClientImpl.java @@ -0,0 +1,285 @@ +/* + * 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.odata4.client.core.edm; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.olingo.odata4.client.api.edm.xml.EnumType; +import org.apache.olingo.odata4.client.api.edm.xml.Schema; +import org.apache.olingo.odata4.client.api.edm.xml.XMLMetadata; +import org.apache.olingo.odata4.client.api.edm.xml.v4.ComplexType; +import org.apache.olingo.odata4.client.api.edm.xml.v4.EntityContainer; +import org.apache.olingo.odata4.client.api.edm.xml.v4.EntityType; +import org.apache.olingo.odata4.client.api.edm.xml.v4.TypeDefinition; +import org.apache.olingo.odata4.client.api.utils.EdmTypeInfo; +import org.apache.olingo.odata4.client.core.edm.xml.v4.ActionImpl; +import org.apache.olingo.odata4.client.core.edm.xml.v4.FunctionImpl; +import org.apache.olingo.odata4.client.core.edm.xml.v4.ParameterImpl; +import org.apache.olingo.odata4.client.core.edm.xml.v4.SchemaImpl; +import org.apache.olingo.odata4.commons.api.edm.EdmAction; +import org.apache.olingo.odata4.commons.api.edm.EdmComplexType; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityType; +import org.apache.olingo.odata4.commons.api.edm.EdmEnumType; +import org.apache.olingo.odata4.commons.api.edm.EdmFunction; +import org.apache.olingo.odata4.commons.api.edm.EdmServiceMetadata; +import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmImpl; + +public class EdmClientImpl extends AbstractEdmImpl { + + private final XMLMetadata xmlMetadata; + + private final EdmServiceMetadata serviceMetadata; + + public EdmClientImpl(final XMLMetadata xmlMetadata) { + this.xmlMetadata = xmlMetadata; + this.serviceMetadata = AbstractEdmServiceMetadataImpl.getInstance(xmlMetadata); + } + + public XMLMetadata getXMLMetadata() { + return xmlMetadata; + } + + @Override + protected EdmServiceMetadata createServiceMetadata() { + return serviceMetadata; + } + + @Override + protected Map createAliasToNamespaceInfo() { + final Map aliasToNamespace = new HashMap(); + + for (Schema schema : xmlMetadata.getSchemas()) { + aliasToNamespace.put(null, schema.getNamespace()); + if (StringUtils.isNotBlank(schema.getAlias())) { + aliasToNamespace.put(schema.getAlias(), schema.getNamespace()); + } + } + + return aliasToNamespace; + } + + @Override + protected EdmEntityContainer createEntityContainer(final FullQualifiedName containerName) { + EdmEntityContainer result = null; + + final Schema schema = xmlMetadata.getSchema(containerName.getNamespace()); + if (schema != null) { + final EntityContainer xmlEntityContainer = (EntityContainer) schema.getDefaultEntityContainer(); + if (xmlEntityContainer != null) { + result = new EdmEntityContainerImpl(this, containerName, xmlEntityContainer); + } + } + + return result; + } + + @Override + protected EdmEnumType createEnumType(final FullQualifiedName enumName) { + EdmEnumType result = null; + + final Schema schema = xmlMetadata.getSchema(enumName.getNamespace()); + if (schema != null) { + final EnumType xmlEnumType = schema.getEnumType(enumName.getName()); + if (xmlEnumType != null) { + result = new EdmEnumTypeImpl(this, enumName, xmlEnumType); + } + } + + return result; + } + + @Override + protected EdmTypeDefinition createTypeDefinition(final FullQualifiedName typeDefinitionName) { + EdmTypeDefinition result = null; + + final Schema schema = xmlMetadata.getSchema(typeDefinitionName.getNamespace()); + if (schema instanceof SchemaImpl) { + final TypeDefinition xmlTypeDefinition = ((SchemaImpl) schema).getTypeDefinition(typeDefinitionName.getName()); + if (xmlTypeDefinition != null) { + result = new EdmTypeDefinitionImpl(this, typeDefinitionName, xmlTypeDefinition); + } + } + + return result; + } + + @Override + protected EdmEntityType createEntityType(final FullQualifiedName entityTypeName) { + EdmEntityType result = null; + + final Schema schema = xmlMetadata.getSchema(entityTypeName.getNamespace()); + if (schema instanceof SchemaImpl) { + final EntityType xmlEntityType = ((SchemaImpl) schema).getEntityType(entityTypeName.getName()); + if (xmlEntityType != null) { + result = EdmEntityTypeImpl.getInstance(this, entityTypeName, xmlEntityType); + } + } + + return result; + } + + @Override + protected EdmComplexType createComplexType(final FullQualifiedName complexTypeName) { + EdmComplexType result = null; + + final Schema schema = xmlMetadata.getSchema(complexTypeName.getNamespace()); + if (schema instanceof SchemaImpl) { + final ComplexType xmlComplexType = ((SchemaImpl) schema).getComplexType(complexTypeName.getName()); + if (xmlComplexType != null) { + result = EdmComplexTypeImpl.getInstance(this, complexTypeName, xmlComplexType); + } + } + + return result; + } + + @Override + protected EdmAction createUnboundAction(final FullQualifiedName actionName) { + EdmAction result = null; + + final Schema schema = xmlMetadata.getSchema(actionName.getNamespace()); + if (schema instanceof SchemaImpl) { + final List actions = ((SchemaImpl) schema).getActions(actionName.getName()); + boolean found = false; + for (Iterator itor = actions.iterator(); itor.hasNext() && !found;) { + final ActionImpl action = itor.next(); + if (!action.isBound()) { + found = true; + result = EdmActionImpl.getInstance(this, actionName, action); + } + } + } + + return result; + } + + @Override + protected EdmFunction createUnboundFunction(final FullQualifiedName functionName, final List parameterNames) { + EdmFunction result = null; + + final Schema schema = xmlMetadata.getSchema(functionName.getNamespace()); + if (schema instanceof SchemaImpl) { + final List functions = ((SchemaImpl) schema).getFunctions(functionName.getName()); + boolean found = false; + for (Iterator itor = functions.iterator(); itor.hasNext() && !found;) { + final FunctionImpl function = itor.next(); + if (!function.isBound()) { + final Set functionParamNames = new HashSet(); + for (ParameterImpl param : function.getParameters()) { + functionParamNames.add(param.getName()); + } + found = parameterNames == null + ? functionParamNames.isEmpty() + : functionParamNames.containsAll(parameterNames); + result = EdmFunctionImpl.getInstance(this, functionName, function); + } + } + } + + return result; + } + + @Override + protected EdmAction createBoundAction(final FullQualifiedName actionName, + final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) { + + EdmAction result = null; + + final Schema schema = xmlMetadata.getSchema(actionName.getNamespace()); + if (schema instanceof SchemaImpl) { + final List actions = ((SchemaImpl) schema).getActions(actionName.getName()); + boolean found = false; + for (Iterator itor = actions.iterator(); itor.hasNext() && !found;) { + final ActionImpl action = itor.next(); + if (action.isBound()) { + final EdmTypeInfo boundParam = new EdmTypeInfo(action.getParameters().get(0).getType()); + if (bindingParameterTypeName.equals(boundParam.getFullQualifiedName()) + && isBindingParameterCollection.booleanValue() == boundParam.isCollection()) { + + found = true; + result = EdmActionImpl.getInstance(this, actionName, action); + } + } + } + } + + return result; + } + + @Override + protected EdmFunction createBoundFunction(final FullQualifiedName functionName, + final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection, + final List parameterNames) { + + EdmFunction result = null; + + final Schema schema = xmlMetadata.getSchema(functionName.getNamespace()); + if (schema instanceof SchemaImpl) { + final List functions = ((SchemaImpl) schema).getFunctions(functionName.getName()); + boolean found = false; + for (Iterator itor = functions.iterator(); itor.hasNext() && !found;) { + final FunctionImpl function = itor.next(); + if (function.isBound()) { + final EdmTypeInfo boundParam = new EdmTypeInfo(function.getParameters().get(0).getType()); + if (bindingParameterTypeName.equals(boundParam.getFullQualifiedName()) + && isBindingParameterCollection.booleanValue() == boundParam.isCollection()) { + + final Set functionParamNames = new HashSet(); + for (ParameterImpl param : function.getParameters()) { + functionParamNames.add(param.getName()); + } + found = parameterNames == null + ? functionParamNames.isEmpty() + : functionParamNames.containsAll(parameterNames); + result = EdmFunctionImpl.getInstance(this, functionName, function); + } + } + } + } + + return result; + } + + @Override + public boolean equals(final Object obj) { + return EqualsBuilder.reflectionEquals(this, obj); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + @Override + public String toString() { + return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE); + } +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmComplexTypeImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmComplexTypeImpl.java new file mode 100644 index 000000000..c036172e4 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmComplexTypeImpl.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.odata4.client.core.edm; + +import java.util.Map; +import org.apache.olingo.odata4.client.api.edm.xml.v4.ComplexType; +import org.apache.olingo.odata4.client.api.utils.EdmTypeInfo; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata4.commons.api.edm.EdmProperty; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmComplexType; +import org.apache.olingo.odata4.commons.core.edm.EdmStructuredTypeHelper; + +public class EdmComplexTypeImpl extends AbstractEdmComplexType { + + private final EdmStructuredTypeHelper helper; + + public static EdmComplexTypeImpl getInstance(final Edm edm, final FullQualifiedName fqn, + final ComplexType complexType) { + + final FullQualifiedName baseTypeName = complexType.getBaseType() == null + ? null : new EdmTypeInfo(complexType.getBaseType()).getFullQualifiedName(); + final EdmComplexTypeImpl instance = new EdmComplexTypeImpl(edm, fqn, baseTypeName, complexType); + instance.baseType = instance.buildBaseType(baseTypeName); + + return instance; + } + + private EdmComplexTypeImpl(final Edm edm, final FullQualifiedName fqn, final FullQualifiedName baseTypeName, + final ComplexType complexType) { + + super(edm, fqn, baseTypeName); + this.helper = new EdmStructuredTypeHelperImpl(edm, complexType); + } + + @Override + protected Map getProperties() { + return helper.getProperties(); + } + + @Override + protected Map getNavigationProperties() { + return helper.getNavigationProperties(); + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEntityContainerImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEntityContainerImpl.java new file mode 100644 index 000000000..31269a23d --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEntityContainerImpl.java @@ -0,0 +1,87 @@ +/* + * 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.odata4.client.core.edm; + +import org.apache.olingo.odata4.client.api.edm.xml.v4.ActionImport; +import org.apache.olingo.odata4.client.api.edm.xml.v4.EntityContainer; +import org.apache.olingo.odata4.client.api.edm.xml.v4.EntitySet; +import org.apache.olingo.odata4.client.api.edm.xml.v4.FunctionImport; +import org.apache.olingo.odata4.client.api.edm.xml.v4.Singleton; +import org.apache.olingo.odata4.client.api.utils.EdmTypeInfo; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmActionImport; +import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet; +import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImport; +import org.apache.olingo.odata4.commons.api.edm.EdmSingleton; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmEntityContainer; + +public class EdmEntityContainerImpl extends AbstractEdmEntityContainer { + + private final EntityContainer xmlEntityContainer; + + public EdmEntityContainerImpl(final Edm edm, final FullQualifiedName entityContainerName, + final EntityContainer xmlEntityContainer) { + + super(edm, entityContainerName); + this.xmlEntityContainer = xmlEntityContainer; + } + + @Override + protected EdmSingleton createSingleton(final String singletonName) { + final Singleton singleton = xmlEntityContainer.getSingleton(singletonName); + if (singleton == null) { + throw new EdmException("Singleton named '" + singletonName + "' not found in " + entityContainerName); + } + return new EdmSingletonImpl(edm, this, singletonName, + new EdmTypeInfo(singleton.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(), + singleton); + } + + @Override + protected EdmEntitySet createEntitySet(final String entitySetName) { + final EntitySet entitySet = (EntitySet) xmlEntityContainer.getEntitySet(entitySetName); + if (entitySet == null) { + throw new EdmException("EntitySet named '" + entitySetName + "' not found in " + entityContainerName); + } + return new EdmEntitySetImpl(edm, this, entitySetName, + new EdmTypeInfo(entitySet.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(), + entitySet); + } + + @Override + protected EdmActionImport createActionImport(final String actionImportName) { + final ActionImport actionImport = xmlEntityContainer.getActionImport(actionImportName); + if (actionImport == null) { + throw new EdmException("ActionImport named '" + actionImportName + "' not found in " + entityContainerName); + } + return new EdmActionImportImpl(edm, this, actionImportName, actionImport); + } + + @Override + protected EdmFunctionImport createFunctionImport(final String functionImportName) { + final FunctionImport functionImport = (FunctionImport) xmlEntityContainer.getFunctionImport(functionImportName); + if (functionImport == null) { + throw new EdmException("FunctionImport named '" + functionImportName + "' not found in " + entityContainerName); + } + return new EdmFunctionImportImpl(edm, this, functionImportName, functionImport); + } + +} diff --git a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/Target.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEntitySetImpl.java similarity index 59% rename from odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/Target.java rename to odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEntitySetImpl.java index 57c400d0c..669e431c9 100644 --- a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/Target.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEntitySetImpl.java @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -16,32 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.olingo.odata4.server.api.edm.provider; +package org.apache.olingo.odata4.client.core.edm; +import org.apache.olingo.odata4.client.api.edm.xml.v4.EntitySet; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; -public class Target { +public class EdmEntitySetImpl extends EdmBindingTargetImpl implements EdmEntitySet { - private String targetName; + public EdmEntitySetImpl(final Edm edm, final EdmEntityContainer container, final String name, + final FullQualifiedName type, final EntitySet entitySet) { - private FullQualifiedName entityContainer; - - public String getTargetName() { - return targetName; - } - - public Target setTargetName(final String targetPathName) { - targetName = targetPathName; - return this; - } - - public FullQualifiedName getEntityContainer() { - return entityContainer; - } - - public Target setEntityContainer(final FullQualifiedName entityContainer) { - this.entityContainer = entityContainer; - return this; + super(edm, container, name, type, entitySet); } } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEntityTypeImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEntityTypeImpl.java new file mode 100644 index 000000000..8c17a1e9f --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEntityTypeImpl.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.odata4.client.core.edm; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.apache.olingo.odata4.client.api.edm.xml.PropertyRef; +import org.apache.olingo.odata4.client.api.edm.xml.v4.EntityType; +import org.apache.olingo.odata4.client.api.utils.EdmTypeInfo; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityType; +import org.apache.olingo.odata4.commons.api.edm.EdmKeyPropertyRef; +import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata4.commons.api.edm.EdmProperty; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmEntityType; +import org.apache.olingo.odata4.commons.core.edm.EdmStructuredTypeHelper; + +public class EdmEntityTypeImpl extends AbstractEdmEntityType { + + private final EdmStructuredTypeHelper helper; + + public static EdmEntityTypeImpl getInstance(final Edm edm, final FullQualifiedName fqn, final EntityType entityType) { + final FullQualifiedName baseTypeName = entityType.getBaseType() == null + ? null : new EdmTypeInfo(entityType.getBaseType()).getFullQualifiedName(); + final EdmEntityTypeImpl instance = new EdmEntityTypeImpl(edm, fqn, baseTypeName, entityType); + instance.baseType = instance.buildBaseType(baseTypeName); + + if (instance.baseType == null) { + instance.entityBaseType = null; + + final List edmKey = new ArrayList( + entityType.getKey().getPropertyRefs().size()); + for (PropertyRef ref : entityType.getKey().getPropertyRefs()) { + edmKey.add(new EdmKeyPropertyRefImpl(instance, ref)); + } + instance.setEdmKeyPropertyRef(edmKey); + } else { + instance.entityBaseType = (EdmEntityType) instance.baseType; + } + + return instance; + } + + private EdmEntityTypeImpl(final Edm edm, final FullQualifiedName fqn, final FullQualifiedName baseTypeName, + final EntityType entityType) { + + super(edm, fqn, baseTypeName, entityType.isHasStream()); + this.helper = new EdmStructuredTypeHelperImpl(edm, entityType); + } + + @Override + protected Map getProperties() { + return helper.getProperties(); + } + + @Override + protected Map getNavigationProperties() { + return helper.getNavigationProperties(); + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEnumTypeImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEnumTypeImpl.java new file mode 100644 index 000000000..6d090aba0 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmEnumTypeImpl.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.odata4.client.core.edm; + +import org.apache.olingo.odata4.commons.core.edm.EdmMemberImpl; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.apache.olingo.odata4.client.api.edm.xml.EnumType; +import org.apache.olingo.odata4.client.api.edm.xml.Member; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmEnumType; +import org.apache.olingo.odata4.commons.api.edm.EdmMember; +import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmEnumType; +import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind; + +public class EdmEnumTypeImpl extends AbstractEdmEnumType implements EdmEnumType { + + private final EdmPrimitiveType underlyingType; + + private final List memberNames; + + private final Map members; + + public EdmEnumTypeImpl(final Edm edm, final FullQualifiedName fqn, final EnumType xmlEnumType) { + super(edm, fqn, xmlEnumType.isFlags()); + + if (xmlEnumType.getUnderlyingType() == null) { + this.underlyingType = EdmPrimitiveTypeKind.Int32.getEdmPrimitiveTypeInstance(); + } else { + this.underlyingType = EdmPrimitiveTypeKind.fromString( + xmlEnumType.getUnderlyingType()).getEdmPrimitiveTypeInstance(); + // TODO: Should we validate that the underlying type is of byte, sbyte, in16, int32 or int64? + } + + final List xmlMembers = xmlEnumType.getMembers(); + final List _memberNames = new ArrayList(); + final Map _members = new LinkedHashMap(xmlMembers.size()); + for (Member xmlMember : xmlMembers) { + _memberNames.add(xmlMember.getName()); + _members.put(xmlMember.getName(), new EdmMemberImpl(edm, xmlMember.getName(), xmlMember.getValue())); + } + this.memberNames = Collections.unmodifiableList(_memberNames); + this.members = Collections.unmodifiableMap(_members); + } + + @Override + public EdmPrimitiveType getUnderlyingType() { + return underlyingType; + } + + @Override + public List getMemberNames() { + return memberNames; + } + + @Override + protected Collection getMembers() { + return members.values(); + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmFunctionImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmFunctionImpl.java new file mode 100644 index 000000000..aa83cb350 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmFunctionImpl.java @@ -0,0 +1,44 @@ +/* + * 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.odata4.client.core.edm; + +import org.apache.olingo.odata4.client.api.edm.xml.v4.Function; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmFunction; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; + +public class EdmFunctionImpl extends EdmOperationImpl implements EdmFunction { + + private final Function function; + + public static EdmFunctionImpl getInstance(final Edm edm, final FullQualifiedName name, final Function function) { + return EdmOperationImpl.getInstance(new EdmFunctionImpl(edm, name, function)); + } + + private EdmFunctionImpl(final Edm edm, final FullQualifiedName name, final Function function) { + super(edm, name, function, EdmTypeKind.FUNCTION); + this.function = function; + } + + @Override + public boolean isComposable() { + return function.isComposable(); + } +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmFunctionImportImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmFunctionImportImpl.java new file mode 100644 index 000000000..8c65d59bb --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmFunctionImportImpl.java @@ -0,0 +1,47 @@ +/* + * 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.odata4.client.core.edm; + +import java.util.List; +import org.apache.olingo.odata4.client.api.edm.xml.v4.FunctionImport; +import org.apache.olingo.odata4.client.api.utils.EdmTypeInfo; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.odata4.commons.api.edm.EdmFunction; +import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImport; + +public class EdmFunctionImportImpl extends EdmOperationImportImpl implements EdmFunctionImport { + + private final FunctionImport functionImport; + + public EdmFunctionImportImpl(final Edm edm, final EdmEntityContainer container, final String name, + final FunctionImport functionImport) { + + super(edm, container, name, functionImport); + this.functionImport = functionImport; + } + + @Override + public EdmFunction getFunction(final List parameterNames) { + return edm.getFunction( + new EdmTypeInfo(functionImport.getFunction(), container.getNamespace()).getFullQualifiedName(), + null, null, parameterNames); + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmKeyPropertyRefImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmKeyPropertyRefImpl.java new file mode 100644 index 000000000..0264c281d --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmKeyPropertyRefImpl.java @@ -0,0 +1,49 @@ +/* + * 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.odata4.client.core.edm; + +import org.apache.olingo.odata4.client.api.edm.xml.PropertyRef; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityType; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmKeyPropertyRef; + +public class EdmKeyPropertyRefImpl extends AbstractEdmKeyPropertyRef { + + private final PropertyRef propertyRef; + + public EdmKeyPropertyRefImpl(final EdmEntityType edmEntityType, final PropertyRef propertyRef) { + super(edmEntityType); + this.propertyRef = propertyRef; + } + + @Override + public String getKeyPropertyName() { + return propertyRef.getName(); + } + + @Override + public String getAlias() { + return propertyRef.getAlias(); + } + + @Override + public String getPath() { + throw new UnsupportedOperationException("Not supported in client code."); + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmNavigationPropertyImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmNavigationPropertyImpl.java new file mode 100644 index 000000000..9d7991469 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmNavigationPropertyImpl.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.odata4.client.core.edm; + +import java.util.List; +import org.apache.olingo.odata4.client.api.edm.xml.v4.NavigationProperty; +import org.apache.olingo.odata4.client.api.edm.xml.v4.ReferentialConstraint; +import org.apache.olingo.odata4.client.api.utils.EdmTypeInfo; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmNavigationProperty; + +public class EdmNavigationPropertyImpl extends AbstractEdmNavigationProperty { + + private final NavigationProperty navigationProperty; + + private final EdmTypeInfo edmTypeInfo; + + public EdmNavigationPropertyImpl(final Edm edm, final NavigationProperty navigationProperty) { + super(edm, navigationProperty.getName()); + this.navigationProperty = navigationProperty; + this.edmTypeInfo = new EdmTypeInfo(navigationProperty.getType()); + } + + @Override + protected FullQualifiedName getTypeFQN() { + return edmTypeInfo.getFullQualifiedName(); + } + + @Override + protected String internatGetPartner() { + return navigationProperty.getPartner(); + } + + @Override + public boolean isCollection() { + return edmTypeInfo.isCollection(); + } + + @Override + public Boolean isNullable() { + return navigationProperty.isNullable(); + } + + @Override + public String getReferencingPropertyName(final String referencedPropertyName) { + final List referentialConstraints = navigationProperty.getReferentialConstraints(); + if (referentialConstraints != null) { + for (ReferentialConstraint constraint : referentialConstraints) { + if (constraint.getReferencedProperty().equals(referencedPropertyName)) { + return constraint.getProperty(); + } + } + } + return null; + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmOperationImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmOperationImpl.java new file mode 100644 index 000000000..932fe57d1 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmOperationImpl.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.odata4.client.core.edm; + +import java.util.ArrayList; +import java.util.List; +import org.apache.olingo.odata4.client.api.edm.xml.CommonParameter; +import org.apache.olingo.odata4.client.api.edm.xml.v4.Action; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmParameter; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmOperation; + +public abstract class EdmOperationImpl extends AbstractEdmOperation { + + protected final Action operation; + + protected static T getInstance(final T instance) { + + final List parameters = instance.operation.getParameters(); + if (parameters != null) { + final List _parameters = new ArrayList(parameters.size()); + for (CommonParameter parameter : parameters) { + _parameters.add(EdmParameterImpl.getInstance(instance.edm, parameter)); + } + instance.setParameters(_parameters); + } + + instance.setEntitySetPath(instance.operation.getEntitySetPath()); + + instance.setIsBound(instance.operation.isBound()); + + if (instance.operation.getReturnType() != null) { + instance.setReturnType(EdmReturnTypeImpl.getInstance(instance.edm, instance.operation.getReturnType())); + } + + return instance; + } + + protected EdmOperationImpl(final Edm edm, final FullQualifiedName name, final Action operation, + final EdmTypeKind kind) { + + super(edm, name, kind); + this.operation = operation; + } +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmOperationImportImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmOperationImportImpl.java new file mode 100644 index 000000000..450ebc2a0 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmOperationImportImpl.java @@ -0,0 +1,35 @@ +/* + * 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.odata4.client.core.edm; + +import org.apache.olingo.odata4.client.api.edm.xml.v4.OperationImport; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.odata4.commons.api.edm.Target; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmOperationImport; + +public abstract class EdmOperationImportImpl extends AbstractEdmOperationImport { + + protected EdmOperationImportImpl(final Edm edm, final EdmEntityContainer container, final String name, + final OperationImport operationImport) { + + super(edm, container, name, new Target.Builder(operationImport.getEntitySet(), container).build()); + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmParameterImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmParameterImpl.java new file mode 100644 index 000000000..9b3beb48a --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmParameterImpl.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.odata4.client.core.edm; + +import org.apache.olingo.odata4.client.api.edm.xml.CommonParameter; +import org.apache.olingo.odata4.client.api.utils.EdmTypeInfo; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmMapping; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmParameter; + +public class EdmParameterImpl extends AbstractEdmParameter { + + private final CommonParameter parameter; + + private final EdmTypeInfo parameterInfo; + + public static EdmParameterImpl getInstance(final Edm edm, final CommonParameter parameter) { + final EdmTypeInfo paramTypeInfo = new EdmTypeInfo(parameter.getType()); + return new EdmParameterImpl(edm, parameter, paramTypeInfo); + } + + private EdmParameterImpl(final Edm edm, final CommonParameter parameter, final EdmTypeInfo parameterInfo) { + super(edm, parameter.getName(), parameterInfo.getFullQualifiedName()); + this.parameter = parameter; + this.parameterInfo = parameterInfo; + } + + @Override + public boolean isCollection() { + return parameterInfo.isCollection(); + } + + @Override + public EdmMapping getMapping() { + throw new UnsupportedOperationException("Not supported in client code."); + } + + @Override + public Boolean isNullable() { + return parameter.isNullable(); + } + + @Override + public Integer getMaxLength() { + return parameter.getMaxLength(); + } + + @Override + public Integer getPrecision() { + return parameter.getPrecision(); + } + + @Override + public Integer getScale() { + return parameter.getScale(); + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmPropertyImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmPropertyImpl.java new file mode 100644 index 000000000..20ffb2c74 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmPropertyImpl.java @@ -0,0 +1,91 @@ +/* + * 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.odata4.client.core.edm; + +import org.apache.olingo.odata4.client.api.edm.xml.CommonProperty; +import org.apache.olingo.odata4.client.api.utils.EdmTypeInfo; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmMapping; +import org.apache.olingo.odata4.commons.api.edm.EdmProperty; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmProperty; + +public class EdmPropertyImpl extends AbstractEdmProperty implements EdmProperty { + + private final CommonProperty property; + + private final EdmTypeInfo edmTypeInfo; + + public EdmPropertyImpl(final Edm edm, final CommonProperty property) { + super(edm, property.getName()); + this.property = property; + this.edmTypeInfo = new EdmTypeInfo(property.getType()); + } + + @Override + protected FullQualifiedName getTypeFQN() { + return edmTypeInfo.getFullQualifiedName(); + } + + @Override + public boolean isCollection() { + return edmTypeInfo.isCollection(); + } + + @Override + public EdmMapping getMapping() { + throw new UnsupportedOperationException("Not supported in client code."); + } + + @Override + public String getMimeType() { + throw new UnsupportedOperationException("Not supported in client code."); + } + + @Override + public Boolean isNullable() { + return property.isNullable(); + } + + @Override + public Integer getMaxLength() { + return property.getMaxLength(); + } + + @Override + public Integer getPrecision() { + return property.getPrecision(); + } + + @Override + public Integer getScale() { + return property.getScale(); + } + + @Override + public Boolean isUnicode() { + return property.isUnicode(); + } + + @Override + public String getDefaultValue() { + return property.getDefaultValue(); + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmReturnTypeImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmReturnTypeImpl.java new file mode 100644 index 000000000..c17b99689 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmReturnTypeImpl.java @@ -0,0 +1,68 @@ +/* + * 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.odata4.client.core.edm; + +import org.apache.olingo.odata4.client.api.edm.xml.v4.ReturnType; +import org.apache.olingo.odata4.client.api.utils.EdmTypeInfo; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmReturnType; + +public class EdmReturnTypeImpl extends AbstractEdmReturnType { + + private final ReturnType returnType; + + private final EdmTypeInfo returnTypeInfo; + + public static EdmReturnTypeImpl getInstance(final Edm edm, final ReturnType returnType) { + final EdmTypeInfo returnTypeInfo = new EdmTypeInfo(returnType.getType()); + return new EdmReturnTypeImpl(edm, returnType, returnTypeInfo); + } + + private EdmReturnTypeImpl(final Edm edm, final ReturnType returnType, final EdmTypeInfo returnTypeInfo) { + super(edm, returnTypeInfo.getFullQualifiedName()); + this.returnType = returnType; + this.returnTypeInfo = returnTypeInfo; + } + + @Override + public Boolean isNullable() { + return returnType.isNullable(); + } + + @Override + public Integer getMaxLength() { + return returnType.getMaxLength(); + } + + @Override + public Integer getPrecision() { + return returnType.getPrecision(); + } + + @Override + public Integer getScale() { + return returnType.getScale(); + } + + @Override + public boolean isCollection() { + return returnTypeInfo.isCollection(); + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmSingletonImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmSingletonImpl.java new file mode 100644 index 000000000..6d1415439 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmSingletonImpl.java @@ -0,0 +1,35 @@ +/* + * 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.odata4.client.core.edm; + +import org.apache.olingo.odata4.client.api.edm.xml.v4.Singleton; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.odata4.commons.api.edm.EdmSingleton; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; + +public class EdmSingletonImpl extends EdmBindingTargetImpl implements EdmSingleton { + + public EdmSingletonImpl(final Edm edm, final EdmEntityContainer container, final String name, + final FullQualifiedName type, final Singleton singleton) { + + super(edm, container, name, type, singleton); + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmStructuredTypeHelperImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmStructuredTypeHelperImpl.java new file mode 100644 index 000000000..c090f50b7 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmStructuredTypeHelperImpl.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.odata4.client.core.edm; + +import java.util.LinkedHashMap; +import java.util.Map; +import org.apache.olingo.odata4.client.api.edm.xml.CommonNavigationProperty; +import org.apache.olingo.odata4.client.api.edm.xml.CommonProperty; +import org.apache.olingo.odata4.client.api.edm.xml.v4.ComplexType; +import org.apache.olingo.odata4.client.api.edm.xml.v4.NavigationProperty; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata4.commons.api.edm.EdmProperty; +import org.apache.olingo.odata4.commons.core.edm.EdmStructuredTypeHelper; + +public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper { + + private final Edm edm; + + private final ComplexType complexType; + + private Map properties; + + private Map navigationProperties; + + public EdmStructuredTypeHelperImpl(final Edm edm, final ComplexType complexType) { + this.edm = edm; + this.complexType = complexType; + } + + @Override + public Map getProperties() { + if (properties == null) { + properties = new LinkedHashMap(); + for (CommonProperty property : complexType.getProperties()) { + properties.put(property.getName(), new EdmPropertyImpl(edm, property)); + } + } + return properties; + } + + @Override + public Map getNavigationProperties() { + if (navigationProperties == null) { + navigationProperties = new LinkedHashMap(); + for (CommonNavigationProperty navigationProperty : complexType.getNavigationProperties()) { + if (navigationProperty instanceof NavigationProperty) { + navigationProperties.put(navigationProperty.getName(), + new EdmNavigationPropertyImpl(edm, (NavigationProperty) navigationProperty)); + } + } + } + return navigationProperties; + } +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmTypeDefinitionImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmTypeDefinitionImpl.java new file mode 100644 index 000000000..43a5455ff --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/EdmTypeDefinitionImpl.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.odata4.client.core.edm; + +import org.apache.olingo.odata4.client.api.edm.xml.v4.TypeDefinition; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType; +import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmTypeDefinition; +import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind; + +public class EdmTypeDefinitionImpl extends AbstractEdmTypeDefinition implements EdmTypeDefinition { + + private TypeDefinition typeDefinition; + + private EdmPrimitiveType edmPrimitiveTypeInstance; + + public EdmTypeDefinitionImpl(final Edm edm, final FullQualifiedName typeDefinitionName, + final TypeDefinition typeDefinition) { + + super(edm, typeDefinitionName); + this.typeDefinition = typeDefinition; + // TODO: Should we check for edmNamespace in the underlying type name? + try { + edmPrimitiveTypeInstance = EdmPrimitiveTypeKind.fromString( + typeDefinition.getUnderlyingType()).getEdmPrimitiveTypeInstance(); + } catch (IllegalArgumentException e) { + throw new EdmException("Invalid underlying type: " + typeDefinition.getUnderlyingType(), e); + } + } + + @Override + public EdmPrimitiveType getUnderlyingType() { + return edmPrimitiveTypeInstance; + } + + @Override + public Integer getMaxLength() { + return typeDefinition.getMaxLength(); + } + + @Override + public Integer getPrecision() { + return typeDefinition.getPrecision(); + } + + @Override + public Integer getScale() { + return typeDefinition.getScale(); + } + + @Override + public Boolean isUnicode() { + return typeDefinition.isUnicode(); + } +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v3/EdmServiceMetadataImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v3/EdmServiceMetadataImpl.java new file mode 100644 index 000000000..1b84dcb9d --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v3/EdmServiceMetadataImpl.java @@ -0,0 +1,52 @@ +/* + * 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.odata4.client.core.edm.v3; + +import java.util.Collections; +import java.util.List; +import org.apache.olingo.odata4.client.core.edm.AbstractEdmServiceMetadataImpl; +import org.apache.olingo.odata4.client.core.edm.xml.v3.XMLMetadataImpl; +import org.apache.olingo.odata4.commons.api.edm.EdmActionImportInfo; +import org.apache.olingo.odata4.commons.api.edm.EdmSingletonInfo; +import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion; + +public class EdmServiceMetadataImpl extends AbstractEdmServiceMetadataImpl { + + private static final ODataServiceVersion SERVICE_VERSION = ODataServiceVersion.V30; + + public EdmServiceMetadataImpl(final XMLMetadataImpl xmlMetadata) { + super(xmlMetadata); + } + + @Override + public String getDataServiceVersion() { + return SERVICE_VERSION.toString(); + } + + @Override + public List getSingletonInfos() { + return Collections.emptyList(); + } + + @Override + public List getActionImportInfos() { + return Collections.emptyList(); + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v3/EdmTypeImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v3/EdmTypeImpl.java index 551c4ef00..18216c629 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v3/EdmTypeImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v3/EdmTypeImpl.java @@ -18,7 +18,8 @@ */ package org.apache.olingo.odata4.client.core.edm.v3; -import org.apache.olingo.odata4.client.core.edm.AbstractEdmType; +import org.apache.olingo.odata4.client.api.edm.xml.XMLMetadata; +import org.apache.olingo.odata4.client.core.edm.xml.AbstractEdmType; import org.apache.olingo.odata4.client.core.edm.xml.v3.ComplexTypeImpl; import org.apache.olingo.odata4.client.core.edm.xml.v3.EntityTypeImpl; import org.apache.olingo.odata4.client.core.edm.xml.v3.EnumTypeImpl; @@ -29,7 +30,7 @@ public class EdmTypeImpl extends AbstractEdmType { super(typeExpression); } - public EdmTypeImpl(final EdmMetadataImpl metadata, final String typeExpression) { + public EdmTypeImpl(final XMLMetadata metadata, final String typeExpression) { super(metadata, typeExpression); } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v4/EdmServiceMetadataImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v4/EdmServiceMetadataImpl.java new file mode 100644 index 000000000..2f797eebf --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v4/EdmServiceMetadataImpl.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.odata4.client.core.edm.v4; + +import java.util.ArrayList; +import java.util.List; +import org.apache.olingo.odata4.client.api.edm.xml.Schema; +import org.apache.olingo.odata4.client.api.edm.xml.v4.ActionImport; +import org.apache.olingo.odata4.client.api.edm.xml.v4.EntityContainer; +import org.apache.olingo.odata4.client.api.edm.xml.v4.Singleton; +import org.apache.olingo.odata4.client.core.edm.AbstractEdmServiceMetadataImpl; +import org.apache.olingo.odata4.client.core.edm.xml.v4.XMLMetadataImpl; +import org.apache.olingo.odata4.commons.api.edm.EdmActionImportInfo; +import org.apache.olingo.odata4.commons.api.edm.EdmSingletonInfo; +import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion; +import org.apache.olingo.odata4.commons.core.edm.EdmActionImportInfoImpl; +import org.apache.olingo.odata4.commons.core.edm.EdmSingletonInfoImpl; + +public class EdmServiceMetadataImpl extends AbstractEdmServiceMetadataImpl { + + private static final ODataServiceVersion SERVICE_VERSION = ODataServiceVersion.V40; + + private List singletonInfos; + + private List actionImportInfos; + + public EdmServiceMetadataImpl(final XMLMetadataImpl xmlMetadata) { + super(xmlMetadata); + } + + @Override + public String getDataServiceVersion() { + return SERVICE_VERSION.toString(); + } + + @Override + public List getSingletonInfos() { + synchronized (this) { + if (singletonInfos == null) { + singletonInfos = new ArrayList(); + for (Schema schema : xmlMetadata.getSchemas()) { + final EntityContainer entityContainer = (EntityContainer) schema.getDefaultEntityContainer(); + for (Singleton singleton : entityContainer.getSingletons()) { + singletonInfos.add(new EdmSingletonInfoImpl(entityContainer.getName(), singleton.getName())); + } + } + } + return singletonInfos; + } + } + + @Override + public List getActionImportInfos() { + synchronized (this) { + if (actionImportInfos == null) { + actionImportInfos = new ArrayList(); + for (Schema schema : xmlMetadata.getSchemas()) { + final EntityContainer entityContainer = (EntityContainer) schema.getDefaultEntityContainer(); + for (ActionImport actionImport : entityContainer.getActionImports()) { + actionImportInfos.add(new EdmActionImportInfoImpl(entityContainer.getName(), actionImport.getName())); + } + } + } + return actionImportInfos; + } + } +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v4/EdmTypeImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v4/EdmTypeImpl.java index e71efef41..c693f9cab 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v4/EdmTypeImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v4/EdmTypeImpl.java @@ -18,7 +18,8 @@ */ package org.apache.olingo.odata4.client.core.edm.v4; -import org.apache.olingo.odata4.client.core.edm.AbstractEdmType; +import org.apache.olingo.odata4.client.api.edm.xml.XMLMetadata; +import org.apache.olingo.odata4.client.core.edm.xml.AbstractEdmType; import org.apache.olingo.odata4.client.core.edm.xml.v4.ComplexTypeImpl; import org.apache.olingo.odata4.client.core.edm.xml.v4.EntityTypeImpl; import org.apache.olingo.odata4.client.core.edm.xml.v4.EnumTypeImpl; @@ -29,7 +30,7 @@ public class EdmTypeImpl extends AbstractEdmType { super(typeExpression); } - public EdmTypeImpl(final EdmMetadataImpl metadata, final String typeExpression) { + public EdmTypeImpl(final XMLMetadata metadata, final String typeExpression) { super(metadata, typeExpression); } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/AbstractEdmType.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractEdmType.java similarity index 94% rename from odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/AbstractEdmType.java rename to odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractEdmType.java index 2d4dccfff..48de56066 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/AbstractEdmType.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractEdmType.java @@ -16,20 +16,17 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.olingo.odata4.client.core.edm; +package org.apache.olingo.odata4.client.core.edm.xml; import org.apache.commons.lang3.StringUtils; import org.apache.olingo.odata4.client.api.data.EdmSimpleType; import org.apache.olingo.odata4.client.api.edm.xml.ComplexType; -import org.apache.olingo.odata4.client.api.edm.EdmMetadata; import org.apache.olingo.odata4.client.api.edm.EdmType; import org.apache.olingo.odata4.client.api.edm.EdmTypeNotFoundException; import org.apache.olingo.odata4.client.api.edm.xml.EntityType; import org.apache.olingo.odata4.client.api.edm.xml.EnumType; import org.apache.olingo.odata4.client.api.edm.xml.Schema; -import org.apache.olingo.odata4.client.core.edm.xml.AbstractComplexType; -import org.apache.olingo.odata4.client.core.edm.xml.AbstractEntityType; -import org.apache.olingo.odata4.client.core.edm.xml.AbstractEnumType; +import org.apache.olingo.odata4.client.api.edm.xml.XMLMetadata; /** * Parse type information from metadata into semantic data. @@ -67,7 +64,7 @@ public abstract class AbstractEdmType implements EdmType { * @param metadata metadata. * @param typeExpression type expression. */ - public AbstractEdmType(final EdmMetadata metadata, final String typeExpression) { + public AbstractEdmType(final XMLMetadata metadata, final String typeExpression) { this.typeExpression = typeExpression; final int collectionStartIdx = typeExpression.indexOf("Collection("); diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractMember.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractMember.java index c1b2f950b..95c4c818c 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractMember.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractMember.java @@ -29,7 +29,7 @@ public abstract class AbstractMember extends AbstractEdmItem implements Member { private String name; @JsonProperty("Value") - private Integer value; + private String value; @Override public String getName() { @@ -41,11 +41,11 @@ public abstract class AbstractMember extends AbstractEdmItem implements Member { } @Override - public Integer getValue() { + public String getValue() { return value; } - public void setValue(final Integer value) { + public void setValue(final String value) { this.value = value; } } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractParameter.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractParameter.java index 66f9dea71..89c15dbf4 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractParameter.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractParameter.java @@ -18,31 +18,25 @@ */ package org.apache.olingo.odata4.client.core.edm.xml; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigInteger; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.apache.olingo.odata4.client.api.edm.xml.CommonParameter; +@JsonDeserialize(using = ParameterDeserializer.class) public abstract class AbstractParameter extends AbstractEdmItem implements CommonParameter { private static final long serialVersionUID = -4305016554930334342L; - @JsonProperty(value = "Name", required = true) private String name; - @JsonProperty(value = "Type", required = true) private String type; - @JsonProperty(value = "Nullable") private boolean nullable = true; - @JsonProperty("MaxLength") - private String maxLength; + private Integer maxLength; - @JsonProperty("Precision") - private BigInteger precision; + private Integer precision; - @JsonProperty("Scale") - private BigInteger scale; + private Integer scale; @Override public String getName() { @@ -75,32 +69,32 @@ public abstract class AbstractParameter extends AbstractEdmItem implements Commo } @Override - public String getMaxLength() { + public Integer getMaxLength() { return maxLength; } @Override - public void setMaxLength(final String maxLength) { + public void setMaxLength(final Integer maxLength) { this.maxLength = maxLength; } @Override - public BigInteger getPrecision() { + public Integer getPrecision() { return precision; } @Override - public void setPrecision(final BigInteger precision) { + public void setPrecision(final Integer precision) { this.precision = precision; } @Override - public BigInteger getScale() { + public Integer getScale() { return scale; } @Override - public void setScale(final BigInteger scale) { + public void setScale(final Integer scale) { this.scale = scale; } } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractProperty.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractProperty.java index 3f2754ace..2535e23e1 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractProperty.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractProperty.java @@ -18,53 +18,40 @@ */ package org.apache.olingo.odata4.client.core.edm.xml; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigInteger; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.apache.olingo.odata4.client.api.edm.xml.CommonProperty; import org.apache.olingo.odata4.commons.api.edm.constants.ConcurrencyMode; import org.apache.olingo.odata4.commons.api.edm.constants.StoreGeneratedPattern; +@JsonDeserialize(using = PropertyDeserializer.class) public abstract class AbstractProperty extends AbstractEdmItem implements CommonProperty { private static final long serialVersionUID = -6004492361142315153L; - @JsonProperty(value = "Name", required = true) private String name; - @JsonProperty(value = "Type", required = true) private String type; - @JsonProperty(value = "Nullable") private boolean nullable = true; - @JsonProperty(value = "DefaultValue") private String defaultValue; - @JsonProperty(value = "MaxLength") - private String maxLength; + private Integer maxLength; - @JsonProperty(value = "FixedLength") private boolean fixedLength; - @JsonProperty(value = "Precision") - private BigInteger precision; + private Integer precision; - @JsonProperty(value = "Scale") - private BigInteger scale; + private Integer scale; - @JsonProperty(value = "Unicode") private boolean unicode = true; - @JsonProperty(value = "Collation") private String collation; - @JsonProperty(value = "SRID") private String srid; - @JsonProperty(value = "ConcurrencyMode") private ConcurrencyMode concurrencyMode; - @JsonProperty("StoreGeneratedPattern") private StoreGeneratedPattern storeGeneratedPattern = StoreGeneratedPattern.None; @Override @@ -108,12 +95,12 @@ public abstract class AbstractProperty extends AbstractEdmItem implements Common } @Override - public String getMaxLength() { + public Integer getMaxLength() { return maxLength; } @Override - public void setMaxLength(final String maxLength) { + public void setMaxLength(final Integer maxLength) { this.maxLength = maxLength; } @@ -128,22 +115,22 @@ public abstract class AbstractProperty extends AbstractEdmItem implements Common } @Override - public BigInteger getPrecision() { + public Integer getPrecision() { return precision; } @Override - public void setPrecision(final BigInteger precision) { + public void setPrecision(final Integer precision) { this.precision = precision; } @Override - public BigInteger getScale() { + public Integer getScale() { return scale; } @Override - public void setScale(final BigInteger scale) { + public void setScale(final Integer scale) { this.scale = scale; } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/AbstractEdmMetadata.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractXMLMetadata.java similarity index 81% rename from odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/AbstractEdmMetadata.java rename to odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractXMLMetadata.java index 2e6cc1a4c..e05294816 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/AbstractEdmMetadata.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/AbstractXMLMetadata.java @@ -16,23 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.olingo.odata4.client.core.edm; +package org.apache.olingo.odata4.client.core.edm.xml; -import java.io.InputStream; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; -import org.apache.olingo.odata4.client.api.ODataClient; -import org.apache.olingo.odata4.client.api.edm.EdmMetadata; +import org.apache.olingo.odata4.client.api.edm.xml.XMLMetadata; import org.apache.olingo.odata4.client.api.edm.xml.Edmx; import org.apache.olingo.odata4.client.api.edm.xml.Schema; -import org.apache.olingo.odata4.client.core.edm.xml.AbstractEdmItem; /** * Entry point for access information about EDM metadata. */ -public abstract class AbstractEdmMetadata extends AbstractEdmItem implements EdmMetadata { +public abstract class AbstractXMLMetadata extends AbstractEdmItem implements XMLMetadata { private static final long serialVersionUID = -1214173426671503187L; @@ -40,15 +37,8 @@ public abstract class AbstractEdmMetadata extends AbstractEdmItem implements Edm protected final Map schemaByNsOrAlias; - /** - * Constructor. - * - * @param client OData client - * @param inputStream source stream. - */ - @SuppressWarnings("unchecked") - public AbstractEdmMetadata(final ODataClient client, final InputStream inputStream) { - edmx = client.getDeserializer().toMetadata(inputStream); + public AbstractXMLMetadata(final Edmx edmx) { + this.edmx = edmx; this.schemaByNsOrAlias = new HashMap(); for (Schema schema : edmx.getDataServices().getSchemas()) { diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/ParameterDeserializer.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/ParameterDeserializer.java new file mode 100644 index 000000000..e8bd47a8d --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/ParameterDeserializer.java @@ -0,0 +1,69 @@ +/* + * 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.odata4.client.core.edm.xml; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import java.io.IOException; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.olingo.odata4.client.api.edm.xml.v3.ParameterMode; +import org.apache.olingo.odata4.client.core.op.impl.AbstractEdmDeserializer; +import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion; + +public class ParameterDeserializer extends AbstractEdmDeserializer { + + @Override + protected AbstractParameter doDeserialize(final JsonParser jp, final DeserializationContext ctxt) + throws IOException, JsonProcessingException { + + final AbstractParameter parameter = ODataServiceVersion.V30 == client.getServiceVersion() + ? new org.apache.olingo.odata4.client.core.edm.xml.v3.ParameterImpl() + : new org.apache.olingo.odata4.client.core.edm.xml.v4.ParameterImpl(); + + for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { + final JsonToken token = jp.getCurrentToken(); + if (token == JsonToken.FIELD_NAME) { + if ("Name".equals(jp.getCurrentName())) { + parameter.setName(jp.nextTextValue()); + } else if ("Type".equals(jp.getCurrentName())) { + parameter.setType(jp.nextTextValue()); + } else if ("Nullable".equals(jp.getCurrentName())) { + parameter.setNullable(BooleanUtils.toBoolean(jp.nextTextValue())); + } else if ("MaxLength".equals(jp.getCurrentName())) { + final String maxLenght = jp.nextTextValue(); + parameter.setMaxLength(maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght)); + } else if ("Precision".equals(jp.getCurrentName())) { + parameter.setPrecision(Integer.valueOf(jp.nextTextValue())); + } else if ("Scale".equals(jp.getCurrentName())) { + parameter.setScale(Integer.valueOf(jp.nextTextValue())); + } else if ("Mode".equals(jp.getCurrentName())) { + ((org.apache.olingo.odata4.client.core.edm.xml.v3.ParameterImpl) parameter). + setMode(ParameterMode.valueOf(jp.nextTextValue())); + } else if ("SRID".equals(jp.getCurrentName())) { + ((org.apache.olingo.odata4.client.core.edm.xml.v4.ParameterImpl) parameter).setSrid(jp.nextTextValue()); + } + } + } + + return parameter; + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/PropertyDeserializer.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/PropertyDeserializer.java new file mode 100644 index 000000000..f45b51075 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/PropertyDeserializer.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.odata4.client.core.edm.xml; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import java.io.IOException; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.olingo.odata4.client.core.edm.xml.v4.AnnotationImpl; +import org.apache.olingo.odata4.client.core.op.impl.AbstractEdmDeserializer; +import org.apache.olingo.odata4.commons.api.edm.constants.ConcurrencyMode; +import org.apache.olingo.odata4.commons.api.edm.constants.EdmContentKind; +import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion; +import org.apache.olingo.odata4.commons.api.edm.constants.StoreGeneratedPattern; + +public class PropertyDeserializer extends AbstractEdmDeserializer { + + @Override + protected AbstractProperty doDeserialize(final JsonParser jp, final DeserializationContext ctxt) + throws IOException, JsonProcessingException { + + final AbstractProperty property = ODataServiceVersion.V30 == client.getServiceVersion() + ? new org.apache.olingo.odata4.client.core.edm.xml.v3.PropertyImpl() + : new org.apache.olingo.odata4.client.core.edm.xml.v4.PropertyImpl(); + + for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { + final JsonToken token = jp.getCurrentToken(); + if (token == JsonToken.FIELD_NAME) { + if ("Name".equals(jp.getCurrentName())) { + property.setName(jp.nextTextValue()); + } else if ("Type".equals(jp.getCurrentName())) { + property.setType(jp.nextTextValue()); + } else if ("Nullable".equals(jp.getCurrentName())) { + property.setNullable(BooleanUtils.toBoolean(jp.nextTextValue())); + } else if ("DefaultValue".equals(jp.getCurrentName())) { + property.setDefaultValue(jp.nextTextValue()); + } else if ("MaxLength".equals(jp.getCurrentName())) { + final String maxLenght = jp.nextTextValue(); + property.setMaxLength(maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght)); + } else if ("FixedLength".equals(jp.getCurrentName())) { + property.setFixedLength(BooleanUtils.toBoolean(jp.nextTextValue())); + } else if ("Precision".equals(jp.getCurrentName())) { + property.setPrecision(Integer.valueOf(jp.nextTextValue())); + } else if ("Scale".equals(jp.getCurrentName())) { + property.setScale(Integer.valueOf(jp.nextTextValue())); + } else if ("Unicode".equals(jp.getCurrentName())) { + property.setUnicode(BooleanUtils.toBoolean(jp.nextTextValue())); + } else if ("Collation".equals(jp.getCurrentName())) { + property.setCollation(jp.nextTextValue()); + } else if ("SRID".equals(jp.getCurrentName())) { + property.setSrid(jp.nextTextValue()); + } else if ("ConcurrencyMode".equals(jp.getCurrentName())) { + property.setConcurrencyMode(ConcurrencyMode.valueOf(jp.nextTextValue())); + } else if ("StoreGeneratedPattern".equals(jp.getCurrentName())) { + property.setStoreGeneratedPattern(StoreGeneratedPattern.valueOf(jp.nextTextValue())); + } else if ("FC_SourcePath".equals(jp.getCurrentName())) { + ((org.apache.olingo.odata4.client.core.edm.xml.v3.PropertyImpl) property). + setFcSourcePath(jp.nextTextValue()); + } else if ("FC_TargetPath".equals(jp.getCurrentName())) { + ((org.apache.olingo.odata4.client.core.edm.xml.v3.PropertyImpl) property). + setFcTargetPath(jp.nextTextValue()); + } else if ("FC_ContentKind".equals(jp.getCurrentName())) { + ((org.apache.olingo.odata4.client.core.edm.xml.v3.PropertyImpl) property). + setFcContentKind(EdmContentKind.valueOf(jp.nextTextValue())); + } else if ("FC_NsPrefix".equals(jp.getCurrentName())) { + ((org.apache.olingo.odata4.client.core.edm.xml.v3.PropertyImpl) property). + setFcNSPrefix(jp.nextTextValue()); + } else if ("FC_NsUri".equals(jp.getCurrentName())) { + ((org.apache.olingo.odata4.client.core.edm.xml.v3.PropertyImpl) property). + setFcNSURI(jp.nextTextValue()); + } else if ("FC_KeepInContent".equals(jp.getCurrentName())) { + ((org.apache.olingo.odata4.client.core.edm.xml.v3.PropertyImpl) property). + setFcKeepInContent(BooleanUtils.toBoolean(jp.nextTextValue())); + } else if ("Annotation".equals(jp.getCurrentName())) { + ((org.apache.olingo.odata4.client.core.edm.xml.v4.PropertyImpl) property). + setAnnotation(jp.readValueAs(AnnotationImpl.class)); + } + } + } + + return property; + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v3/ParameterImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v3/ParameterImpl.java index d0a85596c..0912b4670 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v3/ParameterImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v3/ParameterImpl.java @@ -19,7 +19,6 @@ package org.apache.olingo.odata4.client.core.edm.xml.v3; import org.apache.olingo.odata4.client.api.edm.xml.v3.ParameterMode; -import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.olingo.odata4.client.api.edm.xml.v3.Parameter; import org.apache.olingo.odata4.client.core.edm.xml.AbstractParameter; @@ -27,7 +26,6 @@ public class ParameterImpl extends AbstractParameter implements Parameter { private static final long serialVersionUID = 7596724999614891358L; - @JsonProperty("Mode") private ParameterMode mode; @Override diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v3/PropertyImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v3/PropertyImpl.java index b4bf986df..8c5210150 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v3/PropertyImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v3/PropertyImpl.java @@ -18,7 +18,6 @@ */ package org.apache.olingo.odata4.client.core.edm.xml.v3; -import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.olingo.odata4.client.api.edm.xml.v3.Property; import org.apache.olingo.odata4.client.core.edm.xml.AbstractProperty; import org.apache.olingo.odata4.commons.api.edm.constants.EdmContentKind; @@ -27,68 +26,74 @@ public class PropertyImpl extends AbstractProperty implements Property { private static final long serialVersionUID = 6224524803474652100L; - @JsonProperty("FC_SourcePath") private String fcSourcePath; - @JsonProperty("FC_TargetPath") private String fcTargetPath; - @JsonProperty("FC_ContentKind") private EdmContentKind fcContentKind = EdmContentKind.text; - @JsonProperty("FC_NsPrefix") private String fcNSPrefix; - @JsonProperty("FC_NsUri") private String fcNSURI; - @JsonProperty("FC_KeepInContent") private boolean fcKeepInContent = true; + @Override public String getFcSourcePath() { return fcSourcePath; } + @Override public void setFcSourcePath(final String fcSourcePath) { this.fcSourcePath = fcSourcePath; } + @Override public String getFcTargetPath() { return fcTargetPath; } + @Override public void setFcTargetPath(final String fcTargetPath) { this.fcTargetPath = fcTargetPath; } + @Override public EdmContentKind getFcContentKind() { return fcContentKind; } + @Override public void setFcContentKind(final EdmContentKind fcContentKind) { this.fcContentKind = fcContentKind; } + @Override public String getFcNSPrefix() { return fcNSPrefix; } + @Override public void setFcNSPrefix(final String fcNSPrefix) { this.fcNSPrefix = fcNSPrefix; } + @Override public String getFcNSURI() { return fcNSURI; } + @Override public void setFcNSURI(final String fcNSURI) { this.fcNSURI = fcNSURI; } + @Override public boolean isFcKeepInContent() { return fcKeepInContent; } + @Override public void setFcKeepInContent(final boolean fcKeepInContent) { this.fcKeepInContent = fcKeepInContent; } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v3/EdmMetadataImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v3/XMLMetadataImpl.java similarity index 74% rename from odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v3/EdmMetadataImpl.java rename to odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v3/XMLMetadataImpl.java index f7e199377..b5399ce11 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/v3/EdmMetadataImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v3/XMLMetadataImpl.java @@ -16,20 +16,17 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.olingo.odata4.client.core.edm.v3; +package org.apache.olingo.odata4.client.core.edm.xml.v3; -import java.io.InputStream; import java.util.List; -import org.apache.olingo.odata4.client.api.ODataClient; -import org.apache.olingo.odata4.client.core.edm.AbstractEdmMetadata; -import org.apache.olingo.odata4.client.core.edm.xml.v3.SchemaImpl; +import org.apache.olingo.odata4.client.core.edm.xml.AbstractXMLMetadata; -public class EdmMetadataImpl extends AbstractEdmMetadata { +public class XMLMetadataImpl extends AbstractXMLMetadata { private static final long serialVersionUID = -7765327879691528010L; - public EdmMetadataImpl(final ODataClient client, final InputStream inputStream) { - super(client, inputStream); + public XMLMetadataImpl(final EdmxImpl edmx) { + super(edmx); } @Override diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/AnnotationDeserializer.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/AnnotationDeserializer.java index b449bdf8c..6a4332aab 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/AnnotationDeserializer.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/AnnotationDeserializer.java @@ -24,7 +24,7 @@ import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import java.io.IOException; import org.apache.olingo.odata4.client.core.op.impl.AbstractEdmDeserializer; -import org.apache.olingo.odata4.client.core.edm.v4.annotation.DynExprConstructImpl; +import org.apache.olingo.odata4.client.core.edm.xml.v4.annotation.DynExprConstructImpl; public class AnnotationDeserializer extends AbstractEdmDeserializer { diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/AnnotationImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/AnnotationImpl.java index 47bc2ad3c..d21f8468a 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/AnnotationImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/AnnotationImpl.java @@ -23,8 +23,8 @@ import org.apache.olingo.odata4.client.api.edm.xml.v4.Annotation; import org.apache.olingo.odata4.client.api.edm.xml.v4.annotation.ConstExprConstruct; import org.apache.olingo.odata4.client.api.edm.xml.v4.annotation.DynExprConstruct; import org.apache.olingo.odata4.client.core.edm.xml.AbstractEdmItem; -import org.apache.olingo.odata4.client.core.edm.v4.annotation.ConstExprConstructImpl; -import org.apache.olingo.odata4.client.core.edm.v4.annotation.DynExprConstructImpl; +import org.apache.olingo.odata4.client.core.edm.xml.v4.annotation.ConstExprConstructImpl; +import org.apache.olingo.odata4.client.core.edm.xml.v4.annotation.DynExprConstructImpl; @JsonDeserialize(using = AnnotationDeserializer.class) public class AnnotationImpl extends AbstractEdmItem implements Annotation { diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/EntityContainerImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/EntityContainerImpl.java index 40bab7ca1..93a04b98e 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/EntityContainerImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/EntityContainerImpl.java @@ -59,10 +59,12 @@ public class EntityContainerImpl extends AbstractEntityContainer implements Anno return entitySets; } + @Override public List getSingletons() { return singletons; } + @Override public SingletonImpl getSingleton(final String name) { return getOneByName(name, getSingletons()); } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/EntitySetImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/EntitySetImpl.java index b0451f589..81601931f 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/EntitySetImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/EntitySetImpl.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.olingo.odata4.client.api.edm.xml.v4.Annotation; import org.apache.olingo.odata4.client.api.edm.xml.v4.EntitySet; +import org.apache.olingo.odata4.client.api.edm.xml.v4.NavigationPropertyBinding; import org.apache.olingo.odata4.client.core.edm.xml.AbstractEntitySet; public class EntitySetImpl extends AbstractEntitySet implements EntitySet { @@ -32,8 +33,7 @@ public class EntitySetImpl extends AbstractEntitySet implements EntitySet { private AnnotationImpl annotation; - private final List navigationPropertyBindings - = new ArrayList(); + private final List navigationPropertyBindings = new ArrayList(); @Override public boolean isIncludeInServiceDocument() { @@ -46,7 +46,7 @@ public class EntitySetImpl extends AbstractEntitySet implements EntitySet { } @Override - public List getNavigationPropertyBindings() { + public List getNavigationPropertyBindings() { return navigationPropertyBindings; } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/ParameterImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/ParameterImpl.java index cf54d9ef7..ed731c3db 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/ParameterImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/ParameterImpl.java @@ -18,7 +18,6 @@ */ package org.apache.olingo.odata4.client.core.edm.xml.v4; -import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.olingo.odata4.client.api.edm.xml.v4.Parameter; import org.apache.olingo.odata4.client.core.edm.xml.AbstractParameter; @@ -26,7 +25,6 @@ public class ParameterImpl extends AbstractParameter implements Parameter { private static final long serialVersionUID = -1067642515116697747L; - @JsonProperty(value = "SRID") private String srid; @Override diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/PropertyImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/PropertyImpl.java index ae2e4d1cf..06550615b 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/PropertyImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/PropertyImpl.java @@ -19,7 +19,6 @@ package org.apache.olingo.odata4.client.core.edm.xml.v4; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.olingo.odata4.client.api.edm.xml.v4.Annotation; import org.apache.olingo.odata4.client.api.edm.xml.v4.Property; import org.apache.olingo.odata4.client.core.edm.xml.AbstractProperty; @@ -28,7 +27,6 @@ public class PropertyImpl extends AbstractProperty implements Property { private static final long serialVersionUID = -5541908235094985412L; - @JsonProperty("Annotation") private AnnotationImpl annotation; @Override diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/ReturnTypeDeserializer.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/ReturnTypeDeserializer.java new file mode 100644 index 000000000..d3e426f58 --- /dev/null +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/ReturnTypeDeserializer.java @@ -0,0 +1,60 @@ +/* + * 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.odata4.client.core.edm.xml.v4; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import java.io.IOException; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.olingo.odata4.client.core.op.impl.AbstractEdmDeserializer; + +public class ReturnTypeDeserializer extends AbstractEdmDeserializer { + + @Override + protected ReturnTypeImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) + throws IOException, JsonProcessingException { + + final ReturnTypeImpl returnType = new ReturnTypeImpl(); + + for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { + final JsonToken token = jp.getCurrentToken(); + if (token == JsonToken.FIELD_NAME) { + if ("Type".equals(jp.getCurrentName())) { + returnType.setType(jp.nextTextValue()); + } else if ("Nullable".equals(jp.getCurrentName())) { + returnType.setNullable(BooleanUtils.toBoolean(jp.nextTextValue())); + } else if ("MaxLength".equals(jp.getCurrentName())) { + final String maxLenght = jp.nextTextValue(); + returnType.setMaxLength(maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght)); + } else if ("Precision".equals(jp.getCurrentName())) { + returnType.setPrecision(Integer.valueOf(jp.nextTextValue())); + } else if ("Scale".equals(jp.getCurrentName())) { + returnType.setScale(Integer.valueOf(jp.nextTextValue())); + } else if ("SRID".equals(jp.getCurrentName())) { + returnType.setSrid(jp.nextTextValue()); + } + } + } + + return returnType; + } + +} diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/ReturnTypeImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/ReturnTypeImpl.java index 6fcf69107..02eb54ae8 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/ReturnTypeImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/ReturnTypeImpl.java @@ -18,31 +18,25 @@ */ package org.apache.olingo.odata4.client.core.edm.xml.v4; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigInteger; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.apache.olingo.odata4.client.api.edm.xml.v4.ReturnType; import org.apache.olingo.odata4.client.core.edm.xml.AbstractEdmItem; +@JsonDeserialize(using = ReturnTypeDeserializer.class) public class ReturnTypeImpl extends AbstractEdmItem implements ReturnType { private static final long serialVersionUID = -5888231162358116515L; - @JsonProperty(value = "Type") private String type; - @JsonProperty(value = "Nullable") private boolean nullable = true; - @JsonProperty(value = "MaxLength") - private String maxLength; + private Integer maxLength; - @JsonProperty(value = "Precision") - private BigInteger precision; + private Integer precision; - @JsonProperty(value = "Scale") - private BigInteger scale; + private Integer scale; - @JsonProperty(value = "SRID") private String srid; @Override @@ -66,32 +60,32 @@ public class ReturnTypeImpl extends AbstractEdmItem implements ReturnType { } @Override - public String getMaxLength() { + public Integer getMaxLength() { return maxLength; } @Override - public void setMaxLength(final String maxLength) { + public void setMaxLength(final Integer maxLength) { this.maxLength = maxLength; } @Override - public BigInteger getPrecision() { + public Integer getPrecision() { return precision; } @Override - public void setPrecision(final BigInteger precision) { + public void setPrecision(final Integer precision) { this.precision = precision; } @Override - public BigInteger getScale() { + public Integer getScale() { return scale; } @Override - public void setScale(final BigInteger scale) { + public void setScale(final Integer scale) { this.scale = scale; } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/SchemaImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/SchemaImpl.java index d37e9fbdd..3987d3cd5 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/SchemaImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/SchemaImpl.java @@ -92,6 +92,10 @@ public class SchemaImpl extends AbstractSchema implements Schema, AnnotatedEdmIt return terms; } + public TypeDefinitionImpl getTypeDefinition(final String name) { + return getOneByName(name, getTypeDefinitions()); + } + public List getTypeDefinitions() { return typeDefinitions; } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/SingletonDeserializer.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/SingletonDeserializer.java index 06385db77..77b788926 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/SingletonDeserializer.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/SingletonDeserializer.java @@ -39,7 +39,7 @@ public class SingletonDeserializer extends AbstractEdmDeserializer navigationPropertyBindings - = new ArrayList(); + private final List navigationPropertyBindings = new ArrayList(); @Override public String getName() { @@ -46,17 +46,17 @@ public class SingletonImpl extends AbstractAnnotatedEdmItem implements Singleton } @Override - public String getType() { - return type; + public String getEntityType() { + return entityType; } @Override - public void setType(final String type) { - this.type = type; + public void setEntityType(final String entityType) { + this.entityType = entityType; } @Override - public List getNavigationPropertyBindings() { + public List getNavigationPropertyBindings() { return navigationPropertyBindings; } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/TypeDefinitionDeserializer.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/TypeDefinitionDeserializer.java index 36b4cbe8b..07d258983 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/TypeDefinitionDeserializer.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/edm/xml/v4/TypeDefinitionDeserializer.java @@ -23,7 +23,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import java.io.IOException; -import java.math.BigInteger; import org.apache.commons.lang3.BooleanUtils; import org.apache.olingo.odata4.client.core.op.impl.AbstractEdmDeserializer; @@ -43,18 +42,18 @@ public class TypeDefinitionDeserializer extends AbstractEdmDeserializer extends JsonDeserializer { diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v3/ODataDeserializerImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v3/ODataDeserializerImpl.java index 36b90b2c5..9096099de 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v3/ODataDeserializerImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v3/ODataDeserializerImpl.java @@ -22,6 +22,7 @@ import java.io.InputStream; import org.apache.olingo.odata4.client.api.ODataClient; import org.apache.olingo.odata4.client.core.op.impl.AbstractODataDeserializer; import org.apache.olingo.odata4.client.core.edm.xml.v3.EdmxImpl; +import org.apache.olingo.odata4.client.core.edm.xml.v3.XMLMetadataImpl; public class ODataDeserializerImpl extends AbstractODataDeserializer { @@ -32,9 +33,9 @@ public class ODataDeserializerImpl extends AbstractODataDeserializer { } @Override - public EdmxImpl toMetadata(final InputStream input) { + public XMLMetadataImpl toMetadata(final InputStream input) { try { - return getXmlMapper().readValue(input, EdmxImpl.class); + return new XMLMetadataImpl(getXmlMapper().readValue(input, EdmxImpl.class)); } catch (Exception e) { throw new IllegalArgumentException("Could not parse as Edmx document", e); } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v3/ODataReaderImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v3/ODataReaderImpl.java index 83f049430..5b1c6cc9b 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v3/ODataReaderImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v3/ODataReaderImpl.java @@ -20,8 +20,9 @@ package org.apache.olingo.odata4.client.core.op.impl.v3; import java.io.InputStream; import org.apache.olingo.odata4.client.core.ODataV3Client; +import org.apache.olingo.odata4.client.core.edm.EdmClientImpl; import org.apache.olingo.odata4.client.core.op.impl.AbstractODataReader; -import org.apache.olingo.odata4.client.core.edm.v3.EdmMetadataImpl; +import org.apache.olingo.odata4.commons.api.edm.Edm; public class ODataReaderImpl extends AbstractODataReader { @@ -32,8 +33,8 @@ public class ODataReaderImpl extends AbstractODataReader { } @Override - public EdmMetadataImpl readMetadata(final InputStream input) { - return new EdmMetadataImpl(client, input); + public Edm readMetadata(final InputStream input) { + return new EdmClientImpl(client.getDeserializer().toMetadata(input)); } // @Override diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v4/ODataDeserializerImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v4/ODataDeserializerImpl.java index b97b69b90..83c1aeaf4 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v4/ODataDeserializerImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v4/ODataDeserializerImpl.java @@ -22,6 +22,7 @@ import java.io.InputStream; import org.apache.olingo.odata4.client.api.ODataClient; import org.apache.olingo.odata4.client.core.op.impl.AbstractODataDeserializer; import org.apache.olingo.odata4.client.core.edm.xml.v4.EdmxImpl; +import org.apache.olingo.odata4.client.core.edm.xml.v4.XMLMetadataImpl; public class ODataDeserializerImpl extends AbstractODataDeserializer { @@ -32,9 +33,9 @@ public class ODataDeserializerImpl extends AbstractODataDeserializer { } @Override - public EdmxImpl toMetadata(final InputStream input) { + public XMLMetadataImpl toMetadata(final InputStream input) { try { - return getXmlMapper().readValue(input, EdmxImpl.class); + return new XMLMetadataImpl(getXmlMapper().readValue(input, EdmxImpl.class)); } catch (Exception e) { throw new IllegalArgumentException("Could not parse as Edmx document", e); } diff --git a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v4/ODataReaderImpl.java b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v4/ODataReaderImpl.java index 11b7112f2..35209c222 100644 --- a/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v4/ODataReaderImpl.java +++ b/odata4-lib/odata4-client-core/src/main/java/org/apache/olingo/odata4/client/core/op/impl/v4/ODataReaderImpl.java @@ -20,8 +20,9 @@ package org.apache.olingo.odata4.client.core.op.impl.v4; import java.io.InputStream; import org.apache.olingo.odata4.client.core.ODataV4Client; +import org.apache.olingo.odata4.client.core.edm.EdmClientImpl; import org.apache.olingo.odata4.client.core.op.impl.AbstractODataReader; -import org.apache.olingo.odata4.client.core.edm.v4.EdmMetadataImpl; +import org.apache.olingo.odata4.commons.api.edm.Edm; public class ODataReaderImpl extends AbstractODataReader { @@ -32,8 +33,8 @@ public class ODataReaderImpl extends AbstractODataReader { } @Override - public EdmMetadataImpl readMetadata(final InputStream input) { - return new EdmMetadataImpl(client, input); + public Edm readMetadata(final InputStream input) { + return new EdmClientImpl(client.getDeserializer().toMetadata(input)); } // @Override diff --git a/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/v3/MetadataTest.java b/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/v3/MetadataTest.java index b23cb72ad..97f855ce3 100644 --- a/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/v3/MetadataTest.java +++ b/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/v3/MetadataTest.java @@ -29,12 +29,12 @@ import org.apache.olingo.odata4.client.api.http.HttpMethod; import org.apache.olingo.odata4.client.core.AbstractTest; import org.apache.olingo.odata4.client.core.ODataV3Client; import org.apache.olingo.odata4.client.core.edm.xml.v3.ComplexTypeImpl; -import org.apache.olingo.odata4.client.core.edm.v3.EdmMetadataImpl; import org.apache.olingo.odata4.client.core.edm.v3.EdmTypeImpl; import org.apache.olingo.odata4.client.core.edm.xml.v3.EntityContainerImpl; import org.apache.olingo.odata4.client.core.edm.xml.v3.EntityTypeImpl; import org.apache.olingo.odata4.client.core.edm.xml.v3.FunctionImportImpl; import org.apache.olingo.odata4.client.core.edm.xml.v3.SchemaImpl; +import org.apache.olingo.odata4.client.core.edm.xml.v3.XMLMetadataImpl; import org.junit.Test; public class MetadataTest extends AbstractTest { @@ -46,8 +46,8 @@ public class MetadataTest extends AbstractTest { @Test public void parse() { - final EdmMetadataImpl metadata = getClient().getReader(). - readMetadata(getClass().getResourceAsStream("metadata.xml")); + final XMLMetadataImpl metadata = getClient().getDeserializer(). + toMetadata(getClass().getResourceAsStream("metadata.xml")); assertNotNull(metadata); final EdmTypeImpl orderCollection = new EdmTypeImpl(metadata, @@ -98,8 +98,8 @@ public class MetadataTest extends AbstractTest { @Test public void multipleSchemas() { - final EdmMetadataImpl metadata = getClient().getReader(). - readMetadata(getClass().getResourceAsStream("northwind-metadata.xml")); + final XMLMetadataImpl metadata = getClient().getDeserializer(). + toMetadata(getClass().getResourceAsStream("northwind-metadata.xml")); assertNotNull(metadata); final SchemaImpl first = metadata.getSchema("NorthwindModel"); @@ -115,8 +115,8 @@ public class MetadataTest extends AbstractTest { @Test public void entityType() { - final EdmMetadataImpl metadata = getClient().getReader(). - readMetadata(getClass().getResourceAsStream("metadata.xml")); + final XMLMetadataImpl metadata = getClient().getDeserializer(). + toMetadata(getClass().getResourceAsStream("metadata.xml")); assertNotNull(metadata); final EntityContainerImpl container = metadata.getSchema(0).getEntityContainers().get(0); @@ -133,8 +133,8 @@ public class MetadataTest extends AbstractTest { @Test public void complexType() { - final EdmMetadataImpl metadata = getClient().getReader(). - readMetadata(getClass().getResourceAsStream("metadata.xml")); + final XMLMetadataImpl metadata = getClient().getDeserializer(). + toMetadata(getClass().getResourceAsStream("metadata.xml")); assertNotNull(metadata); final EntityContainerImpl container = metadata.getSchema(0).getEntityContainers().get(0); @@ -148,8 +148,8 @@ public class MetadataTest extends AbstractTest { @Test public void functionImport() { - final EdmMetadataImpl metadata = getClient().getReader(). - readMetadata(getClass().getResourceAsStream("metadata.xml")); + final XMLMetadataImpl metadata = getClient().getDeserializer(). + toMetadata(getClass().getResourceAsStream("metadata.xml")); assertNotNull(metadata); final EntityContainerImpl container = metadata.getSchema(0).getEntityContainers().get(0); diff --git a/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/v4/MetadataTest.java b/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/v4/MetadataTest.java index 38709ed2a..fba34daa7 100644 --- a/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/v4/MetadataTest.java +++ b/odata4-lib/odata4-client-core/src/test/java/org/apache/olingo/odata4/client/core/v4/MetadataTest.java @@ -19,34 +19,42 @@ package org.apache.olingo.odata4.client.core.v4; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.util.List; -import org.apache.olingo.odata4.client.api.data.EdmSimpleType; import org.apache.olingo.odata4.client.core.AbstractTest; import org.apache.olingo.odata4.client.core.ODataV4Client; -import org.apache.olingo.odata4.client.core.edm.xml.v4.FunctionImportImpl; -import org.apache.olingo.odata4.client.core.edm.xml.v4.ActionImpl; +import org.apache.olingo.odata4.client.core.edm.v4.EdmTypeImpl; +import org.apache.olingo.odata4.client.core.edm.xml.v4.XMLMetadataImpl; import org.apache.olingo.odata4.client.core.edm.xml.v4.AnnotationImpl; import org.apache.olingo.odata4.client.core.edm.xml.v4.AnnotationsImpl; import org.apache.olingo.odata4.client.core.edm.xml.v4.ComplexTypeImpl; -import org.apache.olingo.odata4.client.core.edm.v4.EdmMetadataImpl; -import org.apache.olingo.odata4.client.core.edm.v4.EdmTypeImpl; import org.apache.olingo.odata4.client.core.edm.xml.v4.EntityContainerImpl; -import org.apache.olingo.odata4.client.core.edm.xml.v4.EntitySetImpl; import org.apache.olingo.odata4.client.core.edm.xml.v4.EntityTypeImpl; -import org.apache.olingo.odata4.client.core.edm.xml.v4.EnumTypeImpl; import org.apache.olingo.odata4.client.core.edm.xml.v4.FunctionImpl; +import org.apache.olingo.odata4.client.core.edm.xml.v4.FunctionImportImpl; import org.apache.olingo.odata4.client.core.edm.xml.v4.SchemaImpl; import org.apache.olingo.odata4.client.core.edm.xml.v4.SingletonImpl; -import org.apache.olingo.odata4.client.core.edm.v4.annotation.Apply; -import org.apache.olingo.odata4.client.core.edm.v4.annotation.Collection; -import org.apache.olingo.odata4.client.core.edm.v4.annotation.ConstExprConstructImpl; -import org.apache.olingo.odata4.client.core.edm.v4.annotation.Path; +import org.apache.olingo.odata4.client.core.edm.xml.v4.annotation.Apply; +import org.apache.olingo.odata4.client.core.edm.xml.v4.annotation.Collection; +import org.apache.olingo.odata4.client.core.edm.xml.v4.annotation.ConstExprConstructImpl; +import org.apache.olingo.odata4.client.core.edm.xml.v4.annotation.Path; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmAction; +import org.apache.olingo.odata4.commons.api.edm.EdmComplexType; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityType; +import org.apache.olingo.odata4.commons.api.edm.EdmEnumType; +import org.apache.olingo.odata4.commons.api.edm.EdmFunction; +import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImport; +import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImportInfo; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; import org.apache.olingo.odata4.commons.api.edm.constants.StoreGeneratedPattern; +import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind; +import static org.junit.Assert.assertNull; import org.junit.Test; public class MetadataTest extends AbstractTest { @@ -58,73 +66,70 @@ public class MetadataTest extends AbstractTest { @Test public void parse() { - final EdmMetadataImpl metadata = getClient().getReader(). + final Edm edm = getClient().getReader(). readMetadata(getClass().getResourceAsStream("metadata.xml")); - assertNotNull(metadata); + assertNotNull(edm); // 1. Enum - final EnumTypeImpl responseEnumType = metadata.getSchema(0).getEnumType("ResponseType"); + final EdmEnumType responseEnumType = edm.getEnumType( + new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "ResponseType")); assertNotNull(responseEnumType); - assertEquals(6, responseEnumType.getMembers().size()); - assertEquals(3, responseEnumType.getMember("Accepted").getValue().intValue()); - assertEquals("Accepted", responseEnumType.getMember(3).getName()); - - final EdmTypeImpl responseType = new EdmTypeImpl(metadata, - "Microsoft.Exchange.Services.OData.Model.ResponseType"); - assertNotNull(responseType); - assertFalse(responseType.isCollection()); - assertFalse(responseType.isSimpleType()); - assertTrue(responseType.isEnumType()); - assertFalse(responseType.isComplexType()); - assertFalse(responseType.isEntityType()); + assertEquals(6, responseEnumType.getMemberNames().size()); + assertEquals("3", responseEnumType.getMember("Accepted").getValue()); + assertEquals(EdmTypeKind.ENUM, responseEnumType.getKind()); // 2. Complex - final ComplexTypeImpl responseStatus = metadata.getSchema(0).getComplexType("ResponseStatus"); + final EdmComplexType responseStatus = edm.getComplexType( + new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "ResponseStatus")); assertNotNull(responseStatus); - assertTrue(responseStatus.getNavigationProperties().isEmpty()); - assertEquals(EdmSimpleType.DateTimeOffset, - EdmSimpleType.fromValue(responseStatus.getProperty("Time").getType())); + assertTrue(responseStatus.getNavigationPropertyNames().isEmpty()); + assertEquals("Recipient", responseStatus.getBaseType().getName()); + assertEquals(EdmPrimitiveTypeKind.DateTimeOffset.getEdmPrimitiveTypeInstance(), + responseStatus.getProperty("Time").getType()); // 3. Entity - final EntityTypeImpl user = metadata.getSchema(0).getEntityType("User"); + final EdmEntityType user = edm.getEntityType( + new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "User")); assertNotNull(user); - assertEquals("Microsoft.Exchange.Services.OData.Model.Entity", user.getBaseType()); - assertFalse(user.getProperties().isEmpty()); - assertFalse(user.getNavigationProperties().isEmpty()); - assertEquals("Microsoft.Exchange.Services.OData.Model.Folder", user.getNavigationProperty("Inbox").getType()); + final EdmEntityType entity = edm.getEntityType( + new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Entity")); + assertEquals(entity, user.getBaseType()); + assertFalse(user.getPropertyNames().isEmpty()); + assertFalse(user.getNavigationPropertyNames().isEmpty()); + final EdmEntityType folder = edm.getEntityType( + new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Folder")); + assertEquals(folder, user.getNavigationProperty("Inbox").getType()); // 4. Action - final List moves = metadata.getSchema(0).getActions("Move"); - assertFalse(moves.isEmpty()); - ActionImpl move = null; - for (ActionImpl action : moves) { - if ("Microsoft.Exchange.Services.OData.Model.EmailMessage".equals(action.getReturnType().getType())) { - move = action; - } - } + final EdmAction move = edm.getAction( + new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Move"), + new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Folder"), + false); assertNotNull(move); assertTrue(move.isBound()); - assertEquals("bindingParameter", move.getEntitySetPath()); - assertEquals(2, move.getParameters().size()); - assertEquals("Microsoft.Exchange.Services.OData.Model.EmailMessage", move.getParameters().get(0).getType()); + assertEquals(2, move.getParameterNames().size()); + assertEquals( + EdmPrimitiveTypeKind.String.getEdmPrimitiveTypeInstance(), move.getParameter("DestinationId").getType()); // 5. EntityContainer - final EntityContainerImpl container = metadata.getSchema(0).getEntityContainer(); + final EdmEntityContainer container = edm.getEntityContainer( + new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "EntityContainer")); assertNotNull(container); - final EntitySetImpl users = container.getEntitySet("Users"); + final EdmEntitySet users = container.getEntitySet("Users"); assertNotNull(users); - assertEquals(metadata.getSchema(0).getNamespace() + "." + user.getName(), users.getEntityType()); - assertEquals(user.getNavigationProperties().size(), users.getNavigationPropertyBindings().size()); + assertEquals(edm.getEntityType(new FullQualifiedName(container.getNamespace(), "User")), + users.getEntityType()); + assertEquals(container.getEntitySet("Folders"), users.getRelatedBindingTarget("Folders")); } @Test public void demo() { - final EdmMetadataImpl metadata = getClient().getReader(). - readMetadata(getClass().getResourceAsStream("demo-metadata.xml")); + final XMLMetadataImpl metadata = getClient().getDeserializer(). + toMetadata(getClass().getResourceAsStream("demo-metadata.xml")); assertNotNull(metadata); assertFalse(metadata.getSchema(0).getAnnotationsList().isEmpty()); - AnnotationsImpl annots = metadata.getSchema(0).getAnnotationsList("ODataDemo.DemoService/Suppliers"); + final AnnotationsImpl annots = metadata.getSchema(0).getAnnotationsList("ODataDemo.DemoService/Suppliers"); assertNotNull(annots); assertFalse(annots.getAnnotations().isEmpty()); assertEquals(ConstExprConstructImpl.Type.String, @@ -135,8 +140,8 @@ public class MetadataTest extends AbstractTest { @Test public void multipleSchemas() { - final EdmMetadataImpl metadata = getClient().getReader(). - readMetadata(getClass().getResourceAsStream("northwind-metadata.xml")); + final XMLMetadataImpl metadata = getClient().getDeserializer(). + toMetadata(getClass().getResourceAsStream("northwind-metadata.xml")); assertNotNull(metadata); final SchemaImpl first = metadata.getSchema("NorthwindModel"); @@ -159,8 +164,8 @@ public class MetadataTest extends AbstractTest { */ @Test public void fromdoc1() { - final EdmMetadataImpl metadata = getClient().getReader(). - readMetadata(getClass().getResourceAsStream("fromdoc1-metadata.xml")); + final XMLMetadataImpl metadata = getClient().getDeserializer(). + toMetadata(getClass().getResourceAsStream("fromdoc1-metadata.xml")); assertNotNull(metadata); assertFalse(metadata.getReferences().isEmpty()); @@ -169,7 +174,6 @@ public class MetadataTest extends AbstractTest { final EntityTypeImpl product = metadata.getSchema(0).getEntityType("Product"); assertTrue(product.isHasStream()); assertEquals("UoM.ISOCurrency", product.getProperty("Price").getAnnotation().getTerm()); - //assertEquals("Currency", product.getProperty("Price").getAnnotation().)); assertEquals("Products", product.getNavigationProperty("Supplier").getPartner()); final EntityTypeImpl category = metadata.getSchema(0).getEntityType("Category"); @@ -198,6 +202,31 @@ public class MetadataTest extends AbstractTest { assertNotNull(functionImport); assertEquals(metadata.getSchema(0).getNamespace() + "." + productsByRating.getName(), functionImport.getFunction()); + + // Now let's go high-level + final Edm edm = getClient().getReader(). + readMetadata(getClass().getResourceAsStream("fromdoc1-metadata.xml")); + assertNotNull(edm); + + final EdmFunctionImportInfo fiInfo = edm.getServiceMetadata().getFunctionImportInfos().get(0); + final EdmEntityContainer demoService = edm.getEntityContainer( + new FullQualifiedName(metadata.getSchema(0).getNamespace(), fiInfo.getEntityContainerName())); + assertNotNull(demoService); + final EdmFunctionImport fi = demoService.getFunctionImport(fiInfo.getFunctionImportName()); + assertNotNull(fi); + assertEquals(demoService.getEntitySet("Products"), fi.getReturnedEntitySet()); + + final EdmFunction function = edm.getFunction( + new FullQualifiedName(metadata.getSchema(0).getNamespace(), "ProductsByRating"), + null, Boolean.FALSE, null); + assertNotNull(function); + assertEquals(function.getName(), fi.getFunction(null).getName()); + assertEquals(function.getNamespace(), fi.getFunction(null).getNamespace()); + assertEquals(function.getParameterNames(), fi.getFunction(null).getParameterNames()); + assertEquals(function.getReturnType().getType().getName(), + fi.getFunction(null).getReturnType().getType().getName()); + assertEquals(function.getReturnType().getType().getNamespace(), + fi.getFunction(null).getReturnType().getType().getNamespace()); } /** @@ -205,8 +234,8 @@ public class MetadataTest extends AbstractTest { */ @Test public void fromdoc2() { - final EdmMetadataImpl metadata = getClient().getReader(). - readMetadata(getClass().getResourceAsStream("fromdoc2-metadata.xml")); + final XMLMetadataImpl metadata = getClient().getDeserializer(). + toMetadata(getClass().getResourceAsStream("fromdoc2-metadata.xml")); assertNotNull(metadata); // Check displayName @@ -253,7 +282,7 @@ public class MetadataTest extends AbstractTest { */ @Test public void fromdoc3() { - final EdmMetadataImpl metadata = getClient().getReader(). + final Edm metadata = getClient().getReader(). readMetadata(getClass().getResourceAsStream("fromdoc3-metadata.xml")); assertNotNull(metadata); } diff --git a/odata4-lib/odata4-client-core/src/test/resources/org/apache/olingo/odata4/client/core/v4/demo-metadata.xml b/odata4-lib/odata4-client-core/src/test/resources/org/apache/olingo/odata4/client/core/v4/demo-metadata.xml index 8296468d4..9b21e2f78 100644 --- a/odata4-lib/odata4-client-core/src/test/resources/org/apache/olingo/odata4/client/core/v4/demo-metadata.xml +++ b/odata4-lib/odata4-client-core/src/test/resources/org/apache/olingo/odata4/client/core/v4/demo-metadata.xml @@ -19,4 +19,145 @@ under the License. --> - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/odata4-lib/odata4-client-core/src/test/resources/org/apache/olingo/odata4/client/core/v4/fromdoc1-metadata.xml b/odata4-lib/odata4-client-core/src/test/resources/org/apache/olingo/odata4/client/core/v4/fromdoc1-metadata.xml index d2f99e368..ed4684456 100644 --- a/odata4-lib/odata4-client-core/src/test/resources/org/apache/olingo/odata4/client/core/v4/fromdoc1-metadata.xml +++ b/odata4-lib/odata4-client-core/src/test/resources/org/apache/olingo/odata4/client/core/v4/fromdoc1-metadata.xml @@ -28,6 +28,16 @@ + + + + + + + + + + diff --git a/odata4-lib/odata4-client-core/src/test/resources/org/apache/olingo/odata4/client/core/v4/northwind-metadata.xml b/odata4-lib/odata4-client-core/src/test/resources/org/apache/olingo/odata4/client/core/v4/northwind-metadata.xml index 4c3c37d0f..f65815d50 100644 --- a/odata4-lib/odata4-client-core/src/test/resources/org/apache/olingo/odata4/client/core/v4/northwind-metadata.xml +++ b/odata4-lib/odata4-client-core/src/test/resources/org/apache/olingo/odata4/client/core/v4/northwind-metadata.xml @@ -19,4 +19,453 @@ under the License. --> - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/Edm.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/Edm.java index 3d1e535c9..26861e345 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/Edm.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/Edm.java @@ -28,7 +28,7 @@ import java.util.List; public interface Edm { /** - * Get entity container by full qualified name + * Get entity container by full qualified name. *
* See {@link EdmEntityContainer} for more information. * @@ -38,7 +38,7 @@ public interface Edm { EdmEntityContainer getEntityContainer(FullQualifiedName name); /** - * Get enum type by full qualified name + * Get enum type by full qualified name. *
* See {@link EdmEnumType} for more information * @@ -48,7 +48,7 @@ public interface Edm { EdmEnumType getEnumType(FullQualifiedName name); /** - * Get a type definition by full qualified name + * Get a type definition by full qualified name. *
* See {@link EdmTypeDefinition} for more information * @@ -58,7 +58,7 @@ public interface Edm { EdmTypeDefinition getTypeDefinition(FullQualifiedName name); /** - * Get entity type by full qualified name + * Get entity type by full qualified name. *
* See {@link EdmEntityType} for more information. * @@ -68,7 +68,7 @@ public interface Edm { EdmEntityType getEntityType(FullQualifiedName name); /** - * Get complex type by full qualified name. + * Get complex type by full qualified name.. *
* See {@link EdmComplexType} for more information. * @@ -101,7 +101,7 @@ public interface Edm { Boolean isBindingParameterCollection, List parameterNames); /** - * Get service metadata + * Get service metadata. *
* See {@link EdmServiceMetadata} for more information. * diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmActionImportInfo.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmActionImportInfo.java new file mode 100644 index 000000000..18f0d7438 --- /dev/null +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmActionImportInfo.java @@ -0,0 +1,40 @@ +/* + * 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.odata4.commons.api.edm; + +import java.net.URI; + +/** + * Objects of this class contain information about one action import inside the EntityDataModel. + */ +public interface EdmActionImportInfo extends EdmOperationImportInfo { + + /** + * @return the action import name + */ + String getActionImportName(); + + /** + * We use a {@link URI} object here to ensure the right encoding. If a string representation is needed the + * toASCIIString() method can be used. + * + * @return the uri to this function import + */ + URI getActionImportUri(); +} diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmComplexType.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmComplexType.java index 7b2662186..728722832 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmComplexType.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmComplexType.java @@ -24,7 +24,7 @@ package org.apache.olingo.odata4.commons.api.edm; * EdmComplexType holds a set of related information like {@link EdmPrimitiveType} properties and EdmComplexType * properties. */ -public interface EdmComplexType extends EdmStructuralType { +public interface EdmComplexType extends EdmStructuredType { @Override EdmComplexType getBaseType(); diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmEntityType.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmEntityType.java index 585f8139e..b582551b5 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmEntityType.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmEntityType.java @@ -23,7 +23,7 @@ import java.util.List; /** * A CSDL EntityType element. */ -public interface EdmEntityType extends EdmStructuralType { +public interface EdmEntityType extends EdmStructuredType { /** * Gets all key predicate names. In case an alias is defined for a key predicate this will be returned. diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmFunctionImportInfo.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmFunctionImportInfo.java index ac62798f1..28fc6fa95 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmFunctionImportInfo.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmFunctionImportInfo.java @@ -23,12 +23,7 @@ import java.net.URI; /** * Objects of this class contain information about one function import inside the EntityDataModel. */ -public interface EdmFunctionImportInfo { - - /** - * @return the entity container name which contains this function import. - */ - String getEntityContainerName(); +public interface EdmFunctionImportInfo extends EdmOperationImportInfo { /** * @return the function import name diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmOperationImportInfo.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmOperationImportInfo.java new file mode 100644 index 000000000..1c2c62a06 --- /dev/null +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmOperationImportInfo.java @@ -0,0 +1,31 @@ +/* + * 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.odata4.commons.api.edm; + +/** + * Objects of this class contain information about one action or function import inside the EntityDataModel. + */ +public interface EdmOperationImportInfo { + + /** + * @return the entity container name which contains this function import. + */ + String getEntityContainerName(); + +} diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmServiceMetadata.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmServiceMetadata.java index bf3a6d67b..be6f2c404 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmServiceMetadata.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmServiceMetadata.java @@ -47,6 +47,11 @@ public interface EdmServiceMetadata { */ List getSingletonInfos(); + /** + * @return a list of {@link EdmActionImportInfo} objects inside the data model + */ + List getActionImportInfos(); + /** * @return a list of {@link EdmFunctionImportInfo} objects inside the data model */ diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmStructuralType.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmStructuredType.java similarity index 78% rename from odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmStructuralType.java rename to odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmStructuredType.java index be11391c4..b51595745 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmStructuralType.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/EdmStructuredType.java @@ -25,10 +25,10 @@ import java.util.List; * * Complex types and entity types are described in the Conceptual Schema Definition of the OData protocol. */ -public interface EdmStructuralType extends EdmType { +public interface EdmStructuredType extends EdmType { /** - * Get property by name. + * Get property by name * * @param name * @return simple, complex or navigation property as {@link EdmTyped} @@ -42,6 +42,22 @@ public interface EdmStructuralType extends EdmType { */ List getPropertyNames(); + /** + * Get structural property by name. + * + * @param name + * @return simple or complex property as {@link EdmTyped} + */ + EdmProperty getStructuralProperty(String name); + + /** + * Get navigation property by name. + * + * @param name + * @return navigation property as {@link EdmTyped} + */ + EdmNavigationProperty getNavigationProperty(String name); + /** * Get all navigation property names. * @@ -52,9 +68,9 @@ public interface EdmStructuralType extends EdmType { /** * Base types are described in the OData protocol specification. * - * @return {@link EdmStructuralType} + * @return {@link EdmStructuredType} */ - EdmStructuralType getBaseType(); + EdmStructuredType getBaseType(); /** * Checks if this type is convertible to parameter {@link targetType} diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/Target.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/Target.java new file mode 100644 index 000000000..5acadc40a --- /dev/null +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/Target.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.odata4.commons.api.edm; + +public class Target { + + private String targetName; + + private FullQualifiedName entityContainer; + + public static class Builder { + + private final Target instance; + + public Builder(final String target, final EdmEntityContainer defaultContainer) { + final String[] bindingTargetParts = target.split("/"); + + instance = new Target(); + if (bindingTargetParts.length == 1) { + instance. + setEntityContainer(new FullQualifiedName(defaultContainer.getNamespace(), defaultContainer.getName())). + setTargetName(bindingTargetParts[0]); + } else { + final int idx = bindingTargetParts[0].lastIndexOf('.'); + instance. + setEntityContainer(new FullQualifiedName( + bindingTargetParts[0].substring(0, idx), bindingTargetParts[0].substring(idx))). + setTargetName(bindingTargetParts[1]); + } + } + + public Target build() { + return instance; + } + } + + public String getTargetName() { + return targetName; + } + + public Target setTargetName(final String targetPathName) { + targetName = targetPathName; + return this; + } + + public FullQualifiedName getEntityContainer() { + return entityContainer; + } + + public Target setEntityContainer(final FullQualifiedName entityContainer) { + this.entityContainer = entityContainer; + return this; + } + +} diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmBindingTarget.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmBindingTarget.java new file mode 100644 index 000000000..6e9df5647 --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmBindingTarget.java @@ -0,0 +1,55 @@ +/* + * 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.odata4.commons.core.edm; + +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmBindingTarget; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityType; +import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; + +public abstract class AbstractEdmBindingTarget extends EdmNamedImpl implements EdmBindingTarget { + + protected final EdmEntityContainer container; + + private final FullQualifiedName type; + + public AbstractEdmBindingTarget(final Edm edm, final EdmEntityContainer container, + final String name, final FullQualifiedName type) { + + super(edm, name); + this.container = container; + this.type = type; + } + + @Override + public EdmEntityContainer getEntityContainer() { + return container; + } + + @Override + public EdmEntityType getEntityType() { + final EdmEntityType entityType = edm.getEntityType(this.type); + if (entityType == null) { + throw new EdmException("Can´t find entity type: " + type + " for entity set or singleton: " + getName()); + } + return entityType; + } +} diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmComplexType.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmComplexType.java new file mode 100644 index 000000000..db52f2ede --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmComplexType.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.odata4.commons.core.edm; + +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmComplexType; +import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.EdmStructuredType; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; + +public abstract class AbstractEdmComplexType extends AbstractEdmStructuredType implements EdmComplexType { + + public AbstractEdmComplexType(final Edm edm, final FullQualifiedName fqn, final FullQualifiedName baseTypeName) { + super(edm, fqn, EdmTypeKind.COMPLEX, baseTypeName); + } + + @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() { + return (EdmComplexType) baseType; + } +} diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmEntityContainer.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmEntityContainer.java new file mode 100644 index 000000000..d1839721b --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmEntityContainer.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.odata4.commons.core.edm; + +import java.util.HashMap; +import java.util.Map; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmActionImport; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet; +import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImport; +import org.apache.olingo.odata4.commons.api.edm.EdmSingleton; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; + +public abstract class AbstractEdmEntityContainer extends EdmNamedImpl implements EdmEntityContainer { + + protected final FullQualifiedName entityContainerName; + + private final Map singletons = new HashMap(); + + private final Map entitySets = new HashMap(); + + private final Map actionImports = new HashMap(); + + private final Map functionImports = new HashMap(); + + public AbstractEdmEntityContainer(final Edm edm, final FullQualifiedName entityContainerName) { + super(edm, entityContainerName.getName()); + this.entityContainerName = entityContainerName; + } + + @Override + public String getNamespace() { + return entityContainerName.getNamespace(); + } + + protected abstract EdmSingleton createSingleton(String singletonName); + + @Override + public EdmSingleton getSingleton(final String singletonName) { + EdmSingleton singleton = singletons.get(singletonName); + if (singleton == null) { + singleton = createSingleton(singletonName); + singletons.put(singletonName, singleton); + } + return singleton; + } + + protected abstract EdmEntitySet createEntitySet(String entitySetName); + + @Override + public EdmEntitySet getEntitySet(final String entitySetName) { + EdmEntitySet entitySet = entitySets.get(entitySetName); + if (entitySet == null) { + entitySet = createEntitySet(entitySetName); + entitySets.put(entitySetName, entitySet); + } + return entitySet; + } + + protected abstract EdmActionImport createActionImport(String actionImportName); + + @Override + public EdmActionImport getActionImport(final String actionImportName) { + EdmActionImport actionImport = actionImports.get(actionImportName); + if (actionImport == null) { + actionImport = createActionImport(actionImportName); + actionImports.put(actionImportName, actionImport); + } + return actionImport; + } + + protected abstract EdmFunctionImport createFunctionImport(String functionImportName); + + @Override + public EdmFunctionImport getFunctionImport(final String functionImportName) { + EdmFunctionImport functionImport = functionImports.get(functionImportName); + if (functionImport == null) { + functionImport = createFunctionImport(functionImportName); + functionImports.put(functionImportName, functionImport); + } + return functionImport; + } + +} diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmEntityType.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmEntityType.java new file mode 100644 index 000000000..75f982f4c --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmEntityType.java @@ -0,0 +1,113 @@ +/* + * 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.odata4.commons.core.edm; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityType; +import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.EdmKeyPropertyRef; +import org.apache.olingo.odata4.commons.api.edm.EdmStructuredType; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; + +public abstract class AbstractEdmEntityType extends AbstractEdmStructuredType implements EdmEntityType { + + private final boolean hasStream; + + protected EdmEntityType entityBaseType; + + private final List keyPredicateNames = new ArrayList(); + + private final Map keyPropertyRefs = new LinkedHashMap(); + + private List keyPropertyRefsList; + + protected AbstractEdmEntityType(final Edm edm, final FullQualifiedName fqn, final FullQualifiedName baseTypeName, + final boolean hashStream) { + + super(edm, fqn, EdmTypeKind.ENTITY, baseTypeName); + this.hasStream = hashStream; + } + + protected void setEdmKeyPropertyRef(final List edmKey) { + for (EdmKeyPropertyRef ref : edmKey) { + if (ref.getAlias() == null) { + keyPredicateNames.add(ref.getKeyPropertyName()); + keyPropertyRefs.put(ref.getKeyPropertyName(), 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() { + return entityBaseType; + } + + @Override + public List getKeyPredicateNames() { + if (keyPredicateNames.isEmpty() && baseType != null) { + return entityBaseType.getKeyPredicateNames(); + } + return keyPredicateNames; + } + + @Override + public List getKeyPropertyRefs() { + if (keyPropertyRefsList == null) { + keyPropertyRefsList = new ArrayList(keyPropertyRefs.values()); + } + if (keyPropertyRefsList.isEmpty() && entityBaseType != null) { + return entityBaseType.getKeyPropertyRefs(); + } + return keyPropertyRefsList; + } + + @Override + public EdmKeyPropertyRef getKeyPropertyRef(final String keyPredicateName) { + final EdmKeyPropertyRef edmKeyPropertyRef = keyPropertyRefs.get(keyPredicateName); + if (edmKeyPropertyRef == null && entityBaseType != null) { + return entityBaseType.getKeyPropertyRef(keyPredicateName); + } + return edmKeyPropertyRef; + } + + @Override + public boolean hasStream() { + return hasStream; + } +} diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumImpl.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmEnumType.java similarity index 58% rename from odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumImpl.java rename to odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmEnumType.java index 5de9cf201..dd89349f4 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumImpl.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmEnumType.java @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -16,11 +16,14 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.olingo.odata4.server.core.edm.provider; +package org.apache.olingo.odata4.commons.core.edm; import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; import java.util.List; - +import java.util.Map; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmEnumType; import org.apache.olingo.odata4.commons.api.edm.EdmMember; import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType; @@ -28,35 +31,54 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmInt64; -import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind; -import org.apache.olingo.odata4.server.api.edm.provider.EnumType; -public class EdmEnumImpl extends EdmNamedImpl implements EdmEnumType { +public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnumType { + + private final boolean isFlags; - private final FullQualifiedName enumName; - private final EdmPrimitiveType edmPrimitiveTypeInstance; - private final EnumType enumType; private final String uriPrefix; + private final String uriSuffix; + private List memberNames; - public EdmEnumImpl(final EdmProviderImpl edm, final FullQualifiedName enumName, final EnumType enumType) { - super(edm, enumName.getName()); - this.enumName = enumName; - this.enumType = enumType; - uriPrefix = enumName.getFullQualifiedNameAsString() + '\''; - uriSuffix = "'"; - FullQualifiedName underlyingTypeName = enumType.getUnderlyingType(); - if (underlyingTypeName == null) { - edmPrimitiveTypeInstance = EdmPrimitiveTypeKind.Int32.getEdmPrimitiveTypeInstance(); - } else { - edmPrimitiveTypeInstance = - EdmPrimitiveTypeKind.valueOf(underlyingTypeName.getName()).getEdmPrimitiveTypeInstance(); - // TODO: Should we validate that the underlying type is of byte, sbyte, in16, int32 or int64? - } + private Map members; + public AbstractEdmEnumType(final Edm edm, final FullQualifiedName fqn, final boolean isFlags) { + super(edm, fqn, EdmTypeKind.ENUM); + + this.isFlags = isFlags; + this.uriPrefix = fqn.getFullQualifiedNameAsString() + '\''; + this.uriSuffix = "'"; } + protected abstract Collection getMembers(); + + @Override + public EdmMember getMember(final String name) { + if (members == null) { + members = new LinkedHashMap(); + for (final EdmMember member : getMembers()) { + members.put(member.getName(), member); + } + } + return members.get(name); + } + + @Override + public List getMemberNames() { + if (memberNames == null) { + memberNames = new ArrayList(); + for (final EdmMember member : getMembers()) { + memberNames.add(member.getName()); + } + } + return memberNames; + } + + @Override + public abstract EdmPrimitiveType getUnderlyingType(); + @Override public boolean isCompatible(final EdmPrimitiveType primitiveType) { return equals(primitiveType); @@ -64,13 +86,13 @@ public class EdmEnumImpl extends EdmNamedImpl implements EdmEnumType { @Override public Class getDefaultType() { - return edmPrimitiveTypeInstance.getDefaultType(); + return getUnderlyingType().getDefaultType(); } @Override public boolean validate(final String value, final Boolean isNullable, final Integer maxLength, - final Integer precision, final Integer scale, - final Boolean isUnicode) { + final Integer precision, final Integer scale, final Boolean isUnicode) { + try { valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, getDefaultType()); return true; @@ -79,128 +101,44 @@ public class EdmEnumImpl extends EdmNamedImpl implements EdmEnumType { } } - @Override - public T valueOfString(final String value, final Boolean isNullable, final Integer maxLength, - final Integer precision, final Integer scale, - final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { - if (value == null) { - if (isNullable != null && !isNullable) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED"); - } - return null; - } - return internalValueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType); - } - - @Override - public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength, - final Integer precision, final Integer scale, - final Boolean isUnicode) throws EdmPrimitiveTypeException { - if (value == null) { - if (isNullable != null && !isNullable) { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED"); - } - return null; - } - return internalValueToString(value, isNullable, maxLength, precision, scale, isUnicode); - } - - @Override - public String toUriLiteral(final String literal) { - return literal == null ? null : - uriPrefix.isEmpty() && uriSuffix.isEmpty() ? literal : uriPrefix + literal + uriSuffix; - } - - @Override - public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException { - if (literal == null) { - return null; - } else if (uriPrefix.isEmpty() && uriSuffix.isEmpty()) { - return literal; - } else if (literal.length() >= uriPrefix.length() + uriSuffix.length() - && literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) { - return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length()); - } else { - throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)"); - } - } - - @Override - public String getNamespace() { - return enumName.getNamespace(); - } - - @Override - public EdmTypeKind getKind() { - return EdmTypeKind.ENUM; - } - - @Override - public EdmMember getMember(final String name) { - for (EdmMember member : enumType.getMembers()) { - if (member.getName().equals(name)) { - return member; - } - } - return null; - } - - @Override - public List getMemberNames() { - if (memberNames == null) { - memberNames = new ArrayList(); - for (final EdmMember member : enumType.getMembers()) { - memberNames.add(member.getName()); - } - } - return memberNames; - } - - @Override - public EdmPrimitiveType getUnderlyingType() { - return edmPrimitiveTypeInstance; - } - - private T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { - try { - return EdmInt64.convertNumber(parseEnumValue(value), returnType); - } catch (final IllegalArgumentException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); - } catch (final ClassCastException e) { - throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); - } - } - private Long parseEnumValue(final String value) throws EdmPrimitiveTypeException { Long result = null; - for (final String memberValue : value.split(",", enumType.isFlags() ? -1 : 1)) { + for (final String memberValue : value.split(",", isFlags ? -1 : 1)) { Long memberValueLong = null; - for (final EdmMember member : enumType.getMembers()) { + for (final EdmMember member : getMembers()) { if (member.getName().equals(memberValue) || member.getValue().equals(memberValue)) { memberValueLong = Long.decode(member.getValue()); } } if (memberValueLong == null) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); } result = result == null ? memberValueLong : result | memberValueLong; } return result; } - protected String internalValueToString(final Object value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { - if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) { - return constructEnumValue(((Number) value).longValue()); - } else { + @Override + public T valueOfString(final String value, final Boolean isNullable, final Integer maxLength, + final Integer precision, final Integer scale, final Boolean isUnicode, final Class returnType) + throws EdmPrimitiveTypeException { + + if (value == null) { + if (isNullable != null && !isNullable) { + throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED"); + } + return null; + } + + try { + return EdmInt64.convertNumber(parseEnumValue(value), returnType); + } catch (final IllegalArgumentException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + } catch (final ClassCastException e) { + throw new EdmPrimitiveTypeException( + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); } } @@ -208,7 +146,7 @@ public class EdmEnumImpl extends EdmNamedImpl implements EdmEnumType { long remaining = value; StringBuilder result = new StringBuilder(); - for (final EdmMember member : enumType.getMembers()) { + for (final EdmMember member : getMembers()) { final long memberValue = Long.parseLong(member.getValue()); if ((memberValue & remaining) == memberValue) { if (result.length() > 0) { @@ -221,8 +159,47 @@ public class EdmEnumImpl extends EdmNamedImpl implements EdmEnumType { if (remaining != 0) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); } return result.toString(); } + + @Override + public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength, + final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + + if (value == null) { + if (isNullable != null && !isNullable) { + throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED"); + } + return null; + } + if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) { + return constructEnumValue(((Number) value).longValue()); + } else { + throw new EdmPrimitiveTypeException( + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + } + } + + @Override + public String toUriLiteral(final String literal) { + return literal == null ? null + : uriPrefix.isEmpty() && uriSuffix.isEmpty() ? literal : uriPrefix + literal + uriSuffix; + } + + @Override + public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException { + if (literal == null) { + return null; + } else if (uriPrefix.isEmpty() && uriSuffix.isEmpty()) { + return literal; + } else if (literal.length() >= uriPrefix.length() + uriSuffix.length() + && literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) { + return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length()); + } else { + throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)"); + } + } + } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmImpl.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmImpl.java index 29d9b0434..34eba4b57 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmImpl.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmImpl.java @@ -65,7 +65,7 @@ public abstract class AbstractEdmImpl implements Edm { private EdmServiceMetadata serviceMetadata; private Map aliasToNamespaceInfo; - + @Override public EdmEntityContainer getEntityContainer(final FullQualifiedName namespaceOrAliasFQN) { final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN); diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmKeyPropertyRef.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmKeyPropertyRef.java new file mode 100644 index 000000000..157dd73d2 --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmKeyPropertyRef.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.odata4.commons.core.edm; + +import org.apache.olingo.odata4.commons.api.edm.EdmEntityType; +import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.EdmKeyPropertyRef; +import org.apache.olingo.odata4.commons.api.edm.EdmProperty; +import org.apache.olingo.odata4.commons.api.edm.EdmStructuredType; + +public abstract class AbstractEdmKeyPropertyRef implements EdmKeyPropertyRef { + + private final EdmEntityType edmEntityType; + + private EdmProperty property; + + public AbstractEdmKeyPropertyRef(final EdmEntityType edmEntityType) { + this.edmEntityType = edmEntityType; + } + + @Override + public abstract String getKeyPropertyName(); + + @Override + public abstract String getAlias(); + + @Override + public abstract String getPath(); + + @Override + public EdmProperty getProperty() { + if (property == null) { + if (getAlias() == null) { + property = edmEntityType.getStructuralProperty(getKeyPropertyName()); + if (property == null) { + throw new EdmException("Invalid key property ref specified. Can´t find property with name: " + + getKeyPropertyName()); + } + } else { + if (getPath() == null || getPath().isEmpty()) { + throw new EdmException("Alias but no path specified for propertyRef"); + } + final String[] splitPath = getPath().split("/"); + EdmStructuredType structType = edmEntityType; + for (int i = 0; i < splitPath.length - 1; i++) { + final EdmProperty _property = structType.getStructuralProperty(splitPath[i]); + if (_property == null) { + throw new EdmException("Invalid property ref specified. Can´t find property with name: " + splitPath[i] + + " at type: " + structType.getNamespace() + "." + structType.getName()); + } + structType = (EdmStructuredType) _property.getType(); + } + property = structType.getStructuralProperty(splitPath[splitPath.length - 1]); + if (property == null) { + throw new EdmException("Invalid property ref specified. Can´t find property with name: " + + splitPath[splitPath.length - 1] + " at type: " + structType.getNamespace() + "." + + structType.getName()); + } + } + } + + return property; + } +} diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmNavigationProperty.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmNavigationProperty.java new file mode 100644 index 000000000..3140ef781 --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmNavigationProperty.java @@ -0,0 +1,76 @@ +/* + * 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.odata4.commons.core.edm; + +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityType; +import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata4.commons.api.edm.EdmStructuredType; +import org.apache.olingo.odata4.commons.api.edm.EdmType; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; + +public abstract class AbstractEdmNavigationProperty extends EdmElementImpl implements EdmNavigationProperty { + + private EdmEntityType typeImpl; + + private EdmNavigationProperty partnerNavigationProperty; + + public AbstractEdmNavigationProperty(final Edm edm, final String name) { + super(edm, name); + } + + protected abstract FullQualifiedName getTypeFQN(); + + @Override + public EdmType getType() { + if (typeImpl == null) { + typeImpl = edm.getEntityType(getTypeFQN()); + if (typeImpl == null) { + throw new EdmException("Cannot find type with name: " + getTypeFQN()); + } + } + return typeImpl; + } + + protected abstract String internatGetPartner(); + + @Override + public EdmNavigationProperty getPartner() { + if (partnerNavigationProperty == null) { + String partner = internatGetPartner(); + if (partner != null) { + EdmStructuredType type = (EdmStructuredType) getType(); + EdmNavigationProperty property = null; + final String[] split = partner.split("/"); + for (String element : split) { + property = type.getNavigationProperty(element); + if (property == null) { + throw new EdmException("Cannot find property with name: " + element + " at type " + type.getName()); + } + type = (EdmStructuredType) property.getType(); + } + partnerNavigationProperty = property; + } + } + return partnerNavigationProperty; + } + + public abstract String getReferencingPropertyName(String referencedPropertyName); +} diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmOperation.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmOperation.java new file mode 100644 index 000000000..933714f9d --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmOperation.java @@ -0,0 +1,113 @@ +/* + * 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.odata4.commons.core.edm; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmBindingTarget; +import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet; +import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.EdmOperation; +import org.apache.olingo.odata4.commons.api.edm.EdmParameter; +import org.apache.olingo.odata4.commons.api.edm.EdmReturnType; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; + +public abstract class AbstractEdmOperation extends EdmTypeImpl implements EdmOperation { + + private final Map parameters = new LinkedHashMap(); + + private String entitySetPath; + + private boolean isBound; + + private EdmReturnType returnType; + + private List parameterNames; + + protected AbstractEdmOperation(final Edm edm, final FullQualifiedName fqn, final EdmTypeKind kind) { + super(edm, fqn, kind); + } + + protected void setParameters(final List _parameters) { + for (EdmParameter parameter : _parameters) { + parameters.put(parameter.getName(), parameter); + } + } + + protected void setEntitySetPath(final String entitySetPath) { + this.entitySetPath = entitySetPath; + } + + protected void setIsBound(final boolean isBound) { + this.isBound = isBound; + } + + protected void setReturnType(final EdmReturnType returnType) { + this.returnType = returnType; + } + + @Override + public EdmParameter getParameter(final String name) { + return parameters.get(name); + } + + @Override + public List getParameterNames() { + if (parameterNames == null) { + parameterNames = new ArrayList(parameters.size()); + for (String parameterName : parameters.keySet()) { + parameterNames.add(parameterName); + } + } + return parameterNames; + } + + @Override + public EdmEntitySet getReturnedEntitySet(final EdmEntitySet bindingParameterEntitySet) { + EdmEntitySet returnedEntitySet = null; + if (bindingParameterEntitySet != null && entitySetPath != null) { + final EdmBindingTarget relatedBindingTarget = bindingParameterEntitySet. + getRelatedBindingTarget(entitySetPath); + if (relatedBindingTarget == null) { + throw new EdmException("Cannot find entity set with path: " + entitySetPath); + } + 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() { + return returnType; + } + + @Override + public boolean isBound() { + return isBound; + } + +} diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmOperationImport.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmOperationImport.java new file mode 100644 index 000000000..07bfb7c3a --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmOperationImport.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.odata4.commons.core.edm; + +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet; +import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.EdmOperationImport; +import org.apache.olingo.odata4.commons.api.edm.Target; + +public abstract class AbstractEdmOperationImport extends EdmNamedImpl implements EdmOperationImport { + + protected final EdmEntityContainer container; + + private final Target entitySet; + + private EdmEntitySet returnedEntitySet; + + public AbstractEdmOperationImport(final Edm edm, final EdmEntityContainer container, final String name, + final Target entitySet) { + + super(edm, name); + this.container = container; + this.entitySet = entitySet; + } + + @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; + } +} diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmParameter.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmParameter.java new file mode 100644 index 000000000..e4adb41ed --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmParameter.java @@ -0,0 +1,87 @@ +/* + * 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.odata4.commons.core.edm; + +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.EdmMapping; +import org.apache.olingo.odata4.commons.api.edm.EdmParameter; +import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType; +import org.apache.olingo.odata4.commons.api.edm.EdmType; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind; + +public abstract class AbstractEdmParameter extends EdmElementImpl implements EdmParameter { + + private final FullQualifiedName paramType; + + private EdmType typeImpl; + + public AbstractEdmParameter(final Edm edm, final String name, final FullQualifiedName paramType) { + super(edm, name); + this.paramType = paramType; + } + + @Override + public EdmType getType() { + if (typeImpl == null) { + if (EdmPrimitiveType.EDM_NAMESPACE.equals(paramType.getNamespace())) { + try { + typeImpl = EdmPrimitiveTypeKind.valueOf(paramType.getName()).getEdmPrimitiveTypeInstance(); + } catch (IllegalArgumentException e) { + throw new EdmException("Cannot find type with name: " + paramType, e); + } + } else { + typeImpl = edm.getComplexType(paramType); + if (typeImpl == null) { + typeImpl = edm.getEntityType(paramType); + if (typeImpl == null) { + typeImpl = edm.getEnumType(paramType); + if (typeImpl == null) { + typeImpl = edm.getTypeDefinition(paramType); + if (typeImpl == null) { + throw new EdmException("Cannot find type with name: " + paramType); + } + } + } + } + } + } + return typeImpl; + } + + @Override + public abstract boolean isCollection(); + + @Override + public abstract EdmMapping getMapping(); + + @Override + public abstract Boolean isNullable(); + + @Override + public abstract Integer getMaxLength(); + + @Override + public abstract Integer getPrecision(); + + @Override + public abstract Integer getScale(); + +} diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmProperty.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmProperty.java new file mode 100644 index 000000000..ba28f6c59 --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmProperty.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.odata4.commons.core.edm; + +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType; +import org.apache.olingo.odata4.commons.api.edm.EdmProperty; +import org.apache.olingo.odata4.commons.api.edm.EdmType; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind; + +public abstract class AbstractEdmProperty extends EdmElementImpl implements EdmProperty { + + private EdmType propertyType; + + public AbstractEdmProperty(final Edm edm, final String name) { + super(edm, name); + } + + protected abstract FullQualifiedName getTypeFQN(); + + @Override + public boolean isPrimitive() { + return EdmPrimitiveType.EDM_NAMESPACE.equals(getTypeFQN().getNamespace()); + } + + @Override + public EdmType getType() { + if (propertyType == null) { + final FullQualifiedName typeName = getTypeFQN(); + if (isPrimitive()) { + try { + propertyType = EdmPrimitiveTypeKind.valueOf(typeName.getName()).getEdmPrimitiveTypeInstance(); + } catch (IllegalArgumentException e) { + throw new EdmException("Cannot find type with name: " + typeName, e); + } + } else { + propertyType = edm.getComplexType(typeName); + if (propertyType == null) { + propertyType = edm.getEnumType(typeName); + if (propertyType == null) { + propertyType = edm.getTypeDefinition(typeName); + if (propertyType == null) { + throw new EdmException("Cannot find type with name: " + typeName); + } + } + } + } + } + + return propertyType; + } +} diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmReturnType.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmReturnType.java new file mode 100644 index 000000000..7f2fb393e --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmReturnType.java @@ -0,0 +1,85 @@ +/* + * 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.odata4.commons.core.edm; + +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType; +import org.apache.olingo.odata4.commons.api.edm.EdmReturnType; +import org.apache.olingo.odata4.commons.api.edm.EdmType; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind; + +public abstract class AbstractEdmReturnType implements EdmReturnType { + + private final Edm edm; + + private final FullQualifiedName typeName; + + private EdmType typeImpl; + + public AbstractEdmReturnType(final Edm edm, final FullQualifiedName typeName) { + this.edm = edm; + this.typeName = typeName; + } + + @Override + public EdmType getType() { + if (typeImpl == null) { + if (EdmPrimitiveType.EDM_NAMESPACE.equals(typeName.getNamespace())) { + try { + typeImpl = EdmPrimitiveTypeKind.valueOf(typeName.getName()).getEdmPrimitiveTypeInstance(); + } catch (IllegalArgumentException e) { + throw new EdmException("Cannot find type with name: " + typeName, e); + } + } else { + typeImpl = edm.getComplexType(typeName); + if (typeImpl == null) { + typeImpl = edm.getEntityType(typeName); + if (typeImpl == null) { + typeImpl = edm.getEnumType(typeName); + if (typeImpl == null) { + typeImpl = edm.getTypeDefinition(typeName); + if (typeImpl == null) { + throw new EdmException("Cant find type with name: " + typeName); + } + } + } + } + } + } + return typeImpl; + } + + @Override + public abstract Boolean isNullable(); + + @Override + public abstract Integer getMaxLength(); + + @Override + public abstract Integer getPrecision(); + + @Override + public abstract Integer getScale(); + + @Override + public abstract boolean isCollection(); + +} diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmStructuredType.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmStructuredType.java new file mode 100644 index 000000000..2a3df7cc9 --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmStructuredType.java @@ -0,0 +1,128 @@ +/* + * 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.odata4.commons.core.edm; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmElement; +import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata4.commons.api.edm.EdmProperty; +import org.apache.olingo.odata4.commons.api.edm.EdmStructuredType; +import org.apache.olingo.odata4.commons.api.edm.EdmType; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; + +public abstract class AbstractEdmStructuredType extends EdmTypeImpl implements EdmStructuredType { + + protected EdmStructuredType baseType; + + private List propertyNames; + + private List navigationPropertyNames; + + public AbstractEdmStructuredType(final Edm edm, final FullQualifiedName fqn, final EdmTypeKind kind, + final FullQualifiedName baseTypeName) { + + super(edm, fqn, kind); + } + + protected abstract EdmStructuredType buildBaseType(FullQualifiedName baseTypeName); + + protected abstract Map getProperties(); + + protected abstract Map getNavigationProperties(); + + @Override + public List getPropertyNames() { + if (propertyNames == null) { + propertyNames = new ArrayList(); + if (baseType != null) { + propertyNames.addAll(baseType.getPropertyNames()); + } + propertyNames.addAll(getProperties().keySet()); + } + return propertyNames; + } + + @Override + public List getNavigationPropertyNames() { + if (navigationPropertyNames == null) { + navigationPropertyNames = new ArrayList(); + if (baseType != null) { + navigationPropertyNames.addAll(baseType.getNavigationPropertyNames()); + } + navigationPropertyNames.addAll(getNavigationProperties().keySet()); + } + 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; + 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; + 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; + } +} diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmTypeDefinition.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmTypeDefinition.java new file mode 100644 index 000000000..6a4c03ad0 --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmTypeDefinition.java @@ -0,0 +1,107 @@ +/* + * 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.odata4.commons.core.edm; + +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType; +import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; +import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; + +public abstract class AbstractEdmTypeDefinition extends EdmNamedImpl implements EdmTypeDefinition { + + private final String namespace; + + public AbstractEdmTypeDefinition(final Edm edm, final FullQualifiedName typeDefinitionName) { + super(edm, typeDefinitionName.getName()); + this.namespace = typeDefinitionName.getNamespace(); + } + + @Override + public abstract EdmPrimitiveType getUnderlyingType(); + + @Override + public boolean isCompatible(final EdmPrimitiveType primitiveType) { + return getUnderlyingType().isCompatible(primitiveType); + } + + @Override + public Class getDefaultType() { + return getUnderlyingType().getDefaultType(); + } + + @Override + public boolean validate(final String value, final Boolean isNullable, final Integer maxLength, + final Integer precision, final Integer scale, + final Boolean isUnicode) { + + return getUnderlyingType().validate(value, isNullable, maxLength, precision, scale, isUnicode); + } + + @Override + public T valueOfString(final String value, final Boolean isNullable, final Integer maxLength, + final Integer precision, final Integer scale, + final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + + return getUnderlyingType(). + valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType); + } + + @Override + public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength, + final Integer precision, final Integer scale, + final Boolean isUnicode) throws EdmPrimitiveTypeException { + + return getUnderlyingType().valueToString(value, isNullable, maxLength, precision, scale, isUnicode); + } + + @Override + public String toUriLiteral(final String literal) { + return getUnderlyingType().toUriLiteral(literal); + } + + @Override + public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException { + return getUnderlyingType().fromUriLiteral(literal); + } + + @Override + public String getNamespace() { + return namespace; + } + + @Override + public EdmTypeKind getKind() { + return EdmTypeKind.DEFINITION; + } + + @Override + public abstract Integer getMaxLength(); + + @Override + public abstract Integer getPrecision(); + + @Override + public abstract Integer getScale(); + + @Override + public abstract Boolean isUnicode(); + +} diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmActionImportInfoImpl.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmActionImportInfoImpl.java new file mode 100644 index 000000000..4e60a7f51 --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmActionImportInfoImpl.java @@ -0,0 +1,45 @@ +/* + * 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.odata4.commons.core.edm; + +import java.net.URI; +import org.apache.olingo.odata4.commons.api.edm.EdmActionImportInfo; + +import org.apache.olingo.odata4.commons.api.edm.EdmException; + +public class EdmActionImportInfoImpl extends EdmOperationImportInfoImpl implements EdmActionImportInfo { + + private String actionImportName; + + public EdmActionImportInfoImpl(final String entityContainerName, final String actionImportName) { + super(entityContainerName); + this.actionImportName = actionImportName; + } + + @Override + public String getActionImportName() { + return actionImportName; + } + + @Override + public URI getActionImportUri() { + throw new EdmException("Not yet implemented"); + } + +} diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmElementImpl.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmElementImpl.java similarity index 85% rename from odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmElementImpl.java rename to odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmElementImpl.java index c0d5277e1..d93185361 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmElementImpl.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmElementImpl.java @@ -16,13 +16,14 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.olingo.odata4.server.core.edm.provider; +package org.apache.olingo.odata4.commons.core.edm; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmElement; public abstract class EdmElementImpl extends EdmNamedImpl implements EdmElement { - public EdmElementImpl(final EdmProviderImpl edm, final String name) { + public EdmElementImpl(final Edm edm, final String name) { super(edm, name); } } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetInfoImpl.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmEntitySetInfoImpl.java similarity index 71% rename from odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetInfoImpl.java rename to odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmEntitySetInfoImpl.java index 0d167b771..768960a85 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetInfoImpl.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmEntitySetInfoImpl.java @@ -16,33 +16,32 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.olingo.odata4.server.core.edm.provider; +package org.apache.olingo.odata4.commons.core.edm; import java.net.URI; import org.apache.olingo.odata4.commons.api.edm.EdmEntitySetInfo; import org.apache.olingo.odata4.commons.api.edm.EdmException; -import org.apache.olingo.odata4.server.api.edm.provider.EntityContainer; -import org.apache.olingo.odata4.server.api.edm.provider.EntitySet; public class EdmEntitySetInfoImpl implements EdmEntitySetInfo { - private final EntityContainer entityContainer; - private final EntitySet set; + private final String entityContainerName; - public EdmEntitySetInfoImpl(final EntityContainer entityContainer, final EntitySet set) { - this.entityContainer = entityContainer; - this.set = set; + private final String entitySetName; + + public EdmEntitySetInfoImpl(final String entityContainerName, final String entitySetName) { + this.entityContainerName = entityContainerName; + this.entitySetName = entitySetName; } @Override public String getEntityContainerName() { - return entityContainer.getName(); + return entityContainerName; } @Override public String getEntitySetName() { - return set.getName(); + return entitySetName; } @Override diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportInfoImpl.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmFunctionImportInfoImpl.java similarity index 62% rename from odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportInfoImpl.java rename to odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmFunctionImportInfoImpl.java index 025d9194b..7facfe101 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportInfoImpl.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmFunctionImportInfoImpl.java @@ -16,33 +16,25 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.olingo.odata4.server.core.edm.provider; +package org.apache.olingo.odata4.commons.core.edm; import java.net.URI; import org.apache.olingo.odata4.commons.api.edm.EdmException; import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImportInfo; -import org.apache.olingo.odata4.server.api.edm.provider.EntityContainer; -import org.apache.olingo.odata4.server.api.edm.provider.FunctionImport; -public class EdmFunctionImportInfoImpl implements EdmFunctionImportInfo { +public class EdmFunctionImportInfoImpl extends EdmOperationImportInfoImpl implements EdmFunctionImportInfo { - private EntityContainer entityContainer; - private FunctionImport functionImport; + private String functionImportName; - public EdmFunctionImportInfoImpl(final EntityContainer entityContainer, final FunctionImport functionImport) { - this.entityContainer = entityContainer; - this.functionImport = functionImport; - } - - @Override - public String getEntityContainerName() { - return entityContainer.getName(); + public EdmFunctionImportInfoImpl(final String entityContainerName, final String functionImportName) { + super(entityContainerName); + this.functionImportName = functionImportName; } @Override public String getFunctionImportName() { - return functionImport.getName(); + return functionImportName; } @Override diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmMemberImpl.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmMemberImpl.java similarity index 74% rename from odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmMemberImpl.java rename to odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmMemberImpl.java index b42e39b65..7e6c998d1 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmMemberImpl.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmMemberImpl.java @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -16,23 +16,23 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.olingo.odata4.server.core.edm.provider; +package org.apache.olingo.odata4.commons.core.edm; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmMember; -import org.apache.olingo.odata4.server.api.edm.provider.EnumMember; public class EdmMemberImpl extends EdmNamedImpl implements EdmMember { - private final EnumMember member; + private final String value; - public EdmMemberImpl(final EdmProviderImpl edm, final EnumMember member) { - super(edm, member.getName()); - this.member = member; + public EdmMemberImpl(final Edm edm, final String name, final String value) { + super(edm, name); + this.value = value; } @Override public String getValue() { - return member.getValue(); + return value; } } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNamedImpl.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmNamedImpl.java similarity index 82% rename from odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNamedImpl.java rename to odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmNamedImpl.java index 2526e073b..5f0ac2c78 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNamedImpl.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmNamedImpl.java @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -16,17 +16,18 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.olingo.odata4.server.core.edm.provider; +package org.apache.olingo.odata4.commons.core.edm; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmNamed; public abstract class EdmNamedImpl implements EdmNamed { - private String name; - protected EdmProviderImpl edm; + protected final Edm edm; - // TODO: ValidateName? - public EdmNamedImpl(final EdmProviderImpl edm, final String name) { + private final String name; + + public EdmNamedImpl(final Edm edm, final String name) { this.edm = edm; this.name = name; } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmOperationImportInfoImpl.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmOperationImportInfoImpl.java new file mode 100644 index 000000000..334669b54 --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmOperationImportInfoImpl.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.odata4.commons.core.edm; + +import org.apache.olingo.odata4.commons.api.edm.EdmOperationImportInfo; + +public abstract class EdmOperationImportInfoImpl implements EdmOperationImportInfo { + + protected String entityContainerName; + + public EdmOperationImportInfoImpl(final String entityContainerName) { + this.entityContainerName = entityContainerName; + } + + @Override + public String getEntityContainerName() { + return this.entityContainerName; + } + +} diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonInfoImpl.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmSingletonInfoImpl.java similarity index 70% rename from odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonInfoImpl.java rename to odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmSingletonInfoImpl.java index d69bc9994..6cb8a265c 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonInfoImpl.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmSingletonInfoImpl.java @@ -16,33 +16,32 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.olingo.odata4.server.core.edm.provider; +package org.apache.olingo.odata4.commons.core.edm; import java.net.URI; import org.apache.olingo.odata4.commons.api.edm.EdmException; import org.apache.olingo.odata4.commons.api.edm.EdmSingletonInfo; -import org.apache.olingo.odata4.server.api.edm.provider.EntityContainer; -import org.apache.olingo.odata4.server.api.edm.provider.Singleton; public class EdmSingletonInfoImpl implements EdmSingletonInfo { - private final EntityContainer entityContainer; - private final Singleton singleton; + private final String entityContainerName; - public EdmSingletonInfoImpl(final EntityContainer entityContainer, final Singleton singleton) { - this.entityContainer = entityContainer; - this.singleton = singleton; + private final String singletonName; + + public EdmSingletonInfoImpl(final String entityContainerName, final String singletonName) { + this.entityContainerName = entityContainerName; + this.singletonName = singletonName; } @Override public String getEntityContainerName() { - return entityContainer.getName(); + return entityContainerName; } @Override public String getSingletonName() { - return singleton.getName(); + return singletonName; } @Override diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmStructuredTypeHelper.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmStructuredTypeHelper.java new file mode 100644 index 000000000..8b732aaaf --- /dev/null +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmStructuredTypeHelper.java @@ -0,0 +1,30 @@ +/* + * 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.odata4.commons.core.edm; + +import java.util.Map; +import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata4.commons.api.edm.EdmProperty; + +public interface EdmStructuredTypeHelper { + + Map getProperties(); + + Map getNavigationProperties(); +} diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeImpl.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmTypeImpl.java similarity index 73% rename from odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeImpl.java rename to odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmTypeImpl.java index 3f232c5de..c2f635a7c 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeImpl.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmTypeImpl.java @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -16,26 +16,28 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.olingo.odata4.server.core.edm.provider; +package org.apache.olingo.odata4.commons.core.edm; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmType; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; -public abstract class EdmTypeImpl extends EdmNamedImpl implements EdmType { +public class EdmTypeImpl extends EdmNamedImpl implements EdmType { - private final EdmTypeKind kind; - private final String namespace; + protected final FullQualifiedName fqn; - public EdmTypeImpl(final EdmProviderImpl edm, final FullQualifiedName name, final EdmTypeKind kind) { - super(edm, name.getName()); - namespace = name.getNamespace(); + protected final EdmTypeKind kind; + + public EdmTypeImpl(final Edm edm, final FullQualifiedName fqn, final EdmTypeKind kind) { + super(edm, fqn.getName()); + this.fqn = fqn; this.kind = kind; } @Override public String getNamespace() { - return namespace; + return fqn.getNamespace(); } @Override diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java index 88f4379ec..2b0b08f7e 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java @@ -79,4 +79,20 @@ public enum EdmPrimitiveTypeKind { throw new RuntimeException("Wrong type:" + this); } } + + /** + * Gets EdmPrimitiveTypeKind from a full string (e.g. 'Edm.Int32'). + * + * @param value string value type. + * @return EdmPrimitiveTypeKind object. + */ + public static EdmPrimitiveTypeKind fromString(final String value) { + final String noNsValue = value.substring(4); + for (EdmPrimitiveTypeKind edmSimpleType : EdmPrimitiveTypeKind.values()) { + if (edmSimpleType.name().equals(noNsValue)) { + return edmSimpleType; + } + } + throw new IllegalArgumentException(value); + } } diff --git a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/ActionImport.java b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/ActionImport.java index c9dd8c1bc..931109472 100644 --- a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/ActionImport.java +++ b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/ActionImport.java @@ -19,6 +19,7 @@ package org.apache.olingo.odata4.server.api.edm.provider; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.api.edm.Target; public class ActionImport extends OperationImport { diff --git a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/ComplexType.java b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/ComplexType.java index 6e37a872a..4857b3713 100644 --- a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/ComplexType.java +++ b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/ComplexType.java @@ -22,7 +22,7 @@ import java.util.List; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; -public class ComplexType extends StructuralType { +public class ComplexType extends StructuredType { @Override public ComplexType setName(final String name) { diff --git a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/EntityType.java b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/EntityType.java index 2265cff3a..dec7584b8 100644 --- a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/EntityType.java +++ b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/EntityType.java @@ -22,7 +22,7 @@ import java.util.List; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; -public class EntityType extends StructuralType { +public class EntityType extends StructuredType { private List key; diff --git a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/FunctionImport.java b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/FunctionImport.java index b403bd168..6b82bbede 100644 --- a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/FunctionImport.java +++ b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/FunctionImport.java @@ -19,6 +19,7 @@ package org.apache.olingo.odata4.server.api.edm.provider; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.api.edm.Target; public class FunctionImport extends OperationImport { diff --git a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/NavigationPropertyBinding.java b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/NavigationPropertyBinding.java index 2980a20ec..0e82a3ca3 100644 --- a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/NavigationPropertyBinding.java +++ b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/NavigationPropertyBinding.java @@ -18,6 +18,8 @@ */ package org.apache.olingo.odata4.server.api.edm.provider; +import org.apache.olingo.odata4.commons.api.edm.Target; + public class NavigationPropertyBinding { private String path; diff --git a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/OperationImport.java b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/OperationImport.java index e8850dfb9..bd845bd71 100644 --- a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/OperationImport.java +++ b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/OperationImport.java @@ -18,9 +18,12 @@ */ package org.apache.olingo.odata4.server.api.edm.provider; +import org.apache.olingo.odata4.commons.api.edm.Target; + public abstract class OperationImport { protected String name; + protected Target entitySet; // Annotations? diff --git a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/StructuralType.java b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/StructuredType.java similarity index 83% rename from odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/StructuralType.java rename to odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/StructuredType.java index 1d48b3bc7..f91e55e86 100644 --- a/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/StructuralType.java +++ b/odata4-lib/odata4-server-api/src/main/java/org/apache/olingo/odata4/server/api/edm/provider/StructuredType.java @@ -22,7 +22,7 @@ import java.util.List; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; -public abstract class StructuralType { +public abstract class StructuredType { protected String name; @@ -41,7 +41,7 @@ public abstract class StructuralType { return name; } - public StructuralType setName(final String name) { + public StructuredType setName(final String name) { this.name = name; return this; } @@ -50,7 +50,7 @@ public abstract class StructuralType { return isOpenType; } - public StructuralType setOpenType(final boolean isOpenType) { + public StructuredType setOpenType(final boolean isOpenType) { this.isOpenType = isOpenType; return this; } @@ -59,7 +59,7 @@ public abstract class StructuralType { return baseType; } - public StructuralType setBaseType(final FullQualifiedName baseType) { + public StructuredType setBaseType(final FullQualifiedName baseType) { this.baseType = baseType; return this; } @@ -68,7 +68,7 @@ public abstract class StructuralType { return isAbstract; } - public StructuralType setAbstract(final boolean isAbstract) { + public StructuredType setAbstract(final boolean isAbstract) { this.isAbstract = isAbstract; return this; } @@ -77,7 +77,7 @@ public abstract class StructuralType { return properties; } - public StructuralType setProperties(final List properties) { + public StructuredType setProperties(final List properties) { this.properties = properties; return this; } @@ -86,7 +86,7 @@ public abstract class StructuralType { return navigationProperties; } - public StructuralType setNavigationProperties(final List navigationProperties) { + public StructuredType setNavigationProperties(final List navigationProperties) { this.navigationProperties = navigationProperties; return this; } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImpl.java index e66935071..6f5d6fd69 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImpl.java @@ -18,6 +18,7 @@ */ package org.apache.olingo.odata4.server.core.edm.provider; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmAction; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; @@ -25,7 +26,11 @@ import org.apache.olingo.odata4.server.api.edm.provider.Action; public class EdmActionImpl extends EdmOperationImpl implements EdmAction { - public EdmActionImpl(final EdmProviderImpl edm, final FullQualifiedName name, final Action action) { + 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); } } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImportImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImportImpl.java index 34aca6ded..691842d26 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImportImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImportImpl.java @@ -18,6 +18,7 @@ */ package org.apache.olingo.odata4.server.core.edm.provider; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmAction; import org.apache.olingo.odata4.commons.api.edm.EdmActionImport; import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; @@ -27,9 +28,10 @@ public class EdmActionImportImpl extends EdmOperationImportImpl implements EdmAc private final ActionImport actionImport; - public EdmActionImportImpl(final EdmProviderImpl edm, final String name, final EdmEntityContainer container, - final ActionImport actionImport) { - super(edm, name, container, actionImport); + public EdmActionImportImpl(final Edm edm, final EdmEntityContainer container, final String name, + final ActionImport actionImport) { + + super(edm, container, name, actionImport); this.actionImport = actionImport; } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmBindingTargetImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmBindingTargetImpl.java index cd9217071..be8b35bd5 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmBindingTargetImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmBindingTargetImpl.java @@ -18,51 +18,55 @@ */ package org.apache.olingo.odata4.server.core.edm.provider; +import java.util.Iterator; import java.util.List; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmBindingTarget; import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.odata4.commons.api.edm.EdmEntityType; import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmBindingTarget; import org.apache.olingo.odata4.server.api.edm.provider.BindingTarget; import org.apache.olingo.odata4.server.api.edm.provider.NavigationPropertyBinding; -import org.apache.olingo.odata4.server.api.edm.provider.Target; +import org.apache.olingo.odata4.commons.api.edm.Target; -public abstract class EdmBindingTargetImpl extends EdmNamedImpl implements EdmBindingTarget { +public abstract class EdmBindingTargetImpl extends AbstractEdmBindingTarget { - private BindingTarget target; - private EdmEntityContainer container; + private final BindingTarget target; - public EdmBindingTargetImpl(final EdmProviderImpl edm, final EdmEntityContainer container, - final BindingTarget target) { - super(edm, target.getName()); - this.container = container; + public EdmBindingTargetImpl(final Edm edm, final EdmEntityContainer container, final BindingTarget target) { + super(edm, container, target.getName(), target.getType()); this.target = target; } @Override public EdmBindingTarget getRelatedBindingTarget(final String path) { EdmBindingTarget bindingTarget = null; - List navigationPropertyBindings = target.getNavigationPropertyBindings(); + + final List navigationPropertyBindings = target.getNavigationPropertyBindings(); if (navigationPropertyBindings != null) { - for (NavigationPropertyBinding binding : navigationPropertyBindings) { + boolean found = false; + for (final Iterator itor = navigationPropertyBindings.iterator(); + itor.hasNext() && !found;) { + + final NavigationPropertyBinding binding = itor.next(); if (binding.getPath().equals(path)) { - Target providerTarget = binding.getTarget(); - EdmEntityContainer entityContainer = edm.getEntityContainer(providerTarget.getEntityContainer()); + final Target providerTarget = binding.getTarget(); + final EdmEntityContainer entityContainer = edm.getEntityContainer(providerTarget.getEntityContainer()); if (entityContainer == null) { throw new EdmException("Cant find entity container with name: " + providerTarget.getEntityContainer()); } - String targetName = providerTarget.getTargetName(); + final String targetName = providerTarget.getTargetName(); bindingTarget = entityContainer.getEntitySet(targetName); if (bindingTarget == null) { bindingTarget = entityContainer.getSingleton(targetName); - if (bindingTarget != null) { - break; - } else { + if (bindingTarget == null) { throw new EdmException("Cant find target with name: " + targetName); } + + found = true; } else { - break; + found = true; } } } @@ -70,19 +74,4 @@ public abstract class EdmBindingTargetImpl extends EdmNamedImpl implements EdmBi return bindingTarget; } - - @Override - public EdmEntityContainer getEntityContainer() { - return container; - } - - @Override - public EdmEntityType getEntityType() { - EdmEntityType type = edm.getEntityType(target.getType()); - if (type == null) { - throw new EdmException("Can´t find entity type : " + target.getType() + "for entity set: " + target.getName()); - } - return type; - } - } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmComplexTypeImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmComplexTypeImpl.java index 33e4a257b..e409d09e2 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmComplexTypeImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmComplexTypeImpl.java @@ -18,34 +18,41 @@ */ package org.apache.olingo.odata4.server.core.edm.provider; -import org.apache.olingo.odata4.commons.api.edm.EdmComplexType; -import org.apache.olingo.odata4.commons.api.edm.EdmException; -import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType; +import java.util.Map; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata4.commons.api.edm.EdmProperty; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; -import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmComplexType; +import org.apache.olingo.odata4.commons.core.edm.EdmStructuredTypeHelper; import org.apache.olingo.odata4.server.api.edm.provider.ComplexType; -public class EdmComplexTypeImpl extends EdmStructuralTypeImpl implements EdmComplexType { +public class EdmComplexTypeImpl extends AbstractEdmComplexType { - public EdmComplexTypeImpl(final EdmProviderImpl edm, final FullQualifiedName name, final ComplexType complexType) { - super(edm, name, complexType, EdmTypeKind.COMPLEX); + private final EdmStructuredTypeHelper helper; + + public static EdmComplexTypeImpl getInstance( + final Edm edm, final FullQualifiedName name, final ComplexType complexType) { + + final EdmComplexTypeImpl instance = new EdmComplexTypeImpl(edm, name, complexType); + instance.baseType = instance.buildBaseType(complexType.getBaseType()); + + return instance; + } + + private EdmComplexTypeImpl(final Edm edm, final FullQualifiedName name, final ComplexType complexType) { + super(edm, name, complexType.getBaseType()); + this.helper = new EdmStructuredTypeHelperImpl(edm, complexType); } @Override - public EdmComplexType getBaseType() { - return (EdmComplexType) baseType; + protected Map getProperties() { + return helper.getProperties(); } @Override - protected EdmStructuralType 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; + protected Map getNavigationProperties() { + return helper.getNavigationProperties(); } } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityContainerImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityContainerImpl.java index 2e2b8ffa1..9bc32fc09 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityContainerImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityContainerImpl.java @@ -18,17 +18,14 @@ */ package org.apache.olingo.odata4.server.core.edm.provider; -import java.util.HashMap; -import java.util.Map; - import org.apache.olingo.odata4.commons.api.ODataException; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmActionImport; -import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet; import org.apache.olingo.odata4.commons.api.edm.EdmException; import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImport; import org.apache.olingo.odata4.commons.api.edm.EdmSingleton; -import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmEntityContainer; import org.apache.olingo.odata4.server.api.edm.provider.ActionImport; import org.apache.olingo.odata4.server.api.edm.provider.EdmProvider; import org.apache.olingo.odata4.server.api.edm.provider.EntityContainerInfo; @@ -36,100 +33,78 @@ import org.apache.olingo.odata4.server.api.edm.provider.EntitySet; import org.apache.olingo.odata4.server.api.edm.provider.FunctionImport; import org.apache.olingo.odata4.server.api.edm.provider.Singleton; -public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityContainer { +public class EdmEntityContainerImpl extends AbstractEdmEntityContainer { - private final FullQualifiedName entityContainerName; private final EdmProvider provider; - private final Map singletons = new HashMap(); - private final Map entitySets = new HashMap(); - private final Map actionImports = new HashMap(); - private final Map functionImports = new HashMap(); - public EdmEntityContainerImpl(final EdmProviderImpl edm, final EdmProvider provider, - final EntityContainerInfo entityContainerInfo) { - super(edm, entityContainerInfo.getContainerName().getName()); + public EdmEntityContainerImpl(final Edm edm, final EdmProvider provider, + final EntityContainerInfo entityContainerInfo) { + + super(edm, entityContainerInfo.getContainerName()); this.provider = provider; - entityContainerName = entityContainerInfo.getContainerName(); } @Override - public String getNamespace() { - return entityContainerName.getNamespace(); - } + protected EdmSingleton createSingleton(final String singletonName) { + EdmSingleton singleton = null; - @Override - public EdmSingleton getSingleton(final String singletonName) { - EdmSingleton singleton = singletons.get(singletonName); - if (singleton == null) { - try { - Singleton providerSingleton = provider.getSingleton(entityContainerName, singletonName); - if (providerSingleton != null) { - singleton = new EdmSingletonImpl(edm, this, providerSingleton); - if (singleton != null) { - singletons.put(singletonName, singleton); - } - } - } catch (ODataException e) { - throw new EdmException(e); + 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; } @Override - public EdmEntitySet getEntitySet(final String entitySetName) { - EdmEntitySet entitySet = entitySets.get(entitySetName); - if (entitySet == null) { - try { - EntitySet providerEntitySet = provider.getEntitySet(entityContainerName, entitySetName); - if (providerEntitySet != null) { - entitySet = new EdmEntitySetImpl(edm, this, providerEntitySet); - if (entitySet != null) { - entitySets.put(entitySetName, entitySet); - } - } - } catch (ODataException e) { - throw new EdmException(e); + 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; } @Override - public EdmActionImport getActionImport(final String actionImportName) { - EdmActionImport actionImport = actionImports.get(actionImportName); - if (actionImport == null) { - try { - ActionImport providerImport = provider.getActionImport(entityContainerName, actionImportName); - if (providerImport != null) { - actionImport = new EdmActionImportImpl(edm, actionImportName, this, providerImport); - if (actionImport != null) { - actionImports.put(actionImportName, actionImport); - } - } - } catch (ODataException e) { - throw new EdmException(e); + 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, actionImportName, providerImport); } + } catch (ODataException e) { + throw new EdmException(e); } + return actionImport; } @Override - public EdmFunctionImport getFunctionImport(final String functionImportName) { - EdmFunctionImport functionImport = functionImports.get(functionImportName); - if (functionImport == null) { - try { - FunctionImport providerImport = provider.getFunctionImport(entityContainerName, functionImportName); - if (providerImport != null) { - functionImport = new EdmFunctionImportImpl(edm, functionImportName, this, providerImport); - if (functionImport != null) { - functionImports.put(functionImportName, functionImport); - } - } - } catch (ODataException e) { - throw new EdmException(e); + 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, functionImportName, providerImport); } + } catch (ODataException e) { + throw new EdmException(e); } + return functionImport; } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetImpl.java index d724a5d21..7305b1e5e 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetImpl.java @@ -18,13 +18,14 @@ */ package org.apache.olingo.odata4.server.core.edm.provider; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet; import org.apache.olingo.odata4.server.api.edm.provider.EntitySet; public class EdmEntitySetImpl extends EdmBindingTargetImpl implements EdmEntitySet { - public EdmEntitySetImpl(final EdmProviderImpl edm, final EdmEntityContainer container, final EntitySet entitySet) { + public EdmEntitySetImpl(final Edm edm, final EdmEntityContainer container, final EntitySet entitySet) { super(edm, container, entitySet); } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityTypeImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityTypeImpl.java index 557dd0134..41b8ea9b0 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityTypeImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityTypeImpl.java @@ -19,101 +19,69 @@ package org.apache.olingo.odata4.server.core.edm.provider; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; +import java.util.Map; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmEntityType; import org.apache.olingo.odata4.commons.api.edm.EdmException; import org.apache.olingo.odata4.commons.api.edm.EdmKeyPropertyRef; -import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType; +import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata4.commons.api.edm.EdmProperty; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; -import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmEntityType; +import org.apache.olingo.odata4.commons.core.edm.EdmStructuredTypeHelper; import org.apache.olingo.odata4.server.api.edm.provider.EntityType; import org.apache.olingo.odata4.server.api.edm.provider.PropertyRef; -public class EdmEntityTypeImpl extends EdmStructuralTypeImpl implements EdmEntityType { +public class EdmEntityTypeImpl extends AbstractEdmEntityType { - private EntityType entityType; - private final List keyPredicateNames = new ArrayList(); - private final HashMap keyPropertyRefs = new HashMap(); - private final EdmEntityType entityBaseType; - private ArrayList keyPropertyRefsList; + private final EdmStructuredTypeHelper helper; - public EdmEntityTypeImpl(final EdmProviderImpl edm, final FullQualifiedName name, final EntityType entityType) { - super(edm, name, entityType, EdmTypeKind.ENTITY); - this.entityType = entityType; - if (baseType == null) { - entityBaseType = null; - List key = entityType.getKey(); + private final EntityType entityType; + + public static EdmEntityTypeImpl getInstance(final Edm edm, final FullQualifiedName name, + final EntityType entityType) { + + final EdmEntityTypeImpl instance = new EdmEntityTypeImpl(edm, name, entityType); + instance.baseType = instance.buildBaseType(entityType.getBaseType()); + + if (instance.baseType == null) { + instance.entityBaseType = null; + + final List key = entityType.getKey(); if (key == null && !entityType.isAbstract()) { throw new EdmException("Non-Abstract entity types must define a key."); } if (key != null) { + final List edmKey = new ArrayList(); for (PropertyRef ref : key) { - EdmKeyPropertyRef edmKeyRef = new EdmKeyPropertyRefImpl(this, ref); - if (ref.getAlias() != null) { - keyPredicateNames.add(ref.getAlias()); - keyPropertyRefs.put(ref.getAlias(), edmKeyRef); - } else { - keyPredicateNames.add(ref.getPropertyName()); - keyPropertyRefs.put(ref.getPropertyName(), edmKeyRef); - } + edmKey.add(new EdmKeyPropertyRefImpl(instance, ref)); } + instance.setEdmKeyPropertyRef(edmKey); } } else { - entityBaseType = (EdmEntityType) baseType; + instance.entityBaseType = (EdmEntityType) instance.baseType; } + return instance; + } + + private EdmEntityTypeImpl(final Edm edm, final FullQualifiedName name, final EntityType entityType) { + super(edm, name, entityType.getBaseType(), entityType.hasStream()); + + this.helper = new EdmStructuredTypeHelperImpl(edm, entityType); + this.entityType = entityType; } @Override - public boolean hasStream() { - return entityType.hasStream(); + protected Map getProperties() { + return helper.getProperties(); } @Override - public EdmEntityType getBaseType() { - return entityBaseType; - } - - @Override - public List getKeyPredicateNames() { - if (keyPredicateNames.isEmpty() && baseType != null) { - return entityBaseType.getKeyPredicateNames(); - } - return keyPredicateNames; - } - - @Override - public List getKeyPropertyRefs() { - if (keyPropertyRefsList == null) { - keyPropertyRefsList = new ArrayList(keyPropertyRefs.values()); - } - if (keyPropertyRefsList.isEmpty() && entityBaseType != null) { - return entityBaseType.getKeyPropertyRefs(); - } - return keyPropertyRefsList; - } - - @Override - public EdmKeyPropertyRef getKeyPropertyRef(final String keyPredicateName) { - EdmKeyPropertyRef edmKeyPropertyRef = keyPropertyRefs.get(keyPredicateName); - if (edmKeyPropertyRef == null && entityBaseType != null) { - return entityBaseType.getKeyPropertyRef(keyPredicateName); - } - return edmKeyPropertyRef; - } - - @Override - protected EdmStructuralType 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; + protected Map getNavigationProperties() { + return helper.getNavigationProperties(); } } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumTypeImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumTypeImpl.java new file mode 100644 index 000000000..4e88b4971 --- /dev/null +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumTypeImpl.java @@ -0,0 +1,61 @@ +/* + * 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.odata4.server.core.edm.provider; + +import java.util.List; + +import org.apache.olingo.odata4.commons.api.edm.EdmEnumType; +import org.apache.olingo.odata4.commons.api.edm.EdmMember; +import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmEnumType; +import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind; +import org.apache.olingo.odata4.server.api.edm.provider.EnumType; + +public class EdmEnumTypeImpl extends AbstractEdmEnumType implements EdmEnumType { + + private final EdmPrimitiveType underlyingType; + + private final EnumType enumType; + + public EdmEnumTypeImpl(final EdmProviderImpl edm, final FullQualifiedName enumName, final EnumType enumType) { + super(edm, enumName, enumType.isFlags()); + + if (enumType.getUnderlyingType() == null) { + this.underlyingType = EdmPrimitiveTypeKind.Int32.getEdmPrimitiveTypeInstance(); + } else { + this.underlyingType = EdmPrimitiveTypeKind.valueOf( + enumType.getUnderlyingType().getName()).getEdmPrimitiveTypeInstance(); + // TODO: Should we validate that the underlying type is of byte, sbyte, in16, int32 or int64? + } + + this.enumType = enumType; + } + + @Override + public EdmPrimitiveType getUnderlyingType() { + return underlyingType; + } + + @Override + protected List getMembers() { + return enumType.getMembers(); + } + +} diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImpl.java index 61f513a48..f2e3cf2fb 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImpl.java @@ -18,6 +18,7 @@ */ package org.apache.olingo.odata4.server.core.edm.provider; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmException; import org.apache.olingo.odata4.commons.api.edm.EdmFunction; import org.apache.olingo.odata4.commons.api.edm.EdmReturnType; @@ -27,9 +28,13 @@ import org.apache.olingo.odata4.server.api.edm.provider.Function; public class EdmFunctionImpl extends EdmOperationImpl implements EdmFunction { - private Function function; + private final Function function; - public EdmFunctionImpl(final EdmProviderImpl edm, final FullQualifiedName name, final Function function) { + public static EdmFunctionImpl getInstance(final Edm edm, final FullQualifiedName name, final Function function) { + return EdmOperationImpl.getInstance(new EdmFunctionImpl(edm, name, function)); + } + + private EdmFunctionImpl(final Edm edm, final FullQualifiedName name, final Function function) { super(edm, name, function, EdmTypeKind.FUNCTION); this.function = function; } @@ -41,7 +46,7 @@ public class EdmFunctionImpl extends EdmOperationImpl implements EdmFunction { @Override public EdmReturnType getReturnType() { - EdmReturnType returnType = super.getReturnType(); + final EdmReturnType returnType = super.getReturnType(); if (returnType == null) { throw new EdmException("ReturnType for a function must not be null"); } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportImpl.java index 487ae51e8..f4e06f133 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportImpl.java @@ -19,6 +19,7 @@ package org.apache.olingo.odata4.server.core.edm.provider; import java.util.List; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; import org.apache.olingo.odata4.commons.api.edm.EdmFunction; @@ -29,9 +30,10 @@ public class EdmFunctionImportImpl extends EdmOperationImportImpl implements Edm private final FunctionImport functionImport; - public EdmFunctionImportImpl(final EdmProviderImpl edm, final String name, final EdmEntityContainer container, - final FunctionImport functionImport) { - super(edm, name, container, functionImport); + public EdmFunctionImportImpl(final Edm edm, final EdmEntityContainer container, final String name, + final FunctionImport functionImport) { + + super(edm, container, name, functionImport); this.functionImport = functionImport; } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmKeyPropertyRefImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmKeyPropertyRefImpl.java index 6bff7e3a8..06351ac35 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmKeyPropertyRefImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmKeyPropertyRefImpl.java @@ -19,20 +19,15 @@ package org.apache.olingo.odata4.server.core.edm.provider; import org.apache.olingo.odata4.commons.api.edm.EdmEntityType; -import org.apache.olingo.odata4.commons.api.edm.EdmException; -import org.apache.olingo.odata4.commons.api.edm.EdmKeyPropertyRef; -import org.apache.olingo.odata4.commons.api.edm.EdmProperty; -import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmKeyPropertyRef; import org.apache.olingo.odata4.server.api.edm.provider.PropertyRef; -public class EdmKeyPropertyRefImpl implements EdmKeyPropertyRef { +public class EdmKeyPropertyRefImpl extends AbstractEdmKeyPropertyRef { - private PropertyRef ref; - private EdmEntityType edmEntityType; - private EdmProperty property; + private final PropertyRef ref; public EdmKeyPropertyRefImpl(final EdmEntityType edmEntityType, final PropertyRef ref) { - this.edmEntityType = edmEntityType; + super(edmEntityType); this.ref = ref; } @@ -50,40 +45,4 @@ public class EdmKeyPropertyRefImpl implements EdmKeyPropertyRef { public String getPath() { return ref.getPath(); } - - @Override - public EdmProperty getProperty() { - if (property == null) { - if (ref.getAlias() == null) { - property = (EdmProperty) edmEntityType.getProperty(ref.getPropertyName()); - if (property == null) { - throw new EdmException("Invalid key property ref specified. Can´t find property with name: " - + ref.getPropertyName()); - } - } else { - if (ref.getPath() == null || ref.getPath().isEmpty()) { - throw new EdmException("Alias but no path specified for propertyRef"); - } - String[] splitPath = ref.getPath().split("/"); - EdmStructuralType structType = edmEntityType; - for (int i = 0; i < splitPath.length - 1; i++) { - EdmProperty property = (EdmProperty) structType.getProperty(splitPath[i]); - if (property == null) { - throw new EdmException("Invalid property ref specified. Can´t find property with name: " - + splitPath[i] + " at type: " + structType.getNamespace() + "." + structType.getName()); - } - structType = (EdmStructuralType) property.getType(); - } - property = (EdmProperty) structType.getProperty(splitPath[splitPath.length - 1]); - if (property == null) { - throw new EdmException("Invalid property ref specified. Can´t find property with name: " - + splitPath[splitPath.length - 1] + " at type: " + structType.getNamespace() + "." - + structType.getName()); - } - } - } - - return property; - } - } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNavigationPropertyImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNavigationPropertyImpl.java index c452d8ede..339946775 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNavigationPropertyImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNavigationPropertyImpl.java @@ -20,35 +20,24 @@ package org.apache.olingo.odata4.server.core.edm.provider; import java.util.List; -import org.apache.olingo.odata4.commons.api.edm.EdmElement; -import org.apache.olingo.odata4.commons.api.edm.EdmEntityType; -import org.apache.olingo.odata4.commons.api.edm.EdmException; -import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty; -import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType; -import org.apache.olingo.odata4.commons.api.edm.EdmType; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmNavigationProperty; import org.apache.olingo.odata4.server.api.edm.provider.NavigationProperty; import org.apache.olingo.odata4.server.api.edm.provider.ReferentialConstraint; -public class EdmNavigationPropertyImpl extends EdmElementImpl implements EdmNavigationProperty { +public class EdmNavigationPropertyImpl extends AbstractEdmNavigationProperty { private final NavigationProperty navigationProperty; - private EdmEntityType typeImpl; - private EdmNavigationProperty partnerNavigationProperty; - public EdmNavigationPropertyImpl(final EdmProviderImpl edm, final NavigationProperty navigationProperty) { + public EdmNavigationPropertyImpl(final Edm edm, final NavigationProperty navigationProperty) { super(edm, navigationProperty.getName()); this.navigationProperty = navigationProperty; } @Override - public EdmType getType() { - if (typeImpl == null) { - typeImpl = edm.getEntityType(navigationProperty.getType()); - if (typeImpl == null) { - throw new EdmException("Cannot find type with name: " + navigationProperty.getType()); - } - } - return typeImpl; + protected FullQualifiedName getTypeFQN() { + return navigationProperty.getType(); } @Override @@ -62,29 +51,13 @@ public class EdmNavigationPropertyImpl extends EdmElementImpl implements EdmNavi } @Override - public EdmNavigationProperty getPartner() { - if (partnerNavigationProperty == null) { - String partner = navigationProperty.getPartner(); - if (partner != null) { - EdmStructuralType type = (EdmStructuralType) getType(); - EdmElement property = null; - String[] split = partner.split("/"); - for (String element : split) { - property = type.getProperty(element); - if (property == null) { - throw new EdmException("Cannot find property with name: " + element + " at type " + type.getName()); - } - type = (EdmStructuralType) property.getType(); - } - partnerNavigationProperty = (EdmNavigationProperty) property; - } - } - return partnerNavigationProperty; + protected String internatGetPartner() { + return navigationProperty.getPartner(); } @Override public String getReferencingPropertyName(final String referencedPropertyName) { - List referentialConstraints = navigationProperty.getReferentialConstraints(); + final List referentialConstraints = navigationProperty.getReferentialConstraints(); if (referentialConstraints != null) { for (ReferentialConstraint constraint : referentialConstraints) { if (constraint.getReferencedProperty().equals(referencedPropertyName)) { diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImpl.java index 48066826a..73f440b33 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImpl.java @@ -19,92 +19,49 @@ package org.apache.olingo.odata4.server.core.edm.provider; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import org.apache.olingo.odata4.commons.api.edm.EdmBindingTarget; -import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet; -import org.apache.olingo.odata4.commons.api.edm.EdmException; -import org.apache.olingo.odata4.commons.api.edm.EdmOperation; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmParameter; -import org.apache.olingo.odata4.commons.api.edm.EdmReturnType; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmOperation; import org.apache.olingo.odata4.server.api.edm.provider.EntitySetPath; import org.apache.olingo.odata4.server.api.edm.provider.Operation; import org.apache.olingo.odata4.server.api.edm.provider.Parameter; -public class EdmOperationImpl extends EdmTypeImpl implements EdmOperation { +public abstract class EdmOperationImpl extends AbstractEdmOperation { - private final Map parameters = new HashMap(); - private final Operation operation; - private EdmReturnType returnType; - private List parameterNames; + protected final Operation operation; + + protected static T getInstance(final T instance) { + final List providerParameters = instance.operation.getParameters(); + if (providerParameters != null) { + final List _parameters = new ArrayList(providerParameters.size()); + for (Parameter parameter : providerParameters) { + _parameters.add(new EdmParameterImpl(instance.edm, parameter)); + } + instance.setParameters(_parameters); + } + + final EntitySetPath entitySetPath = instance.operation.getEntitySetPath(); + if (entitySetPath != null && entitySetPath.getPath() != null) { + instance.setEntitySetPath(entitySetPath.getPath()); + } + + instance.setIsBound(instance.operation.isBound()); + + if (instance.operation.getReturnType() != null) { + instance.setReturnType(new EdmReturnTypeImpl(instance.edm, instance.operation.getReturnType())); + } + + return instance; + } + + protected EdmOperationImpl(final Edm edm, final FullQualifiedName name, final Operation operation, + final EdmTypeKind kind) { - public EdmOperationImpl(final EdmProviderImpl edm, final FullQualifiedName name, final Operation operation, - final EdmTypeKind kind) { super(edm, name, kind); this.operation = operation; - List providerParameters = operation.getParameters(); - if (providerParameters != null) { - for (Parameter parameter : providerParameters) { - parameters.put(parameter.getName(), new EdmParameterImpl(edm, parameter)); - } - } } - - @Override - public EdmParameter getParameter(final String name) { - return parameters.get(name); - } - - @Override - public List getParameterNames() { - if (parameterNames == null) { - parameterNames = new ArrayList(); - List providerParameters = operation.getParameters(); - if (providerParameters != null) { - for (Parameter parameter : providerParameters) { - parameterNames.add(parameter.getName()); - } - } - } - return parameterNames; - } - - @Override - public EdmEntitySet getReturnedEntitySet(final EdmEntitySet bindingParameterEntitySet) { - EntitySetPath entitySetPath = operation.getEntitySetPath(); - EdmEntitySet returnedEntitySet = null; - if (bindingParameterEntitySet != null && entitySetPath != null && entitySetPath.getBindingParameter() != null - && entitySetPath.getPath() != null) { - EdmBindingTarget relatedBindingTarget = - bindingParameterEntitySet.getRelatedBindingTarget(entitySetPath.getPath()); - if (relatedBindingTarget == null) { - throw new EdmException("Cannot find entity set with path: " + entitySetPath.getPath()); - } - 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(); - } - } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImportImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImportImpl.java index 41159cee2..51ea5f7ad 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImportImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmOperationImportImpl.java @@ -18,45 +18,16 @@ */ package org.apache.olingo.odata4.server.core.edm.provider; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet; -import org.apache.olingo.odata4.commons.api.edm.EdmException; -import org.apache.olingo.odata4.commons.api.edm.EdmOperationImport; import org.apache.olingo.odata4.server.api.edm.provider.OperationImport; -import org.apache.olingo.odata4.server.api.edm.provider.Target; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmOperationImport; -public abstract class EdmOperationImportImpl extends EdmNamedImpl implements EdmOperationImport { +public abstract class EdmOperationImportImpl extends AbstractEdmOperationImport { - private final OperationImport operationImport; - private final EdmEntityContainer container; - private EdmEntitySet returnedEntitySet; + public EdmOperationImportImpl(final Edm edm, final EdmEntityContainer container, final String name, + final OperationImport operationImport) { - public EdmOperationImportImpl(final EdmProviderImpl edm, final String name, final EdmEntityContainer container, - final OperationImport operationImport) { - super(edm, name); - this.container = container; - this.operationImport = operationImport; + super(edm, container, name, operationImport.getEntitySet()); } - - @Override - public EdmEntitySet getReturnedEntitySet() { - Target target = operationImport.getEntitySet(); - if (target != null && returnedEntitySet == null) { - EdmEntityContainer entityContainer = edm.getEntityContainer(target.getEntityContainer()); - if (entityContainer == null) { - throw new EdmException("Can´t find entity container with name: " + target.getEntityContainer()); - } - returnedEntitySet = entityContainer.getEntitySet(target.getTargetName()); - if (returnedEntitySet == null) { - throw new EdmException("Can´t find entity set with name: " + target.getTargetName()); - } - } - return returnedEntitySet; - } - - @Override - public EdmEntityContainer getEntityContainer() { - return container; - } - } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmParameterImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmParameterImpl.java index 3ae417b24..47679f6ef 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmParameterImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmParameterImpl.java @@ -18,54 +18,20 @@ */ package org.apache.olingo.odata4.server.core.edm.provider; -import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmMapping; -import org.apache.olingo.odata4.commons.api.edm.EdmParameter; -import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType; -import org.apache.olingo.odata4.commons.api.edm.EdmType; -import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; -import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmParameter; import org.apache.olingo.odata4.server.api.edm.provider.Parameter; -public class EdmParameterImpl extends EdmElementImpl implements EdmParameter { +public class EdmParameterImpl extends AbstractEdmParameter { private final Parameter parameter; - private EdmType typeImpl; - public EdmParameterImpl(final EdmProviderImpl edm, final Parameter parameter) { - super(edm, parameter.getName()); + public EdmParameterImpl(final Edm edm, final Parameter parameter) { + super(edm, parameter.getName(), parameter.getType()); this.parameter = parameter; } - @Override - public EdmType getType() { - if (typeImpl == null) { - FullQualifiedName typeName = parameter.getType(); - if (EdmPrimitiveType.EDM_NAMESPACE.equals(typeName.getNamespace())) { - try { - typeImpl = EdmPrimitiveTypeKind.valueOf(typeName.getName()).getEdmPrimitiveTypeInstance(); - } catch (IllegalArgumentException e) { - throw new EdmException("Cannot find type with name: " + typeName, e); - } - } else { - typeImpl = edm.getComplexType(typeName); - if (typeImpl == null) { - typeImpl = edm.getEntityType(typeName); - if (typeImpl == null) { - typeImpl = edm.getEnumType(typeName); - if (typeImpl == null) { - typeImpl = edm.getTypeDefinition(typeName); - if (typeImpl == null) { - throw new EdmException("Cannot find type with name: " + typeName); - } - } - } - } - } - } - return typeImpl; - } - @Override public boolean isCollection() { return parameter.isCollection(); diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmPropertyImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmPropertyImpl.java index 4882a298f..46381fd73 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmPropertyImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmPropertyImpl.java @@ -18,52 +18,25 @@ */ package org.apache.olingo.odata4.server.core.edm.provider; -import org.apache.olingo.odata4.commons.api.edm.EdmException; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmMapping; -import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.odata4.commons.api.edm.EdmProperty; -import org.apache.olingo.odata4.commons.api.edm.EdmType; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; -import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmProperty; import org.apache.olingo.odata4.server.api.edm.provider.Property; -public class EdmPropertyImpl extends EdmElementImpl implements EdmProperty { +public class EdmPropertyImpl extends AbstractEdmProperty implements EdmProperty { private final Property property; - private final boolean isPrimitive; - private EdmType propertyType; - public EdmPropertyImpl(final EdmProviderImpl edm, final Property property) { + public EdmPropertyImpl(final Edm edm, final Property property) { super(edm, property.getName()); this.property = property; - isPrimitive = EdmPrimitiveType.EDM_NAMESPACE.equals(property.getType().getNamespace()); } @Override - public EdmType getType() { - if (propertyType == null) { - FullQualifiedName typeName = property.getType(); - if (isPrimitive) { - try { - propertyType = EdmPrimitiveTypeKind.valueOf(typeName.getName()).getEdmPrimitiveTypeInstance(); - } catch (IllegalArgumentException e) { - throw new EdmException("Cannot find type with name: " + typeName, e); - } - } else { - propertyType = edm.getComplexType(typeName); - if (propertyType == null) { - propertyType = edm.getEnumType(typeName); - if (propertyType == null) { - propertyType = edm.getTypeDefinition(typeName); - if (propertyType == null) { - throw new EdmException("Cannot find type with name: " + typeName); - } - } - } - } - } - - return propertyType; + protected FullQualifiedName getTypeFQN() { + return property.getType(); } @Override @@ -81,11 +54,6 @@ public class EdmPropertyImpl extends EdmElementImpl implements EdmProperty { return property.getMimeType(); } - @Override - public boolean isPrimitive() { - return isPrimitive; - } - @Override public Boolean isNullable() { return property.getNullable(); diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmProviderImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmProviderImpl.java index 49a14fc5c..f2ded8cbe 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmProviderImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmProviderImpl.java @@ -50,7 +50,9 @@ import org.apache.olingo.odata4.server.api.edm.provider.TypeDefinition; public class EdmProviderImpl extends AbstractEdmImpl { private final EdmProvider provider; + private final Map> actionsMap = new HashMap>(); + private final Map> functionsMap = new HashMap>(); public EdmProviderImpl(final EdmProvider provider) { @@ -76,7 +78,7 @@ public class EdmProviderImpl extends AbstractEdmImpl { try { EnumType enumType = provider.getEnumType(enumName); if (enumType != null) { - return new EdmEnumImpl(this, enumName, enumType); + return new EdmEnumTypeImpl(this, enumName, enumType); } return null; } catch (ODataException e) { @@ -102,7 +104,7 @@ public class EdmProviderImpl extends AbstractEdmImpl { try { EntityType entityType = provider.getEntityType(entityTypeName); if (entityType != null) { - return new EdmEntityTypeImpl(this, entityTypeName, entityType); + return EdmEntityTypeImpl.getInstance(this, entityTypeName, entityType); } return null; } catch (ODataException e) { @@ -113,9 +115,9 @@ public class EdmProviderImpl extends AbstractEdmImpl { @Override public EdmComplexType createComplexType(final FullQualifiedName complexTypeName) { try { - ComplexType complexType = provider.getComplexType(complexTypeName); + final ComplexType complexType = provider.getComplexType(complexTypeName); if (complexType != null) { - return new EdmComplexTypeImpl(this, complexTypeName, complexType); + return EdmComplexTypeImpl.getInstance(this, complexTypeName, complexType); } return null; } catch (ODataException e) { @@ -125,32 +127,32 @@ public class EdmProviderImpl extends AbstractEdmImpl { @Override public EdmAction createBoundAction(final FullQualifiedName actionName, - final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) { + final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) { + try { List actions = actionsMap.get(actionName); if (actions == null) { actions = provider.getActions(actionName); - if (actions != null) { - actionsMap.put(actionName, actions); - } else { + if (actions == null) { return null; + } else { + actionsMap.put(actionName, actions); } } - EdmActionImpl actionImpl = null; // Search for bound action where binding parameter matches for (Action action : actions) { - if (action.isBound() == true) { - List parameters = action.getParameters(); - Parameter parameter = parameters.get(0); + if (action.isBound()) { + final List parameters = action.getParameters(); + final Parameter parameter = parameters.get(0); if (bindingParameterTypeName.equals(parameter.getType()) - && isBindingParameterCollection.booleanValue() == parameter.isCollection()) { - actionImpl = new EdmActionImpl(this, actionName, action); - break; + && isBindingParameterCollection.booleanValue() == parameter.isCollection()) { + + return EdmActionImpl.getInstance(this, actionName, action); } } } - return actionImpl; + return null; } catch (ODataException e) { throw new EdmException(e); } @@ -158,46 +160,43 @@ public class EdmProviderImpl extends AbstractEdmImpl { @Override public EdmFunction createBoundFunction(final FullQualifiedName functionName, - final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection, - final List parameterNames) { + final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection, + final List parameterNames) { + try { List functions = functionsMap.get(functionName); if (functions == null) { functions = provider.getFunctions(functionName); - if (functions != null) { - functionsMap.put(functionName, functions); - } else { + if (functions == null) { return null; + } else { + functionsMap.put(functionName, functions); } } - List parameterNamesCopy = parameterNames; - if (parameterNamesCopy == null) { - parameterNamesCopy = Collections.emptyList(); - } - EdmFunctionImpl functionImpl = null; + final List parameterNamesCopy = parameterNames == null? Collections.emptyList(): parameterNames; for (Function function : functions) { - if (function.isBound() == true) { + if (function.isBound()) { List providerParameters = function.getParameters(); if (providerParameters == null || providerParameters.size() == 0) { throw new EdmException("No parameter specified for bound function: " + functionName); } - Parameter bindingParameter = providerParameters.get(0); + final Parameter bindingParameter = providerParameters.get(0); if (bindingParameterTypeName.equals(bindingParameter.getType()) - && isBindingParameterCollection.booleanValue() == bindingParameter.isCollection()) { + && isBindingParameterCollection.booleanValue() == bindingParameter.isCollection()) { + if (parameterNamesCopy.size() == providerParameters.size() - 1) { - List providerParameterNames = new ArrayList(); + final List providerParameterNames = new ArrayList(); for (int i = 1; i < providerParameters.size(); i++) { providerParameterNames.add(providerParameters.get(i).getName()); } if (parameterNamesCopy.containsAll(providerParameterNames)) { - functionImpl = new EdmFunctionImpl(this, functionName, function); - break; + return EdmFunctionImpl.getInstance(this, functionName, function); } } } } } - return functionImpl; + return null; } catch (ODataException e) { throw new EdmException(e); } @@ -210,9 +209,9 @@ public class EdmProviderImpl extends AbstractEdmImpl { @Override protected Map createAliasToNamespaceInfo() { - Map aliasToNamespaceInfos = new HashMap(); + final Map aliasToNamespaceInfos = new HashMap(); try { - List aliasInfos = provider.getAliasInfos(); + final List aliasInfos = provider.getAliasInfos(); if (aliasInfos != null) { for (AliasInfo info : aliasInfos) { aliasToNamespaceInfos.put(info.getAlias(), info.getNamespace()); @@ -230,21 +229,19 @@ public class EdmProviderImpl extends AbstractEdmImpl { List actions = actionsMap.get(actionName); if (actions == null) { actions = provider.getActions(actionName); - if (actions != null) { - actionsMap.put(actionName, actions); - } else { + if (actions == null) { return null; + } else { + actionsMap.put(actionName, actions); } } - EdmActionImpl actionImpl = null; // Search for first unbound action for (Action action : actions) { - if (action.isBound() == false) { - actionImpl = new EdmActionImpl(this, actionName, action); - break; + if (!action.isBound()) { + return EdmActionImpl.getInstance(this, actionName, action); } } - return actionImpl; + return null; } catch (ODataException e) { throw new EdmException(e); } @@ -262,13 +259,9 @@ public class EdmProviderImpl extends AbstractEdmImpl { return null; } } - List parameterNamesCopy = parameterNames; - if (parameterNamesCopy == null) { - parameterNamesCopy = Collections.emptyList(); - } - EdmFunctionImpl functionImpl = null; + final List parameterNamesCopy = parameterNames == null? Collections.emptyList(): parameterNames; for (Function function : functions) { - if (function.isBound() == false) { + if (!function.isBound()) { List providerParameters = function.getParameters(); if (providerParameters == null) { providerParameters = Collections.emptyList(); @@ -280,13 +273,12 @@ public class EdmProviderImpl extends AbstractEdmImpl { } if (parameterNamesCopy.containsAll(functionParameterNames)) { - functionImpl = new EdmFunctionImpl(this, functionName, function); - break; + return EdmFunctionImpl.getInstance(this, functionName, function); } } } } - return functionImpl; + return null; } catch (ODataException e) { throw new EdmException(e); } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmReturnTypeImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmReturnTypeImpl.java index e94d8a0b6..19700af04 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmReturnTypeImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmReturnTypeImpl.java @@ -18,55 +18,19 @@ */ package org.apache.olingo.odata4.server.core.edm.provider; -import org.apache.olingo.odata4.commons.api.edm.EdmException; -import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType; -import org.apache.olingo.odata4.commons.api.edm.EdmReturnType; -import org.apache.olingo.odata4.commons.api.edm.EdmType; -import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; -import org.apache.olingo.odata4.commons.core.edm.AbstractEdmImpl; -import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmReturnType; import org.apache.olingo.odata4.server.api.edm.provider.ReturnType; -public class EdmReturnTypeImpl implements EdmReturnType { +public class EdmReturnTypeImpl extends AbstractEdmReturnType { - private final AbstractEdmImpl edm; private final ReturnType returnType; - private EdmType typeImpl; - public EdmReturnTypeImpl(final AbstractEdmImpl edm, final ReturnType returnType) { - this.edm = edm; + public EdmReturnTypeImpl(final Edm edm, final ReturnType returnType) { + super(edm, returnType.getType()); this.returnType = returnType; } - @Override - public EdmType getType() { - if (typeImpl == null) { - FullQualifiedName typeName = returnType.getType(); - if (EdmPrimitiveType.EDM_NAMESPACE.equals(typeName.getNamespace())) { - try { - typeImpl = EdmPrimitiveTypeKind.valueOf(typeName.getName()).getEdmPrimitiveTypeInstance(); - } catch (IllegalArgumentException e) { - throw new EdmException("Cannot find type with name: " + typeName, e); - } - } else { - typeImpl = edm.getComplexType(typeName); - if (typeImpl == null) { - typeImpl = edm.getEntityType(typeName); - if (typeImpl == null) { - typeImpl = edm.getEnumType(typeName); - if (typeImpl == null) { - typeImpl = edm.getTypeDefinition(typeName); - if (typeImpl == null) { - throw new EdmException("Cant find type with name: " + typeName); - } - } - } - } - } - } - return typeImpl; - } - @Override public boolean isCollection() { return returnType.isCollection(); diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmServiceMetadataImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmServiceMetadataImpl.java index f44f1d64a..ba8a46a59 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmServiceMetadataImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmServiceMetadataImpl.java @@ -23,12 +23,18 @@ import java.util.ArrayList; import java.util.List; import org.apache.olingo.odata4.commons.api.ODataException; +import org.apache.olingo.odata4.commons.api.edm.EdmActionImportInfo; import org.apache.olingo.odata4.commons.api.edm.EdmEntitySetInfo; import org.apache.olingo.odata4.commons.api.edm.EdmException; import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImportInfo; import org.apache.olingo.odata4.commons.api.edm.EdmServiceMetadata; import org.apache.olingo.odata4.commons.api.edm.EdmSingletonInfo; import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion; +import org.apache.olingo.odata4.commons.core.edm.EdmSingletonInfoImpl; +import org.apache.olingo.odata4.commons.core.edm.EdmActionImportInfoImpl; +import org.apache.olingo.odata4.commons.core.edm.EdmFunctionImportInfoImpl; +import org.apache.olingo.odata4.commons.core.edm.EdmEntitySetInfoImpl; +import org.apache.olingo.odata4.server.api.edm.provider.ActionImport; import org.apache.olingo.odata4.server.api.edm.provider.EdmProvider; import org.apache.olingo.odata4.server.api.edm.provider.EntityContainer; import org.apache.olingo.odata4.server.api.edm.provider.EntitySet; @@ -39,11 +45,17 @@ import org.apache.olingo.odata4.server.api.edm.provider.Singleton; public class EdmServiceMetadataImpl implements EdmServiceMetadata { private EdmProvider provider; - private ArrayList entitySetInfos; - private ArrayList functionImportInfos; - private ArrayList singletonInfos; + private List schemas; + private List entitySetInfos; + + private List singletonInfos; + + private List actionImportInfos; + + private List functionImportInfos; + public EdmServiceMetadataImpl(final EdmProvider provider) { this.provider = provider; } @@ -70,12 +82,12 @@ public class EdmServiceMetadataImpl implements EdmServiceMetadata { } } for (Schema schema : schemas) { - EntityContainer entityContainer = schema.getEntityContainer(); + final EntityContainer entityContainer = schema.getEntityContainer(); if (entityContainer != null) { - List entitySets = entityContainer.getEntitySets(); + final List entitySets = entityContainer.getEntitySets(); if (entitySets != null) { for (EntitySet set : entitySets) { - entitySetInfos.add(new EdmEntitySetInfoImpl(entityContainer, set)); + entitySetInfos.add(new EdmEntitySetInfoImpl(entityContainer.getName(), set.getName())); } } } @@ -99,12 +111,12 @@ public class EdmServiceMetadataImpl implements EdmServiceMetadata { } } for (Schema schema : schemas) { - EntityContainer entityContainer = schema.getEntityContainer(); + final EntityContainer entityContainer = schema.getEntityContainer(); if (entityContainer != null) { - List singletons = entityContainer.getSingletons(); + final List singletons = entityContainer.getSingletons(); if (singletons != null) { for (Singleton singleton : singletons) { - singletonInfos.add(new EdmSingletonInfoImpl(entityContainer, singleton)); + singletonInfos.add(new EdmSingletonInfoImpl(entityContainer.getName(), singleton.getName())); } } } @@ -116,6 +128,35 @@ public class EdmServiceMetadataImpl implements EdmServiceMetadata { return singletonInfos; } + @Override + public List getActionImportInfos() { + if (actionImportInfos == null) { + try { + actionImportInfos = new ArrayList(); + if (schemas == null) { + schemas = provider.getSchemas(); + if (schemas == null) { + throw new EdmException("Provider doe not define any schemas."); + } + } + for (Schema schema : schemas) { + final EntityContainer entityContainer = schema.getEntityContainer(); + if (entityContainer != null) { + final List actionImports = entityContainer.getActionImports(); + if (actionImports != null) { + for (ActionImport actionImport : actionImports) { + actionImportInfos.add(new EdmActionImportInfoImpl(entityContainer.getName(), actionImport.getName())); + } + } + } + } + } catch (ODataException e) { + throw new EdmException(e); + } + } + return actionImportInfos; + } + @Override public List getFunctionImportInfos() { if (functionImportInfos == null) { @@ -128,12 +169,13 @@ public class EdmServiceMetadataImpl implements EdmServiceMetadata { } } for (Schema schema : schemas) { - EntityContainer entityContainer = schema.getEntityContainer(); + final EntityContainer entityContainer = schema.getEntityContainer(); if (entityContainer != null) { - List functionImports = entityContainer.getFunctionImports(); + final List functionImports = entityContainer.getFunctionImports(); if (functionImports != null) { for (FunctionImport functionImport : functionImports) { - functionImportInfos.add(new EdmFunctionImportInfoImpl(entityContainer, functionImport)); + functionImportInfos.add( + new EdmFunctionImportInfoImpl(entityContainer.getName(), functionImport.getName())); } } } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonImpl.java index 1ca0fc5ad..9fbd0b0fd 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonImpl.java @@ -18,13 +18,14 @@ */ package org.apache.olingo.odata4.server.core.edm.provider; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer; import org.apache.olingo.odata4.commons.api.edm.EdmSingleton; import org.apache.olingo.odata4.server.api.edm.provider.Singleton; public class EdmSingletonImpl extends EdmBindingTargetImpl implements EdmSingleton { - public EdmSingletonImpl(final EdmProviderImpl edm, final EdmEntityContainer container, final Singleton singleton) { + public EdmSingletonImpl(final Edm edm, final EdmEntityContainer container, final Singleton singleton) { super(edm, container, singleton); } } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmStructuralTypeImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmStructuralTypeImpl.java deleted file mode 100644 index 8849dd0b4..000000000 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmStructuralTypeImpl.java +++ /dev/null @@ -1,129 +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.odata4.server.core.edm.provider; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.olingo.odata4.commons.api.edm.EdmElement; -import org.apache.olingo.odata4.commons.api.edm.EdmException; -import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType; -import org.apache.olingo.odata4.commons.api.edm.EdmType; -import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; -import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; -import org.apache.olingo.odata4.server.api.edm.provider.NavigationProperty; -import org.apache.olingo.odata4.server.api.edm.provider.Property; -import org.apache.olingo.odata4.server.api.edm.provider.StructuralType; - -public abstract class EdmStructuralTypeImpl extends EdmTypeImpl implements EdmStructuralType { - - private final Map properties = new HashMap(); - private ArrayList navigationPropertyNames; - private ArrayList propertyNames; - protected final EdmStructuralType baseType; - private final StructuralType structuralType; - - public EdmStructuralTypeImpl(final EdmProviderImpl edm, final FullQualifiedName name, - final StructuralType structuralType, final EdmTypeKind kind) { - super(edm, name, kind); - this.structuralType = structuralType; - baseType = buildBaseType(structuralType.getBaseType()); - buildProperties(structuralType.getProperties()); - buildNavigationProperties(structuralType.getNavigationProperties()); - } - - private void buildNavigationProperties(final List providerNavigationProperties) { - if (providerNavigationProperties != null) { - for (NavigationProperty navigationProperty : providerNavigationProperties) { - properties.put(navigationProperty.getName(), new EdmNavigationPropertyImpl(edm, navigationProperty)); - } - } - - } - - private void buildProperties(final List providerProperties) { - if (providerProperties != null) { - for (Property property : providerProperties) { - properties.put(property.getName(), new EdmPropertyImpl(edm, property)); - } - } - - } - - @Override - public EdmElement getProperty(final String name) { - EdmElement property = null; - if (baseType != null) { - property = baseType.getProperty(name); - } - if (property == null) { - property = properties.get(name); - } - return property; - } - - @Override - public List getPropertyNames() { - if (propertyNames == null) { - propertyNames = new ArrayList(); - if (baseType != null) { - propertyNames.addAll(baseType.getPropertyNames()); - } - for (Property property : structuralType.getProperties()) { - propertyNames.add(property.getName()); - } - } - return propertyNames; - } - - @Override - public List getNavigationPropertyNames() { - if (navigationPropertyNames == null) { - navigationPropertyNames = new ArrayList(); - if (baseType != null) { - navigationPropertyNames.addAll(baseType.getNavigationPropertyNames()); - } - for (NavigationProperty navProperty : structuralType.getNavigationProperties()) { - navigationPropertyNames.add(navProperty.getName()); - } - } - return navigationPropertyNames; - } - - @Override - public boolean compatibleTo(final EdmType targetType) { - EdmStructuralType sourceType = this; - if (targetType == null) { - throw new EdmException("Target type must not be null"); - } - while (sourceType.getName() != targetType.getName() || - sourceType.getNamespace() != targetType.getNamespace()) { - sourceType = sourceType.getBaseType(); - if (sourceType == null) { - return false; - } - } - - return true; - } - - protected abstract EdmStructuralType buildBaseType(FullQualifiedName baseTypeName); -} diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmStructuredTypeHelperImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmStructuredTypeHelperImpl.java new file mode 100644 index 000000000..cc7eac701 --- /dev/null +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmStructuredTypeHelperImpl.java @@ -0,0 +1,72 @@ +/* + * 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.odata4.server.core.edm.provider; + +import java.util.LinkedHashMap; +import java.util.Map; +import org.apache.olingo.odata4.commons.api.edm.Edm; +import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata4.commons.api.edm.EdmProperty; +import org.apache.olingo.odata4.commons.core.edm.EdmStructuredTypeHelper; +import org.apache.olingo.odata4.server.api.edm.provider.NavigationProperty; +import org.apache.olingo.odata4.server.api.edm.provider.Property; +import org.apache.olingo.odata4.server.api.edm.provider.StructuredType; + +public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper { + + private final Edm edm; + + private final StructuredType structuredType; + + private Map properties; + + private Map navigationProperties; + + public EdmStructuredTypeHelperImpl(final Edm edm, final StructuredType structuredType) { + this.edm = edm; + this.structuredType = structuredType; + } + + @Override + public Map getProperties() { + if (properties == null) { + properties = new LinkedHashMap(); + if (structuredType.getProperties() != null) { + for (Property property : structuredType.getProperties()) { + properties.put(property.getName(), new EdmPropertyImpl(edm, property)); + } + } + } + return properties; + } + + @Override + public Map getNavigationProperties() { + if (navigationProperties == null) { + navigationProperties = new LinkedHashMap(); + if (structuredType.getNavigationProperties() != null) { + for (NavigationProperty navigationProperty : structuredType.getNavigationProperties()) { + navigationProperties.put(navigationProperty.getName(), + new EdmNavigationPropertyImpl(edm, navigationProperty)); + } + } + } + return navigationProperties; + } +} diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeDefinitionImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeDefinitionImpl.java index ad44f08f8..3c370e795 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeDefinitionImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeDefinitionImpl.java @@ -18,87 +18,35 @@ */ package org.apache.olingo.odata4.server.core.edm.provider; +import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.EdmException; import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType; -import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; -import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmTypeDefinition; import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind; import org.apache.olingo.odata4.server.api.edm.provider.TypeDefinition; -public class EdmTypeDefinitionImpl extends EdmNamedImpl implements EdmTypeDefinition { +public class EdmTypeDefinitionImpl extends AbstractEdmTypeDefinition implements EdmTypeDefinition { - private final FullQualifiedName typeDefinitionName; private TypeDefinition typeDefinition; + private EdmPrimitiveType edmPrimitiveTypeInstance; - public EdmTypeDefinitionImpl(final EdmProviderImpl edm, final FullQualifiedName typeDefinitionName, - final TypeDefinition typeDefinition) { - super(edm, typeDefinitionName.getName()); - this.typeDefinitionName = typeDefinitionName; + public EdmTypeDefinitionImpl(final Edm edm, final FullQualifiedName typeDefinitionName, + final TypeDefinition typeDefinition) { + + super(edm, typeDefinitionName); this.typeDefinition = typeDefinition; // TODO: Should we check for edmNamespace in the underlying type name? try { - edmPrimitiveTypeInstance = - EdmPrimitiveTypeKind.valueOf(typeDefinition.getUnderlyingType().getName()).getEdmPrimitiveTypeInstance(); + edmPrimitiveTypeInstance = EdmPrimitiveTypeKind.valueOf( + typeDefinition.getUnderlyingType().getName()).getEdmPrimitiveTypeInstance(); } catch (IllegalArgumentException e) { throw new EdmException("Invalid underlying type: " + typeDefinitionName, e); } } - @Override - public boolean isCompatible(final EdmPrimitiveType primitiveType) { - return edmPrimitiveTypeInstance.isCompatible(primitiveType); - } - - @Override - public Class getDefaultType() { - return edmPrimitiveTypeInstance.getDefaultType(); - } - - @Override - public boolean validate(final String value, final Boolean isNullable, final Integer maxLength, - final Integer precision, final Integer scale, - final Boolean isUnicode) { - return edmPrimitiveTypeInstance.validate(value, isNullable, maxLength, precision, scale, isUnicode); - } - - @Override - public T valueOfString(final String value, final Boolean isNullable, final Integer maxLength, - final Integer precision, final Integer scale, - final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { - return edmPrimitiveTypeInstance - .valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType); - } - - @Override - public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength, - final Integer precision, final Integer scale, - final Boolean isUnicode) throws EdmPrimitiveTypeException { - return edmPrimitiveTypeInstance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode); - } - - @Override - public String toUriLiteral(final String literal) { - return edmPrimitiveTypeInstance.toUriLiteral(literal); - } - - @Override - public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException { - return edmPrimitiveTypeInstance.fromUriLiteral(literal); - } - - @Override - public String getNamespace() { - return typeDefinitionName.getNamespace(); - } - - @Override - public EdmTypeKind getKind() { - return EdmTypeKind.DEFINITION; - } - @Override public EdmPrimitiveType getUnderlyingType() { return edmPrimitiveTypeInstance; diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/UriResourceTypedImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/UriResourceTypedImpl.java index 2cec8dee2..a5b21b11f 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/UriResourceTypedImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/UriResourceTypedImpl.java @@ -18,7 +18,7 @@ */ package org.apache.olingo.odata4.server.core.uri; -import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType; +import org.apache.olingo.odata4.commons.api.edm.EdmStructuredType; import org.apache.olingo.odata4.commons.api.edm.EdmType; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; import org.apache.olingo.odata4.server.api.uri.UriResourceKind; @@ -36,7 +36,7 @@ public abstract class UriResourceTypedImpl extends UriResourceImpl implements Ur return typeFilter; } - public UriResourceTypedImpl setTypeFilter(final EdmStructuralType typeFilter) { + public UriResourceTypedImpl setTypeFilter(final EdmStructuredType typeFilter) { this.typeFilter = typeFilter; return this; } diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/UriParseTreeVisitor.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/UriParseTreeVisitor.java index f13484fb8..1561f1771 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/UriParseTreeVisitor.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/uri/parser/UriParseTreeVisitor.java @@ -38,7 +38,7 @@ import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImport; import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty; import org.apache.olingo.odata4.commons.api.edm.EdmProperty; import org.apache.olingo.odata4.commons.api.edm.EdmSingleton; -import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType; +import org.apache.olingo.odata4.commons.api.edm.EdmStructuredType; import org.apache.olingo.odata4.commons.api.edm.EdmType; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind; @@ -387,12 +387,12 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor { return null; } - if (!(source.type instanceof EdmStructuralType)) { + if (!(source.type instanceof EdmStructuredType)) { throw wrap(new UriParserSemanticException("Can not parse'" + odi + "'Previous path segment not a structural type.")); } - EdmStructuralType structType = (EdmStructuralType) source.type; + EdmStructuredType structType = (EdmStructuredType) source.type; EdmElement property = structType.getProperty(odi); if (property == null) { @@ -1815,11 +1815,11 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor { } } - if (!(prevType instanceof EdmStructuralType)) { + if (!(prevType instanceof EdmStructuredType)) { throw wrap(new UriParserSemanticException("Previous select item is not a structural type")); } - EdmStructuralType structType = (EdmStructuralType) prevType; + EdmStructuredType structType = (EdmStructuredType) prevType; EdmElement element = structType.getProperty(odi); if (element == null) { throw wrap(new UriParserSemanticException("Previous select item has not property: " + odi)); @@ -1888,7 +1888,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor { if (prevType instanceof EdmComplexType) { EdmComplexType ct = edm.getComplexType(fullName); if (ct != null) { - if ((ct.compatibleTo((EdmStructuralType) prevType))) { + if ((ct.compatibleTo((EdmStructuredType) prevType))) { UriResourceStartingTypeFilterImpl resourcePart = new UriResourceStartingTypeFilterImpl(); resourcePart.setCollectionTypeFilter(ct); @@ -1907,7 +1907,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor { } else if (prevType instanceof EdmEntityType) { EdmEntityType et = edm.getEntityType(fullName); if (et != null) { - if ((et.compatibleTo((EdmStructuralType) prevType))) { + if ((et.compatibleTo((EdmStructuredType) prevType))) { UriResourceStartingTypeFilterImpl resourcePart = new UriResourceStartingTypeFilterImpl(); resourcePart.setCollectionTypeFilter(et); @@ -1938,7 +1938,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor { if (prevType instanceof EdmComplexType) { EdmComplexType ct = edm.getComplexType(fullName); if (ct != null) { - if ((ct.compatibleTo((EdmStructuralType) prevType))) { + if ((ct.compatibleTo((EdmStructuredType) prevType))) { UriResourceStartingTypeFilterImpl resourcePart = new UriResourceStartingTypeFilterImpl(); resourcePart.setCollectionTypeFilter(ct); diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImplTest.java index a6b5c3610..866f347b1 100644 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImplTest.java +++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImplTest.java @@ -57,20 +57,20 @@ public class EdmActionImplTest { parameters.add(new Parameter().setName("Id").setType(new FullQualifiedName("namespace", "name"))); FullQualifiedName action1Name = new FullQualifiedName("namespace", "action1"); Action action1 = new Action().setName("action1").setBound(true).setParameters(parameters); - actionImpl1 = new EdmActionImpl(provider, action1Name, action1); + actionImpl1 = EdmActionImpl.getInstance(provider, action1Name, action1); FullQualifiedName action2Name = new FullQualifiedName("namespace", "action2"); FullQualifiedName returnTypeName = new FullQualifiedName("Edm", "String"); ReturnType returnType = new ReturnType().setType(returnTypeName); Action action2 = new Action().setName("action2").setParameters(parameters).setReturnType(returnType); - actionImpl2 = new EdmActionImpl(provider, action2Name, action2); + actionImpl2 = EdmActionImpl.getInstance(provider, action2Name, action2); FullQualifiedName action3Name = new FullQualifiedName("namespace", "action3"); EntitySetPath entitySetPath = new EntitySetPath().setBindingParameter("Id").setPath("path"); Action action3 = new Action().setName("action3").setParameters(parameters).setReturnType(returnType).setEntitySetPath( entitySetPath); - actionImpl3 = new EdmActionImpl(provider, action3Name, action3); + actionImpl3 = EdmActionImpl.getInstance(provider, action3Name, action3); } @Test diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImportImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImportImplTest.java index a829c8999..033800df3 100644 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImportImplTest.java +++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmActionImportImplTest.java @@ -31,15 +31,18 @@ import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet; import org.apache.olingo.odata4.commons.api.edm.EdmException; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; import org.apache.olingo.odata4.server.api.edm.provider.ActionImport; -import org.apache.olingo.odata4.server.api.edm.provider.Target; +import org.apache.olingo.odata4.commons.api.edm.Target; import org.junit.Before; import org.junit.Test; public class EdmActionImportImplTest { EdmEntityContainer container; + EdmActionImport actionImport; + private EdmAction action; + private EdmEntitySet entitySet; @Before @@ -47,8 +50,8 @@ public class EdmActionImportImplTest { FullQualifiedName actionFqn = new FullQualifiedName("namespace", "actionName"); FullQualifiedName entityContainerFqn = new FullQualifiedName("namespace", "containerName"); Target target = new Target().setEntityContainer(entityContainerFqn).setTargetName("entitySetName"); - ActionImport providerActionImport = - new ActionImport().setName("actionImportName").setAction(actionFqn).setEntitySet(target); + ActionImport providerActionImport + = new ActionImport().setName("actionImportName").setAction(actionFqn).setEntitySet(target); EdmProviderImpl edm = mock(EdmProviderImpl.class); container = mock(EdmEntityContainer.class); @@ -58,7 +61,7 @@ public class EdmActionImportImplTest { entitySet = mock(EdmEntitySet.class); when(container.getEntitySet("entitySetName")).thenReturn(entitySet); - actionImport = new EdmActionImportImpl(edm, "actionImportName", container, providerActionImport); + actionImport = new EdmActionImportImpl(edm, container, "actionImportName", providerActionImport); } @Test @@ -82,8 +85,8 @@ public class EdmActionImportImplTest { public void getReturnedEntitySetNonExistingContainer() { Target target = new Target(); ActionImport providerActionImport = new ActionImport().setName("actionImportName").setEntitySet(target); - EdmActionImport actionImport = - new EdmActionImportImpl(mock(EdmProviderImpl.class), "actionImportName", container, providerActionImport); + EdmActionImport actionImport + = new EdmActionImportImpl(mock(EdmProviderImpl.class), container, "actionImportName", providerActionImport); actionImport.getReturnedEntitySet(); } @@ -93,7 +96,7 @@ public class EdmActionImportImplTest { ActionImport providerActionImport = new ActionImport().setName("actionImportName").setEntitySet(target); EdmProviderImpl edm = mock(EdmProviderImpl.class); when(edm.getEntityContainer(null)).thenReturn(container); - EdmActionImport actionImport = new EdmActionImportImpl(edm, "actionImportName", container, providerActionImport); + EdmActionImport actionImport = new EdmActionImportImpl(edm, container, "actionImportName", providerActionImport); actionImport.getReturnedEntitySet(); } diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmComplexTypeImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmComplexTypeImplTest.java index 33832ede4..9ae780bf3 100644 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmComplexTypeImplTest.java +++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmComplexTypeImplTest.java @@ -61,7 +61,7 @@ public class EdmComplexTypeImplTest { .setNavigationProperties(baseNavigationProperties); when(provider.getComplexType(baseName)).thenReturn(baseComplexType); - baseType = new EdmComplexTypeImpl(edm, baseName, baseComplexType); + baseType = EdmComplexTypeImpl.getInstance(edm, baseName, baseComplexType); FullQualifiedName name = new FullQualifiedName("namespace", "typeName"); ComplexType complexType = new ComplexType().setBaseType(baseName); @@ -73,14 +73,14 @@ public class EdmComplexTypeImplTest { .setNavigationProperties(navigationProperties); when(provider.getComplexType(name)).thenReturn(complexType); - type = new EdmComplexTypeImpl(edm, name, complexType); + type = EdmComplexTypeImpl.getInstance(edm, name, complexType); } @Test public void noPropertiesAndNoNavPropertiesMustNotResultInException() { EdmProviderImpl edm = mock(EdmProviderImpl.class); ComplexType complexType = new ComplexType().setName("n"); - new EdmComplexTypeImpl(edm, new FullQualifiedName("n", "n"), complexType); + EdmComplexTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), complexType); } @Test @@ -158,6 +158,6 @@ public class EdmComplexTypeImplTest { new ComplexType().setBaseType(new FullQualifiedName("wrong", "wrong")); complexTypeForNonexistingBaseType.setName("typeName"); when(provider.getComplexType(typeWithNonexistingBaseTypeName)).thenReturn(complexTypeForNonexistingBaseType); - new EdmComplexTypeImpl(edm, typeWithNonexistingBaseTypeName, complexTypeForNonexistingBaseType); + EdmComplexTypeImpl.getInstance(edm, typeWithNonexistingBaseTypeName, complexTypeForNonexistingBaseType); } } diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetImplTest.java index 5bd5fa3e2..85df5201a 100644 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetImplTest.java +++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetImplTest.java @@ -36,7 +36,7 @@ import org.apache.olingo.odata4.server.api.edm.provider.EntitySet; import org.apache.olingo.odata4.server.api.edm.provider.EntityType; import org.apache.olingo.odata4.server.api.edm.provider.NavigationPropertyBinding; import org.apache.olingo.odata4.server.api.edm.provider.PropertyRef; -import org.apache.olingo.odata4.server.api.edm.provider.Target; +import org.apache.olingo.odata4.commons.api.edm.Target; import org.junit.Test; public class EdmEntitySetImplTest { diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetInfoImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetInfoImplTest.java deleted file mode 100644 index d002dd469..000000000 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntitySetInfoImplTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.odata4.server.core.edm.provider; - -import static org.junit.Assert.assertEquals; - -import org.apache.olingo.odata4.commons.api.edm.EdmEntitySetInfo; -import org.apache.olingo.odata4.commons.api.edm.EdmException; -import org.apache.olingo.odata4.server.api.edm.provider.EntityContainer; -import org.apache.olingo.odata4.server.api.edm.provider.EntitySet; -import org.junit.Test; - -public class EdmEntitySetInfoImplTest { - - @Test - public void entitySetTest() { - EntitySet providerEntitySet = new EntitySet().setName("name"); - EntityContainer providerContainer = new EntityContainer().setName("container"); - - EdmEntitySetInfo info = new EdmEntitySetInfoImpl(providerContainer, providerEntitySet); - - assertEquals("name", info.getEntitySetName()); - assertEquals("container", info.getEntityContainerName()); - } - - @Test(expected = EdmException.class) - public void getUriTest() { - EntitySet providerEntitySet = new EntitySet().setName("name"); - EntityContainer providerContainer = new EntityContainer().setName("container"); - - EdmEntitySetInfo info = new EdmEntitySetInfoImpl(providerContainer, providerEntitySet); - info.getEntitySetUri(); - } - -} diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityTypeImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityTypeImplTest.java index 4e2ca118f..a4a26d8fb 100644 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityTypeImplTest.java +++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEntityTypeImplTest.java @@ -72,7 +72,7 @@ public class EdmEntityTypeImplTest { baseType.setNavigationProperties(navigationProperties); when(provider.getEntityType(baseName)).thenReturn(baseType); - this.baseType = new EdmEntityTypeImpl(edm, baseName, baseType); + this.baseType = EdmEntityTypeImpl.getInstance(edm, baseName, baseType); FullQualifiedName typeName = new FullQualifiedName("namespace", "typeName"); EntityType type = new EntityType(); @@ -87,7 +87,7 @@ public class EdmEntityTypeImplTest { type.setNavigationProperties(typeNavigationProperties); when(provider.getEntityType(typeName)).thenReturn(type); - typeWithBaseType = new EdmEntityTypeImpl(edm, typeName, type); + typeWithBaseType = EdmEntityTypeImpl.getInstance(edm, typeName, type); FullQualifiedName typeWithComplexKeyName = new FullQualifiedName("namespace", "typeName"); EntityType typeWithComplexKeyProvider = new EntityType(); @@ -112,7 +112,7 @@ public class EdmEntityTypeImplTest { typeWithComplexKeyProvider.setKey(keyForTypeWithComplexKey); when(provider.getEntityType(typeWithComplexKeyName)).thenReturn(typeWithComplexKeyProvider); - typeWithComplexKey = new EdmEntityTypeImpl(edm, typeWithComplexKeyName, typeWithComplexKeyProvider); + typeWithComplexKey = EdmEntityTypeImpl.getInstance(edm, typeWithComplexKeyName, typeWithComplexKeyProvider); } @Test @@ -246,21 +246,21 @@ public class EdmEntityTypeImplTest { public void noKeyOnTypeWithoutBaseTypeMustResultInException() { EdmProviderImpl edm = mock(EdmProviderImpl.class); EntityType entityType = new EntityType().setName("n"); - new EdmEntityTypeImpl(edm, new FullQualifiedName("n", "n"), entityType); + EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), entityType); } @Test public void abstractTypeDoesNotNeedKey() { EdmProviderImpl edm = mock(EdmProviderImpl.class); EntityType entityType = new EntityType().setName("n").setAbstract(true); - new EdmEntityTypeImpl(edm, new FullQualifiedName("n", "n"), entityType); + EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), entityType); } @Test(expected = EdmException.class) public void invalidBaseType() { EdmProviderImpl edm = mock(EdmProviderImpl.class); EntityType entityType = new EntityType().setName("n").setBaseType(new FullQualifiedName("wrong", "wrong")); - new EdmEntityTypeImpl(edm, new FullQualifiedName("n", "n"), entityType); + EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), entityType); } @Test @@ -270,7 +270,7 @@ public class EdmEntityTypeImplTest { FullQualifiedName baseName = new FullQualifiedName("n", "base"); when(provider.getEntityType(baseName)).thenReturn(new EntityType().setName("base").setAbstract(true)); EntityType entityType = new EntityType().setName("n").setAbstract(true).setBaseType(baseName); - new EdmEntityTypeImpl(edm, new FullQualifiedName("n", "n"), entityType); + EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), entityType); } } diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumTest.java index 4c3110310..b55f625b9 100644 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumTest.java +++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmEnumTest.java @@ -51,11 +51,11 @@ public class EdmEnumTest extends PrimitiveTypeBaseTest { EdmPrimitiveTypeKind.SByte.getFullQualifiedName()); FullQualifiedName enumName = new FullQualifiedName("namespace", "name"); - instance = new EdmEnumImpl(mock(EdmProviderImpl.class), enumName, enumType); + instance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName, enumType); EnumType enumType2 = new EnumType().setName("name").setMembers(memberList).setFlags(false).setUnderlyingType( EdmPrimitiveTypeKind.SByte.getFullQualifiedName()); - nonFlagsInstance = new EdmEnumImpl(mock(EdmProviderImpl.class), enumName, enumType2); + nonFlagsInstance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName, enumType2); // EdmMember member1 = mock(EdmMember.class); // when(member1.getName()).thenReturn("first"); diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImplTest.java index 6ed7ef14f..f5488d39d 100644 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImplTest.java +++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImplTest.java @@ -44,9 +44,9 @@ public class EdmFunctionImplTest { EdmProviderImpl provider = mock(EdmProviderImpl.class); Function function1 = new Function().setReturnType(new ReturnType().setType(new FullQualifiedName("Edm", "String"))); - functionImpl1 = new EdmFunctionImpl(provider, new FullQualifiedName("namespace", "name"), function1); + functionImpl1 = EdmFunctionImpl.getInstance(provider, new FullQualifiedName("namespace", "name"), function1); Function function2 = new Function().setComposable(true); - functionImpl2 = new EdmFunctionImpl(provider, new FullQualifiedName("namespace", "name"), function2); + functionImpl2 = EdmFunctionImpl.getInstance(provider, new FullQualifiedName("namespace", "name"), function2); } @Test diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportImplTest.java index 3a98a8868..f7d7e590d 100644 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportImplTest.java +++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportImplTest.java @@ -69,7 +69,7 @@ public class EdmFunctionImportImplTest { when(provider.getFunctionImport(containerName, functionImportName)).thenReturn(functionImportProvider); final EdmFunctionImport functionImport = - new EdmFunctionImportImpl(edm, "test", entityContainer, functionImportProvider); + new EdmFunctionImportImpl(edm, entityContainer, "test", functionImportProvider); assertEquals(functionImportName, entityContainer.getFunctionImport(functionImportName).getName()); assertEquals("test", functionImport.getName()); final EdmFunction function = functionImport.getFunction(Collections. emptyList()); diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportInfoImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportInfoImplTest.java deleted file mode 100644 index 136d38c85..000000000 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmFunctionImportInfoImplTest.java +++ /dev/null @@ -1,50 +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.odata4.server.core.edm.provider; - -import static org.junit.Assert.assertEquals; - -import org.apache.olingo.odata4.commons.api.edm.EdmException; -import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImportInfo; -import org.apache.olingo.odata4.server.api.edm.provider.EntityContainer; -import org.apache.olingo.odata4.server.api.edm.provider.FunctionImport; -import org.junit.Test; - -public class EdmFunctionImportInfoImplTest { - - @Test - public void functionImportTest() { - FunctionImport providerFunctionImport = new FunctionImport().setName("name"); - EntityContainer providerContainer = new EntityContainer().setName("container"); - - EdmFunctionImportInfo info = new EdmFunctionImportInfoImpl(providerContainer, providerFunctionImport); - - assertEquals("name", info.getFunctionImportName()); - assertEquals("container", info.getEntityContainerName()); - } - - @Test(expected = EdmException.class) - public void getUriTest() { - FunctionImport providerFunctionImport = new FunctionImport().setName("name"); - EntityContainer providerContainer = new EntityContainer().setName("container"); - - EdmFunctionImportInfo info = new EdmFunctionImportInfoImpl(providerContainer, providerFunctionImport); - info.getFunctionImportUri(); - } -} diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmKeyPropertyRefImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmKeyPropertyRefImplTest.java index 4a356fbd9..ce2e374f1 100644 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmKeyPropertyRefImplTest.java +++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmKeyPropertyRefImplTest.java @@ -41,7 +41,7 @@ public class EdmKeyPropertyRefImplTest { PropertyRef providerRef = new PropertyRef().setPropertyName("Id"); EdmEntityType etMock = mock(EdmEntityType.class); EdmProperty keyPropertyMock = mock(EdmProperty.class); - when(etMock.getProperty("Id")).thenReturn(keyPropertyMock); + when(etMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock); EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef); assertEquals("Id", ref.getKeyPropertyName()); assertNull(ref.getAlias()); @@ -58,11 +58,11 @@ public class EdmKeyPropertyRefImplTest { PropertyRef providerRef = new PropertyRef().setPropertyName("Id").setAlias("alias").setPath("comp/Id"); EdmEntityType etMock = mock(EdmEntityType.class); EdmProperty keyPropertyMock = mock(EdmProperty.class); - EdmElement compMock = mock(EdmProperty.class); + EdmProperty compMock = mock(EdmProperty.class); EdmComplexType compTypeMock = mock(EdmComplexType.class); - when(compTypeMock.getProperty("Id")).thenReturn(keyPropertyMock); + when(compTypeMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock); when(compMock.getType()).thenReturn(compTypeMock); - when(etMock.getProperty("comp")).thenReturn(compMock); + when(etMock.getStructuralProperty("comp")).thenReturn(compMock); EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef); assertEquals("alias", ref.getAlias()); assertEquals("comp/Id", ref.getPath()); @@ -103,15 +103,15 @@ public class EdmKeyPropertyRefImplTest { PropertyRef providerRef = new PropertyRef().setPropertyName("Id").setAlias("alias").setPath("comp/comp2/Id"); EdmEntityType etMock = mock(EdmEntityType.class); EdmProperty keyPropertyMock = mock(EdmProperty.class); - EdmElement compMock = mock(EdmProperty.class); + EdmProperty compMock = mock(EdmProperty.class); EdmComplexType compTypeMock = mock(EdmComplexType.class); - EdmElement comp2Mock = mock(EdmProperty.class); + EdmProperty comp2Mock = mock(EdmProperty.class); EdmComplexType comp2TypeMock = mock(EdmComplexType.class); - when(comp2TypeMock.getProperty("Id")).thenReturn(keyPropertyMock); + when(comp2TypeMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock); when(comp2Mock.getType()).thenReturn(comp2TypeMock); - when(compTypeMock.getProperty("comp2")).thenReturn(comp2Mock); + when(compTypeMock.getStructuralProperty("comp2")).thenReturn(comp2Mock); when(compMock.getType()).thenReturn(compTypeMock); - when(etMock.getProperty("comp")).thenReturn(compMock); + when(etMock.getStructuralProperty("comp")).thenReturn(compMock); EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef); EdmProperty property = ref.getProperty(); diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmMemberImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmMemberImplTest.java index 0f249d609..26dffae2b 100644 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmMemberImplTest.java +++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmMemberImplTest.java @@ -18,6 +18,7 @@ */ package org.apache.olingo.odata4.server.core.edm.provider; +import org.apache.olingo.odata4.commons.core.edm.EdmMemberImpl; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; @@ -29,7 +30,7 @@ public class EdmMemberImplTest { @Test public void enumMember() { EnumMember member = new EnumMember().setName("name").setValue("value"); - EdmMemberImpl memberImpl = new EdmMemberImpl(mock(EdmProviderImpl.class), member); + EdmMemberImpl memberImpl = new EdmMemberImpl(mock(EdmProviderImpl.class), member.getName(), member.getValue()); assertEquals("name", memberImpl.getName()); assertEquals("value", memberImpl.getValue()); diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNamedImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNamedImplTest.java index a777be703..986acca4f 100644 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNamedImplTest.java +++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmNamedImplTest.java @@ -21,6 +21,7 @@ package org.apache.olingo.odata4.server.core.edm.provider; import static org.junit.Assert.assertEquals; import org.apache.olingo.odata4.commons.api.edm.EdmNamed; +import org.apache.olingo.odata4.commons.core.edm.EdmNamedImpl; import org.junit.Test; public class EdmNamedImplTest { diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonImplTest.java index b253c5580..d87e8711f 100644 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonImplTest.java +++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonImplTest.java @@ -37,7 +37,7 @@ import org.apache.olingo.odata4.server.api.edm.provider.EntityType; import org.apache.olingo.odata4.server.api.edm.provider.NavigationPropertyBinding; import org.apache.olingo.odata4.server.api.edm.provider.PropertyRef; import org.apache.olingo.odata4.server.api.edm.provider.Singleton; -import org.apache.olingo.odata4.server.api.edm.provider.Target; +import org.apache.olingo.odata4.commons.api.edm.Target; import org.junit.Test; public class EdmSingletonImplTest { diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonInfoImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonInfoImplTest.java deleted file mode 100644 index a8d617584..000000000 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmSingletonInfoImplTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.odata4.server.core.edm.provider; - -import static org.junit.Assert.assertEquals; - -import org.apache.olingo.odata4.commons.api.edm.EdmException; -import org.apache.olingo.odata4.commons.api.edm.EdmSingletonInfo; -import org.apache.olingo.odata4.server.api.edm.provider.EntityContainer; -import org.apache.olingo.odata4.server.api.edm.provider.Singleton; -import org.junit.Test; - -public class EdmSingletonInfoImplTest { - - @Test - public void singletonTest() { - Singleton providerSingleton = new Singleton().setName("name"); - EntityContainer providerContainer = new EntityContainer().setName("container"); - - EdmSingletonInfo info = new EdmSingletonInfoImpl(providerContainer, providerSingleton); - - assertEquals("name", info.getSingletonName()); - assertEquals("container", info.getEntityContainerName()); - } - - @Test(expected = EdmException.class) - public void getUriTest() { - Singleton providerSingleton = new Singleton().setName("name"); - EntityContainer providerContainer = new EntityContainer().setName("container"); - - EdmSingletonInfo info = new EdmSingletonInfoImpl(providerContainer, providerSingleton); - info.getEntitySetUri(); - } - -} diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeImplTest.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeImplTest.java index 1ca05ad3d..2a467b215 100644 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeImplTest.java +++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/edm/provider/EdmTypeImplTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertEquals; import org.apache.olingo.odata4.commons.api.edm.EdmType; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind; +import org.apache.olingo.odata4.commons.core.edm.EdmTypeImpl; import org.junit.Test; public class EdmTypeImplTest { diff --git a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/testutil/EdmTechProvider.java b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/testutil/EdmTechProvider.java index acedb6fb4..c7b072407 100644 --- a/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/testutil/EdmTechProvider.java +++ b/odata4-lib/odata4-server-core/src/test/java/org/apache/olingo/odata4/server/core/testutil/EdmTechProvider.java @@ -45,7 +45,7 @@ import org.apache.olingo.odata4.server.api.edm.provider.PropertyRef; import org.apache.olingo.odata4.server.api.edm.provider.ReferentialConstraint; import org.apache.olingo.odata4.server.api.edm.provider.ReturnType; import org.apache.olingo.odata4.server.api.edm.provider.Singleton; -import org.apache.olingo.odata4.server.api.edm.provider.Target; +import org.apache.olingo.odata4.commons.api.edm.Target; public class EdmTechProvider extends EdmProvider {