protected PeachXPathNavigator(Dom dom, object currentNode, PeachXPathNodeType currentNodeType, int attributeIndex, bool iteratingAttributes) { this.dom = dom; this.currentNode = currentNode; this.currentNodeType = currentNodeType; this.attributeIndex = attributeIndex; this.iteratingAttributes = iteratingAttributes; }
public override bool MoveToParent() { logger.Trace("MoveToParent(" + currentNode.GetType() + ":" + ((INamed)currentNode).name + ")"); if (iteratingAttributes) { iteratingAttributes = false; return(true); } if (currentNodeType == PeachXPathNodeType.Root) { return(false); } dynamic obj = currentNode; // DataModel drives from Block, so if our parent is a DataElementContainer we are all good if (obj is DataModel && !(obj.parent is DataElementContainer)) { if (obj.dom != null) { currentNode = obj.dom; } else if (obj.action != null) { currentNode = obj.action; } else { throw new Exception("Error, data model with no dom/action parent!"); } } else if (obj is StateModel) { // state models have a parent of the dom, but we need to walk // back up to the test since that is how we descend Dom root = obj.parent as Dom; currentNode = root.tests[testIndex]; } else { currentNode = obj.parent; } currentNodeType = MapObjectToNodeType(currentNode); return(true); }
public override bool MoveTo(XPathNavigator other) { logger.Trace("MoveTo"); var otherXpath = other as PeachXPathNavigator; if (otherXpath == null) { return(false); } this.dom = otherXpath.dom; this.currentNode = otherXpath.currentNode; this.currentNodeType = otherXpath.currentNodeType; this.attributeIndex = otherXpath.attributeIndex; return(true); }
public override bool MoveToNext() { logger.Trace("MoveToNext(" + ((INamed)currentNode).name + ")"); if (currentNodeType == PeachXPathNodeType.Root) { return(false); } dynamic obj = currentNode; object parent = obj.parent; if (parent == null) { if (currentNode is DataModel) { if (obj.dom != null) { parent = obj.dom; } else if (obj.action != null) { parent = obj.action; } } if (parent == null) { throw new Exception("Error, parent was unexpectedly null for object '" + obj.name + "' of type " + currentNode.GetType().ToString() + "."); } } // DataModel drives from Block, so if our parent is a DataElementContainer we are all good if (currentNode is DataModel && !(parent is DataElementContainer)) { var action = parent as Action; if (action == null) { throw new Exception("Error, data model has weird parent!"); } if (action.dataModel == currentNode) { if (action.parameters.Count == 0) { return(false); } currentNode = action.parameters[0].dataModel; currentNodeType = PeachXPathNodeType.DataModel; return(true); } int idx = action.parameters.FindIndex(a => a.dataModel == currentNode); if (idx == -1) { throw new Exception("Error, data model missing from action parameters!"); } if (++idx >= action.parameters.Count) { return(false); } currentNode = action.parameters[idx].dataModel; currentNodeType = PeachXPathNodeType.DataModel; return(true); } else if (currentNode is DataElement) { if (parent is DataElementContainer) { var curr = currentNode as DataElement; var block = parent as DataElementContainer; int index = block.IndexOf(curr); for (int i = index + 1; i < block.Count; ++i) { var elem = block[i]; if (elem != curr) { currentNode = elem; return(true); } } return(false); } return(false); } else if (currentNode is StateModel) { return(false); } else if (currentNode is State) { var stateModel = parent as StateModel; int index = 0; for (int cnt = 0; cnt < stateModel.states.Values.Count; cnt++) { if (stateModel.states.Values.ElementAt(cnt) == currentNode) { index = cnt; break; } } if (stateModel.states.Values.Count <= (index + 1)) { return(false); } currentNode = stateModel.states.Values.ElementAt(index + 1); return(true); } else if (currentNode is Action) { var state = parent as State; int index = state.actions.IndexOf((Action)currentNode); if (state.actions.Count <= (index + 1)) { return(false); } currentNode = state.actions[index + 1]; return(true); } else if (currentNode is Test) { var dom = parent as Dom; int index = dom.tests.IndexOfKey(((INamed)currentNode).name); if (dom.tests.Count <= (index + 1)) { return(false); } currentNode = dom.tests[index + 1]; testIndex = index + 1; return(true); } throw new ArgumentException("Error, unknown type"); }
public override bool MoveToFirstChild() { logger.Trace("MoveToFirstChild(" + ((INamed)currentNode).name + ")"); if (currentNode is DataElementContainer) { var container = currentNode as DataElementContainer; if (container.Count == 0) { return(false); } currentNode = container[0]; return(true); } else if (currentNode is DataElement) { return(false); } else if (currentNode is Dom) { var dom = currentNode as Dom; if (dom.tests.Count > 0) { testIndex = 0; currentNode = dom.tests[0]; currentNodeType = PeachXPathNodeType.Test; return(true); } return(false); } else if (currentNode is StateModel) { var stateModel = currentNode as StateModel; if (stateModel.states.Count == 0) { return(false); } currentNode = stateModel.states.Values.First(); return(true); } else if (currentNode is State) { var state = currentNode as State; if (state.actions.Count == 0) { return(false); } currentNode = state.actions[0]; return(true); } else if (currentNode is Action) { var action = currentNode as Action; if (action.dataModel != null) { currentNode = action.dataModel; currentNodeType = PeachXPathNodeType.DataModel; return(true); } if (action.parameters.Count == 0) { return(false); } currentNode = action.parameters[0].dataModel; currentNodeType = PeachXPathNodeType.DataModel; return(true); } else if (currentNode is Test) { var test = currentNode as Test; if (test.stateModel == null) { return(false); } currentNode = test.stateModel; currentNodeType = PeachXPathNodeType.StateModel; return(true); } throw new ArgumentException("Error, unknown type"); }
public PeachXPathNavigator(Dom dom) { currentNode = dom; currentNodeType = PeachXPathNodeType.Root; }