if (nameAtt != null)
nameAtt = fSymbolTable.addSymbol(nameAtt);
// get 'target namespace'
String tnsAtt = null;
XSComplexTypeDecl enclCT = null;
XSObject enclParent = null;
short scope = XSAttributeDecl.SCOPE_ABSENT;
if (isGlobal) {
tnsAtt = schemaDoc.fTargetNamespace;
scope = XSAttributeDecl.SCOPE_GLOBAL;
}
else {
// For XML 1.0, we only store information about enclosing complex types
// For XML 1.1, we store information about enclosing complex types or attribute groups
if (enclosingParent != null) {
if (enclosingParent instanceof XSComplexTypeDecl) {
enclCT = (XSComplexTypeDecl) enclosingParent;
enclParent = enclosingParent;
scope = XSAttributeDecl.SCOPE_LOCAL;
}
else if (fSchemaHandler.fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
enclParent = enclosingParent;
scope = XSAttributeDecl.SCOPE_LOCAL;
}
}
if (targetNsAtt != null) {
// XML Schema 1.1, set the target namespace to be the value of the targetNamespace attribute if one is defined
tnsAtt = fSymbolTable.addSymbol(targetNsAtt);
} else if (formAtt != null) {
if (formAtt.intValue() == SchemaSymbols.FORM_QUALIFIED)
tnsAtt = schemaDoc.fTargetNamespace;
} else if (schemaDoc.fAreLocalAttributesQualified) {
tnsAtt = schemaDoc.fTargetNamespace;
}
}
// get 'value constraint'
// for local named attribute, value constraint is absent
ValidatedInfo attDefault = null;
short constraintType = XSConstants.VC_NONE;
if (isGlobal) {
if (fixedAtt != null) {
attDefault = new ValidatedInfo();
attDefault.normalizedValue = fixedAtt;
constraintType = XSConstants.VC_FIXED;
} else if (defaultAtt != null) {
attDefault = new ValidatedInfo();
attDefault.normalizedValue = defaultAtt;
constraintType = XSConstants.VC_DEFAULT;
}
}
// get 'annotation'
Element child = DOMUtil.getFirstChildElement(attrDecl);
XSAnnotationImpl annotation = null;
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);
}
}
// get 'type definition'
XSSimpleType attrType = null;
boolean haveAnonType = false;
// Handle Anonymous type if there is one
if (child != null) {
String childName = DOMUtil.getLocalName(child);
if (childName.equals(SchemaSymbols.ELT_SIMPLETYPE)) {
attrType = fSchemaHandler.fSimpleTypeTraverser.traverseLocal(child, schemaDoc, grammar, attribute);
haveAnonType = true;
child = DOMUtil.getNextSiblingElement(child);
}
}
// Handle type attribute
if (attrType == null && typeAtt != null) {
XSTypeDefinition type = (XSTypeDefinition)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.TYPEDECL_TYPE, typeAtt, attrDecl);
if (type != null && type.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
attrType = (XSSimpleType)type;
}
else {
reportSchemaError("src-resolve", new Object[]{typeAtt.rawname, "simpleType definition"}, attrDecl);
if (type == null) {
attribute.fUnresolvedTypeName = typeAtt;
}
}
}
if (attrType == null) {
attrType = SchemaGrammar.fAnySimpleType;
}
XSObjectList annotations;
if (annotation != null) {
annotations = new XSObjectListImpl();
((XSObjectListImpl)annotations).addXSObject(annotation);
} else {
annotations = XSObjectListImpl.EMPTY_LIST;
}
boolean inheritable = false;
if (inheritableAtt != null) {
inheritable = inheritableAtt.booleanValue();
}
attribute.setValues(nameAtt, tnsAtt, attrType, constraintType, scope,
attDefault, enclParent, annotations, inheritable);
// Step 3: check against schema for schemas
// required attributes
if (nameAtt == null) {
if (isGlobal)
reportSchemaError("s4s-att-must-appear", new Object[]{SchemaSymbols.ELT_ATTRIBUTE, SchemaSymbols.ATT_NAME}, attrDecl);
else
reportSchemaError("src-attribute.3.1", null, attrDecl);
nameAtt = NO_NAME;
}
// element
if (child != null) {
reportSchemaError("s4s-elt-must-match.1", new Object[]{nameAtt, "(annotation?, (simpleType?))", DOMUtil.getLocalName(child)}, child);
}
// Step 4: check 3.2.3 constraints
// 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.
// This is checked in "traverse" method
// 3 If the item's parent is not <schema>, then all of the following must be true:
// 3.1 One of ref or name must be present, but not both.
// This is checked in XSAttributeChecker
// 3.2 If ref is present, then all of <simpleType>, form and type must be absent.
// Attributes are checked in XSAttributeChecker, elements are checked in "traverse" method
// 4 type and <simpleType> must not both be present.
if (haveAnonType && (typeAtt != null)) {
reportSchemaError( "src-attribute.4", new Object[]{nameAtt}, attrDecl);
}
// Step 5: check 3.2.6 constraints
// check for NOTATION type
checkNotationType(nameAtt, attrType, attrDecl);
// 6 If the targetNamespace attribute is present then all of the following must be true:
if (targetNsAtt != null) {
// 6.2 The form attribute must not be present.
if (formAtt != null) {
reportSchemaError ("src-attribute.6.2", new Object[] {nameAtt}, attrDecl);
}
// 6.3 If the ancestor <schema> does not have a targetNamespace [attribute] or its 'actual value' is different from the 'actual value' of targetNamespace of <attribute>:
String schemaTns = schemaDoc.fTargetNamespace;
if (schemaTns==null || tnsAtt!=schemaTns) {
// 6.3.1 <attribute> must have <complexType> as an ancestor
if (enclCT == null) {
reportSchemaError ("src-attribute.6.3.1", new Object[] {nameAtt}, attrDecl);
}
// 6.3.2 There must be a <restriction> ancestor between the <attribute> and the nearest <complexType> ancestor, and the 'actual value' of the base [attribute] of <restriction> does not 'match' the name of 'xs:anyType'.
else if ((enclCT.getDerivationMethod() != XSConstants.DERIVATION_RESTRICTION) || enclCT.getBaseType() == SchemaGrammar.getXSAnyType(fSchemaHandler.fSchemaVersion)) {
reportSchemaError ("src-attribute.6.3.2", new Object[] {nameAtt}, attrDecl);
}
}
}