From: <bo...@us...> - 2009-05-25 15:42:43
|
Revision: 334 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=334&view=rev Author: bodewig Date: 2009-05-25 15:42:30 +0000 (Mon, 25 May 2009) Log Message: ----------- validation infrastructure .NET style Added Paths: ----------- trunk/xmlunit/src/main/net-core/validation/ trunk/xmlunit/src/main/net-core/validation/Languages.cs trunk/xmlunit/src/main/net-core/validation/ValidationProblem.cs trunk/xmlunit/src/main/net-core/validation/ValidationResult.cs trunk/xmlunit/src/main/net-core/validation/Validator.cs Copied: trunk/xmlunit/src/main/net-core/validation/Languages.cs (from rev 333, trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java) =================================================================== --- trunk/xmlunit/src/main/net-core/validation/Languages.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/validation/Languages.cs 2009-05-25 15:42:30 UTC (rev 334) @@ -0,0 +1,32 @@ +/* + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +namespace net.sf.xmlunit.validation { + + /// <summary> + /// Constants for the languages supported by XMLUnit's schema + /// validation. + /// </summary> +public static class Languages { + + /// <summary>W3C XML Schema.</summary> + public const string W3C_XML_SCHEMA_NS_URI = + "http://www.w3.org/2001/XMLSchema"; + + /// <summary>DTD.</summary> + public const string XML_DTD_NS_URI = "http://www.w3.org/TR/REC-xml"; + + /// <summary>XDR.</summary> + public const string XDR_NS_URI = "xmlunit:validation:XDR"; +} +} Property changes on: trunk/xmlunit/src/main/net-core/validation/Languages.cs ___________________________________________________________________ Added: svn:mergeinfo + Added: svn:eol-style + native Copied: trunk/xmlunit/src/main/net-core/validation/ValidationProblem.cs (from rev 333, trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java) =================================================================== --- trunk/xmlunit/src/main/net-core/validation/ValidationProblem.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/validation/ValidationProblem.cs 2009-05-25 15:42:30 UTC (rev 334) @@ -0,0 +1,72 @@ +/* + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +using System.Xml.Schema; + +namespace net.sf.xmlunit.validation { + + /// <summary> + /// A validation "problem" which may be an error or a warning. + /// </summary> +public class ValidationProblem { + public const int UNKNOWN = -1; + + private readonly int line, column; + private readonly XmlSeverityType type; + private readonly string message; + + public ValidationProblem(string message, int line, int column, + XmlSeverityType type) { + this.message = message; + this.line = line; + this.column = column; + this.type = type; + } + + /// <summary> + /// The line where the problem occured or UNKNOWN. + /// </summary> + public int Line { + get { + return line; + } + } + + /// <summary> + /// The column where the problem occured or UNKNOWN. + /// </summary> + public int Column { + get { + return column; + } + } + + /// <summary> + /// Whether this is an error or a warning. + /// </summary> + public XmlSeverityType Type { + get { + return type; + } + } + + /// <summary> + /// The problem's message. + /// </summary> + public string Message { + get { + return message; + } + } +} +} Property changes on: trunk/xmlunit/src/main/net-core/validation/ValidationProblem.cs ___________________________________________________________________ Added: svn:mergeinfo + Added: svn:eol-style + native Copied: trunk/xmlunit/src/main/net-core/validation/ValidationResult.cs (from rev 333, trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationResult.java) =================================================================== --- trunk/xmlunit/src/main/net-core/validation/ValidationResult.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/validation/ValidationResult.cs 2009-05-25 15:42:30 UTC (rev 334) @@ -0,0 +1,50 @@ +/* + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using System.Collections.Generic; + +namespace net.sf.xmlunit.validation { + + /// <summary> + /// The result of a validation. + /// </summary> +public class ValidationResult { + private readonly bool valid; + private readonly IEnumerable<ValidationProblem> problems; + + public ValidationResult(bool valid, IEnumerable<ValidationProblem> problems) { + this.valid = valid; + this.problems = problems; + } + + /// <summary> + /// Has the validation been successful? + /// </summary> + public bool Valid { + get { + return valid; + } + } + + /// <summary> + /// Retrieves the problems that have been found. + /// </summary> + public IEnumerable<ValidationProblem> Problems { + get { + return problems; + } + } +} +} + Property changes on: trunk/xmlunit/src/main/net-core/validation/ValidationResult.cs ___________________________________________________________________ Added: svn:mergeinfo + Added: svn:eol-style + native Copied: trunk/xmlunit/src/main/net-core/validation/Validator.cs (from rev 333, trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java) =================================================================== --- trunk/xmlunit/src/main/net-core/validation/Validator.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/validation/Validator.cs 2009-05-25 15:42:30 UTC (rev 334) @@ -0,0 +1,108 @@ +/* + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +using System; +using System.Collections.Generic; +using System.Xml; + +namespace net.sf.xmlunit.validation { + + /// <summary> + /// Validates a piece of XML against a schema given in a supported + /// language or the defintion of such a schema itself. + /// </summary> +public class Validator { + private readonly ValidationType language; + private string schemaURI; + private ISource[] sourceLocations; + + private Validator(ValidationType language) { + this.language = language; + } + + /// <summary> + /// The URI (or for example the System ID in case of a DTD) that + /// identifies the schema to validate or use during validation. + /// </summary> + public virtual string SchemaURI { + set { + schemaURI = value; + } + get { + return schemaURI; + } + } + + /// <summary> + /// Where to find the schema. + /// </summary> + public virtual ISource[] SchemaSources { + set { + if (value != null) { + sourceLocations = new ISource[value.Length]; + Array.Copy(value, 0, sourceLocations, 0, value.Length); + } else { + sourceLocations = null; + } + } + get { + return sourceLocations; + } + } + + /// <summary> + /// Where to find the schema. + /// </summary> + public ISource SchemaSource { + set { + SchemaSources = value == null ? null : new ISource[] {value}; + } + } + + /// <summary> + /// Validates a schema. + /// </summary> + public virtual ValidationResult ValidateSchema() { + throw new NotImplementedException(); + } + + /// <summary> + /// Validates an instance against the schema. + /// </summary> + public virtual ValidationResult ValidateInstance(ISource instance) { + throw new NotImplementedException(); + } + + + private static readonly IDictionary<string, ValidationType> types; + + static Validator() { + types = new Dictionary<string, ValidationType>(); + types[Languages.W3C_XML_SCHEMA_NS_URI] = ValidationType.Schema; + types[Languages.XML_DTD_NS_URI] = ValidationType.DTD; + types[Languages.XDR_NS_URI] = ValidationType.XDR; + } + + /// <summary> + /// Factory that obtains a Validator instance based on the schema language. + /// </summary> + public static Validator ForLanguage(string language) { + ValidationType t; + if (types.TryGetValue(language, out t)) { + return new Validator(t); + } + // TODO pick a better exception type + throw new NotImplementedException(); + } +} +} Property changes on: trunk/xmlunit/src/main/net-core/validation/Validator.cs ___________________________________________________________________ Added: svn:mergeinfo + Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |