2003-09-14 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
authorAtsushi Eno <atsushieno@gmail.com>
Sun, 14 Sep 2003 16:15:44 +0000 (16:15 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Sun, 14 Sep 2003 16:15:44 +0000 (16:15 -0000)
* DTMXPathNavigator.cs,
  DTMXPathDocument.cs,
  DTMXPathDocumentBuilder.cs : Added IXmlLineInfo support. Removed
  node's extraneous schemaType. Some code reformatting.

svn path=/trunk/mcs/; revision=18087

mcs/class/System.XML/Mono.Xml.XPath/ChangeLog
mcs/class/System.XML/Mono.Xml.XPath/DTMXPathDocument.cs
mcs/class/System.XML/Mono.Xml.XPath/DTMXPathDocumentBuilder.cs
mcs/class/System.XML/Mono.Xml.XPath/DTMXPathNavigator.cs

index 3bc32187bca6492e030257b708d395de95ab2856..0e238b1051921be7f5459a10678282007554ee26 100644 (file)
@@ -1,3 +1,10 @@
+2003-09-14  Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
+
+       * DTMXPathNavigator.cs,
+         DTMXPathDocument.cs,
+         DTMXPathDocumentBuilder.cs : Added IXmlLineInfo support. Removed
+         node's extraneous schemaType. Some code reformatting.
+
 2003-09-13 Ben Maurer  <bmaurer@users.sourceforge.net>
 
        * Pattern.cs: Support static context.
index 8498e07791f35ca0089c78696ece7dd3f7aa1f2e..82b9375287953faa183229e8a7dc33756ae61653 100644 (file)
@@ -39,7 +39,8 @@ namespace Mono.Xml.XPath
                        string [] value__,
                        string [] xmlLang__,
                        int [] namespaceNode__,
-                       object [] schemaType__,
+                       int [] nodeLineNumber__,
+                       int [] nodeLinePosition__,
                        int [] ownerElement__,
                        int [] nextAttribute__,
                        string [] attrLocalName__,
@@ -47,6 +48,8 @@ namespace Mono.Xml.XPath
                        string [] attrNsUri__,
                        string [] attrValue__,
                        object [] attrSchemaType__,
+                       int [] attrLineNumber__,
+                       int [] attrLinePosition__,
                        int [] nsDeclaredElement__,
                        int [] nextNsNode__,
                        string [] nsNodeName__,
@@ -69,7 +72,8 @@ namespace Mono.Xml.XPath
                        value_ = value__;
                        xmlLang_ = xmlLang__;
                        namespaceNode_ = namespaceNode__;
-                       schemaType_ = schemaType__;
+                       nodeLineNumber_ = nodeLineNumber__;
+                       nodeLinePosition_ = nodeLinePosition__;
 
                        // Attribute
                        ownerElement_ = ownerElement__;
@@ -79,6 +83,8 @@ namespace Mono.Xml.XPath
                        attrNsUri_ = attrNsUri__;
                        attrValue_ = attrValue__;
                        attrSchemaType_ = attrSchemaType__;
+                       attrLineNumber_ = attrLineNumber__;
+                       attrLinePosition_ = attrLinePosition__;
 
                        // NamespaceNode
                        nsDeclaredElement_ = nsDeclaredElement__;
@@ -98,7 +104,40 @@ namespace Mono.Xml.XPath
                public XPathNavigator CreateNavigator ()
                {
                        if (root == null) {
-                               root = new DTMXPathNavigator (this, nameTable, firstChild_, parent_, firstAttribute_, previousSibling_, nextSibling_, depth_, position_, nodeType_, baseUri_, isEmptyElement_, localName_, namespaceUri_, prefix_, value_, xmlLang_, namespaceNode_, schemaType_, ownerElement_, nextAttribute_, attrLocalName_, attrPrefix_, attrNsUri_, attrValue_, attrSchemaType_, nsDeclaredElement_, nextNsNode_, nsNodeName_, nsNodeUri_, idTable_);
+                               root = new DTMXPathNavigator (this,
+                                       nameTable, 
+                                       firstChild_, 
+                                       parent_, 
+                                       firstAttribute_, 
+                                       previousSibling_, 
+                                       nextSibling_, 
+                                       depth_, 
+                                       position_, 
+                                       nodeType_, 
+                                       baseUri_, 
+                                       isEmptyElement_, 
+                                       localName_, 
+                                       namespaceUri_, 
+                                       prefix_, 
+                                       value_, 
+                                       xmlLang_, 
+                                       namespaceNode_, 
+                                       nodeLineNumber_, 
+                                       nodeLinePosition_, 
+                                       ownerElement_, 
+                                       nextAttribute_, 
+                                       attrLocalName_, 
+                                       attrPrefix_, 
+                                       attrNsUri_, 
+                                       attrValue_, 
+                                       attrSchemaType_, 
+                                       attrLineNumber_,
+                                       attrLinePosition_,
+                                       nsDeclaredElement_, 
+                                       nextNsNode_, 
+                                       nsNodeName_, 
+                                       nsNodeUri_, 
+                                       idTable_);
                                return root;
                        } else
                                return root.Clone ();
@@ -130,7 +169,8 @@ namespace Mono.Xml.XPath
                string [] value_;
                string [] xmlLang_;
                int [] namespaceNode_;
-               object [] schemaType_;          // for XPath 2.0
+               int [] nodeLineNumber_;
+               int [] nodeLinePosition_;
 
                // Attribute
                int [] ownerElement_;
@@ -139,7 +179,9 @@ namespace Mono.Xml.XPath
                string [] attrPrefix_;
                string [] attrNsUri_;
                string [] attrValue_;
-               object [] attrSchemaType_;      // for XPath 2.0
+               object [] attrSchemaType_;      // for id()
+               int [] attrLineNumber_;
+               int [] attrLinePosition_;
 
                // NamespaceNode
                int [] nsDeclaredElement_;      // the Element that declares NS, or Root.
index a3af4d2317c5de6b5ee9887e7f7784be1443fab3..04c7b871898e90ca39a109f1ef90a75a38fae1ff 100644 (file)
@@ -19,37 +19,39 @@ namespace Mono.Xml.XPath
        public class DTMXPathDocumentBuilder
        {
                public DTMXPathDocumentBuilder (string url)
-                       : this (url, XmlSpace.None, false)
+                       : this (url, XmlSpace.None, false, 100)
                {
                }
 
                public DTMXPathDocumentBuilder (string url, XmlSpace space)
-                       : this (url, space, false)
+                       : this (url, space, false, 100)
                {
                }
 
-               public DTMXPathDocumentBuilder (string url, XmlSpace space, bool supportID)
-                       : this (new XmlTextReader (url), space, supportID)
+               public DTMXPathDocumentBuilder (string url, XmlSpace space, bool supportID, int defaultCapacity)
+                       : this (new XmlTextReader (url), space, supportID, defaultCapacity)
                {
                }
 
                public DTMXPathDocumentBuilder (XmlReader reader)
-                       : this (reader, XmlSpace.None, false)
+                       : this (reader, XmlSpace.None, false, 100)
                {
                }
 
                public DTMXPathDocumentBuilder (XmlReader reader, XmlSpace space)
-                       : this (reader, space, false)
+                       : this (reader, space, false, 100)
                {
                }
 
-               public DTMXPathDocumentBuilder (XmlReader reader, XmlSpace space, bool supportID)
+               public DTMXPathDocumentBuilder (XmlReader reader, XmlSpace space, bool supportID, int defaultCapacity)
                {
                        this.xmlReader = reader;
                        if (supportID)
                                this.validatingReader = reader as XmlValidatingReader;
+                       lineInfo = reader as IXmlLineInfo;
                        this.xmlSpace = xmlSpace;
                        this.nameTable = reader.NameTable;
+                       DefaultCapacity = defaultCapacity;
                        Compile ();
                }
                
@@ -58,6 +60,7 @@ namespace Mono.Xml.XPath
                XmlValidatingReader validatingReader;
                XmlSpace xmlSpace;
                XmlNameTable nameTable;
+               IXmlLineInfo lineInfo;
                int defaultCapacity = 100;
                public int DefaultCapacity {
                        get { return defaultCapacity; }
@@ -86,7 +89,8 @@ namespace Mono.Xml.XPath
                string [] value_ = new string [0];
                string [] xmlLang_ = new string [0];
                int [] namespaceNode_ = new int [0];
-               object [] schemaType_ = new object [0];
+               int [] nodeLineNumber_ = new int [0];
+               int [] nodeLinePosition_ = new int [0];
 
                // Attribute
                int [] ownerElement_ = new int [0];
@@ -96,6 +100,8 @@ namespace Mono.Xml.XPath
                string [] attrNsUri_ = new string [0];
                string [] attrValue_ = new string [0];
                object [] attrSchemaType_ = new object [0];
+               int [] attrLineNumber_ = new int [0];
+               int [] attrLinePosition_ = new int [0];
 
                // NamespaceNode
                int [] nsDeclaredElement_ = new int [100];
@@ -131,7 +137,8 @@ namespace Mono.Xml.XPath
                                value_,
                                xmlLang_,
                                namespaceNode_,
-                               schemaType_,
+                               nodeLineNumber_,
+                               nodeLinePosition_,
 
                                // Attribute
                                ownerElement_,
@@ -141,6 +148,8 @@ namespace Mono.Xml.XPath
                                attrNsUri_,
                                attrValue_,
                                attrSchemaType_,
+                               attrLineNumber_,
+                               attrLinePosition_,
 
                                // NamespaceNode
                                nsDeclaredElement_,
@@ -158,9 +167,9 @@ namespace Mono.Xml.XPath
                        // index 0 is dummy. No node (including Root) is assigned to this index
                        // So that we can easily compare index != 0 instead of index < 0.
                        // (Difference between jnz or jbe in 80x86.)
-                       AddNode (0, 0, 0, 0, 0, 0, XPathNodeType.All, "", false, "", "", "", "", "", 0, null);
+                       AddNode (0, 0, 0, 0, 0, 0, XPathNodeType.All, "", false, "", "", "", "", "", 0, 0, 0);
                        nodeIndex++;
-                       AddAttribute (0, null, null, null, null, null);
+                       AddAttribute (0, null, null, null, null, null, 0, 0);
                        nextAttribute_ [0] = 0;
                        AddNsNode (0, null, null);
                        nsIndex++;
@@ -169,7 +178,7 @@ namespace Mono.Xml.XPath
                        nextNsNode_ [1] = 0;
 
                        // add root.
-                       AddNode (0, 0, 0, 0, -1, 0, XPathNodeType.Root, xmlReader.BaseURI, false, "", "", "", "", "", 1, null);
+                       AddNode (0, 0, 0, 0, -1, 0, XPathNodeType.Root, xmlReader.BaseURI, false, "", "", "", "", "", 1, 0, 0);
 
                        this.nodeIndex = 1;
                        this.requireFirstChildFill = true;
@@ -267,7 +276,8 @@ namespace Mono.Xml.XPath
                                        value,
                                        xmlReader.XmlLang,
                                        nsIndex,
-                                       null);  // schemaType
+                                       lineInfo != null ? lineInfo.LineNumber : 0,
+                                       lineInfo != null ? lineInfo.LinePosition : 0);
                                // this code is tricky, but after ReadString() invokation,
                                // xmlReader is moved to next node!!
                                if (value == null)
@@ -311,7 +321,14 @@ namespace Mono.Xml.XPath
                                        } else {
                                                // add attribute node.
                                                attributeIndex ++;
-                                               this.AddAttribute (nodeIndex, xmlReader.LocalName, xmlReader.NamespaceURI, xmlReader.Prefix != null ? xmlReader.Prefix : String.Empty, xmlReader.Value, null);
+                                               this.AddAttribute (nodeIndex,
+                                                       xmlReader.LocalName,
+                                                       xmlReader.NamespaceURI, 
+                                                       xmlReader.Prefix != null ? xmlReader.Prefix : String.Empty, 
+                                                       xmlReader.Value,
+                                                       null, 
+                                                       lineInfo != null ? lineInfo.LineNumber : 0,
+                                                       lineInfo != null ? lineInfo.LinePosition : 0);
                                                if (firstAttributeIndex == 0)
                                                        firstAttributeIndex = attributeIndex;
                                                else
@@ -349,7 +366,8 @@ namespace Mono.Xml.XPath
                                "",     // Element has no internal value.
                                xmlReader.XmlLang,
                                nsIndex,
-                               null);  // schemaType
+                               lineInfo != null ? lineInfo.LineNumber : 0,
+                               lineInfo != null ? lineInfo.LinePosition : 0);
                        if (!xmlReader.IsEmptyElement)
                                requireFirstChildFill = true;
                }
