コード例 #1
0
        protected virtual CsdlTypeReference ParseTypeReference(string typeString, XmlElementValueCollection childValues, CsdlLocation parentLocation, Optionality typeInfoOptionality)
        {
            bool isNullable = OptionalBoolean(CsdlConstants.Attribute_Nullable) ?? CsdlConstants.Default_Nullable;

            CsdlTypeReference elementType = null;

            if (typeString != null)
            {
                string[] typeInformation = typeString.Split(new char[] { '(', ')' });
                string   typeName        = typeInformation[0];
                switch (typeName)
                {
                case CsdlConstants.Value_Collection:
                {
                    string elementTypeName = typeInformation.Length > 1 ? typeInformation[1] : typeString;
                    elementType = new CsdlExpressionTypeReference(
                        new CsdlCollectionType(
                            this.ParseNamedTypeReference(elementTypeName, isNullable, parentLocation), parentLocation), isNullable, parentLocation);
                }

                break;

                case CsdlConstants.Value_Ref:
                {
                    string elementTypeName = typeInformation.Length > 1 ? typeInformation[1] : typeString;
                    elementType = new CsdlExpressionTypeReference(
                        new CsdlEntityReferenceType(
                            this.ParseNamedTypeReference(elementTypeName, isNullable, parentLocation), parentLocation), CsdlConstants.Default_Nullable, parentLocation);
                }

                break;

                default:
                    elementType = this.ParseNamedTypeReference(typeName, isNullable, parentLocation);
                    break;
                }
            }
            else if (childValues != null)
            {
                elementType = childValues.ValuesOfType <CsdlTypeReference>().FirstOrDefault();
            }

            if (elementType == null && typeInfoOptionality == Optionality.Required)
            {
                if (childValues != null)
                {
                    // If childValues is null, then it is the case when a required type attribute was expected.
                    // In this case, we do not report the error as it should already be reported by EdmXmlDocumentParser.RequiredType method.
                    this.ReportError(parentLocation, EdmErrorCode.MissingType, Edm.Strings.CsdlParser_MissingTypeAttributeOrElement);
                }
                else
                {
                    Debug.Assert(this.Errors.Any(), "There should be an error reported for the missing required type attribute.");
                }

                elementType = new CsdlNamedTypeReference(String.Empty, isNullable, parentLocation);
            }

            return(elementType);
        }
コード例 #2
0
        private CsdlSingleton OnSingletonElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string name = Required(CsdlConstants.Attribute_Name);
            string type = RequiredQualifiedName(CsdlConstants.Attribute_Type);

            return(new CsdlSingleton(name, type, childValues.ValuesOfType <CsdlNavigationPropertyBinding>(), element.Location));
        }
コード例 #3
0
        private CsdlInclude OnIncludeElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string nameSp = Required(CsdlConstants.Attribute_Namespace);
            string alias  = Optional(CsdlConstants.Attribute_Alias);

            return(new CsdlInclude(alias, nameSp, element.Location));
        }
コード例 #4
0
        private CsdlTypeDefinition OnTypeDefinitionElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string name = Required(CsdlConstants.Attribute_Name);
            string underlyingTypeName = RequiredType(CsdlConstants.Attribute_UnderlyingType);

            return(new CsdlTypeDefinition(name, underlyingTypeName, element.Location));
        }
コード例 #5
0
        private CsdlEnumMember OnEnumMemberElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string name  = Required(CsdlConstants.Attribute_Name);
            long?  value = OptionalLong(CsdlConstants.Attribute_Value);

            return(new CsdlEnumMember(name, value, element.Location));
        }
コード例 #6
0
        private CsdlApplyExpression OnApplyElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string function = Optional(CsdlConstants.Attribute_Function);
            IEnumerable <CsdlExpressionBase> arguments = childValues.ValuesOfType <CsdlExpressionBase>();

            return(new CsdlApplyExpression(function, arguments, element.Location));
        }
