Ejemplo n.º 1
0
 /// <summary>
 /// Constructs a <b>DTDRelease</b> instance describing a DTD
 /// based release of a particular <see cref="HandCoded.Meta.Specification"/>.
 /// </summary>
 /// <param name="specification">The owning <see cref="HandCoded.Meta.Specification"/>.</param>
 /// <param name="version">The version identifier for this release.</param>
 /// <param name="publicId">The public name for the DTD.</param>
 /// <param name="systemId">The system name for the DTD.</param>
 /// <param name="rootElement">The normal root element.</param>
 /// <param name="schemeDefaults">Scheme default URI information.</param>
 /// <param name="schemeCollection">The SchemeCollection of this release.</param>
 public DTDRelease(HandCoded.Meta.Specification specification, string version,
                   string publicId, string systemId, string rootElement,
                   SchemeDefaults schemeDefaults, SchemeCollection schemeCollection)
     : base(specification, version, publicId, systemId, rootElement)
 {
     this.schemeDefaults   = schemeDefaults;
     this.schemeCollection = schemeCollection;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructs a <b>SchemaRelease</b> instance describing a schema
 /// based release of a particular <see cref="HandCoded.Meta.Specification"/>.
 /// </summary>
 /// <param name="specification">The owning <see cref="HandCoded.Meta.Specification"/>.</param>
 /// <param name="version">The version identifier for this release.</param>
 /// <param name="namespaceUri">The namespace used to identify the schema.</param>
 /// <param name="schemaLocation">The default schema location.</param>
 /// <param name="preferredPrefix">The preferred prefix for the namespace.</param>
 /// <param name="alternatePrefix">The alternate prefix for the namespace.</param>
 /// <param name="rootElements">The possible root elements.</param>
 /// <param name="schemeDefaults">Scheme default URI information.</param>
 /// <param name="schemeCollection">The SchemeCollection for this release.</param>
 public SchemaRelease(HandCoded.Meta.Specification specification, string version,
                      string namespaceUri, string schemaLocation, string preferredPrefix,
                      string alternatePrefix, string [] rootElements, SchemeDefaults schemeDefaults,
                      SchemeCollection schemeCollection)
     : base(specification, version, namespaceUri, schemaLocation,
            preferredPrefix, alternatePrefix, rootElements)
 {
     this.schemeDefaults   = schemeDefaults;
     this.schemeCollection = schemeCollection;
 }
        /// <summary>
        /// Build a <see cref="SchemeCollection"/> instance for the release using
        /// the scheme filenames from the XML section describing the schema.
        /// </summary>
        /// <param name="context">The context <see cref="XmlElement"/> for the section.</param>
        /// <returns>A populated <see cref="SchemeCollection"/> instance.</returns>
        private SchemeCollection GetSchemeCollection(XmlElement context)
        {
            SchemeCollection schemes = new SchemeCollection();

            foreach (XmlElement node in XPath.Paths(context, "schemes"))
            {
                schemes.Parse(Application.PathTo(Types.ToToken(node)));
            }

            return(schemes);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructs a <b>SchemaRelease</b> instance describing a schema
 /// based release of a particular <see cref="HandCoded.Meta.Specification"/>.
 /// </summary>
 /// <param name="specification">The owning <see cref="HandCoded.Meta.Specification"/>.</param>
 /// <param name="version">The version identifier for this release.</param>
 /// <param name="namespaceUri">The namespace used to identify the schema.</param>
 /// <param name="schemaLocation">The default schema location.</param>
 /// <param name="preferredPrefix">The preferred prefix for the namespace.</param>
 /// <param name="alternatePrefix">The alternate prefix for the namespace.</param>
 /// <param name="initialiser">The <see cref="HandCoded.Meta.InstanceInitialiser"/>.</param>
 /// <param name="recogniser">The <see cref="HandCoded.Meta.SchemaRecogniser"/>.</param>
 /// <param name="rootElement">The normal root element.</param>
 /// <param name="schemeDefaults">Scheme default URI information.</param>
 /// <param name="schemeCollection">The SchemeCollection for this release.</param>
 public SchemaRelease(HandCoded.Meta.Specification specification, string version,
                      string namespaceUri, string schemaLocation, string preferredPrefix,
                      string alternatePrefix, HandCoded.Meta.InstanceInitialiser initialiser,
                      HandCoded.Meta.SchemaRecogniser recogniser, string rootElement,
                      SchemeDefaults schemeDefaults, SchemeCollection schemeCollection)
     : base(specification, version, namespaceUri, schemaLocation,
            preferredPrefix, alternatePrefix, initialiser, recogniser, rootElement)
 {
     this.schemeDefaults   = schemeDefaults;
     this.schemeCollection = schemeCollection;
 }
        /// <summary>
        /// Validates the data content of a set of elements by locating the scheme
        /// identified by the scheme attribute.
        /// </summary>
        /// <param name="list">An <see cref="XmlNodeList"/> of elements to check.</param>
        /// <param name="errorHandler">The <see cref="ValidationErrorHandler"/> used to report issues.</param>
        /// <returns><c>true</c> if the code values pass the checks, <c>false</c>
        /// otherwise.</returns>
        protected bool Validate(XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool result = true;

            if (list.Count > 0)
            {
                XmlElement fpml    = DOM.GetParent(list [0] as XmlElement);
                string     version = null;

                // Find the FpML root node
                while (fpml != null)
                {
                    if (fpml.LocalName.Equals("FpML"))
                    {
                        version = fpml.GetAttribute("version");
                        break;
                    }
                    if (fpml.HasAttribute("fpmlVersion"))
                    {
                        version = fpml.GetAttribute("fpmlVersion");
                        break;
                    }
                    fpml = DOM.GetParent(fpml);
                }

                SchemeCollection schemes =
                    (Releases.FPML.GetReleaseForVersion(version) as ISchemeAccess).SchemeCollection;

                foreach (XmlElement context in list)
                {
                    string uri = context.GetAttribute(attributeName);

                    if ((uri == null) || (uri.Length == 0))
                    {
                        errorHandler("305", context,
                                     "A qualifying scheme URI has not been defined for this element",
                                     DisplayName, context.LocalName);

                        result = false;
                        continue;
                    }

                    Scheme scheme = schemes.FindSchemeForUri(uri);
                    if (scheme == null)
                    {
                        errorHandler("305", context,
                                     "An unrecognized scheme URI has been used as a qualifier",
                                     DisplayName, uri);

                        result = false;
                        continue;
                    }

                    string value = context.InnerText.Trim();
                    if (scheme.IsValid(value))
                    {
                        continue;
                    }

                    errorHandler("305", context,
                                 "The code value '" + value + "' is not valid in scheme '" + scheme.Uri + "'",
                                 DisplayName, value);

                    result = false;
                }
            }
            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Validates the data content of a set of elements by locating the scheme
        /// identified by the scheme attribute or a default on the root element
        /// for pre FpML-4-0 instances.
        /// </summary>
        /// <param name="list">An <see cref="XmlNodeList"/> of elements to check.</param>
        /// <param name="errorHandler">The <see cref="ValidationErrorHandler"/> used to report issues.</param>
        /// <returns><c>true</c> if the code values pass the checks, <c>false</c>
        /// otherwise.</returns>
        protected bool Validate(XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool result = true;

            if (list.Count > 0)
            {
                XmlElement fpml    = DOM.GetParent(list [0] as XmlElement);
                string     version = null;

                // Find the FpML root node
                while (fpml != null)
                {
                    if (fpml.LocalName.Equals("FpML"))
                    {
                        version = fpml.GetAttribute("version");
                        break;
                    }
                    if (fpml.HasAttribute("fpmlVersion"))
                    {
                        version = fpml.GetAttribute("fpmlVersion");
                        break;
                    }
                    fpml = DOM.GetParent(fpml);
                }

                Release release = Releases.FPML.GetReleaseForVersion(version);
                if (release == null)
                {
                    errorHandler("305", null,
                                 "The document release is not on the schema set -- Check configuration",
                                 DisplayName, null);
                }

                SchemeCollection schemes = (release as ISchemeAccess).SchemeCollection;
                if (schemes == null)
                {
                    errorHandler("305", null,
                                 "No schemes data is available for this FpML version -- Check configuration",
                                 DisplayName, null);
                }

                foreach (XmlElement context in list)
                {
                    // If there is no local override then look for a default on the FpML
                    // element in pre 3-0 versions.
                    string uri = context.GetAttribute(attributeName);
                    if (((uri == null) || (uri.Length == 0)) && (version != null))
                    {
                        string [] components = version.Split('-');
                        if ((components.Length > 1) && (components [0].CompareTo("4") < 0))
                        {
                            ISchemeAccess provider
                                = Specification.ReleaseForDocument(context.OwnerDocument) as ISchemeAccess;

                            string name = provider.SchemeDefaults.GetDefaultAttributeForScheme(attributeName);
                            if (name != null)
                            {
                                uri = fpml.GetAttribute(name);
                            }
                        }
                    }

                    if ((uri == null) || (uri.Length == 0))
                    {
                        errorHandler("305", context,
                                     "A qualifying scheme URI has not been defined for this element",
                                     DisplayName, context.LocalName);

                        result = false;
                        continue;
                    }

                    Scheme scheme = schemes.FindSchemeForUri(uri);
                    if (scheme == null)
                    {
                        errorHandler("305", context,
                                     "An unrecognized scheme URI has been used as a qualifier",
                                     DisplayName, uri);

                        result = false;
                        continue;
                    }

                    string value = context.InnerText.Trim();
                    if (scheme.IsValid(value))
                    {
                        continue;
                    }

                    errorHandler("305", context,
                                 "The code value '" + value + "' is not valid in scheme '" + scheme.Uri + "'",
                                 DisplayName, value);

                    result = false;
                }
            }
            return(result);
        }