Author: atsushi
Date: 2007-03-30 10:08:04 -0500 (Fri, 30 Mar 2007)
New Revision: 75201
Modified:
trunk/olive/class/System.Runtime.Serialization/ChangeLog
trunk/olive/class/System.Runtime.Serialization/System.Xml/ChangeLog
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryDictionaryReader.cs
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlDictionaryReader.cs
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlDictionaryReaderAutoGen.cs
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/ChangeLog
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlBinaryDictionaryReaderTest.cs
trunk/olive/class/System.Runtime.Serialization/reader-method-gen.cs
Log:
2007-03-30 Atsushi Enomoto <[EMAIL PROTECTED]>
* reader-method-gen.cs : changed ReadElementContentAsXxx()
implementation to rather call ReadContentAsXxx() so that binary
reader implementation could be implemented easily.
* XmlBinaryDictionaryReader.cs :
implemented some ReadContentAs[Type]() methods.
* XmlDictionaryReader.cs :
Added Read[[Element]ContentAs]String() implementations.
* XmlDictionaryReaderAutoGen.cs : regenerated
* XmlBinaryDictionaryReaderTest.cs : check if it reads nodes
correctly, by comparing direct output to binary writer.
Modified: trunk/olive/class/System.Runtime.Serialization/ChangeLog
===================================================================
--- trunk/olive/class/System.Runtime.Serialization/ChangeLog 2007-03-30
14:57:58 UTC (rev 75200)
+++ trunk/olive/class/System.Runtime.Serialization/ChangeLog 2007-03-30
15:08:04 UTC (rev 75201)
@@ -1,3 +1,9 @@
+2007-03-30 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * reader-method-gen.cs : changed ReadElementContentAsXxx()
+ implementation to rather call ReadContentAsXxx() so that binary
+ reader implementation could be implemented easily.
+
2007-03-16 Atsushi Enomoto <[EMAIL PROTECTED]>
(oops, I forgot to add entry for it last time)
Modified: trunk/olive/class/System.Runtime.Serialization/System.Xml/ChangeLog
===================================================================
--- trunk/olive/class/System.Runtime.Serialization/System.Xml/ChangeLog
2007-03-30 14:57:58 UTC (rev 75200)
+++ trunk/olive/class/System.Runtime.Serialization/System.Xml/ChangeLog
2007-03-30 15:08:04 UTC (rev 75201)
@@ -1,3 +1,11 @@
+2007-03-30 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * XmlBinaryDictionaryReader.cs :
+ implemented some ReadContentAs[Type]() methods.
+ * XmlDictionaryReader.cs :
+ Added Read[[Element]ContentAs]String() implementations.
+ * XmlDictionaryReaderAutoGen.cs : regenerated
+
2007-03-20 Atsushi Enomoto <[EMAIL PROTECTED]>
* XmlDictionaryReader.cs : simply return false for
Modified:
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryDictionaryReader.cs
===================================================================
---
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryDictionaryReader.cs
2007-03-30 14:57:58 UTC (rev 75200)
+++
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryDictionaryReader.cs
2007-03-30 15:08:04 UTC (rev 75201)
@@ -149,6 +149,8 @@
public string Value {
get {
switch (ValueType) {
+ case 0:
+ case BF.Comment:
case BF.Text:
case BF.EmptyText:
return value;
@@ -174,7 +176,7 @@
case BF.Base64:
return Convert.ToBase64String
((byte []) TypedValue);
default:
- throw new
NotImplementedException ();
+ throw new
NotImplementedException ("ValueType " + ValueType + " on node " + NodeType);
}
}
set { this.value = value; }
@@ -228,7 +230,6 @@
// next byte in the source (one byte token ahead always
// happens because there is no "end of start element" mark).
int next = -1;
- // this is for binary identifier 0x9D (and possible 0x9E, 0x9F)
bool is_next_end_element;
// temporary buffer for utf8enc.GetString()
byte [] tmp_buffer = new byte [128];
@@ -542,6 +543,7 @@
break;
case BF.Comment:
node.Value = ReadUTF8 ();
+ node.ValueType = BF.Comment;
node.NodeType = XmlNodeType.Comment;
break;
case BF.ElemString:
@@ -563,7 +565,7 @@
{
if (depth == 0)
throw new XmlException ("Unexpected end of
element while there is no element started.");
- node = node_stack [--depth];
+ current = node = node_stack [--depth];
node.NodeType = XmlNodeType.EndElement;
context.NamespaceManager.PopScope ();
}
@@ -986,9 +988,60 @@
return true;
}
- public override byte [] ReadElementContentAsBase64 ()
+ public override string ReadContentAsString ()
{
- ReadStartElement ();
+ string value = Value;
+ do {
+ switch (NodeType) {
+ case XmlNodeType.Element:
+ case XmlNodeType.EndElement:
+ return value;
+ case XmlNodeType.Text:
+ value += Value;
+ break;
+ }
+ } while (Read ());
+ return value;
+ }
+
+ #region read typed content
+
+ public override int ReadContentAsInt ()
+ {
+ int ret = GetIntValue ();
+ Read ();
+ return ret;
+ }
+
+ int GetIntValue ()
+ {
+ switch (node.ValueType) {
+ case BF.Zero:
+ return 0;
+ case BF.One:
+ return 1;
+ case BF.Int8:
+ return (byte) current.TypedValue;
+ case BF.Int16:
+ return (short) current.TypedValue;
+ case BF.Int32:
+ return (int) current.TypedValue;
+ }
+ throw new InvalidOperationException ("The element
content is not an integer");
+ }
+
+ public override long ReadContentAsLong ()
+ {
+ if (node.ValueType == BF.Int64) {
+ long v = (long) current.TypedValue;
+ Read ();
+ return v;
+ }
+ return ReadContentAsInt ();
+ }
+
+ public override byte [] ReadContentAsBase64 ()
+ {
byte [] ret = null;
if (node.ValueType != BF.Base64)
throw new InvalidOperationException ("The
element content is not base64");
@@ -1005,8 +1058,34 @@
Read ();
//MoveToContent ();
}
- ReadEndElement ();
return ret;
}
+
+ public override Guid ReadContentAsGuid ()
+ {
+ if (node.ValueType != BF.Guid)
+ throw new InvalidOperationException ("The
element content is not Guid");
+ Guid ret = (Guid) node.TypedValue;
+ Read ();
+ return ret;
+ }
+
+ public override UniqueId ReadContentAsUniqueId ()
+ {
+ switch (node.ValueType) {
+ case BF.Text:
+ UniqueId ret = new UniqueId (node.Value);
+ Read ();
+ return ret;
+ case BF.UniqueIdFromGuid:
+ ret = (UniqueId) node.TypedValue;
+ Read ();
+ return ret;
+ default:
+ throw new InvalidOperationException ("The
element content is not Guid");
+ }
+ }
+
+ #endregion
}
}
Modified:
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlDictionaryReader.cs
===================================================================
---
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlDictionaryReader.cs
2007-03-30 14:57:58 UTC (rev 75200)
+++
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlDictionaryReader.cs
2007-03-30 15:08:04 UTC (rev 75201)
@@ -280,16 +280,15 @@
throw new NotImplementedException ();
}
- [MonoTODO]
public override string ReadContentAsString ()
{
- return base.ReadContentAsString ();
+ return ReadContentAsString
(Quotas.MaxStringContentLength);
}
[MonoTODO]
protected string ReadContentAsString (int
maxStringContentLength)
{
- throw new NotImplementedException ();
+ return base.ReadContentAsString ();
}
[MonoTODO]
@@ -354,6 +353,40 @@
return ret;
}
+ public override string ReadElementContentAsString ()
+ {
+ if (IsEmptyElement) {
+ Read ();
+ return String.Empty;
+ } else {
+ ReadStartElement ();
+ string s;
+ if (NodeType == XmlNodeType.EndElement)
+ s = String.Empty;
+ else
+ s = ReadContentAsString ();
+ ReadEndElement ();
+ return s;
+ }
+ }
+
+ public override string ReadString ()
+ {
+ return ReadString (Quotas.MaxStringContentLength);
+ }
+
+ [MonoTODO]
+ protected string ReadString (int maxStringContentLength)
+ {
+ return base.ReadString ();
+ }
+
+ [MonoTODO]
+ public virtual byte [] ReadValueAsBase64 ()
+ {
+ return ReadContentAsBase64 ();
+ }
+
#endregion
#region Factory Methods
Modified:
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlDictionaryReaderAutoGen.cs
===================================================================
---
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlDictionaryReaderAutoGen.cs
2007-03-30 14:57:58 UTC (rev 75200)
+++
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlDictionaryReaderAutoGen.cs
2007-03-30 15:08:04 UTC (rev 75201)
@@ -462,45 +462,61 @@
return ReadTimeSpanArray (localName.Value,
namespaceUri.Value);
}
- public override bool
ReadElementContentAsBoolean ()
- {
- return ReadElementContentAsBoolean
(LocalName, NamespaceURI);
- }
+ public override bool ReadElementContentAsBoolean ()
+ {
+ ReadStartElement (LocalName, NamespaceURI);
+ bool ret = ReadContentAsBoolean ();
+ ReadEndElement ();
+ return ret;
+ }
- public override DateTime
ReadElementContentAsDateTime ()
- {
- return ReadElementContentAsDateTime
(LocalName, NamespaceURI);
- }
+ public override DateTime ReadElementContentAsDateTime ()
+ {
+ ReadStartElement (LocalName, NamespaceURI);
+ DateTime ret = ReadContentAsDateTime ();
+ ReadEndElement ();
+ return ret;
+ }
- public override decimal
ReadElementContentAsDecimal ()
- {
- return ReadElementContentAsDecimal
(LocalName, NamespaceURI);
- }
+ public override decimal ReadElementContentAsDecimal ()
+ {
+ ReadStartElement (LocalName, NamespaceURI);
+ decimal ret = ReadContentAsDecimal ();
+ ReadEndElement ();
+ return ret;
+ }
- public override double
ReadElementContentAsDouble ()
- {
- return ReadElementContentAsDouble
(LocalName, NamespaceURI);
- }
+ public override double ReadElementContentAsDouble ()
+ {
+ ReadStartElement (LocalName, NamespaceURI);
+ double ret = ReadContentAsDouble ();
+ ReadEndElement ();
+ return ret;
+ }
- public override float ReadElementContentAsFloat
()
- {
- return ReadElementContentAsFloat
(LocalName, NamespaceURI);
- }
+ public override float ReadElementContentAsFloat ()
+ {
+ ReadStartElement (LocalName, NamespaceURI);
+ float ret = ReadContentAsFloat ();
+ ReadEndElement ();
+ return ret;
+ }
- public override int ReadElementContentAsInt ()
- {
- return ReadElementContentAsInt
(LocalName, NamespaceURI);
- }
+ public override int ReadElementContentAsInt ()
+ {
+ ReadStartElement (LocalName, NamespaceURI);
+ int ret = ReadContentAsInt ();
+ ReadEndElement ();
+ return ret;
+ }
- public override long ReadElementContentAsLong ()
- {
- return ReadElementContentAsLong
(LocalName, NamespaceURI);
- }
+ public override long ReadElementContentAsLong ()
+ {
+ ReadStartElement (LocalName, NamespaceURI);
+ long ret = ReadContentAsLong ();
+ ReadEndElement ();
+ return ret;
+ }
- public override string
ReadElementContentAsString ()
- {
- return ReadElementContentAsString
(LocalName, NamespaceURI);
- }
-
}
}
Modified:
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/ChangeLog
===================================================================
--- trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/ChangeLog
2007-03-30 14:57:58 UTC (rev 75200)
+++ trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/ChangeLog
2007-03-30 15:08:04 UTC (rev 75201)
@@ -1,3 +1,8 @@
+2007-03-30 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * XmlBinaryDictionaryReaderTest.cs : check if it reads nodes
+ correctly, by comparing direct output to binary writer.
+
2007-03-19 Atsushi Enomoto <[EMAIL PROTECTED]>
* XmlBinaryDictionaryWriterTest.cs : more WriteValue() cases.
Modified:
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlBinaryDictionaryReaderTest.cs
===================================================================
---
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlBinaryDictionaryReaderTest.cs
2007-03-30 14:57:58 UTC (rev 75200)
+++
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlBinaryDictionaryReaderTest.cs
2007-03-30 15:08:04 UTC (rev 75201)
@@ -48,10 +48,17 @@
[Test]
public void UseCase1 ()
{
+ string xml = @"<?xml version=""1.0""
encoding=""utf-16""?><root a=""""><!----> <AAA
xmlns=""urn:AAA""></AAA><ePfix:AAA
xmlns:ePfix=""urn:AAABBB""></ePfix:AAA><AAA>CCC�X��CCCAAA&AAADDD&DDD��<!--COMMENT--></AAA><AAA
BBB=""bbb"" pfix:BBB=""bbbbb"" xml:lang=""ja"" xml:space=""preserve""
xml:base=""local:hogehoge"" xmlns:pfix=""urn:bbb"">CCCICAg/4Aw</AAA></root>";
+
XmlDictionaryReader reader =
XmlDictionaryReader.CreateBinaryReader
(usecase1,new XmlDictionaryReaderQuotas ());
+ StringWriter sw = new StringWriter ();
+ XmlWriter xw = XmlWriter.Create (sw);
+ reader.Read ();
while (!reader.EOF)
- reader.Read ();
+ xw.WriteNode (reader, false);
+ xw.Close ();
+ Assert.AreEqual (xml, sw.ToString ());
}
// $ : kind
Modified: trunk/olive/class/System.Runtime.Serialization/reader-method-gen.cs
===================================================================
--- trunk/olive/class/System.Runtime.Serialization/reader-method-gen.cs
2007-03-30 14:57:58 UTC (rev 75200)
+++ trunk/olive/class/System.Runtime.Serialization/reader-method-gen.cs
2007-03-30 15:08:04 UTC (rev 75201)
@@ -98,25 +98,31 @@
}
Type xr = typeof (XmlReader);
- string [] names = new string [] {"ReadContentAs",
"ReadElementContentAs"};
- foreach (string name in names) {
- foreach (MethodInfo mi in xr.GetMethods ()) {
- if (!mi.Name.StartsWith (name))
- continue;
- ParameterInfo [] pl = mi.GetParameters ();
- if (pl.Length != 2 || pl [0].ParameterType !=
typeof (string))
- continue;
- if (mi.Name.EndsWith ("AsObject"))
- continue; // special case to filter out.
+ string name = "ReadElementContentAs";
+ foreach (MethodInfo mi in xr.GetMethods ()) {
+ if (!mi.Name.StartsWith (name))
+ continue;
+ ParameterInfo [] pl = mi.GetParameters ();
+ if (pl.Length != 2 || pl [0].ParameterType != typeof
(string))
+ continue;
+ if (mi.Name.EndsWith ("AsObject"))
+ continue; // special case to filter out.
+ if (mi.Name.EndsWith ("AsString"))
+ continue; // special case to filter out.
- bool isOverride = xr.GetMethod (mi.Name,
Type.EmptyTypes) != null;
- Console.WriteLine (@"
- public {2}{0} {1} ()
- {{
- return {1} (LocalName, NamespaceURI);
- }}", ToCSharp (mi.ReturnType), mi.Name,
- isOverride ? "override " : null);
- }
+ bool isOverride = xr.GetMethod (mi.Name,
Type.EmptyTypes) != null;
+ Console.WriteLine (@"
+ public {3}{0} {1} ()
+ {{
+ ReadStartElement (LocalName, NamespaceURI);
+ {0} ret = {2} ();
+ ReadEndElement ();
+ return ret;
+ }}",
+ ToCSharp (mi.ReturnType),
+ mi.Name,
+ mi.Name.Replace ("Element", String.Empty),
+ isOverride ? "override " : null);
}
Console.WriteLine (@"
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches