///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM MUTABLE OBJECTS             //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="CategorySchemeMapCore"/> class.
        /// </summary>
        /// <param name="itemMutableObject">
        /// The agencyScheme. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public CategorySchemeMapCore(ICategorySchemeMapMutableObject itemMutableObject, IStructureSetObject parent)
            : base(itemMutableObject, parent)
        {
            this.categoryMaps = new List<ICategoryMap>();
            if (itemMutableObject.CategoryMaps != null)
            {
                this.categoryMaps = new List<ICategoryMap>();

                foreach (ICategoryMapMutableObject catMap in itemMutableObject.CategoryMaps)
                {
                    ICategoryMap categoryMap = new CategoryMapCore(catMap, this);
                    this.categoryMaps.Add(categoryMap);
                }
            }

            try
            {
                this.Validate();
            }
            catch (SdmxSemmanticException e)
            {
                throw new SdmxSemmanticException(e, ExceptionCode.FailValidation, this);
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM V2 SCHEMA                 //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <see cref="CategorySchemeMapCore"/> class.
        /// </summary>
        /// <param name="catMapType">
        /// The cat map type. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public CategorySchemeMapCore(
            Org.Sdmx.Resources.SdmxMl.Schemas.V20.structure.CategorySchemeMapType catMapType, IStructureSetObject parent)
            : base(
                catMapType, 
                SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CategorySchemeMap), 
                catMapType.id, 
                null, 
                catMapType.Name, 
                catMapType.Description, 
                catMapType.Annotations, 
                parent)
        {
            this.categoryMaps = new List<ICategoryMap>();

            if (catMapType.CategorySchemeRef != null)
            {
                if (catMapType.CategorySchemeRef.URN != null)
                {
                    this.SourceRef = new CrossReferenceImpl(this, catMapType.CategorySchemeRef.URN);
                }
                else
                {
                    this.SourceRef = new CrossReferenceImpl(
                        this, 
                        catMapType.CategorySchemeRef.AgencyID, 
                        catMapType.CategorySchemeRef.CategorySchemeID, 
                        catMapType.CategorySchemeRef.Version, 
                        SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CategoryScheme));
                }
            }

            if (catMapType.TargetCategorySchemeRef != null)
            {
                if (catMapType.TargetCategorySchemeRef.URN != null)
                {
                    this.TargetRef = new CrossReferenceImpl(this, catMapType.TargetCategorySchemeRef.URN);
                }
                else
                {
                    this.TargetRef = new CrossReferenceImpl(
                        this, 
                        catMapType.TargetCategorySchemeRef.AgencyID, 
                        catMapType.TargetCategorySchemeRef.CategorySchemeID, 
                        catMapType.TargetCategorySchemeRef.Version, 
                        SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CategoryScheme));
                }
            }

            if (catMapType.CategoryMap != null)
            {
                foreach (CategoryMapType catMap in catMapType.CategoryMap)
                {
                    ICategoryMap categoryMap = new CategoryMapCore(catMap, this);
                    this.categoryMaps.Add(categoryMap);
                }
            }

            try
            {
                this.Validate();
            }
            catch (SdmxSemmanticException e)
            {
                throw new SdmxSemmanticException(e, ExceptionCode.FailValidation, this);
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM V2.1 SCHEMA                 //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <see cref="CategorySchemeMapCore"/> class.
        /// </summary>
        /// <param name="catMapType">
        /// The cat map type. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public CategorySchemeMapCore(CategorySchemeMapType catMapType, IStructureSetObject parent)
            : base(catMapType, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CategorySchemeMap), parent)
        {
            this.categoryMaps = new List<ICategoryMap>();

            this.SourceRef = RefUtil.CreateReference(this, catMapType.GetTypedSource<CategorySchemeReferenceType>());
            this.TargetRef = RefUtil.CreateReference(this, catMapType.GetTypedTarget<CategorySchemeReferenceType>());

            if (catMapType.ItemAssociation != null)
            {
                foreach (CategoryMap catMap in catMapType.ItemAssociation)
                {
                    ICategoryMap categoryMap = new CategoryMapCore(catMap.Content, this);
                    this.categoryMaps.Add(categoryMap);
                }
            }

            try
            {
                this.Validate();
            }
            catch (SdmxSemmanticException e)
            {
                throw new SdmxSemmanticException(e, ExceptionCode.FailValidation, this);
            }
        }