uriIndex = fTargetNSURI;
}
QName referredAttQName = new QName(-1,referredAttName,referredAttName,uriIndex);
int tempIndex = fSchemaGrammar.getAttributeDeclIndex(typeInfo.templateElementIndex, referredAttQName);
XMLAttributeDecl referredAttrDecl = new XMLAttributeDecl();
fSchemaGrammar.getAttributeDecl(tempIndex, referredAttrDecl);
boolean updated = false;
int useDigits = XMLAttributeDecl.USE_TYPE_OPTIONAL |
XMLAttributeDecl.USE_TYPE_PROHIBITED |
XMLAttributeDecl.USE_TYPE_REQUIRED;
int valueDigits = XMLAttributeDecl.VALUE_CONSTRAINT_DEFAULT |
XMLAttributeDecl.VALUE_CONSTRAINT_FIXED;
if(!isOptional &&
(referredAttrDecl.defaultType & useDigits) !=
(attValueAndUseType & useDigits))
{
if(referredAttrDecl.defaultType != XMLAttributeDecl.USE_TYPE_PROHIBITED) {
referredAttrDecl.defaultType |= useDigits;
referredAttrDecl.defaultType ^= useDigits; // clear the use
referredAttrDecl.defaultType |= (attValueAndUseType & useDigits);
updated = true;
}
}
if(fixedStr.length() > 0) {
if((referredAttrDecl.defaultType & XMLAttributeDecl.VALUE_CONSTRAINT_FIXED) == 0) {
referredAttrDecl.defaultType |= valueDigits;
referredAttrDecl.defaultType ^= valueDigits; // clear the value
referredAttrDecl.defaultType |= XMLAttributeDecl.VALUE_CONSTRAINT_FIXED;
referredAttrDecl.defaultValue = fStringPool.toString(attValueConstraint);
updated = true;
}
}
if(updated) {
fSchemaGrammar.setAttributeDecl(typeInfo.templateElementIndex, tempIndex, referredAttrDecl);
}
}
}
else if (fAttributeDeclRegistry.get(localpart) != null) {
addAttributeDeclFromAnotherSchema(localpart, uriStr, typeInfo);
}
else {
// REVISIT: Localize
reportGenericSchemaError ( "Couldn't find top level attribute " + refStr + errorContext);
}
return 0;
}
if (uriIndex == fXsiURI) {
reportGenericSchemaError("no-xsi: The {target namespace} of an attribute declaration must not match " + SchemaSymbols.URI_XSI + errorContext);
}
// validation of attribute type is same for each case of declaration
if (simpleTypeChild != null) {
attType = XMLAttributeDecl.TYPE_SIMPLE;
dataTypeSymbol = traverseSimpleTypeDecl(simpleTypeChild);
localpart = fStringPool.toString(dataTypeSymbol);
dv = fDatatypeRegistry.getDatatypeValidator(localpart);
}
else if (datatypeStr.length() != 0) {
dataTypeSymbol = fStringPool.addSymbol(datatypeStr);
String prefix;
int colonptr = datatypeStr.indexOf(":");
if ( colonptr > 0) {
prefix = datatypeStr.substring(0,colonptr);
localpart = datatypeStr.substring(colonptr+1);
}
else {
prefix = "";
localpart = datatypeStr;
}
String typeURI = resolvePrefixToURI(prefix);
if ( typeURI.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)
|| typeURI.length()==0) {
dv = getDatatypeValidator("", localpart);
if (localpart.equals("ID")) {
attType = XMLAttributeDecl.TYPE_ID;
} else if (localpart.equals("IDREF")) {
attType = XMLAttributeDecl.TYPE_IDREF;
} else if (localpart.equals("IDREFS")) {
attType = XMLAttributeDecl.TYPE_IDREF;
attIsList = true;
} else if (localpart.equals("ENTITY")) {
attType = XMLAttributeDecl.TYPE_ENTITY;
} else if (localpart.equals("ENTITIES")) {
attType = XMLAttributeDecl.TYPE_ENTITY;
attIsList = true;
} else if (localpart.equals("NMTOKEN")) {
attType = XMLAttributeDecl.TYPE_NMTOKEN;
} else if (localpart.equals("NMTOKENS")) {
attType = XMLAttributeDecl.TYPE_NMTOKEN;
attIsList = true;
} else if (localpart.equals(SchemaSymbols.ELT_NOTATION)) {
attType = XMLAttributeDecl.TYPE_NOTATION;
}
else {
attType = XMLAttributeDecl.TYPE_SIMPLE;
if (dv == null && typeURI.length() == 0) {
Element topleveltype = getTopLevelComponentByName(SchemaSymbols.ELT_SIMPLETYPE, localpart);
if (topleveltype != null) {
traverseSimpleTypeDecl( topleveltype );
dv = getDatatypeValidator(typeURI, localpart);
}else if (!referredTo) {
// REVISIT: Localize
reportGenericSchemaError("simpleType not found : " + "("+typeURI+":"+localpart+")"+ errorContext);
}
}
}
} else { //isn't of the schema for schemas namespace...
attType = XMLAttributeDecl.TYPE_SIMPLE;
// check if the type is from the same Schema
dv = getDatatypeValidator(typeURI, localpart);
if (dv == null && typeURI.equals(fTargetNSURIString) ) {
Element topleveltype = getTopLevelComponentByName(SchemaSymbols.ELT_SIMPLETYPE, localpart);
if (topleveltype != null) {
traverseSimpleTypeDecl( topleveltype );
dv = getDatatypeValidator(typeURI, localpart);
}else if (!referredTo) {
// REVISIT: Localize
reportGenericSchemaError("simpleType not found : " + "("+typeURI+":"+ localpart+")"+ errorContext);
}
}
}
}
else {
attType = XMLAttributeDecl.TYPE_SIMPLE;
localpart = "string";
dataTypeSymbol = fStringPool.addSymbol(localpart);
dv = fDatatypeRegistry.getDatatypeValidator(localpart);
} // if(...Type)
// validation of data constraint is same for each case of declaration
if(defaultStr.length() > 0) {
attValueAndUseType |= XMLAttributeDecl.VALUE_CONSTRAINT_DEFAULT;
attValueConstraint = fStringPool.addString(defaultStr);
}
else if(fixedStr.length() > 0) {
attValueAndUseType |= XMLAttributeDecl.VALUE_CONSTRAINT_FIXED;
attValueConstraint = fStringPool.addString(fixedStr);
}
////// Check W3C's PR-Structure 3.2.6
// --- Constraints on Attribute Declaration Schema Components
// check default value is valid for the datatype.
if (attType == XMLAttributeDecl.TYPE_SIMPLE && attValueConstraint != -1) {
try {
if (dv != null) {
if(defaultStr.length() > 0) {
//REVISIT
dv.validate(defaultStr, null);
}
else {
dv.validate(fixedStr, null);
}
}
else if (!referredTo)
reportSchemaError(SchemaMessageProvider.NoValidatorFor,
new Object [] { datatypeStr });
} catch (InvalidDatatypeValueException idve) {
if (!referredTo)
reportSchemaError(SchemaMessageProvider.IncorrectDefaultType,
new Object [] { attrDecl.getAttribute(SchemaSymbols.ATT_NAME), idve.getMessage() }); //a-props-correct.2
} catch (Exception e) {
e.printStackTrace();
System.out.println("Internal error in attribute datatype validation");
}
}
// check the coexistence of ID and value constraint
dvIsDerivedFromID =
((dv != null) && dv instanceof IDDatatypeValidator);
if (dvIsDerivedFromID && attValueConstraint != -1)
{
reportGenericSchemaError("a-props-correct.3: If type definition is or is derived from ID ," +
"there must not be a value constraint" + errorContext);
}
if (attNameStr.equals("xmlns")) {
reportGenericSchemaError("no-xmlns: The {name} of an attribute declaration must not match 'xmlns'" + errorContext);
}
////// every contraints were matched. Now register the attribute declaration
//put the top-levels in the attribute decl registry.
if (isAttrTopLevel) {
fTempAttributeDecl.datatypeValidator = dv;
fTempAttributeDecl.name.setValues(attQName);
fTempAttributeDecl.type = attType;
fTempAttributeDecl.defaultType = attValueAndUseType;
fTempAttributeDecl.list = attIsList;
if (attValueConstraint != -1 ) {
fTempAttributeDecl.defaultValue = fStringPool.toString(attValueConstraint);
}
fAttributeDeclRegistry.put(attNameStr, new XMLAttributeDecl(fTempAttributeDecl));
}
// add attribute to attr decl pool in fSchemaGrammar,
if (typeInfo != null) {