use of net.sf.saxon.om.NodeInfo in project teiid by teiid.
the class SaxonXQueryExpression method createXMLType.
public XMLType createXMLType(final SequenceIterator iter, BufferManager bufferManager, boolean emptyOnEmpty, CommandContext context) throws XPathException, TeiidComponentException, TeiidProcessingException {
final Item item = iter.next();
if (item == null && !emptyOnEmpty) {
return null;
}
XMLType.Type type = Type.CONTENT;
if (item instanceof NodeInfo) {
NodeInfo info = (NodeInfo) item;
type = getType(info);
}
final Item next = iter.next();
if (next != null) {
type = Type.CONTENT;
}
SQLXMLImpl xml = XMLSystemFunctions.saveToBufferManager(bufferManager, new XMLTranslator() {
@Override
public void translate(Writer writer) throws TransformerException, IOException {
QueryResult.serializeSequence(new PushBackSequenceIterator(iter, item, next), config, writer, DEFAULT_OUTPUT_PROPERTIES);
}
}, context);
XMLType value = new XMLType(xml);
value.setType(type);
return value;
}
use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class ElementNode method compareCommonAncestorChildrenOrder.
/**
* Walks up the hierarchy until a common ancestor is found.
* Then compares topmost sibling nodes.
*
* @param first {@code NodeInfo} to compare
* @param second {@code NodeInfo} to compare
* @return the value {@code 0} if {@code first == second};
* a value less than {@code 0} if {@code first} should be first;
* a value greater than {@code 0} if {@code second} should be first.
*/
private static int compareCommonAncestorChildrenOrder(NodeInfo first, NodeInfo second) {
NodeInfo child1 = first;
NodeInfo child2 = second;
while (!child1.getParent().equals(child2.getParent())) {
child1 = child1.getParent();
child2 = child2.getParent();
}
final int index1 = ((ElementNode) child1).indexAmongSiblings;
final int index2 = ((ElementNode) child2).indexAmongSiblings;
return Integer.compare(index1, index2);
}
use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class PrecedingIterator method next.
/**
* Get the next item in the sequence.
*
* @return the next Item. If there are no more nodes, return null.
*/
@Override
public NodeInfo next() {
NodeInfo result = null;
while (result == null) {
if (descendantEnum != null) {
result = descendantEnum.next();
}
if (result == null && previousSiblingEnum != null) {
result = previousSiblingEnum.next();
if (result == null) {
previousSiblingEnum = null;
} else {
descendantEnum = new ReverseDescendantIterator(result);
}
}
if (result == null) {
result = ancestorEnum.next();
if (result == null) {
break;
}
previousSiblingEnum = result.iterateAxis(AxisInfo.PRECEDING_SIBLING);
}
}
return result;
}
use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class ReverseDescendantIterator method pushToStack.
/**
* Pushes all children to the stack.
*
* @param iterateAxis {@link AxisInfo#CHILD} axis iterator.
*/
private void pushToStack(AxisIterator iterateAxis) {
NodeInfo nodeInfo = iterateAxis.next();
while (nodeInfo != null) {
stack.addLast(nodeInfo);
nodeInfo = iterateAxis.next();
}
}
use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class XpathMapperTest method testQueryAllMethodDefinitionsInContext.
@Test
public void testQueryAllMethodDefinitionsInContext() throws Exception {
final String objectXpath = "//CLASS_DEF[./IDENT[@text='InputXpathMapperAst']]//OBJBLOCK";
final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
final List<NodeInfo> objectNodes = getXpathItems(objectXpath, rootNode);
assertWithMessage("Invalid number of nodes").that(objectNodes).hasSize(1);
final AbstractNode objNode = (AbstractNode) objectNodes.get(0);
final String methodsXpath = "METHOD_DEF";
final List<NodeInfo> methodsNodes = getXpathItems(methodsXpath, objNode);
assertWithMessage("Invalid number of nodes").that(methodsNodes).hasSize(2);
final DetailAST[] actual = convertToArray(methodsNodes);
final DetailAST expectedMethodDefNode = getSiblingByType(rootNode.getUnderlyingNode(), TokenTypes.COMPILATION_UNIT).findFirstToken(TokenTypes.CLASS_DEF).findFirstToken(TokenTypes.OBJBLOCK).findFirstToken(TokenTypes.METHOD_DEF);
final DetailAST[] expected = { expectedMethodDefNode, expectedMethodDefNode.getNextSibling() };
assertWithMessage("Result nodes differ from expected").that(actual).isEqualTo(expected);
assertWithMessage("Invalid token type").that(actual[0].getType()).isEqualTo(TokenTypes.METHOD_DEF);
assertWithMessage("Invalid token type").that(actual[1].getType()).isEqualTo(TokenTypes.METHOD_DEF);
}
Aggregations