Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
nsSchemaLoader Class Reference

#include <nsSchemaLoader.h>

Inheritance diagram for nsSchemaLoader:
Inheritance graph
[legend]
Collaboration diagram for nsSchemaLoader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsSchemaLoader ()
nsresult Init ()
nsISchema load (in AString schemaURI)
void loadAsync (in AString schemaURI, in nsISchemaLoadListener listener)
nsISchema processSchemaElement (in nsIDOMElement element, in nsIWebServiceErrorHandler aErrorHandler)
nsISchema getSchema (in AString targetNamespace)
nsISchemaElement getElement (in AString name, in AString aNamespace)
nsISchemaAttribute getAttribute (in AString name, in AString aNamespace)
nsISchemaType getType (in AString name, in AString aNamespace)

Protected Member Functions

nsresult ProcessElement (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, nsISchemaElement **aSchemaElement)
nsresult ProcessComplexType (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, nsISchemaComplexType **aComplexType)
 Handle <complexType ...>
nsresult ProcessComplexTypeBody (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, nsSchemaComplexType *aComplexType, nsSchemaModelGroup *aSequence, PRUint16 *aContentModel)
nsresult ProcessSimpleContent (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, nsSchemaComplexType *aComplexType, PRUint16 *aDerivation, nsISchemaType **aBaseType)
nsresult ProcessSimpleContentRestriction (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, nsSchemaComplexType *aComplexType, nsISchemaType *aBaseType, nsISchemaSimpleType **aSimpleBaseType)
nsresult ProcessSimpleContentExtension (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, nsSchemaComplexType *aComplexType, nsISchemaType *aBaseType, nsISchemaSimpleType **aSimpleBaseType)
nsresult ProcessComplexContent (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, nsSchemaComplexType *aComplexType, PRUint16 *aContentModel, PRUint16 *aDerivation, nsISchemaType **aBaseType)
nsresult ProcessSimpleType (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, nsISchemaSimpleType **aSimpleType)
nsresult ProcessSimpleTypeRestriction (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, const nsAString &aName, nsISchemaSimpleType **aSimpleType)
nsresult ProcessSimpleTypeList (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, const nsAString &aName, nsISchemaSimpleType **aSimpleType)
nsresult ProcessSimpleTypeUnion (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, const nsAString &aName, nsISchemaSimpleType **aSimpleType)
nsresult ProcessAttribute (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, nsISchemaAttribute **aAttribute)
nsresult ProcessAttributeGroup (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, nsISchemaAttributeGroup **aAttributeGroup)
nsresult ProcessAttributeComponent (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, nsIAtom *aTagName, nsISchemaAttributeComponent **aAttribute)
nsresult ProcessModelGroup (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, nsIAtom *aTagName, nsSchemaModelGroup *aParentSequence, nsISchemaModelGroup **aModelGroup)
nsresult ProcessParticle (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, nsIAtom *aTagName, nsISchemaParticle **aModelGroup)
nsresult ProcessFacet (nsIWebServiceErrorHandler *aErrorHandler, nsSchema *aSchema, nsIDOMElement *aElement, nsIAtom *aTagName, nsISchemaFacet **aFacet)
nsresult GetNewOrUsedType (nsSchema *aSchema, nsIDOMElement *aContext, const nsAString &aTypeName, nsISchemaType **aType)
void GetUse (nsIDOMElement *aElement, PRUint16 *aUse)
void GetProcess (nsIDOMElement *aElement, PRUint16 *aProcess)
void GetMinAndMax (nsIDOMElement *aElement, PRUint32 *aMinOccurs, PRUint32 *aMaxOccurs)
nsresult GetResolvedURI (const nsAString &aSchemaURI, const char *aMethod, nsIURI **aURI)
nsresult ParseArrayType (nsSchema *aSchema, nsIDOMElement *aAttrElement, const nsAString &aStr, nsISchemaType **aType, PRUint32 *aDimension)
nsresult ParseDimensions (nsSchema *aSchema, nsIDOMElement *aAttrElement, const nsAString &aStr, nsISchemaType *aBaseType, nsISchemaType **aArrayType, PRUint32 *aDimension)
void ConstructArrayName (nsISchemaType *aType, nsAString &aName)
nsresult ParseNameAndNS (const nsAString &aName, nsIDOMElement *aElement, nsAString &aTypeName, nsAString &aTypeNS)
nsresult GetDocumentFromURI (const nsAString &aUri, nsIDOMDocument **aDocument)

Protected Attributes

nsInterfaceHashtable
< nsStringHashKey, nsISchema
mSchemas
nsCOMPtr< nsISchemaCollectionmBuiltinCollection

Detailed Description

Definition at line 94 of file nsSchemaLoader.h.


Constructor & Destructor Documentation

Definition at line 513 of file nsSchemaLoader.cpp.

Here is the call graph for this function:


Member Function Documentation

void nsSchemaLoader::ConstructArrayName ( nsISchemaType aType,
nsAString &  aName 
) [protected]

Definition at line 1520 of file nsSchemaLoader.cpp.

{
  nsAutoString typeName;
  
  aType->GetName(typeName);
  aName.Assign(NS_LITERAL_STRING("ArrayOf") + typeName);
}

Here is the caller graph for this function:

nsISchemaAttribute nsISchemaCollection::getAttribute ( in AString  name,
in AString  aNamespace 
) [inherited]
nsresult nsSchemaLoader::GetDocumentFromURI ( const nsAString &  aUri,
nsIDOMDocument **  aDocument 
) [protected]

Definition at line 3368 of file nsSchemaLoader.cpp.

{
  nsCOMPtr<nsIURI> resolvedURI;
  nsresult rv = GetResolvedURI(aUri, "load", getter_AddRefs(resolvedURI));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIXMLHttpRequest> request(do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv));
  NS_ENSURE_TRUE(request, rv);

  nsCAutoString spec;
  resolvedURI->GetSpec(spec);

  const nsAString& empty = EmptyString();
  rv = request->OpenRequest(NS_LITERAL_CSTRING("GET"), spec, PR_FALSE, empty,
                            empty);
  NS_ENSURE_SUCCESS(rv, rv);

  // Force the mimetype of the returned stream to be xml.
  rv = request->OverrideMimeType(NS_LITERAL_CSTRING("application/xml"));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = request->Send(nsnull);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIDOMDocument> document;
  rv = request->GetResponseXML(getter_AddRefs(document));
  NS_ENSURE_SUCCESS(rv, rv);

  if (document) {
    document.swap(*aDocument);
  }

  return NS_OK;
}

Here is the call graph for this function:

nsISchemaElement nsISchemaCollection::getElement ( in AString  name,
in AString  aNamespace 
) [inherited]
void nsSchemaLoader::GetMinAndMax ( nsIDOMElement aElement,
PRUint32 aMinOccurs,
PRUint32 aMaxOccurs 
) [protected]

Definition at line 3302 of file nsSchemaLoader.cpp.

{
  *aMinOccurs = 1;
  *aMaxOccurs = 1;

  nsAutoString minStr, maxStr;
  aElement->GetAttribute(NS_LITERAL_STRING("minOccurs"), minStr);
  aElement->GetAttribute(NS_LITERAL_STRING("maxOccurs"), maxStr);
  
  PRInt32 rv;
  if (!minStr.IsEmpty()) {
    PRInt32 minVal = minStr.ToInteger(&rv);
    if (NS_SUCCEEDED(rv) && (minVal >= 0)) {
      *aMinOccurs = (PRUint32)minVal;
    }
  }

  if (!maxStr.IsEmpty()) {
    if (maxStr.EqualsLiteral("unbounded")) {
      *aMaxOccurs = nsISchemaParticle::OCCURRENCE_UNBOUNDED;
    }
    else {
      PRInt32 maxVal = maxStr.ToInteger(&rv);
      if (NS_SUCCEEDED(rv) && (maxVal >= 0)) {
        *aMaxOccurs = (PRUint32)maxVal;
      }
    }
  }
}

Here is the caller graph for this function:

nsresult nsSchemaLoader::GetNewOrUsedType ( nsSchema aSchema,
nsIDOMElement aContext,
const nsAString &  aTypeName,
nsISchemaType **  aType 
) [protected]

Definition at line 1075 of file nsSchemaLoader.cpp.

