XPathNodeView FillRow(XPathNode ndRow, Shape shape) { object[] columns; XPathNode nd; switch (shape.BindingType) { case BindingType.Text: case BindingType.Attribute: columns = new object[1]; columns[0] = ndRow; return(new XPathNodeView(this, ndRow, columns)); case BindingType.Repeat: columns = new object[1]; nd = TreeNavigationHelper.GetContentChild(ndRow); columns[0] = FillColumn(new ContentIterator(nd, shape), shape); return(new XPathNodeView(this, ndRow, columns)); case BindingType.Sequence: case BindingType.Choice: case BindingType.All: int subShapesCount = shape.SubShapes.Count; columns = new object[subShapesCount]; if (shape.BindingType == BindingType.Sequence && shape.SubShape(0).BindingType == BindingType.Attribute) { FillAttributes(ndRow, shape, columns); } Shape lastSubShape = (Shape)shape.SubShapes[subShapesCount - 1]; if (lastSubShape.BindingType == BindingType.Text) //Attributes followed by simpe content or mixed content { columns[subShapesCount - 1] = ndRow; return(new XPathNodeView(this, ndRow, columns)); } else { nd = TreeNavigationHelper.GetContentChild(ndRow); return(FillSubRow(new ContentIterator(nd, shape), shape, columns)); } default: // should not map to a row #if DEBUG throw new NotSupportedException("Unable to bind row to: " + shape.BindingType.ToString()); #else throw new NotSupportedException(); #endif } }
void FillAttributes(XPathNode nd, Shape shape, object[] cols) { int i = 0; while (i < cols.Length) { Shape attrShape = shape.SubShape(i); if (attrShape.BindingType != BindingType.Attribute) { break; } XmlQualifiedName name = attrShape.AttributeName; XPathNode ndAttr = nd.GetAttribute(name.Name, name.Namespace); if (null != ndAttr) { cols[i] = ndAttr; } i++; } }
XPathNodeView FillSubRow(ContentIterator iter, Shape shape, object[] columns) { if (null == columns) { int colCount = shape.SubShapes.Count; if (0 == colCount) { colCount = 1; } columns = new object[colCount]; } switch (shape.BindingType) { case BindingType.Element: columns[0] = FillColumn(iter, shape); break; case BindingType.Sequence: { int iPrev = -1; int i; while (null != iter.Node) { i = shape.FindMatchingSubShape(iter.Particle); if (i <= iPrev) { break; } columns[i] = FillColumn(iter, shape.SubShape(i)); iPrev = i; } break; } case BindingType.All: { while (null != iter.Node) { int i = shape.FindMatchingSubShape(iter.Particle); if (-1 == i || null != columns[i]) { break; } columns[i] = FillColumn(iter, shape.SubShape(i)); } break; } case BindingType.Choice: { int i = shape.FindMatchingSubShape(iter.Particle); if (-1 != i) { columns[i] = FillColumn(iter, shape.SubShape(i)); } break; } case BindingType.Repeat: default: // should not map to a row throw new NotSupportedException(); } return(new XPathNodeView(this, null, columns)); }
object FillColumn(ContentIterator iter, Shape shape) { object val; switch (shape.BindingType) { case BindingType.Element: val = iter.Node; iter.Next(); break; case BindingType.ElementNested: { ArrayList rows = new ArrayList(); rows.Add(iter.Node); iter.Next(); val = new XPathDocumentView(null, rows, shape.NestedShape); break; } case BindingType.Repeat: { ArrayList rows = new ArrayList(); Shape subShape = shape.SubShape(0); if (subShape.BindingType == BindingType.ElementNested) { Shape nestShape = subShape.NestedShape; XPathDocumentView xivc = new XPathDocumentView(null, null, nestShape); XPathNode nd; while (null != (nd = iter.Node) && subShape.IsParticleMatch(iter.Particle)) { rows.Add(nd); iter.Next(); } xivc.SetRows(rows); val = xivc; } else { XPathDocumentView xivc = new XPathDocumentView(null, null, subShape); XPathNode nd; while (null != (nd = iter.Node) && shape.IsParticleMatch(iter.Particle)) { rows.Add(xivc.FillSubRow(iter, subShape, null)); } xivc.SetRows(rows); val = xivc; } break; } case BindingType.Sequence: case BindingType.Choice: case BindingType.All: { XPathDocumentView docview = new XPathDocumentView(null, null, shape); ArrayList rows = new ArrayList(); rows.Add(docview.FillSubRow(iter, shape, null)); docview.SetRows(rows); val = docview; break; } default: case BindingType.Text: case BindingType.Attribute: throw new NotSupportedException(); } return(val); }
XPathNodeView FillSubRow(ContentIterator iter, Shape shape, object[] columns) { if (null == columns) { int colCount = shape.SubShapes.Count; if (0 == colCount) colCount = 1; columns = new object[colCount]; } switch (shape.BindingType) { case BindingType.Element: columns[0] = FillColumn(iter, shape); break; case BindingType.Sequence: { int iPrev = -1; int i; while (null != iter.Node) { i = shape.FindMatchingSubShape(iter.Particle); if (i <= iPrev) break; columns[i] = FillColumn(iter, shape.SubShape(i)); iPrev = i; } break; } case BindingType.All: { while (null != iter.Node) { int i = shape.FindMatchingSubShape(iter.Particle); if (-1 == i || null != columns[i]) break; columns[i] = FillColumn(iter, shape.SubShape(i)); } break; } case BindingType.Choice: { int i = shape.FindMatchingSubShape(iter.Particle); if (-1 != i) { columns[i] = FillColumn(iter, shape.SubShape(i)); } break; } case BindingType.Repeat: default: // should not map to a row throw new NotSupportedException(); } return new XPathNodeView(this, null, columns); }
object FillColumn(ContentIterator iter, Shape shape) { object val; switch (shape.BindingType) { case BindingType.Element: val = iter.Node; iter.Next(); break; case BindingType.ElementNested: { ArrayList rows = new ArrayList(); rows.Add(iter.Node); iter.Next(); val = new XPathDocumentView(null, rows, shape.NestedShape); break; } case BindingType.Repeat: { ArrayList rows = new ArrayList(); Shape subShape = shape.SubShape(0); if (subShape.BindingType == BindingType.ElementNested) { Shape nestShape = subShape.NestedShape; XPathDocumentView xivc = new XPathDocumentView(null, null, nestShape); XPathNode nd; while (null != (nd = iter.Node) && subShape.IsParticleMatch(iter.Particle)) { rows.Add(nd); iter.Next(); } xivc.SetRows(rows); val = xivc; } else { XPathDocumentView xivc = new XPathDocumentView(null, null, subShape); XPathNode nd; while (null != (nd = iter.Node) && shape.IsParticleMatch(iter.Particle)) { rows.Add(xivc.FillSubRow(iter, subShape, null)); } xivc.SetRows(rows); val = xivc; } break; } case BindingType.Sequence: case BindingType.Choice: case BindingType.All: { XPathDocumentView docview = new XPathDocumentView(null, null, shape); ArrayList rows = new ArrayList(); rows.Add(docview.FillSubRow(iter, shape, null)); docview.SetRows(rows); val = docview; break; } default: case BindingType.Text: case BindingType.Attribute: throw new NotSupportedException(); } return val; }
void FillAttributes(XPathNode nd, Shape shape, object[] cols) { int i = 0; while (i < cols.Length) { Shape attrShape = shape.SubShape(i); if (attrShape.BindingType != BindingType.Attribute) break; XmlQualifiedName name = attrShape.AttributeName; XPathNode ndAttr = nd.GetAttribute( name.Name, name.Namespace ); if (null != ndAttr) cols[i] = ndAttr; i++; } }
XPathNodeView FillRow(XPathNode ndRow, Shape shape) { object[] columns; XPathNode nd; switch (shape.BindingType) { case BindingType.Text: case BindingType.Attribute: columns = new object[1]; columns[0] = ndRow; return new XPathNodeView(this, ndRow, columns); case BindingType.Repeat: columns = new object[1]; nd = TreeNavigationHelper.GetContentChild(ndRow); columns[0] = FillColumn(new ContentIterator(nd, shape), shape); return new XPathNodeView(this, ndRow, columns); case BindingType.Sequence: case BindingType.Choice: case BindingType.All: int subShapesCount = shape.SubShapes.Count; columns = new object[subShapesCount]; if (shape.BindingType == BindingType.Sequence && shape.SubShape(0).BindingType == BindingType.Attribute) { FillAttributes(ndRow, shape, columns); } Shape lastSubShape = (Shape)shape.SubShapes[subShapesCount - 1]; if (lastSubShape.BindingType == BindingType.Text) { //Attributes followed by simpe content or mixed content columns[subShapesCount - 1] = ndRow; return new XPathNodeView(this, ndRow, columns); } else { nd = TreeNavigationHelper.GetContentChild(ndRow); return FillSubRow(new ContentIterator(nd, shape), shape, columns); } default: // should not map to a row #if DEBUG throw new NotSupportedException("Unable to bind row to: "+shape.BindingType.ToString()); #else throw new NotSupportedException(); #endif } }