String defaultAtt = (String) attrValues[XSAttributeChecker.ATTIDX_DEFAULT];
String fixedAtt = (String) attrValues[XSAttributeChecker.ATTIDX_FIXED];
String nameAtt = (String) attrValues[XSAttributeChecker.ATTIDX_NAME];
QName refAtt = (QName) attrValues[XSAttributeChecker.ATTIDX_REF];
XInt useAtt = (XInt) attrValues[XSAttributeChecker.ATTIDX_USE];
// get 'attribute declaration'
XSAttributeDecl attribute = null;
XSAnnotationImpl annotation = null;
if (attrDecl.getAttributeNode(SchemaSymbols.ATT_REF) != null) {
if (refAtt != null) {
attribute = (XSAttributeDecl)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.ATTRIBUTE_TYPE, refAtt, attrDecl);
Element child = DOMUtil.getFirstChildElement(attrDecl);
if (child != null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc);
child = DOMUtil.getNextSiblingElement(child);
}
else {
String text = DOMUtil.getSyntheticAnnotation(attrDecl);
if (text != null) {
annotation = traverseSyntheticAnnotation(attrDecl, text, attrValues, false, schemaDoc);
}
}
if (child != null) {
reportSchemaError("src-attribute.3.2", new Object[]{refAtt.rawname}, child);
}
// for error reporting
nameAtt = refAtt.localpart;
} else {
attribute = null;
}
} else {
attribute = traverseNamedAttr(attrDecl, attrValues, schemaDoc, grammar, false, enclosingCT);
}
// get 'value constraint'
short consType = XSConstants.VC_NONE;
if (defaultAtt != null) {
consType = XSConstants.VC_DEFAULT;
} else if (fixedAtt != null) {
consType = XSConstants.VC_FIXED;
defaultAtt = fixedAtt;
fixedAtt = null;
}
XSAttributeUseImpl attrUse = null;
if (attribute != null) {
if (fSchemaHandler.fDeclPool !=null) {
attrUse = fSchemaHandler.fDeclPool.getAttributeUse();
} else {
attrUse = new XSAttributeUseImpl();
}
attrUse.fAttrDecl = attribute;
attrUse.fUse = useAtt.shortValue();
attrUse.fConstraintType = consType;
if (defaultAtt != null) {
attrUse.fDefault = new ValidatedInfo();
attrUse.fDefault.normalizedValue = defaultAtt;
}
// Get the annotation associated witht the local attr decl
if (attrDecl.getAttributeNode(SchemaSymbols.ATT_REF) == null) {
attrUse.fAnnotations = attribute.getAnnotations();
} else {
XSObjectList annotations;
if (annotation != null) {
annotations = new XSObjectListImpl();
((XSObjectListImpl) annotations).addXSObject(annotation);
} else {
annotations = XSObjectListImpl.EMPTY_LIST;
}
attrUse.fAnnotations = annotations;
}
}
//src-attribute
// 1 default and fixed must not both be present.
if (defaultAtt != null && fixedAtt != null) {
reportSchemaError("src-attribute.1", new Object[]{nameAtt}, attrDecl);
}
// 2 If default and use are both present, use must have the actual value optional.
if (consType == XSConstants.VC_DEFAULT &&
useAtt != null && useAtt.intValue() != SchemaSymbols.USE_OPTIONAL) {
reportSchemaError("src-attribute.2", new Object[]{nameAtt}, attrDecl);
// Recover by honouring the default value
attrUse.fUse = SchemaSymbols.USE_OPTIONAL;
}