{
  nsresult rv = NS_OK;
  nsAutoString prefix, localName, namespaceURI;

  // See if there's a prefix and get the
  // namespace associated with the prefix
  rv = ParseQualifiedName(aContext, aTypeName, prefix, 
                          localName, namespaceURI);
  if (!prefix.IsEmpty() && NS_FAILED(rv)) {
    // Unknown prefix
    return NS_ERROR_SCHEMA_UNKNOWN_PREFIX;
  }

  *aType = nsnull;
  nsAutoString targetNamespace;
  aSchema->GetTargetNamespace(targetNamespace);
  if (namespaceURI.IsEmpty() || namespaceURI.Equals(targetNamespace)) {
    // It's a local type 
    rv = aSchema->GetTypeByName(localName, aType);
  }
  else {
    rv = GetType(localName, namespaceURI, aType);
    if (!*aType) {
      return NS_ERROR_SCHEMA_UNKNOWN_TARGET_NAMESPACE;
    }
  }

  // If we didn't get a type, we need to create a placeholder
  if (NS_SUCCEEDED(rv) && !*aType) {
    nsSchemaTypePlaceholder* placeholder = new nsSchemaTypePlaceholder(aSchema,
                                                                       localName);
    if (!placeholder) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    *aType = placeholder;
    NS_ADDREF(*aType);
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsSchemaLoader::GetProcess ( nsIDOMElement aElement,
PRUint16 aProcess 
) [protected]

Definition at line 3285 of file nsSchemaLoader.cpp.

{
  *aProcess = nsISchemaAnyParticle::PROCESS_STRICT;

  nsAutoString process;
  aElement->GetAttribute(NS_LITERAL_STRING("process"), process);

  if (process.EqualsLiteral("lax")) {
    *aProcess = nsISchemaAnyParticle::PROCESS_LAX;
  }
  else if (process.EqualsLiteral("skip")) {
    *aProcess = nsISchemaAnyParticle::PROCESS_SKIP;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::GetResolvedURI ( const nsAString &  aSchemaURI,
const char *  aMethod,
nsIURI **  aURI 
) [protected]

Definition at line 617 of file nsSchemaLoader.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIXPCNativeCallContext> cc;
  nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
  if(NS_SUCCEEDED(rv)) {
    rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc));
  }

  if (NS_SUCCEEDED(rv) && cc) {
    JSContext* cx;
    rv = cc->GetJSContext(&cx);
    if (NS_FAILED(rv)) return rv;

    nsCOMPtr<nsIScriptSecurityManager> secMan(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv));
    if (NS_FAILED(rv)) return rv;

    nsCOMPtr<nsIURI> baseURI;
    nsCOMPtr<nsIPrincipal> principal;
    rv = secMan->GetSubjectPrincipal(getter_AddRefs(principal));
    if (NS_SUCCEEDED(rv)) {
      principal->GetURI(getter_AddRefs(baseURI));
    }

    rv = NS_NewURI(aURI, aSchemaURI, nsnull, baseURI);
    if (NS_FAILED(rv)) return rv;

    rv = secMan->CheckLoadURIFromScript(cx, *aURI);
    if (NS_FAILED(rv))
    {
      // Security check failed. The above call set a JS exception. The
      // following lines ensure that the exception is propagated.
      cc->SetExceptionWasThrown(PR_TRUE);
      return rv;
    }
  }
  else {
    rv = NS_NewURI(aURI, aSchemaURI, nsnull);
    if (NS_FAILED(rv)) return rv;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsISchema nsISchemaCollection::getSchema ( in AString  targetNamespace) [inherited]
nsISchemaType nsISchemaCollection::getType ( in AString  name,
in AString  aNamespace 
) [inherited]
void nsSchemaLoader::GetUse ( nsIDOMElement aElement,
PRUint16 aUse 
) [protected]

Definition at line 3268 of file nsSchemaLoader.cpp.

{
  *aUse = nsISchemaAttribute::USE_OPTIONAL;

  nsAutoString use;
  aElement->GetAttribute(NS_LITERAL_STRING("use"), use);
  
  if (use.EqualsLiteral("prohibited")) {
    *aUse = nsISchemaAttribute::USE_PROHIBITED;
  }
  else if (use.EqualsLiteral("required")) {
    *aUse = nsISchemaAttribute::USE_REQUIRED;
  }
}

Here is the caller graph for this function:

Definition at line 519 of file nsSchemaLoader.cpp.

{
  return mSchemas.Init() ? NS_OK : NS_ERROR_FAILURE;
}

Here is the call graph for this function:

nsISchema nsISchemaLoader::load ( in AString  schemaURI) [inherited]
void nsISchemaLoader::loadAsync ( in AString  schemaURI,
in nsISchemaLoadListener  listener 
) [inherited]
nsresult nsSchemaLoader::ParseArrayType ( nsSchema aSchema,
nsIDOMElement aAttrElement,
const nsAString &  aStr,
nsISchemaType **  aType,
PRUint32 aDimension 
) [protected]

Definition at line 1613 of file nsSchemaLoader.cpp.

{
  PRInt32 offset;
  
  offset = aStr.FindChar(PRUnichar('['));
  if (offset == -1) {
    return NS_ERROR_SCHEMA_UNKNOWN_TYPE;
  }
  nsDependentSubstring typeStr(aStr, 0, offset);
          
  nsCOMPtr<nsISchemaType> type;
  nsresult rv = GetNewOrUsedType(aSchema, aAttrElement, typeStr, 
                                 getter_AddRefs(type));
  if (NS_FAILED(rv)) {
    return rv;
  }
  
  nsDependentSubstring dimensionStr(aStr, offset, 
                                    aStr.Length() - offset);
  return ParseDimensions(aSchema, aAttrElement, dimensionStr, type,
                         aType, aDimension);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ParseDimensions ( nsSchema aSchema,
nsIDOMElement aAttrElement,
const nsAString &  aStr,
nsISchemaType aBaseType,
nsISchemaType **  aArrayType,
PRUint32 aDimension 
) [protected]

Definition at line 1530 of file nsSchemaLoader.cpp.

{
  nsReadingIterator<PRUnichar> iter, done_reading;
  aStr.BeginReading(iter);
  aStr.EndReading(done_reading);

  PRUint32 dimension = 1;
  PRUnichar uc = *iter++;
  if (uc != PRUnichar('[')) {
    return NS_ERROR_UNEXPECTED;
  }

  while (iter != done_reading) {
    uc = *iter++;
    if (uc == PRUnichar(',')) {
      dimension++;
    }
    else if (uc == PRUnichar(']')) {
      break;
    }
  }
  *aDimension = dimension;

  while ((iter != done_reading) && (*iter == PRUnichar(' '))) {
    ++iter;
  }

  // If there's still more to go, then create an array type
  // based on the base and continue to parse
  if ((iter != done_reading) && (*iter == PRUnichar('['))) {
    nsAutoString name;
    nsCOMPtr<nsISchemaType> myArrayType;
    PRUint32 myDimension;
    
    nsresult rv = ParseDimensions(aSchema, aAttrElement,
                                  nsDependentSubstring(iter, done_reading),
                                  aBaseType, getter_AddRefs(myArrayType), 
                                  &myDimension);
    if (NS_FAILED(rv)) {
      return rv;
    }

    ConstructArrayName(myArrayType, name);
    nsSchemaComplexType* typeInst = new nsSchemaComplexType(aSchema,
                                                            name, 
                                                            PR_FALSE);
    if (!typeInst) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    nsCOMPtr<nsISchemaComplexType> complexType = typeInst;

    rv = typeInst->Init();
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsISchemaType> soapArray;
    rv = GetType(NS_LITERAL_STRING("Array"),
                 NS_LITERAL_STRING(NS_SOAP_1_2_ENCODING_NAMESPACE),
                 getter_AddRefs(soapArray));
    if (NS_FAILED(rv)) {
      return rv;
    }

    typeInst->SetContentModel(nsISchemaComplexType::CONTENT_MODEL_ELEMENT_ONLY);
    typeInst->SetDerivation(nsISchemaComplexType::DERIVATION_RESTRICTION_COMPLEX,
                            soapArray);
    typeInst->SetArrayInfo(myArrayType, myDimension);

    *aArrayType = typeInst;
  }
  else {
    *aArrayType = aBaseType;
  }
  NS_ADDREF(*aArrayType);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ParseNameAndNS ( const nsAString &  aName,
nsIDOMElement aElement,
nsAString &  aTypeName,
nsAString &  aTypeNS 
) [protected]

Definition at line 3335 of file nsSchemaLoader.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIParserService> parserService =
    do_GetService("@mozilla.org/parser/parser-service;1", &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  const nsAFlatString& qName = PromiseFlatString(aName);
  const PRUnichar *colon;
  rv = parserService->CheckQName(qName, PR_TRUE, &colon);
  NS_ENSURE_SUCCESS(rv, rv);

  if (colon) {
    const PRUnichar* end;
    qName.EndReading(end);

    nsAutoString schemaTypePrefix;
    schemaTypePrefix.Assign(Substring(qName.get(), colon));
    aTypeName.Assign(Substring(colon + 1, end));

    nsCOMPtr<nsIDOM3Node> domNode3 = do_QueryInterface(aElement);
    NS_ENSURE_STATE(domNode3);

    // get the namespace url from the prefix
    rv = domNode3->LookupNamespaceURI(schemaTypePrefix, aTypeNS);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessAttribute ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
nsISchemaAttribute **  aAttribute 
) [protected]

Definition at line 2924 of file nsSchemaLoader.cpp.

{
  nsresult rv;

  nsCOMPtr<nsISchemaAttribute> attribute;

  nsAutoString defaultValue, fixedValue;
  aElement->GetAttribute(NS_LITERAL_STRING("default"), defaultValue);
  aElement->GetAttribute(NS_LITERAL_STRING("fixed"), fixedValue);

  PRUint16 use;
  GetUse(aElement, &use);

  nsAutoString ref, refNS;
  aElement->GetAttribute(NS_LITERAL_STRING("ref"), ref);
  if (!ref.IsEmpty()) {
    nsresult rv = ParseNameAndNS(ref, aElement, ref, refNS);
    NS_ENSURE_SUCCESS(rv, rv);

    nsSchemaAttributeRef* attributeRef = new nsSchemaAttributeRef(aSchema,
                                                                  ref, refNS);
    if (!attributeRef) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    attribute = attributeRef;

    attributeRef->SetConstraints(defaultValue, fixedValue);
    attributeRef->SetUse(use);
  }
  else {
    nsAutoString name;
    aElement->GetAttribute(NS_LITERAL_STRING("name"), name);
    
    nsSchemaAttribute* attributeInst = new nsSchemaAttribute(aSchema,
                                                             name);
    if (!attributeInst) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    attribute = attributeInst;

    attributeInst->SetConstraints(defaultValue, fixedValue);
    attributeInst->SetUse(use);

    nsCOMPtr<nsISchemaSimpleType> simpleType;

    nsChildElementIterator iterator(aElement, 
                                    kSchemaNamespaces, 
                                    kSchemaNamespacesLength);
    nsCOMPtr<nsIDOMElement> childElement;
    nsCOMPtr<nsIAtom> tagName;

    while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                              getter_AddRefs(tagName))) &&
           childElement) {
      if (tagName == nsSchemaAtoms::sSimpleType_atom) {
        rv = ProcessSimpleType(aErrorHandler, aSchema, childElement,
                               getter_AddRefs(simpleType));
        if (NS_FAILED(rv)) {
          return rv;
        }
        break;
      }
    }

    if (!simpleType) {
      nsAutoString typeStr;
      aElement->GetAttribute(NS_LITERAL_STRING("type"), typeStr);

      if (!typeStr.IsEmpty()) {
        nsCOMPtr<nsISchemaType> schemaType;
        rv = GetNewOrUsedType(aSchema, aElement, typeStr, 
                              getter_AddRefs(schemaType));
        if (NS_FAILED(rv)) {
          nsAutoString errorMsg;
          errorMsg.AppendLiteral("Failure processing schema, unknown type \"");
          errorMsg.Append(typeStr);
          errorMsg.AppendLiteral("\"");

          NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

          return rv;
        }

        simpleType = do_QueryInterface(schemaType);
        if (!simpleType) {
          nsAutoString errorMsg;
          errorMsg.AppendLiteral("Failure processing schema, invalid type \"");
          errorMsg.Append(typeStr);
          errorMsg.AppendLiteral("\" for attribute \"");
          errorMsg.Append(name);
          errorMsg.AppendLiteral("\"");

          NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_SCHEMA_INVALID_TYPE_USAGE, errorMsg);

          return NS_ERROR_SCHEMA_INVALID_TYPE_USAGE;
        }
      }
    }

    attributeInst->SetType(simpleType);
  }

  *aAttribute = attribute;
  NS_ADDREF(*aAttribute);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessAttributeComponent ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
nsIAtom aTagName,
nsISchemaAttributeComponent **  aAttribute 
) [protected]

Definition at line 2869 of file nsSchemaLoader.cpp.

{
  nsresult rv;

  if (aTagName == nsSchemaAtoms::sAttribute_atom) {
    nsCOMPtr<nsISchemaAttribute> attribute;

    rv = ProcessAttribute(aErrorHandler, aSchema, aElement, 
                          getter_AddRefs(attribute));
    if (NS_FAILED(rv)) {
      return rv;
    }
    *aAttribute = attribute;
    NS_IF_ADDREF(*aAttribute);
  }
  else if (aTagName == nsSchemaAtoms::sAttributeGroup_atom) {
    nsCOMPtr<nsISchemaAttributeGroup> attributeGroup;

    rv = ProcessAttributeGroup(aErrorHandler, aSchema, aElement, 
                               getter_AddRefs(attributeGroup));
    if (NS_FAILED(rv)) {
      return rv;
    }
    *aAttribute = attributeGroup;
    NS_IF_ADDREF(*aAttribute);
  }
  else if (aTagName == nsSchemaAtoms::sAnyAttribute_atom) {
    nsCOMPtr<nsISchemaAttributeComponent> anyAttribute;
    nsSchemaAnyAttribute* anyAttributeInst = new nsSchemaAnyAttribute(aSchema);
    if (!anyAttributeInst) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    anyAttribute = anyAttributeInst;

    PRUint16 process;
    GetProcess(aElement, &process);
    anyAttributeInst->SetProcess(process);

    nsAutoString namespaceStr;
    aElement->GetAttribute(NS_LITERAL_STRING("namespace"), namespaceStr);
    anyAttributeInst->SetNamespace(namespaceStr);
    
    *aAttribute = anyAttribute;
    NS_ADDREF(*aAttribute);

  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessAttributeGroup ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
nsISchemaAttributeGroup **  aAttributeGroup 
) [protected]

Definition at line 3036 of file nsSchemaLoader.cpp.

{
  nsresult rv;

  nsCOMPtr<nsISchemaAttributeGroup> attributeGroup;

  nsAutoString ref, refNS;
  aElement->GetAttribute(NS_LITERAL_STRING("ref"), ref);

  if (!ref.IsEmpty()) {
    // need to handle ns:type
    nsresult rv = ParseNameAndNS(ref, aElement, ref, refNS);
    NS_ENSURE_SUCCESS(rv, rv);

    nsSchemaAttributeGroupRef* attrRef = new nsSchemaAttributeGroupRef(aSchema,
                                                                       ref,
                                                                       refNS);
    if (!attrRef) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    attributeGroup = attrRef;
  }
  else {
    nsAutoString name;
    aElement->GetAttribute(NS_LITERAL_STRING("name"), name);
    
    nsSchemaAttributeGroup* attrInst = new nsSchemaAttributeGroup(aSchema,
                                                                  name);
    if (!attrInst) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    attributeGroup = attrInst;

    rv = attrInst->Init();
    NS_ENSURE_SUCCESS(rv, rv);

    nsChildElementIterator iterator(aElement, 
                                    kSchemaNamespaces, 
                                    kSchemaNamespacesLength);
    nsCOMPtr<nsIDOMElement> childElement;
    nsCOMPtr<nsIAtom> tagName;

    while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                              getter_AddRefs(tagName))) &&
           childElement) {
      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;
        }
        
        rv = attrInst->AddAttribute(attribute);
        if (NS_FAILED(rv)) {
          return rv;
        }
      }    
    }
  }

  *aAttributeGroup = attributeGroup;
  NS_ADDREF(*aAttributeGroup);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessComplexContent ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
