Beispiel #1
0
        public void GetCollectionItems(
            IXmlNode parentNode,
            IDictionaryAdapter parentObject,
            XmlReferenceManager references,
            IList values
            )
        {
            var cursor = SelectCollectionItems(parentNode, false);

            while (cursor.MoveNext())
            {
                object value;

                if (IsReference)
                {
                    IXmlNode node = cursor;
                    value = null;
                    object token;

                    if (references.OnGetStarting(ref node, ref value, out token))
                    {
                        value = serializer.GetValue(node, parentObject, this);
                        references.OnGetCompleted(node, value, token);
                    }
                }
                else
                {
                    value = serializer.GetValue(cursor, parentObject, this);
                }
                values.Add(value);
            }
        }
Beispiel #2
0
        public void UnionWith(XmlReferenceManager other)
        {
            var visited = null as HashSet <Entry>;

            foreach (var otherEntry in other.entriesByValue)
            {
                Entry thisEntry;
                if (entriesByValue.TryGetValue(otherEntry.Key, out thisEntry))
                {
                    if (visited == null)
                    {
                        visited = new HashSet <Entry>(ReferenceEqualityComparer <Entry> .Instance);
                    }
                    else if (visited.Contains(thisEntry))
                    {
                        continue;
                    }
                    visited.Add(thisEntry);

                    foreach (var otherValue in otherEntry.Value.Values)
                    {
                        var otherTarget = otherValue.Value.Target;
                        if (otherTarget == null ||
                            otherTarget == otherEntry.Key ||
                            entriesByValue.ContainsKey(otherTarget))
                        {
                            continue;
                        }
                        AddValueCore(thisEntry, otherValue.Type, otherTarget, false);
                    }
                }
            }
        }
Beispiel #3
0
        public object GetValue(
            IXmlNode node,
            IDictionaryAdapter parentObject,
            XmlReferenceManager references,
            bool nodeExists,
            bool orStub
            )
        {
            object value;

            if ((nodeExists || orStub) && IsReference)
            {
                value = null;
                object token;

                if (references.OnGetStarting(ref node, ref value, out token))
                {
                    value = GetValueCore(node, parentObject, nodeExists, orStub);
                    references.OnGetCompleted(node, value, token);
                }
            }
            else
            {
                value = GetValueCore(node, parentObject, nodeExists, orStub);
            }
            return(value);
        }
Beispiel #4
0
        protected void RemoveCollectionItems(IXmlNode parentNode, XmlReferenceManager references, object value)
        {
            var collection = value as ICollectionProjection;

            if (collection != null)
            {
                collection.Clear();
                return;
            }

            var itemType    = clrType.GetCollectionItemType();
            var accessor    = GetCollectionAccessor(itemType);
            var cursor      = accessor.SelectCollectionItems(parentNode, true);
            var isReference = IsReference;

            var items = value as IEnumerable;

            if (items != null)
            {
                foreach (var item in items)
                {
                    if (!cursor.MoveNext())
                    {
                        break;
                    }
                    if (isReference)
                    {
                        references.OnAssigningNull(cursor, item);
                    }
                }
            }

            cursor.Reset();
            cursor.RemoveAllNext();
        }
Beispiel #5
0
 public override object GetPropertyValue(
     IXmlNode parentNode,
     IDictionaryAdapter parentObject,
     XmlReferenceManager references,
     bool orStub
     )
 {
     return(GetPropertyValueCore(parentNode, parentObject, references, orStub)
            ?? GetDefaultPropertyValue(parentNode, parentObject, references, orStub));
 }
Beispiel #6
0
 private object GetDefaultPropertyValue(
     IXmlNode parentNode,
     IDictionaryAdapter parentObject,
     XmlReferenceManager references,
     bool orStub
     )
 {
     return(defaultAccessor != null
       ? defaultAccessor.GetPropertyValue(parentNode, parentObject, references, orStub)
       : null);
 }
Beispiel #7
0
 private object GetPropertyValueCore(
     IXmlNode parentNode,
     IDictionaryAdapter parentObject,
     XmlReferenceManager references,
     bool orStub
     )
 {
     return(SelectsNodes
       ? base.GetPropertyValue(parentNode, parentObject, references, orStub)
       : Evaluate(parentNode));
 }
