use of io.atlasmap.xml.core.XmlPath in project atlasmap by atlasmap.
the class XmlModule method getCollectionSize.
@Override
public int getCollectionSize(AtlasInternalSession session, Field field) throws AtlasException {
// TODO could this use FieldReader?
try {
Object sourceObject = session.getSourceDocument(getDocId());
Document document = getDocument((String) sourceObject, false);
Element parentNode = document.getDocumentElement();
for (SegmentContext sc : new XmlPath(field.getPath()).getSegmentContexts(false)) {
if (sc.getPrev() == null) {
// "/XOA/contact<>/firstName", skip.
continue;
}
String childrenElementName = XmlPath.cleanPathSegment(sc.getSegment());
String namespaceAlias = XmlPath.getNamespace(sc.getSegment());
if (namespaceAlias != null && !"".equals(namespaceAlias)) {
childrenElementName = namespaceAlias + ":" + childrenElementName;
}
List<Element> children = XmlIOHelper.getChildrenWithName(childrenElementName, parentNode);
if (children == null || children.isEmpty()) {
return 0;
}
if (XmlPath.isCollectionSegment(sc.getSegment())) {
return children.size();
}
parentNode = children.get(0);
}
return 0;
} catch (Exception e) {
throw new AtlasException(e);
}
}
Aggregations