Пример #1
0
        public XPathMutableCursor(IXmlNode parent, CompiledXPath path,
                                  IXmlIncludedTypeMap knownTypes, IXmlNamespaceSource namespaces, CursorFlags flags)
            : base(path, namespaces, parent)
        {
            if (null == parent)
            {
                throw Error.ArgumentNull("parent");
            }
            if (null == path)
            {
                throw Error.ArgumentNull("path");
            }
            if (null == knownTypes)
            {
                throw Error.ArgumentNull("knownTypes");
            }
            if (!path.IsCreatable)
            {
                throw Error.XPathNotCreatable(path);
            }

            this.step       = path.FirstStep;
            this.knownTypes = knownTypes;
            this.flags      = flags;

            var source = parent.RequireRealizable <XPathNavigator>();

            if (source.IsReal)
            {
                iterator = new XPathBufferedNodeIterator(
                    source.Value.Select(path.FirstStep.Path));
            }
        }
Пример #2
0
        private static bool ParseStep(Tokenizer source, CompiledXPath path, ref CompiledXPathStep step)
        {
            var previous = step;
            var start    = source.Index;

            if (!ParseNodeCore(source, StepFactory, ref step))
            {
                return(false);
            }

            if (step != previous)
            {
                var text = source.GetConsumedText(start);
                step.Path = XPathExpression.Compile(text);

                if (previous == null)
                {
                    path.FirstStep = step;
                }
                else
                {
                    LinkNodes(previous, step);
                }

                path.Depth++;
            }
            return(true);
        }
Пример #3
0
        internal static Exception XPathNotCreatable(CompiledXPath path)
        {
            var message = string.Format(
                "The path '{0}' is not a creatable XPath expression.",
                path.Path.Expression);

            return(new XPathException(message));
        }
Пример #4
0
        public XPathAttribute(string path)
        {
            if (path == null)
            {
                throw Error.ArgumentNull("path");
            }

            this.getPath = XPathCompiler.Compile(path);
            this.setPath = this.getPath;
        }
Пример #5
0
        public XPathAttribute(string get, string set)
        {
            if (get == null)
            {
                throw Error.ArgumentNull("get");
            }
            if (set == null)
            {
                throw Error.ArgumentNull("set");
            }

            this.getPath = XPathCompiler.Compile(get);
            this.setPath = XPathCompiler.Compile(set);
        }
Пример #6
0
        public void Configure(XPathAttribute attribute)
        {
            if (path != null)
            {
                throw Error.AttributeConflict(path.Path.Expression);
            }

            path = attribute.SetPath;

            if (path == attribute.GetPath)
            {
                return;
            }
            else if (Serializer.CanGetStub)
            {
                throw Error.SeparateGetterSetterOnComplexType(path.Path.Expression);
            }

            defaultAccessor = new DefaultAccessor(this, attribute.GetPath);
        }
Пример #7
0
 private static bool ParsePath(Tokenizer source, CompiledXPath path)
 {
     for (CompiledXPathStep step = null;;)
     {
         if (!ParseStep(source, path, ref step))
         {
             return(false);
         }
         if (source.Token == Token.EndOfInput)
         {
             return(true);
         }
         if (!Consume(source, Token.StepSeparator))
         {
             return(false);
         }
         if (step.IsAttribute)
         {
             return(false);
         }
     }
 }
Пример #8
0
        public XPathReadOnlyCursor(IXmlNode parent, CompiledXPath path,
                                   IXmlIncludedTypeMap includedTypes, IXmlNamespaceSource namespaces, CursorFlags flags)
            : base(path, namespaces, parent)
        {
            if (parent == null)
            {
                throw Error.ArgumentNull("parent");
            }
            if (path == null)
            {
                throw Error.ArgumentNull("path");
            }
            if (includedTypes == null)
            {
                throw Error.ArgumentNull("includedTypes");
            }

            this.includedTypes = includedTypes;
            this.flags         = flags;

            Reset();
        }
Пример #9
0
        public static CompiledXPath Compile(string path)
        {
            if (null == path)
            {
                throw Error.ArgumentNull("path");
            }

            // Compile whole path to catch errors
            var result = new CompiledXPath();

            result.Path = XPathExpression.Compile(path);

            // Try to split into individual path steps
            var tokenizer = new Tokenizer(path);

            if (!ParsePath(tokenizer, result))
            {
                result.MakeNotCreatable();
            }

            // Finish compilation
            result.Prepare();
            return(result);
        }
Пример #10
0
 public void Enlist(CompiledXPath path)
 {
     path.SetContext(XPathContext);
 }
Пример #11
0
 public DefaultAccessor(XPathBehaviorAccessor parent, CompiledXPath path)
     : base(parent.ClrType, parent.Context)
 {
     this.parent = parent;
     this.path   = path;
 }
