////// PRIVATE CONSTRUCTOR 
        ///// TODO java 0.9.1 has private ctor that is not accessed anywhere 
        ////#region Constructors and Destructors

        /////// <summary>
        /////// Prevents a default instance of the <see cref="SubmitStructureResponseBuilderV2"/> class from being created.
        /////// </summary>
        ////private SubmitStructureResponseBuilderV2()
        ////{
        ////}

        ////#endregion
        #region Public Methods and Operators

        /// <summary>
        /// The build error response.
        /// </summary>
        /// <param name="exception">
        /// The exception.
        /// </param>
        /// <param name="errorBean">
        /// The error bean.
        /// </param>
        /// <returns>
        /// The <see cref="RegistryInterface"/>.
        /// </returns>
        public RegistryInterface BuildErrorResponse(Exception exception, IStructureReference errorBean)
        {
            var responseType = new RegistryInterface();
            RegistryInterfaceType regInterface = responseType.Content;
            V2Helper.Header = regInterface;
            var returnType = new SubmitStructureResponseType();
            regInterface.SubmitStructureResponse = returnType;
            ProcessMaintainable(returnType, errorBean, exception);
            return responseType;
        }
        /// <summary>
        /// The build success response.
        /// </summary>
        /// <param name="beans">
        /// The beans.
        /// </param>
        /// <returns>
        /// The <see cref="RegistryInterface"/>.
        /// </returns>
        public RegistryInterface BuildSuccessResponse(ISdmxObjects beans)
        {
            var responseType = new RegistryInterface();
            RegistryInterfaceType regInterface = responseType.Content;

            HeaderType headerType;
            if (beans.Header != null)
            {
                headerType = this._headerXmlsBuilder.Build(beans.Header);
                regInterface.Header = headerType;
            }
            else
            {
                headerType = new HeaderType();
                regInterface.Header = headerType;
                V2Helper.SetHeader(headerType, beans);
            }

            var returnType = new SubmitStructureResponseType();
            regInterface.SubmitStructureResponse = returnType;
            ProcessMaintainables(returnType, beans.GetAllMaintainables());
            return responseType;
        }
 /// <summary>
 /// Process the <paramref name="maintainableObjects"/> to produce <paramref name="returnType"/>
 /// </summary>
 /// <param name="returnType">
 /// The return type.
 /// </param>
 /// <param name="maintainableObjects">
 /// The maintainable Objects.
 /// </param>
 private static void ProcessMaintainables(
     SubmitStructureResponseType returnType, IEnumerable<IMaintainableObject> maintainableObjects)
 {
     /* foreach */
     foreach (IMaintainableObject maint in maintainableObjects)
     {
         ProcessMaintainable(returnType, maint.AsReference, null);
     }
 }
        /// <summary>
        /// Process maintainable.
        /// </summary>
        /// <param name="returnType">
        /// The return type.
        /// </param>
        /// <param name="structureReference">
        /// The structure reference.
        /// </param>
        /// <param name="th">
        /// The exception.
        /// </param>
        private static void ProcessMaintainable(
            SubmitStructureResponseType returnType, IStructureReference structureReference, Exception th)
        {
            if (structureReference == null)
            {
                AddNewOrganisationSchemeRefSubmissionResult(returnType, null, th);
                return; // TODO MISSING from Java
            }

            switch (structureReference.TargetReference.EnumType)
            {
                case SdmxStructureEnumType.AgencyScheme:
                    AddNewOrganisationSchemeRefSubmissionResult(returnType, structureReference, th);
                    break;
                case SdmxStructureEnumType.DataProviderScheme:
                    AddNewOrganisationSchemeRefSubmissionResult(returnType, structureReference, th);
                    break;
                case SdmxStructureEnumType.DataConsumerScheme:
                    AddNewOrganisationSchemeRefSubmissionResult(returnType, structureReference, th);
                    break;
                case SdmxStructureEnumType.CategoryScheme:
                    AddNewCategorySchemeRefSubmissionResult(returnType, structureReference, th);
                    break;
                case SdmxStructureEnumType.Dataflow:
                    AddNewDataflowRefSubmissionResult(returnType, structureReference, th);
                    break;
                case SdmxStructureEnumType.MetadataFlow:
                    AddNewMetadataflowRefSubmissionResult(returnType, structureReference, th);
                    break;
                case SdmxStructureEnumType.CodeList:
                    AddNewCodelistRefSubmissionResult(returnType, structureReference, th);
                    break;
                case SdmxStructureEnumType.HierarchicalCodelist:
                    AddNewHierarchicalCodelistRefSubmissionResult(returnType, structureReference, th);
                    break;
                case SdmxStructureEnumType.ConceptScheme:
                    AddNewConceptSchemeRefSubmissionResult(returnType, structureReference, th);
                    break;
                case SdmxStructureEnumType.OrganisationUnitScheme:
                    AddNewOrganisationSchemeRefSubmissionResult(returnType, structureReference, th);
                    break;
                case SdmxStructureEnumType.Dsd:
                    AddNewDataStructureRefSubmissionResult(returnType, structureReference, th);
                    break;
                case SdmxStructureEnumType.Msd:
                    AddNewMetadataStructureRefSubmissionResult(returnType, structureReference, th);
                    break;
                case SdmxStructureEnumType.Process:
                    AddNewProcessRefSubmissionResult(returnType, structureReference, th);
                    break;
                case SdmxStructureEnumType.StructureSet:
                    AddNewStructureSetRefSubmissionResult(returnType, structureReference, th);
                    break;
                case SdmxStructureEnumType.ReportingTaxonomy:
                    AddNewReportingTaxonomySetRefSubmissionResult(returnType, structureReference, th);
                    break;
            }
        }
        /// <summary>
        /// Gets new submission result type.
        /// </summary>
        /// <param name="returnType">
        /// The return type.
        /// </param>
        /// <param name="exception">
        /// The exception.
        /// </param>
        /// <returns>
        /// The <see cref="SubmissionResultType"/>.
        /// </returns>
        private static SubmissionResultType GetNewSubmissionResultType(
            SubmitStructureResponseType returnType, Exception exception)
        {
            var submissionResult = new SubmissionResultType();
            returnType.SubmissionResult.Add(submissionResult);
            var statusMessage = new StatusMessageType();
            submissionResult.StatusMessage = statusMessage;
            if (exception == null)
            {
                statusMessage.status = StatusTypeConstants.Success;
            }
            else
            {
                statusMessage.status = StatusTypeConstants.Failure;
                var tt = new TextType();
                statusMessage.MessageText.Add(tt);
                var uncheckedException = exception as SdmxException;
                tt.TypedValue = uncheckedException != null ? uncheckedException.FullMessage : exception.Message;
            }

            return submissionResult;
        }
        /// <summary>
        /// Adds new structure set ref submission result.
        /// </summary>
        /// <param name="returnType">
        /// The return type.
        /// </param>
        /// <param name="structureReference">
        /// The structure reference.
        /// </param>
        /// <param name="exception">
        /// The exception.
        /// </param>
        private static void AddNewStructureSetRefSubmissionResult(
            SubmitStructureResponseType returnType, IStructureReference structureReference, Exception exception)
        {
            SubmissionResultType result = GetNewSubmissionResultType(returnType, exception);
            var submittedStructure = new SubmittedStructureType();
            result.SubmittedStructure = submittedStructure;
            var refType = new StructureSetRefType();
            submittedStructure.StructureSetRef = refType;

            IMaintainableRefObject maintainableReference = structureReference.MaintainableReference;
            refType.AgencyID = maintainableReference.AgencyId;
            refType.StructureSetID = maintainableReference.MaintainableId;
            if (ObjectUtil.ValidString(structureReference.MaintainableUrn))
            {
                refType.URN = structureReference.MaintainableUrn;
            }

            string value = maintainableReference.Version;
            if (!string.IsNullOrWhiteSpace(value))
            {
                refType.Version = maintainableReference.Version;
            }
        }