uriIndex = fTargetNSURI;
}
QName referredAttQName = new QName(-1,referredAttName,referredAttName,uriIndex);
if (prohibited) {
int tempIndex = fSchemaGrammar.getAttributeDeclIndex(typeInfo.templateElementIndex, referredAttQName);
XMLAttributeDecl referredAttrDecl = new XMLAttributeDecl();
fSchemaGrammar.getAttributeDecl(tempIndex, referredAttrDecl);
referredAttrDecl.defaultType = XMLAttributeDecl.DEFAULT_TYPE_PROHIBITED;
fSchemaGrammar.setAttributeDecl(typeInfo.templateElementIndex, tempIndex, referredAttrDecl);
}
else if (required) {
int tempIndex = fSchemaGrammar.getAttributeDeclIndex(typeInfo.templateElementIndex, referredAttQName);
XMLAttributeDecl referredAttrDecl = new XMLAttributeDecl();
fSchemaGrammar.getAttributeDecl(tempIndex, referredAttrDecl);
// now two cases: if it's othre than fixed, no problem, just overwrite.
// but if it is *it* fixed, specs demand attr be treated as both fixed and required.
if(referredAttrDecl.defaultType == XMLAttributeDecl.DEFAULT_TYPE_FIXED)
referredAttrDecl.defaultType = XMLAttributeDecl.DEFAULT_TYPE_REQUIRED_AND_FIXED;
else
referredAttrDecl.defaultType = XMLAttributeDecl.DEFAULT_TYPE_REQUIRED;
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 " + ref);
}
return -1;
} else if (attNameStr.equals(""))
// REVISIT: localize
reportGenericSchemaError ( "An attribute must have a ref or a name!");
if (datatype.equals("")) {
if (simpleTypeChild != null) {
attType = XMLAttributeDecl.TYPE_SIMPLE;
dataTypeSymbol = traverseSimpleTypeDecl(simpleTypeChild);
localpart = fStringPool.toString(dataTypeSymbol);
}
else {
attType = XMLAttributeDecl.TYPE_SIMPLE;
localpart = "string";
dataTypeSymbol = fStringPool.addSymbol(localpart);
}
localpart = fStringPool.toString(dataTypeSymbol);
dv = fDatatypeRegistry.getDatatypeValidator(localpart);
} else {
if(simpleTypeChild != null && !referredTo)
reportGenericSchemaError("Attribute declarations may not contain both a type and a simpleType declaration");
String prefix = "";
localpart = datatype;
dataTypeSymbol = fStringPool.addSymbol(localpart);
int colonptr = datatype.indexOf(":");
if ( colonptr > 0) {
prefix = datatype.substring(0,colonptr);
localpart = datatype.substring(colonptr+1);
}
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+")");
}
}
}
} else { //isn't of the schema for schemas namespace...
// 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+")");
}
}
attType = XMLAttributeDecl.TYPE_SIMPLE;
}
}
// attribute default type
int attDefaultType = -1;
int attDefaultValue = -1;
if (dv == null && !referredTo) {
// REVISIT: Localize
reportGenericSchemaError("could not resolve the type or get a null validator for datatype : "
+ fStringPool.toString(dataTypeSymbol));
}
String fixed = attrDecl.getAttribute(SchemaSymbols.ATT_VALUE);
if (isAttrTopLevel) {
if (!fixed.equals("")) {
if((required || prohibited
|| use.equals(SchemaSymbols.ATTVAL_OPTIONAL)) && !referredTo)
// REVISIT: Localize
reportGenericSchemaError("Globally-declared attributes containing values must have \"use\" set to \"FIXED\" or \"DEFAULT\", not " +
use);
else if (use.equals("") && !referredTo)
// REVISIT: Localize
reportGenericSchemaError("Globally-declared attributes containing values MUST have \"use\" present and set to \"FIXED\" or \"DEFAULT\"");
else if (use.equals(SchemaSymbols.ATTVAL_FIXED)) {
attDefaultType = XMLAttributeDecl.DEFAULT_TYPE_FIXED;
attDefaultValue = fStringPool.addString(fixed);
}
else {
attDefaultType = XMLAttributeDecl.DEFAULT_TYPE_DEFAULT;
attDefaultValue = fStringPool.addString(fixed);
}
}
else { // no value and we're at top level.
if (!use.equals("") && !referredTo)
// REVISIT: Localize
reportGenericSchemaError("Globally-declared attributes containing no value may not have \"use\" present");
else
attDefaultType = XMLAttributeDecl.DEFAULT_TYPE_IMPLIED;
}
}
else { // not at top-level...
// case where "ref" present taken care of above.
if (!fixed.equals("")) {
if(required || prohibited
|| use.equals(SchemaSymbols.ATTVAL_OPTIONAL))
reportGenericSchemaError("Locally-declared attributes containing values must have \"use\" set to \"FIXED\" or \"DEFAULT\", not " +
use);
else if (use.equals(""))
// REVISIT: Localize
reportGenericSchemaError("Locally-declared attributes containing values MUST have \"use\" present and set to \"FIXED\" or \"DEFAULT\"");
else if (use.equals(SchemaSymbols.ATTVAL_FIXED)) {
attDefaultType = XMLAttributeDecl.DEFAULT_TYPE_FIXED;
attDefaultValue = fStringPool.addString(fixed);
}
else {
attDefaultType = XMLAttributeDecl.DEFAULT_TYPE_DEFAULT;
attDefaultValue = fStringPool.addString(fixed);
}
}
else { // no value and we're not at top level.
if(required)
attDefaultType = XMLAttributeDecl.DEFAULT_TYPE_REQUIRED;
else if (prohibited)
attDefaultType = XMLAttributeDecl.DEFAULT_TYPE_PROHIBITED;
// no other case is defined by the specs, so treat as implied...
else
attDefaultType = XMLAttributeDecl.DEFAULT_TYPE_IMPLIED;
}
}
// check default value is valid for the datatype.
if (attType == XMLAttributeDecl.TYPE_SIMPLE && attDefaultValue != -1) {
try {
if (dv != null)
//REVISIT
dv.validate(fStringPool.toString(attDefaultValue), null);
else if (!referredTo)
reportSchemaError(SchemaMessageProvider.NoValidatorFor,
new Object [] { datatype });
} catch (InvalidDatatypeValueException idve) {
if (!referredTo)
reportSchemaError(SchemaMessageProvider.IncorrectDefaultType,
new Object [] { attrDecl.getAttribute(SchemaSymbols.ATT_NAME), idve.getMessage() });
} catch (Exception e) {
e.printStackTrace();
System.out.println("Internal error in attribute datatype validation");
}
}
/***/
// REVISIT: I don't think this code is right. The attribute
// should take on the target namespace of the grammar
// if present. -Ac
int uriIndex = StringPool.EMPTY_STRING;
// refer to 4.3.1 in "XML Schema Part 1: Structures"
if ( fTargetNSURIString.length() > 0) {
if ( isAttrTopLevel ||
(( !isQName.equals(SchemaSymbols.ATTVAL_UNQUALIFIED)) &&
( isQName.equals(SchemaSymbols.ATTVAL_QUALIFIED)||
fAttributeDefaultQualified )))
uriIndex = fTargetNSURI;
}
/***
int uriIndex = fTargetNSURI;
/***/
QName attQName = new QName(-1,attName,attName,uriIndex);
if ( DEBUGGING )
System.out.println(" the dataType Validator for " + fStringPool.toString(attName) + " is " + dv);
//put the top-levels in the attribute decl registry.
if (isAttrTopLevel) {
fTempAttributeDecl.datatypeValidator = dv;
fTempAttributeDecl.name.setValues(attQName);
fTempAttributeDecl.type = attType;
fTempAttributeDecl.defaultType = attDefaultType;
fTempAttributeDecl.list = attIsList;
if (attDefaultValue != -1 ) {
fTempAttributeDecl.defaultValue = new String(fStringPool.toString(attDefaultValue));
}
fAttributeDeclRegistry.put(attNameStr, new XMLAttributeDecl(fTempAttributeDecl));
}
// add attribute to attr decl pool in fSchemaGrammar,
if (typeInfo != null) {
fSchemaGrammar.addAttDef( typeInfo.templateElementIndex,