XPathSequence.cs 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  1. //
  2. // XPathSequence.cs - represents XPath sequence iterator
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. //
  8. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System;
  31. using System.Collections;
  32. using System.Xml;
  33. using System.Xml.Schema;
  34. using System.Xml.Query;
  35. using System.Xml.XPath;
  36. namespace Mono.Xml.XPath2
  37. {
  38. public abstract class XPathSequence : IEnumerable, ICloneable
  39. {
  40. XQueryContext ctx;
  41. int countCache = -1;
  42. int position = 0;
  43. internal XPathSequence (XQueryContext ctx)
  44. {
  45. this.ctx = ctx;
  46. }
  47. internal XPathSequence (XPathSequence original)
  48. {
  49. ctx = original.ctx;
  50. position = original.position;
  51. }
  52. internal XQueryContext Context {
  53. // get { return ctx; }
  54. get { return ctx.ContextManager.CurrentContext; }
  55. }
  56. public virtual int Count {
  57. get {
  58. if (countCache >= 0)
  59. return countCache;
  60. XPathSequence clone = Clone ();
  61. while (clone.MoveNext ())
  62. ;
  63. countCache = clone.Position;
  64. return countCache;
  65. }
  66. }
  67. public XPathItem Current {
  68. get {
  69. if (Position == 0)
  70. throw new InvalidOperationException ("XQuery internal error (should not happen)");
  71. return CurrentCore;
  72. }
  73. }
  74. public abstract XPathItem CurrentCore { get; }
  75. // Returns 0 if not started, otherwise returns XPath positional integer.
  76. public virtual int Position {
  77. get { return position; }
  78. }
  79. public virtual bool MoveNext ()
  80. {
  81. if (!MoveNextCore ())
  82. return false;
  83. position++;
  84. return true;
  85. }
  86. protected abstract bool MoveNextCore ();
  87. public abstract XPathSequence Clone ();
  88. object ICloneable.Clone ()
  89. {
  90. return this.Clone ();
  91. }
  92. public virtual IEnumerator GetEnumerator ()
  93. {
  94. while (MoveNext ())
  95. yield return CurrentCore;
  96. }
  97. }
  98. // empty iterator (still required since it contains XQueryContext)
  99. class XPathEmptySequence : XPathSequence
  100. {
  101. internal XPathEmptySequence (XQueryContext ctx)
  102. : base (ctx)
  103. {
  104. }
  105. public override int Count {
  106. get { return 0; }
  107. }
  108. protected override bool MoveNextCore ()
  109. {
  110. return false;
  111. }
  112. public override XPathItem CurrentCore {
  113. get { throw new InvalidOperationException ("Should not happen. In XPathEmptySequence.Current."); }
  114. }
  115. // Don't return clone. It's waste of resource.
  116. public override XPathSequence Clone ()
  117. {
  118. return this;
  119. }
  120. }
  121. // single item iterator
  122. internal class SingleItemIterator : XPathSequence
  123. {
  124. XPathItem item;
  125. XPathItem current;
  126. // for XQuery execution start point
  127. internal SingleItemIterator (XPathItem item, XQueryContext ctx)
  128. : base (ctx)
  129. {
  130. this.item = item;
  131. }
  132. private SingleItemIterator (SingleItemIterator other)
  133. : base (other)
  134. {
  135. this.item = other.item;
  136. this.current = other.current;
  137. }
  138. public override XPathSequence Clone ()
  139. {
  140. return new SingleItemIterator (this);
  141. }
  142. protected override bool MoveNextCore ()
  143. {
  144. if (current == null) {
  145. current = item;
  146. return true;
  147. }
  148. return false;
  149. }
  150. public override XPathItem CurrentCore {
  151. get {
  152. return current;
  153. }
  154. }
  155. }
  156. // RangeExpr iterator
  157. internal class IntegerRangeIterator : XPathSequence
  158. {
  159. static XmlSchemaSimpleType intType = XmlSchemaType.GetBuiltInSimpleType (new XmlQualifiedName ("int", XmlSchema.Namespace));
  160. int start;
  161. int end;
  162. int next;
  163. XPathItem current;
  164. public IntegerRangeIterator (XQueryContext ctx, int start, int end)
  165. : base (ctx)
  166. {
  167. this.start = start;
  168. this.end = end;
  169. }
  170. private IntegerRangeIterator (IntegerRangeIterator other)
  171. : base (other)
  172. {
  173. this.start = other.start;
  174. this.end = other.end;
  175. this.next = other.next;
  176. this.current = other.current;
  177. }
  178. public override XPathSequence Clone ()
  179. {
  180. return new IntegerRangeIterator (this);
  181. }
  182. protected override bool MoveNextCore ()
  183. {
  184. if (current == null)
  185. next = start;
  186. if (next > end)
  187. return false;
  188. current = new XPathAtomicValue (next++, intType);
  189. return true;
  190. }
  191. public override XPathItem CurrentCore {
  192. get {
  193. return current;
  194. }
  195. }
  196. }
  197. // Slash iterator
  198. // <copy original='System.Xml.XPath/Iterator.cs,
  199. // System.Xml.XPath/XPathComparer.cs'>
  200. internal class PathStepIterator : XPathSequence
  201. {
  202. XPathSequence left;
  203. XPathSequence right;
  204. PathStepExpr step;
  205. ArrayList nodeStore;
  206. SortedList storedIterators;
  207. bool finished;
  208. XPathSequence nextRight;
  209. public PathStepIterator (XPathSequence iter, PathStepExpr source)
  210. : base (iter.Context)
  211. {
  212. left = iter;
  213. step = source;
  214. }
  215. private PathStepIterator (PathStepIterator other)
  216. : base (other)
  217. {
  218. left = other.left.Clone ();
  219. step = other.step;
  220. if (other.right != null)
  221. right = other.right.Clone ();
  222. if (other.nodeStore != null)
  223. nodeStore = (ArrayList) other.nodeStore.Clone ();
  224. if (other.storedIterators != null)
  225. storedIterators = (SortedList) other.storedIterators.Clone ();
  226. if (other.nextRight != null)
  227. nextRight = other.nextRight.Clone ();
  228. }
  229. public override XPathSequence Clone ()
  230. {
  231. return new PathStepIterator (this);
  232. }
  233. protected override bool MoveNextCore ()
  234. {
  235. if (finished)
  236. return false;
  237. if (step.RequireSorting) {
  238. // Mainly '//' ('/descendant-or-self::node()/')
  239. if (nodeStore == null) {
  240. CollectResults ();
  241. if (nodeStore.Count == 0) {
  242. finished = true;
  243. return false;
  244. } else
  245. // Initially it must not go to
  246. // the while loop below
  247. // (.Position -1 is -1).
  248. return true;
  249. }
  250. if (nodeStore.Count == Position) {
  251. finished = true;
  252. return false;
  253. }
  254. while (nodeStore.Count > Position) {
  255. if (((XPathNavigator) nodeStore [Position]).ComparePosition (
  256. (XPathNavigator) nodeStore [Position - 1]) == XmlNodeOrder.Same)
  257. nodeStore.RemoveAt (Position);
  258. else
  259. break;
  260. }
  261. return true;
  262. } else { // Sorting not required
  263. if (right == null) { // First time
  264. if (!left.MoveNext ())
  265. return false;
  266. right = step.Next.Evaluate (left);
  267. storedIterators = new SortedList (XPathSequenceComparer.Instance);
  268. }
  269. while (true) {
  270. while (!right.MoveNext ()) {
  271. if (storedIterators.Count > 0) {
  272. int last = storedIterators.Count - 1;
  273. XPathSequence tmpIter = (XPathSequence) storedIterators.GetByIndex (last);
  274. storedIterators.RemoveAt (last);
  275. switch (((XPathNavigator) tmpIter.Current).ComparePosition ((XPathNavigator) right.Current)) {
  276. case XmlNodeOrder.Same:
  277. case XmlNodeOrder.Before:
  278. right = tmpIter;
  279. continue;
  280. default:
  281. right = tmpIter;
  282. break;
  283. }
  284. break;
  285. } else if (nextRight != null) {
  286. right = nextRight;
  287. nextRight = null;
  288. break;
  289. } else if (!left.MoveNext ()) {
  290. finished = true;
  291. return false;
  292. }
  293. else
  294. right = step.Next.Evaluate (left);
  295. }
  296. bool loop = true;
  297. while (loop) {
  298. loop = false;
  299. if (nextRight == null) {
  300. bool noMoreNext = false;
  301. while (nextRight == null || !nextRight.MoveNext ()) {
  302. if(left.MoveNext ())
  303. nextRight = step.Next.Evaluate (left);
  304. else {
  305. noMoreNext = true;
  306. break;
  307. }
  308. }
  309. if (noMoreNext)
  310. nextRight = null; // FIXME: More efficient code. Maybe making noMoreNext class scope would be better.
  311. }
  312. if (nextRight != null) {
  313. switch (((XPathNavigator) right.Current).ComparePosition ((XPathNavigator) nextRight.Current)) {
  314. case XmlNodeOrder.After:
  315. storedIterators.Add (storedIterators.Count, right);
  316. right = nextRight;
  317. nextRight = null;
  318. loop = true;
  319. break;
  320. case XmlNodeOrder.Same:
  321. if (!nextRight.MoveNext ())
  322. nextRight = null;
  323. else {
  324. int last = storedIterators.Count;
  325. if (last > 0) {
  326. storedIterators.Add (last, nextRight);
  327. nextRight = (XPathSequence) storedIterators.GetByIndex (last);
  328. storedIterators.RemoveAt (last);
  329. }
  330. }
  331. loop = true;
  332. break;
  333. }
  334. }
  335. }
  336. return true;
  337. }
  338. }
  339. }
  340. private void CollectResults ()
  341. {
  342. if (nodeStore != null)
  343. return;
  344. nodeStore = new ArrayList ();
  345. while (true) {
  346. while (right == null || !right.MoveNext ()) {
  347. if (!left.MoveNext ()) {
  348. nodeStore.Sort (XPathNavigatorComparer2.Instance);
  349. return;
  350. }
  351. right = step.Next.Evaluate (left);
  352. }
  353. XPathNavigator nav = (XPathNavigator) right.Current;
  354. nodeStore.Add (nav);
  355. }
  356. }
  357. public override XPathItem CurrentCore {
  358. get {
  359. if (Position <= 0) return null;
  360. if (step.RequireSorting) {
  361. return (XPathNavigator) nodeStore [Position - 1];
  362. } else {
  363. return right.Current;
  364. }
  365. }
  366. }
  367. public override int Count {
  368. get {
  369. if (nodeStore == null)
  370. return base.Count;
  371. else
  372. return nodeStore.Count;
  373. }
  374. }
  375. internal class XPathSequenceComparer : IComparer
  376. {
  377. public static XPathSequenceComparer Instance = new XPathSequenceComparer ();
  378. private XPathSequenceComparer ()
  379. {
  380. }
  381. public int Compare (object o1, object o2)
  382. {
  383. XPathSequence nav1 = o1 as XPathSequence;
  384. XPathSequence nav2 = o2 as XPathSequence;
  385. if (nav1 == null)
  386. return -1;
  387. if (nav2 == null)
  388. return 1;
  389. switch (((XPathNavigator) nav1.Current).ComparePosition ((XPathNavigator) nav2.Current)) {
  390. case XmlNodeOrder.Same:
  391. return 0;
  392. case XmlNodeOrder.After:
  393. return -1;
  394. default:
  395. return 1;
  396. }
  397. }
  398. }
  399. internal class XPathNavigatorComparer2 : IComparer
  400. {
  401. public static XPathNavigatorComparer2 Instance = new XPathNavigatorComparer2 ();
  402. private XPathNavigatorComparer2 ()
  403. {
  404. }
  405. public int Compare (object o1, object o2)
  406. {
  407. XPathNavigator nav1 = o1 as XPathNavigator;
  408. XPathNavigator nav2 = o2 as XPathNavigator;
  409. if (nav1 == null)
  410. return -1;
  411. if (nav2 == null)
  412. return 1;
  413. switch (nav1.ComparePosition (nav2)) {
  414. case XmlNodeOrder.Same:
  415. return 0;
  416. case XmlNodeOrder.After:
  417. return 1;
  418. default:
  419. return -1;
  420. }
  421. }
  422. }
  423. }
  424. // </copy>
  425. // Filter step iterator
  426. internal class FilteredIterator : XPathSequence
  427. {
  428. XPathSequence left;
  429. ExprSequence filter;
  430. public FilteredIterator (XPathSequence iter, FilterStepExpr source)
  431. : base (iter.Context)
  432. {
  433. left = source.Expr.Evaluate (iter);
  434. filter = source.Predicate;
  435. }
  436. private FilteredIterator (FilteredIterator other)
  437. : base (other)
  438. {
  439. left = other.left.Clone ();
  440. filter = other.filter;
  441. }
  442. public override XPathSequence Clone ()
  443. {
  444. return new FilteredIterator (this);
  445. }
  446. protected override bool MoveNextCore ()
  447. {
  448. // FIXME: as for numeric predicates, it is MUCH faster
  449. // when it skips apparent non-candidates, with possible
  450. // method implementation "XPathSequence.SkipTo (int)".
  451. // When it comes true, iteration won't be done first.
  452. while (left.MoveNext ()) {
  453. bool doesntPass = true;
  454. // Treat as OK if any of filter expr passed.
  455. // FIXME: handle numeric predicate.
  456. foreach (ExprSingle single in filter) {
  457. XPathAtomicValue av = single.EvaluateAsAtomic (left);
  458. if (av == null)
  459. continue;
  460. if (SequenceType.IsNumeric (av.XmlType.TypeCode)) {
  461. // numeric filter
  462. if (av.ValueAsInt32 == left.Position) {
  463. doesntPass = false;
  464. break;
  465. }
  466. }
  467. else if (single.EvaluateAsBoolean (left)) {
  468. doesntPass = false;
  469. break;
  470. }
  471. }
  472. if (doesntPass)
  473. continue;
  474. return true;
  475. }
  476. return false;
  477. }
  478. public override XPathItem CurrentCore {
  479. get { return left.Current; }
  480. }
  481. }
  482. // AxisIterator
  483. internal class AxisIterator : XPathSequence
  484. {
  485. NodeIterator iter;
  486. AxisStepExpr source;
  487. public AxisIterator (NodeIterator iter, AxisStepExpr source)
  488. : base (iter.Context)
  489. {
  490. this.iter = iter;
  491. this.source = source;
  492. }
  493. private AxisIterator (AxisIterator other)
  494. : base (other)
  495. {
  496. iter = (NodeIterator) other.iter.Clone ();
  497. source = other.source;
  498. }
  499. public override XPathSequence Clone ()
  500. {
  501. return new AxisIterator (this);
  502. }
  503. protected override bool MoveNextCore ()
  504. {
  505. while (iter.MoveNext ()) {
  506. if (source.Matches (iter.Current as XPathNavigator))
  507. return true;
  508. }
  509. return false;
  510. }
  511. public override XPathItem CurrentCore {
  512. get { return iter.Current; }
  513. }
  514. }
  515. internal abstract class NodeIterator : XPathSequence
  516. {
  517. XPathNavigator node;
  518. XPathNavigator current;
  519. bool emptyInput;
  520. public NodeIterator (XPathNavigator nav, XQueryContext ctx)
  521. : base (ctx)
  522. {
  523. this.node = nav.Clone ();
  524. }
  525. /*
  526. public NodeIterator (XPathSequence iter)
  527. : base (iter.Context)
  528. {
  529. if (iter.Position == 0) {
  530. if (!iter.MoveNext ()) {
  531. emptyInput = true;
  532. return;
  533. }
  534. }
  535. XPathItem item = iter.Current;
  536. node = item as XPathNavigator;
  537. if (node == null)
  538. throw new XmlQueryException (String.Format ("Current item is expected to be a node, but it is {0} ({1}).", item.XmlType.QualifiedName, item.XmlType.TypeCode));
  539. node = node.Clone ();
  540. }
  541. */
  542. internal NodeIterator (NodeIterator other, bool cloneFlag)
  543. : base (other)
  544. {
  545. if (other.emptyInput)
  546. emptyInput = true;
  547. else
  548. node = other.node.Clone ();
  549. }
  550. internal XPathNavigator Node {
  551. get { return node; }
  552. }
  553. public override bool MoveNext ()
  554. {
  555. if (emptyInput)
  556. return false;
  557. if (!base.MoveNext ())
  558. return false;
  559. current = null;
  560. return true;
  561. }
  562. public override XPathItem CurrentCore {
  563. get {
  564. if (current == null)
  565. current = node.Clone ();
  566. return current;
  567. }
  568. }
  569. public virtual bool ReverseAxis {
  570. get { return false; }
  571. }
  572. }
  573. // <copy original='System.Xml.XPath/Iterator.cs'>
  574. internal class SelfIterator : NodeIterator
  575. {
  576. public SelfIterator (XPathNavigator nav, XQueryContext ctx)
  577. : base (nav, ctx)
  578. {
  579. }
  580. private SelfIterator (SelfIterator other, bool cloneFlag)
  581. : base (other, true)
  582. {
  583. }
  584. public override XPathSequence Clone ()
  585. {
  586. return new SelfIterator (this, true);
  587. }
  588. protected override bool MoveNextCore ()
  589. {
  590. if (Position == 0)
  591. return true;
  592. return false;
  593. }
  594. }
  595. internal class ParentIterator : NodeIterator
  596. {
  597. public ParentIterator (XPathNavigator nav, XQueryContext ctx)
  598. : base (nav, ctx)
  599. {
  600. }
  601. private ParentIterator (ParentIterator other, bool cloneFlag)
  602. : base (other, true)
  603. {
  604. }
  605. public override XPathSequence Clone ()
  606. {
  607. return new ParentIterator (this, true);
  608. }
  609. protected override bool MoveNextCore ()
  610. {
  611. if (Position == 0 && Node.MoveToParent ())
  612. return true;
  613. return false;
  614. }
  615. public override bool ReverseAxis {
  616. get { return true; }
  617. }
  618. }
  619. internal class ChildIterator : NodeIterator
  620. {
  621. public ChildIterator (XPathNavigator nav, XQueryContext ctx)
  622. : base (nav, ctx)
  623. {
  624. }
  625. private ChildIterator (ChildIterator other, bool cloneFlag)
  626. : base (other, true)
  627. {
  628. }
  629. public override XPathSequence Clone ()
  630. {
  631. return new ChildIterator (this, true);
  632. }
  633. protected override bool MoveNextCore ()
  634. {
  635. if (Position == 0)
  636. return Node.MoveToFirstChild ();
  637. else
  638. return Node.MoveToNext ();
  639. }
  640. }
  641. internal class FollowingSiblingIterator : NodeIterator
  642. {
  643. public FollowingSiblingIterator (XPathNavigator nav, XQueryContext ctx)
  644. : base (nav, ctx)
  645. {
  646. }
  647. private FollowingSiblingIterator (FollowingSiblingIterator other, bool cloneFlag)
  648. : base (other, true)
  649. {
  650. }
  651. public override XPathSequence Clone ()
  652. {
  653. return new FollowingSiblingIterator (this, true);
  654. }
  655. protected override bool MoveNextCore ()
  656. {
  657. return Node.MoveToNext ();
  658. }
  659. }
  660. internal class PrecedingSiblingIterator : NodeIterator
  661. {
  662. bool finished;
  663. bool started;
  664. XPathNavigator startPosition;
  665. public PrecedingSiblingIterator (XPathNavigator nav, XQueryContext ctx)
  666. : base (nav, ctx)
  667. {
  668. startPosition = Node.Clone ();
  669. }
  670. private PrecedingSiblingIterator (PrecedingSiblingIterator other, bool cloneFlag)
  671. : base (other, true)
  672. {
  673. startPosition = other.startPosition;
  674. started = other.started;
  675. finished = other.finished;
  676. }
  677. public override XPathSequence Clone ()
  678. {
  679. return new PrecedingSiblingIterator (this, true);
  680. }
  681. protected override bool MoveNextCore ()
  682. {
  683. if (finished)
  684. return false;
  685. if (!started) {
  686. started = true;
  687. Node.MoveToFirst ();
  688. } else {
  689. Node.MoveToNext ();
  690. }
  691. if (Node.ComparePosition (startPosition) == XmlNodeOrder.Same) {
  692. finished = true;
  693. return false;
  694. }
  695. else
  696. return true;
  697. }
  698. public override bool ReverseAxis {
  699. get { return true; }
  700. }
  701. }
  702. internal class AncestorIterator : NodeIterator
  703. {
  704. bool finished;
  705. ArrayList nodes = new ArrayList ();
  706. public AncestorIterator (XPathNavigator nav, XQueryContext ctx)
  707. : base (nav, ctx)
  708. {
  709. }
  710. private AncestorIterator (AncestorIterator other, bool cloneFlag)
  711. : base (other, true)
  712. {
  713. finished = other.finished;
  714. nodes = other.nodes;
  715. }
  716. public override XPathSequence Clone ()
  717. {
  718. return new AncestorIterator (this, true);
  719. }
  720. protected override bool MoveNextCore ()
  721. {
  722. if (finished)
  723. return false;
  724. if (nodes != null) {
  725. nodes = new ArrayList ();
  726. while (Node.MoveToParent () && Node.NodeType != XPathNodeType.Root)
  727. nodes.Add (Node.Clone ());
  728. nodes.Reverse ();
  729. }
  730. if (nodes.Count >= Position)
  731. return false;
  732. Node.MoveTo (nodes [Position] as XPathNavigator);
  733. return true;
  734. }
  735. public override bool ReverseAxis {
  736. get { return true; }
  737. }
  738. public override int Count {
  739. get {
  740. if (Position == 0)
  741. return base.Count;
  742. return nodes.Count;
  743. }
  744. }
  745. }
  746. internal class AncestorOrSelfIterator : NodeIterator
  747. {
  748. bool finished;
  749. ArrayList nodes = new ArrayList ();
  750. public AncestorOrSelfIterator (XPathNavigator nav, XQueryContext ctx)
  751. : base (nav, ctx)
  752. {
  753. }
  754. private AncestorOrSelfIterator (AncestorOrSelfIterator other, bool cloneFlag)
  755. : base (other, true)
  756. {
  757. finished = other.finished;
  758. nodes = other.nodes;
  759. }
  760. public override XPathSequence Clone ()
  761. {
  762. return new AncestorOrSelfIterator (this, true);
  763. }
  764. protected override bool MoveNextCore ()
  765. {
  766. if (finished)
  767. return false;
  768. if (nodes != null) {
  769. nodes = new ArrayList ();
  770. do {
  771. nodes.Add (Node.Clone ());
  772. } while (Node.MoveToParent () && Node.NodeType != XPathNodeType.Root);
  773. nodes.Reverse ();
  774. }
  775. if (nodes.Count >= Position)
  776. return false;
  777. Node.MoveTo (nodes [Position] as XPathNavigator);
  778. return true;
  779. }
  780. public override bool ReverseAxis {
  781. get { return true; }
  782. }
  783. public override int Count {
  784. get {
  785. if (Position == 0)
  786. return base.Count;
  787. return nodes.Count;
  788. }
  789. }
  790. }
  791. internal class DescendantIterator : NodeIterator
  792. {
  793. private int depth;
  794. private bool finished;
  795. public DescendantIterator (XPathNavigator nav, XQueryContext ctx)
  796. : base (nav, ctx)
  797. {
  798. }
  799. private DescendantIterator (DescendantIterator other, bool cloneFlag)
  800. : base (other, true)
  801. {
  802. finished = other.finished;
  803. depth = other.depth;
  804. }
  805. public override XPathSequence Clone ()
  806. {
  807. return new DescendantIterator (this, true);
  808. }
  809. protected override bool MoveNextCore ()
  810. {
  811. if (finished)
  812. return false;
  813. if (Node.MoveToFirstChild ()) {
  814. depth ++;
  815. return true;
  816. }
  817. while (depth != 0) {
  818. if (Node.MoveToNext ())
  819. return true;
  820. if (!Node.MoveToParent ()) // should NEVER fail!
  821. throw new XmlQueryException ("There seems some bugs on the XPathNavigator implementation class.");
  822. depth --;
  823. }
  824. finished = true;
  825. return false;
  826. }
  827. }
  828. internal class DescendantOrSelfIterator : NodeIterator
  829. {
  830. protected int depth;
  831. private bool finished;
  832. public DescendantOrSelfIterator (XPathNavigator nav, XQueryContext ctx)
  833. : base (nav, ctx)
  834. {
  835. }
  836. protected DescendantOrSelfIterator (DescendantOrSelfIterator other, bool cloneFlag)
  837. : base (other, true)
  838. {
  839. depth = other.depth;
  840. finished = other.finished;
  841. }
  842. public override XPathSequence Clone ()
  843. {
  844. return new DescendantOrSelfIterator (this, true);
  845. }
  846. protected override bool MoveNextCore ()
  847. {
  848. if (finished)
  849. return false;
  850. if (Position == 0)
  851. return true; // Self
  852. if (Node.MoveToFirstChild ()) {
  853. depth ++;
  854. return true;
  855. }
  856. while (depth != 0) {
  857. if (Node.MoveToNext ())
  858. return true;
  859. if (!Node.MoveToParent ()) // should NEVER fail!
  860. throw new XmlQueryException ("There seems some bugs on the XPathNavigator implementation class.");
  861. depth --;
  862. }
  863. finished = true;
  864. return false;
  865. }
  866. }
  867. internal class FollowingIterator : NodeIterator
  868. {
  869. private bool finished;
  870. public FollowingIterator (XPathNavigator nav, XQueryContext ctx)
  871. : base (nav, ctx)
  872. {
  873. }
  874. protected FollowingIterator (FollowingIterator other, bool cloneFlag)
  875. : base (other, true)
  876. {
  877. finished = other.finished;
  878. }
  879. public override XPathSequence Clone ()
  880. {
  881. return new FollowingIterator (this, true);
  882. }
  883. protected override bool MoveNextCore ()
  884. {
  885. if (finished)
  886. return false;
  887. if (Position == 0) {
  888. // At first, it should not iterate children.
  889. if (Node.MoveToNext ())
  890. return true;
  891. else {
  892. while (Node.MoveToParent ())
  893. if (Node.MoveToNext ())
  894. return true;
  895. }
  896. } else {
  897. if (Node.MoveToFirstChild ())
  898. return true;
  899. do {
  900. if (Node.MoveToNext ())
  901. return true;
  902. } while (Node.MoveToParent ());
  903. }
  904. finished = true;
  905. return false;
  906. }
  907. }
  908. internal class PrecedingIterator : NodeIterator
  909. {
  910. bool finished;
  911. bool started;
  912. XPathNavigator startPosition;
  913. public PrecedingIterator (XPathNavigator nav, XQueryContext ctx)
  914. : base (nav, ctx)
  915. {
  916. startPosition = Node.Clone ();
  917. }
  918. private PrecedingIterator (PrecedingIterator other, bool cloneFlag)
  919. : base (other, true)
  920. {
  921. startPosition = other.startPosition;
  922. started = other.started;
  923. finished = other.finished;
  924. }
  925. public override XPathSequence Clone ()
  926. {
  927. return new PrecedingIterator (this, true);
  928. }
  929. protected override bool MoveNextCore ()
  930. {
  931. if (finished)
  932. return false;
  933. if (!started) {
  934. started = true;
  935. Node.MoveToRoot ();
  936. }
  937. bool loop = true;
  938. while (loop) {
  939. while (!Node.MoveToFirstChild ()) {
  940. while (!Node.MoveToNext ()) {
  941. if (!Node.MoveToParent ()) { // Should not finish, at least before startPosition.
  942. finished = true;
  943. return false;
  944. }
  945. }
  946. break;
  947. }
  948. if (Node.IsDescendant (startPosition))
  949. continue;
  950. loop = false;
  951. break;
  952. }
  953. if (Node.ComparePosition (startPosition) != XmlNodeOrder.Before) {
  954. // Note that if _nav contains only 1 node, it won't be Same.
  955. finished = true;
  956. return false;
  957. }
  958. else
  959. return true;
  960. }
  961. public override bool ReverseAxis {
  962. get { return true; }
  963. }
  964. }
  965. internal class NamespaceIterator : NodeIterator
  966. {
  967. public NamespaceIterator (XPathNavigator nav, XQueryContext ctx)
  968. : base (nav, ctx)
  969. {
  970. }
  971. private NamespaceIterator (NamespaceIterator other, bool cloneFlag)
  972. : base (other, true)
  973. {
  974. }
  975. public override XPathSequence Clone ()
  976. {
  977. return new NamespaceIterator (this, true);
  978. }
  979. protected override bool MoveNextCore ()
  980. {
  981. if (Position == 0) {
  982. if (Node.MoveToFirstNamespace ())
  983. return true;
  984. }
  985. else if (Node.MoveToNextNamespace ())
  986. return true;
  987. return false;
  988. }
  989. public override bool ReverseAxis { get { return true; } }
  990. }
  991. internal class AttributeIterator : NodeIterator
  992. {
  993. public AttributeIterator (XPathNavigator nav, XQueryContext ctx)
  994. : base (nav, ctx)
  995. {
  996. }
  997. private AttributeIterator (AttributeIterator other, bool cloneFlag)
  998. : base (other, true)
  999. {
  1000. }
  1001. public override XPathSequence Clone ()
  1002. {
  1003. return new AttributeIterator (this, true);
  1004. }
  1005. protected override bool MoveNextCore ()
  1006. {
  1007. if (Position == 0) {
  1008. if (Node.MoveToFirstAttribute ())
  1009. return true;
  1010. }
  1011. else if (Node.MoveToNextAttribute ())
  1012. return true;
  1013. return false;
  1014. }
  1015. }
  1016. // </copy>
  1017. internal class ExprSequenceIterator : XPathSequence
  1018. {
  1019. XPathSequence contextSequence;
  1020. XPathSequence iter;
  1021. ExprSequence expr;
  1022. int currentExprIndex;
  1023. public ExprSequenceIterator (XPathSequence iter, ExprSequence expr)
  1024. : base (iter.Context)
  1025. {
  1026. contextSequence = iter;
  1027. this.expr = expr;
  1028. }
  1029. private ExprSequenceIterator (ExprSequenceIterator other)
  1030. : base (other)
  1031. {
  1032. if (other.iter != null)
  1033. iter = other.iter.Clone ();
  1034. expr = other.expr;
  1035. contextSequence = other.contextSequence;
  1036. currentExprIndex = other.currentExprIndex;
  1037. }
  1038. public override XPathSequence Clone ()
  1039. {
  1040. return new ExprSequenceIterator (this);
  1041. }
  1042. protected override bool MoveNextCore ()
  1043. {
  1044. if (iter != null && iter.MoveNext ())
  1045. return true;
  1046. while (currentExprIndex < expr.Count) {
  1047. iter = expr [currentExprIndex++].Evaluate (contextSequence);
  1048. if (iter.MoveNext ())
  1049. return true;
  1050. }
  1051. return false;
  1052. }
  1053. public override XPathItem CurrentCore {
  1054. get { return iter.Current; }
  1055. }
  1056. }
  1057. // FLWOR - Order By
  1058. internal class FLWORIterator : XPathSequence
  1059. {
  1060. XPathSequence contextSequence;
  1061. FLWORExpr expr;
  1062. ArrayList forStack = new ArrayList ();
  1063. IEnumerator en;
  1064. bool finished;
  1065. public FLWORIterator (XPathSequence iter, FLWORExpr expr)
  1066. : base (iter.Context)
  1067. {
  1068. this.contextSequence = iter;
  1069. this.expr = expr;
  1070. }
  1071. private FLWORIterator (FLWORIterator other)
  1072. : base (other)
  1073. {
  1074. contextSequence = other.contextSequence;
  1075. expr = other.expr;
  1076. forStack = other.forStack.Clone () as ArrayList;
  1077. if (en != null)
  1078. en = ((ICloneable) other.en).Clone () as IEnumerator;
  1079. finished = other.finished;
  1080. }
  1081. public override XPathSequence Clone ()
  1082. {
  1083. return new FLWORIterator (this);
  1084. }
  1085. protected override bool MoveNextCore ()
  1086. {
  1087. if (en == null)
  1088. en = GetEnumerator ();
  1089. return en.MoveNext ();
  1090. }
  1091. public override IEnumerator GetEnumerator ()
  1092. {
  1093. return EvaluateRemainingForLet (0);
  1094. }
  1095. private IEnumerator EvaluateRemainingForLet (int flcPosition)
  1096. {
  1097. // Prepare iteration stack
  1098. if (flcPosition < expr.ForLetClauses.Count) {
  1099. IEnumerator items = EvaluateRemainingSingleItem (flcPosition, 0);
  1100. while (items.MoveNext ())
  1101. yield return items.Current;
  1102. } else {
  1103. bool passedFilter = expr.WhereClause == null;
  1104. if (!passedFilter)
  1105. passedFilter = expr.WhereClause.EvaluateAsBoolean (contextSequence);
  1106. if (passedFilter) {
  1107. IEnumerator ie = expr.ReturnExpr.Evaluate (contextSequence).GetEnumerator ();
  1108. while (ie.MoveNext ())
  1109. yield return (XPathItem) ie.Current;
  1110. }
  1111. }
  1112. }
  1113. private IEnumerator EvaluateRemainingSingleItem (int flcPosition, int singlePosition)
  1114. {
  1115. if (singlePosition < expr.ForLetClauses [flcPosition].Count) {
  1116. ForLetSingleBody sb = expr.ForLetClauses [flcPosition] [singlePosition];
  1117. ForSingleBody fsb = sb as ForSingleBody;
  1118. if (fsb != null) {
  1119. XPathSequence backup = contextSequence;
  1120. contextSequence = fsb.Expression.Evaluate (Context.CurrentSequence);
  1121. Context.ContextManager.PushCurrentSequence (contextSequence);
  1122. while (contextSequence.MoveNext ()) {
  1123. XPathItem forItem = (XPathItem) contextSequence.Current;
  1124. Context.PushVariable (fsb.PositionalVar, contextSequence.Position);
  1125. Context.PushVariable (sb.VarName, forItem);
  1126. // recurse here (including following bindings)
  1127. IEnumerator items = EvaluateRemainingSingleItem (flcPosition, singlePosition + 1);
  1128. while (items.MoveNext ())
  1129. yield return (XPathItem) items.Current;
  1130. Context.PopVariable ();
  1131. Context.PopVariable ();
  1132. }
  1133. Context.ContextManager.PopCurrentSequence ();
  1134. contextSequence = backup;
  1135. } else {
  1136. Context.PushVariable (sb.VarName, sb.Expression.Evaluate (contextSequence));
  1137. // recurse here (including following bindings)
  1138. IEnumerator items = EvaluateRemainingSingleItem (flcPosition, singlePosition + 1);
  1139. while (items.MoveNext ())
  1140. yield return (XPathItem) items.Current;
  1141. Context.PopVariable ();
  1142. }
  1143. } else {
  1144. // evaluate next binding
  1145. IEnumerator items = EvaluateRemainingForLet (flcPosition + 1);
  1146. while (items.MoveNext ())
  1147. yield return (XPathItem) items.Current;
  1148. }
  1149. }
  1150. public override XPathItem CurrentCore {
  1151. get { return (XPathItem) en.Current; }
  1152. }
  1153. }
  1154. internal class GroupIterator : XPathSequence
  1155. {
  1156. GroupExpr expr;
  1157. XPathSequence lseq;
  1158. XPathSequence rseq;
  1159. bool started;
  1160. bool left;
  1161. bool leftFinished;
  1162. bool rightFinished;
  1163. public GroupIterator (XPathSequence iter, GroupExpr expr)
  1164. : base (iter.Context)
  1165. {
  1166. this.expr = expr;
  1167. left = true;
  1168. lseq = expr.Left.EvaluateOrdered (iter);
  1169. rseq = expr.Right.EvaluateOrdered (iter);
  1170. }
  1171. private GroupIterator (GroupIterator other)
  1172. : base (other)
  1173. {
  1174. this.expr = other.expr;
  1175. this.started = other.started;
  1176. this.left = other.left;
  1177. this.leftFinished = other.leftFinished;
  1178. this.rightFinished = other.rightFinished;
  1179. this.lseq = other.lseq.Clone ();
  1180. this.rseq = other.rseq.Clone ();
  1181. }
  1182. public override XPathSequence Clone ()
  1183. {
  1184. return new GroupIterator (this);
  1185. }
  1186. protected override bool MoveNextCore ()
  1187. {
  1188. if (leftFinished && rightFinished)
  1189. return false;
  1190. bool proceeded = false;
  1191. if (started) {
  1192. if (left) {
  1193. if (!leftFinished && lseq.MoveNext ())
  1194. proceeded = true;
  1195. else
  1196. leftFinished = true;
  1197. } else {
  1198. if (rightFinished && rseq.MoveNext ())
  1199. proceeded = true;
  1200. else
  1201. rightFinished = true;
  1202. }
  1203. } else {
  1204. started = true;
  1205. if (!lseq.MoveNext ()) {
  1206. leftFinished = true;
  1207. if (!rseq.MoveNext ()) {
  1208. rightFinished = true;
  1209. return false;
  1210. }
  1211. left = false;
  1212. return true;
  1213. }
  1214. proceeded = true;
  1215. if (!rseq.MoveNext ()) {
  1216. rightFinished = true;
  1217. return true;
  1218. }
  1219. }
  1220. if (!proceeded) {
  1221. if (expr.AggregationType == AggregationType.Intersect)
  1222. return false;
  1223. left = !leftFinished;
  1224. return !leftFinished || !rightFinished;
  1225. }
  1226. XPathNavigator lnav = lseq.Current as XPathNavigator;
  1227. XPathNavigator rnav = rseq.Current as XPathNavigator;
  1228. if (lnav == null || rnav == null)
  1229. throw new XmlQueryException ("XP0006: Evaluation against union, intersect, except expressions must result in nodes.");
  1230. XmlNodeOrder order = lnav.ComparePosition (rnav);
  1231. switch (order) {
  1232. case XmlNodeOrder.Same:
  1233. switch (expr.AggregationType) {
  1234. case AggregationType.Union:
  1235. left = false;
  1236. if (!lseq.MoveNext ())
  1237. leftFinished = true;
  1238. return true;
  1239. case AggregationType.Intersect:
  1240. return true;
  1241. case AggregationType.Except:
  1242. default:
  1243. return MoveNext ();
  1244. }
  1245. case XmlNodeOrder.Before:
  1246. left = true;
  1247. if (expr.AggregationType == AggregationType.Intersect)
  1248. return MoveNext ();
  1249. return true;
  1250. default: // After, Unknown
  1251. left = false;
  1252. if (expr.AggregationType == AggregationType.Intersect)
  1253. return MoveNext ();
  1254. return true;
  1255. }
  1256. }
  1257. public override XPathItem CurrentCore {
  1258. get { return left ? lseq.Current : rseq.Current; }
  1259. }
  1260. }
  1261. internal class AtomizingIterator : XPathSequence
  1262. {
  1263. XPathSequence iter;
  1264. public AtomizingIterator (XPathSequence iter)
  1265. : base (iter.Context)
  1266. {
  1267. this.iter = iter;
  1268. }
  1269. private AtomizingIterator (AtomizingIterator other)
  1270. : base (other)
  1271. {
  1272. iter = other.iter.Clone ();
  1273. }
  1274. public override XPathSequence Clone ()
  1275. {
  1276. return new AtomizingIterator (this);
  1277. }
  1278. protected override bool MoveNextCore ()
  1279. {
  1280. return iter.MoveNext ();
  1281. }
  1282. public override XPathItem CurrentCore {
  1283. get {
  1284. XPathNavigator nav = iter.Current as XPathNavigator;
  1285. if (nav == null)
  1286. return (XPathAtomicValue) iter.Current;
  1287. if (nav.SchemaInfo != null)
  1288. return new XPathAtomicValue (
  1289. nav.TypedValue,
  1290. nav.SchemaInfo.SchemaType);
  1291. else
  1292. return new XPathAtomicValue (nav.Value, null);
  1293. }
  1294. }
  1295. }
  1296. internal class ConvertingIterator : XPathSequence
  1297. {
  1298. XPathSequence iter;
  1299. SequenceType type;
  1300. public ConvertingIterator (XPathSequence iter, SequenceType type)
  1301. : base (iter.Context)
  1302. {
  1303. this.iter = iter;
  1304. this.type = type;
  1305. }
  1306. private ConvertingIterator (ConvertingIterator other)
  1307. : base (other)
  1308. {
  1309. iter = other.iter.Clone ();
  1310. type = other.type;
  1311. }
  1312. public override XPathSequence Clone ()
  1313. {
  1314. return new ConvertingIterator (this);
  1315. }
  1316. protected override bool MoveNextCore ()
  1317. {
  1318. return iter.MoveNext ();
  1319. }
  1320. public override XPathItem CurrentCore {
  1321. get { return type.Convert (iter.Current); }
  1322. }
  1323. }
  1324. internal class TracingIterator : XPathSequence
  1325. {
  1326. XPathSequence iter;
  1327. string format;
  1328. public TracingIterator (XPathSequence iter, string format)
  1329. : base (iter.Context)
  1330. {
  1331. this.iter = iter;
  1332. this.format = format;
  1333. }
  1334. private TracingIterator (TracingIterator other)
  1335. : base (other)
  1336. {
  1337. iter = other.iter.Clone ();
  1338. format = other.format;
  1339. }
  1340. public override XPathSequence Clone ()
  1341. {
  1342. return new TracingIterator (this);
  1343. }
  1344. protected override bool MoveNextCore ()
  1345. {
  1346. if (!iter.MoveNext ())
  1347. return false;
  1348. // FIXME: use OnMessageEvent
  1349. string output = String.Format (format, iter.Current.TypedValue);
  1350. Context.StaticContext.OnMessageEvent (iter.Current, new TraceEventArgs (output));
  1351. return true;
  1352. }
  1353. public override XPathItem CurrentCore {
  1354. get { return iter.Current; }
  1355. }
  1356. internal class TraceEventArgs : QueryEventArgs
  1357. {
  1358. string message;
  1359. internal TraceEventArgs (string message)
  1360. {
  1361. this.message = message;
  1362. }
  1363. public override string Message {
  1364. get { return message; }
  1365. }
  1366. }
  1367. }
  1368. internal class ListIterator : XPathSequence
  1369. {
  1370. IList list;
  1371. public ListIterator (XPathSequence iter, IList list)
  1372. : base (iter.Context)
  1373. {
  1374. if (list is ICloneable)
  1375. this.list = list;
  1376. else
  1377. throw new InvalidOperationException (String.Format ("XQuery internal error: target list is not cloneable. List is {0}.", list != null ? list.GetType ().ToString () : "null argument"));
  1378. }
  1379. private ListIterator (ListIterator other)
  1380. : base (other)
  1381. {
  1382. this.list = (IList) ((ICloneable) other.list).Clone ();
  1383. }
  1384. public override XPathSequence Clone ()
  1385. {
  1386. return new ListIterator (this);
  1387. }
  1388. protected override bool MoveNextCore ()
  1389. {
  1390. return (Position < list.Count);
  1391. }
  1392. public override XPathItem CurrentCore {
  1393. get { return (XPathItem) list [Position - 1]; }
  1394. }
  1395. }
  1396. internal class EnumeratorIterator : XPathSequence
  1397. {
  1398. IEnumerator list;
  1399. public EnumeratorIterator (XQueryContext ctx, IEnumerable en)
  1400. : base (ctx)
  1401. {
  1402. list = en.GetEnumerator ();
  1403. if (list is ICloneable)
  1404. this.list = list;
  1405. else
  1406. throw new InvalidOperationException (String.Format ("XQuery internal error: target list's enumerator is not cloneable. List is {0}.", en != null ? en.GetType ().ToString () : "null argument"));
  1407. }
  1408. private EnumeratorIterator (EnumeratorIterator other)
  1409. : base (other)
  1410. {
  1411. this.list = (IEnumerator) ((ICloneable) other.list).Clone ();
  1412. }
  1413. public override XPathSequence Clone ()
  1414. {
  1415. return new EnumeratorIterator (this);
  1416. }
  1417. protected override bool MoveNextCore ()
  1418. {
  1419. return list.MoveNext ();
  1420. }
  1421. public override XPathItem CurrentCore {
  1422. get { return (XPathItem) list.Current; }
  1423. }
  1424. }
  1425. }
  1426. #endif