nsSchemaComplexType aComplexType,
PRUint16 aContentModel,
PRUint16 aDerivation,
nsISchemaType **  aBaseType 
) [protected]

Definition at line 2132 of file nsSchemaLoader.cpp.

{
  nsresult rv = NS_OK;

  nsCOMPtr<nsISchemaType> baseType;
  nsChildElementIterator iterator(aElement, 
                                  kSchemaNamespaces, 
                                  kSchemaNamespacesLength);
  nsCOMPtr<nsIDOMElement> childElement;
  nsCOMPtr<nsIAtom> tagName;
  
  // A complexContent element must have children
  if (!iterator.HasChildNodes()) {
    nsAutoString errorMsg(NS_LITERAL_STRING("Failure processing schema, "));
    errorMsg.AppendLiteral("<complexContent .../> must contains ");
    errorMsg.AppendLiteral("<restriction .../> or <extension .../>");
    NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_SCHEMA_INVALID_STRUCTURE, errorMsg);

    return NS_ERROR_SCHEMA_INVALID_STRUCTURE;
  }
  
  while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                            getter_AddRefs(tagName))) &&
         childElement) {       
    nsAutoString baseStr;
    if ((tagName == nsSchemaAtoms::sRestriction_atom) ||
        (tagName == nsSchemaAtoms::sExtension_atom)) {
      childElement->GetAttribute(NS_LITERAL_STRING("base"), baseStr);
      if (baseStr.IsEmpty()) {
        nsAutoString errorMsg;
        errorMsg.AppendLiteral("Failure processing schema, ");
        
        if (tagName == nsSchemaAtoms::sRestriction_atom) {
          errorMsg.AppendLiteral("restriction");
        }
        else {
          errorMsg.AppendLiteral("extension");
        }
        
        errorMsg.AppendLiteral(" must have a \"base\" attribute in order to ");
        errorMsg.AppendLiteral("specify base type");
        
        NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_SCHEMA_MISSING_TYPE, errorMsg);
        
        return NS_ERROR_SCHEMA_MISSING_TYPE;
      }
      
      rv = GetNewOrUsedType(aSchema, childElement, baseStr, 
                            getter_AddRefs(baseType));
      if (NS_FAILED(rv)) {
        nsAutoString errorMsg;
        errorMsg.AppendLiteral("Failure processing schema, unknown base type \"");
        errorMsg.Append(baseStr);
        errorMsg.AppendLiteral("\"");

        NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

        return rv;
      }

      nsCOMPtr<nsISchemaComplexType> complexBaseType(do_QueryInterface(baseType));

      if (tagName == nsSchemaAtoms::sRestriction_atom) {
        *aDerivation = nsISchemaComplexType::DERIVATION_RESTRICTION_COMPLEX;
        rv = ProcessComplexTypeBody(aErrorHandler, aSchema, childElement,
                                    aComplexType, nsnull, aContentModel);
      }
      else {
        *aDerivation = nsISchemaComplexType::DERIVATION_EXTENSION_COMPLEX;
        
        nsCOMPtr<nsISchemaModelGroup> sequence;
        nsSchemaModelGroup* sequenceInst = nsnull;
        if (complexBaseType) {
          // XXX Should really be cloning
          nsCOMPtr<nsISchemaModelGroup> baseGroup;
          rv = complexBaseType->GetModelGroup(getter_AddRefs(baseGroup));
          if (NS_FAILED(rv)) {
            nsAutoString errorMsg;
            errorMsg.AppendLiteral("Failure processing schema, extension for type \"");
            errorMsg.Append(baseStr);
            errorMsg.AppendLiteral("\" does not contains any model group");
            errorMsg.AppendLiteral("such as <all>, <choice>, <sequence>, or <group>");

            NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

            return rv;
          }
          
          if (baseGroup) {
            // Create a new model group that's going to be the a sequence
            // of the base model group and the content below
            sequenceInst = new nsSchemaModelGroup(aSchema, EmptyString());
            if (!sequenceInst) {
              return NS_ERROR_OUT_OF_MEMORY;
            }
            sequence = sequenceInst;

            PRUint16 compositor;
            baseGroup->GetCompositor(&compositor);

            PRUint32 minOccurs, maxOccurs;
            baseGroup->GetMinOccurs(&minOccurs);
            baseGroup->GetMaxOccurs(&maxOccurs);

            // If the base group also a sequence, we can collapse the 
            // two sequences.
            if ((compositor == nsISchemaModelGroup::COMPOSITOR_SEQUENCE) &&
                (minOccurs == 1) && (maxOccurs == 1)) {
              PRUint32 pIndex, pCount;
              baseGroup->GetParticleCount(&pCount);
              for (pIndex = 0; pIndex < pCount; pIndex++) {
                nsCOMPtr<nsISchemaParticle> particle;
                
                rv = baseGroup->GetParticle(pIndex, getter_AddRefs(particle));
                if (NS_FAILED(rv)) {
                  nsAutoString errorMsg;
                  errorMsg.AppendLiteral("Failure processing schema, failure ");
                  errorMsg.AppendLiteral("processing model group for extension ");
                  errorMsg.AppendLiteral("of type \"");
                  errorMsg.Append(baseStr);
                  errorMsg.AppendLiteral("\"");

                  NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

                  return rv;
                }
                
                rv = sequenceInst->AddParticle(particle);
                if (NS_FAILED(rv)) {
                  nsAutoString errorMsg;
                  errorMsg.AppendLiteral("Failure processing schema, failure ");
                  errorMsg.AppendLiteral("processing model group for extension ");
                  errorMsg.AppendLiteral("of type \"");
                  errorMsg.Append(baseStr);
                  errorMsg.AppendLiteral("\"");

                  NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

                  return rv;
                }
              }
            }
            else {
              sequenceInst->AddParticle(baseGroup);
            }
            
            aComplexType->SetModelGroup(sequence);
          }
        }
        
        PRUint16 explicitContent;
        rv = ProcessComplexTypeBody(aErrorHandler, aSchema, childElement,
                                    aComplexType, sequenceInst,
                                    &explicitContent);
        if (NS_FAILED(rv)) {
          return rv;
        }
        // If the explicit content is empty, get the content type
        // from the base
        if ((explicitContent == nsISchemaComplexType::CONTENT_MODEL_EMPTY) &&
            complexBaseType) {
          complexBaseType->GetContentModel(aContentModel);
        }
        else {
          *aContentModel = explicitContent;
        }
      }

      // Copy over the attributes from the base type
      // XXX Should really be cloning
      if (complexBaseType) {
        PRUint32 attrIndex, attrCount;
        complexBaseType->GetAttributeCount(&attrCount);

        for (attrIndex = 0; attrIndex < attrCount; attrIndex++) {
          nsCOMPtr<nsISchemaAttributeComponent> attribute;

          rv = complexBaseType->GetAttributeByIndex(attrIndex,
                                                    getter_AddRefs(attribute));
          if (NS_FAILED(rv)) {
            nsAutoString errorMsg;
            errorMsg.AppendLiteral("Failure processing schema, cannot clone ");
            errorMsg.AppendLiteral("attributes from base type \"");
            errorMsg.Append(baseStr);
            errorMsg.AppendLiteral("\"");

            NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

            return rv;
          }

          rv = aComplexType->AddAttribute(attribute);
          if (NS_FAILED(rv)) {
            nsAutoString errorMsg;
            errorMsg.AppendLiteral("Failure processing schema, cannot clone ");
            errorMsg.AppendLiteral("attributes from base type \"");
            errorMsg.Append(baseStr);
            errorMsg.AppendLiteral("\"");

            NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

            return rv;
          }
        }
      }

      break;
    }
  }

  nsAutoString mixed;
  aElement->GetAttribute(NS_LITERAL_STRING("mixed"), mixed);
  if (mixed.EqualsLiteral("true")) {
    *aContentModel = nsISchemaComplexType::CONTENT_MODEL_MIXED;
  }

  *aBaseType = baseType;
  NS_IF_ADDREF(*aBaseType);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessComplexType ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
