if (aNameSpaceID == kNameSpaceID_Unknown) { *aElementFactory = mDefaultElementFactory; NS_ADDREF(*aElementFactory);  return NS_OK; }
NameSpaceManagerImpl::GetElementFactory(PRInt32 aNameSpaceID,                                        nsIElementFactory **aElementFactory){  *aElementFactory = nsnull;  NS_ENSURE_TRUE(aNameSpaceID >= 0, NS_ERROR_ILLEGAL_VALUE);  if (aNameSpaceID < mElementFactoryArray.Count()) {    *aElementFactory = mElementFactoryArray.ObjectAt(aNameSpaceID);    if (*aElementFactory) {      NS_ADDREF(*aElementFactory);      return NS_OK;    }  }  nsAutoString uri;  GetNameSpaceURI(aNameSpaceID, uri);  nsCOMPtr<nsIElementFactory> ef;  if (!uri.IsEmpty()) {    nsCAutoString contract_id(NS_ELEMENT_FACTORY_CONTRACTID_PREFIX);    contract_id.Append(NS_ConvertUCS2toUTF8(uri));    ef = do_GetService(contract_id.get());  }  if (!ef) {    ef = mDefaultElementFactory;  }  PRInt32 count = mElementFactoryArray.Count();  if (aNameSpaceID < count) {    mElementFactoryArray.ReplaceObjectAt(ef, aNameSpaceID);  } else {    // This sucks, simply doing an InsertObjectAt() should IMNSHO    // automatically grow the array and insert null's as needed to    // fill up the array!?!!        for (PRInt32 i = count; i < aNameSpaceID; ++i) {      mElementFactoryArray.AppendObject(nsnull);    }    mElementFactoryArray.AppendObject(ef);  }  *aElementFactory = ef;  NS_ADDREF(*aElementFactory);  return NS_OK;}