in xmlschema-walker/src/main/java/org/apache/ws/commons/schema/walker/XmlSchemaScope.java [526:614]
private XmlSchemaAttrInfo getAttribute(XmlSchemaAttribute attribute, boolean forceCopy) {
if (!attribute.isRef() && (attribute.getSchemaType() != null) && !forceCopy) {
if (attribute.getUse().equals(XmlSchemaUse.NONE)) {
attribute.setUse(XmlSchemaUse.OPTIONAL);
}
return new XmlSchemaAttrInfo(attribute);
}
XmlSchemaAttribute globalAttr = null;
QName attrQName = null;
if (attribute.isRef()) {
attrQName = attribute.getRefBase().getTargetQName();
} else {
attrQName = attribute.getQName();
}
if (!attribute.isRef() && (forceCopy || (attribute.getSchemaType() == null))) {
// If we are forcing a copy, there is no reference to follow.
globalAttr = attribute;
} else {
if (attribute.getRef().getTarget() != null) {
globalAttr = attribute.getRef().getTarget();
} else {
globalAttr = schemasByNamespace.getAttributeByName(attrQName);
}
}
XmlSchemaSimpleType schemaType = globalAttr.getSchemaType();
if (schemaType == null) {
final QName typeQName = globalAttr.getSchemaTypeName();
if (typeQName != null) {
schemaType = (XmlSchemaSimpleType) schemasByNamespace.getTypeByName(typeQName);
}
}
/*
* The attribute reference defines the attribute use and overrides the
* ID, default, and fixed fields. Everything else is defined by the
* global attribute.
*/
String fixedValue = attribute.getFixedValue();
if ((fixedValue != null) && (attribute != globalAttr)) {
fixedValue = globalAttr.getFixedValue();
}
String defaultValue = attribute.getDefaultValue();
if ((defaultValue == null) && (fixedValue == null) && (attribute != globalAttr)) {
defaultValue = globalAttr.getDefaultValue();
}
String id = attribute.getId();
if ((id == null) && (attribute != globalAttr)) {
id = globalAttr.getId();
}
XmlSchemaUse attrUsage = attribute.getUse();
if (attrUsage.equals(XmlSchemaUse.NONE)) {
attrUsage = XmlSchemaUse.OPTIONAL;
}
XmlSchema schema = schemasByNamespace.getSchemaDefiningAttribute(attrQName);
if (schema == null) {
// TODO: is this correct? The previous code used whichever schema was stored in the schemasByNamespace HashMap
// for the attribute's namespace.
schema = attribute.getParent();
}
final XmlSchemaAttribute copy = new XmlSchemaAttribute(schema, false);
copy.setName(globalAttr.getName());
copy.setAnnotation(globalAttr.getAnnotation());
copy.setDefaultValue(defaultValue);
copy.setFixedValue(fixedValue);
copy.setForm(globalAttr.getForm());
copy.setId(id);
copy.setLineNumber(attribute.getLineNumber());
copy.setLinePosition(attribute.getLinePosition());
copy.setMetaInfoMap(globalAttr.getMetaInfoMap());
copy.setSchemaType(schemaType);
copy.setSchemaTypeName(globalAttr.getSchemaTypeName());
copy.setSourceURI(globalAttr.getSourceURI());
copy.setUnhandledAttributes(globalAttr.getUnhandledAttributes());
copy.setUse(attrUsage);
return new XmlSchemaAttrInfo(copy, globalAttr.isTopLevel());
}