[Adapdev-commits] Adapdev/src/Adapdev/XPath/Internal ObjectNavigationContext.cs,1.2,1.3 ObjectNaviga
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-11-16 05:33:39
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev/XPath/Internal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19977/src/Adapdev/XPath/Internal Added Files: ObjectNavigationContext.cs ObjectNavigatorState.cs ObjectNavigatorStateDictionary.cs ObjectNavigatorStateItem.cs ObjectNavigatorStateList.cs ObjectNavigatorStateRoot.cs Log Message: Reposting to the repository after it got hosed --- NEW FILE: ObjectNavigationContext.cs --- #region license // Bamboo.Prevalence - a .NET object prevalence engine // Copyright (C) 2004 Rodrigo B. de Oliveira // // Based on the original concept and implementation of Prevayler (TM) // by Klaus Wuestefeld. Visit http://www.prevayler.org for details. // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without restriction, // including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, // and to permit persons to whom the Software is furnished to do so, // subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // Contact Information // // http://bbooprevalence.sourceforge.net // mailto:rod...@us... #endregion using System; using System.Xml; namespace Adapdev.XPath.Internal { internal class ObjectNavigationContext { public NameTable NameTable; public TypeInfoCache TypeInfoCache; public ObjectNavigationContext() { NameTable = new NameTable(); TypeInfoCache = new TypeInfoCache(); } } } --- NEW FILE: ObjectNavigatorStateList.cs --- #region license // Bamboo.Prevalence - a .NET object prevalence engine // Copyright (C) 2004 Rodrigo B. de Oliveira // // Based on the original concept and implementation of Prevayler (TM) // by Klaus Wuestefeld. Visit http://www.prevayler.org for details. // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without restriction, // including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, // and to permit persons to whom the Software is furnished to do so, // subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // Contact Information // // http://bbooprevalence.sourceforge.net // mailto:rod...@us... #endregion using System; using System.Collections; using System.Xml; using System.Xml.XPath; namespace Adapdev.XPath.Internal { internal class ObjectNavigatorStateList : ObjectNavigatorState { IList _children; internal ObjectNavigatorStateList(ObjectNavigationContext context, ObjectNavigatorState parent, object node, string name) : base(context, parent, node, name) { _children = (IList)node; } internal override XPathNodeType NodeType { get { return XPathNodeType.Element; } } internal override ObjectNavigatorState MoveToFirstChild() { return MoveToChild(0); } internal override ObjectNavigatorState MoveToNext() { return _parent.MoveToChild(_index + 1); } internal override ObjectNavigatorState MoveToChild(int index) { while (index < _children.Count) { object child = _children[index]; if (null != child) { ObjectNavigatorState state = CreateElementState(_context, this, child, child.GetType().Name); state.Index = index; return state; } ++index; } return null; } } } --- NEW FILE: ObjectNavigatorStateRoot.cs --- #region license // Bamboo.Prevalence - a .NET object prevalence engine // Copyright (C) 2004 Rodrigo B. de Oliveira // // Based on the original concept and implementation of Prevayler (TM) // by Klaus Wuestefeld. Visit http://www.prevayler.org for details. // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without restriction, // including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, // and to permit persons to whom the Software is furnished to do so, // subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // Contact Information // // http://bbooprevalence.sourceforge.net // mailto:rod...@us... #endregion using System; using System.Xml; using System.Xml.XPath; namespace Adapdev.XPath.Internal { internal class ObjectNavigatorStateRoot : ObjectNavigatorState { ObjectNavigatorState _child; internal ObjectNavigatorStateRoot(ObjectNavigationContext context, object node, string nodeName) : base(context, null, node, "#document") { if (null == nodeName) { nodeName = _node.GetType().Name; } _child = CreateElementState(context, this, node, nodeName); } internal override ObjectNavigatorState MoveToFirstChild() { return _child; } internal override XPathNodeType NodeType { get { return XPathNodeType.Root; } } } } --- NEW FILE: ObjectNavigatorState.cs --- #region license // Bamboo.Prevalence - a .NET object prevalence engine // Copyright (C) 2004 Rodrigo B. de Oliveira // // Based on the original concept and implementation of Prevayler (TM) // by Klaus Wuestefeld. Visit http://www.prevayler.org for details. // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without restriction, // including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, // and to permit persons to whom the Software is furnished to do so, // subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // Contact Information // // http://bbooprevalence.sourceforge.net // mailto:rod...@us... #endregion using System; using System.Collections; using System.Xml; using System.Xml.XPath; namespace Adapdev.XPath.Internal { internal abstract class ObjectNavigatorState { protected int _index; protected string _name; protected ObjectNavigatorState _parent; protected object _node; protected ObjectNavigationContext _context; public ObjectNavigatorState(ObjectNavigationContext context, ObjectNavigatorState parent, object node, string name) { _parent = parent; _context = context; _node = node; _name = _context.NameTable.Add(name); _index = 0; } internal int Index { get { return _index; } set { _index = value; } } internal virtual bool IsSamePosition(ObjectNavigatorState other) { return other._node == _node && other._index == _index && other._name == _name && other._parent == _parent; } internal virtual string Name { get { return _name; } } internal virtual string Value { get { return _node.ToString(); } } internal ObjectNavigatorState Parent { get { return _parent; } } internal object Node { get { return _node; } } internal abstract XPathNodeType NodeType { get; } internal virtual ObjectNavigatorState MoveToFirstChild() { return null; } internal virtual ObjectNavigatorState MoveToNext() { return null; } internal virtual ObjectNavigatorState MoveToChild(int index) { return null; } internal static ObjectNavigatorState CreateElementState(ObjectNavigationContext context, ObjectNavigatorState parent, object node, string name) { if (node is IDictionary) { return new ObjectNavigatorStateDictionary(context, parent, node, name); } else if (node is IList) { return new ObjectNavigatorStateList(context, parent, node, name); } else { return new ObjectNavigatorStateItem(context, parent, node, name); } } } } --- NEW FILE: ObjectNavigatorStateDictionary.cs --- #region license // Bamboo.Prevalence - a .NET object prevalence engine // Copyright (C) 2004 Rodrigo B. de Oliveira // // Based on the original concept and implementation of Prevayler (TM) // by Klaus Wuestefeld. Visit http://www.prevayler.org for details. // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without restriction, // including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, // and to permit persons to whom the Software is furnished to do so, // subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // Contact Information // // http://bbooprevalence.sourceforge.net // mailto:rod...@us... #endregion using System; using System.Collections; using System.Xml; using System.Xml.XPath; namespace Adapdev.XPath.Internal { internal class ObjectNavigatorStateDictionary : ObjectNavigatorState { IDictionary _dictionary; IList _children; internal ObjectNavigatorStateDictionary(ObjectNavigationContext context, ObjectNavigatorState parent, object node, string name) : base(context, parent, node, name) { _dictionary = (IDictionary)node; _children = new ArrayList(_dictionary.Keys); } internal override XPathNodeType NodeType { get { return XPathNodeType.Element; } } internal override ObjectNavigatorState MoveToFirstChild() { return MoveToChild(0); } internal override ObjectNavigatorState MoveToNext() { return _parent.MoveToChild(_index + 1); } internal override ObjectNavigatorState MoveToChild(int index) { while (index < _children.Count) { object key = _children[index]; object child = _dictionary[key]; if (null != child) { ObjectNavigatorState state = CreateElementState(_context, this, child, key.ToString()); state.Index = index; return state; } ++index; } return null; } } } --- NEW FILE: ObjectNavigatorStateItem.cs --- #region license // Bamboo.Prevalence - a .NET object prevalence engine // Copyright (C) 2004 Rodrigo B. de Oliveira // // Based on the original concept and implementation of Prevayler (TM) // by Klaus Wuestefeld. Visit http://www.prevayler.org for details. // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without restriction, // including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, // and to permit persons to whom the Software is furnished to do so, // subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // Contact Information // // http://bbooprevalence.sourceforge.net // mailto:rod...@us... #endregion using System; using System.Xml; using System.Xml.XPath; using System.Reflection; namespace Adapdev.XPath.Internal { internal class ObjectNavigatorStateItem : ObjectNavigatorState { IValueProvider[] _children; internal ObjectNavigatorStateItem(ObjectNavigationContext context, ObjectNavigatorState parent, object node, string name) : base(context, parent, node, name) { } internal override XPathNodeType NodeType { get { return XPathNodeType.Element; } } internal override ObjectNavigatorState MoveToFirstChild() { return MoveToChild(0); } internal override ObjectNavigatorState MoveToNext() { return _parent.MoveToChild(_index + 1); } internal override ObjectNavigatorState MoveToChild(int index) { CheckChildren(); while (index < _children.Length) { object child = _children[index].GetValue(_node); if (null != child) { ObjectNavigatorState state = CreateElementState(_context, this, child, _children[index].Name); state.Index = index; return state; } ++index; } return null; } void CheckChildren() { if (null != _children) { return; } _children = _context.TypeInfoCache.GetNavigableProperties(_node); } } } |