///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////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);
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM MUTABLE OBJECTS             //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="CodelistMapCore"/> class.
        /// </summary>
        /// <param name="itemMutableObject">
        /// The agencyScheme. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public CodelistMapCore(ICodelistMapMutableObject itemMutableObject, IStructureSetObject parent)
            : base(itemMutableObject, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeListMap), parent)
        {
            this.srcAlias = itemMutableObject.SrcAlias;
            this.targetAlias = itemMutableObject.TargetAlias;

            if (itemMutableObject.TargetRef != null)
            {
                this.TargetRef = new CrossReferenceImpl(this, itemMutableObject.TargetRef);
            }

            if (itemMutableObject.SourceRef != null)
            {
                this.SourceRef = new CrossReferenceImpl(this, itemMutableObject.SourceRef);
            }

            try
            {
                this.Validate();
            }
            catch (SdmxSemmanticException e)
            {
                throw new SdmxSemmanticException(e, ExceptionCode.FailValidation, this);
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM MUTABLE OBJECTS             //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ConceptSchemeMapCore"/> class.
        /// </summary>
        /// <param name="conceptSchemeMapMutableObject">
        /// The icon. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public ConceptSchemeMapCore(IConceptSchemeMapMutableObject conceptSchemeMapMutableObject, IStructureSetObject parent)
            : base(conceptSchemeMapMutableObject, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConceptSchemeMap), parent)
        {
            try
            {
                this.Validate();
            }
            catch (SdmxSemmanticException e)
            {
                throw new SdmxSemmanticException(e, ExceptionCode.FailValidation, this);
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM MUTABLE OBJECTS             //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="StructureMapCore"/> class.
        /// </summary>
        /// <param name="structMapType">
        /// The struct map type. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public StructureMapCore(IStructureMapMutableObject structMapType, IStructureSetObject parent)
            : base(structMapType, parent)
        {
            this.components = new List<IComponentMapObject>();
            this.extension = structMapType.Extension;
            if (structMapType.Components != null)
            {
                foreach (IComponentMapMutableObject mutable in structMapType.Components)
                {
                    this.components.Add(new ComponentMapCore(mutable, this));
                }
            }

            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 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);
            }
        }
        private void SetGeneralTab(IStructureSetObject sso)
        {
            if (!sso.Id.Contains(_ntdString))
                txtSSID.Text = sso.Id;

            cmbAgencies.SelectedValue = sso.AgencyId;
            txtAgenciesReadOnly.Text = sso.AgencyId;
            AnnotationGeneral.OwnerAgency = txtAgenciesReadOnly.Text;

            if (!Utils.ViewMode && _action != Action.INSERT)
            {
                DuplicateArtefact1.Visible = true;
            }

            if ( _action == Action.INSERT )
            {
                cmbAgencies.Visible = true;
                txtAgenciesReadOnly.Visible = false;
            }
            else
            {
                cmbAgencies.Visible = false;
                txtAgenciesReadOnly.Visible = true;
            }

            if (sso.Version != _ntdDSDVersion)
                txtVersion.Text = sso.Version;

            chkIsFinal.Checked = sso.IsFinal.IsTrue;

            if (sso.Uri != null)
                txtURI.Text = sso.Uri.AbsoluteUri;

            if (sso.Urn != null)
                txtURN.Text = sso.Urn.AbsoluteUri;

            if (sso.StartDate != null)
                txtValidFrom.Text = sso.StartDate.Date.ToString();

            if (sso.EndDate != null)
                txtValidTo.Text = sso.EndDate.Date.ToString();

            //var dataStructureRef = sso.DataStructureRef;

            //if (!dataStructureRef.AgencyId.Contains(_ntdString))
            //    txtDSD.Text = dataStructureRef.MaintainableId + "," + dataStructureRef.AgencyId + "," + dataStructureRef.Version;

            txtSSName.Text = _localizedUtils.GetNameableName(sso);
            txtSSDescription.Text = _localizedUtils.GetNameableDescription(sso);

            if (_action != Action.VIEW)
            {
                IStructureSetMutableObject ssM = sso.MutableInstance;

                foreach (ITextTypeWrapperMutableObject name in ssM.Names)
                {
                    if (name.Value.Contains(_ntdString))
                    {
                        ssM.Names.Remove(name);
                        break;
                    }
                }

                AddTextName.InitTextObjectMutableList = ssM.Names;
                AddTextDescription.InitTextObjectList = sso.Descriptions;
            }

            AnnotationGeneral.AnnotationObjectList = sso.MutableInstance.Annotations;
        }
 private void SetCodeListMapTab(IStructureSetObject sso)
 {
     PopolateGVCLM();
 }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////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);
            }
        }
        /// <summary>
        /// Build <see cref="StructureSetType"/> from <paramref name="buildFrom"/>.
        /// </summary>
        /// <param name="buildFrom">
        /// The source SDMX Object.
        /// </param>
        /// <returns>
        /// The <see cref="StructureSetType"/> from <paramref name="buildFrom"/> .
        /// </returns>
        public StructureSetType Build(IStructureSetObject buildFrom)
        {
            var builtObj = new StructureSetType();

            // MAINTAINABLE ATTRIBUTES
            string str0 = buildFrom.AgencyId;
            if (!string.IsNullOrWhiteSpace(str0))
            {
                builtObj.agencyID = buildFrom.AgencyId;
            }

            string str1 = buildFrom.Id;
            if (!string.IsNullOrWhiteSpace(str1))
            {
                builtObj.id = buildFrom.Id;
            }

            if (buildFrom.Uri != null)
            {
                builtObj.uri = buildFrom.Uri;
            }
            else if (buildFrom.StructureUrl != null)
            {
                builtObj.uri = buildFrom.StructureUrl;
            }
            else if (buildFrom.ServiceUrl != null)
            {
                builtObj.uri = buildFrom.StructureUrl;
            }
            
            builtObj.urn = buildFrom.Urn;

            string str3 = buildFrom.Version;
            if (!string.IsNullOrWhiteSpace(str3))
            {
                builtObj.version = buildFrom.Version;
            }

            if (buildFrom.StartDate != null)
            {
                builtObj.validFrom = buildFrom.StartDate.Date;
            }

            if (buildFrom.EndDate != null)
            {
                builtObj.validTo = buildFrom.EndDate.Date;
            }

            IList<ITextTypeWrapper> names = buildFrom.Names;
            if (ObjectUtil.ValidCollection(names))
            {
                builtObj.Name = this.GetTextType(names);
            }

            IList<ITextTypeWrapper> descriptions = buildFrom.Descriptions;
            if (ObjectUtil.ValidCollection(descriptions))
            {
                builtObj.Description = this.GetTextType(descriptions);
            }

            if (this.HasAnnotations(buildFrom))
            {
                builtObj.Annotations = this.GetAnnotationsType(buildFrom);
            }

            if (buildFrom.IsExternalReference.IsSet())
            {
                builtObj.isExternalReference = buildFrom.IsExternalReference.IsTrue;
            }

            if (buildFrom.IsFinal.IsSet())
            {
                builtObj.isFinal = buildFrom.IsFinal.IsTrue;
            }

            // MAPS
            ProcessRelatedStructures(builtObj, buildFrom);
            if (buildFrom.StructureMapList != null)
            {
                /* foreach */
                foreach (IStructureMapObject each in buildFrom.StructureMapList)
                {
                    this.ProcessStructureMap(builtObj, each);
                }
            }

            if (buildFrom.CodelistMapList != null)
            {
                /* foreach */
                foreach (ICodelistMapObject each0 in buildFrom.CodelistMapList)
                {
                    this.ProcessCodelistMap(builtObj, each0);
                }
            }

            if (buildFrom.CategorySchemeMapList != null)
            {
                /* foreach */
                foreach (ICategorySchemeMapObject each1 in buildFrom.CategorySchemeMapList)
                {
                    this.ProcessCategorySchemeMap(builtObj, each1);
                }
            }

            if (buildFrom.ConceptSchemeMapList != null)
            {
                /* foreach */
                foreach (IConceptSchemeMapObject each2 in buildFrom.ConceptSchemeMapList)
                {
                    this.ProcessConceptSchemeMap(builtObj, each2);
                }
            }

            if (buildFrom.OrganisationSchemeMapList != null)
            {
                /* foreach */
                foreach (IOrganisationSchemeMapObject each3 in buildFrom.OrganisationSchemeMapList)
                {
                    this.ProcessOrganisationSchemeMap(builtObj, each3);
                }
            }

            return builtObj;
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////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 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);
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM V2 SCHEMA                 //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <see cref="StructureMapCore"/> class.
        /// </summary>
        /// <param name="structMapType">
        /// The struct map type. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public StructureMapCore(
            Org.Sdmx.Resources.SdmxMl.Schemas.V20.structure.StructureMapType structMapType, IStructureSetObject parent)
            : base(
                structMapType, 
                SdmxStructureType.GetFromEnum(SdmxStructureEnumType.StructureMap), 
                structMapType.id, 
                null, 
                structMapType.Name, 
                structMapType.Description, 
                structMapType.Annotations, 
                parent)
        {
            this.components = new List<IComponentMapObject>();

            this.extension = structMapType.isExtension.Value;
            KeyFamilyRefType keyFamilyRef = structMapType.KeyFamilyRef;

            if (keyFamilyRef != null)
            {
                if (keyFamilyRef.URN != null)
                {
                    this.SourceRef = new CrossReferenceImpl(this, keyFamilyRef.URN);
                }
                else
                {
                    string agencyId = keyFamilyRef.KeyFamilyAgencyID;
                    if (string.IsNullOrWhiteSpace(agencyId))
                    {
                        agencyId = this.MaintainableParent.AgencyId;
                    }

                    this.SourceRef = new CrossReferenceImpl(
                        this, 
                        agencyId, 
                        keyFamilyRef.KeyFamilyID, 
                        keyFamilyRef.Version, 
                        SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dsd));
                }
            }
            else if (structMapType.MetadataStructureRef != null)
            {
                if (structMapType.MetadataStructureRef.URN != null)
                {
                    this.SourceRef = new CrossReferenceImpl(this, structMapType.MetadataStructureRef.URN);
                }
                else
                {
                    string agencyId0 = structMapType.KeyFamilyRef.KeyFamilyAgencyID;
                    if (string.IsNullOrWhiteSpace(agencyId0))
                    {
                        agencyId0 = this.MaintainableParent.AgencyId;
                    }

                    this.SourceRef = new CrossReferenceImpl(
                        this, 
                        agencyId0, 
                        structMapType.MetadataStructureRef.MetadataStructureID, 
                        structMapType.MetadataStructureRef.Version, 
                        SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Msd));
                }
            }

            // target ref can be one of two types so get one which isn't null
            if (structMapType.TargetKeyFamilyRef != null)
            {
                if (structMapType.TargetKeyFamilyRef.URN != null)
                {
                    this.TargetRef = new CrossReferenceImpl(this, structMapType.TargetKeyFamilyRef.URN);
                }
                else
                {
                    string agencyId1 = structMapType.TargetKeyFamilyRef.KeyFamilyAgencyID;
                    if (string.IsNullOrWhiteSpace(agencyId1))
                    {
                        agencyId1 = this.MaintainableParent.AgencyId;
                    }

                    this.TargetRef = new CrossReferenceImpl(
                        this, 
                        agencyId1, 
                        structMapType.TargetKeyFamilyRef.KeyFamilyID, 
                        structMapType.TargetKeyFamilyRef.Version, 
                        SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dsd));
                }
            }
            else if (structMapType.TargetMetadataStructureRef != null)
            {
                if (structMapType.TargetMetadataStructureRef.URN != null)
                {
                    this.TargetRef = new CrossReferenceImpl(
                        this, structMapType.TargetMetadataStructureRef.URN);
                }
                else
                {
                    string agencyId2 = structMapType.TargetMetadataStructureRef.MetadataStructureAgencyID;
                    if (string.IsNullOrWhiteSpace(agencyId2))
                    {
                        agencyId2 = this.MaintainableParent.AgencyId;
                    }

                    this.TargetRef = new CrossReferenceImpl(
                        this, 
                        agencyId2, 
                        structMapType.TargetMetadataStructureRef.MetadataStructureID, 
                        structMapType.TargetMetadataStructureRef.Version, 
                        SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Msd));
                }
            }

            // get list of component maps
            if (structMapType.ComponentMap != null)
            {
                foreach (Org.Sdmx.Resources.SdmxMl.Schemas.V20.structure.ComponentMapType compMap in
                    structMapType.ComponentMap)
                {
                    var componentMapCore = new ComponentMapCore(compMap, this);
                    this.components.Add(componentMapCore);
                }
            }

            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="StructureMapCore"/> class.
        /// </summary>
        /// <param name="structMapType">
        /// The struct map type. 
        /// </param>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <exception cref="SdmxSemmanticException">
        /// Throws Validate exception.
        /// </exception>
        public StructureMapCore(StructureMapType structMapType, IStructureSetObject parent)
            : base(structMapType, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.StructureMap), parent)
        {
            this.components = new List<IComponentMapObject>();
            this.SourceRef = RefUtil.CreateReference(this, structMapType.Source);
            this.TargetRef = RefUtil.CreateReference(this, structMapType.Target);
            IList<ComponentMapType> componentMapType = structMapType.ComponentMapTypes;
            if (ObjectUtil.ValidCollection(componentMapType))
            {
                foreach (ComponentMapType compMap in componentMapType)
                {
                    this.components.Add(new ComponentMapCore(compMap, this));
                }
            }

            try
            {
                this.Validate();
            }
            catch (SdmxSemmanticException e)
            {
                throw new SdmxSemmanticException(e, ExceptionCode.FailValidation, this);
            }
        }
 private void SetStructureMapTab(IStructureSetObject sso)
 {
     PopolateGVSM();
 }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////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);
            }
        }
        public List<CodeListMap> GetCodeListMapList(IStructureSetObject sso)
        {
            List<Entity.CodeListMap> lCLM = new List<Entity.CodeListMap>();

            if ((sso.CodelistMapList != null && sso.CodelistMapList.Count <= 0) || sso.CodelistMapList == null)
                return null;

            string clSourceID,clTargetID;

            foreach (ICodelistMapObject clm in sso.CodelistMapList)
            {
                clSourceID = String.Empty;
                clTargetID = String.Empty;

                if (clm.SourceRef != null)
                    clSourceID = clm.SourceRef.MaintainableId + ", " + clm.SourceRef.AgencyId + ", " + clm.SourceRef.Version;

                if (clm.TargetRef != null)
                    clTargetID = clm.TargetRef.MaintainableId + ", " + clm.TargetRef.AgencyId + ", " + clm.TargetRef.Version;

                lCLM.Add(new CodeListMap(clm.Id, clSourceID, clTargetID));
            }

            return lCLM;
        }
        public List<StructureMap> GetStructureMapList(IStructureSetObject sso)
        {
            List<Entity.StructureMap> lSM = new List<Entity.StructureMap>();

            if ((sso.StructureMapList != null && sso.StructureMapList.Count <= 0) || sso.StructureMapList == null)
                return null;

            string SourceID, TargetID, ArtefactType;

            foreach (IStructureMapObject sm in sso.StructureMapList)
            {
                SourceID = String.Empty;
                TargetID = String.Empty;
                ArtefactType = String.Empty;

                if (sm.SourceRef != null)
                    SourceID = sm.SourceRef.MaintainableId + ", " + sm.SourceRef.AgencyId + ", " + sm.SourceRef.Version;

                if (sm.TargetRef != null)
                    TargetID = sm.TargetRef.MaintainableId + ", " + sm.TargetRef.AgencyId + ", " + sm.TargetRef.Version;

                ArtefactType = sm.SourceRef.TargetReference.StructureType;

                lSM.Add(new StructureMap(sm.Id, SourceID, TargetID, ArtefactType));
            }

            return lSM;
        }
        /// <summary>
        /// Process related structures.
        /// </summary>
        /// <param name="structureSetType">
        /// The structure set type.
        /// </param>
        /// <param name="buildFrom">
        /// The build from.
        /// </param>
        private static void ProcessRelatedStructures(StructureSetType structureSetType, IStructureSetObject buildFrom)
        {
            if (buildFrom.RelatedStructures != null)
            {
                var relatedStructuresType = new RelatedStructuresType();
                structureSetType.RelatedStructures = relatedStructuresType;
                IRelatedStructures relatedStructures = buildFrom.RelatedStructures;

                // KEY FAMILY REF
                foreach (ICrossReference xref in relatedStructures.DataStructureRef)
                {
                    var keyFamilyRefType = new KeyFamilyRefType();
                    relatedStructuresType.KeyFamilyRef.Add(keyFamilyRefType);
                    SetDataStructureRefAttributes(keyFamilyRefType, xref);
                }

                // METADATA STRUCTURE REF
                foreach (ICrossReference ref0 in relatedStructures.MetadataStructureRef)
                {
                    var refType = new MetadataStructureRefType();
                    relatedStructuresType.MetadataStructureRef.Add(refType);
                    SetMetadataStructureRefAttributes(refType, ref0);
                }

                // CONCEPT SCHEME REF
                foreach (ICrossReference ref1 in relatedStructures.ConceptSchemeRef)
                {
                    var refType2 = new ConceptSchemeRefType();
                    relatedStructuresType.ConceptSchemeRef.Add(refType2);
                    SetConceptSchemeRefAttributes(refType2, ref1);
                }

                // CATEGORY SCHEME REF
                foreach (ICrossReference ref3 in relatedStructures.CategorySchemeRef)
                {
                    var refType4 = new CategorySchemeRefType();
                    relatedStructuresType.CategorySchemeRef.Add(refType4);
                    SetCategorySchemeRefAttributes(refType4, ref3);
                }

                // ORGANISATION SCHEME REF
                foreach (ICrossReference ref5 in relatedStructures.OrgSchemeRef)
                {
                    var refType6 = new OrganisationSchemeRefType();
                    relatedStructuresType.OrganisationSchemeRef.Add(refType6);
                    SetOrganisationSchemeRefAttributes(refType6, ref5);
                }

                // HCL REF
                foreach (ICrossReference ref7 in relatedStructures.HierCodelistRef)
                {
                    var refType8 = new HierarchicalCodelistRefType();
                    relatedStructuresType.HierarchicalCodelistRef.Add(refType8);
                    SetHclRefAttributes(refType8, ref7);
                }
            }
        }