コード例 #7
0
        private CsdlPropertyValue OnPropertyValueElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string             property   = Required(CsdlConstants.Attribute_Property);
            CsdlExpressionBase expression = this.ParseAnnotationExpression(element, childValues);

            return(new CsdlPropertyValue(property, expression, element.Location));
        }
コード例 #8
0
        private CsdlRecordExpression OnRecordElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string type = OptionalQualifiedName(CsdlConstants.Attribute_Type);
            IEnumerable <CsdlPropertyValue> propertyValues = childValues.ValuesOfType <CsdlPropertyValue>();

            return(new CsdlRecordExpression(type != null ? new CsdlNamedTypeReference(type, false, element.Location) : null, propertyValues, element.Location));
        }
コード例 #9
0
        private CsdlOperationReturn OnReturnTypeElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string            typeName = RequiredType(CsdlConstants.Attribute_Type);
            CsdlTypeReference type     = this.ParseTypeReference(typeName, childValues, element.Location, Optionality.Required);

            return(new CsdlOperationReturn(type, element.Location));
        }
コード例 #10
0
        private CsdlTypeReference OnCollectionTypeElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string            elementTypeName = OptionalType(CsdlConstants.Attribute_ElementType);
            CsdlTypeReference elementType     = this.ParseTypeReference(elementTypeName, childValues, element.Location, Optionality.Required);

            return(new CsdlExpressionTypeReference(new CsdlCollectionType(elementType, element.Location), elementType.IsNullable, element.Location));
        }
コード例 #11
0
        private CsdlActionImport OnActionImportElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string name = Required(CsdlConstants.Attribute_Name);
            string qualifiedActionName = RequiredQualifiedName(CsdlConstants.Attribute_Action);
            string entitySet           = Optional(CsdlConstants.Attribute_EntitySet);

            return(new CsdlActionImport(name, qualifiedActionName, entitySet, element.Location));
        }
コード例 #12
0
        private CsdlEnumType OnEnumTypeElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string name           = Required(CsdlConstants.Attribute_Name);
            string underlyingType = OptionalType(CsdlConstants.Attribute_UnderlyingType);
            bool?  isFlags        = OptionalBoolean(CsdlConstants.Attribute_IsFlags);

            return(new CsdlEnumType(name, underlyingType, isFlags ?? false, childValues.ValuesOfType <CsdlEnumMember>(), element.Location));
        }
コード例 #13
0
        private CsdlAnnotations OnAnnotationsElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string target    = Required(CsdlConstants.Attribute_Target);
            string qualifier = Optional(CsdlConstants.Attribute_Qualifier);
            IEnumerable <CsdlAnnotation> annotations = childValues.ValuesOfType <CsdlAnnotation>();

            return(new CsdlAnnotations(annotations, target, qualifier));
        }
コード例 #14
0
        private CsdlCollectionExpression OnCollectionElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string            typeName = OptionalType(CsdlConstants.Attribute_Type);
            CsdlTypeReference type     = this.ParseTypeReference(typeName, childValues, element.Location, Optionality.Optional);
            IEnumerable <CsdlExpressionBase> elementValues = childValues.ValuesOfType <CsdlExpressionBase>();

            return(new CsdlCollectionExpression(type, elementValues, element.Location));
        }
コード例 #15
0
        private CsdlAnnotation OnAnnotationElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string             term       = RequiredQualifiedName(CsdlConstants.Attribute_Term);
            string             qualifier  = Optional(CsdlConstants.Attribute_Qualifier);
            CsdlExpressionBase expression = this.ParseAnnotationExpression(element, childValues);

            return(new CsdlAnnotation(term, qualifier, expression, element.Location));
        }
コード例 #16
0
        private CsdlProperty OnPropertyElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string            typeName     = OptionalType(CsdlConstants.Attribute_Type);
            CsdlTypeReference type         = this.ParseTypeReference(typeName, childValues, element.Location, Optionality.Required);
            string            name         = Required(CsdlConstants.Attribute_Name);
            string            defaultValue = Optional(CsdlConstants.Attribute_DefaultValue);

            return(new CsdlProperty(name, type, defaultValue, element.Location));
        }