nsISchemaComplexType **  aComplexType 
) [protected]

Handle <complexType ...>

Parameters:
aErrorHandlerWebservice error handler.
aSchemaOwning schema (in)
aElement<complexType> element (in)
aComplexTypeSchema complex type built from |aElement|

Definition at line 1413 of file nsSchemaLoader.cpp.

{
  nsresult rv = NS_OK;
  nsCOMPtr<nsISchemaComplexType> complexType;

  nsAutoString abstract, name;
  aElement->GetAttribute(NS_LITERAL_STRING("abstract"), abstract);
  aElement->GetAttribute(NS_LITERAL_STRING("name"), name);

  nsSchemaComplexType* typeInst;
  typeInst = new nsSchemaComplexType(aSchema, name, 
                                     abstract.EqualsLiteral("true"));
  if (!typeInst) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  complexType = typeInst;

  rv = typeInst->Init();
  NS_ENSURE_SUCCESS(rv, rv);

  nsChildElementIterator iterator(aElement, 
                                  kSchemaNamespaces, 
                                  kSchemaNamespacesLength);
  nsCOMPtr<nsIDOMElement> childElement;
  nsCOMPtr<nsIAtom> tagName;

  PRUint16 contentModel = nsISchemaComplexType::CONTENT_MODEL_EMPTY;
  PRUint16 derivation = nsISchemaComplexType::DERIVATION_SELF_CONTAINED;
  nsCOMPtr<nsISchemaType> baseType;
  nsCOMPtr<nsISchemaModelGroup> modelGroup;

  while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                            getter_AddRefs(tagName))) &&
         childElement) {
    if (tagName == nsSchemaAtoms::sSimpleContent_atom) {
      contentModel = nsISchemaComplexType::CONTENT_MODEL_SIMPLE;

      rv = ProcessSimpleContent(aErrorHandler, aSchema, childElement, typeInst,
                                &derivation, getter_AddRefs(baseType));
      break;
    }

    if (tagName == nsSchemaAtoms::sComplexContent_atom) {
      rv = ProcessComplexContent(aErrorHandler, aSchema, childElement, typeInst,
                                 &contentModel, &derivation,
                                 getter_AddRefs(baseType));
      break;
    }

    if (tagName == nsSchemaAtoms::sModelGroup_atom ||
        tagName == nsSchemaAtoms::sAll_atom ||
        tagName == nsSchemaAtoms::sChoice_atom ||
        tagName == nsSchemaAtoms::sSequence_atom ||
        tagName == nsSchemaAtoms::sAttribute_atom ||
        tagName == nsSchemaAtoms::sAttributeGroup_atom ||
        tagName == nsSchemaAtoms::sAnyAttribute_atom) {
      rv = ProcessComplexTypeBody(aErrorHandler, aSchema,
                                  aElement, typeInst, nsnull,
                                  &contentModel);
      break;
    }

    if (tagName == nsSchemaAtoms::sAnnotation_atom) {
      // XXX: skipping for now
    }
    else {
      // Unexpected schema element
      nsAutoString elementName;
      rv = aElement->GetTagName(elementName);
      NS_ENSURE_SUCCESS(rv, rv);
      rv = NS_ERROR_UNEXPECTED;

      nsAutoString errorMsg;
      errorMsg.AppendLiteral("Failure processing schema, unexpected element \"");
      errorMsg.Append(elementName);
      errorMsg.AppendLiteral("\" in <complexType />, should be <simpleContent .../>");
      errorMsg.AppendLiteral(", <complexContent ../>, <annotation .../>");

      NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

      break;
    }
  }

  if (NS_FAILED(rv)) {
    return rv;
  }

  nsAutoString mixed;
  aElement->GetAttribute(NS_LITERAL_STRING("mixed"), mixed);
  if (mixed.EqualsLiteral("true")) {
    contentModel = nsISchemaComplexType::CONTENT_MODEL_MIXED;
  }

  typeInst->SetContentModel(contentModel);
  typeInst->SetDerivation(derivation, baseType);

  *aComplexType = complexType;
  NS_ADDREF(*aComplexType);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessComplexTypeBody ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
nsSchemaComplexType aComplexType,
nsSchemaModelGroup aSequence,
PRUint16 aContentModel 
) [protected]

Definition at line 1642 of file nsSchemaLoader.cpp.

{
  nsresult rv = NS_OK;
  nsChildElementIterator iterator(aElement, 
                                  kSchemaNamespaces, 
                                  kSchemaNamespacesLength);
  nsCOMPtr<nsIDOMElement> childElement;
  nsCOMPtr<nsIAtom> tagName;

  *aContentModel = nsISchemaComplexType::CONTENT_MODEL_EMPTY;

  nsCOMPtr<nsISchemaModelGroup> modelGroup;
  
  while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                            getter_AddRefs(tagName))) &&
         childElement) {
    if ((tagName == nsSchemaAtoms::sModelGroup_atom) ||
        (tagName == nsSchemaAtoms::sAll_atom) ||
        (tagName == nsSchemaAtoms::sChoice_atom) || 
        (tagName == nsSchemaAtoms::sSequence_atom)) {

      if (modelGroup) {
        // We shouldn't already have a model group
        nsAutoString elementName;
        nsresult rv = childElement->GetTagName(elementName);
        NS_ENSURE_SUCCESS(rv, rv);

        nsAutoString errorMsg;
        errorMsg.AppendLiteral("Failure processing schema, must have ");
        errorMsg.AppendLiteral("model group in <complexType .../>, ");
        errorMsg.AppendLiteral("unexpected element \"");
        errorMsg.Append(elementName);
        errorMsg.AppendLiteral("\"");

        NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_SCHEMA_INVALID_STRUCTURE, errorMsg);

        return NS_ERROR_SCHEMA_INVALID_STRUCTURE;
      }
      
      rv = ProcessModelGroup(aErrorHandler, aSchema, 
                             childElement, tagName,
                             aSequence, getter_AddRefs(modelGroup));
      if (NS_FAILED(rv)) {
        return rv;
      }

      PRUint32 particleCount;
      modelGroup->GetParticleCount(&particleCount);
      if (particleCount) {
        *aContentModel = nsISchemaComplexType::CONTENT_MODEL_ELEMENT_ONLY;
      }
      else {
        PRUint16 compositor;
        modelGroup->GetCompositor(&compositor);
        
        PRUint32 minOccurs;
        modelGroup->GetMinOccurs(&minOccurs);
        
        if ((compositor == nsISchemaModelGroup::COMPOSITOR_CHOICE) &&
            (minOccurs > 0)) {
          *aContentModel = nsISchemaComplexType::CONTENT_MODEL_ELEMENT_ONLY;
        }
      }
      
      if (aSequence) {
        // Check if we were collapsed
        if (modelGroup.get() != NS_STATIC_CAST(nsISchemaModelGroup*, 
                                               aSequence)) {
          rv = aSequence->AddParticle(modelGroup);
        }
      }
      else {
        rv = aComplexType->SetModelGroup(modelGroup);
      }
      if (NS_FAILED(rv)) {
        return 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;
      }

      rv = aComplexType->AddAttribute(attribute);
      if (NS_FAILED(rv)) {
        nsAutoString elementName;
        nsAutoString attributeName;
        nsresult rc = childElement->GetTagName(elementName);
        NS_ENSURE_SUCCESS(rc, rc);

        rc = attribute->GetName(attributeName);
        NS_ENSURE_SUCCESS(rc, rc);

        nsAutoString errorMsg;
        errorMsg.AppendLiteral("Failure processing schema, cannot process attribute \"");
        errorMsg.Append(attributeName);
        errorMsg.AppendLiteral("\" of element \"");
        errorMsg.Append(elementName);
        errorMsg.AppendLiteral("\"");

        NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

        return rv;
      }

      // XXX WSDL ugliness making itself into schemas. Hopefully this
      // mechanism for specifying an array type in schemas will die
      // when the Schema WG address qualified names in attribute
      // default values.
      if (tagName == nsSchemaAtoms::sAttribute_atom) {
#define NS_WSDL_NAMESPACE "http://schemas.xmlsoap.org/wsdl/"
        nsAutoString arrayType;
        childElement->GetAttributeNS(NS_LITERAL_STRING(NS_WSDL_NAMESPACE),
                                     NS_LITERAL_STRING("arrayType"), 
                                     arrayType);
        if (!arrayType.IsEmpty()) {
          nsCOMPtr<nsISchemaType> arraySchemaType;
          PRUint32 arrayDimension;
          rv = ParseArrayType(aSchema, 
                              childElement,
                              arrayType, 
                              getter_AddRefs(arraySchemaType),
                              &arrayDimension);
          if (NS_FAILED(rv)) {
            nsAutoString errorMsg;
            errorMsg.AppendLiteral("Failure processing schema, ");
            errorMsg.AppendLiteral("cannot process array type \"");
            errorMsg.Append(arrayType);
            errorMsg.AppendLiteral("\"");

            NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

            return rv;
          }

          rv = aComplexType->SetArrayInfo(arraySchemaType, arrayDimension);
          if (NS_FAILED(rv)) {
            nsAutoString errorMsg;
            errorMsg.AppendLiteral("Failure processing schema, cannot set ");
            errorMsg.AppendLiteral("array information for array type \"");
            errorMsg.Append(arrayType);
            errorMsg.AppendLiteral("\"");

            NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

            return rv;
          }
        }
      }
    }
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessElement ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
nsISchemaElement **  aSchemaElement 
) [protected]
Parameters:
aErrorHandlerError handler (in).
aSchemaSchema in which is the element, not null (in).
aElementDOM element <element .../>, not null (in).
aSchemaElementSchema element from processing DOM element (out).

