"unresolved type : "+uri+","+localpart
+" found in xsi:type handling");
else if (elementIndex != -1) {
// make sure the new type is related to the
// type of the expected element
DatatypeValidator ancestorValidator = tempElementDecl.datatypeValidator;
DatatypeValidator tempVal = fXsiTypeValidator;
for(; tempVal != null; tempVal = tempVal.getBaseValidator())
// WARNING!!! Comparison by reference.
if(tempVal == ancestorValidator) break;
if(tempVal == null) {
// now if ancestorValidator is a union, then we must
// look through its members to see whether we derive from any of them.
if(ancestorValidator instanceof UnionDatatypeValidator) {
// fXsiTypeValidator must derive from one of its members...
Vector subUnionMemberDV = ((UnionDatatypeValidator)ancestorValidator).getBaseValidators();
int subUnionSize = subUnionMemberDV.size();
boolean found = false;
for (int i=0; i<subUnionSize && !found; i++) {
DatatypeValidator dTempSub = (DatatypeValidator)subUnionMemberDV.elementAt(i);
DatatypeValidator dTemp = fXsiTypeValidator;
for(; dTemp != null; dTemp = dTemp.getBaseValidator()) {
// WARNING!!! This uses comparison by reference andTemp is thus inherently suspect!
if(dTempSub == dTemp) {
found = true;
break;
}
}
if (!found) {
// if dTempSub is anySimpleType,
// then the derivation is ok.
if (dTempSub instanceof AnySimpleType) {
found = true;
}
}
}
if(!found) {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR,
"Type : "+uri+","+localpart
+" does not derive from the type of element " + fStringPool.toString(tempElementDecl.name.localpart));
}
} else
if ((ancestorValidator == null &&
((SchemaGrammar)fGrammar).getElementComplexTypeInfo(elementIndex) == null) ||
(ancestorValidator instanceof AnySimpleType)) {
// if ancestorValidator is anyType or anySimpleType,
// then the derivation is ok.
} else {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR,
"Type : "+uri+","+localpart
+" does not derive from the type of element " + fStringPool.toString(tempElementDecl.name.localpart));
}
} else {
// if we have an attribute but xsi:type's type is simple, we have a problem...
if (tempVal != null && fXsiTypeValidator != null &&
(fGrammar.getFirstAttributeDeclIndex(elementIndex) != -1)) {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR,
"Type : "+uri+","+localpart
+" does not derive from the type of element " + fStringPool.toString(tempElementDecl.name.localpart));
}
// check if element has block set
if((((SchemaGrammar)fGrammar).getElementDeclBlockSet(elementIndex) & SchemaSymbols.RESTRICTION) != 0) {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR,
"Element " + fStringPool.toString(tempElementDecl.name.localpart)
+ "does not permit substitution by a type such as "+uri+","+localpart);
}
}
}
} else {
//
// The type must not be abstract
//
if (typeInfo.isAbstractType()) {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR,
"Abstract type " + xsiType + " should not be used in xsi:type");
}
if (elementIndex != -1) {
// now we look at whether there is a type
// relation and whether the type (and element) allow themselves to be substituted for.
TraverseSchema.ComplexTypeInfo tempType = typeInfo;
TraverseSchema.ComplexTypeInfo destType = ((SchemaGrammar)fGrammar).getElementComplexTypeInfo(elementIndex);
for(; tempType != null && destType != null; tempType = tempType.baseComplexTypeInfo) {
if(tempType.typeName.equals(destType.typeName))
break;
}
if(tempType == null) {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR,
"Type : "+uri+","+localpart
+" does not derive from the type " + destType.typeName);
} else if (destType == null && tempElementDecl.datatypeValidator != null) {
// if the original type is a simple type, check derivation ok.
DatatypeValidator ancestorValidator = tempElementDecl.datatypeValidator;
DatatypeValidator tempVal = fXsiTypeValidator;
for(; tempVal != null; tempVal = tempVal.getBaseValidator())
// WARNING!!! Comparison by reference.
if(tempVal == ancestorValidator) break;
if (tempVal == null) {
// if ancestorValidator is anyType or anySimpleType,
// then the derivation is ok.
if (ancestorValidator instanceof AnySimpleType) {
tempVal = fXsiTypeValidator;
}
}
if(tempVal == null) {
// now if ancestorValidator is a union, then we must
// look through its members to see whether we derive from any of them.
if(ancestorValidator instanceof UnionDatatypeValidator) {
// fXsiTypeValidator must derive from one of its members...
Vector subUnionMemberDV = ((UnionDatatypeValidator)ancestorValidator).getBaseValidators();
int subUnionSize = subUnionMemberDV.size();
boolean found = false;
for (int i=0; i<subUnionSize && !found; i++) {
DatatypeValidator dTempSub = (DatatypeValidator)subUnionMemberDV.elementAt(i);
DatatypeValidator dTemp = fXsiTypeValidator;
for(; dTemp != null; dTemp = dTemp.getBaseValidator()) {
// WARNING!!! This uses comparison by reference andTemp is thus inherently suspect!
if(dTempSub == dTemp) {
found = true;
break;
}
}
if (!found) {
// if dTempSub is anySimpleType,
// then the derivation is ok.
if (dTempSub instanceof AnySimpleType) {
found = true;
}
}
}
if(!found) {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR,
"Type : "+uri+","+localpart
+" does not derive from the type of element " + fStringPool.toString(tempElementDecl.name.localpart));
}
} else {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR,
"Type : "+uri+","+localpart
+" does not derive from the type of element " + fStringPool.toString(tempElementDecl.name.localpart));
}
}
} else if (typeInfo != destType) { // now check whether the element or typeInfo's baseType blocks us.
int derivationMethod = typeInfo.derivedBy;
if((((SchemaGrammar)fGrammar).getElementDeclBlockSet(elementIndex) & derivationMethod) != 0) {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR,
"Element " + fStringPool.toString(tempElementDecl.name.localpart) +
" does not permit xsi:type substitution in the manner required by type "+uri+","+localpart);
} else if (typeInfo.baseComplexTypeInfo != null &&
(typeInfo.baseComplexTypeInfo.blockSet & derivationMethod) != 0) {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR,
"Type " + typeInfo.baseComplexTypeInfo.typeName + " does not permit other types, such as "
+uri+","+localpart + " to be substituted for itself using xsi:type");
}
}
}
elementIndex = typeInfo.templateElementIndex;
}
}
fXsiTypeAttValue = -1;
}
else if (elementIndex != -1) {
//
// xsi:type was not specified...
// If the corresponding type is abstract, detect an error
//
TraverseSchema.ComplexTypeInfo typeInfo =
((SchemaGrammar) fGrammar).getElementComplexTypeInfo(elementIndex);
if (typeInfo != null &&
typeInfo.isAbstractType()) {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR,
"Element " + fStringPool.toString(element.rawname) + " is declared with a type that is abstract. Use xsi:type to specify a non-abstract type");
}
}
if (elementIndex != -1) {
//
// Check whether this element is abstract. If so, an error
//
int miscFlags = ((SchemaGrammar) fGrammar).getElementDeclMiscFlags(elementIndex);
if ((miscFlags & SchemaSymbols.ABSTRACT) != 0) {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR,
"A member of abstract element " + fStringPool.toString(element.rawname) + "'s substitution group must be specified");
}
if (fNil && (miscFlags & SchemaSymbols.NILLABLE) == 0 ) {
fNil = false;
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR,
"xsi:nil must not be specified for the element "+ fStringPool.toString(element.rawname)+
" with {nillable} equals 'false'");
}
//Change the current scope to be the one defined by this element.
fCurrentScope = ((SchemaGrammar) fGrammar).getElementDefinedScope(elementIndex);
// here need to check if we need to switch Grammar by asking SchemaGrammar whether
// this element actually is of a type in another Schema.
String anotherSchemaURI = ((SchemaGrammar)fGrammar).getElementFromAnotherSchemaURI(elementIndex);
if (anotherSchemaURI != null) {
//before switch Grammar, set the elementIndex to be the template elementIndex of its type
if (contentSpecType != -1) {
TraverseSchema.ComplexTypeInfo typeInfo = ((SchemaGrammar) fGrammar).getElementComplexTypeInfo(elementIndex);
if (typeInfo != null) {
elementIndex = typeInfo.templateElementIndex;
}
// now switch the grammar
fGrammarNameSpaceIndex = fCurrentSchemaURI = fStringPool.addSymbol(anotherSchemaURI);
boolean success = switchGrammar(fCurrentSchemaURI);
if (!success && !fNeedValidationOff) {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR,
"Grammar with uri: "
+ fStringPool.toString(fCurrentSchemaURI)
+ " , can not be found");
}
}
}
}
}
// If the elementIndex changed since last time
// we queried the content type, query it again.
if (elementIndex != oldElementIndex)
contentSpecType = getContentSpecType(elementIndex);
if (contentSpecType == -1 && fValidating && !fNeedValidationOff ) {
reportRecoverableXMLError(XMLMessages.MSG_ELEMENT_NOT_DECLARED,
XMLMessages.VC_ELEMENT_VALID,
element.rawname);
}
if (fGrammar != null && fGrammarIsSchemaGrammar && elementIndex != -1) {
fAttrListHandle = addDefaultAttributes(elementIndex, attrList, fAttrListHandle, fValidating, fStandaloneReader != -1);
}
if (fAttrListHandle != -1) {
//fAttrList.endAttrList();
int dupAttrs[];
if ((dupAttrs = fAttrList.endAttrList()) != null) {
Object[] args = {fStringPool.toString(element.rawname), null};
for (int i = 0; i < dupAttrs.length; i++) {
args[1] = fStringPool.toString(dupAttrs[i]);
fErrorReporter.reportError(fErrorReporter.getLocator(),
XMLMessages.XMLNS_DOMAIN,
XMLMessages.MSG_ATTRIBUTE_NOT_UNIQUE,
XMLMessages.WFC_UNIQUE_ATT_SPEC,
args,
XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
}
}
}
if (DEBUG_PRINT_ATTRIBUTES) {
String elementStr = fStringPool.toString(element.rawname);
System.out.print("startElement: <" + elementStr);
if (fAttrListHandle != -1) {
int index = attrList.getFirstAttr(fAttrListHandle);
while (index != -1) {
System.out.print(" " + fStringPool.toString(attrList.getAttrName(index)) + "=\"" +
fStringPool.toString(attrList.getAttValue(index)) + "\"");
index = attrList.getNextAttr(index);
}
}
System.out.println(">");
}
// REVISIT: Validation. Do we need to recheck for the xml:lang
// attribute? It was already checked above -- perhaps
// this is to check values that are defaulted in? If
// so, this check could move to the attribute decl
// callback so we can check the default value before
// it is used.
if (fAttrListHandle != -1 && !fNeedValidationOff ) {
int index = fAttrList.getFirstAttr(fAttrListHandle);
while (index != -1) {
int attrNameIndex = attrList.getAttrName(index);
if (fStringPool.equalNames(attrNameIndex, fXMLLang)) {
fDocumentScanner.checkXMLLangAttributeValue(attrList.getAttValue(index));
// break;
}
// here, we validate every "user-defined" attributes
int _xmlns = fStringPool.addSymbol("xmlns");
if (attrNameIndex != _xmlns && attrList.getAttrPrefix(index) != _xmlns)
if (fGrammar != null) {
fTempQName.setValues(attrList.getAttrPrefix(index),
attrList.getAttrLocalpart(index),
attrList.getAttrName(index),
attrList.getAttrURI(index) );
int attDefIndex = getAttDefByElementIndex(elementIndex, fTempQName);
if (fTempQName.uri != fXsiURI)
if (attDefIndex == -1 ) {
if (fValidating) {
// REVISIT - cache the elem/attr tuple so that we only give
// this error once for each unique occurrence
Object[] args = { fStringPool.toString(element.rawname),
fStringPool.toString(attrList.getAttrName(index))};
/*****/
fAttrNameLocator = getLocatorImpl(fAttrNameLocator);
fErrorReporter.reportError(fAttrNameLocator,
XMLMessages.XML_DOMAIN,
XMLMessages.MSG_ATTRIBUTE_NOT_DECLARED,
XMLMessages.VC_ATTRIBUTE_VALUE_TYPE,
args,
XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
/******/
}
} else {
fGrammar.getAttributeDecl(attDefIndex, fTempAttDecl);
int attributeType = attributeTypeName(fTempAttDecl);
attrList.setAttType(index, attributeType);
if (fGrammarIsDTDGrammar) {
int normalizedValue = validateDTDattribute(element, attrList.getAttValue(index), fTempAttDecl);
attrList.setAttValue(index, normalizedValue);
}
if (fValidating) {
// check to see if this attribute matched an attribute wildcard
if (fGrammarIsDTDGrammar) {
//do nothing
}
else if ( fGrammarIsSchemaGrammar &&
(fTempAttDecl.type == XMLAttributeDecl.TYPE_ANY_ANY
||fTempAttDecl.type == XMLAttributeDecl.TYPE_ANY_LIST
||fTempAttDecl.type == XMLAttributeDecl.TYPE_ANY_OTHER) ) {
if ((fTempAttDecl.defaultType & XMLAttributeDecl.PROCESSCONTENTS_SKIP) > 0) {
// attribute should just be bypassed,
} else if ( (fTempAttDecl.defaultType & XMLAttributeDecl.PROCESSCONTENTS_STRICT) > 0
|| (fTempAttDecl.defaultType & XMLAttributeDecl.PROCESSCONTENTS_LAX) > 0) {
boolean reportError = false;
boolean processContentStrict =
(fTempAttDecl.defaultType & XMLAttributeDecl.PROCESSCONTENTS_STRICT) > 0;
// ??? REVISIT: can't tell whether it's a local attribute
// or a global one with empty namespace
//if (fTempQName.uri == StringPool.EMPTY_STRING) {
// if (processContentStrict) {
// reportError = true;
// }
//} else {
{
Grammar aGrammar =
fGrammarResolver.getGrammar(fStringPool.toString(fTempQName.uri));
if (aGrammar == null || !(aGrammar instanceof SchemaGrammar) ) {
if (processContentStrict) {
reportError = true;
}
} else {
SchemaGrammar sGrammar = (SchemaGrammar) aGrammar;
Hashtable attRegistry = sGrammar.getAttributeDeclRegistry();
if (attRegistry == null) {
if (processContentStrict) {
reportError = true;
}
} else {
XMLAttributeDecl attDecl = (XMLAttributeDecl) attRegistry.get(fStringPool.toString(fTempQName.localpart));
if (attDecl == null) {
if (processContentStrict) {
reportError = true;
}
} else {
DatatypeValidator attDV = attDecl.datatypeValidator;
if (attDV == null) {
if (processContentStrict) {
reportError = true;
}
} else {
try {
String unTrimValue = fStringPool.toString(attrList.getAttValue(index));
String value = unTrimValue.trim();
fWhiteSpace = attDV.getWSFacet();
if (fWhiteSpace == DatatypeValidator.REPLACE) { //CDATA
attDV.validate(unTrimValue, null );
}
else { // normalize
int normalizedValue = fStringPool.addString(value);
attrList.setAttValue(index,normalizedValue );
validateUsingDV(attDV, value, false);
}
} catch (InvalidDatatypeValueException idve) {
fErrorReporter.reportError(fErrorReporter.getLocator(),
SchemaMessageProvider.SCHEMA_DOMAIN,
SchemaMessageProvider.DatatypeError,
SchemaMessageProvider.MSG_NONE,
new Object [] { idve.getMessage()},
XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
}
}
}
}
}
}
if (reportError) {
Object[] args = { fStringPool.toString(element.rawname),
"ANY---"+fStringPool.toString(attrList.getAttrName(index))};
fAttrNameLocator = getLocatorImpl(fAttrNameLocator);
fErrorReporter.reportError(fAttrNameLocator,
XMLMessages.XML_DOMAIN,
XMLMessages.MSG_ATTRIBUTE_NOT_DECLARED,
XMLMessages.VC_ATTRIBUTE_VALUE_TYPE,
args,
XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
}
}
} else if (fTempAttDecl.datatypeValidator == null) {
Object[] args = { fStringPool.toString(element.rawname),
fStringPool.toString(attrList.getAttrName(index))};
System.out.println("[Error] Datatypevalidator for attribute " + fStringPool.toString(attrList.getAttrName(index))
+ " not found in element type " + fStringPool.toString(element.rawname));
/****/
fAttrNameLocator = getLocatorImpl(fAttrNameLocator);
fErrorReporter.reportError(fAttrNameLocator,
XMLMessages.XML_DOMAIN,
XMLMessages.MSG_ATTRIBUTE_NOT_DECLARED,
XMLMessages.VC_ATTRIBUTE_VALUE_TYPE,
args,
XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
/****/
} else {
try {
String unTrimValue = fStringPool.toString(attrList.getAttValue(index));
String value = unTrimValue.trim();
DatatypeValidator tempDV = fTempAttDecl.datatypeValidator;
// if "fixed" is specified, then get the fixed string,
// and compare over value space
if ((fTempAttDecl.defaultType & XMLAttributeDecl.DEFAULT_TYPE_FIXED) > 0 &&
tempDV.compare(value, fTempAttDecl.defaultValue) != 0) {
Object[] args = { fStringPool.toString(element.rawname),
fStringPool.toString(attrList.getAttrName(index)),
unTrimValue,
fTempAttDecl.defaultValue};
fErrorReporter.reportError( fErrorReporter.getLocator(),
XMLMessages.XML_DOMAIN,
XMLMessages.MSG_FIXED_ATTVALUE_INVALID,
XMLMessages.VC_FIXED_ATTRIBUTE_DEFAULT,
args,
XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
}
fWhiteSpace = tempDV.getWSFacet();
if (fWhiteSpace == DatatypeValidator.REPLACE) { //CDATA
tempDV.validate(unTrimValue, null );
}
else { // normalize
int normalizedValue = fStringPool.addString(value);
attrList.setAttValue(index,normalizedValue );
validateUsingDV(tempDV, value, false);