Пример #12
0
        public XmlMetadata(DictionaryAdapterMeta meta, IEnumerable <string> reservedNamespaceUris)
        {
            if (meta == null)
            {
                throw Error.ArgumentNull("meta");
            }
            if (reservedNamespaceUris == null)
            {
                throw Error.ArgumentNull("reservedNamespaceUris");
            }

            source        = meta;
            clrType       = meta.Type;
            context       = new XmlContext(this);
            includedTypes = new XmlIncludedTypeSet();

            this.reservedNamespaceUris
                = reservedNamespaceUris as HashSet <string>
                  ?? new HashSet <string>(reservedNamespaceUris);

            var xmlRoot       = null as XmlRootAttribute;
            var xmlType       = null as XmlTypeAttribute;
            var xmlDefaults   = null as XmlDefaultsAttribute;
            var xmlInclude    = null as XmlIncludeAttribute;
            var xmlNamespace  = null as XmlNamespaceAttribute;
            var reference     = null as ReferenceAttribute;
            var xPath         = null as XPathAttribute;
            var xPathVariable = null as XPathVariableAttribute;
            var xPathFunction = null as XPathFunctionAttribute;

            foreach (var behavior in meta.Behaviors)
            {
                if (TryCast(behavior, ref xmlRoot))
                {
                }
                else if (TryCast(behavior, ref xmlType))
                {
                }
                else if (TryCast(behavior, ref xmlDefaults))
                {
                }
                else if (TryCast(behavior, ref xmlInclude))
                {
                    AddPendingInclude(xmlInclude);
                }
                else if (TryCast(behavior, ref xmlNamespace))
                {
                    context.AddNamespace(xmlNamespace);
                }
                else if (TryCast(behavior, ref reference))
                {
                }
                else if (TryCast(behavior, ref xPath))
                {
                }
                else if (TryCast(behavior, ref xPathVariable))
                {
                    context.AddVariable(xPathVariable);
                }
                else if (TryCast(behavior, ref xPathFunction))
                {
                    context.AddFunction(xPathFunction);
                }
            }

            if (xmlDefaults != null)
            {
                qualified  = xmlDefaults.Qualified;
                isNullable = xmlDefaults.IsNullable;
            }

            if (reference != null)
            {
                isReference = true;
            }

            typeLocalName = XmlConvert.EncodeLocalName
                            (
                (!meta.HasXmlType() ? null : meta.GetXmlType().NonEmpty()) ??
                (xmlType == null    ? null : xmlType.TypeName.NonEmpty()) ??
                GetDefaultTypeLocalName(clrType)
                            );

            rootLocalName = XmlConvert.EncodeLocalName
                            (
                (xmlRoot == null ? null : xmlRoot.ElementName.NonEmpty()) ??
                typeLocalName
                            );

            typeNamespaceUri =
                (
                    (xmlType == null ? null : xmlType.Namespace)
                );

            rootNamespaceUri =
                (
                    (xmlRoot == null ? null : xmlRoot.Namespace)
                );

            childNamespaceUri =
                (
                    typeNamespaceUri ??
                    rootNamespaceUri
                );

            if (xPath != null)
            {
                path = xPath.GetPath;
                path.SetContext(context);
            }
        }
Пример #13
0
 protected XPathNode(CompiledXPath path, IXmlNamespaceSource namespaces, IXmlNode parent)
     : base(namespaces, parent)
 {
     this.xpath = path;
 }
Пример #14
0
 public virtual object Evaluate(CompiledXPath path)
 {
     return(node.Evaluate(path.Path));
 }
Пример #15
0
 public IXmlCursor Select(CompiledXPath path, IXmlIncludedTypeMap includedTypes, IXmlNamespaceSource namespaces, CursorFlags flags)
 {
     return(flags.SupportsMutation()
                         ? (IXmlCursor) new XPathMutableCursor(this, path, includedTypes, namespaces, flags)
                         : (IXmlCursor) new XPathReadOnlyCursor(this, path, includedTypes, namespaces, flags));
 }
Пример #16
0
 public void Enlist(CompiledXPath path)
 {
     throw Error.NotSupported();
 }
Пример #17
0
 public virtual object Evaluate(CompiledXPath path)
 {
     return(node.CreateNavigator().Evaluate(path.Path));
 }
Пример #18
0
 public override object Evaluate(CompiledXPath path)
 {
     return(HasCurrent ? base.Evaluate(path) : null);
 }
Пример #19
0
 public object Evaluate(CompiledXPath path)
 {
     return(node.Evaluate(path));
 }
Пример #20
0
 public IXmlCursor Select(CompiledXPath path, IXmlIncludedTypeMap knownTypes, IXmlNamespaceSource namespaces, CursorFlags flags)
 {
     return(node.Select(path, knownTypes, namespaces, flags));
 }