///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM V2 SCHEMA                 //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <see cref="CodelistMapCore"/> class.
        /// </summary>
        /// <param name="codeMapType">
        /// The code map type. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException"> Throws SdmxSemmanticException.
        /// </exception>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public CodelistMapCore(
            Org.Sdmx.Resources.SdmxMl.Schemas.V20.structure.CodelistMapType codeMapType, IStructureSetObject parent)
            : base(
                codeMapType, 
                SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeListMap), 
                codeMapType.id, 
                null, 
                codeMapType.Name, 
                codeMapType.Description, 
                codeMapType.Annotations, 
                parent)
        {
            try
            {
                if (codeMapType.CodelistRef != null)
                {
                    if (codeMapType.CodelistRef.URN != null)
                    {
                        this.SourceRef = new CrossReferenceImpl(this, codeMapType.CodelistRef.URN);
                    }
                    else
                    {
                        string agencyId = codeMapType.CodelistRef.AgencyID;
                        if (string.IsNullOrWhiteSpace(agencyId))
                        {
                            agencyId = this.MaintainableParent.AgencyId;
                        }

                        this.SourceRef = new CrossReferenceImpl(
                            this, 
                            agencyId, 
                            codeMapType.CodelistRef.CodelistID, 
                            codeMapType.CodelistRef.Version, 
                            SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeList));
                    }
                }
                else if (codeMapType.HierarchicalCodelistRef != null)
                {
                    if (codeMapType.HierarchicalCodelistRef.URN != null)
                    {
                        this.SourceRef = new CrossReferenceImpl(
                            this, codeMapType.HierarchicalCodelistRef.URN);
                    }
                    else
                    {
                        string agencyId0 = codeMapType.HierarchicalCodelistRef.AgencyID;
                        if (string.IsNullOrWhiteSpace(agencyId0))
                        {
                            agencyId0 = this.MaintainableParent.AgencyId;
                        }

                        this.SourceRef = new CrossReferenceImpl(
                            this, 
                            agencyId0, 
                            codeMapType.HierarchicalCodelistRef.HierarchicalCodelistID, 
                            codeMapType.HierarchicalCodelistRef.Version, 
                            SdmxStructureType.GetFromEnum(SdmxStructureEnumType.HierarchicalCodelist));
                    }
                }

                if (codeMapType.TargetCodelistRef != null)
                {
                    if (codeMapType.TargetCodelistRef.URN != null)
                    {
                        this.TargetRef = new CrossReferenceImpl(this, codeMapType.TargetCodelistRef.URN);
                    }
                    else
                    {
                        string agencyId1 = codeMapType.TargetCodelistRef.AgencyID;
                        if (string.IsNullOrWhiteSpace(agencyId1))
                        {
                            agencyId1 = this.MaintainableParent.AgencyId;
                        }

                        this.TargetRef = new CrossReferenceImpl(
                            this, 
                            agencyId1, 
                            codeMapType.TargetCodelistRef.CodelistID, 
                            codeMapType.TargetCodelistRef.Version, 
                            SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeList));
                    }
                }
                else if (codeMapType.TargetHierarchicalCodelistRef != null)
                {
                    if (codeMapType.TargetHierarchicalCodelistRef.URN != null)
                    {
                        this.TargetRef = new CrossReferenceImpl(
                            this, codeMapType.TargetHierarchicalCodelistRef.URN);
                    }
                    else
                    {
                        string agencyId2 = codeMapType.TargetHierarchicalCodelistRef.AgencyID;
                        if (string.IsNullOrWhiteSpace(agencyId2))
                        {
                            agencyId2 = this.MaintainableParent.AgencyId;
                        }

                        this.TargetRef = new CrossReferenceImpl(
                            this, 
                            agencyId2, 
                            codeMapType.TargetHierarchicalCodelistRef.HierarchicalCodelistID, 
                            codeMapType.TargetHierarchicalCodelistRef.Version, 
                            SdmxStructureType.GetFromEnum(SdmxStructureEnumType.HierarchicalCodelist));
                    }
                }

                // get list of code maps
                if (codeMapType.CodeMap != null)
                {
                    foreach (CodeMapType codeMap in codeMapType.CodeMap)
                    {
                        IItemMap item = new ItemMapCore(
                            codeMap.CodeAlias, codeMap.MapCodeRef, codeMap.MapTargetCodeRef, this);
                        this.AddInternalItem(item);
                    }
                }
            }
            catch (SdmxSemmanticException ex)
            {
                throw new SdmxSemmanticException(ex, ExceptionCode.ObjectStructureConstructionError, this.Urn);
            }
            catch (Exception th)
            {
                throw new SdmxException(th, ExceptionCode.ObjectStructureConstructionError, this.Urn);
            }

            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="CodelistMapCore"/> class.
        /// </summary>
        /// <param name="codelistMapType">
        /// The codelist map type. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException"> Throws SdmxSemmanticException.
        /// </exception>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public CodelistMapCore(CodelistMapType codelistMapType, IStructureSetObject parent)
            : base(codelistMapType, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeListMap), parent)
        {
            try
            {
                var source = codelistMapType.GetTypedSource<CodelistReferenceType>();
                this.SourceRef = RefUtil.CreateReference(this, source);
                var target = codelistMapType.GetTypedTarget<CodelistReferenceType>();
                this.TargetRef = RefUtil.CreateReference(this, target);

                foreach (CodeMap codeMap in codelistMapType.ItemAssociation)
                {
                    IItemMap item = new ItemMapCore(codeMap.GetTypedSource<LocalCodeReferenceType>().GetTypedRef<LocalCodeRefType>().id, codeMap.GetTypedTarget<LocalCodeReferenceType>().GetTypedRef<LocalCodeRefType>().id, this);
                    this.AddInternalItem(item);
                }
            }
            catch (SdmxSemmanticException ex)
            {
                throw new SdmxSemmanticException(ex, ExceptionCode.ObjectStructureConstructionError, this.Urn);
            }
            catch (Exception th)
            {
                throw new SdmxException(th, ExceptionCode.ObjectStructureConstructionError, this.Urn);
            }

            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="ConceptSchemeMapCore"/> class.
        /// </summary>
        /// <param name="conceptObject">
        /// The concept object. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public ConceptSchemeMapCore(
            Org.Sdmx.Resources.SdmxMl.Schemas.V20.structure.ConceptSchemeMapType conceptObject, 
            IStructureSetObject parent)
            : base(
                conceptObject, 
                SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConceptSchemeMap), 
                conceptObject.id, 
                null, 
                conceptObject.Name, 
                conceptObject.Description, 
                conceptObject.Annotations, 
                parent)
        {
            if (conceptObject.ConceptSchemeRef != null)
            {
                if (conceptObject.ConceptSchemeRef.URN != null)
                {
                    this.SourceRef = new CrossReferenceImpl(this, conceptObject.ConceptSchemeRef.URN);
                }
                else
                {
                    this.SourceRef = new CrossReferenceImpl(
                        this, 
                        conceptObject.ConceptSchemeRef.AgencyID, 
                        conceptObject.ConceptSchemeRef.ConceptSchemeID, 
                        conceptObject.ConceptSchemeRef.Version, 
                        SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConceptScheme));
                }
            }

            if (conceptObject.TargetConceptSchemeRef != null)
            {
                if (conceptObject.TargetConceptSchemeRef.URN != null)
                {
                    this.TargetRef = new CrossReferenceImpl(this, conceptObject.TargetConceptSchemeRef.URN);
                }
                else
                {
                    this.TargetRef = new CrossReferenceImpl(
                        this, 
                        conceptObject.TargetConceptSchemeRef.AgencyID, 
                        conceptObject.TargetConceptSchemeRef.ConceptSchemeID, 
                        conceptObject.TargetConceptSchemeRef.Version, 
                        SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConceptScheme));
                }
            }

            // get list of code maps
            if (conceptObject.ConceptMap != null)
            {
                foreach (ConceptMapType conMap in conceptObject.ConceptMap)
                {
                    IItemMap item = new ItemMapCore(conMap.conceptAlias, conMap.ConceptID, conMap.TargetConceptID, this);
                    this.AddInternalItem(item);
                }
            }

            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="ConceptSchemeMapCore"/> class.
        /// </summary>
        /// <param name="conMapType">
        /// The con map type. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public ConceptSchemeMapCore(ConceptSchemeMapType conMapType, IStructureSetObject parent)
            : base(conMapType, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConceptSchemeMap), parent)
        {
            this.SourceRef = RefUtil.CreateReference(this, conMapType.Source);
            this.TargetRef = RefUtil.CreateReference(this, conMapType.Target);

            if (conMapType.ItemAssociation != null)
            {
                foreach (ConceptMap conMap in conMapType.ItemAssociation)
                {
                    IItemMap item = new ItemMapCore(conMap.Source.GetTypedRef<LocalConceptRefType>().id, conMap.Target.GetTypedRef<LocalConceptRefType>().id, this);
                    this.AddInternalItem(item);
                }
            }

            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="OrganisationSchemeMapCore"/> class.
        /// </summary>
        /// <param name="organisation">
        /// The organisation. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public OrganisationSchemeMapCore(OrganisationSchemeMapType organisation, IStructureSetObject parent)
            : base(organisation, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.OrganisationSchemeMap), parent)
        {
            this.SourceRef = RefUtil.CreateReference(this, organisation.Source);
            this.TargetRef = RefUtil.CreateReference(this, organisation.Target);

            // get list of code maps
            if (organisation.ItemAssociation != null)
            {
                foreach (OrganisationMap orgMap in organisation.ItemAssociation)
                {
                    IItemMap item = new ItemMapCore(orgMap.Source.GetTypedRef<LocalOrganisationRefType>().id, organisation.Target.GetTypedRef<LocalOrganisationRefType>().id, this);
                    this.AddInternalItem(item);
                }
            }

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