@@ -407,7 +425,8 @@ namespace Mono.Xml.XPath
                        SetStringArrayLength (ref value_, size);
                        SetStringArrayLength (ref xmlLang_, size);
                        SetIntArrayLength (ref namespaceNode_, size);
-                       SetObjectArrayLength (ref schemaType_, size);
+                       SetIntArrayLength (ref nodeLineNumber_, size);
+                       SetIntArrayLength (ref nodeLinePosition_, size);
                }
 
                private void SetAttributeArraysLength (int size)
@@ -419,6 +438,8 @@ namespace Mono.Xml.XPath
                        SetStringArrayLength (ref attrNsUri_, size);
                        SetStringArrayLength (ref attrValue_, size);
                        SetObjectArrayLength (ref attrSchemaType_, size);
+                       SetIntArrayLength (ref attrLineNumber_, size);
+                       SetIntArrayLength (ref attrLinePosition_, size);
                }
 
                private void SetNsArraysLength (int size)
@@ -430,7 +451,7 @@ namespace Mono.Xml.XPath
                }
 
                // Here followings are skipped: firstChild, nextSibling, 
-               public void AddNode (int parent, int firstAttribute, int attributeEnd, int previousSibling, int depth, int position, XPathNodeType nodeType, string baseUri, bool isEmptyElement, string localName, string ns, string prefix, string value, string xmlLang, int namespaceNode, object schemaType)
+               public void AddNode (int parent, int firstAttribute, int attributeEnd, int previousSibling, int depth, int position, XPathNodeType nodeType, string baseUri, bool isEmptyElement, string localName, string ns, string prefix, string value, string xmlLang, int namespaceNode, int lineNumber, int linePosition)
                {
                        if (firstChild_.Length < nodeIndex + 1) {
                                if (firstChild_.Length >= defaultCapacity)
@@ -454,11 +475,12 @@ namespace Mono.Xml.XPath
                        value_ [nodeIndex] = value;
                        xmlLang_ [nodeIndex] = xmlLang;
                        namespaceNode_ [nodeIndex] = namespaceNode;
-                       schemaType_ [nodeIndex] = schemaType;
+                       nodeLineNumber_ [nodeIndex] = lineNumber;
+                       nodeLinePosition_ [nodeIndex] = linePosition;
                }
 
                // Followings are skipped: nextAttribute,
-               public void AddAttribute (int ownerElement, string localName, string ns, string prefix, string value, object schemaType)
+               public void AddAttribute (int ownerElement, string localName, string ns, string prefix, string value, object schemaType, int lineNumber, int linePosition)
                {
                        if (ownerElement_.Length < attributeIndex + 1) {
                                if (ownerElement_.Length >= defaultCapacity)
@@ -472,6 +494,8 @@ namespace Mono.Xml.XPath
                        attrPrefix_ [attributeIndex] = prefix;
                        attrValue_ [attributeIndex] = value;
                        attrSchemaType_ [attributeIndex] = schemaType;
+                       attrLineNumber_ [attributeIndex] = lineNumber;
+                       attrLinePosition_ [attributeIndex] = linePosition;
                }
 
                // Followings are skipped: nextNsNode (may be next attribute in the same element, or ancestors' nsNode)
index 80f702ce5e8342bee868bc49fcd1eb3875a68bb5..9716329cdceba139fb7c92fd97fbb9f6561493ec 100644 (file)
@@ -15,7 +15,7 @@ using System.Xml.XPath;
 
 namespace Mono.Xml.XPath
 {
-       public class DTMXPathNavigator : XPathNavigator
+       public class DTMXPathNavigator : XPathNavigator, IXmlLineInfo
        {
 
 #region Copy of XPathDocument
@@ -29,10 +29,12 @@ namespace Mono.Xml.XPath
                        string [] localName__, string [] namespaceUri__, 
                        string [] prefix__, string [] value__, 
                        string [] xmlLang__, int [] namespaceNode__, 
-                       object [] schemaType__, int [] ownerElement__, 
+                       int [] nodeLineNumber__, int [] nodeLinePosition__, 
+                       int [] ownerElement__, 
                        int [] nextAttribute__, string [] attrLocalName__, 
                        string [] attrPrefix__, string [] attrNsUri__, 
                        string [] attrValue__, object [] attrSchemaType__, 
+                       int [] attrLineNumber__, int [] attrLinePosition__, 
                        int [] nsDeclaredElement__, int [] nextNsNode__, 
                        string [] nsNodeName__, string [] nsNodeUri__,
                        Hashtable idTable__)
@@ -53,7 +55,8 @@ namespace Mono.Xml.XPath
                        value_ = value__;
                        xmlLang_ = xmlLang__;
                        namespaceNode_ = namespaceNode__;
-                       schemaType_ = schemaType__;
+                       nodeLineNumber_ = nodeLineNumber__;
+                       nodeLinePosition_ = nodeLinePosition__;
 
                        // Attribute
                        ownerElement_ = ownerElement__;
@@ -63,6 +66,8 @@ namespace Mono.Xml.XPath
                        attrNsUri_ = attrNsUri__;
                        attrValue_ = attrValue__;
                        attrSchemaType_ = attrSchemaType__;
+                       attrLineNumber_ = attrLineNumber__;
+                       attrLinePosition_ = attrLinePosition__;
 
                        // NamespaceNode
                        nsDeclaredElement_ = nsDeclaredElement__;
@@ -85,9 +90,11 @@ namespace Mono.Xml.XPath
                        org.position_, org.nodeType_, org.baseUri_,
                        org.isEmptyElement_, org.localName_, org.namespaceUri_,
                        org.prefix_, org.value_, org.xmlLang_,
-                       org.namespaceNode_, org.schemaType_, org.ownerElement_, 
+                       org.namespaceNode_, org.nodeLineNumber_, org.nodeLinePosition_, 
+                       org.ownerElement_, 
                        org.nextAttribute_, org.attrLocalName_, org.attrPrefix_, 
                        org.attrNsUri_, org.attrValue_, org.attrSchemaType_, 
+                       org.attrLineNumber_, org.attrLinePosition_,
                        org.nsDeclaredElement_, org.nextNsNode_, org.nsNodeName_,
                        org.nsNodeUri_, org.idTable_)
                {
@@ -121,7 +128,8 @@ namespace Mono.Xml.XPath
                string [] value_;
                string [] xmlLang_;
                int [] namespaceNode_;
-               object [] schemaType_;  // for XPath 2.0
+               int [] nodeLineNumber_;
+               int [] nodeLinePosition_;
 
                // Attribute
                int [] ownerElement_;
@@ -130,7 +138,9 @@ namespace Mono.Xml.XPath
                string [] attrPrefix_;
                string [] attrNsUri_;
                string [] attrValue_;
-               object [] attrSchemaType_;      // for XPath 2.0
+               object [] attrSchemaType_;      // for id()
+               int [] attrLineNumber_;
+               int [] attrLinePosition_;
 
                // NamespaceNode
                int [] nsDeclaredElement_;      // the Element that declares NS.
@@ -182,6 +192,20 @@ namespace Mono.Xml.XPath
                        get { return currentIsNode ? isEmptyElement_ [currentNode] : false; }
                }
 
+               int IXmlLineInfo.LineNumber {
+                       get {
+                               return currentIsAttr ? attrLineNumber_ [currentAttr] :
+                                       nodeLineNumber_ [currentNode];
+                       }
+               }
+
+               int IXmlLineInfo.LinePosition {
+                       get {
+                               return currentIsAttr ? attrLinePosition_ [currentAttr] :
+                                       nodeLinePosition_ [currentNode];
+                       }
+               }
+
                public override string LocalName {
                        get { return currentIsNode ? localName_ [currentNode] : currentIsAttr ? attrLocalName_ [currentAttr] : nsNodeName_ [currentNs]; }
                }
@@ -347,6 +371,11 @@ namespace Mono.Xml.XPath
                        return String.Empty;
                }
 
+               bool IXmlLineInfo.HasLineInfo ()
+               {
+                       return true;
+               }
+
                public override bool IsDescendant (XPathNavigator nav)
                {
                        DTMXPathNavigator another = nav as DTMXPathNavigator;