コード例 #17
0
        private CsdlFunctionImport OnFunctionImportElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string name = Required(CsdlConstants.Attribute_Name);
            string qualifiedActionName      = RequiredQualifiedName(CsdlConstants.Attribute_Function);
            string entitySet                = Optional(CsdlConstants.Attribute_EntitySet);
            bool   includeInServiceDocument = OptionalBoolean(CsdlConstants.Attribute_IncludeInServiceDocument) ?? CsdlConstants.Default_IncludeInServiceDocument;

            return(new CsdlFunctionImport(name, qualifiedActionName, entitySet, includeInServiceDocument, element.Location));
        }
コード例 #18
0
        private CsdlComplexType OnComplexTypeElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string name       = Required(CsdlConstants.Attribute_Name);
            string baseType   = OptionalQualifiedName(CsdlConstants.Attribute_BaseType);
            bool   isOpen     = OptionalBoolean(CsdlConstants.Attribute_OpenType) ?? CsdlConstants.Default_OpenType;
            bool   isAbstract = OptionalBoolean(CsdlConstants.Attribute_Abstract) ?? CsdlConstants.Default_Abstract;

            return(new CsdlComplexType(name, baseType, isAbstract, isOpen, childValues.ValuesOfType <CsdlProperty>(), childValues.ValuesOfType <CsdlNavigationProperty>(), element.Location));
        }
コード例 #19
0
        private CsdlReference OnReferenceElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            // read 'Uri' attribute
            string uri = Required(CsdlConstants.Attribute_Uri);

            return(new CsdlReference(uri,
                                     childValues.ValuesOfType <CsdlInclude>(),
                                     childValues.ValuesOfType <CsdlIncludeAnnotations>(),
                                     element.Location));
        }
コード例 #20
0
        private CsdlEntityType OnEntityTypeElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string name       = Required(CsdlConstants.Attribute_Name);
            string baseType   = OptionalQualifiedName(CsdlConstants.Attribute_BaseType);
            bool   isOpen     = OptionalBoolean(CsdlConstants.Attribute_OpenType) ?? CsdlConstants.Default_OpenType;
            bool   isAbstract = OptionalBoolean(CsdlConstants.Attribute_Abstract) ?? CsdlConstants.Default_Abstract;
            bool   hasStream  = OptionalBoolean(CsdlConstants.Attribute_HasStream) ?? CsdlConstants.Default_HasStream;

            CsdlKey key = childValues.ValuesOfType <CsdlKey>().FirstOrDefault();

            return(new CsdlEntityType(name, baseType, isAbstract, isOpen, hasStream, key, childValues.ValuesOfType <CsdlProperty>(), childValues.ValuesOfType <CsdlNavigationProperty>(), element.Location));
        }
コード例 #21
0
        private CsdlExpressionBase OnIsTypeExpression(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string            typeName = OptionalType(CsdlConstants.Attribute_Type);
            CsdlTypeReference type     = this.ParseTypeReference(typeName, childValues, element.Location, Optionality.Required);

            IEnumerable <CsdlExpressionBase> expressions = childValues.ValuesOfType <CsdlExpressionBase>();

            if (expressions.Count() != 1)
            {
                this.ReportError(element.Location, EdmErrorCode.InvalidIsTypeExpressionIncorrectNumberOfOperands, Edm.Strings.CsdlParser_InvalidIsTypeExpressionIncorrectNumberOfOperands);
            }

            return(new CsdlIsTypeExpression(type, expressions.ElementAtOrDefault(0), element.Location));
        }