Beispiel #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlAdapter"/> class
        /// that represents a child object in a larger object graph.
        /// </summary>
        public XmlAdapter(IXmlNode node, XmlReferenceManager references)
        {
            if (node == null)
            {
                throw Error.ArgumentNull("node");
            }
            if (references == null)
            {
                throw Error.ArgumentNull("references");
            }

            this.node       = node;
            this.references = references;
        }
Beispiel #9
0
        public virtual void SetPropertyValue(
            IXmlNode parentNode,
            IDictionaryAdapter parentObject,
            XmlReferenceManager references,
            object oldValue,
            ref object value
            )
        {
            var cursor = IsCollection
                ? SelectCollectionNode(parentNode, true)
                : SelectPropertyNode(parentNode, true);

            SetValue(cursor, parentObject, references, cursor.MoveNext(), oldValue, ref value);
        }
Beispiel #10
0
 public override void SetPropertyValue(
     IXmlNode parentNode,
     IDictionaryAdapter parentObject,
     XmlReferenceManager references,
     object oldValue,
     ref object value
     )
 {
     if (SelectsNodes)
     {
         base.SetPropertyValue(parentNode, parentObject, references, oldValue, ref value);
     }
     else
     {
         throw Error.XPathNotCreatable(path);
     }
 }
Beispiel #11
0
        public virtual object GetPropertyValue(
            IXmlNode parentNode,
            IDictionaryAdapter parentObject,
            XmlReferenceManager references,
            bool orStub
            )
        {
            if (orStub)
            {
                orStub &= serializer.CanGetStub;
            }

            var cursor = IsCollection
                ? SelectCollectionNode(parentNode, orStub)
                : SelectPropertyNode(parentNode, orStub);

            return(GetValue(cursor, parentObject, references, cursor.MoveNext(), orStub));
        }
 public override void SetValue(
     IXmlCursor cursor,
     IDictionaryAdapter parentObject,
     XmlReferenceManager references,
     bool hasCurrent,
     object oldValue,
     ref object newValue
     )
 {
     if (newValue == null && IsCollection)
     {
         base.RemoveCollectionItems(cursor, references, oldValue);
     }
     else
     {
         base.SetValue(cursor, parentObject, references, hasCurrent, oldValue, ref newValue);
     }
 }
Beispiel #13
0
        public XmlCollectionAdapter(
            IXmlNode parentNode,
            IDictionaryAdapter parentObject,
            IXmlCollectionAccessor accessor)
        {
            items = new List <XmlCollectionItem <T> >();

            this.accessor     = accessor;
            this.cursor       = accessor.SelectCollectionItems(parentNode, true);
            this.parentNode   = parentNode;
            this.parentObject = parentObject;
            this.references   = XmlAdapter.For(parentObject).References;

            while (cursor.MoveNext())
            {
                items.Add(new XmlCollectionItem <T>(cursor.Save()));
            }
        }
Beispiel #14
0
        private void InitializePrimary(DictionaryAdapterMeta meta, IDictionaryAdapter dictionaryAdapter)
        {
            RequireXmlMeta(meta);
            primaryXmlMeta = meta.GetXmlMeta();

            if (node == null)
            {
                node = GetBaseNode();
            }
            if (!node.IsReal)
            {
                node.Realized += HandleNodeRealized;
            }

            if (references == null)
            {
                references = new XmlReferenceManager(node, DefaultXmlReferenceFormat.Instance);
            }
            InitializeReference(this);
        }
