Bug 337179 - Schema with forward type definitions don't load. r=aaronr

This commit is contained in:
doronr%us.ibm.com 2006-05-25 17:06:07 +00:00
Родитель 148944fe8b
Коммит fe6ba26cde
2 изменённых файлов: 53 добавлений и 46 удалений

Просмотреть файл

@ -127,7 +127,20 @@ nsSchemaComplexType::Resolve(nsIWebServiceErrorHandler* aErrorHandler)
if (NS_FAILED(rv)) {
return NS_ERROR_FAILURE;
}
mSimpleBaseType = do_QueryInterface(type);
// mSimpleBaseType could become a complex type under certain conditions
// (simple content that restricts a complex type, which itself is a
// simple content). So if we can't QI to a simple type, get the simple
// base type if it is a complex type.
if (!mSimpleBaseType) {
nsCOMPtr<nsISchemaComplexType> complexType = do_QueryInterface(type);
if (complexType) {
complexType->GetSimpleBaseType(getter_AddRefs(mSimpleBaseType));
}
}
if (!mSimpleBaseType) {
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -1833,61 +1833,63 @@ nsSchemaLoader::ProcessSimpleContentRestriction(nsIWebServiceErrorHandler* aErro
kSchemaNamespacesLength);
nsCOMPtr<nsIDOMElement> childElement;
nsCOMPtr<nsIAtom> tagName;
nsSchemaRestrictionType* restrictionInst;
nsCOMPtr<nsISchemaSimpleType> simpleBase;
restrictionInst = new nsSchemaRestrictionType(aSchema, EmptyString());
if (!restrictionInst) {
return NS_ERROR_OUT_OF_MEMORY;
}
simpleBase = restrictionInst;
// The base type must actually be a complex type (which itself must
// have a simple base type.
nsCOMPtr<nsISchemaComplexType> complexBase = do_QueryInterface(aBaseType);
if (!complexBase) {
nsAutoString baseStr;
rv = aBaseType->GetName(baseStr);
NS_ENSURE_SUCCESS(rv, rv);
// if base type is a place holder, this is ok
PRUint16 schemaType;
rv = aBaseType->GetSchemaType(&schemaType);
nsAutoString errorMsg;
errorMsg.AppendLiteral("Failure processing schema, base type \"");
errorMsg.Append(baseStr);
errorMsg.AppendLiteral("\" of restriction must be a complex type ");
errorMsg.AppendLiteral("which itself must be based on a simple type");
if (NS_SUCCEEDED(rv) && schemaType == nsISchemaType::SCHEMA_TYPE_PLACEHOLDER) {
simpleBase = do_QueryInterface(aBaseType);
} else {
nsAutoString baseStr;
rv = aBaseType->GetName(baseStr);
NS_ENSURE_SUCCESS(rv, rv);
NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_SCHEMA_INVALID_TYPE_USAGE, errorMsg);
nsAutoString errorMsg;
errorMsg.AppendLiteral("Failure processing schema, base type \"");
errorMsg.Append(baseStr);
errorMsg.AppendLiteral("\" of restriction must be a complex type ");
errorMsg.AppendLiteral("which itself must be based on a simple type");
return NS_ERROR_SCHEMA_INVALID_TYPE_USAGE;
}
NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_SCHEMA_INVALID_TYPE_USAGE, errorMsg);
nsCOMPtr<nsISchemaSimpleType> parentSimpleBase;
complexBase->GetSimpleBaseType(getter_AddRefs(parentSimpleBase));
if (parentSimpleBase) {
rv = restrictionInst->SetBaseType(parentSimpleBase);
if (NS_FAILED(rv)) {
return rv;
return NS_ERROR_SCHEMA_INVALID_TYPE_USAGE;
}
} else {
nsCOMPtr<nsISchemaSimpleType> parentSimpleBase;
complexBase->GetSimpleBaseType(getter_AddRefs(parentSimpleBase));
if (parentSimpleBase) {
rv = restrictionInst->SetBaseType(parentSimpleBase);
NS_ENSURE_SUCCESS(rv, rv);
}
}
while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
getter_AddRefs(tagName))) &&
childElement) {
childElement) {
if (tagName == nsSchemaAtoms::sSimpleType_atom) {
nsCOMPtr<nsISchemaSimpleType> simpleType;
rv = ProcessSimpleType(aErrorHandler, aSchema, childElement,
getter_AddRefs(simpleType));
if (NS_FAILED(rv)) {
return rv;
}
NS_ENSURE_SUCCESS(rv, rv);
rv = restrictionInst->SetBaseType(simpleType);
if (NS_FAILED(rv)) {
return rv;
}
NS_ENSURE_SUCCESS(rv, rv);
}
else if ((tagName == nsSchemaAtoms::sMinExclusive_atom) ||
(tagName == nsSchemaAtoms::sMinInclusive_atom) ||
@ -1902,44 +1904,36 @@ nsSchemaLoader::ProcessSimpleContentRestriction(nsIWebServiceErrorHandler* aErro
(tagName == nsSchemaAtoms::sWhiteSpace_atom) ||
(tagName == nsSchemaAtoms::sPattern_atom)) {
nsCOMPtr<nsISchemaFacet> facet;
rv = ProcessFacet(aErrorHandler, aSchema, childElement,
tagName, getter_AddRefs(facet));
if (NS_FAILED(rv)) {
return rv;
}
NS_ENSURE_SUCCESS(rv, rv);
rv = restrictionInst->AddFacet(facet);
if (NS_FAILED(rv)) {
return rv;
}
NS_ENSURE_SUCCESS(rv, rv);
}
else if ((tagName == nsSchemaAtoms::sAttribute_atom) ||
(tagName == nsSchemaAtoms::sAttributeGroup_atom) ||
(tagName == nsSchemaAtoms::sAnyAttribute_atom)) {
nsCOMPtr<nsISchemaAttributeComponent> attribute;
rv = ProcessAttributeComponent(aErrorHandler, aSchema,
childElement, tagName,
getter_AddRefs(attribute));
if (NS_FAILED(rv)) {
return rv;
}
NS_ENSURE_SUCCESS(rv, rv);
rv = aComplexType->AddAttribute(attribute);
if (NS_FAILED(rv)) {
return rv;
}
NS_ENSURE_SUCCESS(rv, rv);
}
}
*aSimpleBaseType = simpleBase;
NS_IF_ADDREF(*aSimpleBaseType);
return NS_OK;
}
nsresult
nsresult
nsSchemaLoader::ProcessSimpleContentExtension(nsIWebServiceErrorHandler* aErrorHandler,
nsSchema* aSchema,
nsIDOMElement* aElement,