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 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 MemberConfig ReadMemberConfig(XElement memberElement) { String memberName = XmlConfigUtil.GetRequiredAttribute(memberElement, XmlConstants.NAME); MemberConfig memberConfig = new MemberConfig(memberName); String columnName = XmlConfigUtil.GetAttribute(memberElement, XmlConstants.COLUMN); if (columnName.Length > 0) { memberConfig.ColumnName = columnName; } String transientValue = XmlConfigUtil.GetAttribute(memberElement, XmlConstants.TRANSIENT); if (transientValue.Length != 0) { memberConfig.Transient = Boolean.Parse(transientValue); } String definedByValue = XmlConfigUtil.GetAttribute(memberElement, XmlConstants.DEFINED_BY); if (definedByValue.Length != 0) { memberConfig.DefinedBy = definedByValue; } return(memberConfig); }
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 void HandleMemberMappings(ValueObjectConfig config, IMap <String, IList <XElement> > configDetails, IEntityMetaData metaData) { Type entityType = config.EntityType; Type valueType = config.ValueType; IMap <String, IPropertyInfo> entityPropertyMap = PropertyInfoProvider.GetPropertyMap(entityType); IMap <String, IPropertyInfo> valuePropertyMap = PropertyInfoProvider.GetPropertyMap(valueType); for (int i = memberTagNames.Length; i-- > 0;) { String memberTagName = memberTagNames[i].LocalName; IList <XElement> memberTags = configDetails.Get(memberTagName); if (memberTags == null) { continue; } for (int j = memberTags.Count; j-- > 0;) { XElement element = memberTags[j]; String memberName = XmlConfigUtil.GetRequiredAttribute(element, XmlConstants.NAME); if (config.IsIgnoredMember(memberName)) { continue; } if (RuntimeValidationActive && !IsPropertyResolvable(valueType, valuePropertyMap, memberName, null)) { throw new ArgumentException("Value type property '" + valueType.Name + "." + memberName + "' not found"); } bool holdsListType = XmlConfigUtil.AttributeIsTrue(element, XmlConstants.LIST_TYPE); if (holdsListType) { config.AddListTypeMember(memberName); } String entityMemberName = XmlConfigUtil.GetAttribute(element, XmlConstants.NAME_IN_ENTITY); if (entityMemberName.Length == 0) { entityMemberName = memberName; } else { config.PutValueObjectMemberName(entityMemberName, memberName); } if (RuntimeValidationActive && !IsPropertyResolvable(entityType, entityPropertyMap, entityMemberName, metaData)) { throw new ArgumentException("Entity type property '" + entityType.Name + "." + entityMemberName + "' not found while configuring value type '" + valueType.Name + "'"); } } } }
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 HandleIgnoredMembers(ValueObjectConfig config, IMap <String, IList <XElement> > configDetails) { IList <XElement> memberTags = configDetails.Get(XmlConstants.IGNORE.LocalName); if (memberTags == null) { return; } for (int j = memberTags.Count; j-- > 0;) { XElement element = memberTags[j]; String memberName = XmlConfigUtil.GetRequiredAttribute(element, XmlConstants.NAME); config.SetValueObjectMemberType(memberName, ValueObjectMemberType.IGNORE); } }
protected ExternalLinkConfig ReadExternalLinkConfig(XElement linkTag) { LinkConfig link = ReadLinkConfig(linkTag); ExternalLinkConfig eLink = new ExternalLinkConfig(link.Source); String sourceColumn = XmlConfigUtil.GetRequiredAttribute(linkTag, XmlConstants.SOURCE_COLUMN); eLink.SourceColumn = sourceColumn; String targetMember = XmlConfigUtil.GetRequiredAttribute(linkTag, XmlConstants.TARGET_MEMBER); eLink.TargetMember = targetMember; eLink.CascadeDeleteDirection = link.CascadeDeleteDirection; eLink.Alias = link.Alias; return(eLink); }
protected IRelationConfig ReadRelationConfig(XElement relationElement, IMap <String, ILinkConfig> nameToLinkMap) { String relationName = XmlConfigUtil.GetRequiredAttribute(relationElement, XmlConstants.NAME); String linkName = XmlConfigUtil.GetAttribute(relationElement, XmlConstants.LINK); ILinkConfig linkConfig = null; if (linkName.Length > 0) { linkConfig = nameToLinkMap.Get(linkName); } if (linkConfig == null) { if (Log.InfoEnabled) { if (linkName.Length > 0) { Log.Info("No LinkConfig found for name '" + linkName + "'. Creating one with default values."); } else { Log.Info("Unconfigured Link found for property '" + relationName + "'. Trying to resolve this later."); } } linkConfig = new LinkConfig(linkName); } try { RelationConfig20 relationConfig = new RelationConfig20(relationName, linkConfig); String entityIdentifierName = XmlConfigUtil.GetAttribute(relationElement, XmlConstants.THIS); if (entityIdentifierName.Length > 0) { EntityIdentifier entityIdentifier = (EntityIdentifier)Enum.Parse(typeof(EntityIdentifier), entityIdentifierName, true); relationConfig.EntityIdentifier = entityIdentifier; } return(relationConfig); } catch (Exception e) { throw new Exception("Error occured while processing relation '" + relationName + "'", e); } }
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 CompositeMemberConfig ReadCompositeMemberConfig(XElement memberElement, IMap <String, MemberConfig> allIdMemberConfigs) { IEnumerable <XElement> idFragmentNodes = GetDescendants(memberElement, XmlConstants.ID_FRAGMENT); IList <XElement> idFragments = XmlConfigUtil.NodesToElements(idFragmentNodes); MemberConfig[] memberConfigs = new MemberConfig[idFragments.Count]; for (int i = 0; i < idFragments.Count; i++) { XElement idFragment = idFragments[i]; String memberName = XmlConfigUtil.GetRequiredAttribute(idFragment, XmlConstants.NAME); MemberConfig memberConfig = allIdMemberConfigs.Get(memberName); if (memberConfig == null) { memberConfig = ReadMemberConfig(idFragment); allIdMemberConfigs.Put(memberName, memberConfig); } memberConfigs[i] = memberConfig; } CompositeMemberConfig compositeMemberConfig = new CompositeMemberConfig(memberConfigs); return(compositeMemberConfig); }
protected LinkConfig ReadLinkConfig(XElement linkTag) { String source = XmlConfigUtil.GetRequiredAttribute(linkTag, XmlConstants.SOURCE); LinkConfig link = new LinkConfig(source); 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 alias = XmlConfigUtil.GetAttribute(linkTag, XmlConstants.ALIAS); if (alias.Length > 0) { link.Alias = alias; } return(link); }
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); } }