Beispiel #15
0
        public void UnionWith(XmlReferenceManager other)
        {
            var visited = null as HashSet <Entry>;

            foreach (var keyValue in other.entriesByValue.Keys)
            {
                Entry thisEntry;
                if (entriesByValue.TryGetValue(keyValue, out thisEntry))
                {
                    if (visited == null)
                    {
                        visited = new HashSet <Entry>(ReferenceEqualityComparer <Entry> .Instance);
                    }
                    else if (visited.Contains(thisEntry))
                    {
                        continue;
                    }
                    visited.Add(thisEntry);

                    var otherEntry = other.entriesByValue[keyValue];

                    foreach (var otherItem in otherEntry.Values)
                    {
                        if (otherItem.Value == keyValue)
                        {
                            continue;
                        }
                        if (entriesByValue.ContainsKey(otherItem.Value))
                        {
                            continue;
                        }
                        AddValueCore(thisEntry, otherItem.Type, otherItem.Value, false);
                    }
                }
            }
        }
Beispiel #16
0
		public virtual object GetPropertyValue(IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references, bool orStub)
		{
			if (orStub) orStub &= serializer.CanGetStub;

			var cursor = IsCollection
				? SelectCollectionNode(parentNode, orStub)
				: SelectPropertyNode  (parentNode, orStub);

			return GetValue(cursor, parentObject, references, cursor.MoveNext(), orStub);
		}
Beispiel #17
0
		public void UnionWith(XmlReferenceManager other)
		{
			var visited = null as HashSet<Entry>;

			foreach (var otherEntry in other.entriesByValue)
			{
				Entry thisEntry;
				if (entriesByValue.TryGetValue(otherEntry.Key, out thisEntry))
				{
					if (visited == null)
						visited = new HashSet<Entry>(ReferenceEqualityComparer<Entry>.Instance);
					else if (visited.Contains(thisEntry))
						continue;
					visited.Add(thisEntry);

					foreach (var otherValue in otherEntry.Value.Values)
					{
						var otherTarget = otherValue.Value.Target;
						if (otherTarget == null           ||
							otherTarget == otherEntry.Key ||
							entriesByValue.ContainsKey(otherTarget))
							{ continue; }
						AddValueCore(thisEntry, otherValue.Type, otherTarget, false);
					}
				}
			}
		}
Beispiel #18
0
        public virtual void SetValue(IXmlCursor cursor, IDictionaryAdapter parentObject, XmlReferenceManager references,
                                     bool hasCurrent, object oldValue, ref object newValue)
        {
            var hasValue    = null != newValue;
            var isNillable  = this.IsNillable;
            var isReference = this.IsReference;

            var clrType = hasValue
                                ? newValue.GetComponentType()
                                : this.clrType;

            if (hasValue || isNillable)
            {
                if (hasCurrent)
                {
                    Coerce(cursor, clrType, !hasValue && cursor.IsAttribute);                     // TODO: Refactor. (NB: && isNillable is emplied)
                }
                else
                {
                    cursor.Create(clrType);
                }
            }
            else if (!hasCurrent)
            {
                // No node exists + no value to assign + and not nillable = no work to do
                return;
            }

            object token = null;

            if (isReference)
            {
                if (!references.OnAssigningValue(cursor, oldValue, ref newValue, out token))
                {
                    return;
                }
            }

            var givenValue = newValue;

            if (hasValue)
            {
                serializer.SetValue(cursor, parentObject, this, oldValue, ref newValue);
            }
            else if (isNillable)
            {
                cursor.IsNil = true;
            }
            else
            {
                cursor.Remove(); cursor.RemoveAllNext();
            }

            if (isReference)
            {
                references.OnAssignedValue(cursor, givenValue, newValue, token);
            }
        }
			public void SetUp()
			{
				OriginalXml = GetXmlText();
				Document    = Xml(OriginalXml);
				OriginalXml = Document.OuterXml;
				Namespaces  = new XmlContextBase();
				Node        = new SysXmlNode(Document.DocumentElement, typeof(object), Namespaces);
				Manager     = new XmlReferenceManager(Node, DefaultXmlReferenceFormat.Instance);
			}
Beispiel #20
0
		protected void RemoveCollectionItems(IXmlNode parentNode, XmlReferenceManager references, object value)
		{
			var collection = value as ICollectionProjection;
			if (collection != null)
			{
				collection.Clear();
				return;
			}

			var itemType    = clrType.GetCollectionItemType();
			var accessor    = GetCollectionAccessor(itemType);
			var cursor      = accessor.SelectCollectionItems(parentNode, true);
			var isReference = IsReference;

			var items = value as IEnumerable;
			if (items != null)
			{
				foreach (var item in items)
				{
					if (!cursor.MoveNext())
						break;
					if (isReference)
						references.OnAssigningNull(cursor, item);
				}
			}

			cursor.Reset();
			cursor.RemoveAllNext();
		}
