protected void HandleRelations(ValueObjectConfig config, IMap <String, IList <XElement> > configDetails) { IList <XElement> elementTypes = configDetails.Get(XmlConstants.RELATION.LocalName); if (elementTypes != null) { for (int i = elementTypes.Count; i-- > 0;) { XElement entry = elementTypes[i]; String memberName = XmlConfigUtil.GetRequiredAttribute(entry, XmlConstants.NAME); if (config.IsIgnoredMember(memberName)) { continue; } config.SetValueObjectMemberType(memberName, ValueObjectMemberType.RELATION); bool holdsListType = XmlConfigUtil.AttributeIsTrue(entry, XmlConstants.LIST_TYPE); if (holdsListType) { config.AddListTypeMember(memberName); } String elementTypeName = XmlConfigUtil.GetAttribute(entry, XmlConstants.TARGET_VALUE_OBJECT); if (elementTypeName.Length > 0) { Type elementType = XmlConfigUtil.GetTypeForName(elementTypeName); config.PutMemberType(memberName, elementType); } } } }
protected void HandlePrimitiveCollections(ValueObjectConfig config, IMap <String, IList <XElement> > configDetails) { IList <XElement> memberTags = configDetails.Get(XmlConstants.BASIC.LocalName); if (memberTags == null) { return; } for (int j = memberTags.Count; j-- > 0;) { XElement element = memberTags[j]; String memberName = XmlConfigUtil.GetRequiredAttribute(element, XmlConstants.NAME); if (config.IsIgnoredMember(memberName)) { continue; } config.SetValueObjectMemberType(memberName, ValueObjectMemberType.BASIC); String targetElementTypeName = XmlConfigUtil.GetAttribute(element, XmlConstants.TARGET_ELEMENT_TYPE); if (targetElementTypeName.Length == 0) { continue; } Type elementType = XmlConfigUtil.GetTypeForName(targetElementTypeName); config.PutMemberType(memberName, elementType); } }
protected ILinkConfig ReadIndependentLinkConfig(XElement linkTag) { String alias = XmlConfigUtil.GetRequiredAttribute(linkTag, XmlConstants.ALIAS); IndependentLinkConfig link = new IndependentLinkConfig(alias); String cascadeDeleteRaw = XmlConfigUtil.GetAttribute(linkTag, XmlConstants.CASCADE_DELETE); if (cascadeDeleteRaw.Length > 0) { CascadeDeleteDirection cascadeDelete = (CascadeDeleteDirection)Enum.Parse(typeof(CascadeDeleteDirection), cascadeDeleteRaw, true); link.CascadeDeleteDirection = cascadeDelete; } String leftStr = XmlConfigUtil.GetAttribute(linkTag, XmlConstants.LEFT); if (leftStr.Length > 0) { Type left = XmlConfigUtil.GetTypeForName(leftStr); link.Left = left; } String rightStr = XmlConfigUtil.GetAttribute(linkTag, XmlConstants.RIGHT); if (rightStr.Length > 0) { Type right = XmlConfigUtil.GetTypeForName(rightStr); link.Right = right; } return(link); }
protected Type ResolveEntityType(XElement item) { IMap <String, IList <XElement> > configs = XmlConfigUtil.ChildrenToElementMap(item); if (!configs.ContainsKey(XmlConstants.VALUE_OBJECT.LocalName)) { return(null); } String entityTypeName = XmlConfigUtil.GetRequiredAttribute(item, XmlConstants.CLASS); return(XmlConfigUtil.GetTypeForName(entityTypeName)); }
protected void ConsumeConfigs(IEntityMetaData metaData, IList <XElement> entities) { for (int i = entities.Count; i-- > 0;) { XElement item = entities[i]; IMap <String, IList <XElement> > configs = XmlConfigUtil.ChildrenToElementMap(item); IList <XElement> voConfigs = configs.Get(XmlConstants.VALUE_OBJECT.LocalName); for (int j = voConfigs.Count; j-- > 0;) { XElement voConfig = voConfigs[j]; String valueTypeName = XmlConfigUtil.GetRequiredAttribute(voConfig, XmlConstants.CLASS); Type valueType = XmlConfigUtil.GetTypeForName(valueTypeName); bool exists = false; foreach (IValueObjectConfig conf in managedValueObjectConfigs) { if (conf.ValueType.Equals(valueType) && conf.EntityType.Equals(metaData.EntityType)) { exists = true; break; } } if (exists) { continue; } ValueObjectConfig config = new ValueObjectConfig(); config.EntityType = metaData.EntityType; config.ValueType = valueType; HandleMembers(config, voConfig, metaData); managedValueObjectConfigs.Add(config); ValueObjectConfigExtendable.RegisterValueObjectConfig(config); } } }
protected EntityConfig ReadEntityConfig(XElement entityTag, IMap <String, ILinkConfig> nameToLinkMap) { String entityTypeName = XmlConfigUtil.GetRequiredAttribute(entityTag, XmlConstants.CLASS); try { Type entityType = XmlConfigUtil.GetTypeForName(entityTypeName); Type realType = ProxyHelper.GetRealType(entityType); EntityConfig entityConfig = new EntityConfig(entityType, realType); bool localEntity = !entityTag.Name.Equals(XmlConstants.EXTERNAL_ENTITY); entityConfig.Local = localEntity; IMap <String, IList <XElement> > attributeMap = null; IMap <String, IList <XElement> > entityDefs = XmlConfigUtil.ChildrenToElementMap(entityTag); if (entityDefs.ContainsKey(XmlConstants.TABLE.LocalName)) { String specifiedTableName = XmlConfigUtil.GetRequiredAttribute(entityDefs.Get(XmlConstants.TABLE.LocalName)[0], XmlConstants.NAME); entityConfig.TableName = specifiedTableName; } if (entityDefs.ContainsKey(XmlConstants.PERMISSION_GROUP.LocalName)) { String permissionGroupName = XmlConfigUtil.GetRequiredAttribute(entityDefs.Get(XmlConstants.PERMISSION_GROUP.LocalName)[0], XmlConstants.NAME); entityConfig.PermissionGroupName = permissionGroupName; } if (entityDefs.ContainsKey(XmlConstants.SEQ.LocalName)) { String sequenceName = XmlConfigUtil.GetRequiredAttribute(entityDefs.Get(XmlConstants.SEQ.LocalName)[0], XmlConstants.NAME); entityConfig.SequenceName = sequenceName; } if (attributeMap.ContainsKey(XmlConstants.DESCRIMINATOR.LocalName)) { String descriminatorName = XmlConfigUtil.GetRequiredAttribute(entityDefs.Get(XmlConstants.DESCRIMINATOR.LocalName)[0], XmlConstants.NAME); entityConfig.DescriminatorName = descriminatorName; } if (entityDefs.ContainsKey(XmlConstants.ATTR.LocalName)) { attributeMap = XmlConfigUtil.ToElementMap(entityDefs.Get(XmlConstants.ATTR.LocalName)[0].Elements()); } bool versionRequired = true; if (attributeMap != null) { IMap <String, MemberConfig> allIdMemberConfigs = new HashMap <String, MemberConfig>(); if (attributeMap.ContainsKey(XmlConstants.ID.LocalName)) { MemberConfig idMemberConfig = ReadUniqueMemberConfig(XmlConstants.ID.LocalName, attributeMap); entityConfig.IdMemberConfig = idMemberConfig; allIdMemberConfigs.Put(idMemberConfig.Name, idMemberConfig); } else if (attributeMap.ContainsKey(XmlConstants.ID_COMP.LocalName)) { XElement memberElement = attributeMap.Get(XmlConstants.ID_COMP.LocalName)[0]; IMemberConfig idMemberConfig = ReadCompositeMemberConfig(memberElement, allIdMemberConfigs); entityConfig.IdMemberConfig = idMemberConfig; } else if (!localEntity) { throw new ArgumentException("ID member name has to be set on external entities"); } if (attributeMap.ContainsKey(XmlConstants.ALT_ID.LocalName)) { IList <XElement> altIds = attributeMap.Get(XmlConstants.ALT_ID.LocalName); for (int j = altIds.Count; j-- > 0;) { XElement memberElement = altIds[j]; MemberConfig memberConfig = ReadMemberConfig(memberElement); memberConfig.AlternateId = true; entityConfig.AddMemberConfig(memberConfig); allIdMemberConfigs.Put(memberConfig.Name, memberConfig); } } if (attributeMap.ContainsKey(XmlConstants.ALT_ID_COMP.LocalName)) { IList <XElement> altIdsComp = attributeMap.Get(XmlConstants.ALT_ID_COMP.LocalName); for (int j = altIdsComp.Count; j-- > 0;) { XElement memberElement = altIdsComp[j]; CompositeMemberConfig memberConfig = ReadCompositeMemberConfig(memberElement, allIdMemberConfigs); memberConfig.AlternateId = true; entityConfig.AddMemberConfig(memberConfig); } } if (attributeMap.ContainsKey(XmlConstants.VERSION.LocalName)) { MemberConfig versionMemberConfig = ReadUniqueMemberConfig(XmlConstants.VERSION.LocalName, attributeMap); entityConfig.VersionMemberConfig = versionMemberConfig; } else if (attributeMap.ContainsKey(XmlConstants.NO_VERSION.LocalName)) { versionRequired = false; } else if (!localEntity) { throw new ArgumentException("Version member name has to be set on external entities"); } if (attributeMap.ContainsKey(XmlConstants.CREATED_BY.LocalName)) { MemberConfig createdByMemberConfig = ReadUniqueMemberConfig(XmlConstants.CREATED_BY.LocalName, attributeMap); entityConfig.CreatedByMemberConfig = createdByMemberConfig; } if (attributeMap.ContainsKey(XmlConstants.CREATED_ON.LocalName)) { MemberConfig createdOnMemberConfig = ReadUniqueMemberConfig(XmlConstants.CREATED_ON.LocalName, attributeMap); entityConfig.CreatedOnMemberConfig = createdOnMemberConfig; } if (attributeMap.ContainsKey(XmlConstants.UPDATED_BY.LocalName)) { MemberConfig updatedByMemberConfig = ReadUniqueMemberConfig(XmlConstants.UPDATED_BY.LocalName, attributeMap); entityConfig.UpdatedByMemberConfig = updatedByMemberConfig; } if (attributeMap.ContainsKey(XmlConstants.UPDATED_ON.LocalName)) { MemberConfig updatedOnMemberConfig = ReadUniqueMemberConfig(XmlConstants.UPDATED_ON.LocalName, attributeMap); entityConfig.UpdatedOnMemberConfig = updatedOnMemberConfig; } if (attributeMap.ContainsKey(XmlConstants.BASIC.LocalName)) { IList <XElement> basicAttrs = attributeMap.Get(XmlConstants.BASIC.LocalName); for (int j = basicAttrs.Count; j-- > 0;) { XElement memberElement = basicAttrs[j]; MemberConfig memberConfig = ReadMemberConfig(memberElement); entityConfig.AddMemberConfig(memberConfig); } } if (attributeMap.ContainsKey(XmlConstants.IGNORE.LocalName)) { IList <XElement> ignoreAttrs = attributeMap.Get(XmlConstants.IGNORE.LocalName); for (int j = ignoreAttrs.Count; j-- > 0;) { XElement ignoreElement = ignoreAttrs[j]; MemberConfig memberConfig = ReadMemberConfig(ignoreElement); memberConfig.Ignore = true; entityConfig.AddMemberConfig(memberConfig); } } if (attributeMap.ContainsKey(XmlConstants.RELATION.LocalName)) { IList <XElement> relationAttrs = attributeMap.Get(XmlConstants.RELATION.LocalName); for (int j = relationAttrs.Count; j-- > 0;) { XElement relationElement = relationAttrs[j]; IRelationConfig relationConfig = ReadRelationConfig(relationElement, nameToLinkMap); entityConfig.AddRelationConfig(relationConfig); } } } entityConfig.VersionRequired = versionRequired; return(entityConfig); } catch (Exception e) { throw RuntimeExceptionUtil.Mask(e, "Error occured while processing mapping for entity: " + entityTypeName); } }