コード例 #22
0
        private CsdlNamedElement OnNavigationPropertyElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string name = Required(CsdlConstants.Attribute_Name);

            string typeName   = RequiredType(CsdlConstants.Attribute_Type);
            bool?  isNullable = OptionalBoolean(CsdlConstants.Attribute_Nullable);
            string partner    = Optional(CsdlConstants.Attribute_Partner);

            bool?        containsTarget = OptionalBoolean(CsdlConstants.Attribute_ContainsTarget);
            CsdlOnDelete onDelete       = childValues.ValuesOfType <CsdlOnDelete>().FirstOrDefault();
            IEnumerable <CsdlReferentialConstraint> referentialConstraints = childValues.ValuesOfType <CsdlReferentialConstraint>().ToList();

            return(new CsdlNavigationProperty(name, typeName, isNullable, partner, containsTarget ?? false, onDelete, referentialConstraints, element.Location));
        }
コード例 #23
0
        internal CsdlAction OnActionElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string name          = Required(CsdlConstants.Attribute_Name);
            bool   isBound       = OptionalBoolean(CsdlConstants.Attribute_IsBound) ?? CsdlConstants.Default_IsBound;
            string entitySetPath = Optional(CsdlConstants.Attribute_EntitySetPath);

            IEnumerable <CsdlOperationParameter> parameters = childValues.ValuesOfType <CsdlOperationParameter>();

            CsdlOperationReturn returnElement = childValues.ValuesOfType <CsdlOperationReturn>().FirstOrDefault();

            this.ReportOperationReadErrorsIfExist(entitySetPath, isBound, name);

            return(new CsdlAction(name, parameters, returnElement, isBound, entitySetPath, element.Location));
        }
コード例 #24
0
        private CsdlExpressionBase OnIfExpression(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            IEnumerable <CsdlExpressionBase> expressions = childValues.ValuesOfType <CsdlExpressionBase>();

            if (expressions.Count() != 3)
            {
                this.ReportError(element.Location, EdmErrorCode.InvalidIfExpressionIncorrectNumberOfOperands, Edm.Strings.CsdlParser_InvalidIfExpressionIncorrectNumberOfOperands);
            }

            return(new CsdlIfExpression(
                       expressions.ElementAtOrDefault(0),
                       expressions.ElementAtOrDefault(1),
                       expressions.ElementAtOrDefault(2),
                       element.Location));
        }
コード例 #25
0
        private CsdlEntitySet OnEntitySetElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string name       = Required(CsdlConstants.Attribute_Name);
            string entityType = RequiredQualifiedName(CsdlConstants.Attribute_EntityType);
            bool?  includeInServiceDocument = OptionalBoolean(CsdlConstants.Attribute_IncludeInServiceDocument);

            if (includeInServiceDocument == null)
            {
                return(new CsdlEntitySet(name, entityType, childValues.ValuesOfType <CsdlNavigationPropertyBinding>(), element.Location));
            }
            else
            {
                return(new CsdlEntitySet(name, entityType, childValues.ValuesOfType <CsdlNavigationPropertyBinding>(), element.Location, (bool)includeInServiceDocument));
            }
        }
コード例 #26
0
        private CsdlLabeledExpression OnLabeledElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string name = Required(CsdlConstants.Attribute_Name);
            IEnumerable <CsdlExpressionBase> expressions = childValues.ValuesOfType <CsdlExpressionBase>();

            if (expressions.Count() != 1)
            {
                this.ReportError(element.Location, EdmErrorCode.InvalidLabeledElementExpressionIncorrectNumberOfOperands, Edm.Strings.CsdlParser_InvalidLabeledElementExpressionIncorrectNumberOfOperands);
            }

            return(new CsdlLabeledExpression(
                       name,
                       expressions.ElementAtOrDefault(0),
                       element.Location));
        }
