Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsSchemaComplexType.cpp File Reference
#include "nsSchemaPrivate.h"

Go to the source code of this file.

Functions

 NS_IMPL_ISUPPORTS3_CI (nsSchemaComplexType, nsISchemaComponent, nsISchemaType, nsISchemaComplexType) NS_IMETHODIMP nsSchemaComplexType

Function Documentation

Definition at line 59 of file nsSchemaComplexType.cpp.

{
  if (mIsResolved) {
    return NS_OK;
  }

  mIsResolved = PR_TRUE;
  nsresult rv;
  PRUint32 i, count;

  count = mAttributes.Count();
  for (i = 0; i < count; ++i) {
    rv = mAttributes.ObjectAt(i)->Resolve(aErrorHandler);
    if (NS_FAILED(rv)) {
      nsAutoString attrName;
      nsresult rv1 = mAttributes.ObjectAt(i)->GetName(attrName);
      NS_ENSURE_SUCCESS(rv1, rv1);

      nsAutoString errorMsg;
      errorMsg.AppendLiteral("Failure resolving schema complex type, ");
      errorMsg.AppendLiteral("cannot resolve attribute \"");
      errorMsg.Append(attrName);
      errorMsg.AppendLiteral("\"");
      
      NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

      return rv;
    }
  }

  if (!mSchema) {
    return NS_ERROR_FAILURE;
  }

  nsCOMPtr<nsISchemaType> type;
  if (mBaseType) {
    rv = mSchema->ResolveTypePlaceholder(aErrorHandler, mBaseType, getter_AddRefs(type));
    if (NS_FAILED(rv)) {
      return NS_ERROR_FAILURE;
    }
    mBaseType = type;
    rv = mBaseType->Resolve(aErrorHandler);
    if (NS_FAILED(rv)) {
      nsAutoString baseStr;
      nsresult rv1 = type->GetName(baseStr);
      NS_ENSURE_SUCCESS(rv1, rv1);

      nsAutoString errorMsg;
      errorMsg.AppendLiteral("Failure resolving schema complex type, ");
      errorMsg.AppendLiteral("cannot resolve base type \"");
      errorMsg.Append(baseStr);
      errorMsg.AppendLiteral("\"");

      NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);
      return NS_ERROR_FAILURE;
    }
  }
    
  if (mSimpleBaseType) {
    rv = mSchema->ResolveTypePlaceholder(aErrorHandler, mSimpleBaseType, 
                                         getter_AddRefs(type));
    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;
    }
    rv = mSimpleBaseType->Resolve(aErrorHandler);
    if (NS_FAILED(rv)) {
      return NS_ERROR_FAILURE;
    }
  }

  if (mModelGroup) {
    rv = mModelGroup->Resolve(aErrorHandler);
    if (NS_FAILED(rv)) {
      nsAutoString modelName;
      nsresult rv1 = mModelGroup->GetName(modelName);
      NS_ENSURE_SUCCESS(rv1, rv1);

      nsAutoString errorMsg;
      errorMsg.AppendLiteral("Failure resolving schema complex type, ");
      errorMsg.AppendLiteral("cannot resolve model group \"");
      errorMsg.Append(modelName);
      errorMsg.AppendLiteral("\"");

      NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

      return NS_ERROR_FAILURE;
    }
  }

  if (mArrayInfo) {
    nsCOMPtr<nsISchemaType> placeHolder;
    mArrayInfo->GetType(getter_AddRefs(placeHolder));
    if (placeHolder) {
      PRUint16 schemaType;
      placeHolder->GetSchemaType(&schemaType);
      if (schemaType == nsISchemaType::SCHEMA_TYPE_PLACEHOLDER) {
        rv = mSchema->ResolveTypePlaceholder(aErrorHandler, placeHolder, getter_AddRefs(type));
        if (NS_FAILED(rv)) {
          return NS_ERROR_FAILURE;
        }
        rv = type->Resolve(aErrorHandler);
        if (NS_FAILED(rv)) {
          return NS_ERROR_FAILURE;
        }
        SetArrayInfo(type, mArrayInfo->GetDimension());
      }
      else {
         rv = placeHolder->Resolve(aErrorHandler);
        if (NS_FAILED(rv)) {
          return NS_ERROR_FAILURE;
        }
      }
    } 
  }

  return NS_OK;
}

Here is the call graph for this function: