public void GetContent(CompilerContext context, ParseTreeNode parseNode) { #region Extract type and attribute //if (parseNode.ChildNodes.Count != 4) // throw new Exception("This is not a [Type].[Attribute] definition: " + parseNode.ChildNodes[0].ToString()); _TypeName = parseNode.ChildNodes[0].Token.ValueString; _TypeAttributeName = parseNode.ChildNodes[2].Token.ValueString; #endregion _EdgeType = new EdgeTypeSetOfReferences(); _AttributeName = parseNode.ChildNodes[3].Token.ValueString; BackwardEdgeDefinition = new BackwardEdgeDefinition(_AttributeName, _TypeName, _TypeAttributeName, _EdgeType); }
public Exceptional<TypeAttribute> CreateBackwardEdgeAttribute(BackwardEdgeDefinition myBackwardEdgeNode, GraphDBType myDBTypeStream, UInt16 beAttrCounter = 0) { var edgeType = GetTypeByName(myBackwardEdgeNode.TypeName); if (edgeType == null) return new Exceptional<TypeAttribute>(new Error_TypeDoesNotExist(myBackwardEdgeNode.TypeName)); var edgeAttribute = edgeType.GetTypeAttributeByName(myBackwardEdgeNode.TypeAttributeName); //error if the attribute does not exist #region if (edgeAttribute == null) { return new Exceptional<TypeAttribute>(new Error_AttributeIsNotDefined(edgeType.Name, myBackwardEdgeNode.TypeAttributeName)); } #endregion //error if the attribute does not represent non userdefined content #region if (!edgeAttribute.GetDBType(this).IsUserDefined) { return new Exceptional<TypeAttribute>(new Error_BackwardEdgesForNotReferenceAttributeTypesAreNotAllowed(myBackwardEdgeNode.TypeAttributeName)); } #endregion //invalid backwardEdge destination #region if (edgeAttribute.GetDBType(this) != myDBTypeStream) return new Exceptional<TypeAttribute>(new Error_BackwardEdgeDestinationIsInvalid(myDBTypeStream.Name, myBackwardEdgeNode.TypeAttributeName)); #endregion //error if there is already an be attribute on the to be changed type that points to the same destination #region var edgeKey = new EdgeKey(edgeType.UUID, edgeAttribute.UUID); if (myDBTypeStream.Attributes.Exists(aKV => aKV.Value.IsBackwardEdge && (aKV.Value.BackwardEdgeDefinition == edgeKey))) { return new Exceptional<TypeAttribute>(new Error_BackwardEdgeAlreadyExist(myDBTypeStream, edgeType.Name, edgeAttribute.Name)); } #endregion //error if the backwardEdge points to a backward edge #region var beDestinationAttribute = edgeKey.GetTypeAndAttributeInformation(this).Item2; if (beDestinationAttribute.IsBackwardEdge) return new Exceptional<TypeAttribute>(new Error_BackwardEdgeAlreadyExist(myDBTypeStream, edgeType.Name, edgeAttribute.Name)); #endregion var ta = new TypeAttribute(Convert.ToUInt16(beAttrCounter + DBConstants.DefaultBackwardEdgeIDStart)); ta.DBTypeUUID = DBBackwardEdgeType.UUID; ta.BackwardEdgeDefinition = edgeKey; ta.KindOfType = KindsOfType.SetOfReferences; ta.Name = myBackwardEdgeNode.AttributeName; ta.EdgeType = myBackwardEdgeNode.EdgeType.GetNewInstance(); ta.TypeCharacteristics.IsBackwardEdge = true; ta.RelatedGraphDBTypeUUID = myDBTypeStream.UUID; return new Exceptional<TypeAttribute>(ta); }