Exemplo n.º 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));
            }
        }
Exemplo n.º 2
0
        public XPathReadOnlyCursor(
            IXmlNode parent,
            CompiledXPath path,
            IXmlIncludedTypeMap includedTypes,
            IXmlNamespaceSource namespaces,
            CursorFlags flags
            ) : base(path, namespaces, parent)
        {
            if (parent == null)
            {
                throw Error.ArgumentNull(nameof(parent));
            }
            if (path == null)
            {
                throw Error.ArgumentNull(nameof(path));
            }
            if (includedTypes == null)
            {
                throw Error.ArgumentNull(nameof(includedTypes));
            }

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

            Reset();
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
		public XPathAttribute(string path)
		{
			if (path == null)
				throw Error.ArgumentNull("path");

			this.getPath = XPathCompiler.Compile(path);
			this.setPath = this.getPath;
		}
Exemplo n.º 5
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));
        }
Exemplo n.º 6
0
 public IXmlCursor Select(
     CompiledXPath path,
     IXmlIncludedTypeMap knownTypes,
     IXmlNamespaceSource namespaces,
     CursorFlags flags
     )
 {
     return(node.Select(path, knownTypes, namespaces, flags));
 }
Exemplo n.º 7
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);
		}
        public XPathAttribute(string path)
        {
            if (path == null)
            {
                throw Error.ArgumentNull("path");
            }

            this.getPath = XPathCompiler.Compile(path);
            this.setPath = this.getPath;
        }
Exemplo n.º 9
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));
 }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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();
		}
        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);
        }
Exemplo n.º 13
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));
		}
Exemplo n.º 14
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);
         }
     }
 }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
			public void Enlist(CompiledXPath path)
			{
				throw Error.NotSupported();
			}
Exemplo n.º 17
0
 protected XPathNode(CompiledXPath path, IXmlNamespaceSource namespaces, IXmlNode parent)
     : base(namespaces, parent)
 {
     this.xpath = path;
 }
Exemplo n.º 18
0
 public virtual object Evaluate(CompiledXPath path)
 {
     return(node.Evaluate(path.Path));
 }
Exemplo n.º 19
0
 public void Enlist(CompiledXPath path)
 {
     path.SetContext(XPathContext);
 }
Exemplo n.º 20
0
		protected abstract IXmlCursor Cursor(IXmlNode parent, CompiledXPath path, IXmlIncludedTypeMap includedTypes, CursorFlags flags);
Exemplo n.º 21
0
 public override object Evaluate(CompiledXPath path)
 {
     return(HasCurrent ? base.Evaluate(path) : null);
 }
Exemplo n.º 22
0
 public object Evaluate(CompiledXPath path)
 {
     return(node.Evaluate(path));
 }
Exemplo n.º 23
0
 public void Enlist(CompiledXPath path)
 {
     throw Error.NotSupported();
 }
Exemplo n.º 24
0
 public virtual object Evaluate(CompiledXPath path)
 {
     return(node.CreateNavigator().Evaluate(path.Path));
 }
Exemplo n.º 25
0
		public override object Evaluate(CompiledXPath path)
		{
			return HasCurrent ? base.Evaluate(path) : null;
		}
Exemplo n.º 26
0
		public void Enlist(CompiledXPath path)
		{
			path.SetContext(XPathContext);
		}
 public DefaultAccessor(XPathBehaviorAccessor parent, CompiledXPath path)
     : base(parent.ClrType, parent.Context)
 {
     this.parent = parent;
     this.path   = path;
 }
Exemplo n.º 28
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);
            }
        }
Exemplo n.º 29
0
		protected override IXmlCursor Cursor(IXmlNode parent, CompiledXPath path, IXmlIncludedTypeMap includedTypes, CursorFlags flags)
		{
			return new XPathMutableCursor(parent, path, includedTypes, NamespaceSource.Instance, flags);
		}