public XQueryExpr(XQueryContext context, object[] expr) : base(context) { m_expr = expr; m_compiledBody = null; QueryOrder = XQueryOrder.Default; }
public XQueryMapping(XQueryContext context, object expr, XQueryExprBase bodyExpr, bool root) : base(context) { m_root = root; m_expr = expr; m_bodyExpr = bodyExpr; }
public XQueryFLWORBase(XQueryContext context, object var, XQuerySequenceType varType, object expr, XQueryExprBase bodyExpr) : base(context) { m_var = var; m_varType = varType; m_expr = expr; m_bodyExpr = bodyExpr; }
public XQueryPathExpr(XQueryContext context, XQueryExprBase[] path, bool isOrdered) : base(context) { _path = path; _isOrderedSet = IsOrderedSet(); _isOrdered = isOrdered; _cache = new SymbolLink(); EnableCaching = true; }
public XQueryStepExpr(XQueryPathExprType type, XQueryContext queryContext) : base(queryContext) { m_type = type; switch (m_type) { case XQueryPathExprType.Self: m_iter = new PathExprIterator(SelfIterator); break; case XQueryPathExprType.Child: m_iter = new PathExprIterator(ChildIterator); break; case XQueryPathExprType.Descendant: case XQueryPathExprType.DescendantOrSelf: m_iter = new PathExprIterator(DescendantIterator); break; case XQueryPathExprType.Attribute: m_iter = new PathExprIterator(AttributeIterator); break; case XQueryPathExprType.Following: m_iter = new PathExprIterator(FollowingIterator); break; case XQueryPathExprType.FollowingSibling: m_iter = new PathExprIterator(FollowingSiblingIterator); break; case XQueryPathExprType.Parent: m_iter = new PathExprIterator(ParentIterator); break; case XQueryPathExprType.Ancestor: case XQueryPathExprType.AncestorOrSelf: m_iter = new PathExprIterator(AncestorIterator); break; case XQueryPathExprType.Preceding: m_iter = new PathExprIterator(PrecedingIterator); break; case XQueryPathExprType.PrecedingSibling: m_iter = new PathExprIterator(PrecedingSiblingIterator); break; case XQueryPathExprType.Namespace: m_iter = new PathExprIterator(NamespaceIterator); break; default: throw new ArgumentException("type"); } }
public DirectAccessPathExpr(XQueryContext context, XQueryExprBase[] path, bool isOrdered) : base(context) { XQueryExprBase[] tmp = new XQueryExprBase[path.Length + 1]; tmp[0] = new XQueryStepExpr(XQueryPathExprType.Self, context); for (int k = 0; k < path.Length; k++) tmp[k + 1] = path[k]; _shadowXPath = new XQueryPathExpr(context, tmp, isOrdered); _path = path; }
public XQueryStepExpr(object nodeTest, XQueryPathExprType type, XQueryContext queryContext) : this(type, queryContext) { if (nodeTest is XmlQualifiedNameTest) m_nameTest = (XmlQualifiedNameTest)nodeTest; else if (nodeTest is XQuerySequenceType) m_typeTest = (XQuerySequenceType)nodeTest; else throw new ArgumentException("nodeTest"); }
public XQueryFLWOR(XQueryContext context, object var, XQuerySequenceType varType, object pos, object expr, XQueryExprBase bodyExpr, bool convert) : base(context, var, varType, expr, bodyExpr) { m_var = var; m_varType = varType; m_pos = pos; m_value = new SymbolLink(varType.ValueType); m_itemType = varType.ItemType; if (m_pos != null) m_posValue = new SymbolLink(typeof(Integer)); m_convert = convert; }
private bool MatchName(XPathNavigator nav, XQueryContext context) { return (NameTest.IsNamespaceWildcard || context.StringEquals(NameTest.Namespace, nav.NamespaceURI)) && (NameTest.IsNameWildcard || context.StringEquals(NameTest.Name, nav.LocalName)); }
private IEnumerable<XPathItem> EnumerateItems(XQueryContext context, string[] items) { foreach (String id in items) { IXPathNavigable doc = context.OpenDocument(_sources[id]); yield return doc.CreateNavigator(); } }
private bool CompareFragment(XQueryContext context, string sourceFile, XQueryNodeIterator iter, XmlSpace space) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<?xml version='1.0'?>"); sb.Append("<root>"); TextReader textReader = new StreamReader(sourceFile, true); sb.Append(textReader.ReadToEnd()); textReader.Close(); sb.Append("</root>"); XmlReaderSettings settings = context.GetSettings(); XmlReader reader = XmlReader.Create(new StringReader(sb.ToString()), settings); XQueryDocument doc1 = new XQueryDocument(reader, space); doc1.Fill(); context.AddDocument(doc1); XQueryDocument doc2 = context.CreateDocument(); XQueryDocumentBuilder builder = new XQueryDocumentBuilder(doc2); builder.WriteStartDocument(); builder.WriteStartElement("root", ""); Core.WriteNode(context.Engine, builder, iter.Clone()); builder.WriteEndElement(); XQueryNodeIterator iter1 = new NodeIterator(new XPathItem[] { doc1.CreateNavigator() }); XQueryNodeIterator iter2 = new NodeIterator(new XPathItem[] { doc2.CreateNavigator() }); TreeComparer comparer = new TreeComparer(); comparer.IgnoreWhitespace = true; bool res = comparer.DeepEqual(iter1, iter2); return res; }
private bool CompareXML(XQueryContext context, string sourceFile, XQueryNodeIterator iter) { IXPathNavigable doc = context.OpenDocument(sourceFile); XQueryNodeIterator src = new NodeIterator(new XPathItem[] { doc.CreateNavigator() }); TreeComparer comparer = new TreeComparer(); comparer.IgnoreWhitespace = true; return comparer.DeepEqual(src, new NodeIterator(DocumentIterator(context, iter))); }
public XQueryCommand(XQueryContext context) { m_context = context; Parameters = new XQueryParameterCollection(); }
public XQueryCommand(XmlNameTable nameTable) { m_context = new WorkContext(this, nameTable); BaseUri = null; SearchPath = null; Parameters = new XQueryParameterCollection(); }
public XQueryLET(XQueryContext context, object var, XQuerySequenceType varType, object expr, XQueryExprBase bodyExpr, bool convert) : base(context, var, varType, expr, bodyExpr) { m_value = new SymbolLink(varType.ValueType); m_convert = convert; }
public void Register(object id, XQueryContext module, XQuerySequenceType[] parameters, XQuerySequenceType resType) { XQueryFunctionRecord rec = new XQueryFunctionRecord(); rec.id = id; rec.module = module; rec.parameters = parameters; rec.returnType = resType; FunctionSocket sock = new FunctionSocket(rec); FunctionSocket next; if (m_table.TryGetValue(rec.id, out next)) sock.next = next; m_table[rec.id] = sock; }
public Translator(XQueryContext context) { _context = context; _varTable = new VarTable(); _fdecl = new Dictionary<object, FunctionDecl>(); _moduleNs = new List<string>(); _schemaNs = new List<string>(); }
public bool Match(XPathItem item, XQueryContext context) { switch (TypeCode) { case XmlTypeCode.None: return false; case XmlTypeCode.Item: return true; case XmlTypeCode.Node: return item.IsNode; case XmlTypeCode.AnyAtomicType: return !item.IsNode; case XmlTypeCode.UntypedAtomic: return !item.IsNode && item.XmlType == XmlSchema.UntypedAtomic; case XmlTypeCode.Document: { XPathNavigator nav = item as XPathNavigator; if (nav != null) { if (nav.NodeType == XPathNodeType.Root) { XPathNavigator cur = nav.Clone(); if (SchemaElement == null) { if (cur.MoveToChild(XPathNodeType.Element) && MatchName(cur, context)) { if (SchemaType == null || SchemaType == XmlSchema.UntypedAtomic) return true; IXmlSchemaInfo schemaInfo = cur.SchemaInfo; if (schemaInfo != null) { if (XmlSchemaType.IsDerivedFrom(schemaInfo.SchemaType, SchemaType, XmlSchemaDerivationMethod.Empty)) return !schemaInfo.IsNil || Nillable; } else return XmlSchemaType.IsDerivedFrom(XmlSchema.UntypedAtomic, SchemaType, XmlSchemaDerivationMethod.Empty); } } else { if (!cur.MoveToChild(XPathNodeType.Element)) return false; IXmlSchemaInfo schemaInfo = cur.SchemaInfo; if (schemaInfo != null) return schemaInfo.SchemaElement.QualifiedName == SchemaElement.QualifiedName; } } } } break; case XmlTypeCode.Element: { XPathNavigator nav = item as XPathNavigator; if (nav != null && nav.NodeType == XPathNodeType.Element) { if (SchemaElement == null) { if (MatchName(nav, context)) { if (SchemaType == null || SchemaType == XmlSchema.UntypedAtomic) return true; IXmlSchemaInfo schemaInfo = nav.SchemaInfo; if (schemaInfo != null) { if (XmlSchemaType.IsDerivedFrom(schemaInfo.SchemaType, SchemaType, XmlSchemaDerivationMethod.Empty)) return !schemaInfo.IsNil || Nillable; } else return XmlSchemaType.IsDerivedFrom(XmlSchema.UntypedAtomic, SchemaType, XmlSchemaDerivationMethod.Empty); } } else { IXmlSchemaInfo schemaInfo = nav.SchemaInfo; if (schemaInfo != null) return schemaInfo.SchemaElement.QualifiedName == SchemaElement.QualifiedName; } } } break; case XmlTypeCode.Attribute: { XPathNavigator nav = item as XPathNavigator; if (nav != null && nav.NodeType == XPathNodeType.Attribute) { if (SchemaAttribute == null) { if (MatchName(nav, context)) { if (SchemaType == null || SchemaType == XmlSchema.UntypedAtomic) return true; IXmlSchemaInfo schemaInfo = nav.SchemaInfo; if (schemaInfo == null) return XmlSchemaType.IsDerivedFrom(XmlSchema.UntypedAtomic, SchemaType, XmlSchemaDerivationMethod.Empty); else return XmlSchemaType.IsDerivedFrom(schemaInfo.SchemaType, SchemaType, XmlSchemaDerivationMethod.Empty); } } else { IXmlSchemaInfo schemaInfo = nav.SchemaInfo; if (schemaInfo != null) return schemaInfo.SchemaAttribute.QualifiedName == SchemaAttribute.QualifiedName; } } } break; case XmlTypeCode.ProcessingInstruction: { XPathNavigator nav = item as XPathNavigator; if (nav != null) return (nav.NodeType == XPathNodeType.ProcessingInstruction && (NameTest.IsNameWildcard || NameTest.Name == nav.Name)); } break; case XmlTypeCode.Comment: { XPathNavigator nav = item as XPathNavigator; if (nav != null) return nav.NodeType == XPathNodeType.Comment; } break; case XmlTypeCode.Text: { XPathNavigator nav = item as XPathNavigator; if (nav != null) return nav.NodeType == XPathNodeType.Text || nav.NodeType == XPathNodeType.SignificantWhitespace; } break; case XmlTypeCode.PositiveInteger: switch (item.XmlType.TypeCode) { case XmlTypeCode.Byte: case XmlTypeCode.Short: case XmlTypeCode.Int: case XmlTypeCode.Long: case XmlTypeCode.Integer: return (decimal)item.ValueAs(typeof(System.Decimal)) > 0; } break; case XmlTypeCode.NegativeInteger: switch (item.XmlType.TypeCode) { case XmlTypeCode.Byte: case XmlTypeCode.Short: case XmlTypeCode.Int: case XmlTypeCode.Long: case XmlTypeCode.Integer: return (decimal)item.ValueAs(typeof(System.Decimal)) < 0; } break; case XmlTypeCode.NonPositiveInteger: switch (item.XmlType.TypeCode) { case XmlTypeCode.Byte: case XmlTypeCode.Short: case XmlTypeCode.Int: case XmlTypeCode.Long: case XmlTypeCode.Integer: return (decimal)item.ValueAs(typeof(System.Decimal)) <= 0; } break; case XmlTypeCode.NonNegativeInteger: switch (item.XmlType.TypeCode) { case XmlTypeCode.Byte: case XmlTypeCode.Short: case XmlTypeCode.Int: case XmlTypeCode.Long: case XmlTypeCode.Integer: return (decimal)item.ValueAs(typeof(System.Decimal)) >= 0; case XmlTypeCode.UnsignedByte: case XmlTypeCode.UnsignedShort: case XmlTypeCode.UnsignedInt: case XmlTypeCode.UnsignedLong: return true; } break; case XmlTypeCode.Integer: switch (item.XmlType.TypeCode) { case XmlTypeCode.Byte: case XmlTypeCode.Short: case XmlTypeCode.Int: case XmlTypeCode.Long: case XmlTypeCode.Integer: case XmlTypeCode.UnsignedByte: case XmlTypeCode.UnsignedShort: case XmlTypeCode.UnsignedInt: case XmlTypeCode.UnsignedLong: return true; case XmlTypeCode.Decimal: decimal value = (decimal)item.ValueAs(typeof(System.Decimal)); return value == Math.Truncate(value); } break; case XmlTypeCode.Entity: return (item.XmlType.TypeCode == XmlTypeCode.String) || (item.XmlType.TypeCode == XmlTypeCode.Entity); default: { if (item.XmlType != null) return XmlSchemaType.IsDerivedFrom(item.XmlType, SchemaType, XmlSchemaDerivationMethod.Empty); } break; } return false; }
public void ImportVariables(XQueryContext module) { foreach (XQueryContext.VariableRecord vr in module.variables) if (vr.module == module) PushVar(vr.id, vr.varType); foreach (KeyValuePair<object, XQueryContext.ExternalVariableRecord> kvp in module.externalVars) PushVar(kvp.Key, kvp.Value.varType); }
private void ProcessImportModule(Notation notation, Notation.Record rec) { Literal[] arr = null; Literal targetNamespace; if (rec.args.Length == 2) { targetNamespace = (Literal)rec.Arg0; if (targetNamespace.Data == "") throw new XQueryException(Properties.Resources.XQST0088); if (_moduleNs.Contains(targetNamespace.Data)) throw new XQueryException(Properties.Resources.XQST0047, targetNamespace.Data); if (rec.args[1] != null) arr = Lisp.ToArray<Literal>(rec.args[1]); else arr = _context.ResolveModuleImport(String.Empty, targetNamespace.Data); } else { Qname prefix = (Qname)rec.Arg0; targetNamespace = (Literal)rec.Arg1; if (targetNamespace.Data == "") throw new XQueryException(Properties.Resources.XQST0088); if (_moduleNs.Contains(targetNamespace.Data)) throw new XQueryException(Properties.Resources.XQST0047, targetNamespace.Data); if (prefix.Name == "xml" || prefix.Name == "xmlns") throw new XQueryException(Properties.Resources.XQST0070, targetNamespace.Data); if (rec.args[2] != null) arr = Lisp.ToArray<Literal>(rec.args[2]); else arr = _context.ResolveModuleImport(prefix.Name, targetNamespace.Data); if (_context.NamespaceManager.HasNamespace(prefix.Name)) throw new XQueryException(Properties.Resources.XQST0033, prefix.Name); _context.AddNamespace(prefix.Name, targetNamespace.Data); } for (int k = 0; k < arr.Length; k++) { Literal filename = (Literal)arr[k]; TextReader reader; string absolutePath; if (Uri.IsWellFormedUriString(filename.Data, UriKind.Absolute) || (_context.BaseUri != null && Uri.IsWellFormedUriString(_context.BaseUri, UriKind.Absolute))) { Uri uri; WebClient client = new WebClient(); client.Proxy.Credentials = CredentialCache.DefaultCredentials; if (!Uri.TryCreate(filename.Data, UriKind.Absolute, out uri)) uri = new Uri(new Uri(_context.BaseUri), filename.Data); absolutePath = uri.AbsoluteUri; reader = new StringReader(client.DownloadString(uri)); } else { if (_context.BaseUri != null) absolutePath = Path.Combine(_context.BaseUri, filename.Data); else absolutePath = filename.Data; reader = new StreamReader(new FileStream(absolutePath, FileMode.Open, FileAccess.Read)); } TokenizerBase tok = new Tokenizer(reader.ReadToEnd()); reader.Close(); Notation notation2 = new Notation(); YYParser parser = new YYParser(notation2); parser.yyparseSafe(tok); XQueryContext context2 = new XQueryContext(targetNamespace.Data, absolutePath, _context); Translator translator = new Translator(context2); translator.PreProcess(notation2); translator.Process(notation2); _varTable.ImportVariables(context2); _context.FunctionTable.CopyFrom(context2.FunctionTable, context2); context2.Close(); } _moduleNs.Add(targetNamespace.Data); }
public XQueryCachedExpr(XQueryContext context, XQueryExpr body) : base(context) { m_body = body; m_cache = new Dictionary<Key, object>(); }
public XQueryFilterExpr(XQueryContext queryContext, XQueryExprBase[] filter) : base(queryContext) { m_filter = filter; }
private static void MagnitudeRelationship(XQueryContext context, XPathItem item1, XPathItem item2, out object x, out object y) { x = item1.TypedValue; y = item2.TypedValue; if (x is UntypedAtomic) { if (ValueProxy.IsNumeric(y.GetType())) x = Convert.ToDouble(x, CultureInfo.InvariantCulture); else if (y is String) x = x.ToString(); else if (!(y is UntypedAtomic)) x = item1.ChangeType(new XQuerySequenceType(item2.XmlType.TypeCode), context).TypedValue; } if (y is UntypedAtomic) { if (ValueProxy.IsNumeric(x.GetType())) y = Convert.ToDouble(y, CultureInfo.InvariantCulture); else if (x is String) y = y.ToString(); else if (!(x is UntypedAtomic)) y = item2.ChangeType(new XQuerySequenceType(item1.XmlType.TypeCode), context).TypedValue; } }
public void CopyFrom(XQueryFunctionTable src, XQueryContext module) { foreach (KeyValuePair<object, FunctionSocket> kvp in src.m_table) { FunctionSocket curr = kvp.Value; while (curr != null) { if (curr.rec.module == module) { FunctionSocket sock = new FunctionSocket(curr.rec); FunctionSocket next; if (m_table.TryGetValue(curr.rec.id, out next)) sock.next = next; m_table[curr.rec.id] = sock; } curr = curr.next; } } }
public XQueryExprBase(XQueryContext queryContext) { _queryContext = queryContext; }
public static XQueryExprBase Create(XQueryContext context, object[] expr) { if (expr.Length == 1 && Lisp.IsFunctor(expr[0], ID.DynExecuteExpr, 4)) return (XQueryExprBase)Lisp.Arg1(expr[0]); return new XQueryExpr(context, expr); }
private IEnumerable<XPathItem> DocumentIterator(XQueryContext context, XQueryNodeIterator iter) { foreach (XPathItem item in iter) { XPathNavigator nav = item as XPathNavigator; if (nav != null && nav.NodeType != XPathNodeType.Root) { XQueryDocument doc = context.CreateDocument(); XQueryDocumentBuilder builder = new XQueryDocumentBuilder(doc); builder.WriteStartDocument(); Core.WriteNode(context.Engine, builder, nav); yield return doc.CreateNavigator(); } else yield return item; } }
public XQueryExpr(XQueryContext context, object[] expr, object[] annotation) : this(context, expr) { Annotation = annotation; }
public XQueryValueExpr(XQueryContext queryContext, object name) : base(queryContext) { this.name = name; }