Exemple #1
0
        void IDictionaryInitializer.Initialize(IDictionaryAdapter dictionaryAdapter, object[] behaviors)
        {
            var meta = dictionaryAdapter.Meta;

            if (meta.MetaInitializers.OfType <XPathBehavior>().FirstOrDefault() == null)
            {
                throw new InvalidOperationException(string.Format(
                                                        "Interface {0} requested xpath support, but was not configured properly.  " +
                                                        "Did you forget to add an XPathBehavior?", meta.Type.FullName));
            }

            dictionaryAdapter.This.CreateStrategy = this;

            Context.ApplyBehaviors(behaviors);
            xmlMeta = dictionaryAdapter.GetXmlMeta();

            if (string.IsNullOrEmpty(xmlMeta.XmlType.Namespace) == false)
            {
                Context.AddNamespace(string.Empty, xmlMeta.XmlType.Namespace);
            }

            if (Parent == null)
            {
                foreach (var behavior in behaviors)
                {
                    if (behavior is XPathAttribute)
                    {
                        var attrib             = (XPathAttribute)behavior;
                        var compiledExpression = attrib.CompiledExpression;
                        if (MoveOffRoot(root, XPathNodeType.Element) == false || Context.Matches(compiledExpression, root))
                        {
                            break;
                        }

                        var navigator = Context.SelectSingleNode(compiledExpression, root);
                        if (navigator != null)
                        {
                            root = navigator;
                            break;
                        }
                    }
                }
                MoveOffRoot(root, XPathNodeType.Element);
            }
        }
Exemple #2
0
		void IDictionaryInitializer.Initialize(IDictionaryAdapter dictionaryAdapter, object[] behaviors)
		{
			var meta = dictionaryAdapter.Meta;
			if (meta.MetaInitializers.OfType<XPathBehavior>().FirstOrDefault() == null)
			{
				throw new InvalidOperationException(string.Format(
					"Interface {0} requested xpath support, but was not configured properly.  " +
					"Did you forget to add an XPathBehavior?", meta.Type.FullName));
			}

			dictionaryAdapter.This.CreateStrategy = this;

			Context.ApplyBehaviors(behaviors);
			xmlMeta = dictionaryAdapter.GetXmlMeta();

			if (string.IsNullOrEmpty(xmlMeta.XmlType.Namespace) == false)
			{
				Context.AddNamespace(string.Empty, xmlMeta.XmlType.Namespace);
			}

			if (Parent == null)
			{
				foreach (var behavior in behaviors)
				{
					if (behavior is XPathAttribute)
					{
						var attrib = (XPathAttribute)behavior;
						var compiledExpression = attrib.CompiledExpression;
						if (MoveOffRoot(root, XPathNodeType.Element) == false || Context.Matches(compiledExpression, root))
						{
							break;
						}

						var navigator = Context.SelectSingleNode(compiledExpression, root);
						if (navigator != null)
						{
							root = navigator;
							break;
						}
					}
				}
				MoveOffRoot(root, XPathNodeType.Element);
			}
		}
Exemple #3
0
        public XPathContext ApplyBehaviors(XmlMetadata xmlMeta, IEnumerable behaviors)
        {
            if (this.xmlMeta == null && xmlMeta != null)
            {
                this.xmlMeta = xmlMeta;
                if (string.IsNullOrEmpty(xmlMeta.XmlType.Namespace) == false)
                {
                    if (xmlMeta.Qualified.GetValueOrDefault(false))
                    {
                        AddNamespace(xmlMeta.XmlType.Namespace);
                        qualifiedNamespace = xmlMeta.XmlType.Namespace;
                    }
                    else
                    {
                        AddNamespace(string.Empty, xmlMeta.XmlType.Namespace);
                    }
                }
            }

            new BehaviorVisitor()
            .OfType <XmlNamespaceAttribute>(attrib =>
            {
                AddNamespace(attrib.Prefix, attrib.NamespaceUri);
                if (attrib.Default)
                {
                    AddNamespace(string.Empty, attrib.NamespaceUri);
                }
                if (attrib.Root)
                {
                    AddRootNamespace(attrib.NamespaceUri, attrib.Prefix);
                }
            })
            .OfType <XmlArrayItemAttribute>(attrib =>
            {
                ListItemMeta = ListItemMeta ?? new List <XmlArrayItemAttribute>();
                ((List <XmlArrayItemAttribute>)ListItemMeta).Add(attrib);
            })
            .OfType <XPathFunctionAttribute>(attrib => AddFunction(attrib.Prefix, attrib.Name, attrib.Function))
            .OfType <IXPathSerializer>(attrib => AddSerializer(attrib))
            .Apply(behaviors);
            return(this);
        }