Definition at line 1127 of file nsSchemaLoader.cpp.

{
  nsresult rv = NS_OK;

  nsCOMPtr<nsISchemaElement> schemaElement;
  PRUint32 minOccurs, maxOccurs;
  GetMinAndMax(aElement, &minOccurs, &maxOccurs);

  // See if it's a reference or an actual element declaration
  nsAutoString ref;
  aElement->GetAttribute(NS_LITERAL_STRING("ref"), ref);
  if (!ref.IsEmpty()) {
    nsSchemaElementRef* elementRef;
    nsAutoString refNS;

    // need to handle ns:type
    nsresult rv = ParseNameAndNS(ref, aElement, ref, refNS);
      NS_ENSURE_SUCCESS(rv, rv);

    elementRef = new nsSchemaElementRef(aSchema, ref, refNS);
    if (!elementRef) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    schemaElement = elementRef;

    elementRef->SetMinOccurs(minOccurs);
    elementRef->SetMaxOccurs(maxOccurs);
  }
  else {
    nsAutoString value;
    nsSchemaElement* elementInst;
    const nsAString& empty = EmptyString();

    rv = aElement->GetAttributeNS(empty, NS_LITERAL_STRING("name"), value);
    
    if (NS_FAILED(rv)) {
      nsresult rc = aElement->GetTagName(value);
      NS_ENSURE_SUCCESS(rc, rc);

      nsAutoString errorMsg;
      errorMsg.AppendLiteral("Failure processing schema element, cannot get ");
      errorMsg.AppendLiteral("attribute \"name\" of element \"");
      errorMsg.Append(value);
      errorMsg.AppendLiteral("\"");

      NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

      return rv;
    }

    value.Trim(" \r\n\t");
    elementInst = new nsSchemaElement(aSchema, value);
    if (!elementInst) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    schemaElement = elementInst;

    elementInst->SetMinOccurs(minOccurs);
    elementInst->SetMaxOccurs(maxOccurs);

    nsAutoString defaultValue, fixedValue;
    rv = aElement->GetAttributeNS(empty, NS_LITERAL_STRING("default"),
                                  defaultValue);
    if (NS_FAILED(rv)) {
      nsresult rc = aElement->GetTagName(value);
      NS_ENSURE_SUCCESS(rc, rc);

      nsAutoString errorMsg;
      errorMsg.AppendLiteral("Failure processing schema element, cannot get ");
      errorMsg.AppendLiteral("attribute \"default\" of element \"");
      errorMsg.Append(value);
      errorMsg.AppendLiteral("\"");

      NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

      return rv;
    }
    
    rv = aElement->GetAttributeNS(empty, NS_LITERAL_STRING("fixed"), 
                                  fixedValue);
    if (NS_FAILED(rv)) {
      nsresult rc = aElement->GetTagName(value);
      NS_ENSURE_SUCCESS(rc, rc);

      nsAutoString errorMsg;
      errorMsg.AppendLiteral("Failure processing schema element, cannot get ");
      errorMsg.AppendLiteral("attribute \"fixed\" of element \"");
      errorMsg.Append(value);
      errorMsg.AppendLiteral("\"");

      NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

      return rv;
    }

    elementInst->SetConstraints(defaultValue, fixedValue);

    rv = aElement->GetAttributeNS(empty, NS_LITERAL_STRING("nillable"), value);
    if (NS_FAILED(rv)) {
      nsresult rc = aElement->GetTagName(value);
      NS_ENSURE_SUCCESS(rc, rc);

      nsAutoString errorMsg;
      errorMsg.AppendLiteral("Failure processing schema element, cannot get ");
      errorMsg.AppendLiteral("attribute \"nillable\" of element \"");
      errorMsg.Append(value);
      errorMsg.AppendLiteral("\"");

      NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

      return rv;
    }
    value.Trim(" \r\n\t");

    PRInt32 flags = 0;
    if (value.EqualsLiteral("true"))
      flags |= nsSchemaElement::NILLABLE;

    rv = aElement->GetAttributeNS(empty, NS_LITERAL_STRING("abstract"), value);
    if (NS_FAILED(rv)) {
      nsresult rc = aElement->GetTagName(value);
      NS_ENSURE_SUCCESS(rc, rc);

      nsAutoString errorMsg;
      errorMsg.AppendLiteral("Failure processing schema element, cannot get ");
      errorMsg.AppendLiteral("attribute \"abstract\" of element \"");
      errorMsg.Append(value);
      errorMsg.AppendLiteral("\"");

      NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

      return rv;
    }
    value.Trim(" \r\n\t");

    if (value.EqualsLiteral("true"))
      flags |= nsSchemaElement::ABSTRACT;

    nsCOMPtr<nsIDOMNode> parent;
    rv = aElement->GetParentNode(getter_AddRefs(parent));
    if (NS_FAILED(rv))
      return rv;
    parent->GetLocalName(value);
    
    // Check if the schema element's targetNamespace applies to <element>.
    // Note: If the <element> element information item has <schema> as its 
    // parent,then the actual value of the targetNamespace is that of the
    // parent <schema> element information item, or absent if there is 
    // none. Otherwise if the <element> element information item has 
    // <schema> element as an ancestor then if "form" is present and its actual
    // value is qualified, or if "form" is absent and the actual value of 
    // elementFormDefault on the <schema> ancestor is qualified, then the
    // actual value of the  targetNamespace [attribute] is that of the ancestor
    // <schema> element information item, or absent if there is none.
    if (value.EqualsLiteral("schema")) {
      flags |= nsSchemaElement::FORM_QUALIFIED;
    }
    else {
      rv = aElement->GetAttributeNS(empty, NS_LITERAL_STRING("form"), 
                                    value);
      if (NS_FAILED(rv)) {
        nsAutoString errorMsg;
        errorMsg.AppendLiteral("Failure processing schema element, cannot get ");
        errorMsg.AppendLiteral("attribute \"form\" of element \"");
        errorMsg.Append(value);
        errorMsg.AppendLiteral("\"");

        NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

        return rv;
      }
      value.Trim(" \r\n\t");
      if (value.IsEmpty()) {
        if (aSchema->IsElementFormQualified()) {
           flags |= nsSchemaElement::FORM_QUALIFIED;
        }
        else {
           flags &= ~nsSchemaElement::FORM_QUALIFIED;
        }
      }
      else if (value.EqualsLiteral("qualified")) {
        flags |= nsSchemaElement::FORM_QUALIFIED;
      }
      else {
         flags &= ~nsSchemaElement::FORM_QUALIFIED;
      }
    }

    elementInst->SetFlags(flags);

    nsCOMPtr<nsISchemaType> schemaType;
    nsAutoString typeStr;
    aElement->GetAttribute(NS_LITERAL_STRING("type"), typeStr);
    if (!typeStr.IsEmpty()) {
      rv = GetNewOrUsedType(aSchema, aElement, typeStr, 
                            getter_AddRefs(schemaType));
      if (NS_FAILED(rv)) {
        nsAutoString errorMsg;
        errorMsg.AppendLiteral("Failure processing schema, unknown type \"");
        errorMsg.Append(typeStr);
        errorMsg.AppendLiteral("\"");

        NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

        return rv;
      }
    }
    // Look for the type as a child of the element 
    else {
      nsChildElementIterator iterator(aElement, 
                                      kSchemaNamespaces, 
                                      kSchemaNamespacesLength);
      nsCOMPtr<nsIDOMElement> childElement;
      nsCOMPtr<nsIAtom> tagName;

      while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                                getter_AddRefs(tagName))) &&
             childElement) {
        if (tagName == nsSchemaAtoms::sSimpleType_atom) {
          nsCOMPtr<nsISchemaSimpleType> simpleType;
          
          rv = ProcessSimpleType(aErrorHandler, aSchema, childElement,
                                 getter_AddRefs(simpleType));
          if (NS_FAILED(rv)) {
            return rv;
          }
          schemaType = simpleType;
          break;
        }
        else if (tagName == nsSchemaAtoms::sComplexType_atom) {
          nsCOMPtr<nsISchemaComplexType> complexType;
          
          rv = ProcessComplexType(aErrorHandler, aSchema, childElement,
                                  getter_AddRefs(complexType));
          if (NS_FAILED(rv)) {
            return rv;
          }
          schemaType = complexType;
          break;
        }
      }
    }

    if (!schemaType) {
      nsAutoString ns;
      aElement->GetNamespaceURI(ns);
      rv = GetType(NS_LITERAL_STRING("anyType"),
                   ns,
                   getter_AddRefs(schemaType));
      if (NS_FAILED(rv)) {
        nsAutoString errorMsg;
        errorMsg.AppendLiteral("Failure processing schema, cannot find \'anyType\' ");
        errorMsg.AppendLiteral("placeholder type in namespace \"");
        errorMsg.Append(ns);
        errorMsg.AppendLiteral("\"");

        NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

        return rv;
      }
    }

    rv = elementInst->SetType(schemaType);
    if (NS_FAILED(rv)) {
      return rv;
    }
  }

  *aSchemaElement = schemaElement;
  NS_ADDREF(*aSchemaElement);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessFacet ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
nsIAtom aTagName,
nsISchemaFacet **  aFacet 
) [protected]

Definition at line 3111 of file nsSchemaLoader.cpp.

