Bug 267480 - XForms should use nsISchemaLoader. r/sr=darin, not part of default build.

This commit is contained in:
doronr%us.ibm.com 2004-11-10 23:24:23 +00:00
Родитель 74ba8eed94
Коммит 8674c69c26
2 изменённых файлов: 13 добавлений и 9 удалений

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

@ -67,6 +67,7 @@
#include "nsXFormsUtils.h" #include "nsXFormsUtils.h"
#include "nsISchemaLoader.h" #include "nsISchemaLoader.h"
#include "nsISchema.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#ifdef DEBUG_beaufour #ifdef DEBUG_beaufour
@ -85,6 +86,7 @@ static nsIAtom* sModelPropsList[eModel__count];
nsXFormsModelElement::nsXFormsModelElement() nsXFormsModelElement::nsXFormsModelElement()
: mElement(nsnull), : mElement(nsnull),
mSchemaCount(0), mSchemaCount(0),
mSchemaTotal(0),
mPendingInstanceCount(0) mPendingInstanceCount(0)
{ {
} }
@ -104,6 +106,7 @@ nsXFormsModelElement::OnDestroyed()
RemoveModelFromDocument(); RemoveModelFromDocument();
mElement = nsnull; mElement = nsnull;
mSchemas = nsnull;
return NS_OK; return NS_OK;
} }
@ -213,16 +216,14 @@ nsXFormsModelElement::DoneAddingChildren()
nsAutoString schemaList; nsAutoString schemaList;
mElement->GetAttribute(NS_LITERAL_STRING("schema"), schemaList); mElement->GetAttribute(NS_LITERAL_STRING("schema"), schemaList);
if (!schemaList.IsEmpty()) { if (!schemaList.IsEmpty()) {
nsCOMPtr<nsISchemaLoader> loader = do_GetService(NS_SCHEMALOADER_CONTRACTID); NS_ENSURE_TRUE(mSchemas, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(loader, NS_ERROR_FAILURE);
// Parse the space-separated list. // Parse the space-separated list.
PRUint32 offset = 0; PRUint32 offset = 0;
nsCOMPtr<nsIContent> content = do_QueryInterface(mElement); nsCOMPtr<nsIContent> content = do_QueryInterface(mElement);
nsRefPtr<nsIURI> baseURI = content->GetBaseURI(); nsRefPtr<nsIURI> baseURI = content->GetBaseURI();
while (1) { while (1) {
++mSchemaCount; ++mSchemaTotal;
PRInt32 index = schemaList.FindChar(PRUnichar(' '), offset); PRInt32 index = schemaList.FindChar(PRUnichar(' '), offset);
nsCOMPtr<nsIURI> newURI; nsCOMPtr<nsIURI> newURI;
@ -239,7 +240,7 @@ nsXFormsModelElement::DoneAddingChildren()
nsCAutoString uriSpec; nsCAutoString uriSpec;
newURI->GetSpec(uriSpec); newURI->GetSpec(uriSpec);
rv = loader->LoadAsync(NS_ConvertUTF8toUTF16(uriSpec), this); rv = mSchemas->LoadAsync(NS_ConvertUTF8toUTF16(uriSpec), this);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
// this is a fatal error // this is a fatal error
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException); nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException);
@ -318,6 +319,8 @@ nsXFormsModelElement::OnCreated(nsIXTFGenericElementWrapper *aWrapper)
nsresult rv = mMDG.Init(); nsresult rv = mMDG.Init();
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
mSchemas = do_GetService(NS_SCHEMALOADER_CONTRACTID);
return NS_OK; return NS_OK;
} }
@ -403,7 +406,7 @@ nsXFormsModelElement::Refresh()
NS_IMETHODIMP NS_IMETHODIMP
nsXFormsModelElement::OnLoad(nsISchema* aSchema) nsXFormsModelElement::OnLoad(nsISchema* aSchema)
{ {
mSchemas.AppendObject(aSchema); mSchemaCount++;
if (IsComplete()) { if (IsComplete()) {
nsresult rv = FinishConstruction(); nsresult rv = FinishConstruction();
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);

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

@ -113,14 +113,15 @@ private:
NS_HIDDEN_(void) RemoveModelFromDocument(); NS_HIDDEN_(void) RemoveModelFromDocument();
PRBool IsComplete() const { return (mSchemas.Count() == mSchemaCount PRBool IsComplete() const { return (mSchemaTotal == mSchemaCount
&& mPendingInstanceCount == 0); } && mPendingInstanceCount == 0); }
nsIDOMElement *mElement; nsIDOMElement *mElement;
nsCOMArray<nsISchema> mSchemas; nsCOMPtr<nsISchemaLoader> mSchemas;
nsVoidArray mFormControls; nsVoidArray mFormControls;
PRInt32 mSchemaCount; PRInt32 mSchemaCount;
PRInt32 mSchemaTotal;
PRInt32 mPendingInstanceCount; PRInt32 mPendingInstanceCount;
nsXFormsMDG mMDG; nsXFormsMDG mMDG;