コード例 #1
0
        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);
            }
        }