use of gov.cms.qpp.conversion.model.DecodeData in project qpp-conversion-tool by CMSgov.
the class QrdaDecoderEngine method decodeTree.
/**
* Decodes the element specified and the entire tree of child {@link Element}s below.
*
* @param element The element who's tree to decode.
* @param parentNode The node to add any possible decoded child {@link Node}s.
* @return The tuple of a {@link DecodeResult} and {@link Node} that was decoded from this tree.
*/
private DecodeData decodeTree(final Element element, final Node parentNode) {
DecodeData result = decodeSingleElement(element, parentNode);
DecodeResult decodedResult = result.getDecodeResult();
Node decodedNode = result.getNode();
decodedNode = decideNewParentNode(decodedNode, parentNode);
if (DecodeResult.TREE_FINISHED == decodedResult) {
return new DecodeData(DecodeResult.TREE_FINISHED, decodedNode);
} else if (DecodeResult.TREE_ESCAPED == decodedResult) {
return new DecodeData(DecodeResult.TREE_FINISHED, null);
}
return decodeChildren(element, decodedNode);
}
use of gov.cms.qpp.conversion.model.DecodeData in project qpp-conversion-tool by CMSgov.
the class QrdaDecoderEngine method decodeChildren.
/**
* Iterates over all the children of the passed in {@link Element} and calls {@link #decodeTree(Element, Node)} on them.
*
* @param element The element who's children will be decoded.
* @param parentNode The parent node
* @return The tuple of a {@link DecodeResult} and {@link Node} that was decoded from the children.
*/
private DecodeData decodeChildren(final Element element, final Node parentNode) {
List<Element> filteredChildElements = getUniqueTemplateIdElements(element.getChildren());
DecodeData decodeData = new DecodeData(DecodeResult.TREE_CONTINUE, parentNode);
Node currentParentNode = parentNode;
for (Element childElement : filteredChildElements) {
DecodeData childDecodeData = decodeTree(childElement, currentParentNode);
DecodeResult childDecodeResult = childDecodeData.getDecodeResult();
Node childDecodedNode = childDecodeData.getNode();
if (DecodeResult.TREE_FINISHED == childDecodeResult) {
decodeData = new DecodeData(DecodeResult.TREE_CONTINUE, parentNode);
break;
}
currentParentNode = childDecodedNode == null ? currentParentNode : childDecodedNode;
}
return decodeData;
}
use of gov.cms.qpp.conversion.model.DecodeData in project qpp-conversion-tool by CMSgov.
the class QrdaDecoderEngine method decodeSingleElement.
/**
* Decodes the passed in element if it is a {@code templateId} and assigns it to the {@code parentNode}.
*
* @param element The element to decode.
* @param parentNode The node add the child decoded {@link Node} to.
* @return The tuple of a {@link DecodeResult} and {@link Node} that was decoded from the {@link Element}.
*/
private DecodeData decodeSingleElement(final Element element, final Node parentNode) {
QrdaDecoder decoder = decoderForElement(element);
if (null == decoder) {
return new DecodeData(DecodeResult.TREE_CONTINUE, null);
}
TemplateId templateId = getTemplateId(element);
Node childNode = new Node(templateId, parentNode);
childNode.setDefaultNsUri(defaultNs.getURI());
decoder.setNamespace(element.getNamespace());
Element parentElement = element.getParentElement();
DecodeResult decodeResult = decoder.decode(parentElement, childNode);
if (decodeResult == DecodeResult.TREE_ESCAPED) {
return new DecodeData(DecodeResult.TREE_ESCAPED, null);
}
childNode.setPath(XPathHelper.getAbsolutePath(parentElement));
parentNode.addChildNode(childNode);
return new DecodeData(decodeResult, childNode);
}
Aggregations