فهرست منبع

2003-07-06 Atsushi Enomoto <[email protected]>

	* added BuiltInDatatype.cs.
	* XmlSchemaDatatype.cs : [GetType()] added support for some
	  built-in datatypes.

svn path=/trunk/mcs/; revision=15984
Atsushi Eno 22 سال پیش
والد
کامیت
8978fca00a

+ 275 - 0
mcs/class/System.XML/System.Xml.Schema/BuiltInDatatype.cs

@@ -0,0 +1,275 @@
+//
+// System.Xml.Schema.XmlSchemaDatatype.cs
+//
+// Author:
+//	Atsushi Enomoto
+//
+// (C)2003 Atsushi Enomoto
+//
+using System;
+using System.Collections;
+using System.Text;
+using System.Xml;
+using System.Xml.Schema;
+
+namespace Mono.Xml.Schema
+{
+	public enum XsdWhitespaceFacet
+	{
+		Preserve,
+		Replace,
+		Collapse
+	}
+
+	// xs:string
+	public class XsdString : XmlSchemaDatatype
+	{
+		internal XsdString ()
+		{
+		}
+
+		public override XmlTokenizedType TokenizedType {
+			get { return XmlTokenizedType.CDATA; }
+		}
+
+		public override Type ValueType {
+			get { return typeof (string); }
+		}
+
+		public override object ParseValue (string s,
+			XmlNameTable nameTable, XmlNamespaceManager nsmgr)
+		{
+			return Normalize (s);
+		}
+
+		// Fundamental Facets
+		public virtual bool Bounded {
+			get { return false; }
+		}
+		public virtual bool Finite {
+			get { return false; }
+		}
+		public virtual bool Numeric {
+			get { return false; }
+		}
+		public virtual bool Ordered {
+			get { return false; }
+		}
+
+		// Constraining Facets
+		public bool HasLengthFacet;
+		public bool HasMaxLengthFacet;
+		public bool HasMinLengthFacet;
+		public int Length;
+		public int MaxLength;
+		public int MinLength;
+		public string Pattern;
+		public ICollection Enumeration;
+	}
+
+	// xs:normalizedString
+	public class XsdNormalizedString : XsdString
+	{
+		internal XsdNormalizedString ()
+		{
+			this.WhitespaceValue = XsdWhitespaceFacet.Replace;
+		}
+
+		public override XmlTokenizedType TokenizedType {
+			get { return XmlTokenizedType.CDATA; }
+		}
+
+		public override Type ValueType {
+			get { return typeof (string); }
+		}
+
+		// ParseValue () method is as same as that of xs:string
+	}
+
+	public class XsdToken : XsdNormalizedString
+	{
+		internal XsdToken ()
+		{
+		}
+
+		public override XmlTokenizedType TokenizedType {
+			get { return XmlTokenizedType.CDATA; }
+		}
+
+		public override Type ValueType {
+			get { return typeof (string); }
+		}
+
+		// ParseValue () method is as same as that of xs:string
+	}
+
+	public class XsdLanguage : XsdToken
+	{
+		internal XsdLanguage ()
+		{
+		}
+
+		public override XmlTokenizedType TokenizedType {
+			get { return XmlTokenizedType.CDATA; }
+		}
+
+		public override Type ValueType {
+			get { return typeof (string); }
+		}
+
+		// ParseValue () method is as same as that of xs:string
+	}
+
+	public class XsdNMToken : XsdToken
+	{
+		internal XsdNMToken ()
+		{
+		}
+
+		public override XmlTokenizedType TokenizedType {
+			get { return XmlTokenizedType.NMTOKEN; }
+		}
+
+		public override Type ValueType {
+			get { return typeof (string); }
+		}
+
+		// ParseValue () method is as same as that of xs:string
+	}
+
+	public class XsdNMTokens : XsdNMToken
+	{
+		internal XsdNMTokens ()
+		{
+		}
+
+		public override XmlTokenizedType TokenizedType {
+			get { return XmlTokenizedType.NMTOKENS; }
+		}
+
+		public override Type ValueType {
+			get { return typeof (string []); }
+		}
+
+		// ParseValue () method is as same as that of xs:string
+	}
+
+	public class XsdName : XsdToken
+	{
+		internal XsdName ()
+		{
+		}
+
+		public override XmlTokenizedType TokenizedType {
+			get { return XmlTokenizedType.CDATA; }
+		}
+
+		public override Type ValueType {
+			get { return typeof (string); }
+		}
+
+		// ParseValue () method is as same as that of xs:string
+	}
+
+	public class XsdNCName : XsdName
+	{
+		internal XsdNCName ()
+		{
+		}
+
+		public override XmlTokenizedType TokenizedType {
+			get { return XmlTokenizedType.NCName; }
+		}
+
+		public override Type ValueType {
+			get { return typeof (string); }
+		}
+
+		// ParseValue () method is as same as that of xs:string
+	}
+
+	public class XsdID : XsdName
+	{
+		internal XsdID ()
+		{
+		}
+
+		public override XmlTokenizedType TokenizedType {
+			get { return XmlTokenizedType.ID; }
+		}
+
+		public override Type ValueType {
+			get { return typeof (string); }
+		}
+
+		// ParseValue () method is as same as that of xs:string
+	}
+
+	public class XsdIDRef : XsdName
+	{
+		internal XsdIDRef ()
+		{
+		}
+
+		public override XmlTokenizedType TokenizedType {
+			get { return XmlTokenizedType.IDREF; }
+		}
+
+		public override Type ValueType {
+			get { return typeof (string); }
+		}
+
+		// ParseValue () method is as same as that of xs:string
+	}
+
+	public class XsdIDRefs : XsdName
+	{
+		internal XsdIDRefs ()
+		{
+		}
+
+		public override XmlTokenizedType TokenizedType {
+			get { return XmlTokenizedType.IDREFS; }
+		}
+
+		public override Type ValueType {
+			get { return typeof (string []); }
+		}
+
+		// ParseValue () method is as same as that of xs:string
+	}
+
+	public class XsdEntity : XsdName
+	{
+		internal XsdEntity ()
+		{
+		}
+
+		public override XmlTokenizedType TokenizedType {
+			get { return XmlTokenizedType.ENTITY; }
+		}
+
+		public override Type ValueType {
+			get { return typeof (string); }
+		}
+
+		// ParseValue () method is as same as that of xs:string
+	}
+
+	public class XsdEntities : XsdName
+	{
+		internal XsdEntities ()
+		{
+		}
+
+		public override XmlTokenizedType TokenizedType {
+			get { return XmlTokenizedType.ENTITIES; }
+		}
+
+		public override Type ValueType {
+			get { return typeof (string []); }
+		}
+
+		// ParseValue () method is as same as that of xs:string
+	}
+}