{
  PRInt32 rv;

  nsCOMPtr<nsISchemaFacet> facet;
  nsSchemaFacet* facetInst = new nsSchemaFacet(aSchema);
  if (!facetInst) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  facet = facetInst;

  PRUint16 facetType;
  if (aTagName == nsSchemaAtoms::sLength_atom) {
    facetType = nsISchemaFacet::FACET_TYPE_LENGTH;
  }
  else if (aTagName == nsSchemaAtoms::sMinLength_atom) {
    facetType = nsISchemaFacet::FACET_TYPE_MINLENGTH;
  }
  else if (aTagName == nsSchemaAtoms::sMaxLength_atom) {
    facetType = nsISchemaFacet::FACET_TYPE_MAXLENGTH;
  }
  else if (aTagName == nsSchemaAtoms::sPattern_atom) {
    facetType = nsISchemaFacet::FACET_TYPE_PATTERN;
  }
  else if (aTagName == nsSchemaAtoms::sEnumeration_atom) {
    facetType = nsISchemaFacet::FACET_TYPE_ENUMERATION;
  }
  else if (aTagName == nsSchemaAtoms::sWhiteSpace_atom) {
    facetType = nsISchemaFacet::FACET_TYPE_WHITESPACE;
  }
  else if (aTagName == nsSchemaAtoms::sMaxInclusive_atom) {
    facetType = nsISchemaFacet::FACET_TYPE_MAXINCLUSIVE;
  }
  else if (aTagName == nsSchemaAtoms::sMinInclusive_atom) {
    facetType = nsISchemaFacet::FACET_TYPE_MININCLUSIVE;
  }
  else if (aTagName == nsSchemaAtoms::sMaxExclusive_atom) {
    facetType = nsISchemaFacet::FACET_TYPE_MAXEXCLUSIVE;
  }
  else if (aTagName == nsSchemaAtoms::sMinExclusive_atom) {
    facetType = nsISchemaFacet::FACET_TYPE_MINEXCLUSIVE;
  }
  else if (aTagName == nsSchemaAtoms::sTotalDigits_atom) {
    facetType = nsISchemaFacet::FACET_TYPE_TOTALDIGITS;
  }
  else if (aTagName == nsSchemaAtoms::sFractionDigits_atom) {
    facetType = nsISchemaFacet::FACET_TYPE_FRACTIONDIGITS;
  }
  else {
    nsAutoString elementName;
    rv = aElement->GetTagName(elementName);
    NS_ENSURE_SUCCESS(rv, rv);

    nsAutoString errorMsg;
    errorMsg.AppendLiteral("Failure processing schema, unknown type of facet \"");
    errorMsg.Append(elementName);
    errorMsg.AppendLiteral("\"");

    NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_UNEXPECTED, errorMsg);

    return NS_ERROR_UNEXPECTED;
  }
  facetInst->SetFacetType(facetType);

  nsAutoString valueStr;
  aElement->GetAttribute(NS_LITERAL_STRING("value"), valueStr);
  if (valueStr.IsEmpty()) {
    nsAutoString elementName;
    rv = aElement->GetTagName(elementName);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = NS_ERROR_SCHEMA_FACET_VALUE_ERROR;

    nsAutoString errorMsg; 
    errorMsg.AppendLiteral("Failure processing schema, invalid empty value ");
    errorMsg.AppendLiteral("for facet \"");
    errorMsg.Append(elementName);
    errorMsg.AppendLiteral("\"");

    NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

    return rv;
  }

  if ((aTagName == nsSchemaAtoms::sLength_atom) ||
      (aTagName == nsSchemaAtoms::sMinLength_atom) ||
      (aTagName == nsSchemaAtoms::sMaxLength_atom) ||
      (aTagName == nsSchemaAtoms::sTotalDigits_atom) ||
      (aTagName == nsSchemaAtoms::sFractionDigits_atom)) {
    PRInt32 intVal = valueStr.ToInteger(&rv);

    if (NS_FAILED(rv) ||
        (intVal < 0) ||
        ((aTagName == nsSchemaAtoms::sTotalDigits_atom) && (intVal == 0))) {
      nsAutoString elementName;
      rv = aElement->GetTagName(elementName);
      NS_ENSURE_SUCCESS(rv, rv);

      nsAutoString errorMsg; 
      errorMsg.AppendLiteral("Failure processing schema, invalid value for facet \"");
      errorMsg.Append(elementName);
      errorMsg.AppendLiteral("\", <=0");

      NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_SCHEMA_FACET_VALUE_ERROR, errorMsg);

      return NS_ERROR_SCHEMA_FACET_VALUE_ERROR;
    }

    facetInst->SetUintValue((PRUint32)intVal);
  }
  else if (aTagName == nsSchemaAtoms::sWhiteSpace_atom) {
    PRUint16 whiteSpaceVal;
    if (valueStr.EqualsLiteral("collapse")) {
      whiteSpaceVal = nsSchemaFacet::WHITESPACE_COLLAPSE;
    }
    else if (valueStr.EqualsLiteral("preserve")) {
      whiteSpaceVal = nsSchemaFacet::WHITESPACE_PRESERVE;
    }
    else if (valueStr.EqualsLiteral("replace")) {
      whiteSpaceVal = nsSchemaFacet::WHITESPACE_REPLACE;
    }
    else {
      nsAutoString elementName;
      rv = aElement->GetTagName(elementName);
      NS_ENSURE_SUCCESS(rv, rv);

      nsAutoString errorMsg; 
      errorMsg.AppendLiteral("Failure processing schema, invalid value for facet \"");
      errorMsg.Append(elementName);
      errorMsg.AppendLiteral("\", should be \"collapse\", \"preserve\" or \"replace\"");

      NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_SCHEMA_FACET_VALUE_ERROR, errorMsg);

      return NS_ERROR_SCHEMA_FACET_VALUE_ERROR;
    }

    facetInst->SetWhitespaceValue(whiteSpaceVal);
  }
  else {
    facetInst->SetValue(valueStr);
  }
  
  nsAutoString isFixed;
  aElement->GetAttribute(NS_LITERAL_STRING("fixed"), isFixed);
  facetInst->SetIsFixed(isFixed.EqualsLiteral("true"));

  *aFacet = facet;
  NS_ADDREF(*aFacet);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessModelGroup ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
nsIAtom aTagName,
nsSchemaModelGroup aParentSequence,
nsISchemaModelGroup **  aModelGroup 
) [protected]

Definition at line 2689 of file nsSchemaLoader.cpp.

{
  nsresult rv = NS_OK;

  nsCOMPtr<nsISchemaModelGroup> modelGroup;
  PRUint32 minOccurs, maxOccurs;
  GetMinAndMax(aElement, &minOccurs, &maxOccurs);

  // Check for a ref attribute
  nsAutoString ref, refNS;
  aElement->GetAttribute(NS_LITERAL_STRING("ref"), ref);
  
  if ((aTagName == nsSchemaAtoms::sModelGroup_atom) &&
      !ref.IsEmpty()) {

    rv = ParseNameAndNS(ref, aElement, ref, refNS);
    NS_ENSURE_SUCCESS(rv, rv);

    nsSchemaModelGroupRef* modelGroupRef = new nsSchemaModelGroupRef(aSchema, 
                                                                     ref,
                                                                     refNS);
    if (!modelGroupRef) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    modelGroup = modelGroupRef;
    
    modelGroupRef->SetMinOccurs(minOccurs);
    modelGroupRef->SetMaxOccurs(maxOccurs);
  }
  else {
    nsAutoString name;
    aElement->GetAttribute(NS_LITERAL_STRING("name"), name);

    nsChildElementIterator iterator(aElement, 
                                    kSchemaNamespaces, 
                                    kSchemaNamespacesLength);
    nsCOMPtr<nsIDOMElement> childElement;
    nsCOMPtr<nsIAtom> tagName = aTagName;

    // If this is a group element, find the first compositor
    // child and continue with that.
    if (aTagName == nsSchemaAtoms::sModelGroup_atom) {
      while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                                getter_AddRefs(tagName))) &&
             childElement) {
        if ((tagName == nsSchemaAtoms::sAll_atom) ||
            (tagName == nsSchemaAtoms::sChoice_atom) ||
            (tagName == nsSchemaAtoms::sSequence_atom)) {
          iterator.SetElement(childElement);
          break;
        }
      }
    }

    nsSchemaModelGroup* modelGroupInst;

    // If we have a parent sequence and we're a sequence that
    // only appears once, then collapse us.
    if (aParentSequence && 
        (tagName == nsSchemaAtoms::sSequence_atom) &&
        (minOccurs == 1) && (maxOccurs == 1)) {
      modelGroupInst = aParentSequence;
      modelGroup = modelGroupInst;
    }
    else {
      modelGroupInst = new nsSchemaModelGroup(aSchema, name);
      if (!modelGroupInst) {
        return NS_ERROR_OUT_OF_MEMORY;
      }
      modelGroup = modelGroupInst;
      
      modelGroupInst->SetMinOccurs(minOccurs);
      modelGroupInst->SetMaxOccurs(maxOccurs);


      if (tagName == nsSchemaAtoms::sAll_atom) {
        modelGroupInst->SetCompositor(nsISchemaModelGroup::COMPOSITOR_ALL);
      }
      else if (tagName == nsSchemaAtoms::sChoice_atom) {
        modelGroupInst->SetCompositor(nsISchemaModelGroup::COMPOSITOR_CHOICE);
      }
      else if (tagName == nsSchemaAtoms::sSequence_atom) {
        modelGroupInst->SetCompositor(nsISchemaModelGroup::COMPOSITOR_SEQUENCE);
      }
    }
    
    while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                              getter_AddRefs(tagName))) &&
           childElement) {
      if (tagName != nsSchemaAtoms::sAnnotation_atom) {
        nsCOMPtr<nsISchemaParticle> particle;

        rv = ProcessParticle(aErrorHandler, aSchema, childElement,
                             tagName, getter_AddRefs(particle));
        if (NS_FAILED(rv)) {
          return rv;
        }

        rv = modelGroupInst->AddParticle(particle);
        if (NS_FAILED(rv)) {
          return rv;
        }
      }
    }   
  }

  *aModelGroup = modelGroup;
  NS_ADDREF(*aModelGroup);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessParticle ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
nsIAtom aTagName,
nsISchemaParticle **  aModelGroup 
) [protected]

Definition at line 2807 of file nsSchemaLoader.cpp.

