in xmlschema-walker/src/main/java/org/apache/ws/commons/schema/walker/XmlSchemaWalker.java [511:568]
private XmlSchemaElement getElement(XmlSchemaElement element, boolean isSubstitutionGroup) {
if (!element.isRef() && !isSubstitutionGroup) {
return element;
}
final QName elemQName = getElementQName(element);
XmlSchemaElement globalElem = null;
if (!element.isRef()) {
globalElem = element;
} else if (element.getRef().getTarget() != null) {
globalElem = element.getRef().getTarget();
} else {
globalElem = schemasByNamespace.getElementByName(elemQName);
}
/*
* An XML Schema element reference defines the id, minOccurs, and
* maxOccurs attributes, while the global element definition defines id
* and all other attributes. This combines the two together.
*/
String id = element.getId();
if (id == null) {
id = globalElem.getId();
}
XmlSchema schema = schemasByNamespace.getSchemaDefiningElement(elemQName);
if (schema == null) {
// TODO: is this correct? The previous code used whichever schema was stored in the schemasByNamespace HashMap
// for the element's namespace.
schema = element.getParent();
}
final XmlSchemaElement copy = new XmlSchemaElement(schema, false);
copy.setName(globalElem.getName());
copy.setAbstract(globalElem.isAbstract());
copy.setAnnotation(globalElem.getAnnotation());
copy.setBlock(globalElem.getBlock());
copy.setDefaultValue(globalElem.getDefaultValue());
copy.setFinal(globalElem.getFinal());
copy.setFixedValue(globalElem.getFixedValue());
copy.setForm(globalElem.getForm());
copy.setId(id);
copy.setLineNumber(element.getLineNumber());
copy.setLinePosition(element.getLinePosition());
copy.setMaxOccurs(element.getMaxOccurs());
copy.setMinOccurs(element.getMinOccurs());
copy.setMetaInfoMap(globalElem.getMetaInfoMap());
copy.setNillable(globalElem.isNillable());
copy.setType(globalElem.getSchemaType());
copy.setSchemaTypeName(globalElem.getSchemaTypeName());
copy.setSourceURI(globalElem.getSourceURI());
copy.setSubstitutionGroup(globalElem.getSubstitutionGroup());
copy.setUnhandledAttributes(globalElem.getUnhandledAttributes());
return copy;
}