Bug 307347 - nsSchemaLoader needs to take ns:name into account for ref=. r/sr=peterv

This commit is contained in:
doronr%us.ibm.com 2005-09-09 14:58:39 +00:00
parent cd22e6bb92
commit 286bede0ab
5 changed files with 111 additions and 43 deletions

View File

@ -196,8 +196,9 @@ nsSchemaAttribute::SetUse(PRUint16 aUse)
//
////////////////////////////////////////////////////////////
nsSchemaAttributeRef::nsSchemaAttributeRef(nsSchema* aSchema,
const nsAString& aRef)
: nsSchemaComponentBase(aSchema), mRef(aRef)
const nsAString& aRef,
const nsAString& aRefNS)
: nsSchemaComponentBase(aSchema), mRef(aRef), mRefNS(aRefNS)
{
}
@ -222,7 +223,16 @@ nsSchemaAttributeRef::Resolve(nsIWebServiceErrorHandler* aErrorHandler)
mIsResolved = PR_TRUE;
if (!mAttribute && mSchema) {
if (mRefNS.IsEmpty()) {
mSchema->GetAttributeByName(mRef, getter_AddRefs(mAttribute));
} else {
// use the namespace and type
nsCOMPtr<nsISchemaCollection> schemaColl;
mSchema->GetCollection(getter_AddRefs(schemaColl));
NS_ENSURE_STATE(schemaColl);
schemaColl->GetAttribute(mRef, mRefNS, getter_AddRefs(mAttribute));
}
}
if (mAttribute) {
@ -474,8 +484,9 @@ nsSchemaAttributeGroup::AddAttribute(nsISchemaAttributeComponent* aAttribute)
//
////////////////////////////////////////////////////////////
nsSchemaAttributeGroupRef::nsSchemaAttributeGroupRef(nsSchema* aSchema,
const nsAString& aRef)
: nsSchemaComponentBase(aSchema), mRef(aRef)
const nsAString& aRef,
const nsAString& aRefNS)
: nsSchemaComponentBase(aSchema), mRef(aRef), mRefNS(aRefNS)
{
}
@ -499,7 +510,21 @@ nsSchemaAttributeGroupRef::Resolve(nsIWebServiceErrorHandler* aErrorHandler)
mIsResolved = PR_TRUE;
if (!mAttributeGroup && mSchema) {
if (mRefNS.IsEmpty()) {
mSchema->GetAttributeGroupByName(mRef, getter_AddRefs(mAttributeGroup));
} else {
// use the namespace and type
nsCOMPtr<nsISchemaCollection> schemaColl;
mSchema->GetCollection(getter_AddRefs(schemaColl));
NS_ENSURE_STATE(schemaColl);
// get the right schema
nsCOMPtr<nsISchema> schema;
schemaColl->GetSchema(mRefNS, getter_AddRefs(schema));
NS_ENSURE_STATE(schema);
schema->GetAttributeGroupByName(mRef, getter_AddRefs(mAttributeGroup));
}
}
if (mAttributeGroup) {

View File

@ -1015,32 +1015,9 @@ nsSchemaLoader::ProcessElement(nsIWebServiceErrorHandler* aErrorHandler,
nsAutoString refNS;
// need to handle ns:type
nsresult rv;
nsCOMPtr<nsIParserService> parserService =
do_GetService("@mozilla.org/parser/parser-service;1", &rv);
rv = ParseNameAndNS(ref, aElement, ref, refNS);
NS_ENSURE_SUCCESS(rv, rv);
const nsAFlatString& qName = PromiseFlatString(ref);
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));
ref.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, refNS);
NS_ENSURE_SUCCESS(rv, rv);
}
elementRef = new nsSchemaElementRef(aSchema, ref, refNS);
if (!elementRef) {
return NS_ERROR_OUT_OF_MEMORY;
@ -2584,13 +2561,18 @@ nsSchemaLoader::ProcessModelGroup(nsIWebServiceErrorHandler* aErrorHandler,
GetMinAndMax(aElement, &minOccurs, &maxOccurs);
// Check for a ref attribute
nsAutoString ref;
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);
ref,
refNS);
if (!modelGroupRef) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -2816,11 +2798,14 @@ nsSchemaLoader::ProcessAttribute(nsIWebServiceErrorHandler* aErrorHandler,
PRUint16 use;
GetUse(aElement, &use);
nsAutoString ref;
nsAutoString ref, refNS;
aElement->GetAttribute(NS_LITERAL_STRING("ref"), ref);
if (!ref.IsEmpty()) {
rv = ParseNameAndNS(ref, aElement, ref, refNS);
NS_ENSURE_SUCCESS(rv, rv);
nsSchemaAttributeRef* attributeRef = new nsSchemaAttributeRef(aSchema,
ref);
ref, refNS);
if (!attributeRef) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -2918,12 +2903,17 @@ nsSchemaLoader::ProcessAttributeGroup(nsIWebServiceErrorHandler* aErrorHandler,
nsCOMPtr<nsISchemaAttributeGroup> attributeGroup;
nsAutoString ref;
nsAutoString ref, refNS;
aElement->GetAttribute(NS_LITERAL_STRING("ref"), ref);
if (!ref.IsEmpty()) {
// need to handle ns:type
rv = ParseNameAndNS(ref, aElement, ref, refNS);
NS_ENSURE_SUCCESS(rv, rv);
nsSchemaAttributeGroupRef* attrRef = new nsSchemaAttributeGroupRef(aSchema,
ref);
ref,
refNS);
if (!attrRef) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -3202,3 +3192,35 @@ nsSchemaLoader::GetMinAndMax(nsIDOMElement* aElement,
}
}
nsresult
nsSchemaLoader::ParseNameAndNS(const nsAString& aName, nsIDOMElement* aElement,
nsAString& aTypeName, nsAString& aTypeNS)
{
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;
}

View File

@ -221,6 +221,9 @@ protected:
void ConstructArrayName(nsISchemaType* aType,
nsAString& aName);
nsresult ParseNameAndNS(const nsAString& aName, nsIDOMElement* aElement,
nsAString& aTypeName, nsAString& aTypeNS);
protected:
nsInterfaceHashtable<nsStringHashKey, nsISchema> mSchemas;
nsCOMPtr<nsISchemaCollection> mBuiltinCollection;

View File

@ -286,8 +286,9 @@ nsSchemaModelGroup::AddParticle(nsISchemaParticle* aParticle)
//
////////////////////////////////////////////////////////////
nsSchemaModelGroupRef::nsSchemaModelGroupRef(nsSchema* aSchema,
const nsAString& aRef)
: nsSchemaParticleBase(aSchema), mRef(aRef)
const nsAString& aRef,
const nsAString& aRefNS)
: nsSchemaParticleBase(aSchema), mRef(aRef), mRefNS(aRefNS)
{
}
@ -312,7 +313,21 @@ nsSchemaModelGroupRef::Resolve(nsIWebServiceErrorHandler* aErrorHandler)
mIsResolved = PR_TRUE;
if (!mModelGroup && mSchema) {
mSchema->GetModelGroupByName(mRef, getter_AddRefs(mModelGroup));
if (mRefNS.IsEmpty()) {
mSchema->GetModelGroupByName(mRef, getter_AddRefs(mModelGroup));
} else {
// use the namespace and type
nsCOMPtr<nsISchemaCollection> schemaColl;
mSchema->GetCollection(getter_AddRefs(schemaColl));
NS_ENSURE_STATE(schemaColl);
// get the right schema
nsCOMPtr<nsISchema> schema;
schemaColl->GetSchema(mRefNS, getter_AddRefs(schema));
NS_ENSURE_STATE(schema);
schema->GetModelGroupByName(mRef, getter_AddRefs(mModelGroup));
}
}
if (mModelGroup) {

View File

@ -336,7 +336,8 @@ class nsSchemaModelGroupRef : public nsSchemaParticleBase,
{
public:
nsSchemaModelGroupRef(nsSchema* aSchema,
const nsAString& aRef);
const nsAString& aRef,
const nsAString& aRefNS);
virtual ~nsSchemaModelGroupRef();
NS_DECL_ISUPPORTS
@ -345,7 +346,7 @@ public:
NS_DECL_NSISCHEMAMODELGROUP
protected:
nsString mRef;
nsString mRef, mRefNS;
nsCOMPtr<nsISchemaModelGroup> mModelGroup;
};
@ -447,7 +448,8 @@ class nsSchemaAttributeRef : public nsSchemaComponentBase,
public nsISchemaAttribute
{
public:
nsSchemaAttributeRef(nsSchema* aSchema, const nsAString& aRef);
nsSchemaAttributeRef(nsSchema* aSchema, const nsAString& aRef,
const nsAString& aRefNS);
virtual ~nsSchemaAttributeRef();
NS_DECL_ISUPPORTS
@ -460,7 +462,7 @@ public:
NS_IMETHOD SetUse(PRUint16 aUse);
protected:
nsString mRef;
nsString mRef, mRefNS;
nsCOMPtr<nsISchemaAttribute> mAttribute;
nsString mDefaultValue;
nsString mFixedValue;
@ -496,7 +498,8 @@ class nsSchemaAttributeGroupRef : public nsSchemaComponentBase,
public nsISchemaAttributeGroup
{
public:
nsSchemaAttributeGroupRef(nsSchema* aSchema, const nsAString& aRef);
nsSchemaAttributeGroupRef(nsSchema* aSchema, const nsAString& aRef,
const nsAString& aRefNS);
virtual ~nsSchemaAttributeGroupRef();
NS_DECL_ISUPPORTS
@ -505,7 +508,7 @@ public:
NS_DECL_NSISCHEMAATTRIBUTEGROUP
protected:
nsString mRef;
nsString mRef, mRefNS;
nsCOMPtr<nsISchemaAttributeGroup> mAttributeGroup;
};