public CsdlAssociationEnd(string role, CsdlTypeReference type, EdmMultiplicity multiplicity, CsdlOnDelete onDelete, CsdlDocumentation documentation, CsdlLocation location) : base(role, documentation, location) { this.type = type; this.multiplicity = multiplicity; this.onDelete = onDelete; }
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); }
/// <summary> /// Parse the IsOf expression using <see cref="JsonElement"/>. /// </summary> /// <param name="element">The input JSON element.</param> /// <param name="context">The parser context.</param> /// <param name="isOfExp">The built IsOf expression.</param> /// <returns>true/false</returns> private static bool BuildIsOfExpression(JsonElement element, JsonParserContext context, out CsdlIsTypeExpression isOfExp) { Debug.Assert(context != null); isOfExp = null; // Is-of expressions are represented as an object with a member $IsOf whose value is an annotation expression, JsonElement propertyValue; if (element.ValueKind != JsonValueKind.Object || !element.TryGetProperty("$IsOf", out propertyValue)) { return(false); } // whose value is an annotation expression, CsdlExpressionBase expression = propertyValue.ProcessProperty("$IsOf", context, ParseExpression); // a member $Type whose value is a string containing an qualified type name, and optionally a member $Collection with a value of true. // If the specified type is a primitive type or a collection of primitive types, // the facet members $MaxLength, $Unicode, $Precision, $Scale, and $SRID MAY be specified if applicable to the specified primitive type. // If the facet members are not specified, their values are considered unspecified. CsdlTypeReference typeReference = CsdlJsonParseHelper.ParseCsdlTypeReference(element, context); isOfExp = new CsdlIsTypeExpression(typeReference, expression, context.Location()); return(true); }
public CsdlProperty(string name, CsdlTypeReference type, bool isFixedConcurrency, string defaultValue, CsdlDocumentation documentation, CsdlLocation location) : base(name, documentation, location) { this.type = type; this.isFixedConcurrency = isFixedConcurrency; this.defaultValue = defaultValue; }
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)); }
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)); }
public CsdlTerm(string name, CsdlTypeReference type, string appliesTo, string defaultValue, CsdlDocumentation documentation, CsdlLocation location) : base(name, documentation, location) { this.type = type; this.appliesTo = appliesTo; this.defaultValue = defaultValue; }
internal static CsdlFunction Function( string name, CsdlOperationParameter[] parameters = default(CsdlOperationParameter[]), CsdlTypeReference typeReference = null, bool isBound = false, string entitySetPath = null, bool isComposable = false, CsdlDocumentation documentation = null, CsdlLocation location = null) { if (parameters == null) { parameters = new CsdlOperationParameter[] { }; } return(new CsdlFunction( name, parameters, typeReference, isBound, entitySetPath, isComposable, documentation, location)); }
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)); }
private CsdlOperationParameter OnFunctionImportParameterElement(XmlElementInfo element, XmlElementValueCollection childValues) { string name = Required(CsdlConstants.Attribute_Name); string typeName = RequiredType(CsdlConstants.Attribute_Type); CsdlTypeReference type = this.ParseTypeReference(typeName, null, element.Location, Optionality.Required); return(new CsdlOperationParameter(name, type, element.Location)); }
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)); }
/// <summary> /// Parse the record expression expression using <see cref="JsonElement"/>. /// </summary> /// <param name="element">The input JSON element.</param> /// <param name="context">The parser context.</param> /// <returns>the built record expression.</returns> private static CsdlRecordExpression ParseRecordExpression(JsonElement element, JsonParserContext context) { Debug.Assert(context != null); // A record expression MAY specify the structured type of its result, which MUST be an entity type or complex type in scope. // If not explicitly specified, the type is derived from the expression’s context // The type of a record expression is represented as the @type control information // for example: "@type": "https://example.org/vocabs/person#org.example.person.Manager", // So far, ODL doesn't support the type "@type" with relative path, only supports like "#Model.VipCustomer", or without # // for 4.0, this name MUST be prefixed with the hash symbol (#); // or non-OData 4.0 payloads, built-in primitive type values SHOULD be represented without the hash symbol, // but consumers of 4.01 or greater payloads MUST support values with or without the hash symbol. CsdlTypeReference typeReference = null; if (element.TryGetProperty("@type", out JsonElement typeValue)) { // Try to build the type. The type should be "Complex type" or "Entity Type". string typeName = typeValue.ProcessProperty("@type", context, (e, c) => e.ParseAsString(c)); int index = typeName.IndexOf('#'); if (index >= 0) { typeName = typeName.Substring(index + 1); // remove the "#" } typeReference = new CsdlNamedTypeReference(typeName, true, context.Location()); } IList <CsdlPropertyValue> propertyValues = new List <CsdlPropertyValue>(); element.ParseAsObject(context, (propertyName, propertyValue) => { // skips the @type, because it's processed above. if (propertyName == "@type") { return; } // It MAY contain annotations for itself and its members. Annotations for record members are prefixed with the member name. // So far, it's not supported. So report non-fatal error for all the annotations on record. if (propertyName.IndexOf('@') != -1) { context.ReportError(EdmErrorCode.UnsupportedElement, Strings.CsdlJsonParser_UnsupportedJsonMember(context.Path)); return; } CsdlExpressionBase propertyValueExpression = ParseExpression(propertyValue, context); propertyValues.Add(new CsdlPropertyValue(propertyName, propertyValueExpression, context.Location())); }); return(new CsdlRecordExpression(typeReference, propertyValues, context.Location())); }
public static CsdlTypeReference ParseCsdlTypeReference(JsonElement element, JsonParserContext context) { Debug.Assert(element.ValueKind == JsonValueKind.Object); // $Type // For single-valued terms the value of $Type is the qualified name of the property/term�s type. // For collection-valued terms the value of $Type is the qualified name of the term�s item type, and the member $Collection MUST be present with the literal value true. // Absence of the $Type member means the type is Edm.String. string typeName = element.ParseOptionalProperty("$Type", context, (v, p) => v.ParseAsString(p)); typeName = typeName == null ? "Edm.String" : typeName; // $Collection // For collection-valued properties the value of $Type is the qualified name of the property�s item type, // and the member $Collection MUST be present with the literal value true. bool?collection = element.ParseOptionalProperty("$Collection", context, (v, p) => v.ParseAsBoolean(p)); // $Nullable, // The value of $Nullable is one of the Boolean literals true or false. Absence of the member means false. bool?isNullable = element.ParseOptionalProperty("$Nullable", context, (v, p) => v.ParseAsBoolean(p)); bool nullable = isNullable == null ? false : isNullable.Value; // $MaxLength, // The value of $MaxLength is a positive integer. // CSDL xml defines a symbolic value max that is only allowed in OData 4.0 responses. This symbolic value is not allowed in CDSL JSON documents at all. int?maxLength = element.ParseOptionalProperty("$MaxLength", context, (v, p) => v.ParseAsInteger(p)); // $Unicode, // The value of $Unicode is one of the Boolean literals true or false. Absence of the member means true. bool?unicode = element.ParseOptionalProperty("$Unicode", context, (v, p) => v.ParseAsBoolean(p)); // $Precision, // The value of $Precision is a number. int?precision = element.ParseOptionalProperty("$Precision", context, (v, p) => v.ParseAsInteger(p)); // $Scale, int?scale = element.ParseOptionalProperty("$Scale", context, (v, p) => v.ParseAsInteger(p)); // $SRID, // The value of $SRID is a string containing a number or the symbolic value variable. // So far, ODL doesn't support string of SRID. int?srid = element.ParseOptionalProperty("$SRID", context, (v, p) => v.ParseAsInteger(p)); CsdlLocation location = context.Location(); CsdlTypeReference csdlType = ParseNamedTypeReference(typeName, nullable, false, maxLength, unicode, precision, scale, srid, location); if (collection != null && collection.Value) { csdlType = new CsdlExpressionTypeReference(new CsdlCollectionType(csdlType, location), nullable, location); } return(csdlType); }
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)); }
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)); }
/// <summary> /// Parse the Cast expression using <see cref="JsonElement"/>. /// </summary> /// <param name="element">The input JSON element.</param> /// <param name="context">The parser context.</param> /// <param name="castExp">The built cast expression.</param> /// <returns>true/false.</returns> private static bool TryParseCastExpression(JsonElement element, JsonParserContext context, out CsdlCastExpression castExp) { Debug.Assert(context != null); castExp = null; // Cast expressions are represented as an object with a member $Cast JsonElement propertyValue; if (element.ValueKind != JsonValueKind.Object || !element.TryGetProperty("$Cast", out propertyValue)) { return(false); } // with a member $Cast whose value is an annotation expression CsdlExpressionBase expression = propertyValue.ProcessProperty("$Cast", context, ParseExpression); // a member $Type whose value is a string containing the qualified type name, and optionally a member $Collection with a value of true. CsdlTypeReference typeReference = CsdlJsonParseHelper.ParseCsdlTypeReference(element, context); castExp = new CsdlCastExpression(typeReference, expression, context.Location()); return(true); }
public CsdlValueTerm(string name, CsdlTypeReference type, CsdlDocumentation documentation, CsdlLocation location) : base(name, documentation, location) { this.type = type; }
internal static IEdmTypeReference WrapTypeReference(CsdlSemanticsSchema schema, CsdlTypeReference type) { CsdlNamedTypeReference reference = type as CsdlNamedTypeReference; if (reference != null) { CsdlPrimitiveTypeReference reference2 = reference as CsdlPrimitiveTypeReference; if (reference2 != null) { switch (reference2.Kind) { case EdmPrimitiveTypeKind.Binary: return(new CsdlSemanticsBinaryTypeReference(schema, (CsdlBinaryTypeReference)reference2)); case EdmPrimitiveTypeKind.Boolean: case EdmPrimitiveTypeKind.Byte: case EdmPrimitiveTypeKind.Double: case EdmPrimitiveTypeKind.Guid: case EdmPrimitiveTypeKind.Int16: case EdmPrimitiveTypeKind.Int32: case EdmPrimitiveTypeKind.Int64: case EdmPrimitiveTypeKind.SByte: case EdmPrimitiveTypeKind.Single: case EdmPrimitiveTypeKind.Stream: return(new CsdlSemanticsPrimitiveTypeReference(schema, reference2)); case EdmPrimitiveTypeKind.DateTime: case EdmPrimitiveTypeKind.DateTimeOffset: case EdmPrimitiveTypeKind.Time: return(new CsdlSemanticsTemporalTypeReference(schema, (CsdlTemporalTypeReference)reference2)); case EdmPrimitiveTypeKind.Decimal: return(new CsdlSemanticsDecimalTypeReference(schema, (CsdlDecimalTypeReference)reference2)); case EdmPrimitiveTypeKind.String: return(new CsdlSemanticsStringTypeReference(schema, (CsdlStringTypeReference)reference2)); case EdmPrimitiveTypeKind.Geography: case EdmPrimitiveTypeKind.GeographyPoint: case EdmPrimitiveTypeKind.GeographyLineString: case EdmPrimitiveTypeKind.GeographyPolygon: case EdmPrimitiveTypeKind.GeographyCollection: case EdmPrimitiveTypeKind.GeographyMultiPolygon: case EdmPrimitiveTypeKind.GeographyMultiLineString: case EdmPrimitiveTypeKind.GeographyMultiPoint: case EdmPrimitiveTypeKind.Geometry: case EdmPrimitiveTypeKind.GeometryPoint: case EdmPrimitiveTypeKind.GeometryLineString: case EdmPrimitiveTypeKind.GeometryPolygon: case EdmPrimitiveTypeKind.GeometryCollection: case EdmPrimitiveTypeKind.GeometryMultiPolygon: case EdmPrimitiveTypeKind.GeometryMultiLineString: case EdmPrimitiveTypeKind.GeometryMultiPoint: return(new CsdlSemanticsSpatialTypeReference(schema, (CsdlSpatialTypeReference)reference2)); } } return(new CsdlSemanticsNamedTypeReference(schema, reference)); } CsdlExpressionTypeReference expressionUsage = type as CsdlExpressionTypeReference; if (expressionUsage != null) { CsdlRowType typeExpression = expressionUsage.TypeExpression as CsdlRowType; if (typeExpression != null) { return(new CsdlSemanticsRowTypeExpression(expressionUsage, new CsdlSemanticsRowTypeDefinition(schema, typeExpression))); } CsdlCollectionType collection = expressionUsage.TypeExpression as CsdlCollectionType; if (collection != null) { return(new CsdlSemanticsCollectionTypeExpression(expressionUsage, new CsdlSemanticsCollectionTypeDefinition(schema, collection))); } CsdlEntityReferenceType entityTypeReference = expressionUsage.TypeExpression as CsdlEntityReferenceType; if (entityTypeReference != null) { return(new CsdlSemanticsEntityReferenceTypeExpression(expressionUsage, new CsdlSemanticsEntityReferenceTypeDefinition(schema, entityTypeReference))); } } return(null); }
public CsdlCollectionType(CsdlTypeReference elementType, CsdlLocation location) : base(location) { this.elementType = elementType; }
public CsdlFunctionParameter(string name, CsdlTypeReference type, EdmFunctionParameterMode mode, CsdlDocumentation documentation, CsdlLocation location) : base(name, documentation, location) { this.type = type; this.mode = mode; }
public CsdlEntityReferenceType(CsdlTypeReference entityType, CsdlLocation location) : base(location) { this.entityType = entityType; }
public CsdlOperationParameter(string name, CsdlTypeReference type, CsdlDocumentation documentation, CsdlLocation location) : base(name, documentation, location) { this.type = type; }
public CsdlIsTypeExpression(CsdlTypeReference type, CsdlExpressionBase operand, CsdlLocation location) : base(location) { this.type = type; this.operand = operand; }
public CsdlFunctionReturnType(CsdlTypeReference returnType, CsdlLocation location) : base(location) { this.returnType = returnType; }
public CsdlOperationParameter(string name, CsdlTypeReference type, CsdlLocation location, bool isOptional, string defaultValue) : this(name, type, location) { this.isOptional = isOptional; this.defaultValue = defaultValue; }
public CsdlProperty(string name, CsdlTypeReference type, string defaultValue, CsdlLocation location) : base(name, location) { this.type = type; this.defaultValue = defaultValue; }
internal static IEdmTypeReference WrapTypeReference(CsdlSemanticsSchema schema, CsdlTypeReference type) { var typeReference = type as CsdlNamedTypeReference; if (typeReference != null) { var primitiveReference = typeReference as CsdlPrimitiveTypeReference; if (primitiveReference != null) { switch (primitiveReference.Kind) { case EdmPrimitiveTypeKind.Boolean: case EdmPrimitiveTypeKind.Byte: case EdmPrimitiveTypeKind.Date: case EdmPrimitiveTypeKind.Double: case EdmPrimitiveTypeKind.Guid: case EdmPrimitiveTypeKind.Int16: case EdmPrimitiveTypeKind.Int32: case EdmPrimitiveTypeKind.Int64: case EdmPrimitiveTypeKind.SByte: case EdmPrimitiveTypeKind.Single: case EdmPrimitiveTypeKind.Stream: return(new CsdlSemanticsPrimitiveTypeReference(schema, primitiveReference)); case EdmPrimitiveTypeKind.Binary: return(new CsdlSemanticsBinaryTypeReference(schema, (CsdlBinaryTypeReference)primitiveReference)); case EdmPrimitiveTypeKind.DateTimeOffset: case EdmPrimitiveTypeKind.Duration: case EdmPrimitiveTypeKind.TimeOfDay: return(new CsdlSemanticsTemporalTypeReference(schema, (CsdlTemporalTypeReference)primitiveReference)); case EdmPrimitiveTypeKind.Decimal: return(new CsdlSemanticsDecimalTypeReference(schema, (CsdlDecimalTypeReference)primitiveReference)); case EdmPrimitiveTypeKind.String: return(new CsdlSemanticsStringTypeReference(schema, (CsdlStringTypeReference)primitiveReference)); case EdmPrimitiveTypeKind.Geography: case EdmPrimitiveTypeKind.GeographyPoint: case EdmPrimitiveTypeKind.GeographyLineString: case EdmPrimitiveTypeKind.GeographyPolygon: case EdmPrimitiveTypeKind.GeographyCollection: case EdmPrimitiveTypeKind.GeographyMultiPolygon: case EdmPrimitiveTypeKind.GeographyMultiLineString: case EdmPrimitiveTypeKind.GeographyMultiPoint: case EdmPrimitiveTypeKind.Geometry: case EdmPrimitiveTypeKind.GeometryPoint: case EdmPrimitiveTypeKind.GeometryLineString: case EdmPrimitiveTypeKind.GeometryPolygon: case EdmPrimitiveTypeKind.GeometryCollection: case EdmPrimitiveTypeKind.GeometryMultiPolygon: case EdmPrimitiveTypeKind.GeometryMultiLineString: case EdmPrimitiveTypeKind.GeometryMultiPoint: return(new CsdlSemanticsSpatialTypeReference(schema, (CsdlSpatialTypeReference)primitiveReference)); } } else { CsdlUntypedTypeReference csdlUntypedTypeReference = typeReference as CsdlUntypedTypeReference; if (csdlUntypedTypeReference != null) { return(new CsdlSemanticsUntypedTypeReference(schema, csdlUntypedTypeReference)); } if (schema.FindType(typeReference.FullName) is IEdmTypeDefinition) { return(new CsdlSemanticsTypeDefinitionReference(schema, typeReference)); } } return(new CsdlSemanticsNamedTypeReference(schema, typeReference)); } var typeExpression = type as CsdlExpressionTypeReference; if (typeExpression != null) { var collectionType = typeExpression.TypeExpression as CsdlCollectionType; if (collectionType != null) { return(new CsdlSemanticsCollectionTypeExpression(typeExpression, new CsdlSemanticsCollectionTypeDefinition(schema, collectionType))); } var entityReferenceType = typeExpression.TypeExpression as CsdlEntityReferenceType; if (entityReferenceType != null) { return(new CsdlSemanticsEntityReferenceTypeExpression(typeExpression, new CsdlSemanticsEntityReferenceTypeDefinition(schema, entityReferenceType))); } } return(null); }
public CsdlOperationReturnType(CsdlTypeReference returnType, CsdlLocation location) : base(location) { this.returnType = returnType; }