TeiidComponentException, TeiidProcessingException {
if (item == null) {
try {
item = result.iter.next();
} catch (XPathException e) {
throw new TeiidProcessingException(e, QueryPlugin.Util.getString("XMLTableNode.error", e.getMessage())); //$NON-NLS-1$
}
rowCount++;
if (item == null) {
terminateBatches();
return;
}
}
List<Object> tuple = new ArrayList<Object>(projectedColumns.size());
for (XMLColumn proColumn : projectedColumns) {
if (proColumn.isOrdinal()) {
tuple.add(rowCount);
} else {
try {
XPathExpression path = proColumn.getPathExpression();
XPathDynamicContext dynamicContext = path.createDynamicContext(item);
SequenceIterator pathIter = path.iterate(dynamicContext);
Item colItem = pathIter.next();
if (colItem == null) {
if (proColumn.getDefaultExpression() != null) {
tuple.add(getEvaluator(Collections.emptyMap()).evaluate(proColumn.getDefaultExpression(), null));
} else {
tuple.add(null);
}
continue;
}
if (proColumn.getSymbol().getType() == DataTypeManager.DefaultDataClasses.XML) {
XMLType value = table.getXQueryExpression().createXMLType(pathIter.getAnother(), this.getBufferManager(), false);
tuple.add(value);
continue;
}
if (pathIter.next() != null) {
throw new TeiidProcessingException(QueryPlugin.Util.getString("XMLTableName.multi_value", proColumn.getName())); //$NON-NLS-1$
}
Object value = Value.convertToJava(colItem);
if (value instanceof Item) {
Item i = (Item)value;
BuiltInAtomicType bat = typeMapping.get(proColumn.getSymbol().getType());
if (bat != null) {
ConversionResult cr = StringValue.convertStringToBuiltInType(i.getStringValueCS(), bat, null);
value = cr.asAtomic();
value = Value.convertToJava((AtomicValue)value);
if (value instanceof Item) {
value = ((Item)value).getStringValue();
}
} else {
value = i.getStringValue();
}
}
value = FunctionDescriptor.importValue(value, proColumn.getSymbol().getType());
tuple.add(value);
} catch (XPathException e) {
throw new TeiidProcessingException(e, QueryPlugin.Util.getString("XMLTableNode.path_error", proColumn.getName())); //$NON-NLS-1$
}
}
}
item = null;
addBatchRow(tuple);