Esempio n. 1
0
        public override bool GetOptimized(out Path optimizedPath)
        {
            if (Steps.Count > 1 &&
                (Steps[0].NodeTest != Step.NODE_TEST_ANY_NODE) &&
                (from psmClass in Schema.PSMClasses where psmClass.IsStructuralRepresentative select psmClass.RepresentedClass).All(rep => rep.Schema == Schema) &&
                Steps.Take(Steps.Count - 1).All(s => s.Axis.IsAmong(Axis.child, Axis.descendant, Axis.descendantOrSelf)))
            {
                Step lastStep = Steps.Last();
                if (!string.IsNullOrEmpty(lastStep.NodeTest) &&
                    lastStep.NodeTest != Step.NODE_TEST_ANY_NODE &&
                    Schema.GetAllXMLElementNames()[lastStep.NodeTest] == 1 &&
                    lastStep.Axis.IsAmong(Axis.child, Axis.descendant, Axis.descendantOrSelf, Axis.attribute)
                    )
                {
                    SimplePath simplePath = new SimplePath(Schema);
                    simplePath.AddStep(new Step {
                        Axis = Axis.descendantOrSelf, NodeTest = Step.NODE_TEST_ANY_NODE
                    });
                    simplePath.AddStep(new Step {
                        Axis = lastStep.Axis != Axis.attribute ? Axis.child : Axis.attribute, NodeTest = lastStep.NodeTest
                    });
                    optimizedPath = simplePath;
                    return(true);
                }
            }

            optimizedPath = this;
            return(false);
        }
Esempio n. 2
0
        private Path JoinInSteps(UnionPath optimizedComponents)
        {
            SimplePath joined = new SimplePath(Schema);

            for (int i = 0; i < ((SimplePath)optimizedComponents.ComponentPaths.First()).Steps.Count; i++)
            {
                if (optimizedComponents.ComponentPaths.Select(path => ((SimplePath)path).Steps[i]).TransitiveTrue((s1, s2) => s1 == s2))
                {
                    // ale are equal, so take first one
                    Step imageStep = ((SimplePath)optimizedComponents.ComponentPaths.First()).Steps[i];
                    joined.AddStep(imageStep.DeepCopy());
                }
                else
                {
                    Step imageStep = ((SimplePath)optimizedComponents.ComponentPaths.First()).Steps[i];
                    // they must be joined
                    Step newStep = new Step()
                    {
                        Axis = Axis.descendant, NodeTest = imageStep.NodeTest
                    };
                    joined.AddStep(newStep);
                }
            }

            return(joined);
        }