internal IXmlNamespaceResolver GetNSResolver (XPathSequence iter) { // FIXME: IXmlNamespaceResolver must be constructed // considering 1)static context and 2)in-scope element // construction. return iter.Context; }
internal XQueryContextManager (XQueryStaticContext ctx, XPathItem input, XmlWriter writer, XmlResolver resolver, XmlArgumentList args) { this.input = input; this.staticContext = ctx; this.args = args; currentWriter = writer; this.extDocResolver = resolver; namespaceManager = new XmlNamespaceManager (ctx.NameTable); foreach (DictionaryEntry de in ctx.NSResolver.GetNamespacesInScope (XmlNamespaceScope.ExcludeXml)) namespaceManager.AddNamespace (de.Key.ToString (), de.Value.ToString ()); namespaceManager.PushScope (); currentContext = new XQueryContext (this, null, new Hashtable ()); if (input != null) { currentSequence = new SingleItemIterator (input, currentContext); currentSequence.MoveNext (); } currentContext = new XQueryContext (this, currentSequence, new Hashtable ()); }
public XPathSequence EvaluateNode (XPathSequence iter, XPathNodeType moveAfterCreation) { XmlDocument doc = new XmlDocument (); XmlWriter w = iter.Context.Writer; try { iter.Context.Writer = doc.CreateNavigator ().AppendChild (); Serialize (iter); iter.Context.Writer.Close (); } finally { iter.Context.Writer = w; } XPathNavigator nav = doc.CreateNavigator (); switch (moveAfterCreation) { case XPathNodeType.Attribute: nav.MoveToFirstAttribute (); break; case XPathNodeType.Root: break; default: nav.MoveToFirstChild (); break; } return new SingleItemIterator (nav, iter.Context); }
private static object FnMinImpl (XPathSequence e, CultureInfo collation) { if (!e.MoveNext ()) return null; switch (e.Current.XmlType.TypeCode) { case XmlTypeCode.DayTimeDuration: return FnMinDayTimeDuration (e); case XmlTypeCode.YearMonthDuration: return FnMinYearMonthDuration (e); case XmlTypeCode.Decimal: return FnMinDecimal (e); case XmlTypeCode.Integer: return FnMinInteger (e); case XmlTypeCode.Float: return FnMinFloat (e); case XmlTypeCode.UntypedAtomic: case XmlTypeCode.Double: return FnMinDouble (e); } throw new XmlQueryException ("avg() function detected that the sequence contains an item whose type is neither of dayTimeDuration, yearMonthDuration, decimal, integer, float, double, nor untypedAtomic."); }
public static object FnMin (XQueryContext ctx, XPathSequence e) { return FnMinImpl (e, ctx.DefaultCollation); }
private static float FnMaxFloat (XPathSequence e) { float ret = float.MinValue; do { ret = System.Math.Max (e.Current.ValueAsSingle, ret); } while (e.MoveNext ()); return ret; }
private static decimal FnMaxDecimal (XPathSequence e) { decimal ret = decimal.MinValue; do { ret = System.Math.Max (e.Current.ValueAsDecimal, ret); } while (e.MoveNext ()); return ret; }
private static TimeSpan FnAvgYearMonthDuration (XPathSequence e) { throw new NotImplementedException (); }
public static bool FnDeepEqualImpl (XPathSequence p1, XPathSequence p2, CultureInfo collation) { // FIXME: use collation while (p1.MoveNext ()) { if (!p2.MoveNext ()) return false; if (!FnDeepEqualItem (p1.Current, p2.Current, collation)) return false; } if (p2.MoveNext ()) return false; return true; }
public static XPathSequence FnRemove (XPathSequence target, int position) { if (position < 1) return target; return new RemovalIterator (target, position); }
public static XPathSequence FnInsertBefore (XPathSequence target, int position, XPathSequence inserts) { if (position < 1) position = 1; return new InsertingIterator (target, position, inserts); }
private static XPathSequence FnDistinctValuesImpl (XQueryContext ctx, XPathSequence items, CultureInfo collation) { return new DistinctValueIterator (ctx, items, collation); }
public static XPathSequence FnDistinctValues (XQueryContext ctx, XPathSequence items, string collation) { return FnDistinctValuesImpl (ctx, items, ctx.GetCulture (collation)); }
public static XPathSequence FnDistinctValues (XQueryContext ctx, XPathSequence items) { return FnDistinctValuesImpl (ctx, items, ctx.DefaultCollation); }
public static bool FnExists (XPathSequence e) { if (e is XPathEmptySequence) return false; return e.MoveNext (); }
public static object FnDeepEqual (XQueryContext ctx, XPathSequence p1, XPathSequence p2) { return FnDeepEqualImpl (p1, p2, ctx.DefaultCollation); }
public static object FnDeepEqual (XQueryContext ctx, XPathSequence p1, XPathSequence p2, string collation) { return FnDeepEqualImpl (p1, p2, ctx.GetCulture (collation)); }
public static XPathSequence FnReverse (XPathSequence arg) { ArrayList al = new ArrayList (); while (arg.MoveNext ()) al.Add (arg.Current); al.Reverse (); return new ListIterator (arg.Context, al); }
public static int FnCount (XPathSequence e) { if (e == null) return 0; return e.Count; }
public static object FnSubsequence (XPathSequence sourceSeq, double startingLoc) { return FnSubsequence (sourceSeq, startingLoc, double.MaxValue); }
private static TimeSpan FnAvgDouble (XPathSequence e) { throw new NotImplementedException (); }
public static object FnSubsequence (XPathSequence sourceSeq, double startingLoc, double length) { throw new NotImplementedException (); }
private static int FnMaxInteger (XPathSequence e) { int ret = int.MinValue; do { ret = System.Math.Max (e.Current.ValueAsInt32, ret); } while (e.MoveNext ()); return ret; }
// Basically it should be optimized by XQueryASTCompiler public static XPathSequence FnUnordered (XPathSequence e) { return e; }
private static double FnMaxDouble (XPathSequence e) { double ret = double.MinValue; do { ret = System.Math.Max (e.Current.ValueAsDouble, ret); } while (e.MoveNext ()); return ret; }
public static XPathItem FnZeroOrOne (XPathSequence e) { if (!e.MoveNext ()) return null; XPathItem item = e.Current; if (e.MoveNext ()) throw new XmlQueryException ("zero-or-one() function detected that the argument sequence contains two or more items."); return item; }
public static object FnMin (XQueryContext ctx, XPathSequence e, string collation) { return FnMinImpl (e, ctx.GetCulture (collation)); }
public static object FnOneOrMore (XPathSequence e) { if (!e.Clone ().MoveNext ()) throw new XmlQueryException ("one-or-more() function detected that the argument sequence contains no items."); return e; }
private static TimeSpan FnMinYearMonthDuration (XPathSequence e) { // FIXME: reject dTD (but is it possible...?) TimeSpan ret = TimeSpan.Zero; do { TimeSpan ts = (TimeSpan) e.Current.TypedValue; if (ts > ret) ret = ts; } while (e.MoveNext ()); return ret; }
public static XPathItem FnExactlyOne (XPathSequence e) { if (!e.MoveNext ()) throw new XmlQueryException ("exactly-one() function detected that the argument sequence contains no items."); XPathItem item = e.Current; if (e.MoveNext ()) throw new XmlQueryException ("exactly-one() function detected that the argument sequence contains two or more items."); return item; }