コード例 #27
0
        private CsdlEntityContainer OnEntityContainerElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string name    = Required(CsdlConstants.Attribute_Name);
            string extends = Optional(CsdlConstants.Attribute_Extends);

            if (entityContainerCount++ > 0)
            {
                this.ReportError(this.currentElement.Location, EdmErrorCode.MetadataDocumentCannotHaveMoreThanOneEntityContainer, Edm.Strings.CsdlParser_MetadataDocumentCannotHaveMoreThanOneEntityContainer);
            }

            return(new CsdlEntityContainer(
                       name,
                       extends,
                       childValues.ValuesOfType <CsdlEntitySet>(),
                       childValues.ValuesOfType <CsdlSingleton>(),
                       childValues.ValuesOfType <CsdlOperationImport>(),
                       element.Location));
        }
コード例 #28
0
        protected override void AnnotateItem(object result, XmlElementValueCollection childValues)
        {
            CsdlElement annotatedItem = result as CsdlElement;

            if (annotatedItem == null)
            {
                return;
            }

            foreach (var xmlAnnotation in this.currentElement.Annotations)
            {
                annotatedItem.AddAnnotation(new CsdlDirectValueAnnotation(xmlAnnotation.NamespaceName, xmlAnnotation.Name, xmlAnnotation.Value, xmlAnnotation.IsAttribute, xmlAnnotation.Location));
            }

            foreach (var annotation in childValues.ValuesOfType <CsdlAnnotation>())
            {
                annotatedItem.AddAnnotation(annotation);
            }
        }
コード例 #29
0
        private CsdlSchema OnSchemaElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string namespaceName = Optional(CsdlConstants.Attribute_Namespace) ?? string.Empty;
            string alias         = OptionalAlias(CsdlConstants.Attribute_Alias);

            CsdlSchema result =
                new CsdlSchema(
                    namespaceName,
                    alias,
                    this.artifactVersion,
                    childValues.ValuesOfType <CsdlStructuredType>(),
                    childValues.ValuesOfType <CsdlEnumType>(),
                    childValues.ValuesOfType <CsdlOperation>(),
                    childValues.ValuesOfType <CsdlTerm>(),
                    childValues.ValuesOfType <CsdlEntityContainer>(),
                    childValues.ValuesOfType <CsdlAnnotations>(),
                    childValues.ValuesOfType <CsdlTypeDefinition>(),
                    element.Location);

            return(result);
        }
コード例 #30
0
        private CsdlOperationParameter OnParameterElement(XmlElementInfo element, XmlElementValueCollection childValues)
        {
            string name         = Required(CsdlConstants.Attribute_Name);
            string typeName     = OptionalType(CsdlConstants.Attribute_Type);
            string defaultValue = null;
            bool   isOptional   = false;

            CsdlTypeReference type = this.ParseTypeReference(typeName, childValues, element.Location, Optionality.Required);

            // TODO (Issue #855): handle out-of-line annotations
            XmlElementValue optionalAnnotationValue = childValues.Where(c =>
                                                                        c is XmlElementValue <CsdlAnnotation> &&
                                                                        (c.ValueAs <CsdlAnnotation>().Term == CoreVocabularyModel.OptionalParameterTerm.ShortQualifiedName() ||
                                                                         c.ValueAs <CsdlAnnotation>().Term == CoreVocabularyModel.OptionalParameterTerm.FullName()))
                                                      .FirstOrDefault();

            if (optionalAnnotationValue != null)
            {
                isOptional = true;
                CsdlRecordExpression optionalValueExpression = optionalAnnotationValue.ValueAs <CsdlAnnotation>().Expression as CsdlRecordExpression;
                if (optionalValueExpression != null)
                {
                    foreach (CsdlPropertyValue property in optionalValueExpression.PropertyValues)
                    {
                        CsdlConstantExpression propertyValue = property.Expression as CsdlConstantExpression;
                        if (propertyValue != null)
                        {
                            if (property.Property == CsdlConstants.Attribute_DefaultValue)
                            {
                                defaultValue = propertyValue.Value;
                            }
                        }
                    }
                }

                childValues.Remove(optionalAnnotationValue);
            }

            return(new CsdlOperationParameter(name, type, element.Location, isOptional, defaultValue));
        }