Example #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);
            }
        }
Example #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);
			}
		}
Example #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);
        }
Example #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);
				}
			}
		}
Example #5
0
		public XPathContext CreateChild(XmlMetadata xmlMeta, params object[] behaviors)
		{
			return CreateChild(xmlMeta, (IEnumerable)behaviors);
		}
Example #6
0
		public XPathContext CreateChild(XmlMetadata xmlMeta, IEnumerable behaviors)
		{
			return new XPathContext(this).ApplyBehaviors(xmlMeta, behaviors);
		}
Example #7
0
		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;
		}
Example #8
0
 internal static void SetXmlMeta(this DictionaryAdapterMeta dictionaryAdapterMeta, XmlMetadata xmlMeta)
 {
     dictionaryAdapterMeta.ExtendedProperties[XmlMetaKey] = xmlMeta;
 }
Example #9
0
 public XPathContext CreateChild(XmlMetadata xmlMeta, params object[] behaviors)
 {
     return(CreateChild(xmlMeta, (IEnumerable)behaviors));
 }
Example #10
0
 public XPathContext CreateChild(XmlMetadata xmlMeta, IEnumerable behaviors)
 {
     return(new XPathContext(this).ApplyBehaviors(xmlMeta, behaviors));
 }
Example #11
0
		internal static void SetXmlMeta(this DictionaryAdapterMeta dictionaryAdapterMeta, XmlMetadata xmlMeta)
		{
			dictionaryAdapterMeta.ExtendedProperties[XmlMetaKey] = xmlMeta;
		}
Example #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);
                }
            }
        }