public final XedCursor findTypeInstanceChild(final String name, final XedCursor cursor) { final Element element = cursor.getElement(); final XedCursor cursorType = findTypeInstance(name, cursor); XedCursor cursorChild = null; final TypeInstance typeInstance = cursorType.getTypeInstance(); final TypeInstance.NodeType nodeType = (typeInstance == null) ? null : typeInstance.getNodeType(); if (TypeInstance.NodeType.attribute.equals(nodeType)) { cursorChild = findChildAttr(ElementU.getAttributeNode(element, name), cursor, cursorType); } else if (TypeInstance.NodeType.element.equals(nodeType)) { cursorChild = findChildElement(ElementU.getChild(element, typeInstance.getQName()), cursor, cursorType); } return cursorChild; }
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private XedCursor findChildElement( final Element child, final XedCursor cursorParent, final XedCursor cursorType) { final Xed xed = cursorParent.getXed(); final Element elementParent = cursorParent.getElement(); final TypeInstance typeInstance = cursorType.getTypeInstance(); XedCursor cursor = new XedCursor(xed, cursorType, null, null, typeInstance); final Collection<Element> children = ElementU.getChildren(elementParent, typeInstance.getName()); int ordinal = -1; for (final Element childIt : children) { ++ordinal; if (childIt.equals(child)) { cursor = new XedCursor(xed, cursorType, childIt, ordinal, typeInstance); break; } } return cursor; }
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public final XedCursor findTypeInstance(final String name, final XedCursor cursor) { XedCursor cursorType = null; final TypeInstance typeInstance = cursor.getTypeInstance(); final TypeInstance typeInstanceChild = typeInstance.getInstance(name); if (typeInstance.getInstances().contains(typeInstanceChild)) { cursorType = new XedCursor(cursor.getXed(), cursor, null, null, typeInstanceChild); } else { final TypeInstanceTraversal traversal = new TypeInstanceTraversal(typeInstance); final List<TypeInstance> typeInstances = traversal.getForName(name); if (!typeInstances.isEmpty()) { cursorType = cursor; for (final TypeInstance typeInstanceIt : typeInstances) { cursorType = new XedCursor(cursor.getXed(), cursorType, null, null, typeInstanceIt); } } } return cursorType; }
private String getIDPrivate(final TypeInstance parentInstance) { return Value.join(XsdU.DOT, parentInstance.getID(), getName()); }