Пример #1
0
        private object[] Compile(string obj0)
        {
            if (_path == null)
            {
                return(new object[0]);
            }

            var list = new List <object>();
            var tok  = new StringTokenizer(_path, ":.");

            while (tok.hasMoreTokens())
            {
                string token = tok.nextToken();
                OpEnum op    = OpEnum.GetInstance(token);
                if (op == null)
                {
                    throw new Error("Bad path compiled " + _path);
                }

                list.Add(op);

                if (op == OpEnum.Relation)
                {
                    list.Add(tok.nextToken());
                }
            }
            return(list.ToArray());
        }
Пример #2
0
        public virtual Item FindItem(Item item)
        {
            if (InterpretPaths)
            {
                return(item.FindItem(_path));
            }

            if (_compiledPath == null)
            {
                _compiledPath = Compile(_path);
            }

            Item pitem = item;

            for (int i = 0; pitem != null && i < _compiledPath.Length;)
            {
                OpEnum op = (OpEnum)_compiledPath[i++];
                if (op == OpEnum.Next)
                {
                    pitem = pitem.GetNext();
                }
                else if (op == OpEnum.Prev)
                {
                    pitem = pitem.GetPrevious();
                }
                else if (op == OpEnum.NextNext)
                {
                    pitem = pitem.GetNext();
                    if (pitem != null)
                    {
                        pitem = pitem.GetNext();
                    }
                }
                else if (op == OpEnum.PrevPrev)
                {
                    pitem = pitem.GetPrevious();
                    if (pitem != null)
                    {
                        pitem = pitem.GetPrevious();
                    }
                }
                else if (op == OpEnum.Parent)
                {
                    pitem = pitem.GetParent();
                }
                else if (op == OpEnum.Daughter)
                {
                    pitem = pitem.Daughter;
                }
                else if (op == OpEnum.LastDaughter)
                {
                    pitem = pitem.GetLastDaughter();
                }
                else if (op == OpEnum.Relation)
                {
                    string relationName = (string)_compiledPath[i++];
                    pitem =
                        pitem.SharedContents
                        .GetItemRelation(relationName);
                }
                else
                {
                    this.LogInfo("findItem: bad feature " + op + " in "
                                 + _path);
                }
            }
            return(pitem);
        }