Beispiel #21
0
		public void GetCollectionItems(IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references, IList values)
		{
			var cursor = SelectCollectionItems(parentNode, false);

			while (cursor.MoveNext())
			{
				object value;

				if (IsReference)
				{
					IXmlNode node = cursor;
					value = null;
					object token;

					if (references.OnGetStarting(ref node, ref value, out token))
					{
						value = serializer.GetValue(node, parentObject, this);
						references.OnGetCompleted(node, value, token);
					}
				}
				else
				{
					value = serializer.GetValue(cursor, parentObject, this);
				}
				values.Add(value);
			}
		}
Beispiel #22
0
		public virtual void SetValue(IXmlCursor cursor, IDictionaryAdapter parentObject, XmlReferenceManager references,
			bool hasCurrent, object oldValue, ref object newValue)
		{
			var hasValue    = null != newValue;
			var isNillable  = this.IsNillable;
			var isReference = this.IsReference;

			var clrType = hasValue
				? newValue.GetComponentType()
				: this.clrType;

			if (hasValue || isNillable)
			{
				if (hasCurrent)
					Coerce(cursor, clrType, !hasValue && cursor.IsAttribute); // TODO: Refactor. (NB: && isNillable is emplied)
				else
					cursor.Create(clrType);
			}
			else if (!hasCurrent)
			{
				// No node exists + no value to assign + and not nillable = no work to do
				return;
			}

			object token = null;
			if (isReference)
				if (!references.OnAssigningValue(cursor, oldValue, ref newValue, out token))
					return;

			var givenValue = newValue;

			if (hasValue)
				serializer.SetValue(cursor, parentObject, this, oldValue, ref newValue);
			else if (isNillable)
				cursor.IsNil = true;
			else
				{ cursor.Remove(); cursor.RemoveAllNext(); }

			if (isReference)
				references.OnAssignedValue(cursor, givenValue, newValue, token);
		}
Beispiel #23
0
		public virtual void SetPropertyValue(IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references,
			object oldValue, ref object value)
		{
			var cursor = IsCollection
				? SelectCollectionNode(parentNode, true)
				: SelectPropertyNode  (parentNode, true);
				
			SetValue(cursor, parentObject, references, cursor.MoveNext(), oldValue, ref value);
		}
Beispiel #24
0
		public object GetValue(IXmlNode node, IDictionaryAdapter parentObject, XmlReferenceManager references, bool nodeExists, bool orStub)
		{
			object value;

			if ((nodeExists || orStub) && IsReference)
			{
				value = null;
				object token;

				if (references.OnGetStarting(ref node, ref value, out token))
				{
					value = GetValueCore(node, parentObject, nodeExists, orStub);
					references.OnGetCompleted(node, value, token);
				}
			}
			else
			{
				value = GetValueCore(node, parentObject, nodeExists, orStub);
			}
			return value;
		}
Beispiel #25
0
		public void UnionWith(XmlReferenceManager other)
		{
			var visited = null as HashSet<Entry>;

			foreach (var keyValue in other.entriesByValue.Keys)
			{
				Entry thisEntry;
				if (entriesByValue.TryGetValue(keyValue, out thisEntry))
				{
					if (visited == null)
						visited = new HashSet<Entry>(ReferenceEqualityComparer<Entry>.Instance);
					else if (visited.Contains(thisEntry))
						continue;
					visited.Add(thisEntry);

				    var otherEntry = other.entriesByValue[keyValue];

					foreach (var otherItem in otherEntry.Values)
					{
						if (otherItem.Value == keyValue)
							continue;
						if (entriesByValue.ContainsKey(otherItem.Value))
							continue;
						AddValueCore(thisEntry, otherItem.Type, otherItem.Value, false);
					}
				}
			}
		}