{
  nsresult rv;

  if (aTagName == nsSchemaAtoms::sElement_atom) {
    nsCOMPtr<nsISchemaElement> element;

    rv = ProcessElement(aErrorHandler, aSchema, aElement, getter_AddRefs(element));
    if (NS_FAILED(rv)) {
      return rv;
    }
    *aParticle = element;
    NS_IF_ADDREF(*aParticle);
  }
  else if ((aTagName == nsSchemaAtoms::sModelGroup_atom) ||
           (aTagName == nsSchemaAtoms::sChoice_atom) ||
           (aTagName == nsSchemaAtoms::sSequence_atom)) {
    nsCOMPtr<nsISchemaModelGroup> modelGroup;
    
    rv = ProcessModelGroup(aErrorHandler, aSchema, aElement, 
                           aTagName, nsnull, getter_AddRefs(modelGroup));
    if (NS_FAILED(rv)) {
      return rv;
    }
    *aParticle = modelGroup;
    NS_IF_ADDREF(*aParticle);
  }
  else if (aTagName == nsSchemaAtoms::sAny_atom) {

    nsCOMPtr<nsISchemaParticle> anyParticle;
    nsSchemaAnyParticle* anyParticleInst = new nsSchemaAnyParticle(aSchema);
    if (!anyParticleInst) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    anyParticle = anyParticleInst;

    PRUint32 minOccurs, maxOccurs;
    GetMinAndMax(aElement, &minOccurs, &maxOccurs);
    anyParticleInst->SetMinOccurs(minOccurs);
    anyParticleInst->SetMaxOccurs(maxOccurs);

    PRUint16 process;
    GetProcess(aElement, &process);
    anyParticleInst->SetProcess(process);

    nsAutoString namespaceStr;
    aElement->GetAttribute(NS_LITERAL_STRING("namespace"), namespaceStr);
    anyParticleInst->SetNamespace(namespaceStr);

    *aParticle = anyParticle;
    NS_ADDREF(*aParticle);
  
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessSimpleContent ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
nsSchemaComplexType aComplexType,
PRUint16 aDerivation,
nsISchemaType **  aBaseType 
) [protected]

Definition at line 1810 of file nsSchemaLoader.cpp.

{
  nsresult rv = NS_OK;

  nsCOMPtr<nsISchemaType> baseType;

  nsChildElementIterator iterator(aElement, 
                                  kSchemaNamespaces, 
                                  kSchemaNamespacesLength);
  nsCOMPtr<nsIDOMElement> childElement;
  nsCOMPtr<nsIAtom> tagName;
  
  // A simpleContent element must have children
  if (!iterator.HasChildNodes()) {
    nsAutoString errorMsg(NS_LITERAL_STRING("Failure processing schema, "));
    errorMsg.AppendLiteral("<simpleContent .../> invalid structure, should contains ");
    errorMsg.AppendLiteral("<restriction .../> or <extension .../>");

    NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_SCHEMA_INVALID_STRUCTURE, errorMsg);

    return NS_ERROR_SCHEMA_INVALID_STRUCTURE;
  }

  while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                            getter_AddRefs(tagName))) &&
         childElement) {       
    nsAutoString baseStr;
    if ((tagName == nsSchemaAtoms::sRestriction_atom) ||
        (tagName == nsSchemaAtoms::sExtension_atom)) {
      childElement->GetAttribute(NS_LITERAL_STRING("base"), baseStr);
      if (baseStr.IsEmpty()) {
        nsAutoString elementName;
        rv = childElement->GetTagName(elementName);
        NS_ENSURE_SUCCESS(rv, rv);

        nsAutoString errorMsg;
        errorMsg.AppendLiteral("Failure processing schema, \"");
        errorMsg.Append(elementName);
        errorMsg.AppendLiteral("\" must have a \"base\" attribute in order ");
        errorMsg.AppendLiteral("to specify base type");

        NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_SCHEMA_MISSING_TYPE, errorMsg);

        return NS_ERROR_SCHEMA_MISSING_TYPE;
      }
      
      rv = GetNewOrUsedType(aSchema, childElement, baseStr, 
                            getter_AddRefs(baseType));
      if (NS_FAILED(rv)) {
        nsAutoString errorMsg;
        errorMsg.AppendLiteral("Failure processing schema, unknown base type \"");
        errorMsg.Append(baseStr);
        errorMsg.AppendLiteral("\"");

        NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

        return rv;
      }

      nsCOMPtr<nsISchemaSimpleType> simpleBaseType;
      if (tagName == nsSchemaAtoms::sRestriction_atom) {
        *aDerivation = nsISchemaComplexType::DERIVATION_RESTRICTION_SIMPLE;
        rv = ProcessSimpleContentRestriction(aErrorHandler, aSchema, childElement,
                                             aComplexType, baseType,
                                             getter_AddRefs(simpleBaseType));
        if (NS_FAILED(rv)) {
          return rv;
        }
      }
      else {
        *aDerivation = nsISchemaComplexType::DERIVATION_EXTENSION_SIMPLE;
        
        nsCOMPtr<nsISchemaComplexType> complexBaseType(do_QueryInterface(baseType));
        if (complexBaseType) {
          // Copy over the attributes from the base type
          // XXX Should really be cloning
          PRUint32 attrIndex, attrCount;
          complexBaseType->GetAttributeCount(&attrCount);
          
          for (attrIndex = 0; attrIndex < attrCount; attrIndex++) {
            nsCOMPtr<nsISchemaAttributeComponent> attribute;
            
            rv = complexBaseType->GetAttributeByIndex(attrIndex,
                                                      getter_AddRefs(attribute));
            if (NS_FAILED(rv)) {
              nsAutoString errorMsg;
              errorMsg.AppendLiteral("Failure processing schema, cannot clone ");
              errorMsg.AppendLiteral("attributes from base type \"");
              errorMsg.Append(baseStr);
              errorMsg.AppendLiteral("\"");

              NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

              return rv;
            }

            rv = aComplexType->AddAttribute(attribute);
            if (NS_FAILED(rv)) {
              nsAutoString errorMsg;
              errorMsg.AppendLiteral("Failure processing schema, cannot clone ");
              errorMsg.AppendLiteral("attributes from base type \"");
              errorMsg.Append(baseStr);
              errorMsg.AppendLiteral("\"");
              
              NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

              return rv;
            }
          }
        }
        
        rv = ProcessSimpleContentExtension(aErrorHandler, aSchema, childElement,
                                           aComplexType, baseType,
                                           getter_AddRefs(simpleBaseType));
        if (NS_FAILED(rv)) {
          return rv;
        }
      }

      if (simpleBaseType) {
        rv = aComplexType->SetSimpleBaseType(simpleBaseType);
        if (NS_FAILED(rv)) {
          return rv;
        }
      }
      break;
    }
  }

  *aBaseType = baseType;
  NS_IF_ADDREF(*aBaseType);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessSimpleContentExtension ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
nsSchemaComplexType aComplexType,
nsISchemaType aBaseType,
nsISchemaSimpleType **  aSimpleBaseType 
) [protected]

Definition at line 2080 of file nsSchemaLoader.cpp.

{
  nsresult rv = NS_OK;

  nsChildElementIterator iterator(aElement, 
                                  kSchemaNamespaces, 
                                  kSchemaNamespacesLength);
  nsCOMPtr<nsIDOMElement> childElement;
  nsCOMPtr<nsIAtom> tagName;

  // If the base type is a complex type, it must itself have a simple
  // base type
  nsCOMPtr<nsISchemaComplexType> complexBase = do_QueryInterface(aBaseType);
  if (complexBase) {
    complexBase->GetSimpleBaseType(aSimpleBaseType);
  }
  else {
    aBaseType->QueryInterface(NS_GET_IID(nsISchemaSimpleType),
                              (void**)aSimpleBaseType);
  }

  while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                            getter_AddRefs(tagName))) &&
         childElement) {       
    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;
      }
      
      rv = aComplexType->AddAttribute(attribute);
      if (NS_FAILED(rv)) {
        return rv;
      }
    }
  }
  
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessSimpleContentRestriction ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
nsSchemaComplexType aComplexType,
nsISchemaType aBaseType,
nsISchemaSimpleType **  aSimpleBaseType 
) [protected]

Definition at line 1951 of file nsSchemaLoader.cpp.

{
  nsresult rv = NS_OK;

  nsChildElementIterator iterator(aElement, 
                                  kSchemaNamespaces, 
                                  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) {
    // if base type is a place holder, this is ok
    PRUint16 schemaType;
    aBaseType->GetSchemaType(&schemaType);

    if (schemaType == nsISchemaType::SCHEMA_TYPE_PLACEHOLDER) {
      simpleBase = do_QueryInterface(aBaseType);
    } else {
      nsAutoString baseStr;
      rv = aBaseType->GetName(baseStr);
      NS_ENSURE_SUCCESS(rv, rv);

      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");

      NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_SCHEMA_INVALID_TYPE_USAGE, errorMsg);

      return NS_ERROR_SCHEMA_INVALID_TYPE_USAGE;
    }
  } else {
    nsCOMPtr<nsISchemaSimpleType> parentSimpleBase;
    complexBase->GetSimpleBaseType(getter_AddRefs(parentSimpleBase));
  
    if (parentSimpleBase) {
      rv = restrictionInst->SetBaseType(parentSimpleBase);
      if (NS_FAILED(rv)) {
        return rv;
      }
    }
  }

  while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                            getter_AddRefs(tagName))) &&
         childElement) {       
    if (tagName == nsSchemaAtoms::sSimpleType_atom) {
      nsCOMPtr<nsISchemaSimpleType> simpleType;
      
      rv = ProcessSimpleType(aErrorHandler, aSchema, childElement, 
                             getter_AddRefs(simpleType));
      if (NS_FAILED(rv)) {
        return rv;
      }

      rv = restrictionInst->SetBaseType(simpleType);
      if (NS_FAILED(rv)) {
        return rv;
      }
    }
    else if ((tagName == nsSchemaAtoms::sMinExclusive_atom) ||
             (tagName == nsSchemaAtoms::sMinInclusive_atom) ||
             (tagName == nsSchemaAtoms::sMaxExclusive_atom) ||
             (tagName == nsSchemaAtoms::sMaxInclusive_atom) ||
             (tagName == nsSchemaAtoms::sTotalDigits_atom) ||
             (tagName == nsSchemaAtoms::sFractionDigits_atom) ||
             (tagName == nsSchemaAtoms::sLength_atom) ||
             (tagName == nsSchemaAtoms::sMinLength_atom) ||
             (tagName == nsSchemaAtoms::sMaxLength_atom) ||
             (tagName == nsSchemaAtoms::sEnumeration_atom) ||
             (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;
      }

      rv = restrictionInst->AddFacet(facet);
      if (NS_FAILED(rv)) {
        return 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;
      }

      rv = aComplexType->AddAttribute(attribute);
      if (NS_FAILED(rv)) {
        return rv;
      }
    }
  }
  
  *aSimpleBaseType = simpleBase;
  NS_IF_ADDREF(*aSimpleBaseType);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessSimpleType ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
nsISchemaSimpleType **  aSimpleType 
) [protected]

Definition at line 2361 of file nsSchemaLoader.cpp.

