Skip to content

Commit

Permalink
NPE with TypeDefinition
Browse files Browse the repository at this point in the history
Fixes #629

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Jun 8, 2020
1 parent 5082892 commit 5f44942
Showing 1 changed file with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ public LocationLink findTypeLocation(DOMNode originNode) {
if (attributeDecl.getScope() == XSConstants.SCOPE_LOCAL) {
return findLocalXSAttribute(originAttribute, targetSchema,
attributeDecl.getEnclosingCTDefinition(), schemaGrammar);

}
}
} else {
Expand All @@ -284,8 +283,12 @@ public LocationLink findTypeLocation(DOMNode originNode) {
if (globalElement) {
return findGlobalXSElement(originElement, targetSchema);
} else {
return findLocalXSElement(originElement, targetSchema,
elementDeclaration.getElementDeclaration().getEnclosingCTDefinition(), schemaGrammar);
XSComplexTypeDefinition complexTypeDefinition = elementDeclaration.getElementDeclaration()
.getEnclosingCTDefinition();
if (complexTypeDefinition != null) {
return findLocalXSElement(originElement, targetSchema, complexTypeDefinition, schemaGrammar);
}
return findXSElement(originElement, targetSchema.getChildNodes(), true);
}
}
}
Expand Down Expand Up @@ -409,7 +412,7 @@ private static LocationLink findGlobalXSElement(DOMElement originElement, DOMDoc
private static LocationLink findLocalXSElement(DOMElement originElement, DOMDocument targetSchema,
XSComplexTypeDefinition enclosingType, SchemaGrammar schemaGrammar) {
// In local xs:element case, xs:element is declared inside a complex type
// (enclosing tye).
// (enclosing type).
// Xerces stores in the SchemaGrammar the locator (offset) for each complex type
// (XSComplexTypeDecl)
// Here we get the offset of the local enclosing complex type xs:complexType.
Expand Down Expand Up @@ -501,16 +504,12 @@ private static LocationLink findXSElement(DOMElement originElement, NodeList chi
Node n = children.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
Element elt = (Element) n;
if (XSDUtils.isXSElement(elt)) {
if (originElement.getLocalName().equals(elt.getAttribute("name"))) {
DOMAttr targetAttr = (DOMAttr) elt.getAttributeNode("name");
LocationLink location = XMLPositionUtility.createLocationLink(originElement,
targetAttr.getNodeAttrValue());
return location;
}
LocationLink location = findXSElement(originElement, elt);
if (location != null) {
return location;
}
if (inAnyLevel && elt.hasChildNodes()) {
LocationLink location = findXSElement(originElement, elt.getChildNodes(), inAnyLevel);
location = findXSElement(originElement, elt.getChildNodes(), inAnyLevel);
if (location != null) {
return location;
}
Expand All @@ -520,6 +519,18 @@ private static LocationLink findXSElement(DOMElement originElement, NodeList chi
return null;
}

private static LocationLink findXSElement(DOMElement originElement, Element elt) {
if (elt != null && XSDUtils.isXSElement(elt)) {
if (originElement.getLocalName().equals(elt.getAttribute("name"))) {
DOMAttr targetAttr = (DOMAttr) elt.getAttributeNode("name");
LocationLink location = XMLPositionUtility.createLocationLink(originElement,
targetAttr.getNodeAttrValue());
return location;
}
}
return null;
}

private static LocationLink findLocalXSAttribute(DOMAttr originAttribute, DOMDocument targetSchema,
XSComplexTypeDefinition enclosingType, SchemaGrammar schemaGrammar) {
int complexTypeOffset = getComplexTypeOffset(enclosingType, schemaGrammar);
Expand Down

0 comments on commit 5f44942

Please sign in to comment.