Exemple #4
0
		void IDictionaryInitializer.Initialize(IDictionaryAdapter dictionaryAdapter, object[] behaviors)
		{
			var meta = dictionaryAdapter.Meta;
			if (meta.MetaInitializers.OfType<XPathBehavior>().FirstOrDefault() == null)
			{
				throw new InvalidOperationException(string.Format(
					"Interface {0} requested xpath support, but was not configured properly.  " +
					"Did you forget to add an XPathBehavior?", meta.Type.FullName));
			}

			var xmlMeta = dictionaryAdapter.GetXmlMeta();

			if (dictionaryAdapter.This.CreateStrategy == null)
			{
				dictionaryAdapter.This.CreateStrategy = this;
				dictionaryAdapter.This.AddCopyStrategy(this);
			}

			if (rootXmlMeta == null)
			{
				rootXmlMeta = xmlMeta;
				Context.ApplyBehaviors(rootXmlMeta, behaviors);

				if (Parent == null)
				{
					foreach (var behavior in behaviors)
					{
						if (behavior is XPathAttribute)
						{
							var attrib = (XPathAttribute)behavior;
							var compiledExpression = attrib.CompiledExpression;
							if (MoveOffRoot(root, XPathNodeType.Element) == false || Context.Matches(compiledExpression, root))
							{
								break;
							}

							var navigator = Context.SelectSingleNode(compiledExpression, root);
							if (navigator != null)
							{
								root = navigator;
								break;
							}
						}
					}
					MoveOffRoot(root, XPathNodeType.Element);
				}
			}
			else
			{
				if (overlays == null)
					overlays = new Dictionary<Type, XPathContext>();

				XPathContext overlay;
				if (overlays.TryGetValue(meta.Type, out overlay) == false)
				{
					overlay = new XPathContext().ApplyBehaviors(xmlMeta, behaviors);
					overlays.Add(meta.Type, overlay);
				}
			}
		}
		public XPathContext CreateChild(XmlMetadata xmlMeta, params object[] behaviors)
		{
			return CreateChild(xmlMeta, (IEnumerable)behaviors);
		}
		public XPathContext CreateChild(XmlMetadata xmlMeta, IEnumerable behaviors)
		{
			return new XPathContext(this).ApplyBehaviors(xmlMeta, behaviors);
		}
		public XPathContext ApplyBehaviors(XmlMetadata xmlMeta, IEnumerable behaviors)
		{
			if (xmlMeta != null)
			{
				this.xmlMeta = xmlMeta;
				if (string.IsNullOrEmpty(xmlMeta.XmlType.Namespace) == false)
				{
					if (xmlMeta.Qualified.GetValueOrDefault(false))
					{
						AddNamespace(xmlMeta.XmlType.Namespace);
						qualifiedNamespace = xmlMeta.XmlType.Namespace;
					}
					else
					{
						AddNamespace(string.Empty, xmlMeta.XmlType.Namespace);
					}
				}
			}

			new BehaviorVisitor()
				.OfType<XmlNamespaceAttribute>(attrib =>
				{
					AddNamespace(attrib.Prefix, attrib.NamespaceUri);
					if (attrib.Default)
					{
						AddNamespace(string.Empty, attrib.NamespaceUri);
					}
				})
				.OfType<XmlArrayItemAttribute>(attrib =>
				{
					ListItemMeta = ListItemMeta ?? new List<XmlArrayItemAttribute>();
					((List<XmlArrayItemAttribute>)ListItemMeta).Add(attrib);
				})
				.OfType<XPathFunctionAttribute>(attrib => AddFunction(attrib.Prefix, attrib.Name, attrib.Function))
				.OfType<IXPathSerializer>(attrib => AddSerializer(attrib))
				.Apply(behaviors);
			return this;
		}
Exemple #8
0
 internal static void SetXmlMeta(this DictionaryAdapterMeta dictionaryAdapterMeta, XmlMetadata xmlMeta)
 {
     dictionaryAdapterMeta.ExtendedProperties[XmlMetaKey] = xmlMeta;
 }
Exemple #9
0
 public XPathContext CreateChild(XmlMetadata xmlMeta, params object[] behaviors)
 {
     return(CreateChild(xmlMeta, (IEnumerable)behaviors));
 }
Exemple #10
0
 public XPathContext CreateChild(XmlMetadata xmlMeta, IEnumerable behaviors)
 {
     return(new XPathContext(this).ApplyBehaviors(xmlMeta, behaviors));
 }
		internal static void SetXmlMeta(this DictionaryAdapterMeta dictionaryAdapterMeta, XmlMetadata xmlMeta)
		{
			dictionaryAdapterMeta.ExtendedProperties[XmlMetaKey] = xmlMeta;
		}
Exemple #12
0
        void IDictionaryInitializer.Initialize(IDictionaryAdapter dictionaryAdapter, object[] behaviors)
        {
            var meta = dictionaryAdapter.Meta;

            if (meta.MetaInitializers.OfType <XPathBehavior>().FirstOrDefault() == null)
            {
                throw new InvalidOperationException(string.Format(
                                                        "Interface {0} requested xpath support, but was not configured properly.  " +
                                                        "Did you forget to add an XPathBehavior?", meta.Type.FullName));
            }

            var xmlMeta = dictionaryAdapter.GetXmlMeta();

            if (dictionaryAdapter.This.CreateStrategy == null)
            {
                dictionaryAdapter.This.CreateStrategy = this;
                dictionaryAdapter.This.AddCopyStrategy(this);
            }

            if (rootXmlMeta == null)
            {
                rootXmlMeta = xmlMeta;
                Context.ApplyBehaviors(rootXmlMeta, behaviors);

                if (Parent == null)
                {
                    foreach (var behavior in behaviors)
                    {
                        if (behavior is XPathAttribute)
                        {
                            var attrib             = (XPathAttribute)behavior;
                            var compiledExpression = attrib.CompiledExpression;
                            if (MoveOffRoot(root, XPathNodeType.Element) == false || Context.Matches(compiledExpression, root))
                            {
                                break;
                            }

                            var navigator = Context.SelectSingleNode(compiledExpression, root);
                            if (navigator != null)
                            {
                                root = navigator;
                                break;
                            }
                        }
                    }
                    MoveOffRoot(root, XPathNodeType.Element);
                }
            }
            else
            {
                if (overlays == null)
                {
                    overlays = new Dictionary <Type, XPathContext>();
                }

                XPathContext overlay;
                if (overlays.TryGetValue(meta.Type, out overlay) == false)
                {
                    overlay = new XPathContext().ApplyBehaviors(xmlMeta, behaviors);
                    overlays.Add(meta.Type, overlay);
                }
            }
        }