+ 6 - 0
mcs/class/System.XML/System.Xml.Schema/ChangeLog

@@ -1,3 +1,9 @@
+2003-07-06  Atsushi Enomoto  <[email protected]>
+
+	* added BuiltInDatatype.cs.
+	* XmlSchemaDatatype.cs : [GetType()] added support for some 
+	  built-in datatypes.
+
 2003-05-05  Atsushi Enomoto  <[email protected]>
 
 	* XmlSchemaAnnotation.cs : It depended on incorrect ReadNode().

+ 96 - 9
mcs/class/System.XML/System.Xml.Schema/XmlSchemaDatatype.cs

@@ -1,30 +1,117 @@
-// Author: Dwivedi, Ajay kumar
-//            [email protected]
+//
+// System.Xml.Schema.XmlSchemaDatatype.cs
+//
+// Authors:
+//	Dwivedi, Ajay kumar <[email protected]>
+//	Atsushi Enomoto <[email protected]>
+//
 using System;
+using System.Collections;
+using System.Text;
 using System.Xml;
+using Mono.Xml.Schema;
 
 namespace System.Xml.Schema
 {
-	/// <summary>
-	/// Summary description for XmlSchemaDatatype.
-	/// </summary>
 	public abstract class XmlSchemaDatatype
 	{
 		protected XmlSchemaDatatype()
 		{
 		}
 		
+		internal XsdWhitespaceFacet WhitespaceValue =
+			XsdWhitespaceFacet.Preserve;
+
+		// Common Facets
+		public virtual XsdWhitespaceFacet Whitespace {
+			get { return WhitespaceValue; }
+		}
+
 		public abstract XmlTokenizedType TokenizedType {  get; }
 		public abstract Type ValueType {  get; }
 
 		// Methods
-		public abstract object ParseValue(string s, 
+		public abstract object ParseValue (string s, 
 			XmlNameTable nameTable, XmlNamespaceManager nsmgr);
 
-		//TODO: This should return appropriate inbuilt type
-		internal static XmlSchemaDatatype GetType(XmlQualifiedName qname)
+		char [] wsChars = new char [] {' ', '\t', '\n', '\r'};
+
+		protected string Normalize (string s)
+		{
+			switch (Whitespace) {
+			case XsdWhitespaceFacet.Collapse:
+				return String.Join (" ", s.Trim ().Split (wsChars));
+			case XsdWhitespaceFacet.Replace:
+				StringBuilder sb = new StringBuilder (s);
+				sb.Replace ('\r', ' ');
+				sb.Replace ('\n', ' ');
+				sb.Replace ('\t', ' ');
+				string result = sb.ToString ();
+				sb.Length = 0;
+				return result;
+			default:
+				return s;
+			}
+		}
+
+		//TODO: This should return all appropriate inbuilt type
+		internal static XmlSchemaDatatype GetType (XmlQualifiedName qname)
+		{
+			if (qname.Namespace == "http://www.w3.org/2001/XMLSchema" ||
+				qname.Namespace == String.Empty)
+				return FromName (qname.Name);
+			throw new NotImplementedException ();
+		}
+
+		//TODO: This should return all appropriate inbuilt type
+		internal static XmlSchemaDatatype FromName (string localName)
 		{
-			return null;
+			switch (localName) {
+			case "string":
+				return datatypeString;
+			case "normalizedString":
+				return datatypeNormalizedString;
+			case "token":
+				return datatypeToken;
+			case "language":
+				return datatypeLanguage;
+			case "NMTOKEN":
+				return datatypeNMToken;
+			case "NMTOKENS":
+				return datatypeNMTokens;
+			case "Name":
+				return datatypeName;
+			case "NCname":
+				return datatypeNCName;
+			case "ID":
+				return datatypeID;
+			case "IDREF":
+				return datatypeIDRef;
+			case "IDREFS":
+				return datatypeIDRefs;
+			case "ENTITY":
+				return datatypeEntity;
+			case "ENTITIES":
+				return datatypeEntities;
+			default:
+				throw new NotImplementedException ();
+			}
+			throw new NotImplementedException ();
 		}
+
+		private static XsdString datatypeString = new XsdString ();
+		private static XsdNormalizedString datatypeNormalizedString = new XsdNormalizedString ();
+		private static XsdToken datatypeToken = new XsdToken ();
+		private static XsdLanguage datatypeLanguage = new XsdLanguage ();
+		private static XsdNMToken datatypeNMToken = new XsdNMToken ();
+		private static XsdNMTokens datatypeNMTokens = new XsdNMTokens ();
+		private static XsdName datatypeName = new XsdName ();
+		private static XsdNCName datatypeNCName = new XsdNCName ();
+		private static XsdID datatypeID = new XsdID ();
+		private static XsdIDRef datatypeIDRef = new XsdIDRef ();
+		private static XsdIDRefs datatypeIDRefs = new XsdIDRefs ();
+		private static XsdEntity datatypeEntity = new XsdEntity ();
+		private static XsdEntities datatypeEntities = new XsdEntities ();
+
 	}
 }