//***************************************************************************// // Visszaadja, hogy egy adott entitás rendelkezik-e attribútumokkal, vagy // // sem. Az ősosztály attribútumait figyelmen kívül hagyja. // // true, ha rendelkezik legalább egy UML-ben definiált attribútummal; // // egyébként false. // //***************************************************************************// proc HasAttributes(MClass) loop (MClass -> MAttribute) return "true"; end loop return "false"; end proc //***************************************************************************// // Segédproc, a GenerateXMLSection() template használja. Visszaadja, hogy // // kell-e temp lokális változót deklarálni, vagy sem. Ez attól függ, hogy az // // entitás rendelkezik-e attribútummal, vagy asszociációval, amit XML-ből // // be kell tölteni, vagy sem. // // true, ha szükséges temp változó deklarálni; egyébként false. // //***************************************************************************// proc NeedTemporaryXmlNode(MClass) if (HasAttributes([MClass]) == "true") return "true"; end if loop (MClass -> Role as StartRole -> MAssociation as CurrentAssoc -> MAssociationEnd as EndRole -> MClass as PartnerClass where (([StartRole.id] != [EndRole.id]) and GetStereoType([PartnerClass]) == "Entity")) if (HasAssociationClass([CurrentAssoc]) == "") if ([EndRole.multiplicity] == "1") return "true"; else if ([EndRole.multiplicity] == "0..1") if (([StartRole.multiplicity] == "1..*") or ([StartRole.multiplicity] == "*") or ([StartRole.multiplicity] == "0..*")) return "true"; end if end if end if end if end loop loop (MClass -> MAssociation as CurrentAssoc -> MAssociationEnd as StartRole -> MClass as StartClass where (GetStereoType([StartClass]) == "Entity") ) loop (CurrentAssoc -> MAssociationEnd as EndRole -> MClass as EndClass where([StartRole.id]<[EndRole.id] and GetStereoType([EndClass]) == "Entity" )) return "true"; end loop end loop return "false"; end proc //***************************************************************************// // Név és típus alapján elkészíti az XML DOM-ból való betöltést // //***************************************************************************// proc GenerateLoadFromXMLExpression(name, type) switch (ToLower([type])) case "integer": return "Int32.Parse(" [name] ".InnerText, LanguageContext.Current.RegionSettings)"; case "string": return [name] ".InnerText"; case "datetime": return "DateTime.Parse(" [name] ".InnerText, LanguageContext.Current.RegionSettings)"; case "boolean": return "Boolean.Parse(" [name] ".InnerText)"; case "char": //return [name] ".InnerText[0]"; return [name] ".InnerText"; case "double": return "Double.Parse(" [name] ".InnerText, LanguageContext.Current.RegionSettings)"; case "float": return "Double.Parse(" [name] ".InnerText, LanguageContext.Current.RegionSettings)"; case "id": return "Int32.Parse(" [name] ".InnerText, LanguageContext.Current.RegionSettings)"; case "dictionaryitem": return "Int32.Parse(" [name] ".InnerText, LanguageContext.Current.RegionSettings) /* XXX DictionaryItem */ "; case "binary": return "System.Convert.FromBase64String(" [name] ".InnerText)"; case "longstring": return "System.Text.UnicodeEncoding.Unicode.GetString(System.Convert.FromBase64String(" [name] ".InnerText))"; end switch return "/* ERROR: ismeretlen tipus: " [type] " */"; end proc //***************************************************************************// // Legenerálja a megadott entitás XML-lel kapcsolatos dolgait // //***************************************************************************// template GenerateXMLSection(MClass as ENTITY) #region XML támogatás protected override void DoLoadFromXml(XmlNode entityNode) { base.DoLoadFromXml(entityNode); [if (NeedTemporaryXmlNode([ENTITY]) == "true")] XmlNode current = null; [end if] [loop (ENTITY -> MAttribute as ATTRIBUTE where [ATTRIBUTE.name] != [ENTITY.name])] if ((current = entityNode.SelectSingleNode(\"./field\[@name='[ATTRIBUTE.name]'\]\")) != null) { [if (IsDefaultonlyAttribute([ATTRIBUTE]) == _True())] if (current.FirstChild.Name == "default") { [ATTRIBUTE.name] = [GetCSharpDefaultValueOfAttribute([ATTRIBUTE])]; } else { throw new InvalidEntityAttributeException("[ENTITY.name]", "[ATTRIBUTE.name]", EntityAttributeError.NotAllowed); } [else] if (current.FirstChild.Name == "null") { [if (IsAttributeRequired([ATTRIBUTE]) == _True())] [ATTRIBUTE.name] = [GetCSharpDefaultValueOfAttribute([ATTRIBUTE])]; [if (HasDefaultValue([ATTRIBUTE]) == "True")] [else] //kotelezo attirbutum de validalasnal majd elszall! m_[ATTRIBUTE.name]IsNull = true; [end if] [else] [ATTRIBUTE.name] = [GetCSharpDefaultValueOfAttribute([ATTRIBUTE])]; // XXX kell??? [if (HasDefaultValue([ATTRIBUTE]) == "True")] [else] [ATTRIBUTE.name]IsNull = true; [end if] [end if] } else { [ATTRIBUTE.name] = [GenerateLoadFromXMLExpression("current", [ATTRIBUTE.type])]; } [end if] } [end loop] [loop (ENTITY -> Role as STARTROLE -> MAssociation as CurrentAssoc -> MAssociationEnd as ENDROLE -> MClass as PartnerClass where (([STARTROLE.id] != [ENDROLE.id]) and GetStereoType([PartnerClass]) == "Entity"))] [if (HasAssociationClass([CurrentAssoc]) == "")] [if ([ENDROLE.multiplicity] == "1")] [if (IsA([PartnerClass], "User") == "True" and IsDefaultonlyAssociation([CurrentAssoc]) == "True")] if ((current = entityNode.SelectSingleNode(\"./field\[@name='[ConvertRoleToName([ENDROLE])]'\]\")) != null) { if (current.FirstChild.Name == "default") { this.Internal[ConvertRoleToName([ENDROLE])] = UserContext.Instance.UserID; } else { throw new InvalidEntityAttributeException("[ENTITY.name]", "[ConvertRoleToName([ENDROLE])]", EntityAttributeError.NotAllowed); } } [else] if ((current = entityNode.SelectSingleNode(\"./field\[@name='[ConvertRoleToName([ENDROLE])]'\]\")) != null) { this.Internal[ConvertRoleToName([ENDROLE])] = [GenerateLoadFromXMLExpression("current", "ID")]; // kötelező asszociáció } [end if] [else] [if ([ENDROLE.multiplicity] == "0..1")] [if (([STARTROLE.multiplicity] == "1..*") or ([STARTROLE.multiplicity] == "*") or ([STARTROLE.multiplicity] == "0..*"))] [if (IsA([PartnerClass], "User") == "True" and IsDefaultonlyAssociation([CurrentAssoc]) == "True")] if ((current = entityNode.SelectSingleNode(\"./field\[@name='[ConvertRoleToName([ENDROLE])]'\]\")) != null) { if (current.FirstChild.Name == "default") { this.Internal[ConvertRoleToName([ENDROLE])] = UserContext.Instance.UserID; } else { throw new InvalidEntityAttributeException("[ENTITY.name]", "[ConvertRoleToName([ENDROLE])]", EntityAttributeError.NotAllowed); } } [else] if ((current = entityNode.SelectSingleNode(\"./field\[@name='[ConvertRoleToName([ENDROLE])]'\]\")) != null) { if (current.FirstChild.Name == "null") { this.Internal[ConvertRoleToName([ENDROLE])] = [GetCSharpDefaultValueOfType("ID")]; } else { if (current.InnerText != "") { this.Internal[ConvertRoleToName([ENDROLE])] = [GenerateLoadFromXMLExpression("current", "ID")]; // nem kötelező asszociáció } else { this.Internal[ConvertRoleToName([ENDROLE])] = [GetCSharpDefaultValueOfType("ID")]; } } } [end if] [end if] [end if] [end if] [end if] [end loop] [loop (ENTITY -> MAssociation as CurrentAssoc -> MAssociationEnd as STARTROLE -> MClass as StartClass where (GetStereoType([StartClass]) == "Entity") )] [loop (CurrentAssoc -> MAssociationEnd as ENDROLE -> MClass as EndClass where([STARTROLE.id] < [ENDROLE.id] and GetStereoType([EndClass]) == "Entity" ))] if ((current = entityNode.SelectSingleNode(\"./field\[@name='[ConvertRoleToName([ENDROLE])]'\]\")) != null) { this.[ConvertRoleToName([ENDROLE])] = [GenerateLoadFromXMLExpression("current", "ID")]; // asszociációs osztályos asszociáció egyik végpontja } if ((current = entityNode.SelectSingleNode(\"./field\[@name='[ConvertRoleToName([STARTROLE])]'\]\")) != null) { this.[ConvertRoleToName([STARTROLE])] = [GenerateLoadFromXMLExpression("current", "ID")]; // asszociációs osztályos asszociáció másik végpontja } [end loop] [end loop] } protected override void DoSaveToXml(EntityXMLAdapter adapter) { base.DoSaveToXml(adapter); [GenerateEntitySaveAllAttributes([ENTITY], "adapter")] [GenerateEntitySaveAllAssociations([ENTITY], "adapter")] } #endregion end template //***************************************************************************// // Legenerálja azt a kódtöredéket, ami egy adott entitás összes attribútumát // // XML-be sorosítja. // //***************************************************************************// template GenerateEntitySaveAllAttributes(MClass as ENTITY, ADAPTERNAME) // [GetEntityName([ENTITY])] attribútumai [loop (ENTITY -> MAttribute as ATTRIBUTE)] [if ([ATTRIBUTE.type] == "DictionaryItem")] EntityUtil.WriteDictionaryItemXml([ADAPTERNAME], "[ATTRIBUTE.name]", "[ATTRIBUTE.defaultValue]", m_[ATTRIBUTE.name], m_[ATTRIBUTE.name]IsNull); [else] EntityUtil.[GetWriteXmlMethod([ATTRIBUTE.type])]([ADAPTERNAME], "[ATTRIBUTE.name]", m_[ATTRIBUTE.name], m_[ATTRIBUTE.name]IsNull); [end if] [/* [if ([ATTRIBUTE.type] == "ID" or [ATTRIBUTE.type] == "String" or [ATTRIBUTE.type] == "Binary")] if (m_[ATTRIBUTE.name]IsNull == false) { [GenerateEntityWrapperSaveToXMLExpression([ADAPTERNAME], [ATTRIBUTE.name], [ATTRIBUTE.type], "m_" [ATTRIBUTE.name], "")] } else { [GenerateEntityWrapperSaveToXMLExpression([ADAPTERNAME], [ATTRIBUTE.name], [ATTRIBUTE.type], "(object)null", "")] } [else] [if ([ATTRIBUTE.type] == "DictionaryItem")] if (m_[ATTRIBUTE.name]IsNull == false) { [GenerateEntityWrapperSaveToXMLExpression([ADAPTERNAME], [ATTRIBUTE.name], [ATTRIBUTE.type], "m_" [ATTRIBUTE.name], [ATTRIBUTE.defaultValue])] } else { [GenerateEntityWrapperSaveToXMLExpression([ADAPTERNAME], [ATTRIBUTE.name], [ATTRIBUTE.type], "(object)null", [ATTRIBUTE.defaultValue])] } [else] if (m_[ATTRIBUTE.name]IsNull == false) { [GenerateEntityWrapperSaveToXMLExpression([ADAPTERNAME], [ATTRIBUTE.name], [ATTRIBUTE.type], "m_" [ATTRIBUTE.name], "")] } else { [GenerateEntityWrapperSaveToXMLExpression([ADAPTERNAME], [ATTRIBUTE.name], [ATTRIBUTE.type], "(object)null", "")] } [end if] [end if] */] [end loop] end template //***************************************************************************// //***************************************************************************// proc GetWriteXmlMethod(ATTRIBUTETYPE) switch (ToLower([ATTRIBUTETYPE])) case "integer": return "WriteIntegerXml"; case "string": return "WriteStringXml"; case "datetime": return "WriteDateTimeXml"; case "boolean": return "WriteBooleanXml"; case "char": return "WriteCharXml"; case "double": return "WriteDoubleXml"; case "float": return "WriteDoubleXml"; case "id": return "WriteIntegerXml"; case "binary": return "WriteBinaryXml"; case "longstring": return "WriteLongStringXml"; end switch return "/* ERROR: ismeretlen tipus: " [ATTRIBUTETYPE] " */"; end proc //***************************************************************************// // Legenerálja azt a kódtöredéket, ami egy adott entitás összes // // asszociációját XML-be sorosítja. // //***************************************************************************// template GenerateEntitySaveAllAssociations(MClass as ENTITY, ADAPTERNAME) // [GetEntityName([ENTITY])] asszociációi [loop (ENTITY -> Role as STARTROLE -> MAssociation as CURRENTASSOCIATION -> MAssociationEnd as ENDROLE -> MClass as PARTNER where (([STARTROLE.id] != [ENDROLE.id]) and GetStereoType([PARTNER]) == "Entity"))] [if (HasAssociationClass([CURRENTASSOCIATION]) == "")] [if ([ENDROLE.multiplicity] == "1" or [ENDROLE.multiplicity] == "0..1")] EntityUtil.WriteAssociationIdXml([ADAPTERNAME], "[GetRoleName([ENDROLE])]", m_[ConvertRoleToName([ENDROLE])], (m_[ConvertRoleToName([ENDROLE])] == [GetCSharpDefaultValueOfType("ID")])); [/* if (m_[ConvertRoleToName([ENDROLE])] != [GetCSharpDefaultValueOfType("ID")]) { [GenerateEntityWrapperSaveToXMLExpression([ADAPTERNAME], GetRoleName([ENDROLE]), "AssociationID", "this.m_" ConvertRoleToName([ENDROLE]), "")] } else { [GenerateEntityWrapperSaveToXMLExpression([ADAPTERNAME], GetRoleName([ENDROLE]), "AssociationID", "(object)null", "")] } */] [end if] [end if] [end loop] [loop (ENTITY -> MAssociation as CURRENTASSOCIATION -> MAssociationEnd as STARTROLE -> MClass as STARTCLASS where (GetStereoType([STARTCLASS]) == "Entity") )] [loop (CURRENTASSOCIATION -> MAssociationEnd as ENDROLE -> MClass as ENDCLASS where([STARTROLE.id] < [ENDROLE.id] and GetStereoType([ENDCLASS]) == "Entity" ))] EntityUtil.WriteAssociationIdXml([ADAPTERNAME], "[GetRoleName([STARTROLE])]", m_[ConvertRoleToName([STARTROLE])], (m_[ConvertRoleToName([STARTROLE])] == [GetCSharpDefaultValueOfType("ID")])); EntityUtil.WriteAssociationIdXml([ADAPTERNAME], "[GetRoleName([ENDROLE])]", m_[ConvertRoleToName([ENDROLE])], (m_[ConvertRoleToName([ENDROLE])] == [GetCSharpDefaultValueOfType("ID")])); [/* if (m_[ConvertRoleToName([STARTROLE])] != [GetCSharpDefaultValueOfType("ID")]) { [GenerateEntityWrapperSaveToXMLExpression([ADAPTERNAME], GetRoleName([STARTROLE]), "AssociationID", "this.m_" ConvertRoleToName([STARTROLE]), "")] } else { [GenerateEntityWrapperSaveToXMLExpression([ADAPTERNAME], GetRoleName([STARTROLE]), "AssociationID", "(object)null", "")] } if (m_[ConvertRoleToName([ENDROLE])] != [GetCSharpDefaultValueOfType("ID")]) { [GenerateEntityWrapperSaveToXMLExpression([ADAPTERNAME], GetRoleName([ENDROLE]), "AssociationID", "this.m_" ConvertRoleToName([ENDROLE]), "")] } else { [GenerateEntityWrapperSaveToXMLExpression([ADAPTERNAME], GetRoleName([ENDROLE]), "AssociationID", "(object)null", "")] } */] [end loop] [end loop] end template