remove svn:executable from .cs files
[mono.git] / mcs / class / System.XML / Mono.Xml.Xsl / XslFunctions.cs
1 //
2 // XsltCompiledContext.cs
3 //
4 // Authors:
5 //      Ben Maurer (bmaurer@users.sourceforge.net)
6 //      Atsushi Enomoto (atsushi@ximian.com)
7 // (C) 2003 Ben Maurer
8 // (C) 2004 Atsushi Enomoto
9 //
10
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31 using System;
32 using System.Collections;
33 using System.Globalization;
34 using System.Reflection;
35 using System.Text;
36 using System.Xml;
37 using System.Xml.XPath;
38 using System.Xml.Xsl;
39 using Mono.Xml.Xsl;
40
41 using QName = System.Xml.XmlQualifiedName;
42
43 namespace Mono.Xml.Xsl
44 {
45         internal abstract class XPFuncImpl : IXsltContextFunction 
46         {
47                 int minargs, maxargs;
48                 XPathResultType returnType;
49                 XPathResultType [] argTypes;
50
51                 public XPFuncImpl () {}
52                 public XPFuncImpl (int minArgs, int maxArgs, XPathResultType returnType, XPathResultType[] argTypes)
53                 {
54                         this.Init(minArgs, maxArgs, returnType, argTypes);
55                 }
56                 
57                 protected void Init (int minArgs, int maxArgs, XPathResultType returnType, XPathResultType[] argTypes)
58                 {
59                         this.minargs    = minArgs;
60                         this.maxargs    = maxArgs;
61                         this.returnType = returnType;
62                         this.argTypes   = argTypes;
63                 }
64
65                 public int Minargs { get { return this.minargs; }}
66                 public int Maxargs { get { return this.maxargs; }}
67                 public XPathResultType ReturnType { get { return this.returnType; }}
68                 public XPathResultType [] ArgTypes { get { return this.argTypes; }}
69                 public object Invoke (XsltContext xsltContext, object [] args, XPathNavigator docContext)
70                 {
71                         return Invoke ((XsltCompiledContext)xsltContext, args, docContext);
72                 }
73                 
74                 public abstract object Invoke (XsltCompiledContext xsltContext, object [] args, XPathNavigator docContext);
75                 
76                 public static XPathResultType GetXPathType (Type type, XPathNavigator node) {
77                         switch (Type.GetTypeCode(type)) {
78                         case TypeCode.String:
79                                 return XPathResultType.String;
80                         case TypeCode.Boolean:
81                                 return XPathResultType.Boolean;
82                         case TypeCode.Object:
83                                 if (typeof (XPathNavigator).IsAssignableFrom (type) || typeof (IXPathNavigable).IsAssignableFrom (type))
84                                         return XPathResultType.Navigator;
85                                 
86                                 if (typeof (XPathNodeIterator).IsAssignableFrom (type))
87                                         return XPathResultType.NodeSet;
88                                 
89                                 return XPathResultType.Any;
90                         case TypeCode.DateTime :
91                                 throw new XsltException ("Invalid type DateTime was specified.", null, node);
92                         default: // Numeric
93                                 return XPathResultType.Number;
94                         } 
95                 }
96         }
97         
98         class XsltExtensionFunction : XPFuncImpl 
99         {
100                 private object extension;
101                 private MethodInfo method;
102                 private TypeCode [] typeCodes;
103
104                 public XsltExtensionFunction (object extension, MethodInfo method, XPathNavigator currentNode)
105                 {
106                         this.extension = extension;
107                         this.method = method;
108
109                         ParameterInfo [] parameters = method.GetParameters ();
110                         int minArgs = parameters.Length;
111                         int maxArgs = parameters.Length;
112                         
113                         this.typeCodes = new TypeCode [parameters.Length];
114                         XPathResultType[] argTypes = new XPathResultType [parameters.Length];
115                         
116                         bool canBeOpt = true;
117                         for (int i = parameters.Length - 1; 0 <= i; i--) { // optionals at the end
118                                 typeCodes [i] = Type.GetTypeCode (parameters [i].ParameterType);
119                                 argTypes [i] = GetXPathType (parameters [i].ParameterType, currentNode);
120                                 if (canBeOpt) {
121                                         if (parameters[i].IsOptional)
122                                                 minArgs --;
123                                         else
124                                                 canBeOpt = false;
125                                 }
126                         }
127                         base.Init (minArgs, maxArgs, GetXPathType (method.ReturnType, currentNode), argTypes);
128                 }
129
130                 public override object Invoke (XsltCompiledContext xsltContext, object [] args, XPathNavigator docContext)
131                 {
132                         try {
133                                 ParameterInfo [] pis = method.GetParameters ();
134                                 object [] castedArgs = new object [pis.Length];
135                                 for (int i = 0; i < args.Length; i++) {
136                                         Type t = pis [i].ParameterType;
137                                         switch (t.FullName) {
138                                         case "System.Int16":
139                                         case "System.UInt16":
140                                         case "System.Int32":
141                                         case "System.UInt32":
142                                         case "System.Int64":
143                                         case "System.UInt64":
144                                         case "System.Single":
145                                         case "System.Decimal":
146                                                 castedArgs [i] = Convert.ChangeType (args [i], t);
147                                                 break;
148                                         default:
149                                                 castedArgs [i] = args [i];
150                                                 break;
151                                         }
152                                 }
153
154                                 object result = null;
155                                 switch (method.ReturnType.FullName) {
156                                 case "System.Int16":
157                                 case "System.UInt16":
158                                 case "System.Int32":
159                                 case "System.UInt32":
160                                 case "System.Int64":
161                                 case "System.UInt64":
162                                 case "System.Single":
163                                 case "System.Decimal":
164                                         result = (double) method.Invoke (extension, castedArgs);
165                                         break;
166                                 default:
167                                         result = method.Invoke(extension, castedArgs);
168                                         break;
169                                 }
170                                 IXPathNavigable navigable = result as IXPathNavigable;
171                                 if (navigable != null)
172                                         return navigable.CreateNavigator ();
173
174                                 return result;
175                         } catch (Exception ex) {
176                                 throw new XsltException ("Custom function reported an error.", ex);
177 //                              Debug.WriteLine ("****** INCORRECT RESOLUTION **********");
178                         }
179                 }
180         }
181         
182         class XsltCurrent : XPathFunction 
183         {
184                 public XsltCurrent (FunctionArguments args) : base (args)
185                 {
186                         if (args != null)
187                                 throw new XPathException ("current takes 0 args");
188                 }
189                 
190                 public override XPathResultType ReturnType { get { return XPathResultType.NodeSet; }}
191
192                 public override object Evaluate (BaseIterator iter)
193                 {
194                         return new SelfIterator ((iter.NamespaceManager as XsltCompiledContext).Processor.CurrentNode, null);
195                 }
196
197                 internal override bool Peer {
198                         get { return false; }
199                 }
200
201                 public override string ToString ()
202                 {
203                         return "current()";
204                 }
205         }
206         
207         class XsltDocument : XPathFunction 
208         {
209                 Expression arg0, arg1;
210                 XPathNavigator doc;
211                 
212                 public XsltDocument (FunctionArguments args, Compiler c) : base (args)
213                 {
214                         if (args == null || (args.Tail != null && args.Tail.Tail != null))
215                                 throw new XPathException ("document takes one or two args");
216                         
217                         arg0 = args.Arg;
218                         if (args.Tail != null)
219                                 arg1 = args.Tail.Arg;
220                         doc = c.Input.Clone ();
221                 }
222                 public override XPathResultType ReturnType { get { return XPathResultType.NodeSet; }}
223
224                 internal override bool Peer {
225                         get { return arg0.Peer && (arg1 != null ? arg1.Peer : true); }
226                 }
227
228                 public override object Evaluate (BaseIterator iter)
229                 {
230                         string baseUri = null;
231                         if (arg1 != null) {
232                                 XPathNodeIterator it = arg1.EvaluateNodeSet (iter);
233                                 if (it.MoveNext())
234                                         baseUri = it.Current.BaseURI;
235                                 else
236                                         baseUri = VoidBaseUriFlag;
237                         }
238
239                         object o = arg0.Evaluate (iter);
240                         if (o is XPathNodeIterator)
241                                 return GetDocument ((iter.NamespaceManager as XsltCompiledContext), (XPathNodeIterator)o, baseUri);
242                         else
243                                 return GetDocument ((iter.NamespaceManager as XsltCompiledContext), o is IFormattable ? ((IFormattable) o).ToString (null, CultureInfo.InvariantCulture) : o.ToString (), baseUri);
244                 }
245                 
246                 static string VoidBaseUriFlag = "&^)(*&%*^$&$VOID!BASE!URI!";
247                 
248                 Uri Resolve (string thisUri, string baseUri, XslTransformProcessor p)
249                 {
250 //                      Debug.WriteLine ("THIS: " + thisUri);
251 //                      Debug.WriteLine ("BASE: " + baseUri);
252                         XmlResolver r = p.Resolver;
253                         if (r == null)
254                                 return null;
255                         Uri uriBase = null;
256                         if (! object.ReferenceEquals (baseUri, VoidBaseUriFlag) && baseUri != String.Empty)
257                                 uriBase = r.ResolveUri (null, baseUri);
258                                 
259                         return r.ResolveUri (uriBase, thisUri);
260                 }
261                 
262                 XPathNodeIterator GetDocument (XsltCompiledContext xsltContext, XPathNodeIterator itr, string baseUri)
263                 {
264                         ArrayList list = new ArrayList ();
265                         Hashtable got = new Hashtable ();
266                         
267                         while (itr.MoveNext()) {
268                                 Uri uri = Resolve (itr.Current.Value, baseUri != null ? baseUri : /*itr.Current.BaseURI*/doc.BaseURI, xsltContext.Processor);
269                                 if (!got.ContainsKey (uri)) {
270                                         got.Add (uri, null);
271                                         if (uri != null && uri.ToString () == "") {
272                                                 XPathNavigator n = doc.Clone ();
273                                                 n.MoveToRoot ();
274                                                 list.Add (n);
275                                         } else
276                                                 list.Add (xsltContext.Processor.GetDocument (uri));
277                                 }
278                         }
279                         
280                         return new ListIterator (list, xsltContext);
281                 }
282         
283                 XPathNodeIterator GetDocument (XsltCompiledContext xsltContext, string arg0, string baseUri)
284                 {
285                         Uri uri = Resolve (arg0, baseUri != null ? baseUri : doc.BaseURI, xsltContext.Processor);
286                         XPathNavigator n;
287                         if (uri != null && uri.ToString () == "") {
288                                 n = doc.Clone ();
289                                 n.MoveToRoot ();
290                         } else
291                                 n = xsltContext.Processor.GetDocument (uri);
292                         
293                         return new SelfIterator (n, xsltContext);
294                 }
295
296                 public override string ToString ()
297                 {
298                         return String.Concat ("document(",
299                                 arg0.ToString (),
300                                 arg1 != null ? "," : String.Empty,
301                                 arg1 != null ? arg1.ToString () : String.Empty,
302                                 ")");
303                 }
304         }
305         
306         class XsltElementAvailable : XPathFunction 
307         {
308                 Expression arg0;
309                 IStaticXsltContext ctx;
310                 
311                 public XsltElementAvailable (FunctionArguments args, IStaticXsltContext ctx) : base (args)
312                 {
313                         if (args == null || args.Tail != null)
314                                 throw new XPathException ("element-available takes 1 arg");
315                         
316                         arg0 = args.Arg;
317                         this.ctx = ctx;
318                 }
319                 
320                 public override XPathResultType ReturnType { get { return XPathResultType.Boolean; }}
321
322                 internal override bool Peer {
323                         get { return arg0.Peer; }
324                 }
325
326                 public override object Evaluate (BaseIterator iter)
327                 {
328                         QName name = XslNameUtil.FromString (arg0.EvaluateString (iter), ctx);
329
330                         return (
331                                 (name.Namespace == Compiler.XsltNamespace) &&
332                                 (
333                                         //
334                                         // A list of all the instructions (does not include top-level-elements)
335                                         //
336                                         name.Name == "apply-imports" ||
337                                         name.Name == "apply-templates" ||
338                                         name.Name == "call-template" ||
339                                         name.Name == "choose" ||
340                                         name.Name == "comment" ||
341                                         name.Name == "copy" ||
342                                         name.Name == "copy-of" ||
343                                         name.Name == "element" ||
344                                         name.Name == "fallback" ||
345                                         name.Name == "for-each" ||
346                                         name.Name == "message" ||
347                                         name.Name == "number" ||
348                                         name.Name == "processing-instruction" ||
349                                         name.Name == "text" ||
350                                         name.Name == "value-of" ||
351                                         name.Name == "variable"
352                                 )
353                         );
354                 }
355         }
356
357         class XsltFormatNumber : XPathFunction 
358         {
359                 Expression arg0, arg1, arg2;
360                 IStaticXsltContext ctx;
361                 
362                 public XsltFormatNumber (FunctionArguments args, IStaticXsltContext ctx) : base (args)
363                 {
364                         if (args == null || args.Tail == null || (args.Tail.Tail != null && args.Tail.Tail.Tail != null))
365                                 throw new XPathException ("format-number takes 2 or 3 args");
366                         
367                         arg0 = args.Arg;
368                         arg1 = args.Tail.Arg;
369                         if (args.Tail.Tail != null) {
370                                 arg2= args.Tail.Tail.Arg;
371                                 this.ctx = ctx;
372                         }
373                 }
374                 public override XPathResultType ReturnType { get { return XPathResultType.String; }}
375
376                 internal override bool Peer {
377                         get { return arg0.Peer && arg1.Peer && (arg2 != null ? arg2.Peer : true); }
378                 }
379                 
380                 public override object Evaluate (BaseIterator iter)
381                 {
382                         double d = arg0.EvaluateNumber (iter);
383                         string s = arg1.EvaluateString (iter);
384                         QName nm = QName.Empty;
385                         
386                         if (arg2 != null)
387                                 nm = XslNameUtil.FromString (arg2.EvaluateString (iter), ctx);
388                         
389                         try {
390                                 return (iter.NamespaceManager as XsltCompiledContext).Processor.CompiledStyle
391                                 .LookupDecimalFormat (nm).FormatNumber (d, s);
392                         } catch (ArgumentException ex) {
393                                 throw new XsltException (ex.Message, ex, iter.Current);
394                         }
395                 }
396         }
397         
398         class XsltFunctionAvailable : XPathFunction 
399         {
400                 Expression arg0;
401                 IStaticXsltContext ctx;
402                 
403                 public XsltFunctionAvailable (FunctionArguments args, IStaticXsltContext ctx) : base (args)
404                 {
405                         if (args == null || args.Tail != null)
406                                 throw new XPathException ("element-available takes 1 arg");
407                         
408                         arg0 = args.Arg;
409                         this.ctx = ctx;
410                 }
411                 
412                 public override XPathResultType ReturnType { get { return XPathResultType.Boolean; }}
413
414                 internal override bool Peer {
415                         get { return arg0.Peer; }
416                 }
417                 
418                 public override object Evaluate (BaseIterator iter)
419                 {
420                         
421                         string name = arg0.EvaluateString (iter);
422                         int colon = name.IndexOf (':');
423                         // extension function
424                         if (colon > 0)
425                                 return (iter.NamespaceManager as XsltCompiledContext).ResolveFunction (
426                                         XslNameUtil.FromString (name, ctx),
427                                         null) != null;
428                         
429                         return (
430                                 //
431                                 // XPath
432                                 //
433                                 name == "boolean" ||
434                                 name == "ceiling" ||
435                                 name == "concat" ||
436                                 name == "contains" ||
437                                 name == "count" ||
438                                 name == "false" ||
439                                 name == "floor" ||
440                                 name == "id"||
441                                 name == "lang" ||
442                                 name == "last" ||
443                                 name == "local-name" ||
444                                 name == "name" ||
445                                 name == "namespace-uri" ||
446                                 name == "normalize-space" ||
447                                 name == "not" ||
448                                 name == "number" ||
449                                 name == "position" ||
450                                 name == "round" ||
451                                 name == "starts-with" ||
452                                 name == "string" ||
453                                 name == "string-length" ||
454                                 name == "substring" ||
455                                 name == "substring-after" ||
456                                 name == "substring-before" ||
457                                 name == "sum" ||
458                                 name == "translate" ||
459                                 name == "true" ||
460                                 // XSLT
461                                 name == "document" ||
462                                 name == "format-number" ||
463                                 name == "function-available" ||
464                                 name == "generate-id" ||
465                                 name == "key" ||
466                                 name == "current" ||
467                                 name == "unparsed-entity-uri" ||
468                                 name == "element-available" ||
469                                 name == "system-property"
470                         );
471                 }
472         } 
473
474         class XsltGenerateId : XPathFunction 
475         {
476                 //FIXME: generate short string, not the huge thing it makes now
477                 Expression arg0;
478                 public XsltGenerateId (FunctionArguments args) : base (args)
479                 {
480                         if (args != null) {
481                                 if (args.Tail != null)
482                                         throw new XPathException ("generate-id takes 1 or no args");
483                                 arg0 = args.Arg;
484                         }
485                 }
486                 
487                 public override XPathResultType ReturnType { get { return XPathResultType.String; }}
488
489                 internal override bool Peer {
490                         get { return arg0.Peer; }
491                 }
492
493                 public override object Evaluate (BaseIterator iter)
494                 {
495                         XPathNavigator n;
496                         if (arg0 != null) {
497                                 XPathNodeIterator itr = arg0.EvaluateNodeSet (iter);
498                                 if (itr.MoveNext ())
499                                         n = itr.Current.Clone ();
500                                 else
501                                         return string.Empty; // empty nodeset == empty string
502                         } else
503                                 n = iter.Current.Clone ();
504                         
505                         StringBuilder sb = new StringBuilder ("Mono"); // Ensure begins with alpha
506                         sb.Append (XmlConvert.EncodeLocalName (n.BaseURI));
507                         sb.Replace ('_', 'm'); // remove underscores from EncodeLocalName
508                         sb.Append (n.NodeType);
509                         sb.Append ('m');
510
511                         do {
512                                 sb.Append (IndexInParent (n));
513                                 sb.Append ('m');
514                         } while (n.MoveToParent ());
515                         
516                         return sb.ToString ();
517                 }
518                 
519                 int IndexInParent (XPathNavigator nav)
520                 {
521                         int n = 0;
522                         while (nav.MoveToPrevious ())
523                                 n++;
524                         
525                         return n;
526                 }
527         } 
528         
529         class XsltKey : XPathFunction 
530         {
531                 Expression arg0, arg1;
532                 IStaticXsltContext staticContext;
533                 
534                 public XsltKey (FunctionArguments args, IStaticXsltContext ctx) : base (args)
535                 {
536                         staticContext = ctx;
537                         if (args == null || args.Tail == null)
538                                 throw new XPathException ("key takes 2 args");
539                         arg0 = args.Arg;
540                         arg1 = args.Tail.Arg;
541                 }
542                 public Expression KeyName { get { return arg0; } }
543                 public Expression Field { get { return arg1; } }
544                 public override XPathResultType ReturnType { get { return XPathResultType.NodeSet; }}
545
546                 internal override bool Peer {
547                         get { return arg0.Peer && arg1.Peer; }
548                 }
549
550                 public bool PatternMatches (XPathNavigator nav, XsltContext nsmgr)
551                 {
552                         XsltCompiledContext ctx = nsmgr as XsltCompiledContext;
553                         // for key pattern, it must contain literal value
554                         return ctx.MatchesKey (nav, staticContext,
555                                 arg0.StaticValueAsString,
556                                 arg1.StaticValueAsString);
557                 }
558
559                 public override object Evaluate (BaseIterator iter)
560                 {
561                         XsltCompiledContext ctx = iter.NamespaceManager
562                                 as XsltCompiledContext;
563                         return ctx.EvaluateKey (staticContext, iter, arg0, arg1);
564                 }
565         }
566         
567         class XsltSystemProperty : XPathFunction 
568         {
569                 Expression arg0;
570                 IStaticXsltContext ctx;
571                 
572                 public XsltSystemProperty (FunctionArguments args, IStaticXsltContext ctx) : base (args)
573                 {
574                         if (args == null || args.Tail != null)
575                                 throw new XPathException ("system-property takes 1 arg");
576                         
577                         arg0 = args.Arg;
578                         this.ctx = ctx;
579                 }
580                 
581                 public override XPathResultType ReturnType { get { return XPathResultType.String; }}
582
583                 internal override bool Peer {
584                         get { return arg0.Peer; }
585                 }
586
587                 public override object Evaluate (BaseIterator iter)
588                 {
589                         QName name = XslNameUtil.FromString (arg0.EvaluateString (iter), ctx);
590                         
591                         if (name.Namespace == Compiler.XsltNamespace) {
592                                 switch (name.Name) {
593                                         case "version": return "1.0";
594                                         case "vendor": return "Mono";
595                                         case "vendor-url": return "http://www.go-mono.com/";
596                                 }
597                         }
598                         
599                         return "";
600                 }
601         } 
602
603         class XsltUnparsedEntityUri : XPathFunction 
604         {
605                 Expression arg0;
606                 
607                 public XsltUnparsedEntityUri (FunctionArguments args) : base (args)
608                 {
609                         if (args == null || args.Tail != null)
610                                 throw new XPathException ("unparsed-entity-uri takes 1 arg");
611                         
612                         arg0 = args.Arg;
613                 }
614                 
615                 public override XPathResultType ReturnType { get { return XPathResultType.String; }}
616
617                 internal override bool Peer {
618                         get { return arg0.Peer; }
619                 }
620
621                 public override object Evaluate (BaseIterator iter)
622                 {
623                         IHasXmlNode xn = iter.Current as IHasXmlNode;
624                         if (xn == null)
625                                 return String.Empty;
626                         XmlNode n = xn.GetNode ();
627                         if (n.OwnerDocument == null)
628                                 return String.Empty;
629                         XmlDocumentType doctype = n.OwnerDocument.DocumentType;
630                         if (doctype == null)
631                                 return String.Empty;
632                         XmlEntity ent = doctype.Entities.GetNamedItem (arg0.EvaluateString (iter)) as XmlEntity;
633                         if (ent == null)
634                                 return String.Empty;
635                         return ent.SystemId != null ? ent.SystemId : String.Empty;
636                 }
637         }
638
639         class MSXslNodeSet : XPathFunction
640         {
641                 Expression arg0;
642
643                 public MSXslNodeSet (FunctionArguments args) : base (args)
644                 {
645                         if (args == null || args.Tail != null)
646                                 throw new XPathException ("element-available takes 1 arg");
647                         
648                         arg0 = args.Arg;
649                 }
650
651                 public override XPathResultType ReturnType {
652                         get {
653                                 return XPathResultType.NodeSet;
654                         }
655                 }
656
657                 internal override bool Peer {
658                         get { return arg0.Peer; }
659                 }
660
661                 public override object Evaluate (BaseIterator iter)
662                 {
663                         XsltCompiledContext ctx = iter.NamespaceManager as XsltCompiledContext;
664                         XPathNavigator loc = iter.Current != null ? iter.Current.Clone () : null;
665                         XPathNavigator nav = arg0.EvaluateAs (iter, XPathResultType.Navigator) as XPathNavigator;
666                         if (nav == null) {
667                                 if (loc != null)
668                                         return new XsltException ("Cannot convert the XPath argument to a result tree fragment.", null, loc);
669                                 else
670                                         return new XsltException ("Cannot convert the XPath argument to a result tree fragment.", null);
671                         }
672                         ArrayList al = new ArrayList ();
673                         al.Add (nav);
674                         return new ListIterator (al, ctx);
675                 }
676         }
677 }