/// <summary>
 /// Returns an response based on the submitted provision, if there is a Exception against the provision
 ///     then the error will be documented, and a status of failure will be put against it.
 /// </summary>
 /// <param name="response">
 /// - a map of provision, and a error message (if there is one)
 /// </param>
 /// <param name="schemaVersion">
 /// - the version of the schema to output the response in
 /// </param>
 /// <returns>
 /// The <see cref="XTypedElement"/>.
 /// </returns>
 public virtual XTypedElement BuildSuccessResponse(
     ICollection<IProvisionAgreementObject> response, SdmxSchemaEnumType schemaVersion)
 {
     switch (schemaVersion)
     {
         case SdmxSchemaEnumType.VersionTwo:
             return this._submitProvisionResponseBuilderV2.BuildResponse(response);
         case SdmxSchemaEnumType.VersionTwoPointOne:
             ISdmxObjects beans = new SdmxObjectsImpl();
             beans.AddIdentifiables(response);
             return this._v21Builder.BuildSuccessResponse(beans);
         default:
             throw new SdmxNotImplementedException(ExceptionCode.Unsupported, schemaVersion);
     }
 }
        /// <summary>
        /// Processes the registry interface document.
        /// </summary>
        /// <param name="dataLocation">
        /// The data location.
        /// </param>
        /// <param name="registryMessage">
        /// The registry message type.
        /// </param>
        /// <param name="schemaVersion">
        /// The schema version type.
        /// </param>
        /// <returns>
        /// The <see cref="ISdmxObjects"/>.
        /// </returns>
        private ISdmxObjects ProcessRegistryInterfaceDocument(IReadableDataLocation dataLocation, RegistryMessageType registryMessage, SdmxSchemaEnumType schemaVersion)
        {
            ArtifactType artifactType = registryMessage.ArtifactType;
            ISdmxObjects returnBeans = new SdmxObjectsImpl();
            switch (artifactType)
            {
                case ArtifactType.Provision:
                    returnBeans.AddIdentifiables(_provisionParsingManager.ParseXML(dataLocation));
                    break;
                case ArtifactType.Registration:
                    foreach (IRegistrationInformation regInfo in _registrationParsingManager.ParseRegXML(dataLocation))
                        returnBeans.AddRegistration(regInfo.Registration);
                    break;
                case ArtifactType.Structure:
                        switch (schemaVersion)
                        {
                            case SdmxSchemaEnumType.VersionTwo:
                                RegistryInterface rid;
                                using (Stream inputStream = dataLocation.InputStream)
                                {
                                    using (XmlReader reader = XMLParser.CreateSdmxMlReader(inputStream, schemaVersion))
                                    {
                                        rid = RegistryInterface.Load(reader);
                                    }
                                }
                                return _sdmxBeansBuilder.Build(rid);
                            case SdmxSchemaEnumType.VersionTwoPointOne:
                                Org.Sdmx.Resources.SdmxMl.Schemas.V21.Message.RegistryInterface rid2_1;
                                using (Stream inputStream = dataLocation.InputStream)
                                {
                                    using (XmlReader reader = XMLParser.CreateSdmxMlReader(inputStream, schemaVersion))
                                    {
                                        rid2_1 = Org.Sdmx.Resources.SdmxMl.Schemas.V21.Message.RegistryInterface.Load(reader);
                                    }
                                }
                                return _sdmxBeansBuilder.Build(rid2_1);
                            default:
                                throw new ArgumentException("Schema version unsupported for RegistryInterfaceDocument: " + schemaVersion.ToString());
                        }

                case ArtifactType.Subscription:
                    returnBeans.AddIdentifiables(_subscriptionParsingManager.ParseSubscriptionXML(dataLocation));
                    break;
                default:
                    throw new SdmxNotImplementedException("StructureParsingManager does not support message of type : " + registryMessage.EnumType.ToString());
            }
            return returnBeans;
        }
        /// <summary>
        /// Builds a QueryProvisioningResponse with a success status, along with
        ///     the provisions returned from the query, if there are no provisions returned
        ///     this will be noted in the response message.
        /// </summary>
        /// <param name="provisions">
        /// The source provisions
        /// </param>
        /// <param name="schemaVersion">
        /// The schema Version.
        /// </param>
        /// <returns>
        /// The <see cref="XTypedElement"/>.
        /// </returns>
        public virtual XTypedElement BuildSuccessResponse(
            ICollection<IProvisionAgreementObject> provisions, SdmxSchemaEnumType schemaVersion)
        {
            XTypedElement response = null;
            switch (schemaVersion)
            {
                case SdmxSchemaEnumType.VersionTwo:
                    response = this._queryProvisionResponseBuilderV2.BuildSuccessResponse(provisions);
                    break;
                case SdmxSchemaEnumType.VersionTwoPointOne:
                    ISdmxObjects beans = new SdmxObjectsImpl();
                    beans.AddIdentifiables(provisions);
                    response = this._queryStructureResponseBuilder.BuildSuccessResponse(beans, schemaVersion, false);
                    break;
                default:
                    throw new SdmxNotImplementedException(ExceptionCode.Unsupported, schemaVersion);
            }

            base.WriteSchemaLocation(response, schemaVersion);
            return response;
        }