{
  nsresult rv = NS_OK;

  nsAutoString name;
  aElement->GetAttribute(NS_LITERAL_STRING("name"), name);

  nsChildElementIterator iterator(aElement, 
                                  kSchemaNamespaces, 
                                  kSchemaNamespacesLength);
  nsCOMPtr<nsIDOMElement> childElement;
  nsCOMPtr<nsIAtom> tagName;

  while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                            getter_AddRefs(tagName))) &&
         childElement) {
    if (tagName == nsSchemaAtoms::sRestriction_atom) {
      rv = ProcessSimpleTypeRestriction(aErrorHandler, aSchema, childElement,
                                        name, aSimpleType);
      break;
    }
    else if (tagName == nsSchemaAtoms::sList_atom) {
      rv = ProcessSimpleTypeList(aErrorHandler, aSchema, childElement,
                                 name, aSimpleType);
      break;
    }
    else if (tagName == nsSchemaAtoms::sUnion_atom) {
      rv = ProcessSimpleTypeUnion(aErrorHandler, aSchema, childElement,
                                  name, aSimpleType);
      break;
    }
  }  
  
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessSimpleTypeList ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
const nsAString &  aName,
nsISchemaSimpleType **  aSimpleType 
) [protected]

Definition at line 2508 of file nsSchemaLoader.cpp.

{
  nsresult rv = NS_OK;

  nsSchemaListType* listInst;
  nsCOMPtr<nsISchemaSimpleType> list;

  listInst = new nsSchemaListType(aSchema, aName);
  if (!listInst) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  list = listInst;

  nsAutoString itemTypeStr;
  aElement->GetAttribute(NS_LITERAL_STRING("itemType"), itemTypeStr);

  nsCOMPtr<nsISchemaSimpleType> itemType;
  if (!itemTypeStr.IsEmpty()) {
    nsCOMPtr<nsISchemaType> type;
    rv = GetNewOrUsedType(aSchema, aElement, itemTypeStr, 
                          getter_AddRefs(type));
    if (NS_FAILED(rv)) {
      nsAutoString errorMsg;
      errorMsg.AppendLiteral("Failure processing schema, unknown item type \"");
      errorMsg.Append(itemTypeStr);
      errorMsg.AppendLiteral("\"");

      NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

      return rv;
    }

    itemType = do_QueryInterface(type);
  }
  else {
    nsChildElementIterator iterator(aElement, 
                                    kSchemaNamespaces, 
                                    kSchemaNamespacesLength);
    nsCOMPtr<nsIDOMElement> childElement;
    nsCOMPtr<nsIAtom> tagName;
    
    while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                              getter_AddRefs(tagName))) &&
           childElement) {
      if (tagName == nsSchemaAtoms::sSimpleType_atom) {
        rv = ProcessSimpleType(aErrorHandler, aSchema, childElement,
                               getter_AddRefs(itemType));
        if (NS_FAILED(rv)) {
          return rv;
        }
        break;
      }
    }
  }

  if (!itemType) {
    nsAutoString errorMsg;
    errorMsg.AppendLiteral("Failure processing schema, no item type ");
    errorMsg.AppendLiteral("for simple type \"");
    errorMsg.Append(aName);
    errorMsg.AppendLiteral("\"");

    NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_SCHEMA_MISSING_TYPE, errorMsg);

    return NS_ERROR_SCHEMA_MISSING_TYPE;
  }
  listInst->SetListType(itemType);

  *aSimpleType = list;
  NS_ADDREF(*aSimpleType);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessSimpleTypeRestriction ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
const nsAString &  aName,
nsISchemaSimpleType **  aSimpleType 
) [protected]

Definition at line 2401 of file nsSchemaLoader.cpp.

{
  nsresult rv = NS_OK;

  nsSchemaRestrictionType* restrictionInst;
  nsCOMPtr<nsISchemaSimpleType> restriction;
 
  restrictionInst = new nsSchemaRestrictionType(aSchema, aName);
  if (!restrictionInst) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  restriction = restrictionInst;

  nsCOMPtr<nsISchemaType> baseType;
  nsAutoString baseStr;
  aElement->GetAttribute(NS_LITERAL_STRING("base"), baseStr);
  if (!baseStr.IsEmpty()) {
    rv = GetNewOrUsedType(aSchema, aElement, baseStr, 
                          getter_AddRefs(baseType));
    if (NS_FAILED(rv)) {
      nsAutoString errorMsg;
      errorMsg.AppendLiteral("Failure processing schema, unknown base type \"");
      errorMsg.Append(baseStr);
      errorMsg.AppendLiteral("\"");

      NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

      return rv;
    }

    nsCOMPtr<nsISchemaSimpleType> simpleBase(do_QueryInterface(baseType));
    if (!simpleBase) {
      nsAutoString errorMsg;
      errorMsg.AppendLiteral("Failure processing schema, base type \"");
      errorMsg.Append(baseStr);
      errorMsg.AppendLiteral("\" should be a simple type");

      NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_SCHEMA_INVALID_TYPE_USAGE, errorMsg);

      return NS_ERROR_SCHEMA_INVALID_TYPE_USAGE;
    }
    rv = restrictionInst->SetBaseType(simpleBase);
  }

  nsChildElementIterator iterator(aElement, 
                                  kSchemaNamespaces, 
                                  kSchemaNamespacesLength);
  nsCOMPtr<nsIDOMElement> childElement;
  nsCOMPtr<nsIAtom> tagName;

  while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                            getter_AddRefs(tagName))) &&
         childElement) {
    if ((tagName == nsSchemaAtoms::sSimpleType_atom) &&
        !baseType) {
      nsCOMPtr<nsISchemaSimpleType> simpleType;
      
      rv = ProcessSimpleType(aErrorHandler, aSchema, childElement, 
                             getter_AddRefs(simpleType));
      if (NS_FAILED(rv)) {
        return rv;
      }

      rv = restrictionInst->SetBaseType(simpleType);
      if (NS_FAILED(rv)) {
        return rv;
      }
      baseType = simpleType;
    }
    else if ((tagName == nsSchemaAtoms::sMinExclusive_atom) ||
             (tagName == nsSchemaAtoms::sMinInclusive_atom) ||
             (tagName == nsSchemaAtoms::sMaxExclusive_atom) ||
             (tagName == nsSchemaAtoms::sMaxInclusive_atom) ||
             (tagName == nsSchemaAtoms::sTotalDigits_atom) ||
             (tagName == nsSchemaAtoms::sFractionDigits_atom) ||
             (tagName == nsSchemaAtoms::sLength_atom) ||
             (tagName == nsSchemaAtoms::sMinLength_atom) ||
             (tagName == nsSchemaAtoms::sMaxLength_atom) ||
             (tagName == nsSchemaAtoms::sEnumeration_atom) ||
             (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;
      }

      rv = restrictionInst->AddFacet(facet);
      if (NS_FAILED(rv)) {
        return rv;
      }
    }
  }

  *aSimpleType = restriction;
  NS_ADDREF(*aSimpleType);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSchemaLoader::ProcessSimpleTypeUnion ( nsIWebServiceErrorHandler aErrorHandler,
nsSchema aSchema,
nsIDOMElement aElement,
const nsAString &  aName,
nsISchemaSimpleType **  aSimpleType 
) [protected]

Definition at line 2587 of file nsSchemaLoader.cpp.

{
  nsresult rv = NS_OK;

  nsSchemaUnionType* unionInst;
  nsCOMPtr<nsISchemaSimpleType> unionType;

  unionInst = new nsSchemaUnionType(aSchema, aName);
  if (!unionInst) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  unionType = unionInst;

  nsCOMPtr<nsISchemaSimpleType> memberType;
  nsAutoString memberTypes;
  aElement->GetAttribute(NS_LITERAL_STRING("memberTypes"), memberTypes);
  if (!memberTypes.IsEmpty()) {
    nsReadingIterator<PRUnichar> begin, end, tokenEnd;

    memberTypes.BeginReading(tokenEnd);
    memberTypes.EndReading(end);

    while (tokenEnd != end) {
      nsAutoString typeStr;
      begin = tokenEnd;
      if (FindCharInReadable(PRUnichar(' '), tokenEnd, end)) {
        CopyUnicodeTo(begin, tokenEnd, typeStr);
        ++tokenEnd;
      }
      else {
        CopyUnicodeTo(begin, end, typeStr);
      }

      nsCOMPtr<nsISchemaType> type;
      rv = GetNewOrUsedType(aSchema, aElement, typeStr, 
                            getter_AddRefs(type));
      if (NS_FAILED(rv)) {
        nsAutoString errorMsg;
        errorMsg.AppendLiteral("Failure processing schema, unknown type \"");
        errorMsg.Append(typeStr);
        errorMsg.AppendLiteral("\"");

        NS_SCHEMALOADER_FIRE_ERROR(rv, errorMsg);

        return rv;
      }
      
      memberType = do_QueryInterface(type);
      if (!memberType) {
        nsAutoString errorMsg;
        errorMsg.AppendLiteral("Failure processing schema, invalid member type \"");
        errorMsg.Append(typeStr);
        errorMsg.AppendLiteral("\" for union about simple type \"");
        errorMsg.Append(aName);
        errorMsg.AppendLiteral("\"");

        NS_SCHEMALOADER_FIRE_ERROR(NS_ERROR_SCHEMA_INVALID_TYPE_USAGE, errorMsg);

        return NS_ERROR_SCHEMA_INVALID_TYPE_USAGE;
      }

      rv = unionInst->AddUnionType(memberType);
      if (NS_FAILED(rv)) {
        return rv;
      }            
    }
  }
  
  nsChildElementIterator iterator(aElement, 
                                  kSchemaNamespaces, 
                                  kSchemaNamespacesLength);
  nsCOMPtr<nsIDOMElement> childElement;
  nsCOMPtr<nsIAtom> tagName;
  
  while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement),
                                            getter_AddRefs(tagName))) &&
         childElement) {
    if (tagName == nsSchemaAtoms::sSimpleType_atom) {
      rv = ProcessSimpleType(aErrorHandler, aSchema, childElement,
                             getter_AddRefs(memberType));
      if (NS_FAILED(rv)) {
        return rv;
      }
      
      rv = unionInst->AddUnionType(memberType);
      if (NS_FAILED(rv)) {
        return rv;
      }      
    }
  }

  *aSimpleType = unionType;
  NS_ADDREF(*aSimpleType);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 232 of file nsSchemaLoader.h.

Definition at line 231 of file nsSchemaLoader.h.


The documentation for this class was generated from the following files: